00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: IMG_Format.h ( IMG Library, C++) 00015 * 00016 * COMMENTS: Declaration of a file format. This class is responsible 00017 */ 00018 00019 #ifndef __IMG_Format__ 00020 #define __IMG_Format__ 00021 00022 #include "IMG_API.h" 00023 #include <iostream.h> 00024 #include "IMG_FileTypes.h" 00025 00026 class UT_IStream; 00027 class UT_String; 00028 class IMG_File; 00029 class IMG_Stat; 00030 class IMG_FileTag; 00031 class IMG_FileOptionList; 00032 class IMG_FileTagList; 00033 00034 extern "C" { 00035 // DSO's should have this function declared. All it has to do is create a 00036 // format of the new type. This will automatically install the format. 00037 // The argument passed in will be a null pointer and can be ignored. 00038 SYS_VISIBILITY_EXPORT void newIMGFormat(void *); 00039 }; 00040 00041 /// Description of a specific image file format, describing the 00042 /// characteristics and capabilities of a specific image file format. 00043 /// It can be used to query the capabilities of that format (resolution limits, 00044 /// data formats supported, image orientation, etc). Image file-specific data 00045 /// (such as resolution of a given file) can be found in IMG_Stat. @n 00046 /// When writing a new data format, many of the virtuals will need to be 00047 /// overridden to properly describe its capabilities. 00048 class IMG_API IMG_Format 00049 { 00050 public: 00051 IMG_Format(); 00052 /// This is a version of the constructor that lets you avoid adding 00053 /// oneself to the list. This is used by the pass throug filter and 00054 /// must be used if you are in multithreaded code as the underlying 00055 /// list is not locked. 00056 explicit IMG_Format(bool addtolist); 00057 virtual ~IMG_Format(); 00058 00059 /// @{ 00060 /// number of currently installed image formats 00061 static int getNFormats(); 00062 /// Access to the list of currently installed image formats 00063 static const IMG_Format *getFormat(int idx); 00064 /// @} 00065 00066 /// @{ 00067 /// Find a format given a filename and a stat - only extension matching. 00068 /// Will only return formats that can read files (isReadable()). 00069 static const IMG_Format *findFormatReadable(const char *filename, 00070 const IMG_Stat *stat = 0); 00071 /// Find a format given a filename and a stat - only extension matching. 00072 /// Will only return formats that can write files (isWritable()). 00073 static const IMG_Format *findFormatWritable(const char *filename, 00074 const IMG_Stat *stat = 0); 00075 /// @} 00076 static const IMG_Format *findFormatByName(const char *format_name); 00077 static const IMG_Format *findFormatByLabel(const char *format_label); 00078 // Find a format given a seekable istream. 00079 static const IMG_Format *findFormatSeekable(UT_IStream &is); 00080 static const IMG_Format *findFormatNonSeekable(UT_IStream &is); 00081 static const IMG_Format *getStdoutFormat(); 00082 IMG_File *allocValidFile() const; 00083 00084 /// @{ 00085 /// All formats must have a unique name (like "JPEG"). 00086 virtual const char *getFormatName() const = 0; 00087 /// If getFormatLabel() is not overridden, the label will be the same as 00088 /// the name. 00089 virtual const char *getFormatLabel() const; 00090 /// @} 00091 00092 /// This can be optionally overridden to return a short description of the 00093 /// format. By default, no description is given. 00094 virtual const char *getFormatDescription() const; 00095 00096 /// Flags whether the format is a pass through format like Flip or Scale. 00097 /// Specific image formats (like JPEG) are never pass-through. 00098 virtual bool isPassThrough() const { return false; } 00099 00100 /// The default extension is used to determine whether the format should 00101 /// appear in the device/format menus. It should not contain the '.' 00102 /// (i.e. "tif" not ".tif") 00103 virtual const char *getDefaultExtension() const; 00104 00105 /// Describes how the format was loaded (i.e. DSO or internal formats) 00106 virtual const char *getFormatLocation() const { return myLocation; } 00107 00108 /// @{ 00109 /// Methods to determine if this is one of our recognized files. 00110 /// The extension is the first try. If there are multiple matches, 00111 /// then we resort to the magic number (when reading) 00112 virtual int checkExtension(const char *filename) const = 0; 00113 /// If possible, this magic numver checker will be called. This is 00114 /// used if the file is "seekable" (i.e. that we can rewind after checking) 00115 virtual int checkMagic(unsigned int) const; 00116 /// If possible, this second magic number checker will be called. This is 00117 /// used if the file is "seekable" (i.e. that we can rewind after checking) 00118 virtual int checkMagicSeekable(UT_IStream &is) const; 00119 /// @} 00120 00121 /// The device method gives a higher priority to device checks. By default, 00122 /// this method returns 0 (no match). This is used to allow things like 00123 /// a60:3.pic (which uses the abekas device). 00124 virtual int checkDevice(const char *) const; 00125 00126 // ------------------------------------------------------------------ 00127 // Image Format features 00128 00129 /// Returns a bitfield of data types supported by this format. 00130 virtual IMG_DataType getSupportedTypes() const = 0; 00131 00132 /// Returns a bitfield of supported color models. If IMG_CM_REVERSED is 00133 /// set, this format stores data in BGR/ABGR format. 00134 virtual IMG_ColorModel getSupportedColorModels() const = 0; 00135 00136 /// Maximum allowable resolution for the file. If a user attempts to write 00137 /// an image larger than this, the image will be scaled to this resolution. 00138 virtual void getMaxResolution(unsigned &x, 00139 unsigned &y) const = 0; 00140 00141 /// @{ 00142 /// Some formats can be read and written in random order. Others require 00143 /// strict sequential order. If these methods return false, you should 00144 /// read and write scanlines in ascending order. When writing, they will 00145 /// be cached until they can be written sequentially. 00146 virtual int isReadRandomAccess() const; 00147 /// If 0 is returned, the scanlines must be written in sequential order or 00148 /// they will be cached until all scanlines can be written sequentially. 00149 virtual int isWriteRandomAccess() const; 00150 /// @} 00151 00152 /// vertical data orientation. Where (0,0) lies in the image 00153 /// (top-left by default). 00154 virtual int isTopFirst() const; 00155 00156 /// horizontal data orientation. Where (0,0) lies in the image 00157 /// (top-left by default). 00158 virtual int isLeftFirst() const; 00159 00160 /// @{ 00161 /// Specifies if this format can read an image file. One of isReadable() 00162 /// or isWritable() (or both) must return true. 00163 virtual bool isReadable() const; 00164 /// Specifies if this format can write an image file. One of isReadable() 00165 /// or isWritable() (or both) must return true. 00166 virtual bool isWritable() const; 00167 //// @} 00168 00169 // data organization. 00170 00171 /// does this format support a data window or sub-area. 00172 virtual bool isDataWindowSupported() const; 00173 00174 /// if true, this format only supports data windows contained within 00175 /// the image resolution (a crop region). 00176 virtual bool isDataWindowCropOnly() const; 00177 00178 /// does this format support saving whether the data outside the window 00179 /// is streaked from the window edges? 00180 virtual bool isDataWindowStreakSupported() const; 00181 00182 /// does this format support deep rasters or multiple images? 00183 /// If not, only one plane of the color models that this format supports 00184 /// is allowed. 00185 virtual bool isDeepRasterSupported() const; 00186 00187 /// does this deep raster allow RGBA in one plane (true) or split into 00188 /// 2 planes (RGB, A). (default false) 00189 virtual IMG_DeepRasterColor getDeepRasterRGBASupport() const; 00190 00191 /// Specifies whether this format stores its data interleaved (RGBRGBRGB) 00192 /// or non-interleaved (RRRGGGBBB). If your format supports both, pick one. 00193 virtual bool isDataInterleaved() const; 00194 00195 /// if true, planes can have different data formats & components. Otherwise, 00196 /// all planes must have the same data type and number of components. 00197 virtual bool canPlaneTypesDiffer() const; 00198 00199 /// Returns a list of options that can be set on the format when reading or 00200 /// writing (like 'compression' or 'comment'). 00201 virtual const IMG_FileOptionList *getOptions() const; 00202 00203 /// @private 00204 // Allocate default tags and their values 00205 void defaultTags(IMG_FileTagList &tags) const; 00206 00207 /// Set an option globally for all formats. Use with extreme care. 00208 static void setGlobalOption(const char *name, const char *value); 00209 /// Read the value of a global option. May return a NULL string. 00210 static void getGlobalOption(const char *name, UT_String &value); 00211 00212 /// Allows you to change an option on a specific format. This will change 00213 /// the option for all formats from this point on, whereas setGlobalOption 00214 /// would not. Returns false if the format or the option couldn't be found. 00215 static bool setFormatOptionDefault(const char *format_name, 00216 const char *format_option, 00217 const char *defvalue); 00218 /// Returns the value of a format-specific option. Returns false if the 00219 /// format or option does not exist. 00220 static bool getFormatOptionDefault(const char *format_name, 00221 const char *format_option, 00222 UT_String &defvalue); 00223 00224 /// Matches a filename against a single extension 00225 static int matchExtension(const char *filename, const char *ext); 00226 00227 /// Matches a filename against a list of extensions (the last entry must be 00228 /// NULL) 00229 static int matchExtensions(const char *filename, const char *ext[]); 00230 00231 /// Between these two formats, which should be preferred? returns either 00232 /// this or the format parameter. This method is used to resolve 00233 /// conflicts between formats when files are being created. 00234 virtual const IMG_Format *resolvePriority(const IMG_Format *format) 00235 const; 00236 00237 protected: 00238 // Returns 1 if the stat's are ok for the format specified. For example, 00239 // if there's a fixed resolution for a format, the format can nullify the 00240 // validity of the format in the determination stage. By default, we 00241 // simply check the image depth (i.e. number of images) and compare the max 00242 // resolution. 00243 virtual IMG_File *createFile() const = 0; 00244 virtual int isFormatOk(const IMG_Stat &stat) const; 00245 void removeFormatFromList(); 00246 00247 static const IMG_Format *findFormat(const char *filename, 00248 const IMG_Stat *stat, 00249 bool for_read); 00250 00251 const IMG_FileTagList *getGlobalTags(); 00252 00253 private: 00254 static int getNFormatsCS(); 00255 static void installBasics(); 00256 char *myLocation; 00257 }; 00258 00259 #endif 00260
1.5.9