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

Side by Side Diff: src/core/SkUnPreMultiply.cpp

Issue 130303005: Factor out UnPreMultiplyPreservingByteOrder (Closed) Base URL: https://skia.googlesource.com/skia.git@dm-r
Patch Set: Created 6 years, 11 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
« no previous file with comments | « include/core/SkUnPreMultiply.h ('k') | src/ports/SkImageDecoder_CG.cpp » ('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 2011 Google Inc. 3 * Copyright 2011 Google Inc.
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 #include "SkUnPreMultiply.h" 8 #include "SkUnPreMultiply.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 10
11 SkColor SkUnPreMultiply::PMColorToColor(SkPMColor c) { 11 SkColor SkUnPreMultiply::PMColorToColor(SkPMColor c) {
12 const unsigned a = SkGetPackedA32(c); 12 const unsigned a = SkGetPackedA32(c);
13 const Scale scale = GetScale(a); 13 const Scale scale = GetScale(a);
14 return SkColorSetARGB(a, 14 return SkColorSetARGB(a,
15 ApplyScale(scale, SkGetPackedR32(c)), 15 ApplyScale(scale, SkGetPackedR32(c)),
16 ApplyScale(scale, SkGetPackedG32(c)), 16 ApplyScale(scale, SkGetPackedG32(c)),
17 ApplyScale(scale, SkGetPackedB32(c))); 17 ApplyScale(scale, SkGetPackedB32(c)));
18 } 18 }
19 19
20 uint32_t SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(SkPMColor c) {
21 const U8CPU a = SkGetPackedA32(c);
22 const Scale scale = GetScale(a);
23 return SkPackARGB32NoCheck(a,
24 ApplyScale(scale, SkGetPackedR32(c)),
25 ApplyScale(scale, SkGetPackedG32(c)),
26 ApplyScale(scale, SkGetPackedB32(c)));
27 }
28
20 const uint32_t SkUnPreMultiply::gTable[] = { 29 const uint32_t SkUnPreMultiply::gTable[] = {
21 0x00000000, 0xFF000000, 0x7F800000, 0x55000000, 0x3FC00000, 0x33000000, 0x2A 800000, 0x246DB6DB, 30 0x00000000, 0xFF000000, 0x7F800000, 0x55000000, 0x3FC00000, 0x33000000, 0x2A 800000, 0x246DB6DB,
22 0x1FE00000, 0x1C555555, 0x19800000, 0x172E8BA3, 0x15400000, 0x139D89D9, 0x12 36DB6E, 0x11000000, 31 0x1FE00000, 0x1C555555, 0x19800000, 0x172E8BA3, 0x15400000, 0x139D89D9, 0x12 36DB6E, 0x11000000,
23 0x0FF00000, 0x0F000000, 0x0E2AAAAB, 0x0D6BCA1B, 0x0CC00000, 0x0C249249, 0x0B 9745D1, 0x0B1642C8, 32 0x0FF00000, 0x0F000000, 0x0E2AAAAB, 0x0D6BCA1B, 0x0CC00000, 0x0C249249, 0x0B 9745D1, 0x0B1642C8,
24 0x0AA00000, 0x0A333333, 0x09CEC4EC, 0x0971C71C, 0x091B6DB7, 0x08CB08D4, 0x08 800000, 0x0839CE74, 33 0x0AA00000, 0x0A333333, 0x09CEC4EC, 0x0971C71C, 0x091B6DB7, 0x08CB08D4, 0x08 800000, 0x0839CE74,
25 0x07F80000, 0x07BA2E8C, 0x07800000, 0x07492492, 0x07155555, 0x06E45307, 0x06 B5E50D, 0x0689D89E, 34 0x07F80000, 0x07BA2E8C, 0x07800000, 0x07492492, 0x07155555, 0x06E45307, 0x06 B5E50D, 0x0689D89E,
26 0x06600000, 0x063831F4, 0x06124925, 0x05EE23B9, 0x05CBA2E9, 0x05AAAAAB, 0x05 8B2164, 0x056CEFA9, 35 0x06600000, 0x063831F4, 0x06124925, 0x05EE23B9, 0x05CBA2E9, 0x05AAAAAB, 0x05 8B2164, 0x056CEFA9,
27 0x05500000, 0x05343EB2, 0x0519999A, 0x05000000, 0x04E76276, 0x04CFB2B8, 0x04 B8E38E, 0x04A2E8BA, 36 0x05500000, 0x05343EB2, 0x0519999A, 0x05000000, 0x04E76276, 0x04CFB2B8, 0x04 B8E38E, 0x04A2E8BA,
28 0x048DB6DB, 0x0479435E, 0x0465846A, 0x045270D0, 0x04400000, 0x042E29F8, 0x04 1CE73A, 0x040C30C3, 37 0x048DB6DB, 0x0479435E, 0x0465846A, 0x045270D0, 0x04400000, 0x042E29F8, 0x04 1CE73A, 0x040C30C3,
29 0x03FC0000, 0x03EC4EC5, 0x03DD1746, 0x03CE540F, 0x03C00000, 0x03B21643, 0x03 A49249, 0x03976FC6, 38 0x03FC0000, 0x03EC4EC5, 0x03DD1746, 0x03CE540F, 0x03C00000, 0x03B21643, 0x03 A49249, 0x03976FC6,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // test the result 80 // test the result
72 for (int j = 1; j <= i; j++) { 81 for (int j = 1; j <= i; j++) {
73 uint32_t test = (j * scale + (1 << 23)) >> 24; 82 uint32_t test = (j * scale + (1 << 23)) >> 24;
74 uint32_t div = roundf(j * 255.0f / i); 83 uint32_t div = roundf(j * 255.0f / i);
75 int diff = SkAbs32(test - div); 84 int diff = SkAbs32(test - div);
76 SkASSERT(diff <= 1 && test <= 255); 85 SkASSERT(diff <= 1 && test <= 255);
77 } 86 }
78 } 87 }
79 } 88 }
80 #endif 89 #endif
OLDNEW
« no previous file with comments | « include/core/SkUnPreMultiply.h ('k') | src/ports/SkImageDecoder_CG.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698