Author: spouliot
Date: 2007-05-30 07:43:13 -0400 (Wed, 30 May 2007)
New Revision: 78191

Modified:
   trunk/libgdiplus/src/ChangeLog
   trunk/libgdiplus/src/imageattributes-private.h
   trunk/libgdiplus/src/imageattributes.c
Log:
2007-05-30  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * imageattributes.c: Add support for ColorMatrixFlags and Gray 
        ColorMatrix (quite popular based on MoMA reports);
        * imageattributes-private.h: Add the gray color matrix and the color
        matrix flags into the GpImageAttribute structure.



Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog      2007-05-30 11:22:08 UTC (rev 78190)
+++ trunk/libgdiplus/src/ChangeLog      2007-05-30 11:43:13 UTC (rev 78191)
@@ -1,3 +1,10 @@
+2007-05-30  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * imageattributes.c: Add support for ColorMatrixFlags and Gray 
+       ColorMatrix (quite popular based on MoMA reports);
+       * imageattributes-private.h: Add the gray color matrix and the color
+       matrix flags into the GpImageAttribute structure.
+
 2007-05-28  Sebastien Pouliot  <[EMAIL PROTECTED]> 
 
        * graphics-cairo.c: Adjust the x,y position (-1,-1) when the pen's 

Modified: trunk/libgdiplus/src/imageattributes-private.h
===================================================================
--- trunk/libgdiplus/src/imageattributes-private.h      2007-05-30 11:22:08 UTC 
(rev 78190)
+++ trunk/libgdiplus/src/imageattributes-private.h      2007-05-30 11:43:13 UTC 
(rev 78191)
@@ -46,6 +46,8 @@
        BOOL key_enabled;
        BOOL no_op;
        ColorMatrix *colormatrix;
+       ColorMatrix *graymatrix;
+       ColorMatrixFlags colormatrix_flags;
        BOOL colormatrix_enabled;
 } GpImageAttribute;
 

Modified: trunk/libgdiplus/src/imageattributes.c
===================================================================
--- trunk/libgdiplus/src/imageattributes.c      2007-05-30 11:22:08 UTC (rev 
78190)
+++ trunk/libgdiplus/src/imageattributes.c      2007-05-30 11:43:13 UTC (rev 
78191)
@@ -17,8 +17,9 @@
  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
OR IN CONNECTION WITH THE SOFTWARE 
  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
- * Author:
- *          Jordi Mas i Hernandez <[EMAIL PROTECTED]>, 2004-2005
+ * Authors:
+ *     Jordi Mas i Hernandez <[EMAIL PROTECTED]>, 2004-2005
+ *     Sebastien Pouliot  <[EMAIL PROTECTED]>
  *
  */
 
@@ -35,6 +36,8 @@
        attr->key_colorhigh = 0;
        attr->key_enabled = FALSE;      
        attr->colormatrix = NULL;
+       attr->graymatrix = NULL;
+       attr->colormatrix_flags = ColorMatrixFlagsDefault;
        attr->colormatrix_enabled = FALSE;
 }
 
@@ -50,6 +53,11 @@
                GdipFree (attr->colormatrix);
                attr->colormatrix = NULL;
        }
+
+       if (attr->graymatrix) {
+               GdipFree (attr->graymatrix);
+               attr->graymatrix = NULL;
+       }
 }
 
 static GpImageAttribute*
@@ -203,9 +211,11 @@
        /* Apply Color Matrix */
        if (cmatrix->colormatrix_enabled && cmatrix->colormatrix) {
                BitmapData *data = bmpdest->active_bitmap;
-               ColorMatrix *cm = cmatrix->colormatrix;
                BYTE *v = ((BYTE*)data->scan0);
                ARGB *scan;
+               ColorMatrixFlags flags = cmatrix->colormatrix_flags;
+               ColorMatrix *cm;
+
                for (y = 0; y < data->height; y++) {
                        scan = (ARGB*) v;
                        for (x = 0; x < data->width; x++) {
@@ -214,6 +224,19 @@
 
                                get_pixel_bgra (*scan, b, g, r, a);
 
+                               /* by default the matrix applies to all colors, 
including grays */
+                               if ((flags != ColorMatrixFlagsDefault) && (b == 
g) && (b == r)) {
+                                       if (flags == ColorMatrixFlagsSkipGrays) 
{
+                                               /* does not apply */
+                                               scan++;
+                                               continue;
+                                       }
+                                       /* ColorMatrixFlagsAltGray */
+                                       cm = cmatrix->graymatrix;
+                               } else {
+                                       cm = cmatrix->colormatrix;
+                               }
+
                                a_new = (r * cm->m[0][3] + g * cm->m[1][3] + b 
* cm->m[2][3] + a * cm->m[3][3] + (255 * cm->m[4][3]));
                                if (a_new == 0) {
                                        /* 100% transparency, don't waste time 
computing other values (pre-mul will always be 0) */
@@ -386,7 +409,6 @@
 GpStatus
 GdipSetImageAttributesOutputChannelColorProfile (GpImageAttributes *imageattr, 
ColorAdjustType type,  BOOL enableFlag,
         GDIPCONST WCHAR *colorProfileFilename)
-
 {       
        return NotImplemented;
 }
@@ -453,15 +475,17 @@
        return NotImplemented;
 }
 
-/* MonoTODO - grayMatrix and flags parameters are ignored */
 GpStatus 
 GdipSetImageAttributesColorMatrix (GpImageAttributes *imageattr, 
ColorAdjustType type, BOOL enableFlag, 
        GDIPCONST ColorMatrix* colorMatrix, GDIPCONST ColorMatrix* grayMatrix, 
ColorMatrixFlags flags)
 {
        GpImageAttribute *imgattr;
        
-       if (!imageattr || (!colorMatrix && enableFlag))
+       if (!imageattr || (!colorMatrix && enableFlag) || (flags < 
ColorMatrixFlagsDefault))
                return InvalidParameter;
+
+       if (flags > (grayMatrix ? ColorMatrixFlagsAltGray : 
ColorMatrixFlagsSkipGrays))
+               return InvalidParameter;
                
        imgattr = gdip_get_image_attribute (imageattr, type);
        
@@ -470,7 +494,7 @@
 
        if (colorMatrix) {
                if (!imgattr->colormatrix) {
-                       imgattr->colormatrix =  GdipAlloc (sizeof 
(ColorMatrix));
+                       imgattr->colormatrix = GdipAlloc (sizeof (ColorMatrix));
                        if (!imgattr->colormatrix)
                                return OutOfMemory;
                }
@@ -478,6 +502,17 @@
                memcpy (imgattr->colormatrix, colorMatrix, sizeof 
(ColorMatrix));
        }
 
+       if (grayMatrix) {
+               if (!imgattr->graymatrix) {
+                       imgattr->graymatrix = GdipAlloc (sizeof (ColorMatrix));
+                       if (!imgattr->graymatrix)
+                               return OutOfMemory;
+               }
+
+               memcpy (imgattr->graymatrix, grayMatrix, sizeof (ColorMatrix));
+       }
+
+       imgattr->colormatrix_flags = flags;
        imgattr->colormatrix_enabled = enableFlag;      
        return Ok;
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to