一、交叉编译libjepg编译

tar xzf libjpeg-turbo-1.2.1.tar.gz

./configure –help

./configure --prefix=/work/project/first_project/13libjepg/libjpeg-turbo-1.2.1/tmp/  --host=arm-linux

make

make install

二、交叉编译jepg2rgb.c

arm-linux-gcc -o jpg2rgb jpg2rgb.c  -I /work/project/first_project/13libjepg/libjpeg-turbo-1.2.1/tmp/include/ -L /work/project/first_project/13libjepg/libjpeg-turbo-1.2.1/tmp/lib/ –ljpeg

把库考到开发板上

cp ../libjpeg-turbo-1.2.1/tmp/lib/*so* /work/nfs_root/fs_mini_mdev/lib/

编译出来的头文件应该放入:
cd /work/project/first_project/13libjepg/libjpeg-turbo-1.2.1/tmp/include

cp *  /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include  -rf

编译出来的库文件应该放入:
cd /work/project/first_project/13libjepg/libjpeg-turbo-1.2.1/tmp/lib

sudo cp * /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib -d –rf

现在不需要指定目录

arm-linux-gcc -o jpg2rgb jpg2rgb.c –ljpeg

1th输出源文件信息,及解压后信息

#include <stdio.h>
#include "jpeglib.h"
#include <setjmp.h> /*
Allocate and initialize a JPEG decompression object // 分配和初始化一个decompression结构体
Specify the source of the compressed data (eg, a file) // 指定源文件
Call jpeg_read_header() to obtain image info // 用jpeg_read_header获得jpg信息
Set parameters for decompression // 设置解压参数,比如放大、缩小
jpeg_start_decompress(...); // 启动解压:jpeg_start_decompress
while (scan lines remain to be read)
jpeg_read_scanlines(...); // 循环调用jpeg_read_scanlines
jpeg_finish_decompress(...); // jpeg_finish_decompress
Release the JPEG decompression object // 释放decompression结构体
*/ /* Uage: jpg2rgb <jpg_file>
*/ int main(int argc, char **argv)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * infile; // 分配和初始化一个decompression结构体
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo); // 指定源文件
if ((infile = fopen(argv[1], "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", argv[1]);
return -1;
}
jpeg_stdio_src(&cinfo, infile); // 用jpeg_read_header获得jpg信息
jpeg_read_header(&cinfo, TRUE);
/* 源信息 */
printf("image_width = %d\n", cinfo.image_width);
printf("image_height = %d\n", cinfo.image_height);
printf("num_components = %d\n", cinfo.num_components); // 设置解压参数,比如放大、缩小 // 启动解压:jpeg_start_decompress
jpeg_start_decompress(&cinfo); /* 输出的图像信息 */
printf("output_width = %d\n", cinfo.output_width);
printf("output_height = %d\n", cinfo.output_height);
printf("output_components = %d\n", cinfo.output_components); // 循环调用jpeg_read_scanlines一行一行的获得解压数据 jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); return 0;
}

使用LCD输出

