Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Unified Diff: tools/SkBitmapRegionDecoderPriv.h

Issue 1321433002: Add subsetting to SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-scan
Patch Set: Rebase - it compiles but I'm sure everything is broken Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/SkBitmapRegionDecoderInterface.cpp ('k') | tools/SkBitmapRegionSampler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/SkBitmapRegionDecoderPriv.h
diff --git a/tools/SkBitmapRegionDecoderPriv.h b/tools/SkBitmapRegionDecoderPriv.h
new file mode 100644
index 0000000000000000000000000000000000000000..0e706dede270d405f1172cd9bf04926d21b6a98f
--- /dev/null
+++ b/tools/SkBitmapRegionDecoderPriv.h
@@ -0,0 +1,35 @@
+/*
+ * 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 SkBitmapRegionDecoderPriv_DEFINED
+#define SkBitmapRegionDecoderPriv_DEFINED
+
+/*
+ * Chooses the correct image subset offsets and dimensions for the partial decode.
+ *
+ * @return true if the subset is completely contained within the image
+ * false otherwise
+ */
+inline bool set_subset_region(int inputOffset, int inputDimension,
+ int imageOriginalDimension, int* imageSubsetOffset, int* outOffset,
+ int* imageSubsetDimension) {
+
+ // This must be at least zero, we can't start decoding the image at a negative coordinate.
+ *imageSubsetOffset = SkTMax(0, inputOffset);
+
+ // If inputOffset is less than zero, we decode to an offset location in the output bitmap.
+ *outOffset = *imageSubsetOffset - inputOffset;
+
+ // Use imageSusetOffset to make sure we don't decode pixels past the edge of the image.
+ // Use outOffset to make sure we don't decode pixels past the edge of the region.
+ *imageSubsetDimension = SkTMin(imageOriginalDimension - *imageSubsetOffset,
+ inputDimension - *outOffset);
+
+ return (*outOffset == 0) && (*imageSubsetDimension == inputDimension);
+}
+
+#endif // SkBitmapRegionDecoderPriv_DEFINED
« no previous file with comments | « tools/SkBitmapRegionDecoderInterface.cpp ('k') | tools/SkBitmapRegionSampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698