Author: Nikita Kitaev <nikita...@gmail.com>
Date:   Tue Mar 22 20:55:34 2011 -0700

Do color conversion when cairo output is in the wrong format

---

 synfig-core/src/synfig/target_scanline.cpp |   38 +++++++++++++++++++++------
 1 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/synfig-core/src/synfig/target_scanline.cpp 
b/synfig-core/src/synfig/target_scanline.cpp
index c74ba22..1d36352 100644
--- a/synfig-core/src/synfig/target_scanline.cpp
+++ b/synfig-core/src/synfig/target_scanline.cpp
@@ -466,6 +466,13 @@ Target_Scanline::add_frame(const unsigned char *data, 
const unsigned int width,
                return false;
        }
 
+    PixelFormat cairo_data_format = (PF_RGB | PF_A | PF_8BITS);
+    int cairo_pixel_size = 4;
+
+    int pixel_size = channels(target_format_);
+    if ( target_format_ && PF_16BITS) pixel_size *= 2;
+    if ( target_format_ && PF_32BITS) pixel_size *= 4;
+
        for (unsigned int y = 0; y < height; y++)
        {
                unsigned char *colordata= start_scanline_rgba(y);
@@ -475,17 +482,30 @@ Target_Scanline::add_frame(const unsigned char *data, 
const unsigned int width,
                        return false;
                }
 
-               // TODO: Add a fragment shader to remove the alpha (OpenGL)
-               /*if(get_remove_alpha())
+               if ( target_format_ == cairo_data_format )
                {
-                       for(int i=0;i<surface->get_w();i++)
-                               
colordata[i]=Color::blend((*surface)[y][i],desc.get_bg_color(),1.0f);
+                       // Same format as cairo data
+                       memcpy(colordata, data + (stride * y), width * 
cairo_pixel_size);
+               }
+               else
+               {
+                       // Cairo data format and target format are not the same
+                       // Perform a (slow) color conversion
+                       for (unsigned int x = 0; x < width; x++)
+                       {
+                               Color c;
+                PixelFormat2Color(c,
+                                  cairo_data_format,
+                                  data + y * stride + x * cairo_pixel_size
+                    );
+
+                               Color2PixelFormat(c,
+                                                                 
target_format_,
+                                                                 colordata + x 
* pixel_size,
+                                                                 gamma()
+                                       );
+                       }
                }
-               else*/
-                       // TODO: If target needs data in other way than RGBA, 
convert using another fragment shader (OpenGL)
-
-               memcpy(colordata, data + (stride * y), width * 4);
-               // ARGB is 4 channels x 8 bits
 
                if(!end_scanline_rgba())
                {


------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to