【转】 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 ...
随机推荐
- Codeforces 1136 - A/B/C/D/E - (Done)
链接:https://codeforces.com/contest/1136/ A - Nastya Is Reading a Book - [二分] #include<bits/stdc++. ...
- python摸爬滚打之day19----类的约束, 异常处理
1.类的约束 父类对子类某些功能的约束. python 中的两种约束: 1, 提取父类, 然后在父类中定义好方法, 该方法什么都不用干, 就通过主动抛出异常 raise NotImplementedE ...
- IntelliJ IDEA 下的svn配置及使用
首先,使用的时候,自己得先在电脑上安装个小乌龟.也就是svn啦. 第一步安装小乌龟. 如下: 具体安装好像没什么具体要求,一路next,就好. 如上图箭头所示,在安装 TortoiseSVN 的时候, ...
- JMeter学习-041-响应数据中文乱码解决方法
华夏子孙,中文为母语.因而在接口测试过程中,响应数据含有中文是再也正常不过的事情.同时,初学JMeter的童鞋,经常会遇到响应数据中中文乱码的问题. 本文中提供两种方式的修正方法,仅供大家参考,谢谢. ...
- DOS的重定向命令及在安全方面的应用
dos的重定向命令 2006-10-15 16:47 新手DOS应用技巧人小鬼大 重定向命令在安全方面的应用来源:ChinaITLab收集整理2005-7-21 11:12:00 大家知道,DOS下有 ...
- Spring中bean标签的属性和值:
Spring中bean标签的属性和值: <bean name="user" class="com.pojo.User" init-method=" ...
- TCP、UDP以及HTTP的简单讲解
先来一个讲TCP.UDP和HTTP关系的 1.TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层.在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议.在传输层中有T ...
- easy ui datatimebox databox 当前时间
databox 当前日期: class="easyui-datebox" var curr_time = new Date(); var strDate = curr_time. ...
- DRF之认证组件源码解析
认证组件 认证的几种方法:cookie,session,token几种.但是session会使服务器的压力增大,所以我们经常使用的是token.获取唯一的随机字符串: 登陆携带token值的处理: ...
- liunx 常用命令学习笔记
通过linux 命令pwd:显示当前所在的目录ls:显示当前目录下的文件cd:切换路径 cd..返回上一级路径mkdir:新建目录rmdir:删除目录 touch:新建文件rm:删除文件 gedit: ...