mozilla / mozjpeg

Improved JPEG encoder.
Other
5.47k stars 414 forks source link

How to use mozjpeg in Android and iOS? #159

Closed Hawkeyes0 closed 8 years ago

Hawkeyes0 commented 9 years ago

Hi all. I want to use mozjpeg in Android/iOS app for saving space of images. Please describe how to compile the mozjpeg for Android or iOS?

CoolOppo commented 9 years ago

I don't think it was ever intended for you to do that, but it is probably not extremely difficult to do.

I know you can use the Android NDK to try and compile it for Android, so give that a try if you're willing and able to be the king of the table.

CoolOppo commented 9 years ago

Actually, the file building.txt explicitly states how to build the library for Android.

dcommander commented 9 years ago

mozjpeg is intended primarily as a way of doing non-real-time (offline) optimization of JPEG files to improve web performance (i.e. if you're hosting a lot of JPEG images, you can shrink them by 10-20% with mozjpeg and save significant disk space and maybe improve the performance of transmitting the web page to users, but doing this optimization is currently very slow and not suitable for real-time compression applications.) Decompression-wise, mozjpeg offers no enhancements relative to libjpeg-turbo, so you should generally use libjpeg-turbo as a decompression library. The Android build instructions are ours, not mozjpeg's.

CoolOppo commented 9 years ago

It doesn't seem so slow that it's completely unsuitable for realtime compression like you're stating. I mean yeah, if you're encoding a movie using MJPEG or something sure it's unsuitable, but in the more likely scenario that OP just wants to encode one image at a time for a camera or photo editing app, it's not that ridiculous. Still though, it's not like mozjpeg is necessary considering you can already generate fairly well-optimized progressive JPEGs with libjpeg-turbo anyways; it's just nice to use if you can build it just as easily anyways.

dcommander commented 9 years ago

Depends on your definition of "slow." For a reasonably-sized digital photograph (10 Mpixels) on my particular test machine (Intel Core i7 64-bit), libjpeg v6b compresses it in about 170 ms (for 4:2:0 quality 80), libjpeg-turbo compresses it in about 50 ms (more than 3 times faster), and mozjpeg 3.1 compresses it in about 1 second (6x slower.) 1 second of delay every time you save a JPEG image, even in a non-realtime application, is slow by modern standards.

(Disclaimer: I am the principal developer and sole maintainer of libjpeg-turbo. I am not trying to compete with mozjpeg in any way. I just feel it's important that users understand that mozjpeg serves a fundamentally different purpose than libjpeg-turbo. mozjpeg is backward ABI compatible with libjpeg-turbo, but the two libraries are not interchangeable in a functional sense.)

CoolOppo commented 9 years ago

I stand corrected. In that case, I completely agree with you. I use mozjpeg constantly, but I never really encode too big of images with it. Seeing actual numbers pertaining to 10 megapixel images, which really aren't uncommon for cell phone cameras now, puts into perspective how ridiculous of a wait using mozjpeg would introduce.

dcommander commented 9 years ago

Also bear in mind that those numbers are from a fast PC. Cell phones would be much slower across the board.