Re: Blend mode 'darken' for NSImage?
Re: Blend mode 'darken' for NSImage?
- Subject: Re: Blend mode 'darken' for NSImage?
- From: Ken Ferry <email@hidden>
- Date: Sun, 18 Apr 2010 20:56:51 -0700
On Sun, Apr 18, 2010 at 8:30 PM, Izak van Langevelde <email@hidden>wrote:
>
> On 2010-04-18, at 11:00 PM, Ken Ferry wrote:
>
> > Ah, so your problem is that not every CG blend mode is available as an
> NSCompositingOperation? If you would, please file a quick bug mentioning
> that you needed this.
> >
>
> From the documentation: "The compositing operations are related to (but
> different from) the blend mode settings used in Quartz. " They are
> different, so I don't consider it a bug...
>
The two sets used to be unrelated, but at this point the blend modes are a
superset of the compositing operations.
>
> > If you're running on 10.6, you can use -[NSImage
> CGImageForProposedRect:context:hints:] to get a CGImage, then draw the
> CGImage with your blend mode.
>
> I don't want to draw anything, I want an NSImage, and I'm not wildly
> enthusiastic about drawing everything in a dummy view and then peeling out
> an NSImage...
>
Ah - you don't need a dummy view. And as far as drawing, what is drawing
but copying bytes from here to there? :-) We're optimized for drawing, it's
not something you want to avoid relative to direct byte access. Think about
how often we have to draw. See AppKit relnotes for more discussion of
what's fast and what's not. If you tried to get direct access to the bytes
of an NSBitmapImageRep, that'd effectively draw the rep, as discussed in the
notes.
CGContextRef ctx = CGBitmapContextCreate(NULL/*CG allocates its own data*/,
dstWidth, dstHeight, 8/*bitsPerComponent*/, 0/*bytesPerRow - since CG is
allocating the data, let it choose bytesPerRow as it sees best*/,
colorSpace/*perhaps [[NSColorSpace sRGBColorSpace]
CGColorSpace]*/, kCGBitmapByteOrder32Host|kCGImageAlphaPremultipliedFirst);
CGContextClearRect(CGRectMake(0,0,dstWidth,dstHeight));
// drawing goes here - either by getting CGImage and drawing it (preferred
on 10.6) or with transparency layer trick above.
CGImageRef im_cg = CGBitmapContextCreateImage(ctx);
CFRelease(ctx);
NSImage *im = [[NSImage alloc] initWithCGImage:im_cg size:NSZeroSize/*take
size from the CGImage*/];
CFRelease(im_cg);
This ought to outperform anything you would do by hand (er, provided what
you would do by hand gets colorspace handling correct).
-Ken
Cocoa Frameworks
> Thanks,
> Izak
>
> ---
> Grinnikend door het leven...
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden