msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 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" |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 9 | #include "SkBitmapRegionDecoder.h" |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 10 | #include "SkCodec.h" |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 11 | |
| 12 | /* |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 13 | * This class implements SkBitmapRegionDecoder using an SkCodec and |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 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 | */ |
msarett | 9a0e346 | 2015-12-11 07:38:50 -0800 | [diff] [blame] | 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. |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 27 | class SkBitmapRegionCanvas : public SkBitmapRegionDecoder { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 28 | public: |
| 29 | |
| 30 | /* |
| 31 | * Takes ownership of pointer to decoder |
| 32 | */ |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 33 | SkBitmapRegionCanvas(SkCodec* decoder); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 34 | |
msarett | cb8d719 | 2015-11-11 13:30:43 -0800 | [diff] [blame] | 35 | bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator, |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 36 | const SkIRect& desiredSubset, int sampleSize, |
| 37 | SkColorType colorType, bool requireUnpremul) override; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 38 | |
msarett | 04965c6 | 2015-10-12 10:24:38 -0700 | [diff] [blame] | 39 | bool conversionSupported(SkColorType colorType) override; |
| 40 | |
msarett | 3f65e93 | 2015-10-27 13:12:59 -0700 | [diff] [blame] | 41 | SkEncodedFormat getEncodedFormat() override { return fDecoder->getEncodedFormat(); } |
| 42 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 43 | private: |
| 44 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 45 | SkAutoTDelete<SkCodec> fDecoder; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 46 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 47 | typedef SkBitmapRegionDecoder INHERITED; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 48 | |
| 49 | }; |