-1

Tonight I'm working on Android. I've to decode, modify and then encode a JPG on a bytearray. I'm using NDK. Some people told me to use libjpeg-turbo. But I can't figure out how to add this lib to NDK.

Any help please ?

Luca D'Amico
  • 3,192
  • 2
  • 26
  • 38
  • You can achieve all this without NDK and without libjpeg, see http://android.okhelp.cz/compressing-a-bitmap-to-jpg-format-android-example/ – Alex Cohn Oct 25 '13 at 18:48
  • 1
    No mate, I really need NDK for low level image editing. Using SDK will produce out of memory errors, and it is terribly slow :/ – Luca D'Amico Oct 25 '13 at 18:49

1 Answers1

1

No doubt, libjpeg-turbo can give you certain performance advantages, but I'd strongly suggest to start with libjpeg, which is preinstalled on all Android devices.

You still need a JNI wrapper to convert the bytearray to uint8_t*. If you don't actually manipulate the bytes in Java, consider using direct ByteBuffer instead, to guarantee most efficient native access.

Here is a short tutorial in Japanese: http://www.usefullcode.net/2011/01/android_ndklibjpeg.html.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Google Translate makes this blog comprehensible (try to open the URL in Chrome). When you speak about fopen etc., do you mean that you will manipulate Jpeg files in your native code? If that's the case, you don't need JNI wrapper for libjpeg at all. – Alex Cohn Oct 25 '13 at 20:25
  • Yep, I can manipulate the jpeg file in my native code, but in order to alter the image pixels I've to uncompress it using libjpeg, right ?? – Luca D'Amico Oct 25 '13 at 22:18
  • have you got some specific questions at this stage? – Alex Cohn Oct 26 '13 at 03:51
  • I can't understand why you say that if I use fopen to load the image in an array I don't need JNI wrapper for libjpeg ?? I've still to uncompress the image to alter the pixel colors etc. – Luca D'Amico Oct 26 '13 at 10:54
  • What I'm saying is that you can handle all work with libjpeg in your C code; you still need some JNI functions according to young app logic, but you should not worry about libjpeg-specific data structures in your Java code. – Alex Cohn Oct 26 '13 at 12:20
  • Well I managed to add the lib to NDK. I've some errors tho, but I'm going to open another question since this one is solved :) Thanks ! – Luca D'Amico Oct 26 '13 at 12:41