Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7081731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:57:27+00:00 2026-05-28T06:57:27+00:00

In GIMP, you’re able to save an image as a C header file. I

  • 0

In GIMP, you’re able to save an image as a C header file. I did so with an XPM file, which looks like the image below:

If I were to save the XPM image as a C header file, GIMP will output this C header file.

In order to process each pixel of the given image data, the header pixel is called repeatedly. What I don’t understand is what the header pixel does to process the data 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 it in use in another person’s code, they stated the byte order was in the wrong order and rearranged it themselves. 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 that didn’t really help me understand what is going on with all the bit shifting and bitwise or’s and “why minus 33?” and so forth. If anyone can give an explanation on what is going on to process to the image data in the header, that would be much appreciated.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:57:28+00:00Added an answer on May 28, 2026 at 6:57 am

    Each pixel is represented by 3 bytes. These pixels are defined as a character array, named header_data.

    The problem is that not every byte is a printable character that could exist in that header file.

    This is solved by only using the printable characters 33 through 97. That gives 6 bits of information, so every four characters will give 24 bits, which can represent all permutations of 3 bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello as maybe you have heard about GIMP or something like that which uses
I'm looking for something like paint.net or Gimp, but for audio files, and runs
I have 3 layered window (like Gimp software). All my JWindow is assigned to
I'd like to trace some code in GIMP and therefore need GIMP with debug
I could like to set a pixel in GIMP, but I can't figure out
If I have an XCF file (or any other supported by Gimp) how can
I have a png image, which you can see here: http://img10.imageshack.us/img10/9145/archer5.png The background of
I would like to do a presentation like this : (done with Gimp )
I am building a Gimp plugin in python. I would like to load a
In the GIMP UI, there is an Apply Threshold functionality (GIMP 2.6) which has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.