aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/SkBitmapRegionDecoderInterface.h
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2015-09-08 15:35:32 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-08 15:35:32 -0700
commita5783aeff042ccaf517e50dee3660a4925f5f694 (patch)
tree17144d306e184bd3d6178e863769c5febbd59e22 /tools/SkBitmapRegionDecoderInterface.h
parent036fd8e6f66b53cf87a5f91083cae82f0aeb3635 (diff)
Provides various implementations of Android's SkBitmapRegionDecoder.
Implements testing in DM for these implementations. nanobench testing will follow after this. TBR=scroggo BUG=skia: Committed: https://skia.googlesource.com/skia/+/76f755e6d54a32f9887ad254ce59a3a62f28bde4 Review URL: https://codereview.chromium.org/1288963002
Diffstat (limited to 'tools/SkBitmapRegionDecoderInterface.h')
-rw-r--r--tools/SkBitmapRegionDecoderInterface.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/SkBitmapRegionDecoderInterface.h b/tools/SkBitmapRegionDecoderInterface.h
new file mode 100644
index 0000000000..bc28c2b2af
--- /dev/null
+++ b/tools/SkBitmapRegionDecoderInterface.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBitmapRegionDecoder_DEFINED
+#define SkBitmapRegionDecoder_DEFINED
+
+#include "SkBitmap.h"
+#include "SkStream.h"
+
+/*
+ * This class aims to provide an interface to test multiple implementations of
+ * SkBitmapRegionDecoder.
+ */
+class SkBitmapRegionDecoderInterface {
+public:
+
+ enum Strategy {
+ kCanvas_Strategy, // Draw to the canvas, uses SkCodec
+ kOriginal_Strategy, // Sampling, uses SkImageDecoder
+ // TODO (msarett): Add strategy for SkScaledCodec
+ };
+
+ /*
+ * @param stream Encoded image stream, takes ownership
+ * @param strategy Strategy used for scaling and subsetting
+ * @return Tries to create an SkBitmapRegionDecoder, returns NULL
+ * on failure
+ */
+ static SkBitmapRegionDecoderInterface* CreateBitmapRegionDecoder(
+ SkStreamRewindable* stream, Strategy strategy);
+
+ /*
+ * Decode a scaled region of the encoded image stream
+ *
+ * @param start_x X-coordinate of upper-left corner of region.
+ * This coordinate is unscaled, relative to the original dimensions.
+ * @param start_y Y-coordinate of upper-left corner of region.
+ * This coordinate is unscaled, relative to the original dimensions.
+ * @param width Width of the region to decode.
+ * This distance is unscaled, relative to the original dimensions.
+ * @param height Height of the region to decode.
+ * This distance is unscaled, relative to the original dimensions.
+ * @param sampleSize An integer downscaling factor for the decode.
+ * @param colorType Preferred output colorType.
+ * New implementations should return NULL if they do not support
+ * decoding to this color type.
+ * The old kOriginal_Strategy will decode to a default color type
+ * if this color type is unsupported.
+ * @return Pointer to a bitmap of the decoded region on success, NULL on
+ * failure.
+ */
+ virtual SkBitmap* decodeRegion(int start_x, int start_y, int width,
+ int height, int sampleSize,
+ SkColorType colorType) = 0;
+
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+
+ virtual ~SkBitmapRegionDecoderInterface() {}
+
+protected:
+
+ SkBitmapRegionDecoderInterface(int width, int height)
+ : fWidth(width)
+ , fHeight(height)
+ {}
+
+private:
+ const int fWidth;
+ const int fHeight;
+};
+
+#endif