【转】 RGB各种格式
转自:https://blog.csdn.net/LG1259156776/article/details/52006457?locationNum=10&fps=1
RGB组合格式
名字
RGB组合格式
描述
此格式用来匹配PC图形帧缓存。每个像素占据8,16,24或32个位,他们都是组合像素格式,其意为在内存中所有像素数据都是相邻排列的。当使用这些格式之一时,驱动应该上报颜色空间为V4L2_COLORSPACE_SRGB。
表2.6 组合RGB图像格式
定义 | 码 | Byte 0 | Byte 1 | Byte 2 | Byte 3 |
---|---|---|---|---|---|
V4L2_PIX_FMT_RGB332 | RGB1 | r2 r1 r0 g2 g1 g0 b1 b0 | - | - | - |
V4L2_PIX_FMT_RGB444 | R444 | g3 g2 g1 g0 b3 b2 b1 b0 | a3 a2 a1 a0 r3 r2 r1 r0 | - | - |
V4L2_PIX_FMT_RGB555 | RGBO | g2 g1 g0 b4 b3 b2 b1 b0 | a r4 r3 r2 r1 r0 g4 g3 | - | - |
V4L2_PIX_FMT_RGB565 | RGBP | g2 g1 g0 b4 b3 b2 b1 b0 | r4 r3 r2 r1 r0 g5 g4 g3 | - | - |
V4L2_PIX_FMT_RGB555X | RGBQ | a r4 r3 r2 r1 r0 g4 g3 | g2 g1 g0 b4 b3 b2 b1 b0 | - | - |
V4L2_PIX_FMT_RGB565X | RGBR | r4 r3 r2 r1 r0 g5 g4 g3 | g2 g1 g0 b4 b3 b2 b1 b0 | - | - |
V4L2_PIX_FMT_BGR666 | BGRH | b5 b4 b3 b2 b1 b0 g5 g4 | g3 g2 g1 g0 r5 r4 r3 r2 | r1 r0 | - |
V4L2_PIX_FMT_BGR24 | BGR3 | b7 b6 b5 b4 b3 b2 b1 b0 | g7 g6 g5 g4 g3 g2 g1 g0 | r7 r6 r5 r4 r3 r2 r1 r0 | - |
V4L2_PIX_FMT_RGB24 | RGB3 | r7 r6 r5 r4 r3 r2 r1 r0 | g7 g6 g5 g4 g3 g2 g1 g0 | b7 b6 b5 b4 b3 b2 b1 b0 | - |
V4L2_PIX_FMT_BGR32 | RGR4 | b7 b6 b5 b4 b3 b2 b1 b0 | g7 g6 g5 g4 g3 g2 g1 g0 | r7 r6 r5 r4 r3 r2 r1 r0 | a7 a6 a5 a4 a3 a2 a1 a0 |
V4L2_PIX_FMT_RGB32 | RGB4 | a7 a6 a5 a4 a3 a2 a1 a0 | r7 r6 r5 r4 r3 r2 r1 r0 | g7 g6 g5 g4 g3 g2 g1 g0 | b7 b6 b5 b4 b3 b2 b1 b0 |
第7位是符号位,a(alpha)的值在读取驱动时并未定义,所以编写驱动时忽略它吧,除非是在Overlay或输出Overlay时候协商了透明度,又或是在使用V4L2_CID_ALPHA_COMPONENT控制视频捕捉时候设置透明度部分。
例2.2 V4L2_PIX_FMT_BGR24 4 x 4像素图像
- start + 00: B00 G00 R00 B01 G01 R01 B02 G02 R02 B03 G03 R03
- start + 12: B10 G10 R10 B11 G11 R11 B12 G12 R12 B13 G13 R13
- start + 24: B20 G20 R20 B21 G21 R21 B22 G22 R22 B23 G23 R23
- start + 36: B30 G30 R30 B31 G31 R31 B32 G32 R32 B33 G33 R33
V4L2_PIX_FMT_SBGGR8('BA81')
名字
V4L2_PIX_FMT_SBGGR8 贝尔RGB格式
描述
这一般是数字相机的本地格式,与CCD设备的传感器阵列对应。每个像素只有一个值或是红色、绿色、蓝色,丢失的部分必须由相邻像素插值而来。第一行从左到右由蓝色和绿色组成,第二行是绿色和红色,每两行/列以此类推。
例2.3 V4L2_PIX_FMT_SBGGR8 4 x 4像素图像
- start + 0: B00 G01 B02 G03
- start + 4: G10 R11 G12 R13
- start + 8: B20 G21 B22 G23
- start +12: G30 R31 G32 R33
V4L2_PIX_FMT_SGBRG8 ('GBRG')
名字
V4L2_PIX_FMT_SGBRG8 贝尔RGB格式
描述
贝尔格式描述基本相同,只是像素排列规则不同。此格式是第一行从做到有包含绿色和蓝色,第二行是红色和绿色,每两行/列依此类推。
例2.4 V4L2_PIX_FMT_SGBRG8 4 x 4像素图像
- start + 0: G00 B01 G02 B03
- start + 4: R10 G11 R12 G13
- start + 8: G20 B21 G22 B23
- start +12: R30 G31 R32 G33
V4L2_PIX_FMT_SGRBG8 ('GRBG')
名字
V4L2_PIX_FMT_SGRBG8 贝尔RGB格式
描述
第一行从左到右包含绿色和蓝色,第二行包含红色和绿色,每两行/列依此类推。
例2.5 V4L2_PIX_FMT_SGRBG8 4 x 4像素图像
- start + 0: G00 R01 G02 R03
- start + 4: R10 B11 R12 B13
- start + 8: G20 R21 G22 R23
- start +12: R30 B31 R32 B33
V4L2_PIX_FMT_SRGGB8 ('RGGB')
名字
V4L2_PIX_FMT_SRGGB8 贝尔RGB格式
描述
第一行从左到右包含红色和绿色,第二行包含绿色和蓝色,每两行/列依此类推。
例2.6 V4L2_PIX_FMT_SRGGB8 4 x 4像素图像
- start + 0: R00 G01 R02 G03
- start + 4: G10 B11 G12 B13
- start + 8: R20 G21 R22 G23
- start +12: G30 B31 G32 B33
V4L2_PIX_FMT_SBGGR16 ('BYR2')
名字
V4L2_PIX_FMT_SBGGR16 贝尔RGB格式
描述
此格式与V4L2_PIX_FMT_SBGGR8很相似,不同是每个像素拥有16位深度。低数据存储在小地址内存中(低位机)。实际采样精度可能会比16位低,必须每个像素10位,值范围0~1023(如MT9T001)。
例2.7 V4L2_PIX_FMT_SBGGR16 4 x 4像素图像
- start + 0: B00low B00high G01low G01high B02low B02high G03low G03high
- start + 8: G10low G10high R11low R11high G12low G12high R13low R13high
- start +16: B20low B20high G21low G21high B22low B22high G23low G23high
- start +24: G30low G30high R31low R31high G32low G32high R33low R33high
V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10')
名字
V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10') 10bit贝尔格式扩展的16位格式
描述
这4个像素格式是每个颜色10位的raw sRGB/贝尔格式。每个颜色部分都存储在16位字段中,高6位是不用的,填充0。每n像素行包含n/2个绿色取样和n/2个蓝色取样或红色取样,红色和蓝色行交替。字节以低位机序列存储。他们通常是来描述如GRGR...BGBG...或RGRG...GBGB...等等。以下是其中的一个例子。
例2.8 V4L2_PIX_FMT_SBGGR10 4 x 4像素图像
- 每个代表一个字节,高字节的高6位为0
- start + 0: B00low B00high G01low G01high B02low B02high G03low G03high
- start + 8: G10low G10high R11low R11high G12low G12high R13low R13high
- start +16: B20low B20high G21low G21high B22low B22high G23low G23high
- start +24: G30low G30high R31low R31high G32low G32high R33low R33high
V4L2_PIX_FMT_SBGGR10ALAW8 ('aBA8'), V4L2_PIX_FMT_SGBRG10ALAW8 ('aGA8'), V4L2_PIX_FMT_SGRBG10ALAW8 ('agA8'), V4L2_PIX_FMT_SRGGB10ALAW8 ('aRA8')
名字
V4L2_PIX_FMT_SBGGR10ALAW8 , V4L2_PIX_FMT_SGBRG10ALAW8 , V4L2_PIX_FMT_SGRBG10ALAW8 , V4L2_PIX_FMT_SRGGB10ALAW8 10位贝尔格式压缩至8位。
描述
这些格式是每个颜色10位的raw sRGB/贝尔格式压缩到8位,使用A-LAW算法。每个颜色部分在内存中占据8位,其他与V4L2_PIX_FMT_SRGGB8特性类似。
V4L2_PIX_FMT_SBGGR10DPCM8 ('bBA8'), V4L2_PIX_FMT_SGBRG10DPCM8 ('bGA8'), V4L2_PIX_FMT_SGRBG10DPCM8 ('BD10'), V4L2_PIX_FMT_SRGGB10DPCM8 ('bRA8')
名字
V4L2_PIX_FMT_SBGGR10DPCM8, V4L2_PIX_FMT_SGBRG10DPCM8, V4L2_PIX_FMT_SGRBG10DPCM8, V4L2_PIX_FMT_SRGGB10DPCM8 10位贝尔格式压缩至8位。
描述
使用DPCM将每个颜色部分压缩至8位。DPCM调整是有损耗的,每个颜色在内存中占用8位,其他部分与V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10')类似。
V4L2_PIX_FMT_SRGGB12 ('RG12'), V4L2_PIX_FMT_SGRBG12 ('BA12'), V4L2_PIX_FMT_SGBRG12 ('GB12'), V4L2_PIX_FMT_SBGGR12 ('BG12')
名字
V4L2_PIX_FMT_SRGGB12, V4L2_PIX_FMT_SGRBG12, V4L2_PIX_FMT_SGBRG12, V4L2_PIX_FMT_SBGGR12 12位贝尔格式扩展为16位
描述
每个颜色12位的raw sRGB/贝尔格式,每个颜色部分被保存在16位的字段中,高6位为0。每个n像素行包含n/2个绿色取样及n/2个蓝色或红色取样,红、蓝行交替。字节按低位机顺序存储在内存中,通常用来描述如GEGE...BGBG...或RGRG...RBRB...等。下边是其中一个的例子。
例2.9 V4L2_PIX_FMT_SBGGR12 4 x 4像素图片
- start + 0: B00low B00high G01low G01high B02low B02high G03low G03high
- start + 8: G10low G10high R11low R11high G12low G12high R13low R13high
- start +16: B20low B20high G21low G21high B22low B22high G23low G23high
- start +24: G30low G30high R31low R31high G32low G32high R33low R33high
.........................................................................................................................
以下是根据上面的文档写的转换代码:RGGB/BGGR转RGB
- #include <fcntl.h>
- #include <getopt.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/mman.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- static void raw10_to_raw8(char *in, char *out, int width, int height)
- {
- int i,j;
- char temp;
- //RAW10 --> RAW8
- for(j = ; j < height; j++)
- {
- for(i = ; i < width * ; i = i + )
- {
- temp = ;
- temp = in[j * width * + i]; //low
- out[j * width + i / ] = temp;
- /*
- temp = 0;
- temp = in[j * width * 2 + i] >> 2; //low
- temp |= in[j * width * 2 + i + 1] << 6; //high
- out[j * width + i / 2] = temp;
- */
- }
- }
- //printf("aa0 %x %x %x %x \n", out[0], out[1], out[2], out[3]);
- //printf("aa1 %x %x %x %x \n", out[width], out[width+1], out[width+2], out[width+3]);
- }
- #if 0
- static int rggb2rgb(char *in, char *out, int width, int height)
- {
- /*
- R G1 ---> RG1B RG1B
- G2 B ---> RG2B RG2B
- */
- int i,j;
- //RGRGRG
- for(j = ; j < height; j= j + )
- {
- for(i = ; i < width * ; i = i + )
- {
- //(0,0)
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //G1
- out[(j * width * ) + (i + )] = in[((j+) * width) + (i / ) + ];//B
- //(0,1) == (0,0)
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //G1
- out[(j * width * ) + (i + )] = in[((j+) * width) + (i / ) + ];//B
- }
- }
- //GBGBGB
- for(j = ; j < height; j= j + )
- {
- for(i = ; i < width * ; i = i + )
- {
- //(1,0)
- out[(j * width * ) + (i + )] = in[((j-) * width) + (i / )]; //R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //G2
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //B
- //(1,0) == (1,1)
- out[(j * width * ) + (i + )] = in[((j-) * width) + (i / )]; //R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //G2
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //B
- }
- }
- //printf("000 %x %x %x %x \n", out[0], out[1], out[2], out[3]);
- //printf("111 %x %x %x %x \n", out[width], out[width+1], out[width+2], out[width+3]);
- return width * height * ;
- }
- #endif
- #if 1
- static int bggr2rgb(char *in, char *out, int width, int height)
- {
- /*
- B G1 ---> RG1B RG1B
- G2 R ---> RG2B RG2B
- */
- int i,j;
- //BGBGBG
- for(j = ; j < height; j= j + )
- {
- for(i = ; i < width * ; i = i + )
- {
- //(0,0)
- out[(j * width * ) + (i + )] = in[((j+) * width) + (i / ) + ];//R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //G1
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //B
- //(0,1) == (0,0)
- out[(j * width * ) + (i + )] = in[((j+) * width) + (i / ) + ];//R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //G1
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //B
- }
- }
- //GRGRGR
- for(j = ; j < height; j= j + )
- {
- for(i = ; i < width * ; i = i + )
- {
- //(1,0)
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //G2
- out[(j * width * ) + (i + )] = in[((j-) * width) + (i / )]; //B
- //(1,0) == (1,1)
- out[(j * width * ) + (i + )] = in[(j * width) + (i / ) + ]; //R
- out[(j * width * ) + (i + )] = in[(j * width) + (i / )]; //G2
- out[(j * width * ) + (i + )] = in[((j-) * width) + (i / )]; //B
- }
- }
- //printf("000 %x %x %x %x \n", out[0], out[1], out[2], out[3]);
- //printf("111 %x %x %x %x \n", out[width], out[width+1], out[width+2], out[width+3]);
- return width * height * ;
- }
- #endif
- static void usage( char * name )
- {
- printf("usage: %s\n", name);
- printf(" --input,-i input file\n");
- printf(" --output,-o output file\n");
- printf(" --width,-w image width (pixels)\n");
- printf(" --height,-v image height (pixels)\n");
- printf(" --help,-h this helpful message\n");
- }
- int main( int argc, char ** argv )
- {
- int width = ;
- int height = ;
- int size_in = ;
- int size_out = ;
- char c;
- int optidx = ;
- char *infile = NULL;
- char *outfile = NULL;
- FILE *input_fd = NULL;
- FILE *output_fd = NULL;
- char *buff_tmp = NULL;
- char *buff_in = NULL;
- char *buff_out = NULL;
- int param_num = ;
- while (param_num--)
- {
- optidx = ;
- struct option longopt[] = {
- {"input",,NULL,'i'},
- {"output",,NULL,'o'},
- {"width",,NULL,'w'},
- {"height",,NULL,'v'},
- {"help",,NULL,'h'},
- {,,,}
- };
- c = getopt_long(argc, argv, "i:o:w:v:h", longopt, &optidx);
- if (c == -)
- break;
- switch ( c )
- {
- case 'i':
- infile = strdup( optarg );
- break;
- case 'o':
- outfile = strdup( optarg );
- break;
- case 'w':
- width = strtol( optarg, NULL, );
- break;
- case 'v':
- height = strtol( optarg, NULL, );
- break;
- case 'h':
- usage(argv[]);
- return ;
- break;
- default:
- printf("lsc bad arg %c\n", c);
- usage(argv[]);
- //return 1;
- }
- }
- // arguments: infile outfile width height
- if( infile == NULL || outfile == NULL || width == || height == )
- {
- printf("Bad parameter\n");
- usage(argv[]);
- return ;
- }
- buff_tmp = calloc(width * height, sizeof(char));
- buff_in = calloc(width * height * , sizeof(char));
- buff_out = calloc(width * height * , sizeof(char));
- if(NULL == buff_tmp || NULL == buff_in || NULL == buff_out)
- {
- printf("malloc error\n");
- goto end;
- }
- input_fd = fopen(infile, "r");
- if(NULL == input_fd)
- {
- printf("Problem opening input: %s\n", infile);
- return ;
- }
- output_fd = fopen(outfile, "w");
- if(NULL == output_fd)
- {
- printf("Problem opening output: %s\n", outfile);
- return ;
- }
- //读文件
- size_in = fread(buff_in, , width * height * , input_fd);
- if(size_in != width * height * )
- {
- printf("error!! size_in != width * height 2, size_in= %d\n", size_in);
- goto end;
- }
- raw10_to_raw8(buff_in, buff_tmp, width, height);
- size_out = bggr2rgb(buff_tmp, buff_out, width, height);
- //size_out = rggb2rgb(buff_tmp, buff_out, width, height);
- //写入数据到文件
- fwrite(buff_out, , size_out, output_fd);
- end:
- if(input_fd)
- fclose(input_fd);
- if(output_fd)
- fclose(output_fd);
- if(NULL == buff_tmp)
- {
- free(buff_tmp);
- }
- if(NULL == buff_in)
- {
- free(buff_in);
- }
- if(NULL == buff_out)
- {
- free(buff_out);
- }
- return ;
- }
【转】 RGB各种格式的更多相关文章
- 【VS开发】【图像处理】RGB各种格式
RGB格式 RGB组合格式 名字 RGB组合格式 描述 此格式用来匹配PC图形帧缓存.每个像素占据8,16,24或32个位,他们都是组合像素格式,其意为在内存中所有像素数据都是相邻排列的.当使用这些格 ...
- yuv rgb 像素格式1
===========大小============= 一般,直接采集到的视频数据是RGB24的格式 RGB24一帧的大小size=width×heigth×3 Byte, RGB32的size=wid ...
- 嵌入式开发之davinci--- 8148/8168/8127 中的图像采集格式Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别
简单来说,YUV: luma (Y) + chroma (UV) 格式, 一般情况下sensor支持YUV422格式,即数据格式是按Y-U-Y-V次序输出的RGB: 传统的红绿蓝格式,比如RGB565 ...
- RAW RGB格式
RAW RGB格式 10bit Raw RGB, 就是说用10bit去表示一个R, G, 或者B, 通常的都是用8bit的. 所以你后面处理时要把它转换为8bit的, 比较简单的方法就是将低两位去掉, ...
- Sensor信号输出YUV、RGB、RAW DATA、JPEG【转】
本文转载自:http://blog.csdn.net/southcamel/article/details/8305873 简单来说,YUV: luma (Y) + chroma (UV) 格式, 一 ...
- 多媒体编程基础之RGB和YUV
一.概念 1.什么是RGB? 对一种颜色进行编码的方法统称为“颜色空间”或“色域”.用最简单的话说,世界上任何一种颜色的“颜色空间”都可定义成一个固定的数字或变量.RGB(红.绿.蓝)只是众多颜色空间 ...
- VLC 用到的那些 YUV 格式
YUV是视频应用中使用的一类像素格式.YUV实际上是所有“YUV”像素格式共有的颜色空间的名称. 与RGB格式(红 - 绿 - 蓝)相对应,YUV颜色用一个称为Y(相当于灰度)的“亮度”分量和两个“色 ...
- Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别
简单来说,YUV: luma (Y) + chroma (UV) 格式, 一般情况下sensor支持YUV422格式,即数据格式是按Y-U-Y-V次序输出的RGB: 传统的红绿蓝格式,比如RGB565 ...
- IPC网络高清摄像机基础知识4(Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别) 【转】
转自:http://blog.csdn.net/times_poem/article/details/51682785 [-] 一 概念介绍 二 两个疑问 三 RAW和JPEG的区别 1 概念说明 3 ...
随机推荐
- jq1.9.0以上版本不兼容live()解决方法
最近一个项目里用bootstrap做图形渲染,需要用到jq1.9以上版本,而copy的js代码里用到了live()方法,故两者产生了兼容问题,下面是解决方案: $('#my').on("cl ...
- InnoDB中锁的算法(3)
Ⅰ.隐式锁vs显示锁 session1: (root@localhost) [test]> show variables like 'tx_isolation'; +-------------- ...
- react中进入某个详情页URL路劲参数Id获取问题
<Route path={`${match.url}/detail/:id`} component={AppManageAddDetail} /> const { match:{param ...
- nessus无法访问https://localhost:8834/#/,解决方法。
之前没弄明白为啥经常访问不了https://localhost:8834/#/,后面才发现是服务关闭了. 首先netstat -an 查看8834是否开启, 直接运行一下nessus目录下的nessu ...
- TP框架中分页类的使用
public function test(){ $m=M('Message'); import('ORG.Util.Page');// 导入分页类 $count = $m->count();// ...
- Vuex入门(5)—— 为什么要用Action管理异步操作
Action 类似于 mutation,不同在于: 1.Action 提交的是 mutation,而不是直接变更状态. 2.Action 可以包含任意异步操作. 官方给的定义我没什么意见,事实上我通过 ...
- CentOS 7 keepalived+LVS
LVS架构中 , 不管是NAT模式还是DR模式 , 当后端的RS宕机了 , 调度器还是会把请求转发到宕掉的RS上 , 然而keepalived可以解决该问题 , 它不仅仅有高可用的功能 , 还有负载均 ...
- 玩转spring boot——war部署
前言 之前部署spring boot应用是通过直接输入命令“java -jar”来实现的.而有些情况,由于部署环境的制约,只能把项目从jar转换成war才能部署,如新浪云sae的java环境容器.那怎 ...
- Subverion仓库迁移知识点整理
目录 dump远程仓库内容到本地 可能碰到的问题 将dumpFile导入到本地仓库 可能碰到的问题 如何获取控制台信息 最近在工作上提出了一个需求,需要将各个团队的Subversion仓库进行集中管理 ...
- CentOS6.5安装与配置Mysql数据库
from:http://www.centoscn.com/mysql/2014/1211/4290.html 一.mysql简介 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle ...