Quickly swapping NSImages / NSImageReps
Quickly swapping NSImages / NSImageReps
- Subject: Quickly swapping NSImages / NSImageReps
- From: Ken Tabb <email@hidden>
- Date: Mon, 17 Sep 2001 17:55:04 +0100
Hi,
I have an Obj-C app which does a lot of image processing (at the bitmap
level). I have 2x NSImages, making sure they both have an
NSBitmapImageRep in them (or adding one if not), and both are the same
dimensions (height, width, colour depth, number of channels etc..
I have 2 NSBitmapImageRep pointers called 'src' and 'dest', which start
as the following:
src = bitmap1
dest = bitmap2
I work in dest, using the pixels in src (some operations can't have the
same image as both the source and destination). When I've finished a
stage of the image processing, I reverse which bitmaps src and dest point
to, so that I can now work again from src (bitmap2) to dest (bitmap1).
This swapping happens as many times as I've got image operations.
I only display one of the images (the most recent one) onscreen, although
obviously this changes after each operation (the most recent one being
either bitmap1 or bitmap2).
I'm after some advice. Is the better (i.e. fastest, not worried about RAM
very much) way to:
[1] Keep swapping the image which is displayed in the NSImageView (i.e.
[myImageView setImage:theOtherNSImage];) as currently, or
[2] Have only 1x NSImage, with 2x separate NSBitmapImageReps (as before),
and keep adding and removing representations from the NSImage. I'd never
need to call [myImageView setImage] then, as it'd be the same image (just
with different reps). Presumably this way I'd need to make sure the
NSImage isn't caching its reps, otherwise it'll have the wrong
NSBitmapImageRep being cached? Is there anything I've got to call (at
either the NSImage or NSImageView level) to get the different bitmap to
'take effect' onscreen? I'm imagining I've got to call [myImageView
setNeedsDisplay:YES], but don't know if that's all?
Thanks for any advice or pitfalls you can envisage with either method. Or
maybe there's a third, faster, way?
Ken
----------------------------------------------
Ken Tabb
Mac & UNIX Propellerhead & Network Bloke (Health & Human Sciences)
Computer Vision / Neural Network researcher (Computer Science)
University of Hertfordshire
e-mail: email@hidden
http://www.health.herts.ac.uk/ken/
Certified non-Microsoft Solution Provider