libjpeg移植到dm368平台
来源:互联网 发布:最安全的国家知乎 编辑:程序博客网 时间:2024/06/05 06:32
库版本:
jpegsrc.v6b.tar.gz
下载地址:
http://www.ijg.org/files/jpegsrc.v6b.tar.gz
编译器版本:
arm-none-linux-gnueabi-gcc
代码成功移植到dm368平台。
第一步,libpeg移植具体操作步骤:
step1、解压库源码包
tar -xzvf jpegsrc.v6b.tar.gz
会在同目录下面生成一个jpeg-6b文件夹
step2、进入到安装目录,运行./configure命令完成必要配置
具体命令和必要参数:
./configure CC=/opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-gcc LD=/opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-gcc-ld --prefix=/home/davinci/jpeg_arm/ --exec-prefix=/home/davinci/jpeg_arm/ --enable-shared --enable-static --host=/opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi
参数介绍:
CC:代表交叉编译程序
LD:代表交叉编译链接程序
prefix:表示执行sudo make install以后头文件、库文件和帮助文档安装的目录
exec-prefix:和上一个总是一样的
enable-shared和enabled-static:表示支持静态链接和动态链接
host:一般就是去CC和LD的公共部分
执行完这条配置命令以后,完成的Makefile的配置。下面我把我自己的执行前后的Makefile贴出来对比一下:
执行之前:
# Generated automatically from makefile.cfg by configure.# Makefile for Independent JPEG Group's software# makefile.cfg is edited by configure to produce a custom Makefile.# Read installation instructions before saying "make" !!# For compiling with source and object files in different directories.srcdir = .# Where to install the programs and man pages.prefix = exec_prefix = bindir = $(exec_prefix)/binlibdir = $(exec_prefix)/libincludedir = $(prefix)/includebinprefix =manprefix =manext = 1mandir = $(prefix)/man/man$(manext)# The name of your C compiler:CC= # You may need to adjust these cc options:CFLAGS= -O2 -I$(srcdir)# Generally, we recommend defining any configuration symbols in jconfig.h,# NOT via -D switches here.# However, any special defines for ansi2knr.c may be included here:ANSI2KNRFLAGS= # Link-time cc options:LDFLAGS= # To link any special libraries, add the necessary -l commands here.LDLIBS= # If using GNU libtool, LIBTOOL references it; if not, LIBTOOL is empty.LIBTOOL = ./libtool# $(O) expands to "lo" if using libtool, plain "o" if not.# Similarly, $(A) expands to "la" or "a".O = loA = la# Library version ID; libtool uses this for the shared library version number.# Note: we suggest this match the macro of the same name in jpeglib.h.JPEG_LIB_VERSION = 62# Put here the object file name for the correct system-dependent memory# manager file. For Unix this is usually jmemnobs.o, but you may want# to use jmemansi.o or jmemname.o if you have limited swap space.SYSDEPMEM= jmemnobs.$(O)# miscellaneous OS-dependent stuffSHELL= /bin/sh# linkerLN= $(LIBTOOL) --mode=link $(CC)# file deletion commandRM= rm -f# directory creation commandMKDIR= mkdir# library (.a) file creation commandAR= ar rc# second step in .a creation (use "touch" if not needed)AR2= ranlib# installation programINSTALL= /usr/bin/install -cINSTALL_PROGRAM= $(LIBTOOL) --mode=install ${INSTALL}INSTALL_LIB= $(LIBTOOL) --mode=install ${INSTALL}INSTALL_DATA= ${INSTALL} -m 644# End of configurable options.# source files: JPEG library properLIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \ jquant2.c jutils.c jmemmgr.c# memmgr back ends: compile only one of these into a working librarySYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcomAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.cSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)# files included by source filesINCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h# documentation, test, and support filesDOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \ coderules.doc filelist.doc change.logMKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \ makvms.optCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \ jconfig.vmsCONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.shOTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asmTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \ testimgp.jpgDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)# library object files common to compression and decompressionCOMOBJECTS= jcomapi.$(O) jutils.$(O) jerror.$(O) jmemmgr.$(O) $(SYSDEPMEM)# compression library object filesCLIBOBJECTS= jcapimin.$(O) jcapistd.$(O) jctrans.$(O) jcparam.$(O) \ jdatadst.$(O) jcinit.$(O) jcmaster.$(O) jcmarker.$(O) jcmainct.$(O) \ jcprepct.$(O) jccoefct.$(O) jccolor.$(O) jcsample.$(O) jchuff.$(O) \ jcphuff.$(O) jcdctmgr.$(O) jfdctfst.$(O) jfdctflt.$(O) \ jfdctint.$(O)# decompression library object filesDLIBOBJECTS= jdapimin.$(O) jdapistd.$(O) jdtrans.$(O) jdatasrc.$(O) \ jdmaster.$(O) jdinput.$(O) jdmarker.$(O) jdhuff.$(O) jdphuff.$(O) \ jdmainct.$(O) jdcoefct.$(O) jdpostct.$(O) jddctmgr.$(O) \ jidctfst.$(O) jidctflt.$(O) jidctint.$(O) jidctred.$(O) \ jdsample.$(O) jdcolor.$(O) jquant1.$(O) jquant2.$(O) jdmerge.$(O)# These objectfiles are included in libjpeg.aLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)# object files for sample applications (excluding library files)COBJECTS= cjpeg.$(O) rdppm.$(O) rdgif.$(O) rdtarga.$(O) rdrle.$(O) \ rdbmp.$(O) rdswitch.$(O) cdjpeg.$(O)DOBJECTS= djpeg.$(O) wrppm.$(O) wrgif.$(O) wrtarga.$(O) wrrle.$(O) \ wrbmp.$(O) rdcolmap.$(O) cdjpeg.$(O)TROBJECTS= jpegtran.$(O) rdswitch.$(O) cdjpeg.$(O) transupp.$(O)all: libjpeg.$(A) cjpeg djpeg jpegtran rdjpgcom wrjpgcom# Special compilation rules to support ansi2knr and libtool..SUFFIXES: .lo .la# How to compile with libtool..c.lo: $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$*.c# How to use ansi2knr, when not using libtool.# .c.o:# ./ansi2knr $(srcdir)/$*.c knr/$*.c# $(CC) $(CFLAGS) -c knr/$*.c# $(RM) knr/$*.c# How to use ansi2knr AND libtool.# .c.lo:# ./ansi2knr $(srcdir)/$*.c knr/$*.c# $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c knr/$*.c# $(RM) knr/$*.cansi2knr: ansi2knr.c $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr $(srcdir)/ansi2knr.c $(MKDIR) knr# the library:# without libtool:libjpeg.a: $(LIBOBJECTS) $(RM) libjpeg.a $(AR) libjpeg.a $(LIBOBJECTS) $(AR2) libjpeg.a# with libtool:libjpeg.la: $(LIBOBJECTS) $(LIBTOOL) --mode=link $(CC) -o libjpeg.la $(LIBOBJECTS) \ -rpath $(libdir) -version-info $(JPEG_LIB_VERSION)# sample programs:cjpeg: $(COBJECTS) libjpeg.$(A) $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.$(A) $(LDLIBS)djpeg: $(DOBJECTS) libjpeg.$(A) $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.$(A) $(LDLIBS)jpegtran: $(TROBJECTS) libjpeg.$(A) $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.$(A) $(LDLIBS)rdjpgcom: rdjpgcom.$(O) $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.$(O) $(LDLIBS)wrjpgcom: wrjpgcom.$(O) $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.$(O) $(LDLIBS)# Installation rules:install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom install-lib $(INSTALL_PROGRAM) cjpeg $(bindir)/$(binprefix)cjpeg $(INSTALL_PROGRAM) djpeg $(bindir)/$(binprefix)djpeg $(INSTALL_PROGRAM) jpegtran $(bindir)/$(binprefix)jpegtran $(INSTALL_PROGRAM) rdjpgcom $(bindir)/$(binprefix)rdjpgcom $(INSTALL_PROGRAM) wrjpgcom $(bindir)/$(binprefix)wrjpgcominstall-lib: libjpeg.$(A) install-headers $(INSTALL_LIB) libjpeg.$(A) $(libdir)/$(binprefix)libjpeg.$(A)install-headers: jconfig.h $(INSTALL_DATA) jconfig.h $(includedir)/jconfig.h $(INSTALL_DATA) $(srcdir)/jpeglib.h $(includedir)/jpeglib.h $(INSTALL_DATA) $(srcdir)/jmorecfg.h $(includedir)/jmorecfg.h $(INSTALL_DATA) $(srcdir)/jerror.h $(includedir)/jerror.hclean: $(RM) *.o *.lo libjpeg.a libjpeg.la $(RM) cjpeg djpeg jpegtran rdjpgcom wrjpgcom $(RM) ansi2knr core testout* config.log config.status $(RM) -r knr .libs _libsdistclean: clean $(RM) Makefile jconfig.h libtool config.cachetest: cjpeg djpeg jpegtran $(RM) testout* ./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg ./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm ./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm ./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg cmp $(srcdir)/testimg.ppm testout.ppm cmp $(srcdir)/testimg.bmp testout.bmp cmp $(srcdir)/testimg.jpg testout.jpg cmp $(srcdir)/testimg.ppm testoutp.ppm cmp $(srcdir)/testimgp.jpg testoutp.jpg cmp $(srcdir)/testorig.jpg testoutt.jpgcheck: test# Mistake catcher:jconfig.h: jconfig.doc echo You must prepare a system-dependent jconfig.h file. echo Please read the installation directions in install.doc. exit 1# GNU Make likes to know which target names are not really files to be made:.PHONY: all install install-lib install-headers clean distclean test checkjcapimin.$(O): jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcapistd.$(O): jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjccoefct.$(O): jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjccolor.$(O): jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcdctmgr.$(O): jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjchuff.$(O): jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.hjcinit.$(O): jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcmainct.$(O): jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcmarker.$(O): jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcmaster.$(O): jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcomapi.$(O): jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcparam.$(O): jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcphuff.$(O): jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.hjcprepct.$(O): jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcsample.$(O): jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjctrans.$(O): jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdapimin.$(O): jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdapistd.$(O): jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdatadst.$(O): jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.hjdatasrc.$(O): jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.hjdcoefct.$(O): jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdcolor.$(O): jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjddctmgr.$(O): jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjdhuff.$(O): jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.hjdinput.$(O): jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmainct.$(O): jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmarker.$(O): jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmaster.$(O): jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmerge.$(O): jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdphuff.$(O): jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.hjdpostct.$(O): jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdsample.$(O): jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdtrans.$(O): jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjerror.$(O): jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.hjfdctflt.$(O): jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjfdctfst.$(O): jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjfdctint.$(O): jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctflt.$(O): jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctfst.$(O): jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctint.$(O): jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctred.$(O): jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjquant1.$(O): jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjquant2.$(O): jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjutils.$(O): jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjmemmgr.$(O): jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemansi.$(O): jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemname.$(O): jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemnobs.$(O): jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemdos.$(O): jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemmac.$(O): jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hcjpeg.$(O): cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.hdjpeg.$(O): djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.hjpegtran.$(O): jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.hrdjpgcom.$(O): rdjpgcom.c jinclude.h jconfig.hwrjpgcom.$(O): wrjpgcom.c jinclude.h jconfig.hcdjpeg.$(O): cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdcolmap.$(O): rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdswitch.$(O): rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.htransupp.$(O): transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.hrdppm.$(O): rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrppm.$(O): wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdgif.$(O): rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrgif.$(O): wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdtarga.$(O): rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrtarga.$(O): wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdbmp.$(O): rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrbmp.$(O): wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdrle.$(O): rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrrle.$(O): wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
执行命令之后:
# Generated automatically from makefile.cfg by configure.# Makefile for Independent JPEG Group's software# makefile.cfg is edited by configure to produce a custom Makefile.# Read installation instructions before saying "make" !!# For compiling with source and object files in different directories.srcdir = .# Where to install the programs and man pages.prefix = /home/davinci/jpeg_arm/exec_prefix = /home/davinci/jpeg_arm/bindir = $(exec_prefix)/binlibdir = $(exec_prefix)/libincludedir = $(prefix)/includebinprefix =manprefix =manext = 1mandir = $(prefix)/man/man$(manext)# The name of your C compiler:CC= /opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-gcc# You may need to adjust these cc options:CFLAGS= -O2 -I$(srcdir)# Generally, we recommend defining any configuration symbols in jconfig.h,# NOT via -D switches here.# However, any special defines for ansi2knr.c may be included here:ANSI2KNRFLAGS= # Link-time cc options:LDFLAGS= # To link any special libraries, add the necessary -l commands here.LDLIBS= # If using GNU libtool, LIBTOOL references it; if not, LIBTOOL is empty.LIBTOOL = ./libtool# $(O) expands to "lo" if using libtool, plain "o" if not.# Similarly, $(A) expands to "la" or "a".O = loA = la# Library version ID; libtool uses this for the shared library version number.# Note: we suggest this match the macro of the same name in jpeglib.h.JPEG_LIB_VERSION = 62# Put here the object file name for the correct system-dependent memory# manager file. For Unix this is usually jmemnobs.o, but you may want# to use jmemansi.o or jmemname.o if you have limited swap space.SYSDEPMEM= jmemnobs.$(O)# miscellaneous OS-dependent stuffSHELL= /bin/sh# linkerLN= $(LIBTOOL) --mode=link $(CC)# file deletion commandRM= rm -f# directory creation commandMKDIR= mkdir# library (.a) file creation commandAR= /opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-ar rc# second step in .a creation (use "touch" if not needed)AR2= /opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-ranlib# installation programINSTALL= /usr/bin/install -cINSTALL_PROGRAM= $(LIBTOOL) --mode=install ${INSTALL}INSTALL_LIB= $(LIBTOOL) --mode=install ${INSTALL}INSTALL_DATA= ${INSTALL} -m 644# End of configurable options.# source files: JPEG library properLIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \ jquant2.c jutils.c jmemmgr.c# memmgr back ends: compile only one of these into a working librarySYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcomAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.cSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)# files included by source filesINCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h# documentation, test, and support filesDOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \ coderules.doc filelist.doc change.logMKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \ makvms.optCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \ jconfig.vmsCONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.shOTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asmTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \ testimgp.jpgDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)# library object files common to compression and decompressionCOMOBJECTS= jcomapi.$(O) jutils.$(O) jerror.$(O) jmemmgr.$(O) $(SYSDEPMEM)# compression library object filesCLIBOBJECTS= jcapimin.$(O) jcapistd.$(O) jctrans.$(O) jcparam.$(O) \ jdatadst.$(O) jcinit.$(O) jcmaster.$(O) jcmarker.$(O) jcmainct.$(O) \ jcprepct.$(O) jccoefct.$(O) jccolor.$(O) jcsample.$(O) jchuff.$(O) \ jcphuff.$(O) jcdctmgr.$(O) jfdctfst.$(O) jfdctflt.$(O) \ jfdctint.$(O)# decompression library object filesDLIBOBJECTS= jdapimin.$(O) jdapistd.$(O) jdtrans.$(O) jdatasrc.$(O) \ jdmaster.$(O) jdinput.$(O) jdmarker.$(O) jdhuff.$(O) jdphuff.$(O) \ jdmainct.$(O) jdcoefct.$(O) jdpostct.$(O) jddctmgr.$(O) \ jidctfst.$(O) jidctflt.$(O) jidctint.$(O) jidctred.$(O) \ jdsample.$(O) jdcolor.$(O) jquant1.$(O) jquant2.$(O) jdmerge.$(O)# These objectfiles are included in libjpeg.aLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)# object files for sample applications (excluding library files)COBJECTS= cjpeg.$(O) rdppm.$(O) rdgif.$(O) rdtarga.$(O) rdrle.$(O) \ rdbmp.$(O) rdswitch.$(O) cdjpeg.$(O)DOBJECTS= djpeg.$(O) wrppm.$(O) wrgif.$(O) wrtarga.$(O) wrrle.$(O) \ wrbmp.$(O) rdcolmap.$(O) cdjpeg.$(O)TROBJECTS= jpegtran.$(O) rdswitch.$(O) cdjpeg.$(O) transupp.$(O)all: libjpeg.$(A) cjpeg djpeg jpegtran rdjpgcom wrjpgcom# Special compilation rules to support ansi2knr and libtool..SUFFIXES: .lo .la# How to compile with libtool..c.lo: $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$*.c# How to use ansi2knr, when not using libtool.# .c.o:# ./ansi2knr $(srcdir)/$*.c knr/$*.c# $(CC) $(CFLAGS) -c knr/$*.c# $(RM) knr/$*.c# How to use ansi2knr AND libtool.# .c.lo:# ./ansi2knr $(srcdir)/$*.c knr/$*.c# $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c knr/$*.c# $(RM) knr/$*.cansi2knr: ansi2knr.c $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr $(srcdir)/ansi2knr.c $(MKDIR) knr# the library:# without libtool:libjpeg.a: $(LIBOBJECTS) $(RM) libjpeg.a $(AR) libjpeg.a $(LIBOBJECTS) $(AR2) libjpeg.a# with libtool:libjpeg.la: $(LIBOBJECTS) $(LIBTOOL) --mode=link $(CC) -o libjpeg.la $(LIBOBJECTS) \ -rpath $(libdir) -version-info $(JPEG_LIB_VERSION)# sample programs:cjpeg: $(COBJECTS) libjpeg.$(A) $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.$(A) $(LDLIBS)djpeg: $(DOBJECTS) libjpeg.$(A) $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.$(A) $(LDLIBS)jpegtran: $(TROBJECTS) libjpeg.$(A) $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.$(A) $(LDLIBS)rdjpgcom: rdjpgcom.$(O) $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.$(O) $(LDLIBS)wrjpgcom: wrjpgcom.$(O) $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.$(O) $(LDLIBS)# Installation rules:install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom install-lib $(INSTALL_PROGRAM) cjpeg $(bindir)/$(binprefix)cjpeg $(INSTALL_PROGRAM) djpeg $(bindir)/$(binprefix)djpeg $(INSTALL_PROGRAM) jpegtran $(bindir)/$(binprefix)jpegtran $(INSTALL_PROGRAM) rdjpgcom $(bindir)/$(binprefix)rdjpgcom $(INSTALL_PROGRAM) wrjpgcom $(bindir)/$(binprefix)wrjpgcominstall-lib: libjpeg.$(A) install-headers $(INSTALL_LIB) libjpeg.$(A) $(libdir)/$(binprefix)libjpeg.$(A)install-headers: jconfig.h $(INSTALL_DATA) jconfig.h $(includedir)/jconfig.h $(INSTALL_DATA) $(srcdir)/jpeglib.h $(includedir)/jpeglib.h $(INSTALL_DATA) $(srcdir)/jmorecfg.h $(includedir)/jmorecfg.h $(INSTALL_DATA) $(srcdir)/jerror.h $(includedir)/jerror.hclean: $(RM) *.o *.lo libjpeg.a libjpeg.la $(RM) cjpeg djpeg jpegtran rdjpgcom wrjpgcom $(RM) ansi2knr core testout* config.log config.status $(RM) -r knr .libs _libsdistclean: clean $(RM) Makefile jconfig.h libtool config.cachetest: cjpeg djpeg jpegtran $(RM) testout* ./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg ./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm ./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm ./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg cmp $(srcdir)/testimg.ppm testout.ppm cmp $(srcdir)/testimg.bmp testout.bmp cmp $(srcdir)/testimg.jpg testout.jpg cmp $(srcdir)/testimg.ppm testoutp.ppm cmp $(srcdir)/testimgp.jpg testoutp.jpg cmp $(srcdir)/testorig.jpg testoutt.jpgcheck: test# Mistake catcher:jconfig.h: jconfig.doc echo You must prepare a system-dependent jconfig.h file. echo Please read the installation directions in install.doc. exit 1# GNU Make likes to know which target names are not really files to be made:.PHONY: all install install-lib install-headers clean distclean test checkjcapimin.$(O): jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcapistd.$(O): jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjccoefct.$(O): jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjccolor.$(O): jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcdctmgr.$(O): jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjchuff.$(O): jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.hjcinit.$(O): jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcmainct.$(O): jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcmarker.$(O): jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcmaster.$(O): jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcomapi.$(O): jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcparam.$(O): jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcphuff.$(O): jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.hjcprepct.$(O): jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjcsample.$(O): jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjctrans.$(O): jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdapimin.$(O): jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdapistd.$(O): jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdatadst.$(O): jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.hjdatasrc.$(O): jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.hjdcoefct.$(O): jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdcolor.$(O): jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjddctmgr.$(O): jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjdhuff.$(O): jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.hjdinput.$(O): jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmainct.$(O): jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmarker.$(O): jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmaster.$(O): jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdmerge.$(O): jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdphuff.$(O): jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.hjdpostct.$(O): jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdsample.$(O): jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjdtrans.$(O): jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjerror.$(O): jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.hjfdctflt.$(O): jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjfdctfst.$(O): jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjfdctint.$(O): jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctflt.$(O): jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctfst.$(O): jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctint.$(O): jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjidctred.$(O): jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.hjquant1.$(O): jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjquant2.$(O): jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjutils.$(O): jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.hjmemmgr.$(O): jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemansi.$(O): jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemname.$(O): jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemnobs.$(O): jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemdos.$(O): jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hjmemmac.$(O): jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.hcjpeg.$(O): cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.hdjpeg.$(O): djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.hjpegtran.$(O): jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.hrdjpgcom.$(O): rdjpgcom.c jinclude.h jconfig.hwrjpgcom.$(O): wrjpgcom.c jinclude.h jconfig.hcdjpeg.$(O): cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdcolmap.$(O): rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdswitch.$(O): rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.htransupp.$(O): transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.hrdppm.$(O): rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrppm.$(O): wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdgif.$(O): rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrgif.$(O): wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdtarga.$(O): rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrtarga.$(O): wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdbmp.$(O): rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrbmp.$(O): wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hrdrle.$(O): rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.hwrrle.$(O): wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
好好对比一下两个Makefile内容。我们会发现,编译器和安装目录设置。
step3、创建make以后安装lib和include,以及bin的文件目录
sudo mkdir /home/davinci/jpeg_armsudo mkdir /home/davinci/jpeg_arm/libsudo mkdir /home/davinci/jpeg_arm/include
step4、编译
sudo make
step5、安装
sudo make install
注意:step3必须做,否则make install安装的时候,一定会报文件找不到的错误。
第二 步:基于libjpeg完成jpg和bmp的C语言程序
首先,去看看jpeg-6b/下面的example.c文件,主要是可以了解一下libjpeg的基本用法。
注意:#include “include/jpeglib.h”这句话,我为什么这么写?是因为我的这个源码文件就在/home/davinci/jpeg_arm/目录下,其实就是执行sudo make install的安装目录。
然后,我先摆上jpg2bmp.c的源码:
#include <stdio.h>#include <setjmp.h>#include <string.h>#include <stdlib.h>#include "include/jpeglib.h"//value low 8bit write to array[offset]//value high 8bit write to array[offset +1]#define put_2b(array,offset,value) array[offset] = (char) ((value) & 0xff);\ array[offset+1] = (char) (((value) >> 8) & 0xff)#define put_4b(array,offset,value) \ (array[offset] = (char) ((value) & 0xff),\ array[offset+1] = (char) (((value) >> 8) & 0xff),\ array[offset+2] = (char) (((value) >> 16) & 0xff),\ array[offset+3] = (char) (((value) >> 24) & 0xff))//write head file void write_bmp_header(j_decompress_ptr cinfo, FILE *output_file){ char bmpfileheader[14]; char bmpinfoheader[40]; long headersize, bfsize; int bits_per_pixel, cmap_entries; struct colormap{ //the struct of color table UINT8 blue; UINT8 green; UINT8 red; UINT8 reserved; }; int step; int i=0; /* compute colormap size and total file size */ if (cinfo->out_color_space == JCS_RGB) { if (cinfo->quantize_colors) { /* colormapped rgb */ bits_per_pixel = 8; cmap_entries = 256; } else { /* unquantized, full color rgb */ bits_per_pixel = 24; cmap_entries = 0; } } else { /* grayscale output. we need to fake a 256-entry colormap. */ bits_per_pixel = 8; cmap_entries = 256; } step = cinfo->output_width * cinfo->output_components; while ((step & 3) != 0) step++; /* file size */ headersize = 14 + 40 + cmap_entries * 4; /* header and colormap */ bfsize = headersize + (long) step * (long) cinfo->output_height; /* set unused fields of header to 0 */ memset(bmpfileheader, 0, sizeof(bmpfileheader)); memset(bmpinfoheader, 0 ,sizeof(bmpinfoheader)); /* fill the file header */ bmpfileheader[0] = 0x42;/* first 2 bytes are ascii 'b', 'm' */ bmpfileheader[1] = 0x4d; put_4b(bmpfileheader, 2, bfsize); /* bfsize */ /* we leave bfreserved1 & bfreserved2 = 0 */ put_4b(bmpfileheader, 10, headersize); /* bfoffbits */ /* fill the info header (microsoft calls this a bitmapinfoheader) */ put_2b(bmpinfoheader, 0, 40); /* bisize */ put_4b(bmpinfoheader, 4, cinfo->output_width); /* biwidth */ put_4b(bmpinfoheader, 8, cinfo->output_height); /* biheight */ put_2b(bmpinfoheader, 12, 1); /* biplanes - must be 1 */ put_2b(bmpinfoheader, 14, bits_per_pixel); /* bibitcount */ /* we leave bicompression = 0, for none */ /* we leave bisizeimage = 0; this is correct for uncompressed data */ if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */ put_4b(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* xpels/m */ put_4b(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* xpels/m */ } put_2b(bmpinfoheader, 32, cmap_entries); /* biclrused */ /* we leave biclrimportant = 0 */ //write file head if (fwrite(bmpfileheader, 1, 14, output_file) != (size_t) 14) { printf("write bmpfileheader error\n"); } //write info head if (fwrite(bmpinfoheader, 1, 40, output_file) != (size_t) 40) { printf("write bmpinfoheader error\n"); } //write color table or gray table if (cmap_entries ==256) { struct colormap rgb[256]; for(i=0;i<256;i++) { rgb[i].blue=i; rgb[i].green=i; rgb[i].red=i; rgb[i].reserved=0; } //write color table if (fwrite(rgb, 1, sizeof(struct colormap)*256, output_file) <0) { printf("write color error\n"); } }}//write bitmap data void write_pixel_data(j_decompress_ptr cinfo, unsigned char *output_buffer, FILE *output_file){ int rows, cols; int row_width; int step; unsigned char *tmp = NULL; unsigned char *pdata; row_width = cinfo->output_width * cinfo->output_components; step = row_width; while ((step & 3) != 0) step++; pdata = (unsigned char *)malloc(step); memset(pdata, 0, step); //we need to change the order while change line //bgr in the window, but rgb in the libjpeg tmp = output_buffer + row_width * (cinfo->output_height - 1); if(cinfo->output_components==3){ //24bit real color piture for (rows = 0; rows < cinfo->output_height; rows++) { for (cols = 0; cols < row_width; cols += 3) { pdata[cols + 2] = tmp[cols + 0]; pdata[cols + 1] = tmp[cols + 1]; pdata[cols + 0] = tmp[cols + 2]; } tmp -= row_width; fwrite(pdata, 1, step, output_file); } } else //cinfo->output_components==1,8bit gray picture { for (rows = 0; rows < cinfo->output_height; rows++) { for (cols = 0; cols < row_width; cols ++) { pdata[cols] = tmp[cols]; } tmp -= row_width; fwrite(pdata, 1, step, output_file); } } free(pdata);}//refer to example.c int read_jpeg_file(const char *input_filename, const char *output_filename){ struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE *input_file; FILE *output_file; JSAMPARRAY buffer; int row_width; unsigned char *output_buffer; unsigned char *tmp = NULL; cinfo.err = jpeg_std_error(&jerr); if ((input_file = fopen(input_filename, "rb")) == NULL) { fprintf(stderr, "can't open %s\n", input_filename); return -1; } if ((output_file = fopen(output_filename, "wb")) == NULL) { fprintf(stderr, "can't open %s\n", output_filename); return -1; } jpeg_create_decompress(&cinfo); /* specify data source for decompression */ jpeg_stdio_src(&cinfo, input_file); /* read file header, set default decompression parameters */ (void) jpeg_read_header(&cinfo, TRUE); /* start decompressor */ (void) jpeg_start_decompress(&cinfo); row_width = cinfo.output_width * cinfo.output_components; buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_width, 1); //write bmp file head write_bmp_header(&cinfo, output_file); //alloc bmp buffer output_buffer = (unsigned char *)malloc(row_width * cinfo.output_height); memset(output_buffer, 0, row_width * cinfo.output_height); tmp = output_buffer; /* process data */ while (cinfo.output_scanline < cinfo.output_height) { (void) jpeg_read_scanlines(&cinfo, buffer, 1); memcpy(tmp, *buffer, row_width); tmp += row_width; } //write bmp data write_pixel_data(&cinfo, output_buffer, output_file); free(output_buffer); (void) jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); /* close files, if we opened them */ fclose(input_file); fclose(output_file); return 0;}int main(int argc, char *argv[]){ if (argc < 3) { //read_jpeg_file("tt.jpg", "tt.bmp"); printf("use:appname inputfile outputfile!\n"); } else { read_jpeg_file(argv[1], argv[2]); } return 0;}
接着就是完成源码文件的编译:以我自己的为例子,
/opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-gcc -L /home/davinci/jpeg_arm/lib -o jpg2bmp jpg2bmp.c -ljpeg
执行成功以后,将jpg2bmp二进制文件移动到dm368的板上linux系统。使用:
./jpg2bmp test.jpg test.bmp
执行成功以后,就会在同目录下面生成一个test.bmp文件。
使用:
du -sh test.bmp
查看一下文件大小,我们会发现文件大小大概会从76k变成2.6M。
最后,摆上bmp2jpg.c源码文件:
同样要注意,#include “include/jpeglib.h”,依然是同目录的。
#include <stdio.h>#include <setjmp.h>#include <string.h>#include <stdlib.h>#include "include/jpeglib.h"FILE *bmpfile;//input fileint image_width,image_height,image_size,bits_per_pixel,headersize,depth;unsigned char *src_data;//bitmap data int get_2b(unsigned char*a,int offset){ return a[offset+1]<<8|a[offset];}int get_4b(unsigned char*a,int offset){ return (a[offset+3]<<24)|(a[offset+2]<<16)|(a[offset+1]<<8)|a[offset];}//read bitmap head and datavoid read_bmp_header(char *bmpfilename){ unsigned char bmpfileheader[14];//file head unsigned char bmpinfoheader[40];//info head bmpfile=fopen(bmpfilename,"r");// if(bmpfile<0) printf("open bmp file error!\n"); printf("open bmp file success!\n"); //read the bmp file head fread(bmpfileheader,14,1,bmpfile); int type=get_2b(bmpfileheader,0); printf("type=0x%x\n",type); int filesize=get_4b(bmpfileheader,2); printf("filesize=%d bytes\n",filesize); headersize=get_4b(bmpfileheader,10); printf("headersize=%d bytes\n",headersize); if(headersize>54) printf("colormap size=%d bytes\n",headersize-54); //read the bmp info head fseek(bmpfile,14,SEEK_SET); fread(bmpinfoheader,40,1,bmpfile); image_width=get_4b(bmpinfoheader,4); /*the width must be %4 ==0, otherwise the picture is unnormal */ while (image_width%4!=0) image_width++; printf("weight=%d\n",image_width); image_height=get_4b(bmpinfoheader,8); printf("height=%d\n",image_height); bits_per_pixel=get_2b(bmpinfoheader,14); printf("bits_per_pixel=%d\n",bits_per_pixel); depth=bits_per_pixel/8; image_size=image_width*image_height*depth; src_data=(unsigned char *)malloc(image_size); fseek(bmpfile,headersize,SEEK_SET); fread(src_data,sizeof(unsigned char)*image_size,1,bmpfile); fclose(bmpfile);}//refer to example.cvoid write_jpeg_file (char * outfilename, unsigned char * buffer,int quality){ struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE * outfile; unsigned char *dst_data; int i,j; //char *point; JSAMPROW row_pointer[1]; //js amparray buffer; int row_stride; cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); //open output jpg file if ((outfile = fopen(outfilename, "w+")) == NULL) { fprintf(stderr, "can't open %s\n", outfilename); exit(1); } jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width = image_width; /* image width and height, in pixels */ cinfo.image_height = image_height; cinfo.input_components = depth; /* # of color components per pixel */ cinfo.in_color_space = (depth==3) ? JCS_RGB : JCS_GRAYSCALE; /* colorspace of input image */ jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-jpeg values */); dst_data=(unsigned char *)malloc(image_size*sizeof(unsigned char)); //modify the order rgb: bgr->rgb for(i=0;i<image_height;i++){ for(j=0;j<image_width;j++) { if(depth==1)//gray picture *(dst_data+i*image_width+j)=*(src_data+i*image_width+j); else //real color picture { *(dst_data+i*image_width*depth+j*3+0)=*(src_data+i*image_width*depth+j*3+2); *(dst_data+i*image_width*depth+j*3+1)=*(src_data+i*image_width*depth+j*3+1); *(dst_data+i*image_width*depth+j*3+2)=*(src_data+i*image_width*depth+j*3+0); } } } jpeg_start_compress(&cinfo, TRUE); row_stride = image_width * cinfo.input_components; /* js amples per row in image_buffer */ while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = & dst_data[(cinfo.image_height - cinfo.next_scanline - 1) * row_stride];//cinfo.next_scanline * row_stride (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); fclose(outfile); jpeg_destroy_compress(&cinfo); free(src_data); free(dst_data);}int main(int argc,char *argv[]){ if(argc<4) printf("use:appname inputname outputname quality\n"); else { read_bmp_header(argv[1]); write_jpeg_file(argv[2],src_data,atoi(argv[3])); } return 0;}
使用如下命令完成编译:
/opt/codesourcery/arm-2009q1/bin/arm-none-linux-gnueabi-gcc -L /home/davinci/jpeg_arm/lib -o bmp2jpg.c bmp2jpg.c -ljpeg
还是像jpg2bmp一样,移动到dm368的板上linux系统。使用:
./bmp2jpg test.bmp test.jpg 75
解释一下,75,代表bmp转成jpg的压缩图像质量,有效值是5-95之间。值越大,压缩后的jpg图片质量越好,但是文件尺寸也越大。
最后,解释一下编译的
“-L /home/davinci/jpeg_arm/lib”指定编译的库目录
“-ljpeg”是怎么得来的?去看看/home/davinci/jpeg_arm/lib目录下面有什么文件,我们确实是指定了库的目录,但是并不是所有的库我们都需要的,所以我们要确切的指定。那么指定的规则是什么?首先,在lib目录下有这么几个文件:libjpeg.la、libjpeg.so、libjpeg.so.62、libjpeg.so.62.0.0一共4个文件。去掉前缀lib和后缀就只剩下jpeg,然而具体指定需要使用-l(小写L),最后综合一下就是 -ljpeg
到现在为止,libjpeg移植和应用完成。
最后,在说一句。基本上所有的linux嵌入式移植都是这个流程。
- libjpeg移植到dm368平台
- libjpeg移植到arm
- libjpeg移植到arm
- 移植ubifs到dm368成功 .
- 移植ubifs到dm368成功
- 移植ubifs到dm368成功
- libjpeg移植到RT5350 mips
- 移植开源项目libjpeg到VS2008平台,使用VS2008 IDE直接编译libjpeg,针对windows mobile 6.5.3 / wince 6.0平台做项目开发
- 移植libjpeg
- libjpeg移植
- libjpeg移植
- libjpeg移植
- libjpeg移植
- 移植Open SSH到DM368 IPNC中 linux arm ssh
- 移植gdb到DM368 IPNC中 linux arm gdb
- 移植gdb到DM368 IPNC中 linux arm gdb
- 移植gdb到DM368 IPNC中 linux arm gdb
- 移植gdb到DM368 IPNC中 linux arm gdb
- 【JS】事件冒泡&事件捕获
- PHP安装扩展
- 前后台数据交互——ajax()方法 后台返回一个实体类的list
- iOS 工作之余小总结之(六)(3) --四种界面反向传值的方式:委托代理传值
- Docker学习+基于Docker MySQL的主从复制
- libjpeg移植到dm368平台
- TortoiseGit 记住用户名和密码的方法
- tomact配置域名和端口直接访问网站
- Aerospike数据库实战(一) -- Aerospike是大数据时代互联网广告专用数据库,为RTB而生
- Android圆形图片控件CircleImageView的使用
- Java基础——Comparable和Comparator的区别
- SpringBoot项目实战--mybatis
- DVWA - XSS (Stored) (low, medium, high)
- IIC总线时序