Thread View: comp.sys.next.programmer
2 messages
2 total messages
Started by Detlev Droege
Fri, 09 Oct 1992 13:28
NXImage - problem forcing image depth (2.x)
Author: Detlev Droege
Date: Fri, 09 Oct 1992 13:28
Date: Fri, 09 Oct 1992 13:28
44 lines
2383 bytes
2383 bytes
One of our students has following problem. He's not reachable by mail, I'll forward any answers to him. - Detlev I'm writing a program to convert 24-bit-color images (color reduction). Therefore I need to load the image with its full color. Because these images are large I've compressed them with "compress"; to load them I'm setting up a pipe to "zcat" and decompress them into a stream. From this stream I instantiate an new NXImage with following piece of code: --- generate 'userStream' localImage = [NXImage alloc]; // some flags to force loading 24-bit rgb-images [localImage setDataRetained:YES]; [localImage setCacheDepthBounded:NO]; [localImage setColorMatchPreferred:NO]; [localImage setScalable:YES]; [localImage setMatchedOnMultipleResolution:NO]; [localImage initFromStream:userStream]; --- close and remove 'userStream' This loading works fine on all devices (NeXT-Colorstation, NeXT-Dimension and NeXTstation); the imageRep (NXCachedImageRep) contains all informations from the compressed image. BUT...: When _not_ working on a NeXT-Dimension, the first time I use the image (e.g. composite it into a view) the informations of the imagerep will change to the depth of the framebuffer; no _new_ representation will be generated, but the original will change. This only happens with compressed TIFF-files. If I'll map a stream on a (uncompressed) TIFF-image and perform this code, the representation does not change. Now my question: How can I force the Image not to change the imagerep? or How to load an image from a stream and use it without loosing informations? Thanks in advance Roger Craemer -- Detlev Droege | droege@infko.uni-koblenz.de Universitaet Koblenz, | (NeXTmail ok) Institut fuer Informatik | Voice: +49 261 9119-421 Rheinau 3-4, D-5400 Koblenz, Germany | Fax: +49 261 9119-499
Re: NXImage - problem forcing image depth (2.x)
Author: Ali Ozer
Date: Sun, 11 Oct 1992 22:35
Date: Sun, 11 Oct 1992 22:35
45 lines
2709 bytes
2709 bytes
In article <1992Oct09.132830.14359@infko.uucp> Detlev Droege writes: >I'm writing a program to convert 24-bit-color images (color reduction). >Therefore I need to load the image with its full color. Because these images >are large I've compressed them with "compress"; to load them I'm setting up a >pipe to "zcat" and decompress them into a stream. From this stream I >instantiate an new NXImage with following piece of code: > --- generate 'userStream' > localImage = [NXImage alloc]; > // some flags to force loading 24-bit rgb-images > [localImage setDataRetained:YES]; > [localImage setCacheDepthBounded:NO]; > [localImage setColorMatchPreferred:NO]; > [localImage setScalable:YES]; > [localImage setMatchedOnMultipleResolution:NO]; > [localImage initFromStream:userStream]; > --- close and remove 'userStream' First of all, the code above has one big problem: It allocs and uses an object without an init. This is not right; all objects need to be alloced then init'ed (once) before they can be used. In fact, the best way to use alloc & init is to nest them, because the convention is that if an init method fails to init for some reason, it will free the object and return nil: myObject = [[Class allocFromZone:...] init]; In the case of the above code, if you need to do the loading from stream after setting all the other params, you should use loadFromStream: instead. initFromStream: is equivalent to init + loadFromStream:. To get back to the original problem... If you wish to load an image into an NXImage, and would like the image to keep its original depth, the correct method to use is setCacheDepthBounded:, with a NO argument. This tells the NXImage to make the cache deep enough to hold the image in its full glory. This is done correctly in the above code. I suspect the reason this isn't working for you must be the wrong order in which init is done; one of the things init does is to set all the flags to their default values. Moving init to the right place should solve the problem. If you don't need the image cached, but would just like to munge through the image data, you can also just use the NXBitmapImageRep class. This will give you the data in its original depth, even if it's a depth not supported by the windowserver (such as 1 or 4 bit grayscale)... Ali, Ali_Ozer@NeXT.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads