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

Side by Side Diff: Source/core/platform/image-decoders/ImageDecoder.h

Issue 17448010: Speed up png decoding by eliminating branches from the core loop that fills ImageFrame with pixels (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Speed up png decoding by eliminating branches from the core loop that fills ImageFrame with pixels Created 7 years, 6 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
OLDNEW
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
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, r, g, b, a);
182 *dest = 0; 187 else
183 return; 188 setRGBARaw(dest, r, g, b, a);
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) {
Noel Gordon 2013/06/26 05:15:26 Why did you change the shape of this routine? The
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 setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
212 {
213 ASSERT(!m_premultiplyAlpha);
Noel Gordon 2013/06/26 05:15:26 Ditto re the ASSERT, why do we need it all when th
214
215 *dest = SkPackARGB32NoCheck(a, r, g, b);
216 }
217
196 private: 218 private:
197 int width() const 219 int width() const
198 { 220 {
199 return m_bitmap->bitmap().width(); 221 return m_bitmap->bitmap().width();
200 } 222 }
201 223
202 int height() const 224 int height() const
203 { 225 {
204 return m_bitmap->bitmap().height(); 226 return m_bitmap->bitmap().height();
205 } 227 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 464
443 IntSize m_size; 465 IntSize m_size;
444 bool m_sizeAvailable; 466 bool m_sizeAvailable;
445 bool m_isAllDataReceived; 467 bool m_isAllDataReceived;
446 bool m_failed; 468 bool m_failed;
447 }; 469 };
448 470
449 } // namespace WebCore 471 } // namespace WebCore
450 472
451 #endif 473 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698