8

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.

Ivin
  • 1,081
  • 11
  • 21
  • 1
    Just a note: "progressive" is exactly what you get: from top to bottom. What you're looking for is called "interlaced". JPEG output format does not support interlacing. PNG does, so you need to look at creating interlaced PNG image. – Aleks G Jun 11 '12 at 12:49
  • 1
    @AleksG Sorry, but I have to disagree. Please check out [wikipedia](https://en.wikipedia.org/wiki/JPEG) section 'JPEG compression'. As I mentioned in the question, this format is easy to create on 'Linux' using jpegtran. – Ivin Jun 12 '12 at 13:23
  • What is current situation with encoding progressive JPEG in Android? – Ilia Feb 14 '19 at 16:58

1 Answers1

1

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.

TFuto
  • 1,361
  • 15
  • 33
  • Thank you for the suggestion, but I need the solution in Android, and JPEGImageWriteParam is not available there. Using the libjpeg (Openjpeg) directly I just did not get the chance to work on. – Ivin Jun 06 '13 at 14:59
  • I got it. But the JDK source is available, and maybe you could reuse that/those source classes? – TFuto Jun 06 '13 at 15:05
  • They are available and I have tried - but if you try to pull that functionality across, you are pulling several dozen classes along with ti. Most of the packages in this area are not supported by Android. – Ivin Jun 06 '13 at 15:52