jpeg->yuv420sp

#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值