简体   繁体   English

将 C 源图像转储转换为原始图像

[英]Convert C-Source image dump into original image

I have created with GIMP a C-Source image dump like the following:我用 GIMP 创建了一个 C 源图像转储,如下所示:

/* 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?有没有办法在 GIMP 中再次读取它以取回原始图像? 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.恢复图像的最简单方法是......让ImageMagick来做。

So, take your C file and add a main() to it that simply writes the 304x98x2 bytes starting at &(example.pixel_data) to stdout:因此,获取您的 C 文件并向其中添加一个main() ,它只需将 304x98x2 字节从 &(example.pixel_data) 开始写入标准输出:

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:然后运行它,写入ImageMagick的文件:

./program > image.bin

And tell ImageMagick its size, type and where it is and what you want as a result:并告诉ImageMagick它的大小、类型、它的位置以及你想要的结果:

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:我目前还没有 C 编译器,并且已经有 4-5 年没有编写任何 C 了,但它看起来像:

#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));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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