GIMP创建的XPM映像的C头文件中的头像素说明 [英] Explanation of Header Pixel in GIMP created C Header File of an XPM image

查看:211
本文介绍了GIMP创建的XPM映像的C头文件中的头像素说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GIMP中,您可以将图像另存为C头文件.我是使用XPM文件来完成此操作的,该文件如下图所示:

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:

如果我将XPM图像另存为C头文件,则GIMP将输出此C头文件.

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

但是,这并没有真正帮助我理解所有移位和按位运算符以及为什么减33"的情况.等等.如果任何人都可以解释标题中的图像数据将要处理的内容,那将不胜感激.

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.

提前谢谢!

推荐答案

每个像素用3个字节表示.这些像素被定义为一个名为header_data的字符数组.

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

问题是,并非每个字节都是该头文件中可能存在的可打印字符.

这仅通过使用可打印字符3397来解决.这给出了6位信息,因此每四个字符将给出24位,可以表示3个字节的所有排列.

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.

这篇关于GIMP创建的XPM映像的C头文件中的头像素说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