使用jpeg库将jpeg图像解码为yuv

在做算法的过程中经常终端传来的是jpeg图片,需要将jpeg解码为yuv再进行处理。这里使用jpeg-6b交叉编译,然后进行解码,下面是解码的过程:
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <setjmp.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <time.h>


#include <stdlib.h>
#include <string.h>

 #include "jpeglib.h"
 #include <setjmp.h>

 #include "decode.h"


struct my_error_mgr {
   
    struct jpeg_error_mgr pub;  /* "public" fields */

    jmp_buf setjmp_buffer;  /* for return to caller */
};

typedef struct my_error_mgr * my_error_ptr;

void my_decompress_error_exit (j_common_ptr cinfo)
{
   
    /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
    my_error_ptr myerr = (my_error_ptr) cinfo->err;

    /* Always display the message. */
    /* We could postpone this until after returning, if we chose. */
    (*cinfo->err->output_message) (cinfo);

    /* Return control to the setjmp point */
    longjmp(myerr->setjmp_buffer, 1);
}
int decode_jpeg_file (char *frame,int frame_size,char *decoded_frame,int *decoded_frame_size,int *decoded_width,int *decoded_height,int color_space)
{
   
			
	struct jpeg_decompress_struct cinfo;
	struct my_error_mgr jerr;
	FILE *infile, *outfile;
	JSAMPARRAY buffer;      /* Output row buffer */
	int row_stride;     /* physical row width in output buffer */

	int finished = 1;
	int chromaWidth, chromaHeight;
	int yMask,xMask;

	int x,y;
	int width,height;

	unsigned char *pixels=NULL,*rgbPixels=NULL, *src=NULL;
	unsigned char *yPixels=NULL, *uPixels=NULL, *vPixels=NULL;
	unsigned char *yPtr=NULL, *uPtr=NULL, *vPtr=NULL;

	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = my_decompress_error_exit;
	if (setjmp(jerr.setjmp_buffer)) 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值