Code Monkey home page Code Monkey logo

rust-turbojpeg's Introduction

turbojpeg

Rust bindings for TurboJPEG, which provides simple and fast operations for JPEG images:

  • Compression (encoding)
  • Decompression (decoding)
  • Lossless transformations

Usage with image-rs (version 0.24)

To quickly encode and decode images from the image crate (version 0.24), add this to the [dependencies] section in your Cargo.toml:

turbojpeg = {version = "1.0", features = ["image"]}

and then use the functions turbojpeg::decompress_image and turbojpeg::compress_image.

For more advanced usage without the image crate, please see the documentation.

Requirements

The low-level binding to libturbojpeg is provided by the crate turbojpeg-sys, which needs to link to the C library. Typically, you will need CMake, a C compiler and NASM to build the library from source, but see its README for details.

Contributing

All contributions are welcome! Please contact me (@honzasp) or open a pull request. This crate is rather minimal, the main areas of improvement are:

  • Improving the build process of turbojpeg-sys crate, so that it works seamlessly on a wide range of systems.
  • Testing.
  • Extending the safe Rust API provided by turbojpeg crate.

License

This software is released into the public domain or is available with the MIT license (your choice).

rust-turbojpeg's People

Contributors

broose-goose avatar edgarriba avatar honzasp avatar j-baker avatar jesse-bakker avatar makoto-miyazaki-hyper avatar rschoon avatar tvh avatar tyilo avatar

Stargazers

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

Watchers

 avatar  avatar

rust-turbojpeg's Issues

cannot find -lturbojpeg

hi ! I'm trying to package a rust-python package that includes this crate via Pyo3 maturin. I use the following docker image required to generate a manywheels distribution: quay.io/pypa/manylinux2014_x86_64

Also yum install libjpeg-turbo-devel but I get a linking error. Any ideas what would be happening ?

Is shrink-on-load available?

E.g. In c:

tjDecompress2(
    decompressor, jpegBuf, jpegSize, imgBuf, width, 0, height, TJPF_RGB, 
    TJFLAG_FASTDCT | scaling factor // here, efficient shrinking by multiples of 2
);

image::Bgr<u8> not found in `image`

hi! I'm trying to integrate your crate and I'm facing the following issue at compilation time.

 --> /home/edgar/.cargo/registry/src/github.com-1ecc6299db9ec823/turbojpeg-0.2.1/src/image.rs:79:27
   |
