Code Monkey home page Code Monkey logo

avif-coder's Introduction

AVIF/HEIF Coder for Android 24+

Library provides simple interface to decode or encode ( create ) AVIF and HEIF images for Android Very fast and convinient to use AVIF in android apps with api version 24+. Based on libheif, libde265, libx265, libyuv, libaom and libdav1d

Correctly handles ICC, and color profiles and HDR images. Fully supports HDR images, 10, 12 bit. Preprocess image in tile to increase speed. Extremly fast in decoding large HDR images or just large images. The most featured AVIF, HEIF library in android. Supported decoding in all necessary pixel formats in Android and avoids android decoding bugs.

Image processing speeded up by libhwy

Usage example

// May decode AVIF(AV1) and HEIC (HEVC) images, HDR images supported
val bitmap: Bitmap = HeifCoder().decode(buffer) // Decode avif from ByteArray
val bytes: ByteArray = HeifCoder().encodeAvif(decodedBitmap) // Encode Bitmap to AVIF
val bytes = HeifCoder().encodeHeic(bitmap) // Encode Bitmap to HEIC / Supports HDR in RGBA_F16, RGBA_1010102, HARDWARE
// Check if image is valid AVIF(AV1) image
val isAvif = HeifCoder().isAvif(byteArray)
// Check if image is valid HEIF(HEVC) image
val isHeif = HeifCoder().isHeif(byteArray)
// Check if image is AVIF or HEIF, just supported one
val isImageSupported = HeifCoder().isSupportedImage(byteArray)
// Get image size ( this call never throw)
val imageSize: Size? = HeifCoder().getSize(byteArray)
// Decode AVIF or HEIF in sample size if needed
val bitmap: Bitmap = decodeSampled(byteArray, scaledWidth, scaledHeight)

Add Jitpack repository

repositories {
    maven { url "https://jitpack.io" }
}
implementation 'com.github.awxkee:avif-coder:1.7.5' // or any version above picker from release tags

// Glide avif plugin if you need one
implementation 'com.github.awxkee:avif-coder-glide:1.7.5' // or any version above picker from release tags

// Coil avif plugin if you need one
implementation 'com.github.awxkee:avif-coder-coil:1.7.5' // or any version above picker from release tags

Also supports coil integration

Just add to image loader heif decoder factory and use it as image loader in coil

val imageLoader = ImageLoader.Builder(context)
    .components {
        add(HeifDecoder.Factory(context))
    }
    .build()

Self-build

Requirements

libdav1d:

  • ndk
  • meson
  • ninja
  • cmake
  • nasm

libyuv, de265, x265, aom, sharpyuv(webp):

  • ndk
  • ninja
  • cmake
  • nasm
  • yasm

libheif:

  • ndk
  • ninja
  • cmake
  • and all built libraries above

If you wish to build by yourself you may use ready build_aom.sh script, build_dav1d.sh, build_x265.sh, build_de265.sh, build_yuv.sh, build_heif.sh or you may use build_all.sh

All commands are require the NDK path set by NDK_PATH environment variable

  • If you wish to build for x86 you have to add a $INCLUDE_X86 environment variable for example:*
NDK_PATH=/path/to/ndk INCLUDE_X86=yes bash build_aom.sh

Disclaimer

AVIF

AVIF is the next step in image optimization based on the AV1 video codec. It is standardized by the Alliance for Open Media. AVIF offers more compression gains than other image formats such as JPEG and WebP. Our and other studies have shown that, depending on the content, encoding settings, and quality target, you can save up to 50% versus JPEG or 20% versus WebP images. The advanced image encoding feature of AVIF brings codec and container support for HDR and wide color gamut images, film grain synthesis, and progressive decoding. AVIF support has improved significantly since Chrome M85 implemented AVIF support last summer.

avif-coder's People

Contributors

awxkee avatar snowfluke avatar t8rin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

avif-coder's Issues

Jxl support

