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

Unified Diff: tools/SkCodecTools.h

Issue 1402863002: Implementation of SkBitmapRegionDecoder using SkAndroidCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@split1
Patch Set: 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
Index: tools/SkCodecTools.h
diff --git a/tools/SkCodecTools.h b/tools/SkCodecTools.h
index 097915b5d719711c37559f860791ca3b50936dd7..413f0335f3cadeacf8e0fdf2b24e94383b1f3cb0 100644
--- a/tools/SkCodecTools.h
+++ b/tools/SkCodecTools.h
@@ -12,4 +12,28 @@ inline float get_scale_from_sample_size(uint32_t sampleSize) {
return 1.0f / (float) sampleSize;
}
+/*
+ * 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 // SkCodecTools_DEFINED
« tools/SkBitmapRegionDecoderInterface.h ('K') | « tools/SkBitmapRegionDecoderInterface.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698