Author: Nikita Kitaev <[email protected]>
Date:   Wed Mar 23 17:04:32 2011 -0700

Use dedicated function for pixel format conversions

---

 synfig-core/src/synfig/color.h             |   98 ++++++++++++++++++++++++++++
 synfig-core/src/synfig/target_scanline.cpp |   14 ++---
 2 files changed, 103 insertions(+), 9 deletions(-)

diff --git a/synfig-core/src/synfig/color.h b/synfig-core/src/synfig/color.h
index 208d059..60f4688 100644
--- a/synfig-core/src/synfig/color.h
+++ b/synfig-core/src/synfig/color.h
@@ -895,7 +895,105 @@ PixelFormat2Color(Color &color, const PixelFormat 
&pf,const unsigned char *out)
        return out;
 }
 
+inline const unsigned char*
+convert_pixel_formats(const unsigned char *in, const PixelFormat &pf_in, 
unsigned char *out, const PixelFormat &pf_out)
+{
+       // Assume 8-bit color channels everwhere
+       unsigned char a,r,g,b;
+       if (FLAGS(pf_in,PF_ZA|PF_A_START|PF_Z_START))
+       {
+               if(FLAGS(pf_in,PF_Z_START))
+                       in++;
+               if(FLAGS(pf_in,PF_A_START))
+                       a=*in++;
+       }
+       else
+       {
+               if(FLAGS(pf_in,PF_A_START))
+                       a=*in++;
+               if(FLAGS(pf_in,PF_Z_START))
+                       *in++;
+       }
+       if(FLAGS(pf_in,PF_GRAY))
+               r=g=b=*in++;
+       else
+       {
+               if(FLAGS(pf_in,PF_BGR))
+               {
+                       b = *in++;
+                       g = *in++;
+                       r = *in++;
+               }
+               else
+               {
+                       r = *in++;
+                       g = *in++;
+                       b = *in++;
+               }
+       }
+       if(FLAGS(pf_in,PF_ZA))
+       {
+               if(!FLAGS(pf_in,PF_Z_START) && FLAGS(pf_in,PF_Z))
+                       *in++;
+               if(!FLAGS(pf_in,PF_A_START) && FLAGS(pf_in,PF_A))
+                       a = *in++;
+       }
+       else
+       {
+               if(!FLAGS(pf_in,PF_A_START) && FLAGS(pf_in,PF_A))
+                       a = *in++;
+               if(!FLAGS(pf_in,PF_Z_START) && FLAGS(pf_in,PF_Z))
+                       *in++;
+       }
 
+       //Write the new color format
+       if (FLAGS(pf_out,PF_ZA|PF_A_START|PF_Z_START))
+       {
+               if(FLAGS(pf_out,PF_Z_START))
+                       out++;
+               if(FLAGS(pf_out,PF_A_START))
+                       *out++=a;
+       }
+       else
+       {
+               if(FLAGS(pf_out,PF_A_START))
+                       *out++=a;
+               if(FLAGS(pf_out,PF_Z_START))
+                       *out++;
+       }
+       if(FLAGS(pf_out,PF_GRAY))
+               *out++=(r+g+b)/3; //verify
+       else
+       {
+               if(FLAGS(pf_out,PF_BGR))
+               {
+                       *out++ = b;
+                       *out++ = g;
+                       *out++ = r;
+               }
+               else
+               {
+                       *out++ = r;
+                       *out++ = g;
+                       *out++ = b;
+               }
+       }
+       if(FLAGS(pf_out,PF_ZA))
+       {
+               if(!FLAGS(pf_out,PF_Z_START) && FLAGS(pf_out,PF_Z))
+                       *out++;
+               if(!FLAGS(pf_out,PF_A_START) && FLAGS(pf_out,PF_A))
+                       *out++ = a;
+       }
+       else
+       {
+               if(!FLAGS(pf_out,PF_A_START) && FLAGS(pf_out,PF_A))
+                       *out++ = a;
+               if(!FLAGS(pf_out,PF_Z_START) && FLAGS(pf_out,PF_Z))
+                       *out++;
+       }
+       return out;
+}
 
 }; // END of namespace synfig
 
diff --git a/synfig-core/src/synfig/target_scanline.cpp 
b/synfig-core/src/synfig/target_scanline.cpp
index 9f076ca..b5f34d4 100644
--- a/synfig-core/src/synfig/target_scanline.cpp
+++ b/synfig-core/src/synfig/target_scanline.cpp
@@ -503,15 +503,11 @@ Target_Scanline::add_frame(const unsigned char *data, 
const unsigned int width,
                        // 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()
+                               convert_pixel_formats(
+                                       data + y * stride + x * 
cairo_pixel_size,
+                                       cairo_data_format,
+                                       colordata + x * pixel_size,
+                                       target_format_
                                        );
                        }
                }


------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to