blob: bc28c2b2af6f2710c8c2d94ef3a64abb45cbe2c2 [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;
59
60 int width() const { return fWidth; }
61 int height() const { return fHeight; }
62
63 virtual ~SkBitmapRegionDecoderInterface() {}
64
65protected:
66
67 SkBitmapRegionDecoderInterface(int width, int height)
68 : fWidth(width)
69 , fHeight(height)
70 {}
71
72private:
73 const int fWidth;
74 const int fHeight;
75};
76
77#endif