分享

android 编译libjpeg

 勤奋不止 2014-04-22

最近解码视频生成的是yuv数据,然后需要生成jpg图片,之前的方案是yuv-rgb-bmp-jpg这样的话是很慢的,计算了时间大概要300ms左右,导致多次点击照相,会造成视频画面的延迟,所以只能使用别的方案替代,在网上查询libjpeg,但是又看了一篇文章http://www./bbs/thread374093.html说libjpeg-turbo比libjpeg快了2-3倍时间,所以打算使用libjpg-turbo来实现yuv转换为jpg图像。下面是使用ndk来交叉编译libjpeg-turbo生成libjpeg-turbo.so。

1、从官网下载最新的libjpeg-turbo源码,http:///projects/libjpeg-turbo/ ,现在最新的版本是libjpeg-turbo-1.2.1

2、解压缩下载的文件,然后进入,并创建jni文件夹,最后将里面的文件都拷贝到jni文件中

3、进入jni目录,然后创建配置文件(例如jconfig.h,config.h),在终端输入:

  1. ./configure --with-jpeg8  

就会生成

  1. config.status: creating config.h  
  2. config.status: creating jconfig.h  
4、接下来是创建Android.mk文件

  1. # Makefile for libjpeg-turbo  
  2.   
  3. ##################################################  
  4. ###                simd                        ###  
  5. ##################################################  
  6. LOCAL_PATH := $(my-dir)  
  7. include $(CLEAR_VARS)  
  8. LOCAL_CFLAGS += -D__ARM_HAVE_NEON  
  9.   
  10. # From autoconf-generated Makefile  
  11. EXTRA_DIST = simd/nasm_lt.sh simd/jcclrmmx.asm simd/jcclrss2.asm simd/jdclrmmx.asm simd/jdclrss2.asm \  
  12.     simd/jdmrgmmx.asm simd/jdmrgss2.asm simd/jcclrss2-64.asm simd/jdclrss2-64.asm \  
  13.     simd/jdmrgss2-64.asm simd/CMakeLists.txt  
  14.    
  15. libsimd_SOURCES_DIST = simd/jsimd_arm_neon.S \  
  16.                        simd/jsimd_arm.c   
  17.   
  18. LOCAL_SRC_FILES := $(libsimd_SOURCES_DIST)  
  19.   
  20. LOCAL_C_INCLUDES := $(LOCAL_PATH)/simd \  
  21.                     $(LOCAL_PATH)/android  
  22.    
  23. AM_CFLAGS := -march=armv7-a -mfpu=neon  
  24. AM_CCASFLAGS := -march=armv7-a -mfpu=neon  
  25. LOCAL_ARM_MODE=arm   
  26. LOCAL_MODULE_TAGS := debug  
  27.    
  28. LOCAL_MODULE := libsimd  
  29.    
  30. include $(BUILD_STATIC_LIBRARY)  
  31.    
  32. ######################################################  
  33. ###           libjpeg.so                       ##  
  34. ######################################################  
  35.    
  36. include $(CLEAR_VARS)  
  37.   
  38. # From autoconf-generated Makefile  
  39. libjpeg_SOURCES_DIST =  jcapimin.c jcapistd.c jccoefct.c jccolor.c \  
  40.         jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \  
  41.         jcomapi.c jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c \  
  42.         jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \  
  43.         jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \  
  44.         jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c \  
  45.         jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c \  
  46.         jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c \  
  47.     jaricom.c jcarith.c jdarith.c \  
  48.     turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c \  
  49.     turbojpeg-mapfile  
  50.   
  51. LOCAL_SRC_FILES:= $(libjpeg_SOURCES_DIST)  
  52.    
  53. LOCAL_SHARED_LIBRARIES := libcutils  
  54. LOCAL_STATIC_LIBRARIES := libsimd  
  55. LOCAL_ARM_MODE=arm  
  56. LOCAL_C_INCLUDES := $(LOCAL_PATH)   
  57.    
  58. LOCAL_CFLAGS :=-O3 -fstrict-aliasing -fprefetch-loop-arrays  -DANDROID \  
  59.         -DANDROID_TILE_BASED_DECODE -DENABLE_ANDROID_NULL_CONVERT -D__ARM_HAVE_NEON  
  60. AM_CFLAGS := -march=armv7-a -mfpu=neon  
  61. AM_CCASFLAGS := -march=armv7-a -mfpu=neon  
  62. LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_STATIC_LIBRARY)  
  63. LOCAL_MODULE_TAGS := debug  
  64. LOCAL_MODULE := libjpeg  
  65. include $(BUILD_SHARED_LIBRARY)  

