Photoshop multiply effect
Posted: 2012-04-26T11:21:21-07:00
Hi, i have a question...
i want replicate the Photoshp Multiply effect with image magick.
I use the image magick library (c++) on my iphone app.
For this my request i use this my example but I not see my goal..
What change i in my code?
Tnx to all!
i want replicate the Photoshp Multiply effect with image magick.
I use the image magick library (c++) on my iphone app.
For this my request i use this my example but I not see my goal..
Code: Select all
CGImageRef srcCGImage = createStandardImage(aSourceImage.CGImage);
int width = CGImageGetWidth(srcCGImage);
int height = CGImageGetHeight(srcCGImage);
// could use the image directly if it has 8/16 bits per component,
// otherwise the image must be converted into something more common (such as images with 5-bits per component)
// here we’ll be simple and always convert
const char *map = MAP_FILTER_TYPE; // hard coded
const StorageType inputStorage = CharPixel;
CGImageRef standardized = createStandardImage(srcCGImage);
NSData *srcData = (NSData *) CGDataProviderCopyData(CGImageGetDataProvider(standardized));
CGImageRelease(standardized);
const void *bytes = [srcData bytes];
MagickWand *mw = NewMagickWand();
MagickWandGenesis();
MagickBooleanType status = MagickConstituteImage(mw, width, width, map, inputStorage, bytes);
MagickWand *mwc = CloneMagickWand(mw);
MagickWand *mwf = MagickFxImage(mwc,"A");
MagickSetImageAlphaChannel(mwf,DeactivateAlphaChannel);
MagickBlurImage(mwf,0,2);
MagickShadeImage(mwf,MagickTrue,0,90);
MagickNormalizeImage(mwf);
MagickBlurImage(mwf,0,2);
MagickNegateImage(mwf,MagickFalse);
MagickEvaluateImage(mwf,MultiplyEvaluateOperator,1.0);
MagickNegateImage(mwf,MagickFalse);
MagickRollImage(mwf,-.5,-1);
MagickCompositeImage(mwf,mw,MultiplyCompositeOp,0,0);
MagickCompositeImage(mw,mwf,InCompositeOp,0,0);
const int bitmapBytesPerRow = (width * strlen(map));
const int bitmapByteCount = (bitmapBytesPerRow * height);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
char *trgt_image = malloc(bitmapByteCount);
status = MagickExportImagePixels(mw, 0, 0, width, height, map, CharPixel, trgt_image);
/*
if (status == MagickFalse) {
ThrowWandException(magick_wand_local);
}
*/
if(mw)mw = DestroyMagickWand(mw);
if(mwc)mwc = DestroyMagickWand(mwc);
if(mwf)mwf = DestroyMagickWand(mwf);
MagickWandTerminus();
CGContextRef context = CGBitmapContextCreate (trgt_image,
width,
height,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedFirst);
CGColorSpaceRelease(colorSpace);
CGImageRef cgimage = CGBitmapContextCreateImage(context);
UIImage *image = [[UIImage alloc] initWithCGImage:cgimage];
CGImageRelease(cgimage);
CGContextRelease(context);
[srcData release];
free(trgt_image);
return image;
Tnx to all!