1 //  ----------------------------------------------------------------------------
2 //  MODULE    : PHierarchicalImage
3 //  LANGUAGE  : C++
4 //  CREATOR   : Philippe BOSSUT
5 //  CREAT. DATE : Tuesday, March 12, 1996
6 //  DESCRIPTION :
7 //  COMMENTS  :
8 //  SCCSID      : @(#)ph_image.h  1.1 11:46:41 18 Dec 1996
9 //  ----------------------------------------------------------------------------
10 //  Copyright (c) 1999 Digital Imaging Group, Inc.
11 //  For conditions of distribution and use, see copyright notice
12 //  in Flashpix.h
13 //  ----------------------------------------------------------------------------
14   #ifndef PHierarchicalImage_h
15   #define PHierarchicalImage_h
16   #ifndef Commun_h
17     #include  "common.h"
18   #endif
19 //  ----------------------------------------------------------------------------
20 
21 //  Includes
22 //  --------
23 
24 #ifndef PRIImage_h
25   #include  "priimage.h"
26 #endif
27 #ifndef Fichier_h
28   #include  "a_file.h"  // just for Mode
29 #endif
30 #ifndef Compresseur_h
31   #include  "fpxcompress.h"
32 #endif
33 
34 #ifndef FPXBaselineIO_h
35   #include "fpxlibio.h"
36 #endif
37 
38 //  Constants
39 //  ---------
40 
41 //  Types Declarations
42 //  ------------------
43 
44 //  Types Definitions
45 //  -----------------
46 
47 //  Classes Declarations
48 //  --------------------
49 
50   class PResolutionIVUE;
51   class PResolutionFlashPix;
52   class PTileIVUE;
53   class PTileFlashPix;
54   class PHierarchicalImage;
55 
56 //  Classes Definitions
57 //  -------------------
58 
59   // Implementation of Resolution Independent Image with Hierarchy (IVUE and FlashPix)
60 
61   class PHierarchicalImage : public PRIImage {
62 
63   friend class PResolutionLevel;
64   friend class PResolutionIVUE;
65   friend class PResolutionFlashPix;
66   friend class PTile;
67   friend class PTileIVUE;
68   friend class PTileFlashPix;
69   friend class PageImage;
70 
71   public:
72         // Constructors and destructor :
73 
74                  // Open the file in Create Mode
75                  PHierarchicalImage (FicNom& refNom, int width, int height, float resolution);
76                  PHierarchicalImage (int fd, int width, int height, float resolution);
77                  // Open the file in Read Mode only
78                  PHierarchicalImage (FicNom& refNom);
79                  PHierarchicalImage (int fd);
80                  // Open the file in Read/Write mode (but not Create)
81                  PHierarchicalImage (FicNom& refNom, mode_Ouverture openMode);
82                  PHierarchicalImage (int fd, mode_Ouverture openMode);
83 
84         virtual     ~PHierarchicalImage ();
85 
86         // Public interface: Customize a RI Image:
87         // ---------------------------------------
88 
89         // Read a buffer of pixels methods:
90         virtual FPXStatus ReadRectangle (int x0, int y0, int x1, int y1, Pixel* rect, int resolution = -1);
91         virtual FPXStatus ReadInARectangle(Pixel* bufferOut, short pixelsParLigne, short largeur, short hauteur,
92                          const CorrectLut* correctLut = NULL, Boolean useAlphaChannel = FALSE, const CombinMat* matDeCombinaison = NULL);
93         virtual FPXStatus Read4Points (int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, Pixel* table, int levelSubImage = -1);
94         virtual FPXStatus ReadMean (int xi, int yi, Pixel& pix, int levelSubImage);
95 
96         // Return true if the alpha channel is not flat in the neighborhood
97             Boolean DispersionAlphaChannel (int xNW, int yNW, int xNE, int yNE, int xSW, int ySW, int xSE, int ySE, int levelSubImage);
98 
99         // Get information tools
100         virtual FPXStatus GetTileSize (int* tileSize);
101         virtual FPXStatus GetFileName (FicNom& refNom);
102         virtual FPXStatus GetHistogram (int* alpha, int* red, int* green, int* blue, int* brightness, const CorrectLut* correctLut = NULL);
103 
104         // Set information tools
105         virtual void  SetConvolution (Typ_Convolution newConvolution);
106         virtual void  SetAutomaticDecimation (Boolean automaticDecimationOn);
107 
108         // Set compression
109         virtual void  SetCompression (Typ_Compression theCompression);
110 
111         // Alpha channel management
112         virtual Boolean SetAlphaChannel(Boolean exist);
113 
114         // Path management :
115         virtual OSErr ReadPaths  (data_Record** thePath, int* nbRecords, int* theClipPathNum);
116         virtual OSErr WritePaths (data_Record*  thePath, int  nbRecords, int  theClipPathNum);
117 
118         // Public interface: Methods used by the application to use a Hierarchical Image:
119         // ------------------------------------------------------------------------------
120         // These methods must be derived in most of the cases
121 
122         // File management:
123         virtual FPXStatus OpenImage();        // Open an Image in read, write or create mode
124         virtual void    DoNotCloseFileWhenDelete();
125         virtual void*   GetCurrentFile();     // return the file descriptor filePtr
126         virtual Boolean   EnoughDiskSpace ();     // Test if there is enough space on disk to create the file
127 
128         // Write a buffer of pixels methods:
129         virtual FPXStatus WriteLine (Pixel* line, short plan = -1);
130         virtual FPXStatus WriteRectangle (int x0, int y0, int x1, int y1, Pixel* rect, short plan = -1, short resolution = 0);
131         virtual FPXStatus RegenerateHierarchy ();
132 
133         // Get information tools
134             long    GetNbResolutions ();
135         virtual FPXStatus GetInfo (int* width, int* height, int* tileWidth, int* tileHeight, Typ_Compression* compr);
136 
137         // Color space & background color management
138     FPXBaselineColorSpace   GetBaselineSpace();
139     FPXBaselineColorSpace GetUsedColorSpace ();
140             void  SetUsedColorSpace (FPXBaselineColorSpace colorSpace);
141             void  SetBaseColorSpace (FPXBaselineColorSpace colorSpace);
142             void  ResetUsedColorSpace ();
143             void  SetBackgroundColor (FPXBaselineColorSpace colorSpace, Pixel backgroundColor);
144             void  SetUncalibratedFlag(Boolean isUncalibrated);
145             Boolean GetUncalibratedFlag();
146 
147   protected:
148         // Protected interface: Customize a RI Image:
149         // ------------------------------------------
150 
151         virtual FPXStatus ReadSampledRectangle(int x0, int y0,int x1, int y1, Pixel* map, short pixelsPerLine, int mapWidth, int mapHeight, Boolean showAlphaChannel = FALSE, float ratio = 0.0);
152         virtual FPXStatus SearchPixelTopLeftCorner(int* x1, int* y1, float ratio);
153 
154         // Alpha channel management
155         virtual FPXStatus InverseAlpha();     // Inverse alpha channel in all opened sub-images
156 
157         // Error management
158         virtual void    UpdateErrorCount();   // Increment counter and invalid the image if necessary
159 
160         // Protected interface: Methods used by the derived classes to customize the behavior of a Hierarchical Image:
161         // -----------------------------------------------------------------------------------------------------------
162 
163         // Set information tools
164         virtual FPXStatus SetTileParameter (int width, int height);
165 
166         // File management:
167         virtual FPXStatus OpenFile();         // Read or Init header file information
168         virtual FPXStatus CloseFile();                              // End sub images computation and writing before closing the file
169         virtual void    CloseFileWhenDelete();
170 
171         // Resolution hierarchy management:
172         virtual FPXStatus InitResolutionLevelsTable();                      // Update pointers array of sub images
173         virtual FPXStatus CreateInitResolutionLevelList();                    // Make a sub image list in read or write mode
174         virtual FPXStatus CreateEmptyResolutionLevelList();                   // Make a sub image list in create mode
175     virtual PResolutionLevel* CreateEmptyResolutionLevel(int width, int height, int* quelImage); // Make a sub image in create mode
176     virtual PResolutionLevel* CreateInitResolutionLevel(int* offset, long id);           // Make a sub image in read or write mode
177 
178         // Protected data of the Hierarchical Image object
179         // -----------------------------------------------
180 
181         FicNomSearchIVUE  fileName;     // Name of the image file
182         PImageFile*     filePtr;        // The image file descriptor
183         int         fd;           // The standard file descriptor (if provided by the user)
184         mode_Ouverture    mode;         // The opening mode
185         int32       posFic;         // Position of the header in the file
186         int32       version;        // Version of the file
187 
188         PResolutionLevel* firstSubImage;      // This first resolution level is the full resolution image.
189         long        nbSubImages;      // Number of sub-images
190         PResolutionLevel**  subImages;        // Copy of the sub-image list
191 
192         int32       posPath;        // Position of the paths in the file
193         Boolean       isFlatFile;
194 
195   protected:
196         // Private init of a PHierarchicalmage -> this is not a virtual method
197             void  Init();
198 
199         // Private data of the Hierarchical Image object
200         // ---------------------------------------------
201 
202     FPXBaselineColorSpace     baseSpace;        // Base color space used natively in the file
203         Boolean       baseUncalibrated;   // True if the colors are not calibrated in the file
204     FPXBaselineColorSpace     usedSpace;        // Color space used by the user when reading or writing
205         unsigned char   alphaOffset;      // position of the alpha channel in a 32 bits pixel for the usedSpace
206         Pixel       backgroundBase;     // Color of the background in the base color space (used when writing)
207         Pixel       backgroundUsed;     // Color of the background in the used color space (used when reading)
208 
209         Typ_Convolution   convolution;      // Convolution used in this image file
210         Typ_Filter      filter;         // Convolution function used in this image file
211         Boolean       automaticDecimation;  // Convolution of subimages done automatically if true
212 
213         Typ_Compression   compression;      // Compression mode used in this image file
214         void*       compressionHandle;    // Compression/decompression handle
215         int         handleSize;       // Size (in bytes) on this handle
216 
217         int         tileWidth;        // Width in pixels of a tile
218         int         tileSize;       // = tileWidth * tileWidth * Sizeof(Pixel)
219         int         tileLineSize;     // = tileWidth * Sizeof(Pixel)
220         int         log2TileWidth;      // When doing ">>" instead of "/" (fast integer computation)
221         int         maskTileWidth;      // When doing "&"  instead of "%" (fast integer computation)
222   };
223 
224 //  'inline' Functions
225 //  ------------------
226 
GetNbResolutions()227 inline long PHierarchicalImage::GetNbResolutions () { return nbSubImages; }
228 
SetCompression(Typ_Compression theCompression)229 inline void PHierarchicalImage::SetCompression (Typ_Compression theCompression) { compression = theCompression; }
230 
GetUsedColorSpace()231 inline FPXBaselineColorSpace PHierarchicalImage::GetUsedColorSpace () { return usedSpace; }
GetBaselineSpace()232 inline FPXBaselineColorSpace PHierarchicalImage::GetBaselineSpace()   { return baseSpace; }
ResetUsedColorSpace()233 inline void PHierarchicalImage::ResetUsedColorSpace () { SetUsedColorSpace (baseSpace); }
SetUncalibratedFlag(Boolean isUncalibrated)234 inline void PHierarchicalImage::SetUncalibratedFlag(Boolean isUncalibrated) { baseUncalibrated = isUncalibrated; }
GetUncalibratedFlag()235 inline Boolean PHierarchicalImage::GetUncalibratedFlag() { return baseUncalibrated; }
236 
237 
238 
239 
240 //  'extern' Functions
241 //  ------------------
242 
243 //  'extern' Variables
244 //  ------------------
245 
246 //  ----------------------------------------------------------------------------
247   #endif // PHierarchicalImage_h
248 //  ----------------------------------------------------------------------------
249