In GIMP, you can save the image as a header file C. I did this with an XPM file that looks like this:

If I wanted to save the XPM image as a C header file, GIMP would output that C header file .
To process each pixel of data in a given image, the header pixel is called repeatedly. I donβt understand what the header pixel does for data processing in the first place.
#define HEADER_PIXEL(data,pixel) {\ pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \ pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); \ pixel[2] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); \ data += 4; \ }
When I saw that it was being used in another personβs code , they stated that the byte order was in the wrong order and rebuilt it on their own. They used it like this:
char *pixel, *data = header_data; int i = width * height; *processed_data = pixel = malloc(i * 4 + 1); while(i-- > 0) { pixel[0] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); pixel[2] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); pixel[3] = 0; data += 4; pixel += 4; }
But this did not help me understand what is happening with all bit offsets and bitwise or "why minus 33?". and so on. If anyone can give an explanation of what is happening to process the image data in the header, that would be greatly appreciated.
Thanks in advance!
c header-files gimp xlib
SpeedBurner Jan 16 '12 at 2:27 2012-01-16 02:27
source share