3,882
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <iostream>
#include <stdexcept>
#include <windows.h>
#include <time.h>
using namespace std;
#define MAKEDWORD(r,g,b) ((( ((unsigned char)(r)<<8) +(unsigned char)(g))<<8)+(unsigned char)(b) )
char GrayGraphic[1024*768*256];
char ***m_convertTable1 = (char***)new unsigned char **[256];
char *m_convertTable2 = (char*)new unsigned char [256*256*256]; //就是2^24
char m_convertTable3[256*256*256];
unsigned char pixel[1024*768*3];
unsigned int rgb[ 1024*768 ];
void InitTest1()
{
for(int i = 0; i < 256; i++)
{
m_convertTable1[i] = (char**)new unsigned char *[256];
for(int j = 0; j < 256; j++)
{
m_convertTable1[i][j] = (char*)new unsigned char[256];
}
}
}
void test1()
{
int m;
for(int i = 0; i < 1024*768*256; i++)
{
//k=i/256;
m=i%256;
unsigned char r = pixel[m];
unsigned char g = pixel[m+1];
unsigned char b = pixel[m+2];
GrayGraphic[i] = m_convertTable1[r][g][b];
}
}
void test2()
{
int m;
for(int i = 0; i < 1024*768*256; i++ )
{
m=i%256;
unsigned char r = pixel[m];
unsigned char g = pixel[m+1];
unsigned char b = pixel[m+2];
GrayGraphic[i] = m_convertTable2[MAKEDWORD(r,g,b)];
}
}
void test3()
{
int m;
for(int i = 0; i < 1024*768*256; i++ )
{
m=i%256;
GrayGraphic[i] = m_convertTable3[ rgb[m] ];
}
}
int main()
{
int i;
srand((unsigned)time(NULL));
for( i = 0; i < 1024*768*3; i++ )
{
pixel[i]=rand()%256;
}
for( i=0; i<1024*768; i+=3 )
{
rgb[i] = MAKEDWORD( pixel[i],pixel[i+1],pixel[i+2] );
}
DWORD t;
InitTest1();
t = ::GetTickCount();
test2();
cout << "test2 "<< ::GetTickCount()-t<<endl;
t = ::GetTickCount();
test1();
cout << "test1 "<< ::GetTickCount()-t<<endl;
t = ::GetTickCount();
test3();
cout << "test3 "<< ::GetTickCount()-t<<endl;
return 0;
}
#include <string>
#include <iostream>
#include <stdexcept>
#include <windows.h>
using namespace std;
#define MAKEDWORD(r,g,b) ( (( (r<<8) +g)<<8)+b )
char GrayGraphic[1024*768*256];
void InitTest1()
{
int m;
char ***m_convertTable1 = (char***)new unsigned char **[256];
for(int i = 0; i < 256; i++)
{
m_convertTable1[i] = (char**)new unsigned char *[256];
for(int j = 0; j < 256; j++)
{
m_convertTable1[i][j] = (char*)new unsigned char[256];
}
}
for(int i = 0; i < 1024*768*256; i++)
{
m=i%256;
unsigned char r = m;
unsigned char g = m;
unsigned char b = m;
GrayGraphic[i] = m_convertTable1[r][g][b];
}
}
void test1()
{
int m;
char *m_convertTable1 = (char*)new unsigned char [256*256*256]; //就是2^24
for(int i = 0; i < 1024*768*256; i++)
{
m = i % 256;
unsigned char r = m;
unsigned char g = m;
unsigned char b = m;
GrayGraphic[i] = m_convertTable1[r*256*256+g*256+b];
}
}
void test2()
{
int m;
char *m_convertTable2 = (char*)new unsigned char [256*256*256]; //就是2^24
for(int i = 0; i < 1024*768*256; i++ )
{
m=i%256;
unsigned char r = m;
unsigned char g = m;
unsigned char b = m;
GrayGraphic[i] = m_convertTable2[MAKEDWORD(r,g,b)];
}
}
int main()
{
DWORD t;
t = ::GetTickCount();
InitTest1();//Release =~ 5100
cout << ::GetTickCount()-t<<endl;
t = ::GetTickCount();
test1();//Release =~ 3100
cout << ::GetTickCount()-t<<endl;
t = ::GetTickCount();
test2();//Release =~ 3100
cout << ::GetTickCount()-t<<endl;
system("pause");
}
#include <string>
#include <iostream>
#include <stdexcept>
#include <windows.h>
using namespace std;
#define MAKEDWORD(r,g,b) ( (( (r<<8) +g)<<8)+b )
char GrayGraphic[1024*768*256];
char ***m_convertTable1 = (char***)new unsigned char **[256];
char *m_convertTable2 = (char*)new unsigned char [256*256*256]; //就是2^24
void InitTest1()
{
for(int i = 0; i < 256; i++)
{
m_convertTable1[i] = (char**)new unsigned char *[256];
for(int j = 0; j < 256; j++)
{
m_convertTable1[i][j] = (char*)new unsigned char[256];
}
}
}
void test1()
{
int m;
for(int i = 0; i < 1024*768*256; i++)
{
//k=i/256;
m=i%256;
unsigned char r = m;
unsigned char g = m;
unsigned char b = m;
GrayGraphic[i] = m_convertTable1[r][g][b];
}
}
void test2()
{
int m;
for(int i = 0; i < 1024*768*256; i++ )
{
m=i%256;
unsigned char r = m;
unsigned char g = m;
unsigned char b = m;
GrayGraphic[i] = m_convertTable2[MAKEDWORD(r,g,b)];
}
}
int main()
{
DWORD t;
InitTest1();
t = ::GetTickCount();
test1();
cout << ::GetTickCount()-t<<endl;
t = ::GetTickCount();
test2();
cout << ::GetTickCount()-t<<endl;
return 0;
}
// 用 #pragma align 或者 __attribute__((align)) 做一下对齐
struct PIXEL
{
UCHAR R;
UCHAR G;
UCHAR B;
UCHAR __padding;
}
int main()
{
////////////////////////////
DWORD t = ::GetTickCount();
char ***m_convertTable = (char***)new unsigned char **[256];
for( t i = 0; i < 256; i++)
{
m_convertTable[i] = (char**)new unsigned char *[256];
for(int j = 0; j < 256; j++)
{
m_convertTable[i][j] = (char*)new unsigned char[256];
for(int k = 0; k < 256; k++)
{
m_convertTable[i][j][k] = 0.3 * i+0.6 * j+0.1* k;
}
}
}
char GrayGraphic[1024*768];
const int d = 1024*768;
for(int i = 0; i < d; i++)
{
unsigned char r = 7;
unsigned char g = 7;
unsigned char b = 7;
GrayGraphic[i] = m_convertTable[r][g][b];
}
cout << ::GetTickCount()-t<<endl;
system( "pause ");
return 0;
}
int main()
{
////////////////////////////
DWORD t = ::GetTickCount();
int i,j,k;
char *m_convertTable = (char*)new unsigned char [256*256*256];
for(int n = 0; n < 256*256*256; n++)
{
i = n/256/256;
j = n/256;
k = n%256;
m_convertTable[n] = 0.3 * i+0.6 * j+0.1* k;
}
char GrayGraphic[1024*768];
const int d = 1024*768;
for(int i = 0; i < d; i++)
{
unsigned char r = 7;
unsigned char g = 7;
unsigned char b = 7;
GrayGraphic[i] = m_convertTable[r*256*256+g*256+b];
}
cout << ::GetTickCount()-t<<endl;
system( "pause ");
return 0;
}