This is SurfImageDecoder.rtf in view mode; [Download] [Up]
paperh18648 margl-907 margr0 margt0 margb0fi0 ri0 ql sb0 f1 fs24 Copyright f3 'e3f1 1995 by Netsurfer, Inc., All Rights Reserved. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 fs16 fs28 fs16 fs28 pard s5 li2116 fi0 ri1007 ql f0 b fs56 SurfImageDecoder fs16 fs56 pard s17 li4888 fi-2771 ri1007 ql tx4888 f1 b0 fs28 fs16 fs28 f0 b fs28 Inherits From: b0 fs28 f1 Object fs16 s10 fs16 fs28 f0 b fs28 Declared In: b0 fs28 f1 SurfImageDecoder.h fs16 fs28 pard s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 fs36 Class Description fs16 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs28 fs16 fs28 A controller for image decoding. This class implements a generic image decoder that can be used to decde any of a number of different image formats depending on what decoder classes have been registered with the instance. fs16 fs28 fs16 fs28 Given an arbitrary path or stream, an instance of b SurfImageDecoderb0 will determine the type of the image, attempt to decode it, and, upon success, will return an instance of b NXImageb0 containing the decoded image. fs16 fs28 fs16 fs28 Instances are designed to be used in a multi-threaded context. Any instance can be decoding image in any thread of execution while other instances are simultaneously decoding images. A single instance i cannoti0 decode multiple images from different threads; to attempt this guarantees catastrophic failure of the environment. fs16 fs28 fs16 fs28 b Registrering Custom Decodersb0 fs16 fs28 fs16 fs28 A class can register to be a potential decoder by calling b SurfImageDecoderb0 's b -addDecoderClass:b0 method. When instantiated, an instance of SurfImageDecoder automatically registers the b SurfGIFDecoderb0 and b SurfJPEGDecoderb0 classes. fs16 fs28 fs16 fs28 b How Image Formats Are Determinedb0 fs16 fs28 fs16 fs28 The b -loadFromStream:...b0 family of methods determines the contents of the stream by calling {+canLoadFromStream:} within each potentially eligible decoder's class. The first decoder to return YES decodes the stream. fs16 fs28 fs16 fs28 b -loadFromFile:...b0 and friends try to determine the image type by looking up the file's extension in the b decoderByTypeb0 HashTable. If not found, the stream is mapped into memory and passed to b -loadFromStream:...b0 . fs16 fs28 fs16 fs28 Note: the b -lastImageCorruptb0 method assumes that the last decoder used still exists and is still viable; ie: don't call b -lastImageCorruptb0 if you are using external decoders that may have been freed between the time an image decoding attempt was made and the time that b -lastImageCorruptb0 is called!. fs28s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 fs36 Instance Variables fs16 pard s18 li2116 fi0 ri1007 ql tx2872 f1 b0 fs28 HashTable *b decoderClassByTypeb0 ; HashTable *b decoderByTypeb0 ; List *b decoderListb0 ; NXWindowDepth b imageDepthb0 ; id <SurfErrorDelegate> b errorDelegateb0 ; pard s11 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 decoderClassByType decoder classes hashed by type fs16 fs28 decoderByType decoders hashed by type fs16 fs28 decoderList list of all decoders fs16 fs28 imageDepth target decoding depth fs16 fs28 errorDelegate Error Delegate pard s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 fs36 Method Types fs16 f1 b0 fs28 s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Existance Methods + sharedInstance pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} init {f3 -} free pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Image Type Management {f3 -} imageUnfilteredFileTypes pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} canLoadFromStream: {f3 -} dumpTypes pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Decoder Management {f3 -} decoderForType: pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} decoderClassForType: {f3 -} decoderForStream: {f3 -} decoderClassForStream: {f3 -} addDecoderClass: pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Decoding an Image {f3 -} decodeFromFile: pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} decodeFromFile:intoImage: {f3 -} decodeFromFile:intoImage:withDecoder: {f3 -} decodeFromStream: {f3 -} decodeFromStream:intoImage: {f3 -} decodeFromStream:intoImage:withDecoder: pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Configuration {f3 -} setImageDepth: pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} imageDepth pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 State Inspection {f3 -} lastImageCorrupt pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} decoderList {f3 -} decoderByType {f3 -} decoderClassByType {f3 -} verboseMode {f3 -} setVerboseMode: pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Error Handling {f3 -} setSpewToStderr: pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} spewToStderr {f3 -} setErrorDelegate: {f3 -} errorDelegate pard s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16 fs28 Debugging {f3 -} printForDebugger: pard s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 fs36 Class Methods fs16 fs36 s21 li2493 fi-1132 fi-376 fs28 fs16 fs29 b sharedInstance s20 li3249 fi-1132 fi-756 f1 b0 fs28 + b sharedInstanceb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the shared instance of SurfImageDecoder. Should only be used in applications that require a single image decoder. pard s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 fs36 Instance Methods fs16 fs36 s21 li2493 fi-1132 fi-376 fs28 fs16 fs29 b addDecoderClass: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b addDecoderClass:b0 i aClassi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Adds i aClassi0 as a possible decoder. This is accomplished by retrieving the types accepted by the decoder class by calling b +imageUnfilteredFileTypesb0 . The returned types are appended to the list of types that can be converted by this image converter object. An instance of the class is allocated and an entry is created in i hashedExtensionsi0 for each type the decoder can decode. If a decoder that can decode that particular type already exists in i hashedExtensionsi0 , it is replaced (but not freed). fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b canLoadFromStream: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (BOOL)b canLoadFromStream:b0 (NXStream *)i aStreami0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns YES if the decoder thinks it can decode the data in i aStreami0 . This forwards i aStreami0 to each specific format decoding class, if any return YES, this method immediately returns YES. fs16 fs28 fs16 fs28 The current position in the stream is unchanged. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decodeFromFile: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decodeFromFile:b0 (const char *)i filePathi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Attempts to decode the data in i filePathi0 as an image. Uses the i filePathi0 's extension to determine the image type. If it fails to find a decoder given the i filePathi0 's extension, the method maps the i filePathi0 and calls {-decodeFromStream:} in hopes that one of the image decoders will decide it can decode the stream contents. fs16 fs28 fs16 fs28 Returns the decoded image upon success and b nilb0 upon failure. This methdo is a cover for b -decodeFromFile:intoImage:withDecoder:b0 fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decodeFromFile:intoImage: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decodeFromFile:b0 (const char *)i filePathi0 b intoImage:b0 i anImagei0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Attempts to decode the contents of i filePathi0 in the same fashion as b -decodeFromFile:b0 . Instead of allocating an instance of NXImage, this method will append the newly decoded image in an NXBitmapImageRep using the b -useRepresentation:b0 method. fs16 fs28 fs16 fs28 Returns the decoded image upon success or b nilb0 upon failure. This methdo is a cover for b -decodeFromFile:intoImage:withDecoder:b0 fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decodeFromFile:intoImage:withDecoder: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decodeFromFile:b0 (const char *)i filePathi0 b intoImage:b0 i anImagei0 b withDecoder:b0 i aDecoderi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Attempts to decode the contents of i filePathi0 using i aDecoderi0 . If i anImagei0 is defined, the decoded representation will be appended to i anImagei0 using the b -useRepresentation:b0 method. If i aDecoderi0 is not defined, the method will try to identify the decoder to be used from i filePathi0 's extension. If that fails, this method will map the file and pass control b -decodeFromStream:...b0 . fs16 fs28 fs16 fs28 Returns the decoded image upon success or b nilb0 upon failure. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decodeFromStream: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decodeFromStream:b0 (NXStream *)i aStreami0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 This method is a cover for b -decodeFromStream:intoImage:withDecoder:b0 . fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decodeFromStream:intoImage: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decodeFromStream:b0 (NXStream *)i aStreami0 b intoImage:b0 i anImagei0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 This method is a cover for b -decodeFromStream:intoImage:withDecoder:b0 . fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decodeFromStream:intoImage:withDecoder: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decodeFromStream:b0 (NXStream *)i aStreami0 b intoImage:b0 i anImagei0 b withDecoder:b0 i aDecoderi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Decodes the contents of i aStreami0 into the image i anImagei0 using the decoder i aDecoderi0 . If i anImagei0 is defined, the decoded image will be appended using the b -useRepresentation:b0 method. If i aDecoderi0 is not defined, this method determines the decoder using the b -decoderForStream:b0 method. fs16 fs28 fs16 fs28 Returns the decoded image upon success, or b nilb0 upon failure. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderByType s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decoderByTypeb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoderByType HashTable. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderClassByType s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decoderClassByTypeb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoderClassByType HashTable. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderClassForStream: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (Class)b decoderClassForStream:b0 (NXStream *)i aStreami0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoder Class used to decode i aStreami0 . If no class is available, returns b nilb0 . fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderClassForType: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (Class)b decoderClassForType:b0 (const char *)i imageTypei0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoder class for images of type i imageTypei0 . This can be used to customize the particular image decoder. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderForStream: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decoderForStream:b0 (NXStream *)i aStreami0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoder object that should be used to decode i aStreami0 . If an appropriate decoder object is not available, returns b nilb0 . fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderForType: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decoderForType:b0 (const char *)i imageTypei0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoder for images of type i imageTypei0 . This can be used to customize the particular image decoder. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b decoderList s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b decoderListb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the decoderList List. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b dumpTypes s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (void)b dumpTypesb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Pretty-prints file extensions to stderr. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b errorDelegate s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b errorDelegateb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns the image decoder's error delegate. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b free s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b freeb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Frees the image decoder and all specific type decoders. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b imageDepth s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (NXWindowDepth)b imageDepthb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns i imageDepthi0 . fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b imageUnfilteredFileTypes s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (const char *const *)b imageUnfilteredFileTypesb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns b NULLb0 terminated array of strings containing all of the image types an instance of SurfImageDecoder can decode. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b init s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} b initb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Designated intializer. Creates entries in i decoderByTypei0 for each decoder type, but does not allocate/initialize any decoders. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b lastImageCorrupt s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (BOOL)b lastImageCorruptb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns YES if last the image that was decoded contained some kind of error. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b printForDebugger: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (void)b printForDebugger:b0 (NXStream *)i aStreami0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Prints a summary of the decoders state to i aStreami0 . fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b setErrorDelegate: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (void)b setErrorDelegate:b0 (id <SurfErrorDelegate>)i aDelegatei0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Sets the error delegate to i aDelegatei0 . i aDelegatei0 's implementation of b -decoder:spewMessage:withSeverity:b0 will be invoked whenever a decoder generates an error message. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b setImageDepth: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (void)b setImageDepth:b0 (NXWindowDepth)i aDepthi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Sets the target image depth to i aDepthi0 . Some of the image decoders can optimize the decoding process to a specific depth. This method will propagate i aDepthi0 to all decoders using the b setImageDepthb0 method; whether or not a decoder can actually decode to that depth is entirely up to the decoder. fs16 fs28 fs16 fs28 Generally, image decoders default to producing 24-bit deep images. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b setSpewToStderr: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (void)b setSpewToStderr:b0 (BOOL)i aFlagi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 If i aFlagi0 is YES, error messages geneerated by decoders will be printed via NXLogError(). fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b setVerboseMode: s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (void)b setVerboseMode:b0 (BOOL)i aFlagi0 b b0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Enabled/disables verbose mode. Verbose mode spews a HUGE quantity of state information to stderr. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b spewToStderr s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (BOOL)b spewToStderrb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns YES if error messages will be printed to the console/stderr. fs16 fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 fs29 b verboseMode s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (BOOL)b verboseModeb0 pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 fs28 Returns YES if verbose mode is enabled. }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.