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

Unified Diff: src/codec/SkCodecPriv.h

Issue 1835083002: Support RGBA/BGRA swizzles using SkEncodedInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@skencodedinfo
Patch Set: Fix bugs 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkGifCodec.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodecPriv.h
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
index 2b22922b0c9b158c148b3c0271a0913ccaa2f3bc..8398d5b8e74af219a8639e40defccc405bfec8cd 100644
--- a/src/codec/SkCodecPriv.h
+++ b/src/codec/SkCodecPriv.h
@@ -132,7 +132,8 @@ inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src)
// Check for supported color types
switch (dst.colorType()) {
- case kN32_SkColorType:
+ case kRGBA_8888_SkColorType:
+ case kBGRA_8888_SkColorType:
return true;
case kRGB_565_SkColorType:
return kOpaque_SkAlphaType == dst.alphaType();
@@ -275,4 +276,52 @@ inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) {
return (data[0] << 8) | (data[1]);
}
+inline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
+ if (a != 255) {
+ r = SkMulDiv255Round(r, a);
+ g = SkMulDiv255Round(g, a);
+ b = SkMulDiv255Round(b, a);
+ }
+
+ return SkPackARGB_as_RGBA(a, r, g, b);
+}
+
+inline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
+ if (a != 255) {
+ r = SkMulDiv255Round(r, a);
+ g = SkMulDiv255Round(g, a);
+ b = SkMulDiv255Round(b, a);
+ }
+
+ return SkPackARGB_as_BGRA(a, r, g, b);
+}
+
+inline bool is_rgba(SkColorType colorType) {
+#ifdef SK_PMCOLOR_IS_RGBA
+ return (kBGRA_8888_SkColorType != colorType);
+#else
+ return (kRGBA_8888_SkColorType == colorType);
+#endif
+}
+
+// Method for coverting to a 32 bit pixel.
+typedef uint32_t (*PackColorProc)(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
+
+inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType colorType) {
+ bool isRGBA = is_rgba(colorType);
+ if (isPremul) {
+ if (isRGBA) {
+ return &premultiply_argb_as_rgba;
+ } else {
+ return &premultiply_argb_as_bgra;
+ }
+ } else {
+ if (isRGBA) {
+ return &SkPackARGB_as_RGBA;
+ } else {
+ return &SkPackARGB_as_BGRA;
+ }
+ }
+}
+
#endif // SkCodecPriv_DEFINED
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkGifCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698