Thanks for creating such a great library, I don't know enough about NDK to write a jxl coder/encoder but if you can so, because you've already written avif coder, please create it, because there are literally NO alternatives unfortunately, thanks for attention, keep going!

The new version doesn't work

I've just tried a new library version and it is not displaying images, and also not saving them, something went wrong with encode and decode functions i think, also no errors during these processes are thrown... F.e. version 1.0.24 work as expected

Will it support tile encoding

Will it support tile encoding? I see you are using libheif to encode the heif image,but libheif don't support tile encoding

Question

Sorry for asking here, do you know any maintained jpeg2000 decoders/encoders for Android?๐Ÿ‘€

Compiling master encountered the following error

[CXX1429] error when building with cmake using \avif-coder\app\src\main\cpp\CMakeLists.txt: C++ build system [configure] failed while executing:
@echo off
"
:\Android\SDK\cmake\3.22.1\bin\cmake.exe" ^
"-HG:\work\avif-coder\app\src\main\cpp" ^
"-DCMAKE_SYSTEM_NAME=Android" ^
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" ^
"-DCMAKE_SYSTEM_VERSION=24" ^
"-DANDROID_PLATFORM=android-24" ^
"-DANDROID_ABI=arm64-v8a" ^
"-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a" ^
"-DANDROID_NDK=:\Android\SDK\ndk\25.1.8937393" ^
"-DCMAKE_ANDROID_NDK=
:\Android\SDK\ndk\25.1.8937393" ^
"-DCMAKE_TOOLCHAIN_FILE=:\Android\SDK\ndk\25.1.8937393\build\cmake\android.toolchain.cmake" ^
"-DCMAKE_MAKE_PROGRAM=
:\Android\SDK\cmake\3.22.1\bin\ninja.exe" ^
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=*:\avif-coder\app\build\intermediates\cxx\Debug\431y1p69\obj\arm64-v8a" ^
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=
:\avif-coder\app\build\intermediates\cxx\Debug\431y1p69\obj\arm64-v8a" ^
"-DCMAKE_BUILD_TYPE=Debug" ^
"-
:\avif-coder\app\.cxx\Debug\431y1p69\arm64-v8a" ^
-GNinja

Add effort option

Effort is many times an important option to have, either to compress quicker or to compress harder

100% quality looks worse than 99%

100% seems to smooth things out too much, also blockier

Examples (converted to png because github skill issue):
See the wall, floor, arm, text also looks better in 99%

99% (173kb):
IMG_2024-03-18_16-30-38_4431

100% (20kb):
IMG_2024-03-18_16-30-57_1386

Related issue (with additional example) T8RIN/ImageToolbox#891

Jitpack

By some reason
image
and i even can't get it from gradle :(

FFmpeg libswscale

Hi, can you implement bitmap scaling based on ffmpeg libswscale, because it can choose between some algorhytms, like bicubic, bilenear, lancoz and others, if you can here is abandoned project that support only two archs and not starts on api 24 and abov

Are the prebuilt artifacts available?

Hi,

Are the prebuilt artifacts available on Maven or somewhere?

adding implementation "com.github.awxkee:avif-coder:1.0.18" in my gradle build I am getting this error:

Could not resolve com.github.awxkee.avif-coder:avif-coder:1.0.18

Cannot find package from Jitpack

Hi, I'm trying to include the dependency from Jitpack, and Gradle can't manage to find it. I'm already using other Jitpack projects, so I don't think it's an issue with my configuration.

Anyway, here's what I'm using:

# libs.versions.toml

[versions]
auxkee-avif = "master-SNAPSHOT"

[libraries]
auxkee-avif-coder = { module = "com.github.awxkee:avif-coder", version.ref = "auxkee-avif" }

[plugins]
// build.gradle.kts

repositories {
    mavenCentral()
    maven("https://jitpack.io")
}

dependencies {
    implementation(libs.auxkee.avif.coder)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.