Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / January 2006



Tip: Looking for answers? Try searching our database.

TIFF Image To Pre-Existing NSBitmapImageRep?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Darel - 29 Dec 2005 22:31 GMT
I have a TIFF image in my nib file's Images tab, and I can acquire that
image and "composite" it into an NSImage object.  But what I really
want to do is copy it into an NSBitmapImageRep that I have pre-created
and defined to my own specifications.  This seems to be impossible,
because you can draw the TIFF only to the current drawing context,
which is chosen with lockFocus, and lockFocus works only on NSViews and
NSImages, not on NSImageReps.

I can, of course, use addRepresentation to make my NSBitmapImageRep a
representation in an NSImage, and then draw into that NSImage, right?
But it doesn't work -- what happens is that lockFocus creates *another*
representation for the NSImage, and the TIFF-drawing takes place there,
not in the NSBitmapImageRep that you wanted it to use.  (This seems to
happen even if you use lockFocusOnRepresentation and specify the
pre-existing NSBitmapImageRep.)

In summary:  How do we get a TIFF image from the nib file to an
existing (pre-defined) NSBitmapImageRep?

Please reply to this posting only if you have a specific answer to my
specific question.  I wouldn't be posting it here if I hadn't already
spent several hours searching the internet, reading Apple's
documentation, and experimenting with these objects in an attempt to
figure it out.

Thanks in advance,
Darel
Michael Ash - 30 Dec 2005 12:27 GMT
> I have a TIFF image in my nib file's Images tab, and I can acquire that
> image and "composite" it into an NSImage object.  But what I really
[quoted text clipped - 14 lines]
> In summary:  How do we get a TIFF image from the nib file to an
> existing (pre-defined) NSBitmapImageRep?

I think you're going to have to do the copying of the data yourself.
NSImage will not draw into an NSBitmapImageRep. It's relatively trivial to
get a *new* NSBitmapImageRep from an arbitrary NSImage, but for whatever
reason you don't want that.

If you load an NSImage with your TIFF, resize it to fit your existing
NSBitmapImageRep, and then pull a new NSBitmapImageRep out of it, it
should be relatively trivial to write a blitter that will copy the pixel
data out of the new one and into your existing one.

Signature

Michael Ash
Rogue Amoeba Software

Darel - 30 Dec 2005 22:55 GMT
Thanks, Michael -- I was afraid that might be the case.  Basically I
want to be able to specify the exact structure of the NSBitmapImageRep
(planes, bits-per-plane, etc.) so I can manipulate its contents with my
own graphics functions.  Your suggestion that I get a new
NSBitmapImageRep from an NSImage would be perfect if I can be
guaranteed that it will produce the same kind of NSBitmapImageRep each
time... is that controllable when getting a new NSBitmapImageRep from
an NSImage?

Your wisdom is appreciated -- please forget my earlier feistiness in
another thread!  :D

Darel

> I think you're going to have to do the copying of the data yourself.
> NSImage will not draw into an NSBitmapImageRep. It's relatively trivial to
[quoted text clipped - 5 lines]
> should be relatively trivial to write a blitter that will copy the pixel
> data out of the new one and into your existing one.
Michael Ash - 31 Dec 2005 12:42 GMT
> Thanks, Michael -- I was afraid that might be the case.  Basically I
> want to be able to specify the exact structure of the NSBitmapImageRep
[quoted text clipped - 4 lines]
> time... is that controllable when getting a new NSBitmapImageRep from
> an NSImage?

For some reason, this question really got me curious, but I couldn't find
anything. I even wrote up a bunch of stuff about how I can't find anything
but you could probably get away with assuming X, or trying Y. Then I found
the answer. Actually, I did this *twice*, each time finding a better
answer. I think I'm done now. So here you go:

NSGraphicsContext has a graphicsContextWithBitmapImageRep: method. It has
a restriction that it only works with single-plane data, but this should
be no great problem. Once you create that, you should be able to start
drawing into it by using the +setCurrentContext: method of the class
(disclaimer: I've never tried this), then draw your image. Actually, you
probably want to do a saveGraphicsState first, then a restoreGraphicsState
after.

And whew, there you go. I hope you'll report back on how it works, since
this is something untried for me.

> Your wisdom is appreciated -- please forget my earlier feistiness in
> another thread!  :D

Don't worry about it. Bygones, right?

Signature

Michael Ash
Rogue Amoeba Software

Darel - 07 Jan 2006 00:53 GMT
Michael,

Bygones!  Probably more my fault than yours.

Thanks very much for that technique -- I read it several days ago but
am just replying now.  I also tried your method of reading the file in
as pure data and copying it to my NSBitmapImageRep with a loop.  That
worked too, but it took me a few tries before I figured out how to read
the uncompressed 24-bit BMP format I'm now using.

My maiden Cocoa project is coming along well, but there's still a lot
of work to do -- it's pretty heavy on custom graphic manipulation,
which is why I needed to control the imagerep so tightly.  Also had to
research spline curves for part of it; that's interesting.  Wikipedia
does a good job of explaining it.

Just saw something interesting on DaringFireball that your company is
hiring?  Telecommuters at that?  But it'll be a while before I can even
apply -- my Cocoa experience is just beginning.

I'll keep you posted!

Regards,
Darel Finley
<DarelRex@gmail.com>
Michael Ash - 07 Jan 2006 13:15 GMT
[snip]

> Thanks very much for that technique -- I read it several days ago but
> am just replying now.

I guess that means it worked? I'm glad to hear it. There's no reason it
shouldn't, but I don't trust untested stuff.

>  I also tried your method of reading the file in
> as pure data and copying it to my NSBitmapImageRep with a loop.  That
> worked too, but it took me a few tries before I figured out how to read
> the uncompressed 24-bit BMP format I'm now using.

That's not actually what I originally suggested, but that's ok. I was
suggesting that you read it using NSBitmapImageRep, but make assumptions
about the resulting pixel format. I've written code like this before and
it was pretty easy, but making assumptions like that is a bad thing to do.
Until I researched my second answer, I didn't even know there was a
general way to do it "right".

> My maiden Cocoa project is coming along well, but there's still a lot
> of work to do -- it's pretty heavy on custom graphic manipulation,
> which is why I needed to control the imagerep so tightly.  Also had to
> research spline curves for part of it; that's interesting.  Wikipedia
> does a good job of explaining it.

I hope you've checked out CoreImage. With a decent graphics card you can
get some amazing speed out of it, and using the straightforward kernel
language it's very customizable. It's not really oriented toward stuff
like spline curves though, so it might not be useful to you.

> Just saw something interesting on DaringFireball that your company is
> hiring?  Telecommuters at that?  But it'll be a while before I can even
> apply -- my Cocoa experience is just beginning.

It's always the same story, too many projects and not enough people.

Since it's been brought up, if anybody else is following along and
interested, there's more information here:

http://www.rogueamoeba.com/company/jobs/

Signature

Michael Ash
Rogue Amoeba Software

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.