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

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

Issue 1907593004: Support the non-native (RGBA/BGRA) swizzle (Closed) Base URL: https://skia.googlesource.com/skia.git@tryagain
Patch Set: Rebase Created 4 years, 8 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // will treat the encoded data as linear regardless of what the client 121 // will treat the encoded data as linear regardless of what the client
122 // requests. 122 // requests.
123 123
124 // Ensure the alpha type is valid 124 // Ensure the alpha type is valid
125 if (!valid_alpha(dst.alphaType(), src.alphaType())) { 125 if (!valid_alpha(dst.alphaType(), src.alphaType())) {
126 return false; 126 return false;
127 } 127 }
128 128
129 // Check for supported color types 129 // Check for supported color types
130 switch (dst.colorType()) { 130 switch (dst.colorType()) {
131 case kN32_SkColorType: 131 case kRGBA_8888_SkColorType:
132 case kBGRA_8888_SkColorType:
132 return true; 133 return true;
133 case kRGB_565_SkColorType: 134 case kRGB_565_SkColorType:
134 return kOpaque_SkAlphaType == dst.alphaType(); 135 return kOpaque_SkAlphaType == dst.alphaType();
135 case kGray_8_SkColorType: 136 case kGray_8_SkColorType:
136 if (kOpaque_SkAlphaType != dst.alphaType()) { 137 if (kOpaque_SkAlphaType != dst.alphaType()) {
137 return false; 138 return false;
138 } 139 }
139 // Fall through 140 // Fall through
140 default: 141 default:
141 return dst.colorType() == src.colorType(); 142 return dst.colorType() == src.colorType();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 265 }
265 266
266 inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) { 267 inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) {
267 if (littleEndian) { 268 if (littleEndian) {
268 return (data[1] << 8) | (data[0]); 269 return (data[1] << 8) | (data[0]);
269 } 270 }
270 271
271 return (data[0] << 8) | (data[1]); 272 return (data[0] << 8) | (data[1]);
272 } 273 }
273 274
275 inline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
276 if (a != 255) {
277 r = SkMulDiv255Round(r, a);
278 g = SkMulDiv255Round(g, a);
279 b = SkMulDiv255Round(b, a);
280 }
281
282 return SkPackARGB_as_RGBA(a, r, g, b);
283 }
284
285 inline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
286 if (a != 255) {
287 r = SkMulDiv255Round(r, a);
288 g = SkMulDiv255Round(g, a);
289 b = SkMulDiv255Round(b, a);
290 }
291
292 return SkPackARGB_as_BGRA(a, r, g, b);
293 }
294
295 inline bool is_rgba(SkColorType colorType) {
296 #ifdef SK_PMCOLOR_IS_RGBA
297 return (kBGRA_8888_SkColorType != colorType);
298 #else
299 return (kRGBA_8888_SkColorType == colorType);
300 #endif
301 }
302
303 // Method for coverting to a 32 bit pixel.
304 typedef uint32_t (*PackColorProc)(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
305
306 inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType colorType ) {
307 bool isRGBA = is_rgba(colorType);
308 if (isPremul) {
309 if (isRGBA) {
310 return &premultiply_argb_as_rgba;
311 } else {
312 return &premultiply_argb_as_bgra;
313 }
314 } else {
315 if (isRGBA) {
316 return &SkPackARGB_as_RGBA;
317 } else {
318 return &SkPackARGB_as_BGRA;
319 }
320 }
321 }
322
274 #endif // SkCodecPriv_DEFINED 323 #endif // SkCodecPriv_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698