Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2007-05-30 Sebastien Pouliot <sebastien@ximian.com>

	* 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.


svn path=/trunk/libgdiplus/; revision=78191
  • Loading branch information...
commit 3beefe81ba28e8997cb910ea780e0e5c40becab3 1 parent b53156e
Sebastien Pouliot authored
View
7 src/ChangeLog
@@ -1,3 +1,10 @@
+2007-05-30 Sebastien Pouliot <sebastien@ximian.com>
+
+ * 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 <sebastien@ximian.com>
* graphics-cairo.c: Adjust the x,y position (-1,-1) when the pen's
View
2  src/imageattributes-private.h
@@ -46,6 +46,8 @@ typedef struct {
BOOL key_enabled;
BOOL no_op;
ColorMatrix *colormatrix;
+ ColorMatrix *graymatrix;
+ ColorMatrixFlags colormatrix_flags;
BOOL colormatrix_enabled;
} GpImageAttribute;
View
49 src/imageattributes.c
@@ -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 <jordi@ximian.com>, 2004-2005
+ * Authors:
+ * Jordi Mas i Hernandez <jordi@ximian.com>, 2004-2005
+ * Sebastien Pouliot <sebastien@ximian.com>
*
*/
@@ -35,6 +36,8 @@ gdip_init_image_attribute (GpImageAttribute* attr)
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 @@ gdip_dispose_image_attribute (GpImageAttribute* attr)
GdipFree (attr->colormatrix);
attr->colormatrix = NULL;
}
+
+ if (attr->graymatrix) {
+ GdipFree (attr->graymatrix);
+ attr->graymatrix = NULL;
+ }
}
static GpImageAttribute*
@@ -203,9 +211,11 @@ gdip_process_bitmap_attributes (GpBitmap *bitmap, void **dest, GpImageAttributes
/* 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 @@ gdip_process_bitmap_attributes (GpBitmap *bitmap, void **dest, GpImageAttributes
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 @@ GdipSetImageAttributesColorKeys (GpImageAttributes *imageattr, ColorAdjustType t
GpStatus
GdipSetImageAttributesOutputChannelColorProfile (GpImageAttributes *imageattr, ColorAdjustType type, BOOL enableFlag,
GDIPCONST WCHAR *colorProfileFilename)
-
{
return NotImplemented;
}
@@ -453,14 +475,16 @@ GdipGetImageAttributesAdjustedPalette (GpImageAttributes *imageattr, ColorPalett
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 @@ GdipSetImageAttributesColorMatrix (GpImageAttributes *imageattr, ColorAdjustType
if (colorMatrix) {
if (!imgattr->colormatrix) {
- imgattr->colormatrix = GdipAlloc (sizeof (ColorMatrix));
+ imgattr->colormatrix = GdipAlloc (sizeof (ColorMatrix));
if (!imgattr->colormatrix)
return OutOfMemory;
}
@@ -478,6 +502,17 @@ GdipSetImageAttributesColorMatrix (GpImageAttributes *imageattr, ColorAdjustType
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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.