Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a progressive JPEG image on Android

Tags:

java

android

jpeg

I need to send images over a very low-bandwidth connection from an android phone (down to 10kByte/s) and would like to send them in progressive (interlaced) mode so that the user at the other end starts seeing the image already during the lengthy transfer. Right now, I am creating the image with the regular photo app:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

But this creates non-progressive photos and I have not been able to discover how to convince it to do otherwise. The second option I explored (reading and re-compressing the taken image) got foiled because the Bitmap's compress method does not allow any encoding parameters besides format name and compression factor as far as I could determine:

bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);

My preferred solution would be to instruct the photo app to save in progressive mode.

The next best option would be a Java algorithm that losslessly converts the stored jpeg to progressive (jpegtran does this on Linux, but it is in C and relies on libjepeg).

The next best would a method to specify the relevant encoding parameters to android allowing me to re-compress it, or an alternative Java library that does the same.

Further research revealed that the algorithms are already there (/system/lib/libjpeg.so) with the sources in ~/android-sdk-linux/source-tree/external/jpeg -- but there do not seem to be JNI wrappers readily available.

like image 871
Ivin Avatar asked Jun 11 '12 08:06

Ivin


People also ask

How do I know if my JPEG is baseline or progressive?

Photoshop — Open file. Select File -> Save for Web & Devices . If it's a progressive jpeg, the Progressive checkbox will be selected. Any browser — Baselines jpegs will load top to bottom, and progressive jpegs will do something else.

What is JPEG encoder?

- JPEG encoder is the main component for lossless and hierarchical encoders. - It is suitable for gray scale and color images. - Each image is divided into 8 x 8 blocks. - A group of 4 tables are specified by JPEG. - If the table has quality value with 1, then the quality is best and compression is lowest.


1 Answers

Have you seen this document?

http://docs.oracle.com/javase/6/docs/api/javax/imageio/plugins/jpeg/JPEGImageWriteParam.html

It seems to have write progressive support.

Alternatively, you could use e.g. OpenJPEG through JNI. See http://www.linux-mag.com/id/7697/ as a start.

like image 103
TFuto Avatar answered Nov 06 '22 21:11

TFuto