blob: 047f023c808bd4a419befb5d98334e5990140ecd [file] [log] [blame]
msaretta5783ae2015-09-08 15:35:32 -07001/*
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 "SkStream.h"
13
14/*
15 * This class aims to provide an interface to test multiple implementations of
16 * SkBitmapRegionDecoder.
17 */
18class SkBitmapRegionDecoderInterface {
19public:
20
21 enum Strategy {
22 kCanvas_Strategy, // Draw to the canvas, uses SkCodec
23 kOriginal_Strategy, // Sampling, uses SkImageDecoder
24 // TODO (msarett): Add strategy for SkScaledCodec
25 };
26
27 /*
28 * @param stream Encoded image stream, takes ownership
29 * @param strategy Strategy used for scaling and subsetting
30 * @return Tries to create an SkBitmapRegionDecoder, returns NULL
31 * on failure
32 */
33 static SkBitmapRegionDecoderInterface* CreateBitmapRegionDecoder(
34 SkStreamRewindable* stream, Strategy strategy);
35
36 /*
37 * Decode a scaled region of the encoded image stream
38 *
39 * @param start_x X-coordinate of upper-left corner of region.
40 * This coordinate is unscaled, relative to the original dimensions.
41 * @param start_y Y-coordinate of upper-left corner of region.
42 * This coordinate is unscaled, relative to the original dimensions.
43 * @param width Width of the region to decode.
44 * This distance is unscaled, relative to the original dimensions.
45 * @param height Height of the region to decode.
46 * This distance is unscaled, relative to the original dimensions.
47 * @param sampleSize An integer downscaling factor for the decode.
48 * @param colorType Preferred output colorType.
49 * New implementations should return NULL if they do not support
50 * decoding to this color type.
51 * The old kOriginal_Strategy will decode to a default color type
52 * if this color type is unsupported.
53 * @return Pointer to a bitmap of the decoded region on success, NULL on
54 * failure.
55 */
56 virtual SkBitmap* decodeRegion(int start_x, int start_y, int width,
57 int height, int sampleSize,
58 SkColorType colorType) = 0;
msarett04965c62015-10-12 10:24:38 -070059 /*
60 * @param Requested destination color type
61 * @return true if we support the requested color type and false otherwise
62 */
63 virtual bool conversionSupported(SkColorType colorType) = 0;
msaretta5783ae2015-09-08 15:35:32 -070064
65 int width() const { return fWidth; }
66 int height() const { return fHeight; }
67
68 virtual ~SkBitmapRegionDecoderInterface() {}
69
70protected:
71
72 SkBitmapRegionDecoderInterface(int width, int height)
73 : fWidth(width)
74 , fHeight(height)
75 {}
76
77private:
78 const int fWidth;
79 const int fHeight;
80};
81
82#endif