#include <stdio.h>
#include "jpeglib.h"
#include <setjmp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <string.h> #define FB_DEVICE_NAME "/dev/fb0"
#define DBG_PRINTF printf static int g_fd; static struct fb_var_screeninfo g_tFBVar;
static struct fb_fix_screeninfo g_tFBFix;
static unsigned char *g_pucFBMem;
static unsigned int g_dwScreenSize; static unsigned int g_dwLineWidth;
static unsigned int g_dwPixelWidth; static int FBDeviceInit(void)
{
int ret; g_fd = open(FB_DEVICE_NAME, O_RDWR);
if (0 > g_fd)
{
DBG_PRINTF("can't open %s\n", FB_DEVICE_NAME);
} ret = ioctl(g_fd, FBIOGET_VSCREENINFO, &g_tFBVar);
if (ret < 0)
{
DBG_PRINTF("can't get fb's var\n");
return -1;
} ret = ioctl(g_fd, FBIOGET_FSCREENINFO, &g_tFBFix);
if (ret < 0)
{
DBG_PRINTF("can't get fb's fix\n");
return -1;
} g_dwScreenSize = g_tFBVar.xres * g_tFBVar.yres * g_tFBVar.bits_per_pixel / 8;
g_pucFBMem = (unsigned char *)mmap(NULL , g_dwScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, g_fd, 0);
if (0 > g_pucFBMem)
{
DBG_PRINTF("can't mmap\n");
return -1;
}
/*
g_tFBOpr.iXres = g_tFBVar.xres;
g_tFBOpr.iYres = g_tFBVar.yres;
g_tFBOpr.iBpp = g_tFBVar.bits_per_pixel;
*/
g_dwLineWidth = g_tFBVar.xres * g_tFBVar.bits_per_pixel / 8;
g_dwPixelWidth = g_tFBVar.bits_per_pixel / 8; return 0;
} static int FBShowPixel(int iX, int iY, unsigned int dwColor)
{
unsigned char *pucFB;
unsigned short *pwFB16bpp;
unsigned int *pdwFB32bpp;
unsigned short wColor16bpp; /* 565 */
int iRed;
int iGreen;
int iBlue; if ((iX >= g_tFBVar.xres) || (iY >= g_tFBVar.yres))
{
DBG_PRINTF("out of region\n");
return -1;
} pucFB = g_pucFBMem + g_dwLineWidth * iY + g_dwPixelWidth * iX;
pwFB16bpp = (unsigned short *)pucFB;
pdwFB32bpp = (unsigned int *)pucFB; switch (g_tFBVar.bits_per_pixel)
{
case 8:
{
*pucFB = (unsigned char)dwColor;
break;
}
case 16:
{
iRed = (dwColor >> (16+3)) & 0x1f;
iGreen = (dwColor >> (8+2)) & 0x3f;
iBlue = (dwColor >> 3) & 0x1f;
wColor16bpp = (iRed << 11) | (iGreen << 5) | iBlue;
*pwFB16bpp = wColor16bpp;
break;
}
case 32:
{
*pdwFB32bpp = dwColor;
break;
}
default :
{
DBG_PRINTF("can't support %d bpp\n", g_tFBVar.bits_per_pixel);
return -1;
}
} return 0;
} static int FBCleanScreen(unsigned int dwBackColor)
{
unsigned char *pucFB;
unsigned short *pwFB16bpp;
unsigned int *pdwFB32bpp;
unsigned short wColor16bpp; /* 565 */
int iRed;
int iGreen;
int iBlue;
int i = 0; pucFB = g_pucFBMem;
pwFB16bpp = (unsigned short *)pucFB;
pdwFB32bpp = (unsigned int *)pucFB; switch (g_tFBVar.bits_per_pixel)
{
case 8:
{
memset(g_pucFBMem, dwBackColor, g_dwScreenSize);
break;
}
case 16:
{
iRed = (dwBackColor >> (16+3)) & 0x1f;
iGreen = (dwBackColor >> (8+2)) & 0x3f;
iBlue = (dwBackColor >> 3) & 0x1f;
wColor16bpp = (iRed << 11) | (iGreen << 5) | iBlue;
while (i < g_dwScreenSize)
{
*pwFB16bpp = wColor16bpp;
pwFB16bpp++;
i += 2;
}
break;
}
case 32:
{
while (i < g_dwScreenSize)
{
*pdwFB32bpp = dwBackColor;
pdwFB32bpp++;
i += 4;
}
break;
}
default :
{
DBG_PRINTF("can't support %d bpp\n", g_tFBVar.bits_per_pixel);
return -1;
}
} return 0;
} static int FBShowline(int iXStart, int iXEnd, int iY, unsigned char *pucRGBArray)
{
int i = iXStart * 3; //每个像素占据三个字节
int iX;
unsigned int dwColor; if(iY >= g_tFBVar.yres)
return -1; if(iXStart>= g_tFBVar.xres)
return -1; if((iXEnd >= g_tFBVar.xres))
{
iXEnd = g_tFBVar.xres;
} for(iX = iXStart; iX < iXEnd; iX++)
{
/* 0xRRGGBB */
dwColor = (pucRGBArray[i] << 16 ) + (pucRGBArray[i + 1] << 8) + (pucRGBArray[i + 2] << 0);
i += 3;
FBShowPixel(iX, iY, dwColor);
}
return 0;
} /*
Allocate and initialize a JPEG decompression object // 分配和初始化一个decompression结构体
Specify the source of the compressed data (eg, a file) // 指定源文件
Call jpeg_read_header() to obtain image info // 用jpeg_read_header获得jpg信息
Set parameters for decompression // 设置解压参数,比如放大、缩小
jpeg_start_decompress(...); // 启动解压:jpeg_start_decompress
while (scan lines remain to be read)
jpeg_read_scanlines(...); // 循环调用jpeg_read_scanlines
jpeg_finish_decompress(...); // jpeg_finish_decompress
Release the JPEG decompression object // 释放decompression结构体
*/ /* Uage: jpg2rgb <jpg_file>
*/ int main(int argc, char **argv)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * infile;
int row_stride;
unsigned char *buffer; if(FBDeviceInit())
{
return -1;
}
FBCleanScreen(0); // 分配和初始化一个decompression结构体
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo); // 指定源文件
if ((infile = fopen(argv[1], "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", argv[1]);
return -1;
}
jpeg_stdio_src(&cinfo, infile); // 用jpeg_read_header获得jpg信息
jpeg_read_header(&cinfo, TRUE);
/* 源信息 */
printf("image_width = %d\n", cinfo.image_width);
printf("image_height = %d\n", cinfo.image_height);
printf("num_components = %d\n", cinfo.num_components); // 设置解压参数,比如放大、缩小
printf("enter M/N: \n");
scanf("%d/%d", &cinfo.scale_num, &cinfo.scale_denom);
printf("scale to : %d/%d\n", cinfo.scale_num, cinfo.scale_denom); // 启动解压:jpeg_start_decompress
jpeg_start_decompress(&cinfo); /* 输出的图像信息 */
printf("output_width = %d\n", cinfo.output_width);
printf("output_height = %d\n", cinfo.output_height);
printf("output_components = %d\n", cinfo.output_components); //一行的数据长度
row_stride = cinfo.output_width * cinfo.output_components;
buffer = malloc(row_stride); // 循环调用jpeg_read_scanlines一行一行的获得解压数据
while (cinfo.output_scanline < cinfo.output_height)
{
(void) jpeg_read_scanlines(&cinfo, &buffer, 1);
//写到LCD去
FBShowline(0, cinfo.output_width, cinfo.output_scanline, buffer); }
free(buffer);
jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); return 0;
}

