libjpeg的編譯和使用進(jìn)行圖片壓縮

來點(diǎn)前奏說明

當(dāng)你打開這個(gè)文檔的時(shí)候,你已經(jīng)做好準(zhǔn)備了,話不多說開搞。
本文以https://github.com/libjpeg-turbo/libjpeg-turbo
的默認(rèn)master分支進(jìn)行編譯,以Ubuntu進(jìn)行演示編譯過程。

1、硬件要求:

系統(tǒng):  Unbuntu

2、軟件要求:

sudo apt install git
sudo apt install yasm
sudo apt install vim
sudo snap install cmake 

NDK版本要求:NDK 14及其以前的版本

下載NDK 14以前包括14的版本


3、libjpeg 編譯

git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git
cd libjpeg-turbo/

Building libjpeg-turbo for Android platforms requires v13b or later of the Android NDK.

先放上我已經(jīng)寫好的shell腳本,以ARMv8 (64-bit)寫的,為命名為build_arm64_android.sh

#!/bin/bash
# Set these variables to suit your needs
NDK_PATH=/home/zhangbin/Android/Sdk/ndk-bundle
#TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,and "clang" must be used with NDK r17c and later}
TOOLCHAIN=gcc
#ANDROID_VERSION={the minimum version of Android to support.  "21" or lateris required for a 64-bit build.}
ANDROID_VERSION=21
cmake -G"Unix Makefiles" \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_ARM_MODE=arm \
  -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
  -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
  -DCMAKE_ASM_FLAGS="--target=aarch64-linux-android${ANDROID_VERSION}" \
  -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \

ARMv7 (32-bit)

# Set these variables to suit your needs
NDK_PATH={full path to the NDK directory-- for example,
  /opt/android/android-ndk-r16b}
TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r16b and earlier,
  and "clang" must be used with NDK r17c and later}
ANDROID_VERSION={the minimum version of Android to support-- for example,
  "16", "19", etc.}

cd {build_directory}
cmake -G"Unix Makefiles" \
  -DANDROID_ABI=armeabi-v7a \
  -DANDROID_ARM_MODE=arm \
  -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
  -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
  -DCMAKE_ASM_FLAGS="--target=arm-linux-androideabi${ANDROID_VERSION}" \
  -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
  [additional CMake flags] {source_directory}
make

ARMv8 (64-bit)

# Set these variables to suit your needs
NDK_PATH={full path to the NDK directory-- for example,
  /opt/android/android-ndk-r16b}
TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,
  and "clang" must be used with NDK r17c and later}
ANDROID_VERSION={the minimum version of Android to support.  "21" or later
  is required for a 64-bit build.}

cd {build_directory}
cmake -G"Unix Makefiles" \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_ARM_MODE=arm \
  -DANDROID_PLATFORM=android-${ANDROID_VERSION} \
  -DANDROID_TOOLCHAIN=${TOOLCHAIN} \
  -DCMAKE_ASM_FLAGS="--target=aarch64-linux-android${ANDROID_VERSION}" \
  -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
  [additional CMake flags] {source_directory}
make

執(zhí)行上面寫好的腳本,我的腳本命名為build_arm64_android.sh

./build_arm64_android.sh

Installing libjpeg-turbo

sudo make install

成功的標(biāo)志,a文件為靜態(tài)庫,so文件為動(dòng)態(tài)庫

目錄下面生成  libjpeg.a 和  libturbojpeg.a

4、libjpeg 使用

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容