Created
February 6, 2017 20:55
-
-
Save svenk/a56a468ec25ddd187b8463f97fd118ee to your computer and use it in GitHub Desktop.
Convert a GIMP exported Header file back to a PNM Image which can be viewed with any program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "The-GIMP-exported-file.h" | |
#include <stdio.h> | |
/* This code converts a GIMP C export back to a readable PNM Image. Such | |
header file looks like | |
static const struct { | |
unsigned int width; | |
unsigned int height; | |
unsigned int bytes_per_pixel; // 2:RGB16, 3:RGB, 4:RGBA | |
unsigned char pixel_data[1252 * 695 * 3 + 1]; | |
} Image = { | |
1252, 695, 3, | |
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" | |
... | |
SvenK 2017 Public Domain | |
*/ | |
int main(int argc, char** argv) { | |
printf("P3\n"); | |
printf("%d %d\n", Image.width, Image.height); | |
for(int x=0; x<1252 * 695 * 3; x++) { | |
printf("%d ", Image.pixel_data[x]); | |
} | |
} |
I guess your problem is because your image is RGBA but my code was only tested for RGB images.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I'm trying to use this code to get the original Image , I used different RGBA files as input with no luck, for example this: https://github.com/dnrl/UE4/blob/ad355f1b341437dbf04c5c4c2102466b5f8d871e/Engine/Source/ThirdParty/SDL2/SDL-gui-backend/src/test/SDL_test_imageFace.c
int main(int argc, char** argv) {
printf("P4\n");
printf("%d %d\n", Image.width, Image.height);
for(int x=0; x<25 * 38 * 4; x++) {
printf("%d ", Image.pixel_data[x]);
}
}
it results in this image:
Any suggestions?