square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.72k stars 3.97k forks source link

Add metadata into the pipeline #639

Open ghost opened 10 years ago

ghost commented 10 years ago

Android L has a new feature that will extract common colors out of an image. Palette.generate(bitmap) This should be run on a background thread. I think it would be cool and efficient to provide a callback after the image has been loaded into memory(from disk or net) on the SAME thread so we can do more processing. I don't think transitions are the correct place for this but I could be wrong and they also don't rerun transition on loading from disk which i would need it to do. I need to call that function and add the results to an internal cache for fast retrieval for activity animations.

I know i could use the Target class and kick off a new task to compute this but we already have thread that had to deal with the bitmap. Just seems inefficient to spin these up and I feel like this is going to need to be done a lot in the near future.

Also this is more of a request. I have no idea if this is the correct place for this.

Thanks Joe

JakeWharton commented 10 years ago

Palette isn't in L, it's a support library for 2.2 and newer. But yeah, it would be nice to figure out an easy way to do this. On Aug 29, 2014 10:23 PM, "cforlife" notifications@github.com wrote:

Android L has a new feature that will extract common colors out of an image. Palette.generate(bitmap) This should be run on a background thread. I think it would be cool and efficient to provide a callback after the image has been loaded into memory(from disk or net) on the SAME thread so we can do more processing. I don't think transitions are the correct place for this but I could be wrong. I need to call that function and add the results to an internal cache for fast retrieval for activity animations.

I know i could use the Target class and kick off a new task to compute this but we already have thread that had to deal with the bitmap. Just seems inefficient to spin these up and I feel like this is going to need to be done a lot in the near future.

Also this is more of a request. I have no idea if this is the correct place for this.

Thanks Joe

— Reply to this email directly or view it on GitHub https://github.com/square/picasso/issues/639.

JakeWharton commented 10 years ago

So I made this work with the current API but the problem is in the memory cache's explicit use of Bitmap as a key. This means we can't store extra metadata in the cache.

I still might be able to make this work...

ghost commented 10 years ago

You know the more i think about this the more i don't know if you should store the data with the bitmap. The swatch that is returned from the generation and it has many colors to pick from including text color. What if you had a callback when the texture is done loading from disk or web that i can regenerate the swatch and store it in a runtime cache? The callback would need original URL and the image.

JakeWharton commented 10 years ago

Good idea. You can actually already do this. I'll write it up and post shortly.

JakeWharton commented 10 years ago

So it turns out there's all kind of compromises when trying to do this. I've outlined them here: http://jakewharton.com/coercing-picasso-to-play-with-palette/. We'll look at a metadata component to Picasso's pipeline in the next major version.

geovanisouza92 commented 10 years ago

What about something like this:

Picasso.with(context)
    .load(url)
    .fit().centerCrop()
    .extractPalette(new PaletteCallback() {
        public void onSuccess(Palette palette) {
        }
    })
    .into(imageView);

And the PaletteTransformation:

public final PaletteTransformation implements Transformation {
  @Override public Bitmap transform(Bitmap source, PaletteCallback cb) {
    // TODO Palette all the things and send back through cb!
    return source;
  }

  @Override public Bitmap transform(Bitmap source) {
    return null;
  }

  @Override public String key() {
    return ""; // Stable key for all requests. An unfortunate requirement.
  }
}

I think that this way the PaletteTransformation could be singleton and stateless.

JakeWharton commented 10 years ago

I don't want a Palette specific API. I'd rather it be a general metadata pipeline for arbitrary data. On Nov 9, 2014 1:17 PM, "Geovani de Souza" notifications@github.com wrote:

What about something like this:

Picasso.with(context) .load(url) .fit().centerCrop() .extractPalette(new PaletteCallback() { public void onSuccess(Palette palette) { } }) .into(imageView);

And the PaletteTransformation:

public final PaletteTransformation implements Transformation { @Override public Bitmap transform(Bitmap source, PaletteCallback cb) { // TODO Palette all the things and send back through cb! return source; }

@Override public Bitmap transform(Bitmap source) { return null; }

@Override public String key() { return ""; // Stable key for all requests. An unfortunate requirement. } }

I think that this way the PaletteTransformation could be singleton and stateless.

— Reply to this email directly or view it on GitHub https://github.com/square/picasso/issues/639#issuecomment-62303123.

dnkoutso commented 9 years ago

Yes this will be done using generic means of metadata for requests.

JakeWharton commented 6 years ago

I'm thinking this is just a Map on the response where you can hang arbitrary tags. No different than a servlet context or thread local map in other multi-stage systems.