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

Side by Side Diff: include/core/SkColorPriv.h

Issue 15602003: add SkLerpXfermode (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « gyp/gmslides.gypi ('k') | include/effects/SkLerpXfermode.h » ('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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkColorPriv_DEFINED 10 #ifndef SkColorPriv_DEFINED
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 U8CPU srcWeight) { 266 U8CPU srcWeight) {
267 unsigned scale = SkAlpha255To256(srcWeight); 267 unsigned scale = SkAlpha255To256(srcWeight);
268 return SkFourByteInterp256(src, dst, scale); 268 return SkFourByteInterp256(src, dst, scale);
269 } 269 }
270 270
271 /** 271 /**
272 * 32b optimized version; currently appears to be 10% faster even on 64b 272 * 32b optimized version; currently appears to be 10% faster even on 64b
273 * architectures than an equivalent 64b version and 30% faster than 273 * architectures than an equivalent 64b version and 30% faster than
274 * SkFourByteInterp(). Third parameter controls blending of the first two: 274 * SkFourByteInterp(). Third parameter controls blending of the first two:
275 * (src, dst, 0) returns dst 275 * (src, dst, 0) returns dst
276 * (src, dst, 0xFF) returns src 276 * (src, dst, 256) returns src
277 * ** Does not match the results of SkFourByteInterp() because we use 277 * ** Does not match the results of SkFourByteInterp256() because we use
278 * a more accurate scale computation! 278 * a more accurate scale computation!
279 * TODO: migrate Skia function to using an accurate 255->266 alpha 279 * TODO: migrate Skia function to using an accurate 255->266 alpha
280 * conversion. 280 * conversion.
281 */ 281 */
282 static inline SkPMColor SkFastFourByteInterp(SkPMColor src, 282 static inline SkPMColor SkFastFourByteInterp256(SkPMColor src,
283 SkPMColor dst, 283 SkPMColor dst,
284 U8CPU srcWeight) { 284 unsigned scale) {
285 SkASSERT(srcWeight < 256); 285 SkASSERT(scale <= 256);
286 286
287 // Reorders ARGB to AG-RB in order to reduce the number of operations. 287 // Reorders ARGB to AG-RB in order to reduce the number of operations.
288 const uint32_t mask = 0xFF00FF; 288 const uint32_t mask = 0xFF00FF;
289 uint32_t src_rb = src & mask; 289 uint32_t src_rb = src & mask;
290 uint32_t src_ag = (src >> 8) & mask; 290 uint32_t src_ag = (src >> 8) & mask;
291 uint32_t dst_rb = dst & mask; 291 uint32_t dst_rb = dst & mask;
292 uint32_t dst_ag = (dst >> 8) & mask; 292 uint32_t dst_ag = (dst >> 8) & mask;
293 293
294 // scale = srcWeight + (srcWeight >> 7) is more accurate than
295 // scale = srcWeight + 1, but 7% slower
296 int scale = srcWeight + (srcWeight >> 7);
297
298 uint32_t ret_rb = src_rb * scale + (256 - scale) * dst_rb; 294 uint32_t ret_rb = src_rb * scale + (256 - scale) * dst_rb;
299 uint32_t ret_ag = src_ag * scale + (256 - scale) * dst_ag; 295 uint32_t ret_ag = src_ag * scale + (256 - scale) * dst_ag;
300 296
301 return (ret_ag & ~mask) | ((ret_rb & ~mask) >> 8); 297 return (ret_ag & ~mask) | ((ret_rb & ~mask) >> 8);
302 } 298 }
303 299
300 static inline SkPMColor SkFastFourByteInterp(SkPMColor src,
301 SkPMColor dst,
302 U8CPU srcWeight) {
303 SkASSERT(srcWeight <= 255);
304 // scale = srcWeight + (srcWeight >> 7) is more accurate than
305 // scale = srcWeight + 1, but 7% slower
306 return SkFastFourByteInterp256(src, dst, srcWeight + (srcWeight >> 7));
307 }
308
304 /** 309 /**
305 * Same as SkPackARGB32, but this version guarantees to not check that the 310 * Same as SkPackARGB32, but this version guarantees to not check that the
306 * values are premultiplied in the debug version. 311 * values are premultiplied in the debug version.
307 */ 312 */
308 static inline SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { 313 static inline SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
309 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) | 314 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) |
310 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT); 315 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
311 } 316 }
312 317
313 static inline 318 static inline
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 int srcG = SkColorGetG(color); 859 int srcG = SkColorGetG(color);
855 int srcB = SkColorGetB(color); 860 int srcB = SkColorGetB(color);
856 861
857 for (int i = 0; i < width; i++) { 862 for (int i = 0; i < width; i++) {
858 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], src[i], 863 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], src[i],
859 opaqueDst); 864 opaqueDst);
860 } 865 }
861 } 866 }
862 867
863 #endif 868 #endif
OLDNEW
« no previous file with comments | « gyp/gmslides.gypi ('k') | include/effects/SkLerpXfermode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698