[libjpeg]读取一张raw图(NV12格式),利用libjpeg压缩为jpg图像,并统计耗时.

面对图像较大而带宽不足的情况,往往需要对图像进行压缩,使其变小后得以方便传输。

本文使用libjpeg(非libjpeg-turbo)实现了对图像的压缩。

1.encode_by_libjpeg.h


#include <iostream>
#include <fstream>
#include <cstring>

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

int yuv420sp_to_jpeg(const char * filename, unsigned char* pdata,int image_width,int image_height, int quality);

int read_Image_from_raw_by_iostream(const std::string filename, unsigned char **buffer);

2.encode_by_libjpeg.cpp

#include "encode_by_libjpeg.h"


int yuv420sp_to_jpeg(const char * filename,  unsigned char* pdata,int image_width,int image_height, int quality)
{   
    struct jpeg_compress_struct cinfo;  
    struct jpeg_error_mgr jerr;  
    cinfo.err = jpeg_std_error(&jerr);  
    jpeg_create_compress(&cinfo);  /*初始化*/
 
    FILE * outfile;    // target file  
    if ((outfile = fopen(filename, "wb")) == NULL) {  
        fprintf(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值