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

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

Issue 18099004: Improve PNG decode performance: avoid branching in the row write loop (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: template patch. Created 6 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
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 inline PixelData* getAddr(int x, int y) 155 inline PixelData* getAddr(int x, int y)
156 { 156 {
157 return m_bitmap.getAddr32(x, y); 157 return m_bitmap.getAddr32(x, y);
158 } 158 }
159 159
160 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a) 160 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a)
161 { 161 {
162 setRGBA(getAddr(x, y), r, g, b, a); 162 setRGBA(getAddr(x, y), r, g, b, a);
163 } 163 }
164 164
165 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a)
166 {
167 if (m_premultiplyAlpha)
Peter Kasting 2014/05/12 19:36:11 We could simplify this to just: setRGBA<m_pre
Noel Gordon 2014/05/13 01:39:19 Doesn't compile on any C++ compiler I know. VS2010
Peter Kasting 2014/05/13 01:54:56 Huh, that's odd. I could swear I've done precisel
168 setRGBA<true>(dest, r, g, b, a);
169 else
170 *dest = SkPackARGB32NoCheck(a, r, g, b);
171 }
172
165 static const unsigned div255 = static_cast<unsigned>(1.0 / 255 * (1 << 24)) + 1; 173 static const unsigned div255 = static_cast<unsigned>(1.0 / 255 * (1 << 24)) + 1;
166 174
175 template <bool Premultiply>
167 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a) 176 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a)
Peter Kasting 2014/05/12 19:36:11 This can be static, can't it?
Noel Gordon 2014/05/13 01:39:19 Could be, but you'd then add function calling over
Peter Kasting 2014/05/13 01:54:56 Why? Can't something be both static and inline?
168 { 177 {
169 if (m_premultiplyAlpha && a < 255) { 178 if (Premultiply && a < 255) {
170 if (!a) { 179 if (!a) {
171 *dest = 0; 180 *dest = 0;
172 return; 181 return;
173 } 182 }
174 183
175 unsigned alpha = a * div255; 184 unsigned alpha = a * div255;
176 r = (r * alpha) >> 24; 185 r = (r * alpha) >> 24;
177 g = (g * alpha) >> 24; 186 g = (g * alpha) >> 24;
178 b = (b * alpha) >> 24; 187 b = (b * alpha) >> 24;
179 } 188 }
180 189
181 // Call the "NoCheck" version since we may deliberately pass non-premult iplied 190 // Call the "NoCheck" version since we may deliberately pass non-premult iplied
182 // values, and we don't want an assert. 191 // values, and we don't want an assert.
183 *dest = SkPackARGB32NoCheck(a, r, g, b); 192 *dest = SkPackARGB32NoCheck(a, r, g, b);
184 } 193 }
185 194
186 inline void setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) 195 inline void setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
Peter Kasting 2014/05/12 19:36:11 Seems like this should just disappear, and callers
Noel Gordon 2014/05/13 01:39:19 Mentioned that in #15. Was a little slower accord
Peter Kasting 2014/05/13 01:54:56 If the difference isn't large, let's make the chan
187 { 196 {
188 *dest = SkPackARGB32NoCheck(a, r, g, b); 197 *dest = SkPackARGB32NoCheck(a, r, g, b);
189 } 198 }
190 199
191 // Notifies the SkBitmap if any pixels changed and resets the flag. 200 // Notifies the SkBitmap if any pixels changed and resets the flag.
192 inline void notifyBitmapIfPixelsChanged() 201 inline void notifyBitmapIfPixelsChanged()
193 { 202 {
194 if (m_pixelsChanged) 203 if (m_pixelsChanged)
195 m_bitmap.notifyPixelsChanged(); 204 m_bitmap.notifyPixelsChanged();
196 m_pixelsChanged = false; 205 m_pixelsChanged = false;
(...skipping 30 matching lines...) Expand all
227 // be read for image formats that do not have multiple frames. 236 // be read for image formats that do not have multiple frames.
228 size_t m_requiredPreviousFrameIndex; 237 size_t m_requiredPreviousFrameIndex;
229 #if !ASSERT_DISABLED 238 #if !ASSERT_DISABLED
230 bool m_requiredPreviousFrameIndexValid; 239 bool m_requiredPreviousFrameIndexValid;
231 #endif 240 #endif
232 }; 241 };
233 242
234 } // namespace WebCore 243 } // namespace WebCore
235 244
236 #endif 245 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698