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

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

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows errors Created 5 years, 3 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/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodec_libgif.cpp » ('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 12 matching lines...) Expand all
23 uint8_t zeroAlpha = 0; \ 23 uint8_t zeroAlpha = 0; \
24 uint8_t maxAlpha = 0xFF; 24 uint8_t maxAlpha = 0xFF;
25 25
26 #define UPDATE_RESULT_ALPHA(alpha) \ 26 #define UPDATE_RESULT_ALPHA(alpha) \
27 zeroAlpha |= (alpha); \ 27 zeroAlpha |= (alpha); \
28 maxAlpha &= (alpha); 28 maxAlpha &= (alpha);
29 29
30 #define COMPUTE_RESULT_ALPHA \ 30 #define COMPUTE_RESULT_ALPHA \
31 SkSwizzler::GetResult(zeroAlpha, maxAlpha); 31 SkSwizzler::GetResult(zeroAlpha, maxAlpha);
32 32
33 /*
34 * Returns the first coordinate that we will keep during a scaled decode.
35 * The output can be interpreted as an x-coordinate or a y-coordinate.
36 *
37 * This does not need to be called and is not called when sampleFactor == 1.
38 */
39 static int get_start_coord(int sampleFactor) { return sampleFactor / 2; };
40
41 /*
42 * Given a coordinate in the original image, this returns the corresponding
43 * coordinate in the scaled image. This function is meaningless if
44 * IsCoordNecessary returns false.
45 * The output can be interpreted as an x-coordinate or a y-coordinate.
46 *
47 * This does not need to be called and is not called when sampleFactor == 1.
48 */
49 static int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sam pleFactor; };
50
51 /*
52 * When scaling, we will discard certain y-coordinates (rows) and
53 * x-coordinates (columns). This function returns true if we should keep the
54 * coordinate and false otherwise.
55 * The inputs may be x-coordinates or y-coordinates.
56 *
57 * This does not need to be called and is not called when sampleFactor == 1.
58 */
59 static bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) {
60 // Get the first coordinate that we want to keep
61 int startCoord = get_start_coord(sampleFactor);
62
63 // Return false on edge cases
64 if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaled Dim) {
65 return false;
66 }
67
68 // Every sampleFactor rows are necessary
69 return ((srcCoord - startCoord) % sampleFactor) == 0;
70 }
71
33 static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { 72 static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
34 // Check for supported alpha types 73 // Check for supported alpha types
35 if (srcAlpha != dstAlpha) { 74 if (srcAlpha != dstAlpha) {
36 if (kOpaque_SkAlphaType == srcAlpha) { 75 if (kOpaque_SkAlphaType == srcAlpha) {
37 // If the source is opaque, we must decode to opaque 76 // If the source is opaque, we must decode to opaque
38 return false; 77 return false;
39 } 78 }
40 79
41 // The source is not opaque 80 // The source is not opaque
42 switch (dstAlpha) { 81 switch (dstAlpha) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 164 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
126 return compute_row_bytes_ppb(width, pixelsPerByte); 165 return compute_row_bytes_ppb(width, pixelsPerByte);
127 } else { 166 } else {
128 SkASSERT(0 == bitsPerPixel % 8); 167 SkASSERT(0 == bitsPerPixel % 8);
129 const uint32_t bytesPerPixel = bitsPerPixel / 8; 168 const uint32_t bytesPerPixel = bitsPerPixel / 8;
130 return compute_row_bytes_bpp(width, bytesPerPixel); 169 return compute_row_bytes_bpp(width, bytesPerPixel);
131 } 170 }
132 } 171 }
133 172
134 /* 173 /*
174 * On incomplete images, get the color to fill with
175 */
176 static inline SkPMColor get_fill_color_or_index(SkAlphaType alphaType) {
177 // This condition works properly for all supported output color types.
178 // kIndex8: The low 8-bits of both possible return values is 0, which is
179 // our desired default index.
180 // kGray8: The low 8-bits of both possible return values is 0, which is
181 // black, our desired fill value.
182 // kRGB565: The low 16-bits of both possible return values is 0, which is
183 // black, our desired fill value.
184 // kN32: Return black for opaque images and transparent for non-opaque
185 // images.
186 return kOpaque_SkAlphaType == alphaType ?
187 SK_ColorBLACK : SK_ColorTRANSPARENT;
188 }
189
190 /*
135 * Get a byte from a buffer 191 * Get a byte from a buffer
136 * This method is unsafe, the caller is responsible for performing a check 192 * This method is unsafe, the caller is responsible for performing a check
137 */ 193 */
138 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { 194 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) {
139 return buffer[i]; 195 return buffer[i];
140 } 196 }
141 197
142 /* 198 /*
143 * Get a short from a buffer 199 * Get a short from a buffer
144 * This method is unsafe, the caller is responsible for performing a check 200 * This method is unsafe, the caller is responsible for performing a check
(...skipping 22 matching lines...) Expand all
167 #endif 223 #endif
168 } 224 }
169 225
170 #ifdef SK_PRINT_CODEC_MESSAGES 226 #ifdef SK_PRINT_CODEC_MESSAGES
171 #define SkCodecPrintf SkDebugf 227 #define SkCodecPrintf SkDebugf
172 #else 228 #else
173 #define SkCodecPrintf(...) 229 #define SkCodecPrintf(...)
174 #endif 230 #endif
175 231
176 #endif // SkCodecPriv_DEFINED 232 #endif // SkCodecPriv_DEFINED
OLDNEW
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodec_libgif.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698