@Override public Resource<Palette> decode(InputStream source, int width, int height) throws IOException { if (!source.markSupported()) { source = new BufferedInputStream(source); } Log.d("PALETTE", "Decoding from cache"); if (isBitmap(source)) { Log.d("PALETTE", "It's a cached bitmap"); Resource<Bitmap> bitmap = bitmapDecoder.decode(source, width, height); try { Palette palette = new Palette.Builder(bitmap.get()) .resizeBitmapArea(-1) .generate(); Log.d("PALETTE", "Palette generated"); return new SimpleResource<>(palette); } finally { bitmap.recycle(); } } else { Log.d("PALETTE", "It's a cached palette"); if (PaletteCacheEncoder.PALETTE_MAGIC_BYTE != source.read()) { throw new IOException("Cannot read palette magic."); } return paletteDecoder.decode(source, width, height); } }
public Resource<SVG> decode(InputStream source, int width, int height, Options options) throws IOException { try { SVG svg = SVG.getFromInputStream(source); return new SimpleResource<SVG>(svg); } catch (SVGParseException ex) { throw new IOException("Cannot load SVG from stream", ex); } }
@Override public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode) { SVG svg = toTranscode.get(); Picture picture = svg.renderToPicture(); PictureDrawable drawable = new PictureDrawable(picture); return new SimpleResource<PictureDrawable>(drawable); }
public Resource<SVG> decode(InputStream source, int width, int height, Options options) throws IOException { try { SVG svg = SVG.getFromInputStream(source); return new SimpleResource<>(svg); } catch (SVGParseException ex) { throw new IOException("Cannot load SVG from stream", ex); } }
@Override public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode, Options options) { SVG svg = toTranscode.get(); Picture picture = svg.renderToPicture(); PictureDrawable drawable = new PictureDrawable(picture); return new SimpleResource<>(drawable); }
public Resource<SVG> decode(InputStream source, int width, int height) throws IOException { try { SVG svg = SVG.getFromInputStream(source); return new SimpleResource<SVG>(svg); } catch (SVGParseException ex) { throw new IOException("Cannot load SVG from stream", ex); } }
@Override public Resource<SVG> decode (InputStream source, int width, int height) throws IOException { try { SVG svg = SVG.getFromInputStream( source ); return new SimpleResource<SVG>( svg ); } catch ( SVGParseException ex ) { throw new IOException( "Cannot load SVG from stream", ex ); } }
@Override public Resource<PictureDrawable> transcode (Resource<SVG> toTranscode) { SVG svg = toTranscode.get( ); Picture picture = svg.renderToPicture( ); PictureDrawable drawable = new PictureDrawable( picture ); return new SimpleResource<PictureDrawable>( drawable ); }
@Override public Resource<Size> transcode(Resource<Bitmap> toTranscode) { Bitmap bitmap = toTranscode.get(); Size size = new Size(); size.width = bitmap.getWidth(); size.height = bitmap.getHeight(); return new SimpleResource<>(size); }
@Override public Resource<Size> transcode(Resource<Options> toTranscode) { Options options = toTranscode.get(); Size size = new Size(); size.width = options.outWidth; size.height = options.outHeight; return new SimpleResource<>(size); }
@Override public Resource<Palette> decode(InputStream source, int width, int height) throws IOException { try { ObjectInputStream stream = new ObjectInputStream(source); PaletteSerializer palette = (PaletteSerializer)stream.readObject(); Log.d("PALETTE", "Palette loaded"); return new SimpleResource<>(palette.getPalette()); } catch (Exception e) { Log.w("PALETTE", "Cannot deserialize", e); throw new IOException("Cannot read palette", e); } }
@Override public boolean encode(Resource<PaletteBitmap> data, OutputStream os) { PaletteBitmap bitmap = data.get(); // Resource objects are only created to satisfy the contract, they don't need to be recycled. boolean paletteOK = paletteEncoder.encode(new SimpleResource<>(bitmap.palette), os); boolean bitmapOK = bitmapEncoder.encode(new BitmapResource(bitmap.bitmap, FAKE_POOL), os); return bitmapOK && paletteOK; }
@Override public Resource<Options> decode(File source, int width, int height) throws IOException { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(source.getAbsolutePath(), options); return new SimpleResource<>(options); }
@Override public Resource<SVG> decode(InputStream source, int width, int height) throws IOException { try { SVG svg = SVG.getFromInputStream(source); svg.setDocumentHeight(height); svg.setDocumentWidth(width); svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX); return new SimpleResource<>(svg); } catch (SVGParseException ex) { throw new IOException("Cannot load SVG from stream", ex); } }
@Override public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode) { SVG svg = toTranscode.get(); Picture picture = svg.renderToPicture(); PictureDrawable drawable = new PictureDrawable(picture); return new SimpleResource<>(drawable); }
public Resource<SVG> decode(InputStream source, int width, int height) throws IOException { try { SVG svg = SVG.getFromInputStream(source); return new SimpleResource<>(svg); } catch (SVGParseException ex) { throw new IOException("Cannot load SVG from stream", ex); } }
@Override public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode) { SVG svg = toTranscode.get(); Picture picture; if (svg.getDocumentWidth() != -1) { svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.FULLSCREEN); picture = svg.renderToPicture(); } else { picture = svg.renderToPicture(mDeviceWidth, Math.round(mDeviceWidth/svg.getDocumentAspectRatio())); } PictureDrawable drawable = new PictureDrawable(picture); return new SimpleResource<>(drawable); }
@Override public Resource<T> decode(T source, int width, int height) throws IOException { return new SimpleResource<>(source); }