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

Unified Diff: tools/SkCodecTools.h

Issue 1402863002: Implementation of SkBitmapRegionDecoder using SkAndroidCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@split1
Patch Set: Let's call this AndroidCodec_Strategy 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..e798bda21dcdec346a909eddf20895b2bd305866 100644
--- a/tools/SkCodecTools.h
+++ b/tools/SkCodecTools.h
@@ -12,4 +12,52 @@ inline float get_scale_from_sample_size(uint32_t sampleSize) {
return 1.0f / (float) sampleSize;
}
+enum SubsetType {
+ kFullyInside_SubsetType,
+ kPartiallyInside_SubsetType,
+ kInvalid_SubsetType,
scroggo 2015/10/21 20:56:20 Maybe kOutside?
msarett 2015/10/21 22:00:00 Done.
+};
+
+/*
+ * Corrects image subset offsets and dimensions in order to perform a valid decode.
+ * Also indicates if the image subset should be placed at an offset within the
+ * output bitmap.
+ *
+ * Values of output variables are undefined if the SubsetType is kInvalid.
+ *
+ * @param imageDims Original image dimensions.
+ * @param subset As input, the subset that the client requested.
+ * As output, the image subset that we will decode.
+ * @param outX The left offset of the image subset within the output bitmap.
+ * @param outY The top offset of the image subset within the output bitmap.
+ *
+ * @return An indication of how the subset is contained in the image.
+ * If the return value is kInvalid, values of output variables are undefined.
+ */
+inline SubsetType adjust_subset_rect(const SkISize& imageDims, SkIRect* subset, int* outX,
+ int* outY) {
+ // These must be at least zero, we can't start decoding the image at a negative coordinate.
+ int left = SkTMax(0, subset->fLeft);
+ int top = SkTMax(0, subset->fTop);
+
+ // If input offsets are less than zero, we decode to an offset location in the output bitmap.
+ *outX = left - subset->fLeft;
+ *outY = top - subset->fTop;
+
+ // Make sure we don't decode pixels past the edge of the image or past the edge of the region.
scroggo 2015/10/21 20:56:20 nit: region -> subset Android called it BitmapReg
msarett 2015/10/21 22:00:00 Yes thanks! I generally try to say subset, but I'
+ int width = SkTMin(imageDims.width() - left, subset->width() - *outX);
+ int height = SkTMin(imageDims.height() - top, subset->height() - *outY);
+ if (width <= 0 || height <= 0) {
+ return SubsetType::kInvalid_SubsetType;
+ }
+
+ subset->setXYWH(left, top, width, height);
+ if ((*outX != 0) || (*outY != 0) || (width != subset->width()) ||
+ (height != subset->height())) {
+ return SubsetType::kPartiallyInside_SubsetType;
+ }
+
+ return SubsetType::kFullyInside_SubsetType;
+}
+
#endif // SkCodecTools_DEFINED
« tools/SkBitmapRegionDecoderInterface.cpp ('K') | « tools/SkBitmapRegionDecoderInterface.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698