#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <string.h>
#include "linux/fb.h"
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <jpeglib.h>
#include <setjmp.h>
#define RGB(R,G,B) ((R&0xf8)<<8)|((G&0xfc)<<3)|((B&0xf8)>>3)
#include <setjmp.h>
struct my_error_mgr
{
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct my_error_mgr * my_error_ptr;
METHODDEF(void) my_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 main()
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer))
{
int a=9;
return -1;
}
jpeg_create_decompress(&cinfo);
FILE* fp=fopen("test2.jpg","r");
if(fp==NULL)
{
printf("open error\n");
return -1;
}
jpeg_stdio_src(&cinfo, fp);//指定要解压缩的图像文件
jpeg_read_header(&cinfo, TRUE); //调用jpeg_read_header()获取图像信息
cinfo.out_color_space = JCS_YCbCr;
jpeg_start_decompress(&cinfo);
int row_stride =cinfo.output_width * cinfo.output_components;
int new_row_stride = (row_stride + 3) & ~3;
int y_len = new_row_stride*cinfo.output_height;
char* y= malloc(y_len);
char* uv= malloc(y_len);
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride,1);
while(cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo,buffer, 1);//¶ÁÈ¡Ò»ÐÐ
char* src = buffer[0];
char* yDst = y + cinfo.output_scanline*288;
char* uvDst = uv + cinfo.output_scanline*288;
int i=0;
for( i = 0; i < row_stride; i+= 6)
{
*yDst++ = *src++;
*uvDst++ = *src++;
*uvDst++ = *src++;
*yDst++ = *src++;
src += 2;
}
}
jpeg_finish_decompress(&cinfo);
fclose(fp);
FILE* fp2 = fopen("test2.yuv","wb");
fwrite(y,y_len,1,fp2);
fwrite(uv,y_len,1,fp2);
fflush(fp2);
fclose(fp2);
return 0;
}
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <string.h>
#include "linux/fb.h"
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <jpeglib.h>
#include <setjmp.h>
#define RGB(R,G,B) ((R&0xf8)<<8)|((G&0xfc)<<3)|((B&0xf8)>>3)
#include <setjmp.h>
struct my_error_mgr
{
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct my_error_mgr * my_error_ptr;
METHODDEF(void) my_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 main()
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer))
{
int a=9;
return -1;
}
jpeg_create_decompress(&cinfo);
FILE* fp=fopen("test2.jpg","r");
if(fp==NULL)
{
printf("open error\n");
return -1;
}
jpeg_stdio_src(&cinfo, fp);//指定要解压缩的图像文件
jpeg_read_header(&cinfo, TRUE); //调用jpeg_read_header()获取图像信息
cinfo.out_color_space = JCS_YCbCr;
jpeg_start_decompress(&cinfo);
int row_stride =cinfo.output_width * cinfo.output_components;
int new_row_stride = (row_stride + 3) & ~3;
int y_len = new_row_stride*cinfo.output_height;
char* y= malloc(y_len);
char* uv= malloc(y_len);
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride,1);
while(cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo,buffer, 1);//¶ÁÈ¡Ò»ÐÐ
char* src = buffer[0];
char* yDst = y + cinfo.output_scanline*288;
char* uvDst = uv + cinfo.output_scanline*288;
int i=0;
for( i = 0; i < row_stride; i+= 6)
{
*yDst++ = *src++;
*uvDst++ = *src++;
*uvDst++ = *src++;
*yDst++ = *src++;
src += 2;
}
}
jpeg_finish_decompress(&cinfo);
fclose(fp);
FILE* fp2 = fopen("test2.yuv","wb");
fwrite(y,y_len,1,fp2);
fwrite(uv,y_len,1,fp2);
fflush(fp2);
fclose(fp2);
return 0;
}