gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9581: Write an RGBA image if an ima


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9581: Write an RGBA image if an image::rgba is passed.
Date: Tue, 12 Aug 2008 13:00:48 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9581
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2008-08-12 13:00:48 +0200
message:
  Write an RGBA image if an image::rgba is passed.
modified:
  libbase/GnashImage.h
  libbase/GnashImagePng.cpp
  libbase/GnashImagePng.h
  libbase/image.cpp
    ------------------------------------------------------------
    revno: 9577.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-08-12 12:58:20 +0200
    message:
      Implement writing RGBA PNG images.
    modified:
      libbase/GnashImage.h
      libbase/GnashImagePng.cpp
      libbase/GnashImagePng.h
      libbase/image.cpp
=== modified file 'libbase/GnashImage.h'
--- a/libbase/GnashImage.h      2008-08-11 16:42:50 +0000
+++ b/libbase/GnashImage.h      2008-08-12 10:58:20 +0000
@@ -21,8 +21,7 @@
 #define GNASH_GNASHIMAGE_H
 
 #include <boost/shared_ptr.hpp> 
-
-#include "dsodefs.h"
+#include "log.h"
 
 // Forward declarations
 namespace gnash { class IOChannel; }
@@ -85,6 +84,11 @@
     virtual ~ImageOutput() {}
     
     virtual void writeImageRGB(unsigned char* rgbData) = 0;
+    
+    virtual void writeImageRGBA(unsigned char* /*rgbaData*/)
+    {
+        log_error("This image format does not support writing RGBA images");
+    }
 
 protected:
 

=== modified file 'libbase/GnashImagePng.cpp'
--- a/libbase/GnashImagePng.cpp 2008-08-11 19:05:37 +0000
+++ b/libbase/GnashImagePng.cpp 2008-08-12 10:58:20 +0000
@@ -168,6 +168,30 @@
     }
 }
 
+void
+PngImageOutput::writeImageRGBA(unsigned char* rgbaData)
+{
+    png_set_write_fn(_pngPtr, _outStream.get(), &writeData, &flushData);
+
+    boost::scoped_array<png_bytep> rows(new png_bytep[_height]);
+
+    // RGB
+    const size_t components = 4;
+
+    for (size_t y = 0; y < _height; ++y)
+    {
+        rows[y] = rgbaData + _width * y * components;
+    }
+
+    png_set_rows(_pngPtr, _infoPtr, rows.get());
+
+    png_set_IHDR(_pngPtr, _infoPtr, _width, _height,
+       8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
+       PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+
+    png_write_png(_pngPtr, _infoPtr, PNG_TRANSFORM_IDENTITY, NULL);
+}
+
 
 void
 PngImageOutput::writeImageRGB(unsigned char* rgbData)

=== modified file 'libbase/GnashImagePng.h'
--- a/libbase/GnashImagePng.h   2008-08-11 16:42:50 +0000
+++ b/libbase/GnashImagePng.h   2008-08-12 10:58:20 +0000
@@ -106,6 +106,8 @@
        ~PngImageOutput();
 
        void writeImageRGB(unsigned char* rgbData);
+       
+       void writeImageRGBA(unsigned char* rgbaData);
 
        DSOEXPORT static std::auto_ptr<ImageOutput> 
create(boost::shared_ptr<IOChannel> out, size_t width, size_t height, int 
quality);
        

=== modified file 'libbase/image.cpp'
--- a/libbase/image.cpp 2008-08-11 16:42:50 +0000
+++ b/libbase/image.cpp 2008-08-12 10:58:20 +0000
@@ -190,13 +190,9 @@
        // Write the given image to the given out stream, in jpeg format.
        void writeImageData(FileType type, boost::shared_ptr<IOChannel> out, 
image::image_base* image, int quality)
        {
-               image::rgb* im = dynamic_cast<image::rgb*>(image);
-               
-               // We only handle rgb data at the moment.
-               assert(im);
-               
-               const size_t width = im->width();
-               const size_t height = im->height();
+               
+               const size_t width = image->width();
+               const size_t height = image->height();
                                
                std::auto_ptr<ImageOutput> outChannel;
 
@@ -213,7 +209,18 @@
                 break;
         }
 
-        outChannel->writeImageRGB(im->data());
+        image::rgb* imageRGB = dynamic_cast<image::rgb*>(image);
+        if (imageRGB)
+        {
+            outChannel->writeImageRGB(imageRGB->data());
+            return;        
+        }
+
+        image::rgba* imageRGBA = dynamic_cast<image::rgba*>(image);
+        if (imageRGBA)
+        {
+            outChannel->writeImageRGBA(imageRGBA->data());
+        }
        }
 
     // See gnash.h for file types.


reply via email to

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