79 | impl JpegPixel for image::Bgr<u8> {
   |                           ^^^ not found in `image`

Decode to YUV

I've been trying out this library, and I was wondering how I can make it decode my (already YUV encoded) JPEG images straight into a YUV planar image (ideally 420)? I see mention of it in the comments, and turbojpeg itself should be able to do this, but I cannot set an output pixel format of YUV (or ycbcr or however you want to refer to it as).

performance poor respect to libjpegturbo in tensorflow

hi! i've been using this crate for a while for the kornia-rs repository and recently we benchmarked against different existing libraries and we found that the implementation of the decompress function is quite slow compared to the one in tensorflow.

You can check here some numbers: kornia/kornia-rs#58

Digging a bit into it, i found that mainly this crate uses the raw::tj3Decompress8 that encapsulates all the logic in there, while in the tensorflow version seems a bit more sophisticated and the time results seems quite considerable to review the current implementation.

Happy to assist with anything.

Licensing

Hi,
Could I potentially convince you to convert the licensing of this Crate/project to a more defined license perhaps MIT? There are some issues with "unlicensed" software that can make life a bit difficult.
I specifically would like to use it in code I am writing for my job, so I realize asking for the license to be changed so a corporation can use your work for free is probably a bit annoying, but I figured I'd try asking anyways ๐Ÿ™‚ .

Support for MozJPEG

Hi, I heard that MozJPEG is a immediate replacement(actually a fork) of turbojpeg. Would you consider making it an option?

Building turbojpeg-sys using CMake fails for Android x86

I'm using the following environment variables to build for Android x86:

ANDROID_ABI=x86
ANDROID_NDK=/home/tyilo/Android/Sdk/ndk/21.4.7075529
ANDROID_PLATFORM=17
AR=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
AS=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android17-clang
CARGO_BUILD_TARGET=i686-linux-android
CARGO_TARGET_I686_LINUX_ANDROID_LINKER=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android17-clang
CC=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android17-clang
CMAKE_TOOLCHAIN_FILE=/home/tyilo/Android/Sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake
CXX=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android17-clang++
LD=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
RANLIB=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
STRIP=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip

I can build libjpeg-turbo for Android x86 manually using CMake:

$ cd $(mktemp -d)
$ git clone --recursive https://github.com/honzasp/rust-turbojpeg
$ cd rust-turbojpeg/turbojpeg-sys/libjpeg-turbo
$ mkdir build
$ cd build
$ cmake ..
$ make

However if I try to build a project using turbojpeg-sys with the cmake feature, I get an error:

$ cd $(mktemp -d)
$ cargo new turbojpeg_android_test
$ cd turbojpeg_android_test
$ cargo add --no-default-features --features cmake turbojpeg-sys
    Updating crates.io index
      Adding turbojpeg-sys v0.2.2 to dependencies.
             Features:
             + cmake
             - bindgen
             - pkg-config
             - require-simd
$ cat > src/main.rs
fn main() {
    unsafe {
        turbojpeg_sys::tjAlloc(1024);
    }
}
^D
$ cargo build
   Compiling anyhow v1.0.66
   Compiling cc v1.0.77
   Compiling libc v0.2.137
   Compiling cmake v0.1.49
   Compiling turbojpeg-sys v0.2.2
   Compiling turbojpeg_android_test v0.1.0 (/tmp/tmp.sk84AUqLbu/turbojpeg_android_test)
error: linking with `/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android17-clang` failed: exit status: 1
  |
  = note: "/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android17-clang" "/tmp/rustcZfoMlb/symbols.o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7.2vod6ppifzjgbxmp.rcgu.o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7.3a4x8z63o5kdjxem.rcgu.o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7.597w44jmsw2lks12.rcgu.o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7.5e5tw586s0m4cc6.rcgu.o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7.gry6mwfxm7q2c2i.rcgu.o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7.zrbw5pxyg4tddzf.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps" "-L" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/debug/deps" "-L" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/build/turbojpeg-sys-a7073ee1dadd896f/out/lib" "-L" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib" "-Wl,-Bstatic" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/libturbojpeg_sys-2ead15d1b4f80846.rlib" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/liblibc-665123b2360d668c.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libstd-622dd9b0332e26c9.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libpanic_unwind-8eed901191a90505.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libobject-a6301f462a1afc81.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libmemchr-93e670f0c20d09fd.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libaddr2line-41b5de145182a9b6.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libgimli-bbfb84cf04d9c494.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/librustc_demangle-e7484fb8d6809e4b.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libstd_detect-d6b62c0a4eb43f93.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libhashbrown-3a9f90107e729020.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libminiz_oxide-4deb44ec92052fb6.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libadler-4a6b480a176dcdfe.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/librustc_std_workspace_alloc-c299c9753161493f.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libunwind-295a81fa953b2dbd.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libcfg_if-abe19b897bf8ce07.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/liblibc-11a826f7ccf51420.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/liballoc-87fd81c649bbeba2.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/librustc_std_workspace_core-10180754ab6ad528.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libcore-a8584b609ee8c62b.rlib" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib/libcompiler_builtins-c93094a148dc18fa.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lgcc" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/tyilo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-linux-android/lib" "-o" "/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/turbojpeg_android_test-1c4ad68e50ad93e7" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: /tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/libturbojpeg_sys-2ead15d1b4f80846.rlib(turbojpeg.c.o): incompatible target
          src/main.rs:3: error: undefined reference to 'tjAlloc'
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `turbojpeg_android_test` due to previous error

If I inspect the file that rust is trying to link to (/tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/libturbojpeg_sys-2ead15d1b4f80846.rlib(turbojpeg.c.o)), I can see that it is an ARM object file and not a x86 object file as expected:

$ ar x /tmp/tmp.sk84AUqLbu/turbojpeg_android_test/target/i686-linux-android/debug/deps/libturbojpeg_sys-2ead15d1b4f8084
6.rlib
$ file turbojpeg.c.o 
turbojpeg.c.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped

If I instead try to build for Android armv7a with the following environment variables, then cargo build succeeds:

ANDROID_ABI=armeabi-v7a
ANDROID_NDK=/home/tyilo/Android/Sdk/ndk/21.4.7075529
ANDROID_PLATFORM=17
AR=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
AS=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi17-clang
CARGO_BUILD_TARGET=armv7-linux-androideabi
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi17-clang
CC=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi17-clang
CMAKE_TOOLCHAIN_FILE=/home/tyilo/Android/Sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake
CXX=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi17-clang++
LD=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
RANLIB=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
STRIP=/home/tyilo/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip

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.