本地编译libjpeg库

下载

http://www.ijg.org/files/

编译

参数说明:

  • –prefix
    指定安装目录,如果不指定则默认安装在/usr/local/目录下
  • –host
    指定目标程序运行环境
  • CC
    指定编译工具链
在container中交叉编译

./configure --prefix=/data/jpeglib/jpeg-9a/build/ --host=arm-linux CC=arm-himix200-linux-gcc --disable-shared

在ubuntu上编译

./configure --prefix=/data/jpeglib/jpeg-9a/build-pc/ --disable-shared

在mac上编译

./configure --prefix=/Users/xxxx/Downloads/jpeg-9a/build/ --disable-shared

example
#include <iostream>
#include "jpeglib.h"
#include <memory.h>
using namespace std;
// outJpegFileName:输出的jpeg文件名称
// yuvData: yuv420格式的数据,其数据存储顺序为:y->u->v
// quaulity: 输出的jpeg图像质量,有效范围为0-100
int Yuv420PToJpeg(const char * outJpegFileName, unsigned char* yuvData, 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(outJpegFileName, "wb")) == NULL)
	{
		fprintf(stderr, "can't open %s\n", outJpegFileName);
		exit(1);
	}
	jpeg_stdio_dest(&cinfo, outfile);
 
	cinfo.image_width = image_width;    
	cinfo.image_height = image_height;
	cinfo.input_components = 3;    // # of color components per pixel  
	cinfo.in_color_space = JCS_YCbCr;  //colorspace of input image  
	jpeg_set_defaults(&cinfo);
	jpeg_set_quality(&cinfo, quality, TRUE);
 
	//  
	//  cinfo.raw_data_in = TRUE;  
	cinfo.jpeg_color_space = JCS_YCbCr;
	cinfo.comp_info[0].h_samp_factor = 2;
	cinfo.comp_info[0].v_samp_factor = 2;
	
 
	jpeg_start_compress(&cinfo, TRUE);
 
	JSAMPROW row_pointer[1];
 
	// 获取y、u、v三个分量各自数据的指针地址
	unsigned char *ybase, *ubase, *vbase;
	ybase = yuvData;
	ubase = yuvData + image_width*image_height;
	vbase = ubase + image_height*image_width / 4;
 
	unsigned char *yuvLine = new unsigned char[image_width * 3];
	memset(yuvLine, 0, image_width * 3);
 
	int j = 0;
	while (cinfo.next_scanline < cinfo.image_height)
	{
		int idx = 0;
		for (int i = 0; i<image_width; i++)
		{
			// 分别取y、u、v的数据
			yuvLine[idx++] = ybase[i + j * image_width];
			yuvLine[idx++] = ubase[(j>>1) * image_width/2 + (i>>1) ];
			yuvLine[idx++] = vbase[(j>>1) * image_width/2 + (i>>1) ];
		}
		row_pointer[0] = yuvLine;
		jpeg_write_scanlines(&cinfo, row_pointer, 1);
		j++;
	}
	jpeg_finish_compress(&cinfo);
	jpeg_destroy_compress(&cinfo);
	fclose(outfile);
 
	delete[]yuvLine;
	return 0;
}

int main(int argc, char* argv[])
{
    cout <<"hellp world"<<endl;
    const char* path = "/data/prj/Lift_Control_prj/Lift_Control_prj/test/raw_1920_1080.yuv";
    unsigned char* pYuv = (unsigned char*) malloc(1920 * 1080 * 1.5 * sizeof(unsigned char));
    FILE* fd_yuv = fopen(path, "r");
    if(fd_yuv)
    {
        fread(pYuv, sizeof(unsigned char), 1920 * 1080 * 1.5, fd_yuv);
    }
    fclose(fd_yuv);

    const char* jpgPath = "/data/prj/Lift_Control_prj/Lift_Control_prj/test/1.jpg";
    Yuv420PToJpeg(jpgPath, pYuv, 1920, 1080, 50);


    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值