5、然后在终端输入ndk-build,结果如下:

  1. root@zhangjie:/home/libjpeg-turbo-1.2.1/jni# ndk-build  
  2. Android NDK: WARNING: Unsupported source file extensions in /home/libjpeg-turbo-1.2.1/jni/Android.mk for module jpeg      
  3. Android NDK:   turbojpeg-mapfile      
  4. Compile arm    : jpeg <= jcapimin.c  
  5. Compile arm    : jpeg <= jcapistd.c  
  6. Compile arm    : jpeg <= jccoefct.c  
  7. Compile arm    : jpeg <= jccolor.c  
  8. Compile arm    : jpeg <= jcdctmgr.c  
  9. Compile arm    : jpeg <= jchuff.c  
  10. Compile arm    : jpeg <= jcinit.c  
  11. Compile arm    : jpeg <= jcmainct.c  
  12. Compile arm    : jpeg <= jcmarker.c  
  13. Compile arm    : jpeg <= jcmaster.c  
  14. Compile arm    : jpeg <= jcomapi.c  
  15. Compile arm    : jpeg <= jcparam.c  
  16. Compile arm    : jpeg <= jcphuff.c  
  17. Compile arm    : jpeg <= jcprepct.c  
  18. Compile arm    : jpeg <= jcsample.c  
  19. Compile arm    : jpeg <= jctrans.c  
  20. Compile arm    : jpeg <= jdapimin.c  
  21. Compile arm    : jpeg <= jdapistd.c  
  22. Compile arm    : jpeg <= jdatadst.c  
  23. Compile arm    : jpeg <= jdatasrc.c  
  24. Compile arm    : jpeg <= jdcoefct.c  
  25. Compile arm    : jpeg <= jdcolor.c  
  26. Compile arm    : jpeg <= jddctmgr.c  
  27. Compile arm    : jpeg <= jdhuff.c  
  28. Compile arm    : jpeg <= jdinput.c  
  29. Compile arm    : jpeg <= jdmainct.c  
  30. Compile arm    : jpeg <= jdmarker.c  
  31. Compile arm    : jpeg <= jdmaster.c  
  32. Compile arm    : jpeg <= jdmerge.c  
  33. Compile arm    : jpeg <= jdphuff.c  
  34. Compile arm    : jpeg <= jdpostct.c  
  35. Compile arm    : jpeg <= jdsample.c  
  36. Compile arm    : jpeg <= jdtrans.c  
  37. Compile arm    : jpeg <= jerror.c  
  38. Compile arm    : jpeg <= jfdctflt.c  
  39. Compile arm    : jpeg <= jfdctfst.c  
  40. Compile arm    : jpeg <= jfdctint.c  
  41. Compile arm    : jpeg <= jidctflt.c  
  42. Compile arm    : jpeg <= jidctfst.c  
  43. Compile arm    : jpeg <= jidctint.c  
  44. Compile arm    : jpeg <= jidctred.c  
  45. Compile arm    : jpeg <= jquant1.c  
  46. Compile arm    : jpeg <= jquant2.c  
  47. Compile arm    : jpeg <= jutils.c  
  48. Compile arm    : jpeg <= jmemmgr.c  
  49. Compile arm    : jpeg <= jmemnobs.c  
  50. Compile arm    : jpeg <= jaricom.c  
  51. Compile arm    : jpeg <= jcarith.c  
  52. Compile arm    : jpeg <= jdarith.c  
  53. Compile arm    : jpeg <= turbojpeg.c  
  54. Compile arm    : jpeg <= transupp.c  
  55. Compile arm    : jpeg <= jdatadst-tj.c  
  56. Compile arm    : jpeg <= jdatasrc-tj.c  
  57. Compile arm    : simd <= jsimd_arm_neon.S  
  58. Compile arm    : simd <= jsimd_arm.c  
  59. StaticLibrary  : libsimd.a  
  60. SharedLibrary  : libjpeg.so  
  61. Install        : libjpeg.so => libs/armeabi/libjpeg.so  



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多