转自: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像素图像

  1.  
    start + 00: B00 G00 R00 B01 G01 R01 B02 G02 R02 B03 G03 R03
  2.  
    start + 12: B10 G10 R10 B11 G11 R11 B12 G12 R12 B13 G13 R13
  3.  
    start + 24: B20 G20 R20 B21 G21 R21 B22 G22 R22 B23 G23 R23
  4.  
    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像素图像

  1.  
    start + 0: B00 G01 B02 G03
  2.  
    start + 4: G10 R11 G12 R13
  3.  
    start + 8: B20 G21 B22 G23
  4.  
    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像素图像

  1.  
    start + 0: G00 B01 G02 B03
  2.  
    start + 4: R10 G11 R12 G13
  3.  
    start + 8: G20 B21 G22 B23
  4.  
    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像素图像

  1.  
    start + 0: G00 R01 G02 R03
  2.  
    start + 4: R10 B11 R12 B13
  3.  
    start + 8: G20 R21 G22 R23
  4.  
    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像素图像

  1.  
    start + 0: R00 G01 R02 G03
  2.  
    start + 4: G10 B11 G12 B13
  3.  
    start + 8: R20 G21 R22 G23
  4.  
    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像素图像

  1.  
    start + 0: B00low B00high G01low G01high B02low B02high G03low G03high
  2.  
    start + 8: G10low G10high R11low R11high G12low G12high R13low R13high
  3.  
    start +16: B20low B20high G21low G21high B22low B22high G23low G23high
  4.  
    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像素图像

  1.  
    每个代表一个字节,高字节的高6位为0
  2.  
    start + 0: B00low B00high G01low G01high B02low B02high G03low G03high
  3.  
    start + 8: G10low G10high R11low R11high G12low G12high R13low R13high
  4.  
    start +16: B20low B20high G21low G21high B22low B22high G23low G23high
  5.  
    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像素图片

  1.  
    start + 0: B00low B00high G01low G01high B02low B02high G03low G03high
  2.  
    start + 8: G10low G10high R11low R11high G12low G12high R13low R13high
  3.  
    start +16: B20low B20high G21low G21high B22low B22high G23low G23high
  4.  
    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各种格式的更多相关文章

  1. 【VS开发】【图像处理】RGB各种格式

    RGB格式 RGB组合格式 名字 RGB组合格式 描述 此格式用来匹配PC图形帧缓存.每个像素占据8,16,24或32个位,他们都是组合像素格式,其意为在内存中所有像素数据都是相邻排列的.当使用这些格 ...

  2. yuv rgb 像素格式1

    ===========大小============= 一般,直接采集到的视频数据是RGB24的格式 RGB24一帧的大小size=width×heigth×3 Byte, RGB32的size=wid ...

  3. 嵌入式开发之davinci--- 8148/8168/8127 中的图像采集格式Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别

    简单来说,YUV: luma (Y) + chroma (UV) 格式, 一般情况下sensor支持YUV422格式,即数据格式是按Y-U-Y-V次序输出的RGB: 传统的红绿蓝格式,比如RGB565 ...

  4. RAW RGB格式

    RAW RGB格式 10bit Raw RGB, 就是说用10bit去表示一个R, G, 或者B, 通常的都是用8bit的. 所以你后面处理时要把它转换为8bit的, 比较简单的方法就是将低两位去掉, ...

  5. Sensor信号输出YUV、RGB、RAW DATA、JPEG【转】

    本文转载自:http://blog.csdn.net/southcamel/article/details/8305873 简单来说,YUV: luma (Y) + chroma (UV) 格式, 一 ...

  6. 多媒体编程基础之RGB和YUV

    一.概念 1.什么是RGB? 对一种颜色进行编码的方法统称为“颜色空间”或“色域”.用最简单的话说,世界上任何一种颜色的“颜色空间”都可定义成一个固定的数字或变量.RGB(红.绿.蓝)只是众多颜色空间 ...

  7. VLC 用到的那些 YUV 格式

    YUV是视频应用中使用的一类像素格式.YUV实际上是所有“YUV”像素格式共有的颜色空间的名称. 与RGB格式(红 - 绿 - 蓝)相对应,YUV颜色用一个称为Y(相当于灰度)的“亮度”分量和两个“色 ...

  8. Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别

    简单来说,YUV: luma (Y) + chroma (UV) 格式, 一般情况下sensor支持YUV422格式,即数据格式是按Y-U-Y-V次序输出的RGB: 传统的红绿蓝格式,比如RGB565 ...

  9. IPC网络高清摄像机基础知识4(Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别) 【转】

    转自:http://blog.csdn.net/times_poem/article/details/51682785 [-] 一 概念介绍 二 两个疑问 三 RAW和JPEG的区别 1 概念说明 3 ...

随机推荐

  1. 安装ipa文件

    https://www.jianshu.com/p/419a35f9533a 1.通过iTunes直接拖动到左侧的侧边栏(未尝试) 2.通过Xcode点击进入Devices管理,添加ipa文件进行安装 ...

  2. vim正则表达式

    目录 一.使用正则表达式的命令[/,?, s, g] 1. 搜索命令 2. 替换命令s 3. global 命令形式 二.正则表达式的用法 表示位置的符号 表示数量的元字符 元字符一览 方括号内的特殊 ...

  3. 微信小游戏跳一跳简单手动外挂(基于adb 和 python)

    只有两个python文件,代码很简单. shell.py: #coding:utf-8 import subprocess import math import os def execute_comm ...

  4. 第一个微信小程序踩的几个小坑

    1.小程序测试调试阶段可以打开项目设置中的“开发环境不校验请求域名.TLS版本及HTTPS证书”配置,即可以和自己的服务器联调了. (需要在工具栏的设置 -> 项目设置 中配置,mac下直接co ...

  5. 使用hashlib进行登录校验

    注册登录和密码验证 用户注册时,文件中保存用户名,和密码的密文 登录时,密码与文件中的密文进行比较,如果相同就同意登录 import hashlib # 导入模块 def md5(username,p ...

  6. java EE(1)

    1.安装eclipse javaEE版本,配置好Tomcat服务器(略) 2.新建项目: Dynamic web project 3.创建服务器,并选择项目发布目录 4.添加项目: 右键服务器,选择A ...

  7. SpringBoot框架的使用

    什么是SpringBoot Spring Boot是Spring社区发布的一个开源项目,旨在帮助开发者快速并且更简单的构建项目.大多数SpringBoot项目只需要很少的配置文件. SpringBoo ...

  8. pytorch预训练模型的下载地址以及解决下载速度慢的方法

    https://github.com/pytorch/vision/tree/master/torchvision/models 几乎所有的常用预训练模型都在这里面 总结下各种模型的下载地址: 1 R ...

  9. hadoop执行 报错

    Error: java.io.IOException: Initialization of all the collectors failed. Error in last collector was ...

  10. spring boot + vue + element-ui全栈开发入门——前后端整合开发

    一.配置 思路是通过node的跨域配置来调用spring boot的rest api. 修改config\index.js文件,设置跨域配置proxyTable: proxyTable: { '/ap ...