7 libjpeg使用的更多相关文章

  1. libjpeg 编译makfile

    一.准备 首先需要下载libjpeg库,网址在这里:http://www.ijg.org/ 如果不想编译就在这下载吧:http://pan.baidu.com/s/1hqeTDre 二.编译 1. 解 ...

  2. 编译libjpeg库

    最近在写车牌识别软件,需要用到BMP转成JPG的功能,自然就想到借助libjpeg来实现 OS: win7 64位 编译器: VS2008 1. 下载源代码下载地址:http://www.ijg.or ...

  3. 嵌入式 linux 移植修改后的libjpeg 实现内存中解码

    1.修改libjpeg源码,使之实现内存解码. 修改libjpeg中读取或者输出jpeg文件的函数接口文件jdatadst.c和jdatasrc.c见下面这篇帖子. http://blog.163.c ...

  4. libjpeg 交叉编译动态库和静态库

    1.下载libjpeg库,解压之     得到了jpeg6b和libtool-2.2.4两个文件夹. 2.编译安装libtool工具.   这是配置libtool,这里需要注意:configure 参 ...

  5. linux x64下编译libjpeg,libpng,zlib

    libJpeg编译: 下载libjpeg源码:http://www.ijg.org/,下载jpegsrc.v9a.tar.gz 解压源码,命令:tar -zxvf jpegsrc.v9a,源码文件夹为 ...

  6. imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be

    imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be ...

  7. VS2010编译libjpeg

    环境:win7旗舰版 x64 VS2010 下载源代码下载地址:http://www.ijg.org/,选择windows format file 解压源代码,修改源代码中jconfig.vc为jco ...

  8. 【转】VS2013编译libjpeg库

    原文地址:http://blog.csdn.net/weixinhum/article/details/42718959 现在,很多图像处理工具和开源库都给出了图像解码的函数接口,然而有时这些接口并不 ...

  9. imod报错:error while loading shared libraries: libjpeg.so.62的解决办法

    the file libjpeg.so.62(in /usr/lib/libjpeg.so.62)belongs to the package libjpeg62so try to reinstall ...

  10. <转>libjpeg解码内存中的jpeg数据

    转自http://my.unix-center.net/~Simon_fu/?p=565 熟悉libjpeg的朋友都知道libjpeg是一个开源的库.Linux和Android都是用libjpeg来 ...

