暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

使用libjpeg

ta是一个搬运工 2021-08-03
1325

1 说明

libjpeg可用来转换图片格式,比如BMP转JPEG、JPEG转PGM等。用于UNIX-like系统。

可以从官网下载最新的版本,也可以在百度网盘下载源码包和测试文件。

链接:https://pan.baidu.com/s/1LYt542WqChuXFJzlB9qJXQ

提取码:2ufb


2 PC linuxUbuntu 1604 server)使用libjpeg

2.1 移植

    tar xzf jpegsrc.v9c.tar.gz
    cd jpeg-9c/
    ./configure
    复制

    make,生成cjpeg(用来生成JPEG格式文件)、djpeg(用来解压JPEG格式文件)、jpegtran(用来旋转、缩放JPEG图片等)等可执行程序。

    2.2 使用命令行

    网盘压缩包testPIC1_Ubuntu.rar里面有BMPJPEG图片用于测试。

    ./djpeg -bmp -outfile test1_.bmp test1.jpg,将test1.jpg解压并保存到test1_.bmp

    ./djpeg -grayscale -outfile test1_.pgm test1.jpg,将test1.jpg解压并保存到test1_.pgm

    ./cjpeg -rgb -outfile test1_.jpg test1.bmp,将test1.bmp压缩并保存到test1_.jpg

    ./jpegtran -rotate 90 -outfile test1_1.jpg test1_.jpg,将test1_.jpg旋转90度并保存到test1_1.jpg

    2.3 使用api

    查看安装包的Makefile,可以看到所以编译源文件、可执行程序依赖的源文件等。

    需要将${LIBSOURCES}的所有源文件编译成库文件(libjpeg.a

    ar crsv libjpeg.a jaricom.o jcapimin.o jcapistd.o jcarith.o jccoefct.o jccolor.o jcdctmgr.o jchuff.o jcinit.o jcmainct.o jcmarker.o jcmaster.o jcomapi.o jcparam.o jcprepct.o jcsample.o jctrans.o jdapimin.o jdapistd.o jdarith.o jdatadst.o jdatasrc.o jdcoefct.o jdcolor.o jddctmgr.o jdhuff.o jdinput.o jdmainct.o jdmarker.o jdmaster.o jdmerge.o jdpostct.o jdsample.o jdtrans.o jerror.o jfdctflt.o jfdctfst.o jfdctint.o jidctflt.o jidctfst.o jidctint.o jquant1.o jquant2.o jutils.o jmemmgr.o jmemnobs.o

    在使用api时,以djpeg为例,只需将${djpeg_SOURCES}的源文件以源代码的形式编译到可执行程序中,需要注意的是要将djpeg.cmain函数适当修改和包含相关头文件。网盘中test1_Ubuntu.rar包含测试用的文件。

      gcc main.c djpeg.c wrppm.c wrgif.c wrtarga.c wrrle.c wrbmp.c rdcolmap.c cdjpeg.c libjpeg.a -o test
      root@ubuntu:/home/lijun/USE_libjpeg/test1# valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./test
      ==5180== Memcheck, a memory error detector
      ==5180== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
      ==5180== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
      ==5180== Command: ./test
      ==5180==
      main.c 29, ret=0
      ==5180==
      ==5180== HEAP SUMMARY:
      ==5180== in use at exit: 0 bytes in 0 blocks
      ==5180== total heap usage: 21 allocs, 21 frees, 154,984 bytes allocated
      ==5180==
      ==5180== All heap blocks were freed -- no leaks are possible
      ==5180==
      ==5180== For lists of detected and suppressed errors, rerun with: -s
      ==5180== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
      复制

      同理,使用cjpeg时,只需将${cjpeg_SOURCES}的源文件以源代码的形式编译到可执行程序中,需要注意的是要将cjpeg.cmain函数适当修改和包含相关头文件。网盘中test2_Ubuntu.rar包含测试用的文件。

        gcc main.c cjpeg.c rdppm.c rdgif.c rdtarga.c rdrle.c rdbmp.c rdswitch.c cdjpeg.c libjpeg.a -o test
        root@ubuntu:/home/lijun/USE_libjpeg/test2# valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./test
        ==5218== Memcheck, a memory error detector
        ==5218== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
        ==5218== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
        ==5218== Command: ./test
        ==5218==
        main.c 29, ret=0
        ==5218==
        ==5218== HEAP SUMMARY:
        ==5218== in use at exit: 0 bytes in 0 blocks
        ==5218== total heap usage: 23 allocs, 23 frees, 72,560 bytes allocated
        ==5218==
        ==5218== All heap blocks were freed -- no leaks are possible
        ==5218==
        ==5218== For lists of detected and suppressed errors, rerun with: -s
        ==5218== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
        复制


        3 Hi3518ev300使用libjpeg

        3.1 移植

          tar xzf jpegsrc.v9c.tar.gz
          cd jpeg-9c/
          ./configure --prefix=$PWD CC=arm-himix100-linux-gcc --host=arm
          复制

          make,生成cjpeg(用来生成JPEG格式文件)、djpeg(用来解压JPEG格式文件)、jpegtran(用来旋转、缩放JPEG图片等)等可执行程序。

          3.2 使用命令行

          跟在PC linux使用方式一样。

          3.3 使用api

          跟在PC linux使用方式一样。

          文章转载自ta是一个搬运工,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

          评论