Chromium Code Reviews| 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 checkAddress(dest); | |
| 181 *dest = SkPackARGB32NoCheck(255, r, g, b); | |
| 182 } | |
| 183 | |
| 178 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) | 184 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 179 { | 185 { |
| 180 if (m_premultiplyAlpha && a < 255) { | 186 if (m_premultiplyAlpha) |
| 181 if (!a) { | 187 setRGBAPremultiply(dest, a, r, g, b); |
| 182 *dest = 0; | 188 else |
| 183 return; | 189 setRGBANoPremultiply(dest, a, r, g, b); |
| 184 } | 190 } |
| 185 | 191 |
| 192 inline void setRGBAPremultiply(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) | |
| 193 { | |
| 194 checkAddress(dest); | |
| 195 ASSERT(m_premultiplyAlpha); | |
| 196 | |
| 197 if (!a) { | |
| 198 *dest = 0; | |
| 199 return; | |
| 200 } | |
| 201 if (a < 255) { | |
| 186 unsigned alphaMult = a * fixPointMult; | 202 unsigned alphaMult = a * fixPointMult; |
| 187 r = fixPointUnsignedMultiply(r, alphaMult); | 203 r = fixPointUnsignedMultiply(r, alphaMult); |
| 188 g = fixPointUnsignedMultiply(g, alphaMult); | 204 g = fixPointUnsignedMultiply(g, alphaMult); |
| 189 b = fixPointUnsignedMultiply(b, alphaMult); | 205 b = fixPointUnsignedMultiply(b, alphaMult); |
| 190 } | 206 } |
| 207 | |
| 191 // Call the "NoCheck" version since we may deliberately pass non-pre multiplied | 208 // Call the "NoCheck" version since we may deliberately pass non-pre multiplied |
| 192 // values, and we don't want an assert. | 209 // values, and we don't want an assert. |
| 193 *dest = SkPackARGB32NoCheck(a, r, g, b); | 210 *dest = SkPackARGB32NoCheck(a, r, g, b); |
| 194 } | 211 } |
| 195 | 212 |
| 213 inline void setRGBANoPremultiply(PixelData* dest, unsigned r, unsigned g , unsigned b, unsigned a) | |
| 214 { | |
| 215 checkAddress(dest); | |
| 216 ASSERT(!m_premultiplyAlpha); | |
| 217 | |
| 218 *dest = SkPackARGB32NoCheck(a, r, g, b); | |
| 219 } | |
| 220 | |
| 221 inline void setInvertedCMYK(PixelData* dest, unsigned c, unsigned m, uns igned y, unsigned k) | |
| 222 { | |
| 223 checkAddress(dest); | |
| 224 | |
| 225 unsigned kMult = k * fixPointMult; | |
| 226 unsigned r = fixPointUnsignedMultiply(c, kMult); | |
| 227 unsigned g = fixPointUnsignedMultiply(m, kMult); | |
| 228 unsigned b = fixPointUnsignedMultiply(y, kMult); | |
| 229 | |
| 230 *dest = SkPackARGB32NoCheck(255, r, g, b); | |
| 231 } | |
| 232 | |
| 196 private: | 233 private: |
| 197 int width() const | 234 int width() const |
| 198 { | 235 { |
| 199 return m_bitmap->bitmap().width(); | 236 return m_bitmap->bitmap().width(); |
| 200 } | 237 } |
| 201 | 238 |
| 202 int height() const | 239 int height() const |
| 203 { | 240 { |
| 204 return m_bitmap->bitmap().height(); | 241 return m_bitmap->bitmap().height(); |
| 205 } | 242 } |
| 206 | 243 |
| 244 void checkAddress(PixelData* address) | |
|
Peter Kasting
2013/06/12 18:47:07
I would just omit this. The previous code had a s
| |
| 245 { | |
| 246 ASSERT(getAddr(0, 0) <= address && address <= getAddr(0, 0) + width( ) * height() * m_hasAlpha ? 4 : 3); | |
| 247 } | |
| 248 | |
| 207 RefPtr<NativeImageSkia> m_bitmap; | 249 RefPtr<NativeImageSkia> m_bitmap; |
| 208 SkBitmap::Allocator* m_allocator; | 250 SkBitmap::Allocator* m_allocator; |
| 209 bool m_hasAlpha; | 251 bool m_hasAlpha; |
| 210 IntRect m_originalFrameRect; // This will always just be the entire | 252 IntRect m_originalFrameRect; // This will always just be the entire |
| 211 // buffer except for GIF frames whose | 253 // buffer except for GIF frames whose |
| 212 // original rect was smaller than the | 254 // original rect was smaller than the |
| 213 // overall image size. | 255 // overall image size. |
| 214 FrameStatus m_status; | 256 FrameStatus m_status; |
| 215 unsigned m_duration; | 257 unsigned m_duration; |
| 216 FrameDisposalMethod m_disposalMethod; | 258 FrameDisposalMethod m_disposalMethod; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 | 484 |
| 443 IntSize m_size; | 485 IntSize m_size; |
| 444 bool m_sizeAvailable; | 486 bool m_sizeAvailable; |
| 445 bool m_isAllDataReceived; | 487 bool m_isAllDataReceived; |
| 446 bool m_failed; | 488 bool m_failed; |
| 447 }; | 489 }; |
| 448 | 490 |
| 449 } // namespace WebCore | 491 } // namespace WebCore |
| 450 | 492 |
| 451 #endif | 493 #endif |
| OLD | NEW |