| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // Use fix point multiplier instead of integer division or floating poin
t math. | 168 // Use fix point multiplier instead of integer division or floating poin
t math. |
| 169 // This multipler produces exactly the same result for all values in ran
ge 0 - 255. | 169 // This multipler produces exactly the same result for all values in ran
ge 0 - 255. |
| 170 static const unsigned fixPointShift = 24; | 170 static const unsigned fixPointShift = 24; |
| 171 static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 *
(1 << fixPointShift)) + 1; | 171 static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 *
(1 << fixPointShift)) + 1; |
| 172 // Multiplies unsigned value by fixpoint value and converts back to unsi
gned. | 172 // Multiplies unsigned value by fixpoint value and converts back to unsi
gned. |
| 173 static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v) | 173 static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v) |
| 174 { | 174 { |
| 175 return (fixed * v) >> fixPointShift; | 175 return (fixed * v) >> fixPointShift; |
| 176 } | 176 } |
| 177 | 177 |
| 178 inline void setRGB(PixelData* dest, unsigned r, unsigned g, unsigned b) |
| 179 { |
| 180 *dest = SkPackARGB32NoCheck(255, r, g, b); |
| 181 } |
| 182 |
| 178 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b,
unsigned a) | 183 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b,
unsigned a) |
| 179 { | 184 { |
| 180 if (m_premultiplyAlpha && a < 255) { | 185 if (m_premultiplyAlpha) |
| 181 if (!a) { | 186 setRGBAPremultiply(dest, a, r, g, b); |
| 182 *dest = 0; | 187 else |
| 183 return; | 188 setRGBANoPremultiply(dest, a, r, g, b); |
| 184 } | 189 } |
| 185 | 190 |
| 191 inline void setRGBAPremultiply(PixelData* dest, unsigned r, unsigned g,
unsigned b, unsigned a) |
| 192 { |
| 193 ASSERT(m_premultiplyAlpha); |
| 194 |
| 195 if (!a) { |
| 196 *dest = 0; |
| 197 return; |
| 198 } |
| 199 if (a < 255) { |
| 186 unsigned alphaMult = a * fixPointMult; | 200 unsigned alphaMult = a * fixPointMult; |
| 187 r = fixPointUnsignedMultiply(r, alphaMult); | 201 r = fixPointUnsignedMultiply(r, alphaMult); |
| 188 g = fixPointUnsignedMultiply(g, alphaMult); | 202 g = fixPointUnsignedMultiply(g, alphaMult); |
| 189 b = fixPointUnsignedMultiply(b, alphaMult); | 203 b = fixPointUnsignedMultiply(b, alphaMult); |
| 190 } | 204 } |
| 205 |
| 191 // Call the "NoCheck" version since we may deliberately pass non-pre
multiplied | 206 // Call the "NoCheck" version since we may deliberately pass non-pre
multiplied |
| 192 // values, and we don't want an assert. | 207 // values, and we don't want an assert. |
| 193 *dest = SkPackARGB32NoCheck(a, r, g, b); | 208 *dest = SkPackARGB32NoCheck(a, r, g, b); |
| 194 } | 209 } |
| 195 | 210 |
| 211 inline void setRGBANoPremultiply(PixelData* dest, unsigned r, unsigned g
, unsigned b, unsigned a) |
| 212 { |
| 213 ASSERT(!m_premultiplyAlpha); |
| 214 |
| 215 *dest = SkPackARGB32NoCheck(a, r, g, b); |
| 216 } |
| 217 |
| 218 inline void setInvertedCMYK(PixelData* dest, unsigned c, unsigned m, uns
igned y, unsigned k) |
| 219 { |
| 220 unsigned kMult = k * fixPointMult; |
| 221 unsigned r = fixPointUnsignedMultiply(c, kMult); |
| 222 unsigned g = fixPointUnsignedMultiply(m, kMult); |
| 223 unsigned b = fixPointUnsignedMultiply(y, kMult); |
| 224 |
| 225 *dest = SkPackARGB32NoCheck(255, r, g, b); |
| 226 } |
| 227 |
| 196 private: | 228 private: |
| 197 int width() const | 229 int width() const |
| 198 { | 230 { |
| 199 return m_bitmap->bitmap().width(); | 231 return m_bitmap->bitmap().width(); |
| 200 } | 232 } |
| 201 | 233 |
| 202 int height() const | 234 int height() const |
| 203 { | 235 { |
| 204 return m_bitmap->bitmap().height(); | 236 return m_bitmap->bitmap().height(); |
| 205 } | 237 } |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 474 |
| 443 IntSize m_size; | 475 IntSize m_size; |
| 444 bool m_sizeAvailable; | 476 bool m_sizeAvailable; |
| 445 bool m_isAllDataReceived; | 477 bool m_isAllDataReceived; |
| 446 bool m_failed; | 478 bool m_failed; |
| 447 }; | 479 }; |
| 448 | 480 |
| 449 } // namespace WebCore | 481 } // namespace WebCore |
| 450 | 482 |
| 451 #endif | 483 #endif |
| OLD | NEW |