libjpeg移植到dm368平台

库版本:
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)/bin
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
binprefix =
manprefix =
manext = 1
mandir = $(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 = lo
A = 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 stuff
SHELL= /bin/sh
# linker
LN= $(LIBTOOL) --mode=link $(CC)
# file deletion command
RM= rm -f
# directory creation command
MKDIR= mkdir
# library (.a) file creation command
AR= ar rc
# second step in .a creation (use "touch" if not needed)
AR2= ranlib
# installation program
INSTALL= /usr/bin/install -c
INSTALL_PROGRAM= $(LIBTOOL) --mode=install ${INSTALL}
INSTALL_LIB= $(LIBTOOL) --mode=install ${INSTALL}
INSTALL_DATA= ${INSTALL} -m 644

# End of configurable options.


# source files: JPEG library proper
LIBSOURCES= 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 library
SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
APPSOURCES= 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.c
SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
# files included by source files
INCLUDES= 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 files
DOCS= 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.log
MKFILES= 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.opt
CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
        jconfig.vms
CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
        testimgp.jpg
DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
# library object files common to compression and decompression
COMOBJECTS= jcomapi.$(O) jutils.$(O) jerror.$(O) jmemmgr.$(O) $(SYSDEPMEM)
# compression library object files
CLIBOBJECTS= 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 files
DLIBOBJECTS= 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.a
LIBOBJECTS= $(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/$*.c

ansi2knr: 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)wrjpgcom

install-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.h

clean:
    $(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 _libs

distclean: clean
    $(RM) Makefile jconfig.h libtool config.cache

test: 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.jpg

check: 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 check


jcapimin.$(O): jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcapistd.$(O): jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jccoefct.$(O): jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jccolor.$(O): jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcdctmgr.$(O): jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jchuff.$(O): jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
jcinit.$(O): jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcmainct.$(O): jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcmarker.$(O): jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcmaster.$(O): jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcomapi.$(O): jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcparam.$(O): jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcphuff.$(O): jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
jcprepct.$(O): jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcsample.$(O): jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jctrans.$(O): jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdapimin.$(O): jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdapistd.$(O): jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdatadst.$(O): jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
jdatasrc.$(O): jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
jdcoefct.$(O): jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdcolor.$(O): jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jddctmgr.$(O): jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jdhuff.$(O): jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
jdinput.$(O): jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmainct.$(O): jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmarker.$(O): jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmaster.$(O): jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmerge.$(O): jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdphuff.$(O): jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
jdpostct.$(O): jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdsample.$(O): jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdtrans.$(O): jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jerror.$(O): jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
jfdctflt.$(O): jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jfdctfst.$(O): jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jfdctint.$(O): jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctflt.$(O): jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctfst.$(O): jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctint.$(O): jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctred.$(O): jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jquant1.$(O): jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jquant2.$(O): jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jutils.$(O): jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jmemmgr.$(O): jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemansi.$(O): jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemname.$(O): jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemnobs.$(O): jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemdos.$(O): jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemmac.$(O): jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
cjpeg.$(O): cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
djpeg.$(O): djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
jpegtran.$(O): jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
rdjpgcom.$(O): rdjpgcom.c jinclude.h jconfig.h
wrjpgcom.$(O): wrjpgcom.c jinclude.h jconfig.h
cdjpeg.$(O): cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdcolmap.$(O): rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdswitch.$(O): rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
transupp.$(O): transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
rdppm.$(O): rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrppm.$(O): wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdgif.$(O): rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrgif.$(O): wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdtarga.$(O): rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrtarga.$(O): wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdbmp.$(O): rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrbmp.$(O): wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdrle.$(O): rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrrle.$(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)/bin
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
binprefix =
manprefix =
manext = 1
mandir = $(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 = lo
A = 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 stuff
SHELL= /bin/sh
# linker
LN= $(LIBTOOL) --mode=link $(CC)
# file deletion command
RM= rm -f
# directory creation command
MKDIR= mkdir
# library (.a) file creation command
AR= /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 program
INSTALL= /usr/bin/install -c
INSTALL_PROGRAM= $(LIBTOOL) --mode=install ${INSTALL}
INSTALL_LIB= $(LIBTOOL) --mode=install ${INSTALL}
INSTALL_DATA= ${INSTALL} -m 644

# End of configurable options.


# source files: JPEG library proper
LIBSOURCES= 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 library
SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
APPSOURCES= 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.c
SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
# files included by source files
INCLUDES= 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 files
DOCS= 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.log
MKFILES= 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.opt
CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
        jconfig.vms
CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
        testimgp.jpg
DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
# library object files common to compression and decompression
COMOBJECTS= jcomapi.$(O) jutils.$(O) jerror.$(O) jmemmgr.$(O) $(SYSDEPMEM)
# compression library object files
CLIBOBJECTS= 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 files
DLIBOBJECTS= 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.a
LIBOBJECTS= $(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/$*.c

ansi2knr: 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)wrjpgcom

install-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.h

clean:
    $(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 _libs

distclean: clean
    $(RM) Makefile jconfig.h libtool config.cache

test: 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.jpg

check: 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 check


jcapimin.$(O): jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcapistd.$(O): jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jccoefct.$(O): jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jccolor.$(O): jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcdctmgr.$(O): jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jchuff.$(O): jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
jcinit.$(O): jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcmainct.$(O): jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcmarker.$(O): jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcmaster.$(O): jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcomapi.$(O): jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcparam.$(O): jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcphuff.$(O): jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
jcprepct.$(O): jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jcsample.$(O): jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jctrans.$(O): jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdapimin.$(O): jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdapistd.$(O): jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdatadst.$(O): jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
jdatasrc.$(O): jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
jdcoefct.$(O): jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdcolor.$(O): jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jddctmgr.$(O): jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jdhuff.$(O): jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
jdinput.$(O): jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmainct.$(O): jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmarker.$(O): jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmaster.$(O): jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdmerge.$(O): jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdphuff.$(O): jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
jdpostct.$(O): jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdsample.$(O): jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jdtrans.$(O): jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jerror.$(O): jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
jfdctflt.$(O): jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jfdctfst.$(O): jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jfdctint.$(O): jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctflt.$(O): jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctfst.$(O): jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctint.$(O): jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jidctred.$(O): jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
jquant1.$(O): jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jquant2.$(O): jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jutils.$(O): jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
jmemmgr.$(O): jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemansi.$(O): jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemname.$(O): jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemnobs.$(O): jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemdos.$(O): jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
jmemmac.$(O): jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
cjpeg.$(O): cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
djpeg.$(O): djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
jpegtran.$(O): jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
rdjpgcom.$(O): rdjpgcom.c jinclude.h jconfig.h
wrjpgcom.$(O): wrjpgcom.c jinclude.h jconfig.h
cdjpeg.$(O): cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdcolmap.$(O): rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdswitch.$(O): rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
transupp.$(O): transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
rdppm.$(O): rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrppm.$(O): wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdgif.$(O): rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrgif.$(O): wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdtarga.$(O): rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrtarga.$(O): wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdbmp.$(O): rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrbmp.$(O): wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
rdrle.$(O): rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
wrrle.$(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_arm
sudo mkdir /home/davinci/jpeg_arm/lib
sudo 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 file
int 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 data
void 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.c
void 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嵌入式移植都是这个流程。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值