[英]Convert C-Source image dump from RGB565 into RGB888
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 convert this image from RG565 to RGB888?有没有办法将此图像从 RG565 转换为 RGB888?
I mean, I have found a way to covert pixel by pixel:我的意思是,我找到了一种逐像素转换的方法:
for (i = 0; i < w * h; i++)
{
uint16_t color = *RGB565p++;
uint8_t r = ((color >> 11) & 0x1F);
uint8_t g = ((color >> 5) & 0x3F);
uint8_t b = (color & 0x1F);
r = ((((color >> 11) & 0x1F) * 527) + 23) >> 6;
g = ((((color >> 5) & 0x3F) * 259) + 33) >> 6;
b = (((color & 0x1F) * 527) + 23) >> 6;
uint32_t RGB888 = r << 16 | g << 8 | b;
printf("%d \n", RGB888);
}
the problem is that using this logic I get numbers that are not represented as the one used n the original image:问题是使用此逻辑我得到的数字未表示为原始图像中使用的数字:
P3
304 98
255
3223857
3223857
3223857
3223857
3223857
3223857
3223857
3223857
Did I miss something?我错过了什么?
EDIT: here you can find the original image: https://drive.google.com/file/d/1YBphg5_V6M2FA3HWcaFZT4fHqD6yeEOl/view编辑:在这里你可以找到原始图片: https://drive.google.com/file/d/1YBphg5_V6M2FA3HWcaFZT4fHqD6yeEOl/view
There are two things you need to do to create a C file similar to the original.要创建类似于原始文件的 C 文件,您需要做两件事。
The first part means simply changing the 2
to 3
, so you get:第一部分意味着简单地将2
更改为3
,所以你得到:
guint8 pixel_data[304 * 98 * 3 + 1];
} example= {
304, 98, 3,
In the second part the simplest method would be to print ALL characters in octal representation.在第二部分中,最简单的方法是以八进制表示形式打印所有字符。 (The original code has the "printable" characters visible, but the non-printable as octal escape sequences.) (原始代码具有可见的“可打印”字符,但不可打印为八进制转义序列。)
To print ALL the characters in octal representation, do similar to要以八进制表示形式打印所有字符,请执行类似于
for (i = 0; i < w * h; i++)
{
...
R, G and B calculation goes here
...
// Print start of line and string (every 16 pixels)
if (i % 16 == 0)
printf("\n\"");
printf("\\%3o\\%3o\\%3o", r, g, b);
// Print end of string and line (every 16 pixels)
if ((i+1) % 16 == 0)
printf("\"\n");
}
printf("\"\n"); // Termination of last line
This prints three bytes in octal representation \123\123\123
and after 16 pixels, prints end of string and newline.这将以八进制表示形式打印三个字节\123\123\123
并在 16 像素后打印字符串结尾和换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.