linux yuv转换工具,嵌入式linux中YUV转换成RGB算法

本文介绍了如何将YUV图像格式转换为RGB,并提供了详细的算法实现。同时,还展示了将BMP图像转换为JPEG格式的过程,包括使用JPEG库进行压缩的步骤。这些内容对于图像处理和编码技术的学习者非常实用。
摘要由CSDN通过智能技术生成

在图像采集中,经常需要将YUV格式转换成RGB格式,本文例举YUV转RGB的算法

void yuvtorgb ( double *rgb,unsigned char *yuv)

{

int i;

rgb[0] = 1.0 * yuv[0] + 0 + 1.402 * (yuv[2] - 128); // r

rgb[1] = 1.0 * yuv[0] - 0.34413 * (yuv[1] - 128) - 0.71414 * (yuv[2]-128); // g

rgb[2] = 1.0 * yuv[0] + 1.772 * (yuv[1]-128) + 0; // b

for(i=0;i<3;i++)

{

if(rgb[i]>255)

rgb[i] = 255;

if(rgb[i]<0)

rgb[i] = 0;

}

}

void yuv422convertrgb(unsigned char *yuv_ptr,unsigned char *rgb_ptr,int width,int height)

{

int i,j,k;

int framesize_rgb;

doublergb[3];

unsigned char yuv[3];

unsigned char *prgb,*pyuv;

framesize_rgb = width * height * 3;

prgb = rgb_ptr;

pyuv = yuv_ptr;

prgb = rgb_ptr + framesize_rgb - width * 3;

pyuv++;

for(j=0;jBMP格式转JPEG格式

int Bmp2Jpg(const char *bmp_data, const char *jeg_file, const int width, const int height)

{

int ret;

int depth = 3;

JSAMPROW * row_pointer;

long rgb_index = 0;

int i=0;

struct jpeg_compress_struct cinfo;

struct jpeg_error_mgr jerr;

FILE *outfile;

//Convert BMP to JPG

cinfo.err = jpeg_std_error(&jerr);

//* Now we can initialize the JPEG compression object.

jpeg_create_compress(&cinfo);

if ((outfile = fopen(jeg_file, "wb")) == NULL)

{

fprintf(stderr, "can't open %s

", jeg_file);

return -1;

}

jpeg_stdio_dest(&cinfo, outfile);

cinfo.image_width = width; //* image width and height, in pixels

cinfo.image_height = height;

cinfo.input_components = depth; //* # of color components per pixel

cinfo.in_color_space = JCS_RGB; //* colorspace of input image

jpeg_set_defaults(&cinfo);

//Now you can set any non-default parameters you wish to.

//Here we just illustrate the use of quality (quantization table) scaling:

jpeg_set_quality(&cinfo, JPEG_QUALITY, TRUE ); //* limit to baseline-JPEG values

jpeg_start_compress(&cinfo, TRUE);

//一次写入

int j=0;

row_pointer = malloc(height*width*3);

char * line[1000];

for(i=0;i

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值