OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
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 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 const int width = srcInfo.width(); | 147 const int width = srcInfo.width(); |
148 const int height = srcInfo.height(); | 148 const int height = srcInfo.height(); |
149 | 149 |
150 // Handle fancy alpha swizzling if both are ARGB32 | 150 // Handle fancy alpha swizzling if both are ARGB32 |
151 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { | 151 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { |
152 SkDstPixelInfo dstPI; | 152 SkDstPixelInfo dstPI; |
153 dstPI.fColorType = dstInfo.colorType(); | 153 dstPI.fColorType = dstInfo.colorType(); |
154 dstPI.fAlphaType = dstInfo.alphaType(); | 154 dstPI.fAlphaType = dstInfo.alphaType(); |
155 dstPI.fPixels = dstPixels; | 155 dstPI.fPixels = dstPixels; |
156 dstPI.fRowBytes = dstRB; | 156 dstPI.fRowBytes = dstRB; |
157 | 157 |
158 SkSrcPixelInfo srcPI; | 158 SkSrcPixelInfo srcPI; |
159 srcPI.fColorType = srcInfo.colorType(); | 159 srcPI.fColorType = srcInfo.colorType(); |
160 srcPI.fAlphaType = srcInfo.alphaType(); | 160 srcPI.fAlphaType = srcInfo.alphaType(); |
161 srcPI.fPixels = srcPixels; | 161 srcPI.fPixels = srcPixels; |
162 srcPI.fRowBytes = srcRB; | 162 srcPI.fRowBytes = srcRB; |
163 | 163 |
164 return srcPI.convertPixelsTo(&dstPI, width, height); | 164 return srcPI.convertPixelsTo(&dstPI, width, height); |
165 } | 165 } |
166 | 166 |
167 // If they agree on colorType and the alphaTypes are compatible, then we jus
t memcpy. | 167 // If they agree on colorType and the alphaTypes are compatible, then we jus
t memcpy. |
168 // Note: we've already taken care of 32bit colortypes above. | 168 // Note: we've already taken care of 32bit colortypes above. |
169 if (srcInfo.colorType() == dstInfo.colorType()) { | 169 if (srcInfo.colorType() == dstInfo.colorType()) { |
170 switch (srcInfo.colorType()) { | 170 switch (srcInfo.colorType()) { |
171 case kRGB_565_SkColorType: | 171 case kRGB_565_SkColorType: |
172 case kAlpha_8_SkColorType: | 172 case kAlpha_8_SkColorType: |
173 break; | 173 break; |
(...skipping 15 matching lines...) Expand all Loading... |
189 * are supported. | 189 * are supported. |
190 */ | 190 */ |
191 | 191 |
192 // Can no longer draw directly into 4444, but we can manually whack it for a
few combinations | 192 // Can no longer draw directly into 4444, but we can manually whack it for a
few combinations |
193 if (kARGB_4444_SkColorType == dstInfo.colorType() && | 193 if (kARGB_4444_SkColorType == dstInfo.colorType() && |
194 (kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcI
nfo.colorType())) { | 194 (kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcI
nfo.colorType())) { |
195 if (srcInfo.alphaType() == kUnpremul_SkAlphaType) { | 195 if (srcInfo.alphaType() == kUnpremul_SkAlphaType) { |
196 // Our method for converting to 4444 assumes premultiplied. | 196 // Our method for converting to 4444 assumes premultiplied. |
197 return false; | 197 return false; |
198 } | 198 } |
199 | 199 |
200 const SkPMColor* table = NULL; | 200 const SkPMColor* table = NULL; |
201 if (kIndex_8_SkColorType == srcInfo.colorType()) { | 201 if (kIndex_8_SkColorType == srcInfo.colorType()) { |
202 if (NULL == ctable) { | 202 if (NULL == ctable) { |
203 return false; | 203 return false; |
204 } | 204 } |
205 table = ctable->lockColors(); | 205 table = ctable->readColors(); |
206 } | 206 } |
207 | 207 |
208 for (int y = 0; y < height; ++y) { | 208 for (int y = 0; y < height; ++y) { |
209 DITHER_4444_SCAN(y); | 209 DITHER_4444_SCAN(y); |
210 SkPMColor16* SK_RESTRICT dstRow = (SkPMColor16*)dstPixels; | 210 SkPMColor16* SK_RESTRICT dstRow = (SkPMColor16*)dstPixels; |
211 if (table) { | 211 if (table) { |
212 const uint8_t* SK_RESTRICT srcRow = (const uint8_t*)srcPixels; | 212 const uint8_t* SK_RESTRICT srcRow = (const uint8_t*)srcPixels; |
213 for (int x = 0; x < width; ++x) { | 213 for (int x = 0; x < width; ++x) { |
214 dstRow[x] = SkDitherARGB32To4444(table[srcRow[x]], DITHER_VA
LUE(x)); | 214 dstRow[x] = SkDitherARGB32To4444(table[srcRow[x]], DITHER_VA
LUE(x)); |
215 } | 215 } |
216 } else { | 216 } else { |
217 const SkPMColor* SK_RESTRICT srcRow = (const SkPMColor*)srcPixel
s; | 217 const SkPMColor* SK_RESTRICT srcRow = (const SkPMColor*)srcPixel
s; |
218 for (int x = 0; x < width; ++x) { | 218 for (int x = 0; x < width; ++x) { |
219 dstRow[x] = SkDitherARGB32To4444(srcRow[x], DITHER_VALUE(x))
; | 219 dstRow[x] = SkDitherARGB32To4444(srcRow[x], DITHER_VALUE(x))
; |
220 } | 220 } |
221 } | 221 } |
222 dstPixels = (char*)dstPixels + dstRB; | 222 dstPixels = (char*)dstPixels + dstRB; |
223 srcPixels = (const char*)srcPixels + srcRB; | 223 srcPixels = (const char*)srcPixels + srcRB; |
224 } | 224 } |
225 | |
226 if (table) { | |
227 ctable->unlockColors(); | |
228 } | |
229 return true; | 225 return true; |
230 } | 226 } |
231 | 227 |
232 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 228 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
233 // We do not support drawing to unpremultiplied bitmaps. | 229 // We do not support drawing to unpremultiplied bitmaps. |
234 return false; | 230 return false; |
235 } | 231 } |
236 | 232 |
237 // Final fall-back, draw with a canvas | 233 // Final fall-back, draw with a canvas |
238 // | 234 // |
(...skipping 11 matching lines...) Expand all Loading... |
250 | 246 |
251 SkPaint paint; | 247 SkPaint paint; |
252 paint.setDither(true); | 248 paint.setDither(true); |
253 | 249 |
254 canvas->clear(0); | 250 canvas->clear(0); |
255 canvas->drawBitmap(bm, 0, 0, &paint); | 251 canvas->drawBitmap(bm, 0, 0, &paint); |
256 return true; | 252 return true; |
257 } | 253 } |
258 } | 254 } |
259 | 255 |
OLD | NEW |