分离RGB24像素数据中的R、G、B分量

master
dezhihuang 2017-10-18 10:52:30 +08:00
parent a571e3a1e4
commit 666067a3b6
7 changed files with 317 additions and 0 deletions

View File

@ -140,5 +140,40 @@ yuv420_split.cpp 程序中的函数可以将YUV420P数据中的Y、U、V三个
<br /> <br />
## 分离RGB24像素数据中的R、G、B分量
> 说明与YUV420P三个分量分开存储不同RGB24格式的每个像素的三个分量是连续存储的。一帧宽高分别为w、h的RGB24图像一共占用w * h * 3 Byte的存储空间。RGB24格式规定首先存储第一个像素的R、G、B然后存储第二个像素的R、G、B…以此类推。类似于YUV420P的存储方式称为Planar方式而类似于RGB24的存储方式称为Packed方式。
调用方法:
> ./rgb24_split ./mediadata/cie1931_500x500.rgb 500 500
上述代码运行后将会把一张分辨率为500x500的名称为cie1931_500x500.rgb的RGB24格式的像素数据文件分离成为三个文件
- output_r.yR数据分辨率为**500x500**。
- output_g.yG数据分辨率为**500x500**。
- output_b.yB数据分辨率为**500x500**。
输入的原图是一张标准的CIE 1931色度图。该色度图右下为红色上方为绿色左下为蓝色如下图所示
![](./images/cie1931_500x500.png)
R数据图像如图所示 ![](./images/cie1931_500x500_r.png)
G数据图像如图所示 ![](./images/cie1931_500x500_g.png)
B数据图像如图所示 ![](./images/cie1931_500x500_b.png)
<br />
<br />
参考:[视音频数据处理入门RGB、YUV像素数据处理](http://blog.csdn.net/leixiaohua1020/article/details/50534150) 参考:[视音频数据处理入门RGB、YUV像素数据处理](http://blog.csdn.net/leixiaohua1020/article/details/50534150)
![](./images/leixiaohua_avDataProcess.png) ![](./images/leixiaohua_avDataProcess.png)

BIN
images/cie1931_500x500.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

File diff suppressed because one or more lines are too long

47
rgb24_split.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int BOOL;
#define TRUE 1
#define FALSE 0
BOOL rgb24_split(const char *file, int width, int height)
{
if (file == NULL) {
return FALSE;
}
FILE *fp = fopen(file, "rb+");
FILE *fp_r = fopen("./out/output_rgb24_r.y", "wb+");
FILE *fp_g = fopen("./out/output_rgb24_g.y", "wb+");
FILE *fp_b = fopen("./out/output_rgb24_b.y", "wb+");
unsigned char *data = (unsigned char *)malloc(width*height*3);
memset(data, 0, width*height*3);
fread(data, 1, width*height*3, fp);
for(int i=0; i<width*height*3; i=i+3) {
fwrite(data+i+0, 1, 1, fp_r);
fwrite(data+i+1, 1, 1, fp_g);
fwrite(data+i+2, 1, 1, fp_b);
}
free(data);
fclose(fp);
fclose(fp_r);
fclose(fp_g);
fclose(fp_b);
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc == 4) {
rgb24_split(argv[1], atoi(argv[2]), atoi(argv[3]));
}
return 0;
}