Index: src/codec/SkCodecPriv.h |
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h |
index 0442625dd20b858ee7e9cd84877f3417124fcbd1..766b222e6bee2976f05aa0f923f19df7692735ae 100644 |
--- a/src/codec/SkCodecPriv.h |
+++ b/src/codec/SkCodecPriv.h |
@@ -31,6 +31,10 @@ |
#define COMPUTE_RESULT_ALPHA \ |
SkSwizzler::GetResult(zeroAlpha, maxAlpha); |
+inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) { |
+ return SkIRect::MakeSize(imageDims).contains(subset); |
+} |
+ |
/* |
* returns a scaled dimension based on the original dimension and the sampleSize |
* NOTE: we round down here for scaled dimension to match the behavior of SkImageDecoder |
@@ -64,21 +68,28 @@ inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam |
* When scaling, we will discard certain y-coordinates (rows) and |
* x-coordinates (columns). This function returns true if we should keep the |
* coordinate and false otherwise. |
- * The inputs may be x-coordinates or y-coordinates. |
+ * |
+ * The inputs may be x-coordinates or y-coordinates, but for clarity, it helps |
+ * to name variables using y-coordinate naming conventions. |
scroggo
2015/10/12 20:47:07
Was y picked arbitrarily over x? I understand it m
|
* |
* This does not need to be called and is not called when sampleFactor == 1. |
+ * |
+ * @param srcY Unscaled, original y-coordinate |
+ * @param sampleY Sampling factor used in the y-dimension |
+ * @param scaledSubsetHeight Height of the final output, after any scaling or subsetting |
+ * @param subsetY Top of the subset as an unscaled, original y-coordinate |
*/ |
-inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) { |
+inline bool is_coord_necessary(int srcY, int sampleY, int scaledSubsetHeight, int subsetY) { |
// Get the first coordinate that we want to keep |
- int startCoord = get_start_coord(sampleFactor); |
+ int startY = get_start_coord(sampleY) + subsetY; |
// Return false on edge cases |
- if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaledDim) { |
+ if (srcY < startY || get_dst_coord(srcY - subsetY, sampleY) >= scaledSubsetHeight) { |
return false; |
} |
- // Every sampleFactor rows are necessary |
- return ((srcCoord - startCoord) % sampleFactor) == 0; |
+ // Every sampleY rows are necessary |
+ return ((srcY - startY) % sampleY) == 0; |
} |
inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { |