Article View: comp.sys.next.programmer
Article #1411Re: NXImage - problem forcing image depth (2.x)
From: 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
Technical Details
Message-ID:
<5381@rosie.NeXT.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!rosie!aozerReferences:
<1992Oct09.132830.14359@infko.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!rosie!aozer From: aozer@next.com (Ali Ozer) Newsgroups: comp.sys.next.programmer Subject: Re: NXImage - problem forcing image depth (2.x) Message-ID: <5381@rosie.NeXT.COM> Date: 11 Oct 92 22:35:24 GMT References: <1992Oct09.132830.14359@infko.uucp> Sender: news@NeXT.COM Organization: Next Computer, Inc. Lines: 45