On Wed, 05 May 2010 21:08:37 -0400
[email protected] wrote:
| I'm trying to do what should be fairly simple: mask parts of an image
| (using a greyscale mask - some parts could be masked out, others would
| have varying levels of transparency based on the darkness of the mask)
| and compose it on a background. The code below builds a mask and uses
| CopyCompositeOp to set the alpha channel of the top layer, but the
| resulting image is just the mask composed on the blue background rather
| than a masked copy of the top image.
|
| What's the proper series of function calls to get this done properly?
|
| thx --
|
| ,----
| | #include <wand/magick_wand.h>
| |
| | int
| | main (void)
| | {
| | MagickWand *background;
| | PixelWand *pw;
| | MagickWand *img;
| | MagickWand *mask;
| | DrawingWand *dw;
| | MagickBooleanType rc;
| |
| | MagickWandGenesis ();
| |
| | background = NewMagickWand ();
| | pw = NewPixelWand ();
| |
| | rc = PixelSetColor (pw, "blue");
| | rc = MagickNewImage (background, 640, 800, pw);
| |
| | img = NewMagickWand ();
| |
| | rc = MagickReadImage (img, "test-image.png");
| |
| | mask = NewMagickWand ();
| |
| | rc = PixelSetColor (pw, "gray");
| | rc = MagickNewImage (mask, MagickGetImageWidth (img),
MagickGetImageHeight (img), pw);
| |
| | dw = NewDrawingWand ();
| |
| | rc = PixelSetColor (pw, "white");
| | DrawSetFillColor (dw, pw);
| | DrawRectangle (dw, 10.0, 10.0, 90.0, 90.0);
| | rc = MagickDrawImage (mask, dw);
| |
| | DestroyDrawingWand (dw);
| |
| | rc = MagickCompositeImageChannel (img, AlphaChannel, mask,
CopyCompositeOp, 0, 0);
| |
| | DestroyMagickWand (mask);
| |
| | rc = MagickCompositeImage (background, img, OverCompositeOp, 40, 40);
| |
| | DestroyMagickWand (img);
| |
| | DestroyPixelWand (pw);
| |
| | MagickDisplayImage (background,":0");
| |
| | DestroyMagickWand (background);
| |
| | MagickWandTerminus();
| |
| | return 0;
| | }
| `----
|
Up until a few days ago, Channel did not thing in Image Composition!
That is because SVG defintions did not do any form of 'per channel'
composition, but (generally) did 'Over' Blending. See
Mathematical Composition and Alpha Blending
http://www.imagemagick.org/Usage/compose/#math_blending
The CopyCompositeOp also ignored 'channel', but its defintion was
to simply copy the alpha/opacity channel, REPLACING that of the
original. It would also treat the source image as a greyscale mask if
no alpha channel was enabled in that image.
See CopyOpacity Composition
http://www.imagemagick.org/Usage/compose/#copyopacity
Now as of IM v6.6.1-6 you can use channel controls, at least with
the mathematical compositions. The default channel setting has a
'SyncChannels' flag, that means 'perform channel operations in
synchronous with color and alpha channel. If this flag is removed
the mathematical composes will now do 'per channel' compositions.
In your case (over compositions) what you wnt to do is 'multiply'
the alpha channels of your image and your mask (as a shaped image)
See IM Examples, Mathematical Compositions, Image Channel Maths.
http://www.imagemagick.org/Usage/compose/#image_math
The example here is Actually Multiply!!!!
ASIDE: the real way three image 'masked' compositions is suposed to work
for ALL compositions (not just 'Over') is explained in...
Composite Mask Bug bug Report...
http://www.imagemagick.org/Usage/bugs/composite_mask/
Anthony Thyssen ( System Programmer ) <[email protected]>
--------------------------------------------------------------------------
One thing to take into account is that MS Windows is deliberately
designed to cripple your hardware, so that you keep upgrading
(hardware and software), which means you are being asset-stripped.
-- Ron Savage
--------------------------------------------------------------------------
Anthony's Castle http://www.cit.griffith.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users