#include <stdio.h>
#include <stdlib.h>
#define WIDTH 130
#define HEIGHT 130
void main()
{
unsigned char red;
unsigned char green;
unsigned char blue;
int colorVal;
int i, j;
FILE* source = fopen("image.raw", "rb");
FILE* target = fopen("image.txt", "w");
for(i=0 ; i<HEIGHT ; i++)
{
for(j=0 ; j<WIDTH ; j++)
{
red = fgetc(source);
green = fgetc(source);
blue = fgetc(source);
colorVal = red + green*256 + blue*65536;
fprintf(target, "%d", colorVal);
if(j != WIDTH-1)
{
fprintf(target, ",");
}
}
fprintf(target, "\n");
}
fclose(source);
fclose(target);
} |