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 #ifndef SkBitmapRegionDecoder_DEFINED 9 #define SkBitmapRegionDecoder_DEFINED 10 11 #include "SkBitmap.h" 12 #include "SkBRDAllocator.h" 13 #include "SkEncodedFormat.h" 14 #include "SkStream.h" 15 16 /* 17 * This class aims to provide an interface to test multiple implementations of 18 * SkBitmapRegionDecoder. 19 */ 20 class SkBitmapRegionDecoder { 21 public: 22 23 enum Strategy { 24 kCanvas_Strategy, // Draw to the canvas, uses SkCodec 25 kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsetting 26 }; 27 28 /* 29 * @param data Refs the data while this object exists, unrefs on destruction 30 * @param strategy Strategy used for scaling and subsetting 31 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure 32 */ 33 static SkBitmapRegionDecoder* Create( 34 SkData* data, Strategy strategy); 35 36 /* 37 * @param stream Takes ownership of the stream 38 * @param strategy Strategy used for scaling and subsetting 39 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure 40 */ 41 static SkBitmapRegionDecoder* Create( 42 SkStreamRewindable* stream, Strategy strategy); 43 44 /* 45 * Decode a scaled region of the encoded image stream 46 * 47 * @param bitmap Container for decoded pixels. It is assumed that the pixels 48 * are initially unallocated and will be allocated by this function. 49 * @param allocator Allocator for the pixels. If this is NULL, the default 50 * allocator (HeapAllocator) will be used. 51 * @param desiredSubset Subset of the original image to decode. 52 * @param sampleSize An integer downscaling factor for the decode. 53 * @param colorType Preferred output colorType. 54 * New implementations should return NULL if they do not support 55 * decoding to this color type. 56 * The old kOriginal_Strategy will decode to a default color type 57 * if this color type is unsupported. 58 * @param requireUnpremul If the image is not opaque, we will use this to determine the 59 * alpha type to use. 60 * 61 */ 62 virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator, 63 const SkIRect& desiredSubset, int sampleSize, 64 SkColorType colorType, bool requireUnpremul) = 0; 65 /* 66 * @param Requested destination color type 67 * @return true if we support the requested color type and false otherwise 68 */ 69 virtual bool conversionSupported(SkColorType colorType) = 0; 70 71 virtual SkEncodedFormat getEncodedFormat() = 0; 72 width()73 int width() const { return fWidth; } height()74 int height() const { return fHeight; } 75 ~SkBitmapRegionDecoder()76 virtual ~SkBitmapRegionDecoder() {} 77 78 protected: 79 SkBitmapRegionDecoder(int width,int height)80 SkBitmapRegionDecoder(int width, int height) 81 : fWidth(width) 82 , fHeight(height) 83 {} 84 85 private: 86 const int fWidth; 87 const int fHeight; 88 }; 89 90 #endif 91