Picasso fails to decode some images: skia decode returned false

3.7k views Asked by At

Update: It seems that this question boils down to that some images are correctly decoded, while some don't. If I convert the non-working JPEGs to pngs, they work. None of my images taken directly as JPEGs from either a Nikon D5000, a Panasonic Lumix or a Sony Experia phone can be decoded.


I am using Picasso to fill a ListView in my Android app. I am, however, running into the error --- decoder->decode returned false for the images I am to use, but it works fine for other pictures I run across around the web. Therefore, I believe it has something to do with the images, but I am not really sure. The error arises in the Skia library which is used by Picasso (as far as I know).

For example, this image works fine, while this does not, and it is the latter I need to work. All other pictures I need to use are taken with the same camera and edited by Gimp in the same way, resulting in images like the first one, but none of them work. Hence, I suspect it has something to do with the images themselves rather than the decoder.

A few questions that pops up:

  1. Is it possible that the metadata can do something in this process? The metadata are similar in all the pictures.
  2. Could it be something with the encoded images that makes the encoder go crazy? If so, what could it be and how can I investigate it? End of file missing or anything?
  3. Is it possible to enable more debugging and output from Picasso or Skia? Stack traces, for example?
  4. Will non-UTF8 characters mess things up, or is this handled correctly? The example image does not have UTF8 characters in it, but some of the images may have.

What I have tried:

  1. I tried opening a non-working image in Inkscape and exporting it as a png file instead. Now, the image actually works, so there seems to be something with the JPEG encoding.
  2. Another try was to open the image in Gimp and exporting to JPEG again, but that did not help.
  3. I also tried opening the image in Shotwell and re-exporting to JPEG, both with and without the metadata, but none of these images work. Exporting to png works as with exporting to png from Inkscape.
  4. All the non-working images are taken with a Nikon D5000 camera, so I tried taking a few images with a Sony Experia phone and a Panasonic Lumix camera. Non of the JPEGs work directly, but if converted to PNG they are all decoded.
  5. I tried setting up a Picasso.Builder object as shown here, to get a stack trace. I have pasted the stack trace below. It might seem that it actually is the Android.BitmapFactory.decodeStream() that fails, as the stack trace points to com.squareup.picasso.BitmapHunter.decodeStream(), which utilizes Android.BitmapFactory.decodeStream(). So maybe the error has nothing to do with Skia after all.
  6. I also used Imagemagick's identify -verbose on the working and the non-working images and compared the outputs. I was unable to find any differences that stood out, so it did not bring me any further.

Example Logcat output:

D/Picasso(528): Main        created      [R0] Request{http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg}
D/Picasso(528): Dispatcher  enqueued     [R0]+7ms 
D/Picasso(528): Main        created      [R1] Request{http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg}
D/Picasso(528): Hunter      joined       [R1]+1ms to [R0]+10ms, [R1]+1ms
D/Picasso(528): Main        created      [R2] Request{http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg}
D/Picasso(528): Hunter      joined       [R2]+1ms to [R0]+14ms, [R1]+5ms, [R2]+2ms
D/Picasso(528): Hunter      executing    [R0]+21ms, [R1]+12ms, [R2]+9ms 
D/skia(528):    --- decoder->decode returned false
D/Picasso(528): Dispatcher  retrying     [R0]+1456ms, [R1]+1447ms, [R2]+1444ms 
D/Picasso(528): Hunter      executing    [R0]+1458ms, [R1]+1448ms, [R2]+1445ms 
D/skia(528):    --- decoder->decode returned false
D/Picasso(528): Dispatcher  retrying     [R0]+2867ms, [R1]+2857ms, [R2]+2854ms 
D/Picasso(528): Hunter      executing    [R0]+2868ms, [R1]+2859ms, [R2]+2855ms 
D/skia(528):    --- decoder->decode returned false
D/Picasso(528): Dispatcher  batched      [R0]+3406ms, [R1]+3397ms, [R2]+3394ms for error
D/dalvikvm(249): GC_EXPLICIT freed 119 objects / 5288 bytes in 28ms
I/TAGZ(528):    Error! url = http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg
D/Picasso(528): Main        errored      [R0]+3607ms 
I/TAGZ(528):    Error! url = http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg
D/Picasso(528): Main        errored      [R1]+3598ms 
I/TAGZ(528):    Error! url = http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg
D/Picasso(528): Main        errored      [R2]+3596ms 
D/Picasso(528): Dispatcher  delivered    [R0]+3610ms, [R1]+3601ms, [R2]+3598ms 

Stack trace from Picasso, pointing to this file.

W/System.err(1467): java.io.IOException: Failed to decode stream.
W/System.err(1467):     at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:145)
W/System.err(1467):     at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
W/System.err(1467):     at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
W/System.err(1467):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
W/System.err(1467):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(1467):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(1467):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
W/System.err(1467):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
W/System.err(1467):     at java.lang.Thread.run(Thread.java:1096)
W/System.err(1467):     at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)

getView method in my BaseAdapter for the ListView:

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    final View view;
    Recipe recipe = this.getItem(position);

    if (convertView != null){
        view = convertView;
        view.setTag(recipe.getId());
    }
    else{
        view = myActivity.getLayoutInflater().inflate(R.layout.recipe_item, parent, false);
        view.setTag(recipe.getId());
    }

    ImageView imageView = (ImageView) view.findViewById(R.id.filtered_recipes_list_image_view);

//  final String foo = "https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg";
    final String foo = "http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg";

    Picasso.with(myActivity).setIndicatorsEnabled(true);
    Picasso.with(myActivity).setLoggingEnabled(true);
    Picasso.with(myActivity).load(foo).into(imageView, new Callback() {

        @Override
        public void onSuccess() {
            Log.i("TAGZ", "Success! url = " + foo);
        }

        @Override
        public void onError() {
            Log.i("TAGZ", "Error! url = " + foo);
        }

    });

    return view;
}
1

There are 1 answers

0
Arjun G On

Reason for that error is: You are trying to set an image of size which is more than your image view layout size.

I found a simple solution for that! If you are using picasso library for image loading..then, resize your image to fir your image view layout.

i.e, I have done like this:

Picasso.with(ImageLoaderActivity.this)
                        .load("https://static.pexels.com/photos/34578/pexels-photo.jpg")
                        .resize(200,250)
                        .into(img);