【发布时间】:2014-10-26 11:52:49
【问题描述】:
..这是有用的。但是..我在 i-net 上看不到任何相关内容..这似乎有点问题。这就是为什么..我尝试自己构建功能:
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef struct
{
byte R;
byte G;
byte B;
} RGB;
dword
getpixels
(char *FILE_NAME)
{
dword WIDTH = 500; // example dimension
dword HEIGHT = 500; // example dimension
FILE* fp = fopen(FILE_NAME, "rb");
#define HEADERS_SIZE 54
byte color[3];
byte colorTable[50000][3]; // maximum 50000 pixels
int val = (-1), valr;
dword l;
dword count = 0;
fseek(fp, HEADERS_SIZE, SEEK_SET); // move iterator to where the pixels start fromS
// alternate : fread(&valr, 1, 1, fp) == 1
while( (valr = fgetc(fp)) != EOF ) // runs the code while this is true
{
val++; // increment index
if(val > 2) val = 0;
color[val] = valr;
for(l=0; l<50000; l++) {
if(val == 2 && color[0] != colorTable[l][0] && color[1] != colorTable[l][1] && color[2] != colorTable[l][2])
{
colorTable[l][0] = color[0];
colorTable[l][1] = color[1];
colorTable[l][2] = color[2];
count++;
}
}
fseek(fp, WIDTH%4, SEEK_CUR); // skip padding
}
fclose(fp);
return count;
}
您可能已经感觉到.. 该功能无法正常工作,因为.. 我不知道。这就是我真正要问的。我做错了什么?
【问题讨论】: