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

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

Issue 1406223002: Create an SkAndroidCodec API separate from SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
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 // FIXME: Consider sharing with dm, nanbench, and tools.
35 inline float get_scale_from_sample_size(int sampleSize) {
36 return 1.0f / ((float) sampleSize);
37 }
38
39 inline bool is_valid_subset(const SkIRect& subset, const SkISize& imageDims) {
40 return SkIRect::MakeSize(imageDims).contains(subset);
41 }
42
34 /* 43 /*
35 * returns a scaled dimension based on the original dimension and the sampleSize 44 * 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 45 * NOTE: we round down here for scaled dimension to match the behavior of SkImag eDecoder
46 * FIXME: I think we should call this get_sampled_dimension().
37 */ 47 */
38 inline int get_scaled_dimension(int srcDimension, int sampleSize) { 48 inline int get_scaled_dimension(int srcDimension, int sampleSize) {
39 if (sampleSize > srcDimension) { 49 if (sampleSize > srcDimension) {
40 return 1; 50 return 1;
41 } 51 }
42 return srcDimension / sampleSize; 52 return srcDimension / sampleSize;
43 } 53 }
44 54
45 /* 55 /*
46 * Returns the first coordinate that we will keep during a scaled decode. 56 * Returns the first coordinate that we will keep during a scaled decode.
(...skipping 10 matching lines...) Expand all
57 * The output can be interpreted as an x-coordinate or a y-coordinate. 67 * The output can be interpreted as an x-coordinate or a y-coordinate.
58 * 68 *
59 * This does not need to be called and is not called when sampleFactor == 1. 69 * This does not need to be called and is not called when sampleFactor == 1.
60 */ 70 */
61 inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; }; 71 inline int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; };
62 72
63 /* 73 /*
64 * When scaling, we will discard certain y-coordinates (rows) and 74 * When scaling, we will discard certain y-coordinates (rows) and
65 * x-coordinates (columns). This function returns true if we should keep the 75 * x-coordinates (columns). This function returns true if we should keep the
66 * coordinate and false otherwise. 76 * coordinate and false otherwise.
67 * The inputs may be x-coordinates or y-coordinates. 77 *
78 * The inputs may be x-coordinates or y-coordinates, but for clarity, it helps
79 * to name variables using y-coordinate naming conventions. This is an
80 * arbitrary choice.
68 * 81 *
69 * This does not need to be called and is not called when sampleFactor == 1. 82 * This does not need to be called and is not called when sampleFactor == 1.
83 *
84 * @param srcY Unscaled, original y-coordinate
85 * @param sampleY Sampling factor used in the y-dimension
86 * @param scaledSubsetHeight Height of the final output, after any scaling or su bsetting
87 * @param subsetY Top of the subset as an unscaled, original y-coordi nate
70 */ 88 */
71 inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) { 89 inline bool is_coord_necessary(int srcY, int sampleY, int scaledSubsetHeight, in t subsetY) {
72 // Get the first coordinate that we want to keep 90 // Get the first coordinate that we want to keep
73 int startCoord = get_start_coord(sampleFactor); 91 int startY = get_start_coord(sampleY) + subsetY;
74 92
75 // Return false on edge cases 93 // Return false on edge cases
76 if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaled Dim) { 94 if (srcY < startY || get_dst_coord(srcY - subsetY, sampleY) >= scaledSubsetH eight) {
77 return false; 95 return false;
78 } 96 }
79 97
80 // Every sampleFactor rows are necessary 98 // Every sampleY rows are necessary
81 return ((srcCoord - startCoord) % sampleFactor) == 0; 99 return ((srcY - startY) % sampleY) == 0;
82 } 100 }
83 101
84 inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { 102 inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
85 // Check for supported alpha types 103 // Check for supported alpha types
86 if (srcAlpha != dstAlpha) { 104 if (srcAlpha != dstAlpha) {
87 if (kOpaque_SkAlphaType == srcAlpha) { 105 if (kOpaque_SkAlphaType == srcAlpha) {
88 // If the source is opaque, we must decode to opaque 106 // If the source is opaque, we must decode to opaque
89 return false; 107 return false;
90 } 108 }
91 109
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 #endif 255 #endif
238 } 256 }
239 257
240 #ifdef SK_PRINT_CODEC_MESSAGES 258 #ifdef SK_PRINT_CODEC_MESSAGES
241 #define SkCodecPrintf SkDebugf 259 #define SkCodecPrintf SkDebugf
242 #else 260 #else
243 #define SkCodecPrintf(...) 261 #define SkCodecPrintf(...)
244 #endif 262 #endif
245 263
246 #endif // SkCodecPriv_DEFINED 264 #endif // SkCodecPriv_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698