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

Side by Side Diff: src/images/transform_scanline.h

Issue 2325223002: Support RGBA/BGRA Premul/Unpremul from SkPNGImageEncoder (Closed)
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 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 /** 8 /**
9 * Functions to transform scanlines between packed-pixel formats. 9 * Functions to transform scanlines between packed-pixel formats.
10 */ 10 */
(...skipping 30 matching lines...) Expand all
41 const uint16_t* SK_RESTRICT srcP = (const uint16_t*)src; 41 const uint16_t* SK_RESTRICT srcP = (const uint16_t*)src;
42 for (int i = 0; i < width; i++) { 42 for (int i = 0; i < width; i++) {
43 unsigned c = *srcP++; 43 unsigned c = *srcP++;
44 *dst++ = SkPacked16ToR32(c); 44 *dst++ = SkPacked16ToR32(c);
45 *dst++ = SkPacked16ToG32(c); 45 *dst++ = SkPacked16ToG32(c);
46 *dst++ = SkPacked16ToB32(c); 46 *dst++ = SkPacked16ToB32(c);
47 } 47 }
48 } 48 }
49 49
50 /** 50 /**
51 * Transform from kARGB_8888_Config to 3-bytes-per-pixel RGB. 51 * Transform from kRGBA_8888_SkColorType to 3-bytes-per-pixel RGB.
52 * Alpha channel data, if any, is abandoned. 52 * Alpha channel data is abandoned.
53 */ 53 */
54 static void transform_scanline_888(const char* SK_RESTRICT src, int width, 54 static void transform_scanline_RGB1(const char* SK_RESTRICT src, int width,
55 char* SK_RESTRICT dst) { 55 char* SK_RESTRICT dst) {
56 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src; 56 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
57 for (int i = 0; i < width; i++) { 57 for (int i = 0; i < width; i++) {
58 SkPMColor c = *srcP++; 58 SkPMColor c = *srcP++;
59 *dst++ = SkGetPackedR32(c); 59 *dst++ = (c >> 0) & 0xFF;
60 *dst++ = SkGetPackedG32(c); 60 *dst++ = (c >> 8) & 0xFF;
61 *dst++ = SkGetPackedB32(c); 61 *dst++ = (c >> 16) & 0xFF;
62 } 62 }
63 } 63 }
64 64
65 /**
66 * Transform from kBGRA_8888_SkColorType to 3-bytes-per-pixel RGB.
67 * Alpha channel data is abandoned.
68 */
69 static void transform_scanline_BGR1(const char* SK_RESTRICT src, int width,
70 char* SK_RESTRICT dst) {
71 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
72 for (int i = 0; i < width; i++) {
73 SkPMColor c = *srcP++;
74 *dst++ = (c >> 16) & 0xFF;
75 *dst++ = (c >> 8) & 0xFF;
76 *dst++ = (c >> 0) & 0xFF;
77 }
78 }
79
65 /** 80 /**
66 * Transform from kARGB_4444_Config to 3-bytes-per-pixel RGB. 81 * Transform from kARGB_4444_Config to 3-bytes-per-pixel RGB.
67 * Alpha channel data, if any, is abandoned. 82 * Alpha channel data, if any, is abandoned.
68 */ 83 */
69 static void transform_scanline_444(const char* SK_RESTRICT src, int width, 84 static void transform_scanline_444(const char* SK_RESTRICT src, int width,
70 char* SK_RESTRICT dst) { 85 char* SK_RESTRICT dst) {
71 const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src; 86 const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src;
72 for (int i = 0; i < width; i++) { 87 for (int i = 0; i < width; i++) {
73 SkPMColor16 c = *srcP++; 88 SkPMColor16 c = *srcP++;
74 *dst++ = SkPacked4444ToR32(c); 89 *dst++ = SkPacked4444ToR32(c);
75 *dst++ = SkPacked4444ToG32(c); 90 *dst++ = SkPacked4444ToG32(c);
76 *dst++ = SkPacked4444ToB32(c); 91 *dst++ = SkPacked4444ToB32(c);
77 } 92 }
78 } 93 }
79 94
80 /** 95 /**
81 * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA. 96 * Transform from kPremul, kRGBA_8888_SkColorType to 4-bytes-per-pixel unpremult iplied RGBA.
82 * (This would be the identity transformation, except for byte-order and
83 * scaling of RGB based on alpha channel).
84 */ 97 */
85 static void transform_scanline_8888(const char* SK_RESTRICT src, int width, 98 static void transform_scanline_rgbA(const char* SK_RESTRICT src, int width,
86 char* SK_RESTRICT dst) { 99 char* SK_RESTRICT dst) {
87 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src; 100 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
88 const SkUnPreMultiply::Scale* SK_RESTRICT table = 101 const SkUnPreMultiply::Scale* SK_RESTRICT table =
89 SkUnPreMultiply::GetScaleTable(); 102 SkUnPreMultiply::GetScaleTable();
90 103
91 for (int i = 0; i < width; i++) { 104 for (int i = 0; i < width; i++) {
92 SkPMColor c = *srcP++; 105 SkPMColor c = *srcP++;
93 unsigned a = SkGetPackedA32(c); 106 unsigned r = (c >> 0) & 0xFF;
94 unsigned r = SkGetPackedR32(c); 107 unsigned g = (c >> 8) & 0xFF;
95 unsigned g = SkGetPackedG32(c); 108 unsigned b = (c >> 16) & 0xFF;
96 unsigned b = SkGetPackedB32(c); 109 unsigned a = (c >> 24) & 0xFF;
97 110
98 if (0 != a && 255 != a) { 111 if (0 != a && 255 != a) {
99 SkUnPreMultiply::Scale scale = table[a]; 112 SkUnPreMultiply::Scale scale = table[a];
100 r = SkUnPreMultiply::ApplyScale(scale, r); 113 r = SkUnPreMultiply::ApplyScale(scale, r);
101 g = SkUnPreMultiply::ApplyScale(scale, g); 114 g = SkUnPreMultiply::ApplyScale(scale, g);
102 b = SkUnPreMultiply::ApplyScale(scale, b); 115 b = SkUnPreMultiply::ApplyScale(scale, b);
103 } 116 }
104 *dst++ = r; 117 *dst++ = r;
105 *dst++ = g; 118 *dst++ = g;
106 *dst++ = b; 119 *dst++ = b;
107 *dst++ = a; 120 *dst++ = a;
108 } 121 }
109 } 122 }
110 123
111 /** 124 /**
125 * Transform from kPremul, kBGRA_8888_SkColorType to 4-bytes-per-pixel unpremult iplied RGBA.
126 */
127 static void transform_scanline_bgrA(const char* SK_RESTRICT src, int width,
128 char* SK_RESTRICT dst) {
129 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
130 const SkUnPreMultiply::Scale* SK_RESTRICT table =
131 SkUnPreMultiply::GetScaleTable();
132
133 for (int i = 0; i < width; i++) {
134 SkPMColor c = *srcP++;
135 unsigned r = (c >> 16) & 0xFF;
136 unsigned g = (c >> 8) & 0xFF;
137 unsigned b = (c >> 0) & 0xFF;
138 unsigned a = (c >> 24) & 0xFF;
139
140 if (0 != a && 255 != a) {
141 SkUnPreMultiply::Scale scale = table[a];
142 r = SkUnPreMultiply::ApplyScale(scale, r);
143 g = SkUnPreMultiply::ApplyScale(scale, g);
144 b = SkUnPreMultiply::ApplyScale(scale, b);
145 }
146 *dst++ = r;
147 *dst++ = g;
148 *dst++ = b;
149 *dst++ = a;
150 }
151 }
152
153 /**
154 * Transform from kUnpremul, kRGBA_8888_SkColorType to 4-bytes-per-pixel unpremu ltiplied RGBA.
155 */
156 static void transform_scanline_RGBA(const char* SK_RESTRICT src, int width, char * SK_RESTRICT dst) {
157 memcpy(dst, src, sizeof(SkPMColor) * width);
158 }
159
160 /**
161 * Transform from kUnpremul, kBGRA_8888_SkColorType to 4-bytes-per-pixel unpremu ltiplied RGBA.
162 */
163 static void transform_scanline_BGRA(const char* SK_RESTRICT src, int width, char * SK_RESTRICT dst) {
164 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
165 for (int i = 0; i < width; i++) {
166 SkPMColor c = *srcP++;
167 *dst++ = (c >> 0) & 0xFF;
168 *dst++ = (c >> 8) & 0xFF;
169 *dst++ = (c >> 16) & 0xFF;
170 *dst++ = (c >> 24) & 0xFF;
171 }
172 }
173
174 /**
112 * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA, 175 * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA,
113 * with scaling of RGB based on alpha channel. 176 * with scaling of RGB based on alpha channel.
114 */ 177 */
115 static void transform_scanline_4444(const char* SK_RESTRICT src, int width, 178 static void transform_scanline_4444(const char* SK_RESTRICT src, int width,
116 char* SK_RESTRICT dst) { 179 char* SK_RESTRICT dst) {
117 const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src; 180 const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src;
118 const SkUnPreMultiply::Scale* SK_RESTRICT table = 181 const SkUnPreMultiply::Scale* SK_RESTRICT table =
119 SkUnPreMultiply::GetScaleTable(); 182 SkUnPreMultiply::GetScaleTable();
120 183
121 for (int i = 0; i < width; i++) { 184 for (int i = 0; i < width; i++) {
122 SkPMColor16 c = *srcP++; 185 SkPMColor16 c = *srcP++;
123 unsigned a = SkPacked4444ToA32(c); 186 unsigned a = SkPacked4444ToA32(c);
124 unsigned r = SkPacked4444ToR32(c); 187 unsigned r = SkPacked4444ToR32(c);
125 unsigned g = SkPacked4444ToG32(c); 188 unsigned g = SkPacked4444ToG32(c);
126 unsigned b = SkPacked4444ToB32(c); 189 unsigned b = SkPacked4444ToB32(c);
127 190
128 if (0 != a && 255 != a) { 191 if (0 != a && 255 != a) {
129 SkUnPreMultiply::Scale scale = table[a]; 192 SkUnPreMultiply::Scale scale = table[a];
130 r = SkUnPreMultiply::ApplyScale(scale, r); 193 r = SkUnPreMultiply::ApplyScale(scale, r);
131 g = SkUnPreMultiply::ApplyScale(scale, g); 194 g = SkUnPreMultiply::ApplyScale(scale, g);
132 b = SkUnPreMultiply::ApplyScale(scale, b); 195 b = SkUnPreMultiply::ApplyScale(scale, b);
133 } 196 }
134 *dst++ = r; 197 *dst++ = r;
135 *dst++ = g; 198 *dst++ = g;
136 *dst++ = b; 199 *dst++ = b;
137 *dst++ = a; 200 *dst++ = a;
138 } 201 }
139 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698