1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkBitmap.h" 9 #include "SkBitmapRegionDecoder.h" 10 #include "SkCodec.h" 11 12 /* 13 * This class implements SkBitmapRegionDecoder using an SkCodec and 14 * an SkCanvas. It uses the scanline decoder to subset the height. It then 15 * will subset the width and scale by drawing to an SkCanvas. 16 */ 17 // FIXME: This class works well as a performance/quality comparison for 18 // SkBitmapRegionCodec, but it lacks several capabilities that are 19 // required by BitmapRegionDecoder in Android. 20 // (1) WEBP decodes - because SkWebpCodec does not have a scanline 21 // decoder. 22 // (2) Decodes to kGray8 and kIndex8. 23 // (3) Decodes to kUnpremul. 24 // (4) Correcting an invalid dstColorType. For example, if the 25 // client requests kRGB_565 for a non-opaque image, rather than 26 // fail, we need to go ahead and decode to kN32. 27 class SkBitmapRegionCanvas : public SkBitmapRegionDecoder { 28 public: 29 30 /* 31 * Takes ownership of pointer to decoder 32 */ 33 SkBitmapRegionCanvas(SkCodec* decoder); 34 35 bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator, 36 const SkIRect& desiredSubset, int sampleSize, 37 SkColorType colorType, bool requireUnpremul) override; 38 39 bool conversionSupported(SkColorType colorType) override; 40 getEncodedFormat()41 SkEncodedFormat getEncodedFormat() override { return fDecoder->getEncodedFormat(); } 42 43 private: 44 45 SkAutoTDelete<SkCodec> fDecoder; 46 47 typedef SkBitmapRegionDecoder INHERITED; 48 49 }; 50