在做算法的过程中经常终端传来的是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;
jmp_buf setjmp_buffer;
};
typedef struct my_error_mgr * my_error_ptr;
void my_decompress_error_exit (j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr) cinfo->err;
(*cinfo->err->output_message) (cinfo);
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;
int row_stride;
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))