gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10362: Cache jpeg height and width


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10362: Cache jpeg height and width as suggested by dolphinling. Both values are
Date: Thu, 27 Nov 2008 09:19:11 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10362
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2008-11-27 09:19:11 +0100
message:
  Cache jpeg height and width as suggested by dolphinling. Both values are
  used in several places and called many times, so it makes sense to cache
  them for the whole function scope.
  
  Reduce (virtual) function calls in mergeAlpha().
modified:
  libbase/GnashImage.cpp
=== modified file 'libbase/GnashImage.cpp'
--- a/libbase/GnashImage.cpp    2008-10-27 16:05:13 +0000
+++ b/libbase/GnashImage.cpp    2008-11-27 08:19:11 +0000
@@ -20,7 +20,7 @@
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2002
 
 #include <cstring>
-#include <memory>              // for auto_ptr
+#include <memory>        // for auto_ptr
 #include <boost/scoped_array.hpp>
 #include <boost/shared_ptr.hpp>
 
@@ -140,7 +140,7 @@
     assert(x < _width);
     assert(y < _height);
 
-    boost::uint8_t*    data = scanline(y) + 4 * x;
+    boost::uint8_t* data = scanline(y) + 4 * x;
 
     data[0] = r;
     data[1] = g;
@@ -149,12 +149,21 @@
 }
 
 
-void ImageRGBA::mergeAlpha(const boost::uint8_t* alphaData, const size_t 
bufferLength)
+void
+ImageRGBA::mergeAlpha(const boost::uint8_t* alphaData,
+        const size_t bufferLength)
 {
     assert (bufferLength * 4 <= _size);
 
-    for (size_t i = 0; i < bufferLength; i++) {
-        data()[4 * i + 3] = alphaData[i];
+    // Point to the first alpha byte
+    boost::uint8_t* p = data();
+
+    // Set each 4th byte to the correct alpha value.
+    for (size_t i = 0; i < bufferLength; ++i) {
+        p += 3;
+        *p = *alphaData;
+        ++p;
+        ++alphaData;
     }
 }
 
@@ -291,7 +300,7 @@
 ImageInput::readSWFJpeg3(boost::shared_ptr<IOChannel> in)
 {
 
-    std::auto_ptr<ImageRGBA> im(NULL);
+    std::auto_ptr<ImageRGBA> im;
 
     // Calling with headerBytes as 0 has a special effect...
     std::auto_ptr<JpegImageInput> j_in(
@@ -302,17 +311,19 @@
 
     j_in->read();
 
-    im.reset(new ImageRGBA(j_in->getWidth(), j_in->getHeight()));
-
-    boost::scoped_array<boost::uint8_t> line (
-            new boost::uint8_t[3 * j_in->getWidth()]);
-
-    for (size_t y = 0; y < j_in->getHeight(); y++) 
+    const size_t height = j_in->getHeight();
+    const size_t width = j_in->getWidth();
+
+    im.reset(new ImageRGBA(width, height));
+
+    boost::scoped_array<boost::uint8_t> line(new boost::uint8_t[3 * width]);
+
+    for (size_t y = 0; y < height; ++y) 
     {
         j_in->readScanline(line.get());
 
-        boost::uint8_t*        data = im->scanline(y);
-        for (size_t x = 0; x < j_in->getWidth(); x++) 
+        boost::uint8_t* data = im->scanline(y);
+        for (size_t x = 0; x < width; ++x) 
         {
             data[4*x+0] = line[3*x+0];
             data[4*x+1] = line[3*x+1];
@@ -326,9 +337,3 @@
 
 } // namespace gnash
 
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8 
-// tab-width: 8
-// indent-tabs-mode: t
-// End:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]