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

Side by Side Diff: src/codec/SkCodecPriv.h

Issue 1395183003: Add scaled subset API to SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@split0
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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The Android Open Source Project 2 * Copyright 2015 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkCodecPriv_DEFINED 8 #ifndef SkCodecPriv_DEFINED
9 #define SkCodecPriv_DEFINED 9 #define SkCodecPriv_DEFINED
10 10
(...skipping 13 matching lines...) Expand all
24 uint8_t zeroAlpha = 0; \ 24 uint8_t zeroAlpha = 0; \
25 uint8_t maxAlpha = 0xFF; 25 uint8_t maxAlpha = 0xFF;
26 26
27 #define UPDATE_RESULT_ALPHA(alpha) \ 27 #define UPDATE_RESULT_ALPHA(alpha) \
28 zeroAlpha |= (alpha); \ 28 zeroAlpha |= (alpha); \
29 maxAlpha &= (alpha); 29 maxAlpha &= (alpha);
30 30
31 #define COMPUTE_RESULT_ALPHA \ 31 #define COMPUTE_RESULT_ALPHA \
32 SkSwizzler::GetResult(zeroAlpha, maxAlpha); 32 SkSwizzler::GetResult(zeroAlpha, maxAlpha);
33 33
34 inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) {
35 return SkIRect::MakeSize(imageDims).contains(subset);
36 }
37
34 /* 38 /*
35 * returns a scaled dimension based on the original dimension and the sampleSize 39 * returns a scaled dimension based on the original dimension and the sampleSize
36 * NOTE: we round down here for scaled dimension to match the behavior of SkImag eDecoder 40 * NOTE: we round down here for scaled dimension to match the behavior of SkImag eDecoder
37 */ 41 */
38 inline int get_scaled_dimension(int srcDimension, int sampleSize) { 42 inline int get_scaled_dimension(int srcDimension, int sampleSize) {
39 if (sampleSize > srcDimension) { 43 if (sampleSize > srcDimension) {
40 return 1; 44 return 1;
41 } 45 }
42 return srcDimension / sampleSize; 46 return srcDimension / sampleSize;
43 } 47 }
(...skipping 13 matching lines...) Expand all
57 * The output can be interpreted as an x-coordinate or a y-coordinate. 61 * The output can be interpreted as an x-coordinate or a y-coordinate.
58 * 62 *
59 * This does not need to be called and is not called when sampleFactor == 1. 63 * This does not need to be called and is not called when sampleFactor == 1.
60 */ 64 */
61 inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; }; 65 inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; };
62 66
63 /* 67 /*
64 * When scaling, we will discard certain y-coordinates (rows) and 68 * When scaling, we will discard certain y-coordinates (rows) and
65 * x-coordinates (columns). This function returns true if we should keep the 69 * x-coordinates (columns). This function returns true if we should keep the
66 * coordinate and false otherwise. 70 * coordinate and false otherwise.
67 * The inputs may be x-coordinates or y-coordinates. 71 *
72 * The inputs may be x-coordinates or y-coordinates, but for clarity, it helps
73 * 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
68 * 74 *
69 * This does not need to be called and is not called when sampleFactor == 1. 75 * This does not need to be called and is not called when sampleFactor == 1.
76 *
77 * @param srcY Unscaled, original y-coordinate
78 * @param sampleY Sampling factor used in the y-dimension
79 * @param scaledSubsetHeight Height of the final output, after any scaling or su bsetting
80 * @param subsetY Top of the subset as an unscaled, original y-coordi nate
70 */ 81 */
71 inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) { 82 inline bool is_coord_necessary(int srcY, int sampleY, int scaledSubsetHeight, in t subsetY) {
72 // Get the first coordinate that we want to keep 83 // Get the first coordinate that we want to keep
73 int startCoord = get_start_coord(sampleFactor); 84 int startY = get_start_coord(sampleY) + subsetY;
74 85
75 // Return false on edge cases 86 // Return false on edge cases
76 if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaled Dim) { 87 if (srcY < startY || get_dst_coord(srcY - subsetY, sampleY) >= scaledSubsetH eight) {
77 return false; 88 return false;
78 } 89 }
79 90
80 // Every sampleFactor rows are necessary 91 // Every sampleY rows are necessary
81 return ((srcCoord - startCoord) % sampleFactor) == 0; 92 return ((srcY - startY) % sampleY) == 0;
82 } 93 }
83 94
84 inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { 95 inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
85 // Check for supported alpha types 96 // Check for supported alpha types
86 if (srcAlpha != dstAlpha) { 97 if (srcAlpha != dstAlpha) {
87 if (kOpaque_SkAlphaType == srcAlpha) { 98 if (kOpaque_SkAlphaType == srcAlpha) {
88 // If the source is opaque, we must decode to opaque 99 // If the source is opaque, we must decode to opaque
89 return false; 100 return false;
90 } 101 }
91 102
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 #endif 248 #endif
238 } 249 }
239 250
240 #ifdef SK_PRINT_CODEC_MESSAGES 251 #ifdef SK_PRINT_CODEC_MESSAGES
241 #define SkCodecPrintf SkDebugf 252 #define SkCodecPrintf SkDebugf
242 #else 253 #else
243 #define SkCodecPrintf(...) 254 #define SkCodecPrintf(...)
244 #endif 255 #endif
245 256
246 #endif // SkCodecPriv_DEFINED 257 #endif // SkCodecPriv_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698