随机推荐

  1. 【Todo】OSGi学习

    经常听到.见到OSGi这个名字.那么就单开一篇文章记录一下对OSGi的学习吧. 主要是做一些概念上面的学习.暂时不打算深入实践. 主要参考:http://www.osgi.com.cn/article ...

  2. C++——类继承

    类库:类库由类声明和实现构成.类组合了数据表示和类方法,因此提供了比函数库更加完整的程序包. 类继承:从已有的类派生出新的类,派生类继承了原有类(称为基类)的特征,包括方法. 通过类继承可以完成的工作 ...

  3. iframe页面调用父窗口JS函数

    A页面iframe 页面B, 此时 如果要在B页面调用父页面A的函数 B页面写法 parent.functionName(); 错误1: 解决办法 var js_domain_async = 'bai ...

  4. Mysql中的排序规则utf8_unicode_ci、utf8_general_ci的区别总结

    Mysql中utf8_general_ci与utf8_unicode_ci有什么区别呢?在编程语言中,通常用unicode对中文字符做处理,防止出现乱码,那么在MySQL里,为什么大家都使用utf8_ ...

  5. iOS事件处理之七种手势

    手势在开发中经常用到,所以就简单通俗易懂的说下, 话不多说,直接看代码: // 初始化一个UIimageView UIImageView *imageView = [[UIImageView allo ...

  6. 【bug】“Mat map” opencv全局变量不明确

    Mat map= Mat::zeros(WIN_WIDTH, WIN_HIGH, CV_8UC3);//全局变量 int main() { map.setTo(); } Error map 不明确 s ...

  7. 资源 之 4.3 访问Resource(拾壹)

    4.3.1  ResourceLoader接口 ResourceLoader接口用于返回Resource对象:其实现可以看作是一个生产Resource的工厂类. public interface Re ...

  8. 如何使用Retrofit获取服务器返回来的JSON字符串

    有关Retrofit的简单集成攻略,大家可以参考我此前的一篇文章有关更多API文档的查阅请大家到Retrofit官网查看. 在大家使用网络请求的时候,往往会出现一种情况:需要在拿到服务器返回来的JSO ...

  9. js和jquery获取子元素

    <ul id="nav"> <li></li> <li> <ul> <li></li> < ...

  10. Github/Eclipse管理Maven项目

    Eclipse和Git插件 (To-do: 直接从workspace导入也可以,弄明白这个repo管理的本质,查看sprigmvc是如何导入的) 最新版本的Eclipse都直接集成了Git插件 Ecl ...