OLD | NEW |
---|---|
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 Loading... | |
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) { | |
scroggo
2015/10/02 18:27:03
Why not:
return SkIRect::MakeSize(imageDims).cont
| |
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 Loading... | |
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) { |
scroggo
2015/10/02 18:27:03
I assume scaledDim now means scaled version of sub
| |
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 #endif | 275 #endif |
263 } | 276 } |
264 | 277 |
265 #ifdef SK_PRINT_CODEC_MESSAGES | 278 #ifdef SK_PRINT_CODEC_MESSAGES |
266 #define SkCodecPrintf SkDebugf | 279 #define SkCodecPrintf SkDebugf |
267 #else | 280 #else |
268 #define SkCodecPrintf(...) | 281 #define SkCodecPrintf(...) |
269 #endif | 282 #endif |
270 | 283 |
271 #endif // SkCodecPriv_DEFINED | 284 #endif // SkCodecPriv_DEFINED |
OLD | NEW |