1 //  ----------------------------------------------------------------------------
2 //  MODULE    : PRIImage
3 //  LANGUAGE  : C++
4 //  CREATOR   : Philippe BOSSUT
5 //  CREAT. DATE : Tuesday, March 12, 1996
6 //  DESCRIPTION :
7 //  COMMENTS  :
8 //  SCCSID      : @(#)priimage.cpp  1.1 11:46:42 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 //  #define Memoire_Debug
15 //  ----------------------------------------------------------------------------
16 
17 //  ----------------------------------------------------------------------------
18   #include "priimage.h"
19 //  ----------------------------------------------------------------------------
20 
21 //  Includes
22 //  --------
23 
24   #include  <stdio.h>
25   #include  <stdlib.h>
26   #include  <string.h>
27 #ifndef _WINDOWS
28   #include  <strings.h>
29 #endif
30   #include  <math.h>
31 #ifdef macintosh
32   #include  <Errors.h>
33 #endif
34 
35 
36 #ifndef Debug_h
37   #include  "debug.h"
38 #endif
39 #ifndef Memoire_h
40 //include "b_memory.h"
41 #endif
42 
43 #ifndef PResolutionLevel_h
44   #include "pr_level.h"
45 #endif
46 #ifndef PTile_h
47   #include "ptile.h"
48 #endif
49 
50 
51 #ifndef Numbers_h
52   #include  "numbers.h"
53 #endif
54 
55 
56 //  Constants
57 //  ---------
58 
59   #define NB_MAX_ERREUR       5
60 
61 //  Variables
62 //  ---------
63 
64   Boolean     PRIImage::readInterpolated = false; // Default is no antialiasing
65 
66 //  ----------------------------------------------------------------------------
67 
68 //  ----------------------------------------------------------------------------
69 
70 //  ----------------------------------------------------------------------------
71 //  Internal Functions
72 //  ----------------------------------------------------------------------------
73 
74 //  ----------------------------------------------------------------------------
75 //  Member Functions
76 //  ----------------------------------------------------------------------------
77 
78 //  ----------------------------------------------------------------------------
79 //  Methods of the PRIImage class
80 //  ----------------------------------------------------------------------------
81 
82 
83 //  ----------------------------------------------------------------------------
84 // Constructor to be used when creating a new Image file
PRIImage(int width,int height,float resolution)85 PRIImage::PRIImage (int width, int height, float resolution)
86 {
87   Init ();                  // Init the object
88   SetImageSize (width, height, resolution); // Set the high res size and related values
89 }
90 
91 
92 //  ----------------------------------------------------------------------------
93 // Constructor to be used when reading or writing onto an existing Image file
PRIImage()94 PRIImage::PRIImage ()
95 
96 {
97   Init ();    // Init the object
98 }
99 
100 
101 //  ----------------------------------------------------------------------------
102 // Close file and clean memory
~PRIImage()103 PRIImage::~PRIImage ()
104 {
105   ReleasePaths ();
106 }
107 
108 
109 //  ----------------------------------------------------------------------------
110 // Give default values to image information before starting reading or using them
Init()111 void PRIImage::Init ()
112 {
113   // PRIImage values
114   height          = 0;
115   width         = 0;
116   resolution      = (float) (300.0/2.54);
117   magicNumber     = 0;
118   nbRefs        = 0;
119 
120   useAlphaChannel     = false;
121   existAlphaChannel   = GtheSystemToolkit->existAlpha;
122   inverseAlphaChannel = false;
123   hotSpotX      = 0;
124   hotSpotY      = 0;
125   cropX0        = 0;
126   cropY0        = 0;
127   cropX1        = 0;
128   cropY1        = 0;
129 
130   path        = NULL;
131   nbPaths       = 0;
132   clipPathNum     = 0;
133 
134   error       = FPX_OK;         // No error for now�
135   nbError       = 0;            // No counted error for now�
136 
137   imageParam      = NULL; // Image viewing params set by ViewImage, not here
138   applyParam      = TRUE; // By default, the viewing parameters are ALWAYS applied
139 }
140 
141 
142 // Set the image size and the related parameters
SetImageSize(int theWidth,int theHeight,float theResolution)143 FPXStatus PRIImage::SetImageSize (int theWidth, int theHeight, float theResolution)
144 {
145   resolution  = theResolution;
146 
147   height    = theHeight;
148   width   = theWidth;
149 
150   cropX0    = 0;
151   cropY0    = 0;
152   cropX1    = width;
153   cropY1    = height;
154   hotSpotX  = width/2;
155   hotSpotY  = height/2;
156   return FPX_OK;
157 }
158 
159 
160 //  ----------------------------------------------------------------------------
GetFileName(FicNom &)161 FPXStatus PRIImage::GetFileName (FicNom& )
162 {
163   return FPX_UNIMPLEMENTED_FUNCTION;
164 }
165 
166 
167 //  ----------------------------------------------------------------------------
UpdateErrorCount()168 void PRIImage::UpdateErrorCount()
169 {
170   if (++nbError > NB_MAX_ERREUR)  // If too many errors...
171     error = FPX_ERROR;      // ...then raise an error
172 }
173 
174 
175 //  ----------------------------------------------------------------------------
176 // Return the status of the image file
Status()177 FPXStatus PRIImage::Status ()
178 {
179   return(error);
180 }
181 
182 
183 //  ----------------------------------------------------------------------------
184 // Read a rectangle in the correct resolution level and fill 'pix' with it
ReadRectangle(int,int,int,int,Pixel *,int)185 FPXStatus PRIImage::ReadRectangle (int , int , int , int , Pixel* , int )
186 {
187   return FPX_UNIMPLEMENTED_FUNCTION;
188 }
189 
190 
191 //  ----------------------------------------------------------------------------
Read4Points(int,int,int,int,int,int,int,int,Pixel *,int)192 FPXStatus PRIImage::Read4Points (int , int , int , int , int , int , int , int , Pixel* , int )
193 {
194   return FPX_UNIMPLEMENTED_FUNCTION;
195 }
196 
197 
198 //  ----------------------------------------------------------------------------
199 // Send back the smallest image contained in a rectangle width * height.
200 // Read it on disk if necessary.
201 // If decompressor is missing, send back NULL.
202 // CAUTION : bufferOut must be allocated and freed by calling routine
203 // CAUTION : we allocate a temporary buffer with pixelsPerLine*height pixels
ReadInARectangle(Pixel *,short,short,short,const CorrectLut *,Boolean,const CombinMat *)204 FPXStatus PRIImage::ReadInARectangle (Pixel* , short , short , short ,
205                   const CorrectLut* , Boolean , const CombinMat* )
206 {
207   return FPX_UNIMPLEMENTED_FUNCTION;
208 }
209 
210 
211 //  ----------------------------------------------------------------------------
212 // Read the path from the Image file: this function has to be derived to really write the things in
213 // the file. The following code handle only the memory management part.
ReadPaths(data_Record ** thePath,int * nbRecords,int * theClipPathNum)214 OSErr PRIImage::ReadPaths (data_Record** thePath, int* nbRecords, int* theClipPathNum)
215 {
216   // Provide the cached path to the caller
217   *nbRecords      = nbPaths;
218   *thePath        = path;
219   *theClipPathNum = clipPathNum;
220 
221   OSErr  err = noErr;
222   if (path)
223     // If there is a path already cached here, avoid to read again...
224     err = noErr;
225   else
226     // Can't read here: see derived class...
227     #ifdef macintosh
228       err = userDataItemNotFound;
229     #else
230       err = -1;   // GDN - actual code found in Errors.h
231     #endif
232 
233   return err;
234 }
235 
236 
237 //  ----------------------------------------------------------------------------
238 // Valid for all derived classes
ReleasePaths()239 OSErr PRIImage::ReleasePaths ()
240 {
241   // Delete the path record if any
242   if (path)
243     delete [] path;
244 
245   // Reset all path related data
246   path        = NULL;
247   nbPaths     = 0;
248   clipPathNum = 0;
249 
250   return noErr;
251 }
252 
253 
254 //  ----------------------------------------------------------------------------
UseAlphaChannel(Boolean useAlpha)255 FPXStatus PRIImage::UseAlphaChannel (Boolean useAlpha)
256 {
257   if (existAlphaChannel)
258     useAlphaChannel = useAlpha;
259   return FPX_OK;
260 }
261 
262 
263 //  ----------------------------------------------------------------------------
264 // Set the Boolean existAlphaChannel and test if there is enougth space to use it
SetAlphaChannel(Boolean exist)265 Boolean PRIImage::SetAlphaChannel(Boolean exist)
266 {
267   existAlphaChannel = exist;
268   return true;
269 }
270 
271 
272 //  ----------------------------------------------------------------------------
InverseAlpha()273 FPXStatus PRIImage::InverseAlpha ()
274 {
275   return FPX_OK;
276 }
277 
278 
279 //  ----------------------------------------------------------------------------
InvertAlphaChannel(Boolean inverseAlpha)280 FPXStatus PRIImage::InvertAlphaChannel (Boolean inverseAlpha)
281 {
282   if (existAlphaChannel) {
283     if (inverseAlphaChannel != inverseAlpha) {
284       // Modify the flag
285       inverseAlphaChannel = inverseAlpha;
286       // Reinverse the values already cached
287       InverseAlpha();
288     }
289   }
290   return FPX_OK;
291 }
292 
293 
294 //  ----------------------------------------------------------------------------
GetCropRectangle(int * x0,int * y0,int * x1,int * y1)295 FPXStatus PRIImage::GetCropRectangle (int* x0, int* y0, int* x1, int* y1)
296 {
297   *x0 = cropX0; *y0 = cropY0; *x1 = cropX1; *y1 = cropY1;
298   return FPX_OK;
299 }
300 
301 
302 //  ----------------------------------------------------------------------------
SetCropRectangle(int x0,int y0,int x1,int y1)303 FPXStatus PRIImage::SetCropRectangle (int x0, int y0, int x1, int y1)
304 {
305   // Check consistency : swap bounding values if necessary
306   int t;
307   if (x1 < x0) { t = x1; x1 = x0; x0 = t; }
308   if (y1 < y0) { t = y1; y1 = y0; y0 = t; }
309 
310   // Limit crop rectangle to the true dimension of the image
311   int width, height;
312   if (GetTrueDimensions(&width, &height) != NOT_IMPLEMENTED) {
313     if (x0 < 0)    x0 = 0;
314     if (x1 > width)  x1 = width;
315     if (y0 < 0)    y0 = 0;
316     if (y1 > height) y1 = height;
317   }
318 
319   // Set the crop rectangle
320   cropX0 = x0; cropY0 = y0; cropX1 = x1; cropY1 = y1;
321   return FPX_OK;
322 }
323 
324 
325 //  ----------------------------------------------------------------------------
ResetCropRectangle()326 FPXStatus PRIImage::ResetCropRectangle ()
327 {
328   cropX0 = 0; cropY0 = 0; cropX1 = width; cropY1 = height;
329   return FPX_OK;
330 }
331 
332 
333 //  ----------------------------------------------------------------------------
334 // Read a pixel of a sub image. Read it on disk if necessary.
335 // If error, return false and pixel is set to 0.
336 // CAUTION : coordinates must be discrete with 12 bits precision (1 << 12).
ReadMean(int,int,Pixel &,int)337 FPXStatus PRIImage::ReadMean (int , int , Pixel& , int )
338 {
339   return FPX_UNIMPLEMENTED_FUNCTION;
340 }
341 
342 
343 //  ----------------------------------------------------------------------------
344 // Determine the dispersion of the alpha channel in a neighborhood: the idea is to compare the local value
345 // to the value of the same pixel on the next resolution level. Because of the convolution from a level to
346 // another, one can say that if the pixels are equal, there is no dispersion of the alpha channel, otherwise
347 // there is some. That way, we avoid effective dispersion computation.
348 // CAUTION : coordinates must be discrete with 12 bits precision (1 << 12).
DispersionAlphaChannel(int,int,int,int,int,int,int,int,int)349 Boolean PRIImage::DispersionAlphaChannel (int , int , int , int , int , int , int , int , int )
350 {
351   return (Boolean) NOT_IMPLEMENTED;
352 }
353 
354 
355 //  ----------------------------------------------------------------------------
356 // Read a rectangle (x0,y0,x1,y1: coordinates at full resolution) in a map
357 // The correct sub image is read and sampled in order to fill the map with the rectangle
358 // CAUTION : map must be allocated and freed by calling routine
ReadSampledRectangle(int,int,int,int,Pixel *,short,int,int,Boolean,float)359 FPXStatus PRIImage::ReadSampledRectangle(int , int ,int , int , Pixel* , short , int , int , Boolean , float )
360 {
361   return FPX_UNIMPLEMENTED_FUNCTION;
362 }
363 
364 
365 //  ----------------------------------------------------------------------------
366 // Search the top and left corner of the screen pixel which contains the given position
367 // This function is used when 1 image pixel is represented by more than 1 screen pixel
SearchPixelTopLeftCorner(int *,int *,float)368 FPXStatus PRIImage::SearchPixelTopLeftCorner(int* , int* , float )
369 {
370   return FPX_UNIMPLEMENTED_FUNCTION;
371 }
372 
373 
374 //  ----------------------------------------------------------------------------
375 // Compute histogram for the 4 channels
GetHistogram(int *,int *,int *,int *,int *,const CorrectLut *)376 FPXStatus PRIImage::GetHistogram (int* , int* , int* , int* , int* , const CorrectLut* )
377 {
378   return FPX_UNIMPLEMENTED_FUNCTION;
379 }
380 
381 
382 //  ----------------------------------------------------------------------------
GetTrueDimensions(int * width,int * height)383 FPXStatus PRIImage::GetTrueDimensions (int* width, int* height)
384 {
385   *height = this->height;
386   *width  = this->width;
387   return(FPX_OK);
388 }
389 
390 
391 //  ----------------------------------------------------------------------------
392 // Set the HotSpot coordinates
SetHotSpot(int x0,int y0)393 FPXStatus PRIImage::SetHotSpot (int x0, int y0)
394 {
395   hotSpotX = x0 + cropX0; hotSpotY = y0 + cropY0;
396   return FPX_OK;
397 }
398 
399 
400 //  ----------------------------------------------------------------------------
401 // Get the HotSpot coordinates
GetHotSpot(int * x0,int * y0)402 FPXStatus PRIImage::GetHotSpot (int* x0, int* y0)
403 {
404   *x0 = hotSpotX - cropX0; *y0 = hotSpotY - cropY0;
405   return FPX_OK;
406 }
407 
408 
409 //  - EOF ----------------------------------------------------------------------
410