1 // ----------------------------------------------------------------------------
2 // MODULE : PRIImage
3 // LANGUAGE : C++
4 // CREATOR : Philippe BOSSUT
5 // CREAT. DATE : Tuesday, March 12, 1996
6 // DESCRIPTION : Portable Resolution Independent Image
7 // COMMENTS : This package is a part of the IVUE Toolkit I/O and of
8 // the FlashPix Baseline I/O Toolkit
9 // SCCSID : @(#)priimage.h 1.1 11:46:42 18 Dec 1996
10 // ----------------------------------------------------------------------------
11 // Copyright (c) 1999 Digital Imaging Group, Inc.
12 // For conditions of distribution and use, see copyright notice
13 // in Flashpix.h
14 // ----------------------------------------------------------------------------
15 #ifndef PRIImage_h
16 #define PRIImage_h
17 #ifndef Commun_h
18 #include "common.h"
19 #endif
20 // ----------------------------------------------------------------------------
21
22 // Includes
23 // --------
24
25 #ifndef SystemIVUE_h
26 #include "ri_sys.h"
27 #endif
28 #ifndef FicNomSearchIVUE_h
29 #include "fn_srch.h"
30 #endif
31
32 #ifndef CombinMat_h
33 #include "matrix.h"
34 #endif
35
36 #ifndef FPXBaselineIO_h
37 #include "fpxlibio.h"
38 #endif
39
40 // to avoid include CorrectLut.h
41 struct CorrectLut;
42
43 // Constants
44 // ---------
45 //
46 // A 4x4 sample is defined as follows :
47 //
48 // 2> . .<3 if (x0,y0) are the coordinates of the center of P00, (x1,y1), (x2,y2) and (x3,y3) are
49 // P03 P13 P23 P33 the coordinates of the center of the surrounding pixels. They are outside the sample.
50 // P02 P12 P22 P32 The middle of (0,3) segment is then P22, the middle of (0,1) is P20, etc�
51 // P01 P11 P21 P31
52 // P00 P10 P20 P30 .
53 // ^ ^
54 // 0 1
55 //
56 #define SAMPLE_WIDTH 4
57
58 #define P00 0
59 #define P10 1
60 #define P20 2
61 #define P30 3
62 #define P01 4
63 #define P11 5
64 #define P21 6
65 #define P31 7
66 #define P02 8
67 #define P12 9
68 #define P22 10
69 #define P32 11
70 #define P03 12
71 #define P13 13
72 #define P23 14
73 #define P33 15
74
75 // Types Declarations
76 // ------------------
77
78 // Types Definitions
79 // -----------------
80
81 // Classes Declarations
82 // --------------------
83
84 class PRIImage;
85 class PResolutionLevel;
86 class PTile;
87 class PageImage;
88 class PImageFile;
89 class ViewImage;
90 class PFlashPixImageView;
91
92 // Classes Definitions
93 // -------------------
94
95 // PRIImage stands for Portable Resolution Independent Image
96
97 class PRIImage : public PToolkitObject {
98
99 friend class PResolutionLevel;
100 friend class PTile;
101 friend class PageImage;
102 friend class ViewImage;
103 friend class PFlashPixImageView;
104
105 public:
106 // Constructors and destructor :
107
108 // Image constructors
109 PRIImage ();
110 PRIImage (int width, int height, float resolution);
111
112 virtual ~PRIImage ();
113
114 // Public interface: Methods used by the application to read a RI Image:
115 // ---------------------------------------------------------------------
116 // These methods must be derived in most of the cases
117
118 // Global flag: read with interpolation between levels when true, simple subsampling when false
119 static Boolean readInterpolated;
120
121 // Read a buffer of pixels methods:
122 virtual FPXStatus ReadRectangle (int x0, int y0, int x1, int y1, Pixel* rect, int resolution = -1);
123 virtual FPXStatus ReadInARectangle(Pixel* bufferOut, short pixelsParLigne, short largeur, short hauteur,
124 const CorrectLut* correctLut = NULL, Boolean useAlphaChannel = FALSE, const CombinMat* matDeCombinaison = NULL);
125 virtual FPXStatus Read4Points (int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, Pixel* table, int levelSubImage = -1);
126 virtual FPXStatus ReadMean (int xi, int yi, Pixel& pix, int levelSubImage);
127
128 // Return true if the alpha channel is not flat in the neighborhood
129 Boolean DispersionAlphaChannel (int xNW, int yNW, int xNE, int yNE, int xSW, int ySW, int xSE, int ySE, int levelSubImage);
130
131 // Get information tools
132 virtual FPXStatus GetFileName (FicNom& refNom);
133 FPXStatus GetDimensions (int* width, int* height); // Get pixel dimensions of the high res after cropping (if any)
134 virtual FPXStatus GetTrueDimensions (int* width, int* height); // Get pixel dimensions of the high res without cropping
135 FPXStatus GetResolution (float* resol);
136 virtual FPXStatus GetHistogram (int* alpha, int* red, int* green, int* blue, int* brightness, const CorrectLut* correctLut = NULL);
137 virtual FPXStatus GetCropRectangle (int* x0, int* y0, int* x1, int* y1);
138 virtual FPXStatus GetHotSpot (int* x0, int* y0);
139
140 // Set information tools
141 virtual FPXStatus SetCropRectangle (int x0, int y0, int x1, int y1);
142 virtual FPXStatus ResetCropRectangle ();
143 void SetImageParameter (ViewImage* viewImage);
144 void SetApplyParameter (Boolean applyParameter);
145
146 // Alpha channel management
147 Boolean ExistAlphaChannel();
148 virtual Boolean SetAlphaChannel(Boolean exist);
149 virtual FPXStatus UseAlphaChannel (Boolean useAlpha);
150 virtual FPXStatus InvertAlphaChannel (Boolean inverseAlpha);
151
152 // Path management
153 virtual OSErr ReadPaths (data_Record** thePath, int* nbRecords, int* theClipPathNum);
154 virtual OSErr ReleasePaths ();
155
156 // Error management
157 virtual FPXStatus Status ();
158
159 // Reference management
IncrementReference()160 void IncrementReference() { nbRefs++; }
DecrementReference()161 void DecrementReference() { nbRefs--; }
NoMoreReference()162 Boolean NoMoreReference() { return (nbRefs == 0); }
163
ResetMagicNumber()164 void ResetMagicNumber() { magicNumber = 0; }
SetMagicNumber()165 void SetMagicNumber() { magicNumber = (unsigned long)(this); }
ChallengeMagicNumber()166 Boolean ChallengeMagicNumber() { return (magicNumber == (unsigned long)(this)); }
SetMagicNumber(unsigned long id)167 void SetMagicNumber(unsigned long id) { magicNumber = id; }
ChallengeMagicNumber(unsigned long id)168 Boolean ChallengeMagicNumber(unsigned long id) { return (magicNumber == id); }
GetMagicNumber()169 unsigned long GetMagicNumber() { return magicNumber; }
170 protected:
171 // Protected interface: Methods used by the derived classes to customize the behavior of a RI Image:
172 // -------------------------------------------------------------------------------------------------
173
174 // Read a buffer of pixels methods:
175 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);
176 virtual FPXStatus SearchPixelTopLeftCorner(int* x1, int* y1, float ratio);
177
178 // Set information tools
179 virtual FPXStatus SetHotSpot (int x0, int y0);
180 virtual FPXStatus SetImageSize (int theWidth, int theHeight, float theResolution);
181
182 // Alpha channel management
183 virtual FPXStatus InverseAlpha(); // Inverse alpha channel in all opened sub-images
184
185 // Error management
186 virtual void UpdateErrorCount();
RaiseError(FPXStatus err)187 void RaiseError (FPXStatus err) { error = err; }
188
189 // Data of the Resolution Independent Image object
190 // -----------------------------------------------
191
192 int height, width; // Full resolution image size in pixels
193 float resolution; // Scanning resolution in dot per mm
194 Boolean useAlphaChannel; // Use the alpha channel when reading
195 Boolean existAlphaChannel; // Existence of an alpha channel in the image file
196 Boolean inverseAlphaChannel; // Inverse alpha channel when reading
197 int hotSpotX, hotSpotY; // Hot Spot position within the full resolution image
198
199 int cropX0, cropY0; // Top left crop point position
200 int cropX1, cropY1; // Bottom right crop point position
201 data_Record* path; // Path handle
202 int32 nbPaths; // Number of path records
203 int32 clipPathNum; // Number of the clip path in the path list
204
205 // Pointer to the View Image object (if any) and application flag
206 ViewImage* imageParam;
207 Boolean applyParam;
208
209 private:
210 // Private init of a PRIImage -> this is not a virtual method
211 void Init();
212
213 // Data of the Resolution Independent Image
214 // ----------------------------------------
215
216 // Reference management
217 unsigned long magicNumber; // Used to reference a PRIImage object used by several composition objects
218 int nbRefs; // Number of existing references to this PRIImage object
219
220 // Error management
221 FPXStatus error; // Correctness of the PRIImage : error == 0 when all is OK
222 int nbError; // Count number of errors reading the image
223 };
224
225
226 // 'inline' Functions
227 // ------------------
228
229 // PRIImage inline functions : Obtaining usefull information tools :
230
GetDimensions(int * width,int * height)231 inline FPXStatus PRIImage::GetDimensions (int* width, int* height)
232 {
233 *height = cropY1 - cropY0;
234 *width = cropX1 - cropX0;
235 if (!(*height)) *height = this->height;
236 if (!(*width)) *width = this->width;
237 return FPX_OK;
238 }
239
240 // Return resolution in dot per mm
GetResolution(float * resol)241 inline FPXStatus PRIImage::GetResolution (float* resol)
242 {
243 *resol = resolution;
244 return FPX_OK;
245 }
246
ExistAlphaChannel()247 inline Boolean PRIImage::ExistAlphaChannel ()
248 {
249 return existAlphaChannel;
250 }
251
SetImageParameter(ViewImage * viewImage)252 inline void PRIImage::SetImageParameter (ViewImage* viewImage)
253 {
254 imageParam = viewImage;
255 }
256
SetApplyParameter(Boolean applyParameter)257 inline void PRIImage::SetApplyParameter (Boolean applyParameter)
258 {
259 applyParam = applyParameter;
260 }
261
262 // 'extern' Functions
263 // ------------------
264
265 // 'extern' Variables
266 // ------------------
267
268 // ----------------------------------------------------------------------------
269 #endif // PRIImage_h
270 // ----------------------------------------------------------------------------
271