简体   繁体   中英

Convert C-Source image dump into original image

I have created with GIMP a C-Source image dump like the following:

/* GIMP RGBA C-Source image dump (example.c) */

static const struct {
  guint      width;
  guint      height;
  guint      bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ 
  guint8     pixel_data[304 * 98 * 2 + 1];
} example= {
  304, 98, 2,
  "\206\061\206\061..... }

Is there a way to read this in GIMP again in order to get back the original image? because it doesn't seem possible. Or does it exist a tool that can do this back-conversion?

The easiest way to get your image back would be... to let ImageMagick do it.

So, take your C file and add a main() to it that simply writes the 304x98x2 bytes starting at &(example.pixel_data) to stdout:

Compile it with something like:

clang example.c -o program    # or with GCC
gcc example.c -o program

Then run it, writing to a file for ImageMagick with:

./program > image.bin

And tell ImageMagick its size, type and where it is and what you want as a result:

magick -size 304x98 RGB565:image.bin result.png

I haven't got a C compiler for the moment and haven't written any C for 4-5 years, but it will look something like:

#include <stdio.h>

/* tell compiler what those GIMP types are */
typedef guint int;
typedef guint8 uint8_t;

<PASTE YOUR GIMP FILE HERE>

int main(){
    write(1, &(example.pixel_data), sizeof(example.pixel_data));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM