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

Side by Side Diff: src/codec/SkCodecPriv.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 unified diff | Download patch
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | src/codec/SkCodec_libgif.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (0 > subset->left() || subset->left() >= imageDims.width() ||
36 0 > subset->top() || subset->top() >= imageDims.height() ||
37 0 > subset->width() || subset->left() + subset->width() > imageDims. width() ||
38 0 > subset->height() || subset->top() + subset->height() > imageDims .height()) {
39 return false;
40 }
41 return true;
42 }
43
44 inline float get_scale(uint32_t sampleSize) { return 1.0f / (float) sampleSize; }
45
34 /* 46 /*
35 * returns a scaled dimension based on the original dimension and the sampleSize 47 * 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 48 * NOTE: we round down here for scaled dimension to match the behavior of SkImag eDecoder
37 */ 49 */
38 inline int get_scaled_dimension(int srcDimension, int sampleSize) { 50 inline int get_scaled_dimension(int srcDimension, int sampleSize) {
39 if (sampleSize > srcDimension) { 51 if (sampleSize > srcDimension) {
40 return 1; 52 return 1;
41 } 53 }
42 return srcDimension / sampleSize; 54 return srcDimension / sampleSize;
43 } 55 }
(...skipping 17 matching lines...) Expand all
61 inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; }; 73 inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; };
62 74
63 /* 75 /*
64 * When scaling, we will discard certain y-coordinates (rows) and 76 * When scaling, we will discard certain y-coordinates (rows) and
65 * x-coordinates (columns). This function returns true if we should keep the 77 * x-coordinates (columns). This function returns true if we should keep the
66 * coordinate and false otherwise. 78 * coordinate and false otherwise.
67 * The inputs may be x-coordinates or y-coordinates. 79 * The inputs may be x-coordinates or y-coordinates.
68 * 80 *
69 * This does not need to be called and is not called when sampleFactor == 1. 81 * This does not need to be called and is not called when sampleFactor == 1.
70 */ 82 */
71 inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) { 83 inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim, in t subsetOffset) {
72 // Get the first coordinate that we want to keep 84 // Get the first coordinate that we want to keep
73 int startCoord = get_start_coord(sampleFactor); 85 int startCoord = get_start_coord(sampleFactor) + subsetOffset;
74 86
75 // Return false on edge cases 87 // Return false on edge cases
76 if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaled Dim) { 88 if (srcCoord < startCoord ||
89 get_dst_coord(srcCoord - subsetOffset, sampleFactor) >= scaledDim) {
77 return false; 90 return false;
78 } 91 }
79 92
80 // Every sampleFactor rows are necessary 93 // Every sampleFactor rows are necessary
81 return ((srcCoord - startCoord) % sampleFactor) == 0; 94 return ((srcCoord - startCoord) % sampleFactor) == 0;
82 } 95 }
83 96
84 inline uint32_t ceil_div(uint32_t a, uint32_t b) { 97 inline uint32_t ceil_div(uint32_t a, uint32_t b) {
85 return (a + b - 1) / b; 98 return (a + b - 1) / b;
86 } 99 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 #endif 279 #endif
267 } 280 }
268 281
269 #ifdef SK_PRINT_CODEC_MESSAGES 282 #ifdef SK_PRINT_CODEC_MESSAGES
270 #define SkCodecPrintf SkDebugf 283 #define SkCodecPrintf SkDebugf
271 #else 284 #else
272 #define SkCodecPrintf(...) 285 #define SkCodecPrintf(...)
273 #endif 286 #endif
274 287
275 #endif // SkCodecPriv_DEFINED 288 #endif // SkCodecPriv_DEFINED
OLDNEW
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | src/codec/SkCodec_libgif.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698