1 //  ----------------------------------------------------------------------------
2 //  MODULE    : FPXBaselineIO
3 //  LANGUAGE  : C++
4 //  CREATOR   : Philippe BOSSUT
5 //  CREAT. DATE : Friday, April 5, 1996
6 //  DESCRIPTION :
7 //  COMMENTS  :
8 //    SCCSID          : @(#)fpxlibio.cpp  1.13 12:35:57 22 Jul 1997
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 
15 //  ----------------------------------------------------------------------------
16 
17 //  ----------------------------------------------------------------------------
18 
19 //  Includes
20 //  --------
21 
22 
23 #ifndef Memoire_h
24 //include "b_memory.h"
25 #endif
26 #ifndef OLECommun_h
27   #include "olecomm.h"
28 #endif
29 #ifndef OLECore_h
30   #include "olecore.h"
31 #endif
32 #ifndef OLEStorages_h
33   #include "olestorg.h"
34 #endif
35 #ifndef OLEStreams_h
36   #include "olestrm.h"
37 #endif
38 #ifndef OLEProperties_h
39   #include  "oleprop.h"
40 #endif
41 #ifndef OLEPropertySet_h
42   #include  "oleprops.h"
43 #endif
44 
45 #ifndef Compresseur_h
46   #include "fpxcompress.h"
47 #endif
48 #ifndef CompressorJPEG_h
49   #include "cp_jpeg.h"
50 #endif
51 #ifndef FileFlashPixIO_h
52   #include "f_fpxio.h"
53 #endif
54 #ifndef FPXImageView_h
55   #include "fpximgvw.h"
56 #endif
57 #ifndef FlashPixFormat_h
58   #include "fpxformt.h"
59 #endif
60 #ifndef FlashPixUtils_h
61   #include "fpxutils.h"
62 #endif
63 #ifndef PageIVUE_h
64   #include "ri_page.h"
65 #endif
66 #ifndef FlashPixJPEG_h
67   #include "fpxjpeg.h"
68 #endif
69 #if defined(_UNIX) // for CoFileTimeNow
70   #include "time.hxx"
71 #endif
72 
73 //  Constants
74 //  ---------
75 
76 // Default resolution is 300 dpi
77 #define DEFAULT_RESOLUTION (300.0/25.4)
78 
79 //  Variables
80 //  ---------
81 
82 //  ----------------------------------------------------------------------------
83 //  Internal Functions
84 //  ----------------------------------------------------------------------------
85 
86 //  ----------------------------------------------------------------------------
87 //  Utilities Functions
88 //  ----------------------------------------------------------------------------
89 
90 
91 
FPXUpdateTime(FPXfiletime * theFPXTime)92 void FPXUpdateTime (FPXfiletime* theFPXTime)
93 {
94   // FIXME: This has to be rewritten for UNIX...
95   CoFileTimeNow((FILETIME *)(theFPXTime));
96 }
97 
InitFPXStr(FPXStr * theFPXArray)98 void InitFPXStr (FPXStr* theFPXArray)
99 {
100   theFPXArray->ptr = NULL; theFPXArray->length = 0;
101 }
102 
InitFPXShortArray(FPXShortArray * theFPXArray)103 void InitFPXShortArray (FPXShortArray* theFPXArray)
104 {
105   theFPXArray->ptr = NULL; theFPXArray->length = 0;
106 }
107 
InitFPXLongArray(FPXLongArray * theFPXArray)108 void InitFPXLongArray (FPXLongArray* theFPXArray)
109 {
110   theFPXArray->ptr = NULL; theFPXArray->length = 0;
111 }
112 
InitFPXRealArray(FPXRealArray * theFPXArray)113 void InitFPXRealArray (FPXRealArray* theFPXArray)
114 {
115   theFPXArray->ptr = NULL; theFPXArray->length = 0;
116 }
117 
InitFPXWideStr(FPXWideStr * theFPXArray)118 void InitFPXWideStr (FPXWideStr* theFPXArray)
119 {
120   theFPXArray->ptr = NULL; theFPXArray->length = 0;
121 }
122 
InitFPXWideStrArray(FPXWideStrArray * theFPXArray)123 void InitFPXWideStrArray (FPXWideStrArray* theFPXArray)
124 {
125   theFPXArray->ptr = NULL; theFPXArray->length = 0;
126 }
127 
InitFPXStrArray(FPXStrArray * theFPXArray)128 void InitFPXStrArray (FPXStrArray* theFPXArray)
129 {
130   theFPXArray->ptr = NULL; theFPXArray->length = 0;
131 }
132 
FPX_Strcpy(FPXStr * theFPXStr,const char * string)133 FPXStatus FPX_Strcpy (FPXStr* theFPXStr, const char* string)
134 {
135   size_t i = strlen(string);
136   if (FPX_AllocFPXStr(theFPXStr,i+1)!=FPX_OK) {
137     theFPXStr = NULL;
138     return FPX_MEMORY_ALLOCATION_FAILED;
139   }
140   unsigned char *pt = theFPXStr->ptr;
141   while (i--)
142     *pt++ = *string++;
143   *pt = 0;
144   return FPX_OK;
145 }
146 
FPX_WideStrcpy(FPXWideStr * theFPXStr,const char * string)147 FPXStatus FPX_WideStrcpy (FPXWideStr* theFPXStr, const char* string)
148 {
149   size_t i = strlen(string);
150   if (FPX_AllocFPXWideStr(theFPXStr,i+1)!=FPX_OK) {
151     theFPXStr = NULL;
152     return FPX_MEMORY_ALLOCATION_FAILED;
153   }
154   unsigned short *pt = theFPXStr->ptr;
155   while (i--)
156     *pt++ = *string++;
157   *pt = 0;
158   return FPX_OK;
159 }
160 
161 // FPX_WideStrcmp returns:
162 //  -1 if the first non-match in fpxStr1 is < fpxWStr2 or if fpxWStr1 is shorter
163 //   0 if strings match
164 //  +1 if the first non-match in fpxStr1 is > fpxWStr2 or if fpxWStr1 is longer
FPX_WideStrcmp(const FPXWideStr * fpxWStr1,const FPXWideStr * fpxWStr2)165 int FPX_WideStrcmp (const FPXWideStr* fpxWStr1, const FPXWideStr* fpxWStr2)
166 {
167   size_t      cnt1, cnt2, limit;
168   unsigned short  *ptr1, *ptr2;
169 
170   cnt1 = fpxWStr1->length;
171   cnt2 = fpxWStr2->length;
172 
173   ptr1 = fpxWStr1->ptr;
174   ptr2 = fpxWStr2->ptr;
175 
176   if( cnt1 <= cnt2)
177     limit = cnt1;
178   else
179     limit = cnt2;
180 
181   while (limit-- > 0) {
182     if      (*ptr1 < *ptr2)   return -1;
183     else if (*ptr1 > *ptr2)   return  1;
184     ptr1++;
185     ptr2++;
186   }
187 
188   // If we got here, the first N characters are a match.
189   if      (cnt1 < cnt2) return( -1);
190   else if (cnt1 > cnt2) return(  1);
191   else          return(  0);
192 }
193 
FPX_LPWSTRlen(const WCHAR * wideStr)194 size_t FPX_LPWSTRlen (const WCHAR *wideStr)
195 {
196   size_t cnt;
197   for (cnt = 0; *wideStr++; cnt++)
198     ;
199   return cnt;
200 }
201 
FPX_DeleteFPXStr(FPXStr * theFPXArray)202 FPXStatus FPX_DeleteFPXStr (FPXStr* theFPXArray)
203 {
204   if (theFPXArray->ptr!=NULL) {
205     delete [] theFPXArray->ptr;
206   }
207   InitFPXStr (theFPXArray);
208   return FPX_OK;
209 }
210 
FPX_DeleteFPXShortArray(FPXShortArray * theFPXArray)211 FPXStatus FPX_DeleteFPXShortArray (FPXShortArray* theFPXArray)
212 {
213   if (theFPXArray->ptr!=NULL) {
214     delete [] theFPXArray->ptr;
215   }
216   InitFPXShortArray (theFPXArray);
217   return FPX_OK;
218 }
219 
FPX_DeleteFPXLongArray(FPXLongArray * theFPXArray)220 FPXStatus FPX_DeleteFPXLongArray (FPXLongArray* theFPXArray)
221 {
222   if (theFPXArray->ptr!=NULL) {
223     delete [] theFPXArray->ptr;
224   }
225   InitFPXLongArray (theFPXArray);
226   return FPX_OK;
227 }
228 
FPX_DeleteFPXRealArray(FPXRealArray * theFPXArray)229 FPXStatus FPX_DeleteFPXRealArray (FPXRealArray* theFPXArray)
230 {
231   if (theFPXArray->ptr!=NULL) {
232     delete [] theFPXArray->ptr;
233   }
234   InitFPXRealArray (theFPXArray);
235   return FPX_OK;
236 }
237 
FPX_DeleteFPXWideStr(FPXWideStr * theFPXArray)238 FPXStatus FPX_DeleteFPXWideStr (FPXWideStr* theFPXArray)
239 {
240   if (theFPXArray->ptr!=NULL) {
241     delete [] theFPXArray->ptr;
242   }
243   InitFPXWideStr (theFPXArray);
244   return FPX_OK;
245 }
246 
FPX_DeleteFPXWideStrArray(FPXWideStrArray * theFPXArray)247 FPXStatus FPX_DeleteFPXWideStrArray (FPXWideStrArray* theFPXArray)
248 {
249   if (theFPXArray->ptr!=NULL) {
250     delete [] theFPXArray->ptr;
251   }
252   InitFPXWideStrArray (theFPXArray);
253   return FPX_OK;
254 }
255 
FPX_DeleteFPXStrArray(FPXStrArray * theFPXArray)256 FPXStatus FPX_DeleteFPXStrArray (FPXStrArray* theFPXArray)
257 {
258   if (theFPXArray->ptr!=NULL) {
259     delete [] theFPXArray->ptr;
260   }
261   InitFPXStrArray (theFPXArray);
262   return FPX_OK;
263 }
264 
FPX_AllocFPXStr(FPXStr * theFPXArray,unsigned int nbElem)265 FPXStatus FPX_AllocFPXStr (FPXStr* theFPXArray, unsigned int nbElem)
266 {
267 
268   if (theFPXArray == NULL) {
269     return FPX_OBJECT_CREATION_FAILED;
270   }
271   theFPXArray->ptr    = new unsigned char [nbElem];
272   if (theFPXArray->ptr==NULL) {
273     theFPXArray->length = 0;
274     return FPX_OBJECT_CREATION_FAILED;
275   }
276   theFPXArray->length = nbElem;
277   return FPX_OK;
278 }
279 
FPX_AllocFPXShortArray(FPXShortArray * theFPXArray,unsigned int nbElem)280 FPXStatus FPX_AllocFPXShortArray (FPXShortArray* theFPXArray, unsigned int nbElem)
281 {
282 
283   if (theFPXArray == NULL) {
284     return FPX_OBJECT_CREATION_FAILED;
285   }
286   theFPXArray->ptr    = new uint16_t [nbElem];
287   if (theFPXArray->ptr==NULL) {
288     theFPXArray->length = 0;
289     return FPX_OBJECT_CREATION_FAILED;
290   }
291   theFPXArray->length = nbElem;
292   return FPX_OK;
293 }
294 
FPX_AllocFPXLongArray(FPXLongArray * theFPXArray,unsigned int nbElem)295 FPXStatus FPX_AllocFPXLongArray (FPXLongArray* theFPXArray, unsigned int nbElem)
296 {
297 
298   if (theFPXArray == NULL) {
299     return FPX_OBJECT_CREATION_FAILED;
300   }
301 
302   theFPXArray->ptr    = new uint32_t [nbElem];
303   if (theFPXArray->ptr==NULL) {
304     theFPXArray->length = 0;
305     return FPX_OBJECT_CREATION_FAILED;
306   }
307   theFPXArray->length = nbElem;
308   return FPX_OK;
309 }
310 
FPX_AllocFPXRealArray(FPXRealArray * theFPXArray,unsigned int nbElem)311 FPXStatus FPX_AllocFPXRealArray (FPXRealArray* theFPXArray, unsigned int nbElem)
312 {
313 
314   if (theFPXArray == NULL) {
315     return FPX_OBJECT_CREATION_FAILED;
316   }
317   theFPXArray->ptr    = new float [nbElem];
318   if (theFPXArray->ptr==NULL) {
319     theFPXArray->length = 0;
320     return FPX_OBJECT_CREATION_FAILED;
321   }
322   theFPXArray->length = nbElem;
323   return FPX_OK;
324 }
325 
FPX_AllocFPXWideStr(FPXWideStr * theFPXArray,unsigned int nbElem)326 FPXStatus FPX_AllocFPXWideStr (FPXWideStr* theFPXArray, unsigned int nbElem)
327 {
328 
329   if (theFPXArray == NULL) {
330     return FPX_OBJECT_CREATION_FAILED;
331   }
332   theFPXArray->ptr    = new WCHAR [nbElem];
333   if (theFPXArray->ptr==NULL) {
334     theFPXArray->length = 0;
335     return FPX_OBJECT_CREATION_FAILED;
336   }
337   theFPXArray->length = sizeof(WCHAR) * nbElem;
338   return FPX_OK;
339 }
340 
FPX_AllocFPXWideStrArray(FPXWideStrArray * theFPXArray,unsigned int nbElem)341 FPXStatus FPX_AllocFPXWideStrArray (FPXWideStrArray* theFPXArray, unsigned int nbElem)
342 {
343 
344   if (theFPXArray == NULL) {
345     return FPX_OBJECT_CREATION_FAILED;
346   }
347   theFPXArray->ptr    = new FPXWideStr [nbElem];
348   if (theFPXArray->ptr==NULL) {
349     theFPXArray->length = 0;
350     return FPX_OBJECT_CREATION_FAILED;
351   }
352   theFPXArray->length = nbElem;
353   return FPX_OK;
354 }
355 
FPX_AllocFPXStrArray(FPXStrArray * theFPXArray,unsigned int nbElem)356 FPXStatus FPX_AllocFPXStrArray (FPXStrArray* theFPXArray, unsigned int nbElem)
357 {
358   if (theFPXArray == NULL) {
359     return FPX_OBJECT_CREATION_FAILED;
360   }
361   theFPXArray->ptr    = new FPXStr [nbElem];
362   if (theFPXArray->ptr==NULL) {
363     theFPXArray->length = 0;
364     return FPX_OBJECT_CREATION_FAILED;
365   }
366   theFPXArray->length = nbElem;
367   return FPX_OK;
368 }
369 
370 
371 //  ----------------------------------------------------------------------------
372 //  External Functions
373 //  This is the interface of the Baseline FlashPix IO Toolkit
374 //  ----------------------------------------------------------------------------
375 
376 // System management tools : setting options and obtaining global information
377 
FPX_GetErrorString(FPXStatus errorCode,char * errorString,unsigned short maxStrLen)378 FPXStatus FPX_GetErrorString (FPXStatus errorCode,
379                               char *errorString,
380                               unsigned short maxStrLen) {
381 
382 // errStrTable holds an array of strings.  The first element corresponds to FPX_OK (0),
383 // and so on so the integer enum values can be used to index this array
384 
385 
386 // Note:  This array implementation is only temporary.  If a resource file is
387 // used, the function AfxGetInstanceHandle() must be called, and this causes a
388 // compile error because it uses the non-LivePicture memory management functions (eg malloc)
389 // The solution is to recompile the Afx code using LivePicture memory management.  (but how?)
390 
391 const char *errorStrTable[] = {
392 "FPX_OK",
393 "FPX_INVALID_FORMAT_ERROR",
394 "FPX_FILE_WRITE_ERROR",
395 "FPX_FILE_READ_ERROR",
396 "FPX_FILE_NOT_FOUND",
397 "FPX_COLOR_CONVERSION_ERROR",
398 "FPX_SEVER_INIT_ERROR",
399 "FPX_LOW_MEMORY_ERROR",
400 "FPX_IMAGE_TOO_BIG_ERROR",
401 "FPX_INVALID_COMPRESSION_ERROR",
402 "FPX_INVALID_RESOLUTION",
403 "FPX_INVALID_FPX_HANDLE",
404 "FPX_TOO_MANY_LINES",
405 "FPX_BAD_COORDINATES",
406 "FPX_FILE_SYSTEM_FULL",
407 "FPX_MISSING_TABLE",
408 "FPX_RETURN_PARAMETER_TOO_LARGE",
409 "FPX_NOT_A_VIEW",
410 "FPX_VIEW_IS_TRANFORMLESS",
411 "FPX_ERROR",
412 "FPX_UNIMPLEMENTED_FUNCTION",
413 "FPX_INVALID_IMAGE_DESC",
414 "FPX_INVALID_JPEG_TABLE",
415 "FPX_ILLEGAL_JPEG_ID",
416 "FPX_MEMORY_ALLOCATION_FAILED",
417 "FPX_NO_MEMORY_MANAGEMENT",
418 "FPX_OBJECT_CREATION_FAILED",
419 "FPX_FREE_NULL_PTR",
420 "FPX_INVALID_TILE",
421 "FPX_FILE_IN_USE",
422 "FPX_FILE_CREATE_ERROR",
423 "FPX_FILE_NOT_OPEN_ERROR",
424 "FPX_USER_ABORT",
425 "FPX_OLE_FILE_ERROR",
426 "FPX_INVALID_PIXEL_FORMAT"
427 };
428 
429   if ((size_t)errorCode >= sizeof(errorStrTable)/sizeof(errorStrTable[0])) {
430     return FPX_ERROR;
431   }
432   strncpy(errorString, errorStrTable[errorCode], maxStrLen);
433   errorString[maxStrLen - 1] = '\0';
434 
435   return FPX_OK;
436 
437 //-------------------------------------------------------------------------------------------------
438 // Resource based version.  Again, it won't compile because of the call to AfxGetInstanceHandle()
439 /*
440 WCHAR theError[256];
441 char *tmpStr;
442 
443   if (LoadString(AfxGetInstanceHandle(),  (UINT) errorCode+1, theError, (unsigned short)maxStrLen));
444 
445   WideCharToMultiByte(CP_ACP, 0, (WCHAR *)theError, -1, tmpStr, 256, NULL, NULL);
446   strcpy(errorString,tmpStr);
447   free(tmpStr);
448 */
449 //-----------------------------------------------------------------------------------------------------
450 
451 }
452 
FPX_Delete(void * FPXObj)453 FPXStatus FPX_Delete(void *FPXObj) {
454 
455   if (FPXObj==NULL) {
456     return FPX_FREE_NULL_PTR;
457   }
458   delete (unsigned char*)FPXObj;
459 
460   return FPX_OK;
461 }
462 
463 
FPX_InitSystem()464 FPXStatus FPX_InitSystem ()
465 
466 {
467   FPXStatus status = FPX_OK;        // PTCH_402 ensure OK status if no error found
468   HRESULT   res;
469 
470   // Create an instance of the Toolkit context handle
471   if (GtheSystemToolkitInitialized()) {
472     status = FPX_ClearSystem();
473     if (status != FPX_OK) {
474       return status;
475     }
476   }
477   GtheSystemToolkit = new PSystemToolkit;
478   if (GtheSystemToolkit==NULL) {
479     return FPX_OBJECT_CREATION_FAILED;
480   }
481 
482   res = OLEInit();
483   int retcode = FAILED(res);
484 
485   switch (retcode) {
486     case S_FALSE:
487         GtheSystemToolkit->manageOLE = FALSE;
488         break;
489     case S_OK:
490         GtheSystemToolkit->manageOLE = TRUE;
491         break;
492     default:
493         FPX_ClearSystem();
494         status = FPX_MEMORY_ALLOCATION_FAILED;
495         break;
496   }
497 
498   return status;
499 }
500 
501 // CAUTION : memoryLimit = 0 is a legal value. In this case, no memory management will be
502 // done by the toolkit. Everything should be done by the host using FPX_PurgeToolkitMemory().
FPX_SetToolkitMemoryLimit(size_t * memoryLimit)503 FPXStatus FPX_SetToolkitMemoryLimit (size_t * memoryLimit)
504 
505 {
506   FPXStatus status = FPX_OK;
507 
508   // if the GtheSystemToolkit exist yet delete it
509   if (GtheSystemToolkitInitialized())
510   {
511     GtheSystemToolkit->PurgeSystem();
512     delete GtheSystemToolkit;
513     GtheSystemToolkit = NULL;
514   }
515 
516   if (*memoryLimit > 0 ) {
517     if (*memoryLimit < TOOLKIT_MIN_MEMORY) {
518       // the requested memory is too small
519       *memoryLimit = TOOLKIT_MIN_MEMORY;
520       status = FPX_OK;  // We should may be send a warning to the user...
521     }
522   }
523 
524   GtheSystemToolkit = new PSystemToolkit;
525   if (GtheSystemToolkit==NULL) {
526     return FPX_OBJECT_CREATION_FAILED;
527   }
528 
529   if (status == FPX_OK)
530   {
531     GtheSystemToolkit->manageOLE = TRUE;
532   }
533 
534   return status;
535 }
536 
FPX_PurgeToolkitMemory(size_t memoryToBePurged)537 size_t FPX_PurgeToolkitMemory (size_t memoryToBePurged)
538 {
539   return GtheSystemToolkit->PurgeSystemWithAmount(memoryToBePurged);
540 }
541 
FPX_ClearSystem()542 FPXStatus FPX_ClearSystem ()
543 
544 {
545   if (GtheSystemToolkit != NULL)
546     GtheSystemToolkit->PurgeSystem();
547 
548   if (GtheSystemToolkit->manageOLE == TRUE)
549     OLEUninit();
550 
551   delete GtheSystemToolkit;
552   GtheSystemToolkit = NULL;
553 
554   return FPX_OK;
555 }
556 
FPX_SetProgressFunction(FPXProgressFunction theProgressive)557 FPXStatus FPX_SetProgressFunction ( FPXProgressFunction theProgressive)
558 
559 {
560   GtheSystemToolkit->SetProgFunc(theProgressive);
561 
562   return FPX_OK;
563 }
564 
FPX_GetToolkitMemoryLimit(unsigned long * memoryLimit)565 FPXStatus FPX_GetToolkitMemoryLimit ( unsigned long * memoryLimit)
566 
567 {
568   return FPX_NO_MEMORY_MANAGEMENT;
569 }
570 
FPX_GetToolkitMemoryAvailable(unsigned long * availableMemory)571 FPXStatus FPX_GetToolkitMemoryAvailable ( unsigned long * availableMemory)
572 
573 {
574   return FPX_NO_MEMORY_MANAGEMENT;
575 }
576 
FPX_GetToolkitMemoryUsed(unsigned long * usedMemory)577 FPXStatus FPX_GetToolkitMemoryUsed ( unsigned long * usedMemory)
578 
579 {
580   return FPX_NO_MEMORY_MANAGEMENT;
581 }
582 
FPX_LockFPXImage(FPXImageHandle * theFPX)583 FPXStatus FPX_LockFPXImage ( FPXImageHandle*  theFPX)
584 
585 {
586   GtheSystemToolkit->LockImage(theFPX->GetImage());
587 
588   return FPX_OK;
589 }
590 
FPX_SetUnit(FPXResolutionUnit newUnit)591 FPXStatus FPX_SetUnit ( FPXResolutionUnit  newUnit)
592 
593 {
594   GtheSystemToolkit->SetUnit((Typ_Unit)(newUnit));
595 
596   return FPX_OK;
597 }
598 
FPX_GetUnit(FPXResolutionUnit * newUnit)599 FPXStatus FPX_GetUnit ( FPXResolutionUnit * newUnit)
600 
601 {
602   GtheSystemToolkit->GetUnit((Typ_Unit*)(newUnit));
603 
604   return FPX_OK;
605 }
606 
FPX_GetToolkitVersion(char * versionName,long * versionNumber)607 FPXStatus FPX_GetToolkitVersion ( char* versionName, long* versionNumber)
608 
609 {
610   strcpy(versionName,TOOLKIT_NAME);
611   *versionNumber = GtheSystemToolkit->GetToolkitVersion();
612 
613   return FPX_OK;
614 }
615 
FPX_SetResampleMethod(FPXResampleMethod method)616 FPXStatus FPX_SetResampleMethod ( FPXResampleMethod method)
617 
618 {
619   GtheSystemToolkit->SetAntialias ((Typ_Antialias)(method));
620 
621   return FPX_OK;
622 }
623 
FPX_SetComposeMethod(FPXComposeMethod method)624 FPXStatus FPX_SetComposeMethod (FPXComposeMethod method)
625 
626 {
627   GtheSystemToolkit->PreserveBackground (method == FPX_PROTECT_BACKGROUND);
628 
629   return FPX_OK;
630 }
631 
FPX_SetViewBackgroundColor(FPXColorspace colorspace,FPXBackground color)632 FPXStatus FPX_SetViewBackgroundColor ( FPXColorspace colorspace, FPXBackground color)
633 
634 {
635   // Convert the color space into a Baseline space
636   FPXBaselineColorSpace baseSpace;
637   baseSpace = AnalyseFPXColorSpace (colorspace);
638 
639   // Convert the background color into a Baseline (32 bits per pixel, 8 bits per channel) value
640   unsigned long backColor = ((unsigned char)(color.color1_value) << 24) |
641                   ((unsigned char)(color.color2_value) << 16) |
642                   ((unsigned char)(color.color3_value) <<  8) |
643                    (unsigned char)(color.color4_value);
644   backColor = backColor >> (8 * (4 - colorspace.numberOfComponents));
645 
646   // Update the Global background color
647   // On Mac it is used the constructor Pixel (32int backColor)
648   // (since SetBackgoundColor has Pixel type as a first parameter)
649   // which map an integer on a Mac color; this does not work on Windows
650   // since there is a different memory architecture
651   // So, we do the conversion here---**IM--04/22/97
652 #ifdef _WINDOWS //**IM_18229
653   Pixel newBackColor;
654   newBackColor.alpha = (unsigned char)((backColor >> 24) & 0XFF);
655   newBackColor.rouge = (unsigned char)((backColor >> 16) & 0XFF);
656   newBackColor.vert  = (unsigned char)((backColor >> 8) & 0XFF);
657   newBackColor.bleu  = (unsigned char)(backColor & 0XFF);
658   GtheSystemToolkit->SetBackgroundColor (newBackColor,baseSpace);
659 
660 #else //Mac code
661   GtheSystemToolkit->SetBackgroundColor (backColor,baseSpace);
662 #endif
663   return FPX_OK;
664 }
665 
666 
667 //  Make a FPXJPEGTableGroup from a bunch of Q and H tables.
FPX_CreateJPEGTableGroup(FPXJPEGTableGroup * theGroup,short numOfQuanTable,unsigned char * quanTableChanID,FPXJPEGQuantTable * quanTable,short numOfHuffTable,unsigned char * huffDCTableChanID,unsigned char * huffACTableChanID,FPXJPEGHUFFTable * huffTable)668 FPXStatus FPX_CreateJPEGTableGroup (
669               FPXJPEGTableGroup*    theGroup,
670               short         numOfQuanTable,
671               unsigned char *   quanTableChanID,
672               FPXJPEGQuantTable*    quanTable,
673               short         numOfHuffTable,
674               unsigned char *   huffDCTableChanID,
675               unsigned char *   huffACTableChanID,
676               FPXJPEGHUFFTable*     huffTable )
677 {
678   FPXStatus     status = FPX_OK;
679   ENCODER     encoder;
680   long      headerSize, i;
681   unsigned char header[FPX_MAX_TABLE_STREAM_SIZE];
682   ptr_Compresseur jpegCompressor;
683 
684   JPEGHuffTable   huffmanTables[8];
685     JPEGQuantTable  quantTables[4];
686 
687   // Get the jpeg compressor
688   jpegCompressor = (*tousLesCodecs)[TLC_JPEG];
689   if ( !jpegCompressor )
690   {
691     status = FPX_OBJECT_CREATION_FAILED;
692     return status;
693   }
694 
695   // Check the validity of number of Q-tables
696     if (numOfQuanTable > 4 || numOfQuanTable < 1)
697     return FPX_INVALID_JPEG_TABLE;
698 
699   // Check the validity of number of huffman-tables
700     if (((numOfHuffTable % 2)!=0) || (numOfHuffTable > 8) || (numOfHuffTable < 2))
701     return FPX_INVALID_JPEG_TABLE;
702 
703   // Get the encoder
704   if ( !jpegCompressor->CompresseurPresent() ) {
705     status = FPX_INVALID_JPEG_TABLE;
706     return status;
707   }
708   else
709     encoder = ((PCompressorJPEG *)jpegCompressor)->GetEncoder();
710 
711   for ( i = 0; i< numOfQuanTable; i++ ) {
712     quantTables[i].quantizer = quanTable[i].quantizer;
713     quantTables[i].ident   = quanTable[i].ident;
714   }
715 
716   // Set the Q-tables
717   if ( eJPEG_SetQuantTables(encoder, numOfQuanTable, (JPEGQuantTable **)&quantTables, quanTableChanID) )
718   {
719     status = FPX_INVALID_JPEG_TABLE;
720     return status;
721   }
722 
723   for ( i = 0; i< numOfHuffTable; i++ ) {
724     huffmanTables[i].bits   = huffTable[i].bits;
725     huffmanTables[i].vals   = huffTable[i].vals;
726     huffmanTables[i].hclass = huffTable[i].hclass;
727     huffmanTables[i].ident  = huffTable[i].ident;
728   }
729 
730   // Set the huffman tables
731   if ( eJPEG_SetHuffTables(encoder, numOfHuffTable, (JPEGHuffTable **)&huffmanTables,
732           huffDCTableChanID, huffACTableChanID) )
733   {
734     status = FPX_INVALID_JPEG_TABLE;
735     return status;
736   }
737 
738   // Create the jpeg header
739   if ( eJPEG_CreateHeader(
740             encoder,
741             FPX_MAX_TABLE_STREAM_SIZE,  // the size of the default header in bytes
742             header,           // the buffer itself
743             &headerSize         // header length
744             ))
745   {
746     status = FPX_INVALID_JPEG_TABLE;
747     return status;
748   }
749 
750   theGroup->theStreamSize = (unsigned short) headerSize;
751   memcpy(theGroup->theStream, header, headerSize);
752 
753   return status;
754 }
755 
756 // Open and Close FlashPix files tools :
757 
FPX_CloseImage(FPXImageHandle * theFPX)758 FPXStatus FPX_CloseImage ( FPXImageHandle* theFPX)
759 
760 {
761   FPXStatus status = FPX_OK;
762   if (theFPX == NULL) {
763     status = FPX_INVALID_FPX_HANDLE;
764   } else {
765     status = FPX_FlushModifiedTiles(theFPX);
766     delete theFPX;
767   }
768   return status;
769 }
770 
771 // Basic access tools :
772 
FPX_WriteImageLine(FPXImageHandle * theFPX,FPXImageDesc * theLine)773 FPXStatus FPX_WriteImageLine ( FPXImageHandle* theFPX, FPXImageDesc* theLine)
774 
775 {
776   FPXStatus status = FPX_OK;
777 
778   if (!theFPX) {
779     status = FPX_INVALID_FPX_HANDLE;
780   } else {
781     int width, height;
782     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
783     image->GetTrueDimensions(&width,&height);
784 
785     FPXBufferDesc line(theLine,width,1);
786     if ( line.Get32BitsBuffer() == NULL )
787       return FPX_MEMORY_ALLOCATION_FAILED;
788 
789     if (line.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE)
790       status = FPX_INVALID_IMAGE_DESC;
791     else {
792       line.UpdateBuffer();
793       image->SetUsedColorSpace(line.GetBaselineColorSpace());
794       status = image->WriteLine (line.Get32BitsBuffer(), ActiveChannel_All);
795 
796       if(status == FPX_OK)
797         theFPX->SetImageEditedFlag();
798     }
799   }
800   return status;
801 }
802 
FPX_WriteImageRectangle(FPXImageHandle * theFPX,unsigned int X0,unsigned int Y0,unsigned int X1,unsigned int Y1,FPXImageDesc * theData)803 FPXStatus FPX_WriteImageRectangle (
804               FPXImageHandle*     theFPX,
805               unsigned int        X0,
806               unsigned int        Y0,
807               unsigned int        X1,
808               unsigned int        Y1,
809               FPXImageDesc*       theData)
810 
811 {
812   FPXStatus status = FPX_OK;
813 
814   if (!theFPX)
815     status = FPX_INVALID_FPX_HANDLE;
816   else
817   {
818     // check to see if users descriptor matched internal memory layout
819     // 4 channel RGBA
820     if(!IsASupportedDescriptor(*theData,X1-X0+1))
821     {
822       theFPX->setInternalBuffer(X1-X0+1, Y1-Y0+1);
823     }
824 
825     FPXBufferDesc rect(theData, X1-X0+1,Y1-Y0+1, theFPX->getInternalBuffer());
826 
827     if ( rect.Get32BitsBuffer() == NULL )
828       return FPX_MEMORY_ALLOCATION_FAILED;
829 
830     if (rect.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE)
831       status = FPX_INVALID_IMAGE_DESC;
832     else {
833       rect.UpdateBuffer();
834       PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
835       image->SetUsedColorSpace(rect.GetBaselineColorSpace());
836       status = image->WriteRectangle (X0, Y0, X1, Y1, rect.Get32BitsBuffer(),
837                 ActiveChannel_All);
838       if (status == FPX_OK)
839         theFPX->SetImageEditedFlag();
840     }
841   }
842   return status;
843 }
844 
845 
FPX_WriteBackgroundRectangle(FPXImageHandle * theFPX,unsigned int X0,unsigned int Y0,unsigned int X1,unsigned int Y1,FPXColorspace theColorspace,FPXBackground theColor)846 FPXStatus FPX_WriteBackgroundRectangle (
847               FPXImageHandle*     theFPX,
848               unsigned int        X0,
849               unsigned int        Y0,
850               unsigned int        X1,
851               unsigned int        Y1,
852               FPXColorspace       theColorspace,
853               FPXBackground       theColor)
854 {
855   FPXStatus status = FPX_OK;
856   if (!theFPX)
857     status = FPX_INVALID_FPX_HANDLE;
858   else {
859     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
860 
861     // Convert the color space into a Baseline space
862     FPXBaselineColorSpace baseSpace;
863     baseSpace = AnalyseFPXColorSpace (theColorspace);
864 
865     // Convert the background color into a Baseline (32 bits per pixel, 8 bits per channel) value
866     // CHG_WIN_COLOR - use different byte ordering for Windows than on Mac
867 #ifdef _WINDOWS
868       unsigned long backColor = ((unsigned char)(theColor.color1_value) <<  0) |
869                       ((unsigned char)(theColor.color2_value) <<  8) |
870                       ((unsigned char)(theColor.color3_value) << 16) |
871                       ((unsigned char)(theColor.color4_value) << 24);
872     backColor = backColor << (8 * (4 - theColorspace.numberOfComponents));
873 #else
874       unsigned long backColor = ((unsigned char)(theColor.color1_value) << 24) |
875                       ((unsigned char)(theColor.color2_value) << 16) |
876                       ((unsigned char)(theColor.color3_value) <<  8) |
877                        (unsigned char)(theColor.color4_value);
878     backColor = backColor >> (8 * (4 - theColorspace.numberOfComponents));
879 #endif
880     // Set the description buffer and the used color for the file
881     FPXBufferDesc rect(backColor,X1-X0+1,Y1-Y0+1,baseSpace);
882     if ( rect.Get32BitsBuffer() == NULL )
883       return FPX_MEMORY_ALLOCATION_FAILED;
884 
885     if (rect.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE)
886       status = FPX_INVALID_IMAGE_DESC;
887     else {
888       // Write the rectangle
889       image->SetUsedColorSpace(baseSpace);
890       status = image->WriteRectangle (X0, Y0, X1, Y1, rect.Get32BitsBuffer(), ActiveChannel_All);
891 
892       if(status == FPX_OK)
893         theFPX->SetImageEditedFlag();
894     }
895   }
896   return status;
897 }
898 
FPX_WriteImageResolution(FPXImageHandle * theFPX,unsigned int theResolution,FPXImageDesc * theData)899 FPXStatus FPX_WriteImageResolution (
900               FPXImageHandle*     theFPX,
901               unsigned int        theResolution,
902               FPXImageDesc*       theData)
903 {
904   FPXStatus status = FPX_OK;
905 
906   if (!theFPX)
907     status = FPX_INVALID_FPX_HANDLE;
908   else
909   {
910     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
911 
912     // In the FlashPix API, the resolution ordering is reverse of the natural order...
913     theResolution = image->GetNbResolutions() - 1 - theResolution;
914     int width, height;
915     image->GetResolutionSize((short) theResolution,&width,&height);
916     FPXBufferDesc rect(theData,width,height);
917     if ( rect.Get32BitsBuffer() == NULL )
918       return FPX_MEMORY_ALLOCATION_FAILED;
919 
920     if (rect.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE)
921       status = FPX_INVALID_IMAGE_DESC;
922     else {
923       rect.UpdateBuffer();
924       image->SetUsedColorSpace(rect.GetBaselineColorSpace());
925       status = image->WriteRectangle (0, 0, width-1, height-1, rect.Get32BitsBuffer(), ActiveChannel_All, (short) theResolution);
926 
927       if(status == FPX_OK)
928         theFPX->SetImageEditedFlag();
929     }
930   }
931   return status;
932 }
933 
FPX_FlushModifiedTiles(FPXImageHandle * theFPX)934 FPXStatus FPX_FlushModifiedTiles (
935               FPXImageHandle*     theFPX)
936 {
937   FPXStatus status = FPX_INVALID_FPX_HANDLE;
938 
939   if (theFPX) {
940     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
941 
942     if (image)
943       status = image->FlushModifiedTiles();
944     else
945       status = FPX_INVALID_IMAGE_DESC;
946   }
947 
948   return status;
949 }
950 
FPX_ReadImageTransformRectangle(FPXImageHandle * theFPX,float X0,float Y0,float X1,float Y1,int rectWidth,int rectHeight,FPXImageDesc * theRectangle)951 FPXStatus FPX_ReadImageTransformRectangle (
952               FPXImageHandle*     theFPX,
953               float               X0,
954               float               Y0,
955               float               X1,
956               float               Y1,
957               int                 rectWidth,
958               int                 rectHeight,
959               FPXImageDesc*       theRectangle)
960 
961 {
962   FPXStatus status = FPX_OK;
963 
964   if (!theFPX)
965     status = FPX_INVALID_FPX_HANDLE;
966   else
967   {
968     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
969 
970     FPXBufferDesc rect(theRectangle, rectWidth, rectHeight);
971     if ( rect.Get32BitsBuffer() == NULL )
972       return FPX_MEMORY_ALLOCATION_FAILED;
973 
974     if (rect.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE)
975       status = FPX_INVALID_IMAGE_DESC;
976     else {
977       // Set the color space required by theRectangle
978       image->SetUsedColorSpace(rect.GetBaselineColorSpace());
979 
980       // We will apply the viewing parameters
981       image->SetApplyParameter(TRUE);
982 
983       // Create an intermediate page as a rendering context
984       float resolution = (float)(rectWidth) / (X1 - X0);
985       TransfoPerspective identity;
986       PageImage page (theFPX, rectWidth, rectHeight, resolution, X0, Y0, identity);
987 
988       // Render the page
989       status = page.ReadRectangle (0, 0, rectWidth, rectHeight, rect.Get32BitsBuffer(), rectWidth, FALSE);
990 
991       if(status == FPX_OK)
992         rect.UpdateDescriptor();
993     }
994   }
995   return status;
996 }
997 
FPX_ReadImageRectangle(FPXImageHandle * theFPX,unsigned int X0,unsigned int Y0,unsigned int X1,unsigned int Y1,unsigned int theResolution,FPXImageDesc * theImage)998 FPXStatus FPX_ReadImageRectangle (
999               FPXImageHandle*     theFPX,
1000               unsigned int        X0,
1001               unsigned int        Y0,
1002               unsigned int        X1,
1003               unsigned int        Y1,
1004               unsigned int        theResolution,
1005               FPXImageDesc*       theImage)
1006 
1007 {
1008   FPXStatus status = FPX_OK;
1009 
1010   if (!theFPX)
1011     status = FPX_INVALID_FPX_HANDLE;
1012   else
1013   {
1014     PFileFlashPixIO* image = (PFileFlashPixIO*)(theFPX->GetImage());
1015 
1016     // In the FlashPix API, the resolution ordering is reverse of the natural order...
1017     theResolution = image->GetNbResolutions() - 1 - theResolution;
1018     FPXBufferDesc rect(theImage, X1-X0+1, Y1-Y0+1);
1019     if ( rect.Get32BitsBuffer() == NULL )
1020       return FPX_MEMORY_ALLOCATION_FAILED;
1021 
1022     if ( rect.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE )
1023       status = FPX_INVALID_IMAGE_DESC;
1024     else {
1025       // Set the color space required by theRectangle
1026       image->SetUsedColorSpace(rect.GetBaselineColorSpace());
1027 
1028       // We will NOT apply the viewing parameters
1029       image->SetApplyParameter(FALSE);
1030 
1031       status = image->ReadRectangle (X0, Y0, X1, Y1, rect.Get32BitsBuffer(), theResolution);
1032 
1033       if(status == FPX_OK)
1034         rect.UpdateDescriptor();
1035     }
1036   }
1037   return status;
1038 }
1039 
FPX_ReadImageTile(FPXImageHandle * theFPX,unsigned int whichTile,unsigned int theResolution,FPXImageDesc * theTile)1040 FPXStatus FPX_ReadImageTile (
1041               FPXImageHandle*     theFPX,
1042               unsigned int        whichTile,
1043               unsigned int        theResolution,
1044               FPXImageDesc*       theTile)
1045 {
1046   FPXStatus status = FPX_OK;
1047 
1048   if (!theFPX)
1049     status = FPX_INVALID_FPX_HANDLE;
1050   else
1051   {
1052     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1053 
1054     // In the FlashPix API, the resolution ordering is reverse of the natural order...
1055     theResolution = image->GetNbResolutions() - 1 - theResolution;
1056     long tileWidth = image->GetTileWidth();
1057     FPXBufferDesc rect(theTile, tileWidth, tileWidth);
1058     if ( rect.Get32BitsBuffer() == NULL )
1059       return FPX_OBJECT_CREATION_FAILED;
1060 
1061     if (rect.GetBaselineColorSpace() == NON_AUTHORIZED_SPACE) {
1062       status = FPX_INVALID_IMAGE_DESC;
1063     } else {
1064       int nbTilesW, nbTilesH;
1065       image->GetResolutionTileSize ((short)theResolution, &nbTilesW, &nbTilesH);
1066       int X0 = (whichTile % nbTilesW) * tileWidth;
1067       int Y0 = (whichTile / nbTilesW) * tileWidth;
1068 
1069       // Set the color space required by theRectangle
1070       image->SetUsedColorSpace(rect.GetBaselineColorSpace());
1071 
1072       // We will NOT apply the viewing parameters
1073       image->SetApplyParameter(FALSE);
1074 
1075       status = image->ReadRectangle (X0, Y0, X0+tileWidth-1, Y0+tileWidth-1, rect.Get32BitsBuffer(), theResolution);
1076 
1077       if(status == FPX_OK)
1078         rect.UpdateDescriptor();
1079     }
1080   }
1081   return status;
1082 }
1083 
FPX_ReadImageCompressedTile(FPXImageHandle * theFPX,unsigned int whichTile,unsigned int theResolution,FPXTileDesc * theTile)1084 FPXStatus FPX_ReadImageCompressedTile (
1085               FPXImageHandle*     theFPX,
1086               unsigned int        whichTile,
1087               unsigned int        theResolution,
1088               FPXTileDesc*        theTile)
1089 {
1090   FPXStatus status = FPX_OK;
1091 
1092   if (!theFPX)
1093     status = FPX_INVALID_FPX_HANDLE;
1094   else {
1095 
1096     // Get the pointer to the I/O object
1097     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1098 
1099     // In the FlashPix API, the resolution ordering is reverse of the natural order...
1100     theResolution = image->GetNbResolutions() - 1 - theResolution;
1101 
1102 
1103     // Call the read raw function
1104     status = image->ReadRawTile (theResolution, whichTile,
1105                   &(theTile->compInfo.compressOption),
1106                   &(theTile->compInfo.compressQuality),
1107                   &(theTile->compInfo.compressSubtype),
1108                   &(theTile->dataLength),
1109                   &(theTile->data));
1110   }
1111   return status;
1112 }
1113 
FPX_WriteImageCompressedTile(FPXImageHandle * theFPX,unsigned int whichTile,unsigned int theResolution,FPXTileDesc * theTile)1114 FPXStatus FPX_WriteImageCompressedTile (
1115               FPXImageHandle*     theFPX,
1116               unsigned int        whichTile,
1117               unsigned int        theResolution,
1118               FPXTileDesc*        theTile)
1119 
1120 {
1121   FPXStatus status = FPX_OK;
1122 
1123   if (!theFPX)
1124     status = FPX_INVALID_FPX_HANDLE;
1125   else {
1126 
1127     // Get the pointer to the I/O object
1128     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1129 
1130     // In the FlashPix API, the resolution ordering is reverse of the natural order...
1131     theResolution = image->GetNbResolutions() - 1 - theResolution;
1132 
1133 
1134     // Call the write raw function
1135     status = image->WriteRawTile(theResolution, whichTile,
1136                   theTile->compInfo.compressOption,
1137                   theTile->compInfo.compressQuality,
1138                   theTile->compInfo.compressSubtype,
1139                   theTile->dataLength,
1140                   theTile->data);
1141 
1142     if(status == FPX_OK)     // If no error when writing, set the "edited" flag
1143       theFPX->SetImageEditedFlag();
1144   }
1145   return status;
1146 }
1147 
1148 
FPX_SetDecimationQuality(FPXImageHandle * theFPX,unsigned short decimationQuality)1149 FPXStatus FPX_SetDecimationQuality ( FPXImageHandle*  theFPX, unsigned short decimationQuality)
1150 {
1151   Typ_Convolution newConvolution = Convolution_Standard;
1152   if (decimationQuality >= 4)
1153     newConvolution = Convolution_Gauss;
1154   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1155   image->SetConvolution (newConvolution);
1156   return FPX_OK;
1157 }
1158 
FPX_SetResolutionInfo(FPXImageHandle * theFPX,FPXResolution * theResolutionInfo)1159 FPXStatus FPX_SetResolutionInfo (
1160               FPXImageHandle*  theFPX,
1161               FPXResolution*   theResolutionInfo)
1162 {
1163   FPXStatus status = FPX_OK;
1164 
1165   if (!theFPX)  {
1166     status = FPX_INVALID_FPX_HANDLE;
1167     return status;
1168   }
1169 
1170   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1171   image->SetResolutionInfo(theResolutionInfo);
1172 
1173   return status;
1174 }
1175 
FPX_GetResolutionInfo(FPXImageHandle * theFPX,FPXResolution * theResolutionInfo)1176 FPXStatus FPX_GetResolutionInfo (
1177               FPXImageHandle*  theFPX,
1178               FPXResolution*   theResolutionInfo)
1179 {
1180   FPXStatus status = FPX_OK;
1181 
1182   if (!theFPX)  {
1183     status = FPX_INVALID_FPX_HANDLE;
1184     return status;
1185   }
1186 
1187   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1188   image->GetResolutionInfo(theResolutionInfo);
1189 
1190   return status;
1191 }
1192 
1193 // Not implemented in Baseline
FPX_SetAlphaType(FPXImageHandle * theFPX,FPXPreComputedAlpha theAlphaType)1194 FPXStatus FPX_SetAlphaType (
1195               FPXImageHandle*      theFPX,
1196               FPXPreComputedAlpha  theAlphaType)
1197 {
1198   //  FPXImageHandle* handle = theFPX;
1199   //  FPXPreComputedAlpha  a = theAlphaType;
1200   return FPX_UNIMPLEMENTED_FUNCTION;
1201 }
1202 
1203 // Not implemented in Baseline
FPX_GetAlphaType(FPXImageHandle * theFPX,FPXPreComputedAlpha * theAlphaType)1204 FPXStatus FPX_GetAlphaType (
1205               FPXImageHandle*      theFPX,
1206               FPXPreComputedAlpha* theAlphaType)
1207 {
1208   // FPXImageHandle* handle = theFPX;
1209   // FPXPreComputedAlpha*  a = theAlphaType;
1210   return FPX_UNIMPLEMENTED_FUNCTION;
1211 }
1212 
FPX_SetJPEGTableGroup(FPXImageHandle * theFPX,FPXJPEGTableGroup * theGroup,unsigned char theTableGroupID)1213 FPXStatus FPX_SetJPEGTableGroup (
1214               FPXImageHandle*     theFPX,
1215               FPXJPEGTableGroup*  theGroup,
1216               unsigned char       theTableGroupID)
1217 {
1218   FPXStatus status = FPX_OK;
1219 
1220   if (!theFPX)  {
1221     status = FPX_INVALID_FPX_HANDLE;
1222     return status;
1223   }
1224 
1225   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1226   PFlashPixFile* filePtr = (PFlashPixFile*)(image->GetCurrentFile());
1227 
1228   if (filePtr) {
1229     OLEProperty*  aProp;
1230     OLEBlob     jpegTable;
1231 
1232     // Convert the index into property ID for jpeg table
1233     unsigned long   PID_jpegTableIndex = PID_JPEGTables(theTableGroupID);
1234 
1235     // Copy the stream in jpeg table into blob
1236     jpegTable.WriteVT_VECTOR(theGroup->theStream, (unsigned long)theGroup->theStreamSize);
1237 
1238     // Save the jpeg table into image content property set
1239     if (filePtr->SetImageContentProperty (PID_jpegTableIndex, TYP_JPEGTables, &aProp)) {
1240       *aProp = jpegTable.GetBlob();
1241 
1242       // Save the maximum jpeg table index
1243       if ( !filePtr->GetImageContentProperty (PID_MaxJPEGTables, &aProp) )
1244         if (filePtr->SetImageContentProperty (PID_MaxJPEGTables, TYP_MaxJPEGTables, &aProp))
1245           *aProp = (int32_t)theTableGroupID;
1246         else
1247           return  FPX_INVALID_JPEG_TABLE;
1248       else {
1249         int32_t tempMaxIndex = (int32_t)(*aProp);
1250         tempMaxIndex = (tempMaxIndex < theTableGroupID) ? theTableGroupID : tempMaxIndex;
1251         *aProp = (int32_t)tempMaxIndex;
1252       }
1253       filePtr->Commit();
1254 
1255       // Set the compression table index
1256       image->SetCompressTableGroup(theTableGroupID);
1257     }
1258     else
1259       status = FPX_INVALID_JPEG_TABLE;
1260   }
1261 
1262   return status;
1263 }
1264 
FPX_GetJPEGTableGroup(FPXImageHandle * theFPX,FPXJPEGTableGroup * theGroup,unsigned char theTableGroupID)1265 FPXStatus FPX_GetJPEGTableGroup (
1266               FPXImageHandle*     theFPX,
1267               FPXJPEGTableGroup*  theGroup,
1268               unsigned char       theTableGroupID)
1269 {
1270   FPXStatus status = FPX_OK;
1271 
1272   if (!theFPX)  {
1273     status = FPX_INVALID_FPX_HANDLE;
1274     return status;
1275   }
1276 
1277   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1278   PFlashPixFile* filePtr = (PFlashPixFile*)(image->GetCurrentFile());
1279 
1280   if (filePtr) {
1281     OLEProperty*  aProp;
1282     OLEBlob     jpegTable;
1283 
1284     unsigned long   PID_jpegTableIndex = PID_JPEGTables(theTableGroupID);
1285 
1286     // Get the jpeg table from image content property set
1287     if (filePtr->GetImageContentProperty (PID_jpegTableIndex, &aProp)) {
1288       jpegTable = (BLOB*)(*aProp);
1289     }
1290     else {
1291       status = FPX_INVALID_JPEG_TABLE;
1292       return status;
1293     }
1294 
1295     // Read the stream in jpeg table from blob
1296     unsigned char *str;
1297     size_t strlen;
1298 
1299     strlen = jpegTable.ReadVT_VECTOR(&str);
1300 
1301     // Make sure the stream length can not exceed maximum stream table length
1302     if ( strlen > FPX_MAX_TABLE_STREAM_SIZE )
1303       status = FPX_INVALID_JPEG_TABLE;
1304     else {
1305       theGroup->theStreamSize = (unsigned short) strlen;
1306       memcpy(theGroup->theStream, str, strlen);
1307       delete str;
1308     }
1309 
1310   } else
1311     status = FPX_INVALID_FPX_HANDLE;
1312 
1313   return status;
1314 }
1315 
FPX_SelectJPEGTableGroup(FPXImageHandle * theFPX,unsigned char theTableGroupID)1316 FPXStatus FPX_SelectJPEGTableGroup (
1317               FPXImageHandle*  theFPX,
1318               unsigned char    theTableGroupID)
1319 {
1320   FPXStatus status = FPX_OK;
1321 
1322   if (!theFPX)  {
1323     status = FPX_INVALID_FPX_HANDLE;
1324     return status;
1325   }
1326 
1327   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1328   PFlashPixFile* filePtr = (PFlashPixFile*)(image->GetCurrentFile());
1329 
1330   if (filePtr) {
1331     OLEProperty*  aProp;
1332 
1333     // Convert the index into property ID for jpeg table
1334     unsigned long   PID_jpegTableIndex = PID_JPEGTables(theTableGroupID);
1335 
1336     // Find the jpeg table specified by theTableGroupID in the image content property set
1337     if (filePtr->GetImageContentProperty (PID_jpegTableIndex, &aProp)) {
1338 
1339       // Set the compression table index
1340       image->SetCompressTableGroup(theTableGroupID);
1341     }
1342     else
1343       // No such table in the image content property set
1344       status = FPX_INVALID_JPEG_TABLE;
1345 
1346   }
1347 
1348   return FPX_UNIMPLEMENTED_FUNCTION;
1349   //return status;
1350 }
1351 
FPX_SetJPEGCompression(FPXImageHandle * theFPX,unsigned short theQualityFactor)1352 FPXStatus FPX_SetJPEGCompression (
1353               FPXImageHandle*  theFPX,
1354               unsigned short   theQualityFactor)
1355 {
1356   FPXStatus status = FPX_OK;
1357 
1358   if (!theFPX)  {
1359     status = FPX_INVALID_FPX_HANDLE;
1360     return status;
1361   }
1362 
1363   // Convert the Kodak's quality factor to JPEG's
1364   unsigned char qualityFactor;
1365   qualityFactor = (unsigned char) (2.55 * (100 - theQualityFactor));
1366 
1367   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
1368   image->SetQualityFactor(qualityFactor);       // Set quality factor
1369 
1370   return status;
1371 }
1372 
1373 // Create a fpx file
CreateImageByFilename(FicNom & fileName,unsigned int width,unsigned int height,unsigned int,unsigned int,FPXColorspace colorspace,FPXBackground backgroundColor,FPXCompressionOption compressOption,FPXImageHandle ** theFPX)1374 FPXStatus CreateImageByFilename (
1375               FicNom&               fileName,
1376               unsigned int          width,
1377               unsigned int          height,
1378               unsigned int          /*tileWidth*/,      // not implemented in Baseline (always 64)
1379               unsigned int          /*tileHeight*/,     // not implemented in Baseline (always 64)
1380               FPXColorspace         colorspace,
1381               FPXBackground         backgroundColor,
1382               FPXCompressionOption  compressOption,
1383               FPXImageHandle**      theFPX)
1384 {
1385   FPXStatus status = FPX_OK;
1386 
1387   // CHG_FILE_ERR2 - clear the errors list, so we only get new error reports
1388   GtheSystemToolkit->DeleteErrorsList();
1389 
1390   // Convert the color space into a Baseline space
1391   FPXBaselineColorSpace baseSpace;
1392   baseSpace = AnalyseFPXColorSpace (colorspace);
1393 
1394   // Convert the background color into a Baseline (32 bits per pixel, 8 bits per channel) value
1395   // CHG_WIN_COLOR - use different byte ordering for Windows than on Mac
1396 #ifdef _WINDOWS
1397   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) <<  0) |
1398                   ((unsigned char)(backgroundColor.color2_value) <<  8) |
1399                   ((unsigned char)(backgroundColor.color3_value) << 16) |
1400                   ((unsigned char)(backgroundColor.color4_value) << 24);
1401   backColor = backColor << (8 * (4 - colorspace.numberOfComponents));
1402 #else
1403   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) << 24) |
1404                   ((unsigned char)(backgroundColor.color2_value) << 16) |
1405                   ((unsigned char)(backgroundColor.color3_value) <<  8) |
1406                    (unsigned char)(backgroundColor.color4_value);
1407   backColor = backColor >> (8 * (4 - colorspace.numberOfComponents));
1408 #endif
1409   // The last parameter to "TRUE" indicates that we ALWAYS create a FPX Image View. If the user never call
1410   // Viewing parameter function, the Toolkit will automatically creates transformless images
1411   *theFPX = new PFlashPixImageView(fileName, width, height,(float) DEFAULT_RESOLUTION, baseSpace, backColor, compressOption, TRUE, colorspace.isUncalibrated);
1412 
1413   if (*theFPX == NULL)
1414     status = FPX_SEVER_INIT_ERROR;
1415   else {
1416     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1417     if (image == NULL)
1418       status = FPX_FILE_NOT_FOUND;
1419     else
1420       status = image->OpenImage();
1421   }
1422 
1423   if ((status != FPX_OK) && (*theFPX)) {
1424     delete *theFPX;
1425     *theFPX = NULL;
1426   }
1427 
1428   return status;
1429 }
1430 
1431 // Create function using the proper file identifier for each platform
FPX_CreateImageByFilename(const FSSpec & fileSpecs,unsigned int width,unsigned int height,unsigned int tileWidth,unsigned int tileHeight,FPXColorspace colorspace,FPXBackground backgroundColor,FPXCompressionOption compressOption,FPXImageHandle ** theFPX)1432 FPXStatus FPX_CreateImageByFilename (
1433 #ifdef macintosh
1434               const FSSpec&        fileSpecs,
1435 #else
1436               const char*          fileName,
1437 #endif
1438               unsigned int         width,
1439               unsigned int         height,
1440               unsigned int         tileWidth,
1441               unsigned int         tileHeight,
1442               FPXColorspace        colorspace,
1443               FPXBackground        backgroundColor,
1444               FPXCompressionOption compressOption,
1445               FPXImageHandle**     theFPX)
1446 {
1447 #ifdef macintosh
1448   FicNom  file(fileSpecs);
1449 #else
1450   FicNom  file(fileName);
1451 #endif
1452   return CreateImageByFilename (
1453               file,
1454               width,
1455               height,
1456               tileWidth,
1457               tileHeight,
1458               colorspace,
1459               backgroundColor,
1460               compressOption,
1461               theFPX);
1462 }
1463 
FPX_CreateImageByStorage(IStorage * owningStorage,const char * storageName,unsigned int width,unsigned int height,unsigned int,unsigned int,FPXColorspace colorspace,FPXBackground backgroundColor,FPXCompressionOption compressOption,FPXImageHandle ** theFPX)1464 FPXStatus FPX_CreateImageByStorage (
1465                                     IStorage*            owningStorage,
1466                                     const char*          storageName,
1467                                     unsigned int         width,
1468                                     unsigned int         height,
1469                                     unsigned int         /*tileWidth*/,     // not implemented in Baseline (always 64)
1470                                     unsigned int         /*tileHeight*/,      // not implemented in Baseline (always 64)
1471                                     FPXColorspace        colorspace,
1472                                     FPXBackground        backgroundColor,
1473                                     FPXCompressionOption compressOption,
1474                                     FPXImageHandle**     theFPX)
1475 {
1476   // BEGIN: djk 052297 AI17850
1477   // Check params
1478   if (!(theFPX && owningStorage))
1479     return FPX_ERROR;
1480 
1481   // Satisfy failure conditions
1482   *theFPX = NULL;
1483   // END: djk 052297 AI17850
1484 
1485   FPXStatus status = FPX_OK;
1486 
1487   // Convert the color space into a Baseline space
1488   FPXBaselineColorSpace baseSpace;
1489   baseSpace = AnalyseFPXColorSpace (colorspace);
1490 
1491   // Convert the background color into a Baseline (32 bits per pixel, 8 bits per channel) value
1492 #ifdef _WINDOWS
1493   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) <<  0) |
1494     ((unsigned char)(backgroundColor.color2_value) <<  8) |
1495     ((unsigned char)(backgroundColor.color3_value) << 16) |
1496     ((unsigned char)(backgroundColor.color4_value) << 24);
1497   backColor = backColor << (8 * (4 - colorspace.numberOfComponents));
1498 #else
1499   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) << 24) |
1500     ((unsigned char)(backgroundColor.color2_value) << 16) |
1501     ((unsigned char)(backgroundColor.color3_value) <<  8) |
1502     (unsigned char)(backgroundColor.color4_value);
1503   backColor = backColor >> (8 * (4 - colorspace.numberOfComponents));
1504 #endif
1505   // BEGIN: djk 052297 AI17850: handle sub-storages correctly
1506   const CLSID clsidFpxRoot = ID_ImageView;
1507   OLEStorage* theowningStorage = NULL;
1508   OLEStorage* theSubStorage = NULL;
1509 
1510   if (storageName)
1511     {
1512       // Create an object wrap around the storage
1513       theowningStorage = new OLEStorage(
1514                                         (OLEStorage *)(NULL),
1515                                         owningStorage);
1516       if (!theowningStorage)
1517         {
1518           // Couldn't create storage wrapper
1519           return FPX_MEMORY_ALLOCATION_FAILED;
1520         }
1521 
1522       // Create the sub-storage as an FPX Root
1523       Boolean bRes;
1524       bRes = theowningStorage->CreateStorage(
1525                                              (CLSID) clsidFpxRoot,
1526                                              (const char*) storageName,
1527                                              &theSubStorage);
1528 
1529       // We're done with the parent storage now; release it
1530       status = theowningStorage->getFPXStatus();
1531       delete theowningStorage; theowningStorage = NULL;
1532 
1533       // See if we actually got the sub-storage
1534       if (!bRes)
1535         return status;
1536 
1537       // Create the ImageView
1538       *theFPX = new PFlashPixImageView(
1539                                        theSubStorage,
1540                                        (const char*) NULL,
1541                                        width,
1542                                        height,
1543                                        (float) DEFAULT_RESOLUTION,
1544                                        baseSpace,
1545                                        backColor,
1546                                        compressOption,
1547                                        TRUE,
1548                                        colorspace.isUncalibrated);
1549     }
1550   else
1551     {
1552       // The specified storage is to become an FPX Root.
1553       // Create an object wrap around the storage and set the CLSID for FPX
1554       theowningStorage = new OLEStorage(
1555                                         (CLSID) clsidFpxRoot,
1556                                         (OLEStorage *)(NULL),
1557                                         owningStorage);
1558       if (!theowningStorage)
1559         {
1560           // Couldn't create storage wrapper
1561           return FPX_MEMORY_ALLOCATION_FAILED;
1562         }
1563 
1564       // Create the ImageView at the specified storage
1565       *theFPX = new PFlashPixImageView(
1566                                        theowningStorage,
1567                                        (const char*) NULL,
1568                                        width,
1569                                        height,
1570                                        (float) DEFAULT_RESOLUTION,
1571                                        baseSpace,
1572                                        backColor,
1573                                        compressOption,
1574                                        TRUE,
1575                                        colorspace.isUncalibrated);
1576     }
1577 
1578   // See if we actually got the ImageView
1579   if (*theFPX == NULL)
1580     {
1581       // Couldn't create ImageView; clean up
1582       delete theSubStorage; theSubStorage = NULL;
1583       delete theowningStorage; theowningStorage = NULL;
1584       status = FPX_MEMORY_ALLOCATION_FAILED;
1585     }
1586   // END: djk 052297 AI17850: handle sub-storages correctly
1587   else {
1588     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1589     if (image == NULL)
1590       status = FPX_FILE_NOT_FOUND;
1591     else
1592       status = image->OpenImage();
1593   }
1594 
1595   if ((status != FPX_OK) && (*theFPX)) {
1596     delete *theFPX;
1597     *theFPX = NULL;
1598   }
1599 
1600   return status;
1601 }
1602 
1603 // Open a fpx file
1604 // CHG_VIS_OUT - Added a new argument to support specifying a visible output
1605 //  index during open. This allows support for some non-core files that have
1606 //  multiple visible output images.
OpenImageByFilename(FicNom & fileName,const char * storagePathInFile,unsigned long visibleOutputIndex,unsigned int * width,unsigned int * height,unsigned int * tileWidth,unsigned int * tileHeight,FPXColorspace * colorspace,FPXImageHandle ** theFPX)1607 FPXStatus OpenImageByFilename (
1608               FicNom&          fileName,
1609               const char*      storagePathInFile, // for the moment, only the root storage is considered
1610               unsigned long    visibleOutputIndex,
1611               unsigned int*   width,
1612               unsigned int*   height,
1613               unsigned int*   tileWidth,
1614               unsigned int*   tileHeight,
1615               FPXColorspace*   colorspace,
1616               FPXImageHandle** theFPX)
1617 {
1618   FPXStatus status = FPX_OK;
1619 
1620   // CHG_FILE_ERR2 - clear the errors list, so we only get new error reports
1621   GtheSystemToolkit->DeleteErrorsList();
1622 
1623   //
1624   // Open the FPX thing: the constructor automatically detects if it's a FPX Image Object or a
1625   // FPX Image View
1626   *theFPX = new PFlashPixImageView (fileName, storagePathInFile,
1627             mode_Modification,
1628             visibleOutputIndex,
1629             NULL, &status);
1630   if (*theFPX == NULL)
1631     status = FPX_SEVER_INIT_ERROR;
1632   else {
1633     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1634     if (image == NULL)
1635       status = (*theFPX)->FileStatus ();
1636     else
1637       status = image->OpenImage();
1638   }
1639 
1640   if ((status != FPX_OK) && (*theFPX)) {
1641     delete *theFPX;
1642     *theFPX = NULL;
1643   } else {
1644     // If no error, get the FPX Image Object pointer and read the values
1645     int w, h, tw, th;
1646     FPXBaselineColorSpace baseSpace;
1647     Typ_Compression c;
1648     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1649     image->GetInfo(&w,&h,&tw,&th,&c);
1650     baseSpace = image->GetBaselineSpace();
1651     *width  = w;
1652     *height = h;
1653     *tileWidth  = tw;
1654     *tileHeight = th;
1655     CreateFPXColorSpace (baseSpace, colorspace);
1656     colorspace->isUncalibrated = image->GetUncalibratedFlag();
1657   }
1658 
1659   return status;
1660 }
1661 
FPX_OpenImageByFilename(const FSSpec & _file,const char * storagePathInFile,unsigned int * width,unsigned int * height,unsigned int * tileWidth,unsigned int * tileHeight,FPXColorspace * colorspace,FPXImageHandle ** theFPX)1662 FPXStatus FPX_OpenImageByFilename (
1663 #ifdef macintosh
1664               const FSSpec&    _file,
1665 #else
1666               const char*      _file,
1667 #endif
1668               const char*      storagePathInFile,
1669               unsigned int*    width,
1670               unsigned int*    height,
1671               unsigned int*    tileWidth,
1672               unsigned int*    tileHeight,
1673               FPXColorspace*   colorspace,
1674               FPXImageHandle** theFPX)
1675 {
1676   FicNom  fileSpecs(_file);
1677   return OpenImageByFilename (
1678               fileSpecs,
1679               storagePathInFile,
1680               0,          // CHG_VIS_OUT - Core images use visible output index of 0
1681               width,
1682               height,
1683               tileWidth,
1684               tileHeight,
1685               colorspace,
1686               theFPX);
1687 }
1688 
1689 // CHG_VIS_OUT - Added a file open call to support specifying a visible output
1690 //  index during open. This allows support for some non-core files that have
1691 //  multiple visible output images.
FPX_OpenIndexedImageByFilename(const FSSpec & _file,const char * storagePathInFile,unsigned int visibleOutputIndex,unsigned int * width,unsigned int * height,unsigned int * tileWidth,unsigned int * tileHeight,FPXColorspace * colorspace,FPXImageHandle ** theFPX)1692 FPXStatus FPX_OpenIndexedImageByFilename (
1693 #ifdef macintosh
1694               const FSSpec&    _file,
1695 #else
1696               const char*      _file,
1697 #endif
1698               const char*      storagePathInFile,
1699               unsigned int     visibleOutputIndex,
1700               unsigned int*    width,
1701               unsigned int*    height,
1702               unsigned int*    tileWidth,
1703               unsigned int*    tileHeight,
1704               FPXColorspace*   colorspace,
1705               FPXImageHandle** theFPX)
1706 {
1707   FicNom  file(_file);
1708   return OpenImageByFilename (
1709         file,
1710                 storagePathInFile,
1711                 visibleOutputIndex,
1712                 width,
1713                 height,
1714                 tileWidth,
1715                 tileHeight,
1716                 colorspace,
1717                 theFPX);
1718 }
1719 
FPX_OpenImageByStorage(IStorage * storagePointer,const char * storagePathInFile,unsigned int * width,unsigned int * height,unsigned int * tileWidth,unsigned int * tileHeight,FPXColorspace * colorspace,FPXImageHandle ** theFPX)1720 FPXStatus FPX_OpenImageByStorage (
1721               IStorage*        storagePointer,
1722               const char*      storagePathInFile,
1723               unsigned int*    width,
1724               unsigned int*    height,
1725               unsigned int*    tileWidth,
1726               unsigned int*    tileHeight,
1727               FPXColorspace*   colorspace,
1728               FPXImageHandle** theFPX)
1729 {
1730   FPXStatus status = FPX_OK;
1731 
1732 // BEGIN: djk 052197 AI17850
1733   if (!(storagePointer && width && height && tileWidth && tileHeight && colorspace && theFPX))
1734     return FPX_ERROR;
1735 
1736   // Satisfy failure conditions
1737   *theFPX = NULL;
1738 // END: djk 052197 AI17850
1739 
1740 // BEGIN: djk 052297 AI17850: handle sub-storages correctly
1741   OLEStorage* theowningStorage = NULL;
1742   OLEStorage* theSubStorage = NULL;
1743 
1744   // Create an object wrap around the IStorage
1745   theowningStorage = new OLEStorage
1746     ((OLEStorage *)(NULL),
1747     storagePointer);
1748   if (!theowningStorage)
1749     return FPX_MEMORY_ALLOCATION_FAILED;
1750 
1751   if (storagePathInFile)
1752   {
1753     // Open the sub-storage
1754     theowningStorage->OpenStorage(
1755       (const char*) storagePathInFile,
1756       &theSubStorage,
1757       OLE_READWRITE_MODE);
1758 
1759     // We're done with the parent storage now
1760     status = theowningStorage->getFPXStatus();
1761     delete theowningStorage; theowningStorage = NULL;
1762 
1763     // See if we really got the sub-storage
1764     if (!theSubStorage)
1765       return status;
1766 
1767     // Open the FPX thing: the constructor automatically detects if it's a FPX Image Object or a
1768     // FPX Image View
1769     *theFPX = new PFlashPixImageView(
1770       theSubStorage,
1771       (const char*) NULL,
1772       mode_Modification);
1773   }
1774   else
1775   {
1776     // Open the FPX thing: the constructor automatically detects if it's a FPX Image Object or a
1777     // FPX Image View
1778     *theFPX = new PFlashPixImageView(
1779       theowningStorage,
1780       (const char*) NULL,
1781       mode_Modification);
1782   }
1783 
1784   // See if we actually got the ImageView
1785   if (*theFPX == NULL)
1786   {
1787     // Failed to create ImageView; clean up
1788     delete theSubStorage; theSubStorage = NULL;
1789     delete theowningStorage; theowningStorage = NULL;
1790     status = FPX_SEVER_INIT_ERROR;
1791   }
1792 // END: djk 052297 AI17850: handle sub-storages correctly
1793   else {
1794     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1795     if (image == NULL)
1796       status = FPX_FILE_NOT_FOUND;
1797     else
1798       status = image->OpenImage();
1799   }
1800 
1801   if ((status != FPX_OK) && (*theFPX)) {
1802     delete *theFPX;
1803     *theFPX = NULL;
1804   } else {
1805     // If no error, get the FPX Image Object pointer and read the values
1806     int w, h, tw, th;
1807     FPXBaselineColorSpace baseSpace;
1808     Typ_Compression c;
1809     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1810     image->GetInfo(&w,&h,&tw,&th,&c);
1811     baseSpace = image->GetBaselineSpace();
1812     *width  = w;
1813     *height = h;
1814     *tileWidth  = tw;
1815     *tileHeight = th;
1816     CreateFPXColorSpace (baseSpace, colorspace);
1817     colorspace->isUncalibrated = image->GetUncalibratedFlag();
1818   }
1819 
1820   return status;
1821 }
1822 
1823 /***************************************************************************
1824    IMAGES WITH VIEWS
1825  ***************************************************************************/
1826 
CreateImageWithViewByFilename(FicNom & fileName,unsigned int width,unsigned int height,unsigned int,unsigned int,FPXColorspace colorspace,FPXBackground backgroundColor,FPXCompressionOption compressOption,FPXAffineMatrix * affineMatrix,FPXContrastAdjustment * contrastValue,FPXColorTwistMatrix * colorTwist,FPXFilteringValue * filteringValue,FPXROI * regionOfInterest,FPXResultAspectRatio * resultAspectRatio,FPXImageHandle ** theFPX)1827 FPXStatus CreateImageWithViewByFilename (
1828               FicNom&              fileName,
1829               unsigned int           width,
1830               unsigned int           height,
1831               unsigned int           /*tileWidth*/,       // not implemented in Baseline (always 64)
1832               unsigned int           /*tileHeight*/,      // not implemented in Baseline (always 64)
1833               FPXColorspace          colorspace,
1834               FPXBackground          backgroundColor,
1835               FPXCompressionOption   compressOption,
1836               FPXAffineMatrix*       affineMatrix,
1837               FPXContrastAdjustment* contrastValue,
1838               FPXColorTwistMatrix*   colorTwist,
1839               FPXFilteringValue*     filteringValue,
1840               FPXROI*                regionOfInterest,
1841               FPXResultAspectRatio*  resultAspectRatio,
1842               FPXImageHandle**       theFPX)
1843 {
1844   FPXStatus status = FPX_OK;
1845 
1846   // CHG_FILE_ERR2 - clear the errors list, so we only get new error reports
1847   GtheSystemToolkit->DeleteErrorsList();
1848 
1849   // Convert the color space into a Baseline space
1850   FPXBaselineColorSpace baseSpace;
1851   baseSpace = AnalyseFPXColorSpace (colorspace);
1852 
1853   // Convert the background color into a Baseline (32 bits per pixel, 8 bits per channel) value
1854   // CHG_WIN_COLOR - use different byte ordering for Windows than on Mac
1855 #ifdef _WINDOWS
1856   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) <<  0) |
1857                   ((unsigned char)(backgroundColor.color2_value) <<  8) |
1858                   ((unsigned char)(backgroundColor.color3_value) << 16) |
1859                   ((unsigned char)(backgroundColor.color4_value) << 24);
1860   backColor = backColor << (8 * (4 - colorspace.numberOfComponents));
1861 #else
1862   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) << 24) |
1863                   ((unsigned char)(backgroundColor.color2_value) << 16) |
1864                   ((unsigned char)(backgroundColor.color3_value) <<  8) |
1865                    (unsigned char)(backgroundColor.color4_value);
1866   backColor = backColor >> (8 * (4 - colorspace.numberOfComponents));
1867 #endif
1868   *theFPX = new PFlashPixImageView  (fileName, width, height,(float) DEFAULT_RESOLUTION, baseSpace, backColor, compressOption, TRUE, colorspace.isUncalibrated);
1869 
1870   if (*theFPX == NULL)
1871     status = FPX_SEVER_INIT_ERROR;
1872   else {
1873     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
1874     if (image == NULL)
1875       status = FPX_FILE_NOT_FOUND;
1876     else {
1877       status = image->OpenImage();
1878 
1879       (*theFPX)->SetImageAffineMatrix (affineMatrix);
1880       (*theFPX)->SetImageContrastAdjustment (contrastValue);
1881       (*theFPX)->SetImageColorTwistMatrix (colorTwist);
1882       (*theFPX)->SetImageFilteringValue (filteringValue);
1883       (*theFPX)->SetImageROI (regionOfInterest);
1884       (*theFPX)->SetImageResultAspectRatio (resultAspectRatio);
1885     }
1886   }
1887 
1888   if ((status != FPX_OK) && (*theFPX)) {
1889     delete *theFPX;
1890     *theFPX = NULL;
1891   }
1892 
1893   return status;
1894 }
1895 
1896 // Create function using the proper file identifier for each platform
FPX_CreateImageWithViewByFilename(const FSSpec & _file,unsigned int width,unsigned int height,unsigned int tileWidth,unsigned int tileHeight,FPXColorspace colorspace,FPXBackground backgroundColor,FPXCompressionOption compressOption,FPXAffineMatrix * affineMatrix,FPXContrastAdjustment * contrastValue,FPXColorTwistMatrix * colorTwist,FPXFilteringValue * filteringValue,FPXROI * regionOfInterest,FPXResultAspectRatio * resultAspectRatio,FPXImageHandle ** theFPX)1897 FPXStatus FPX_CreateImageWithViewByFilename (
1898 #ifdef macintosh
1899               const FSSpec&          _file,
1900 #else
1901               const char*            _file,
1902 #endif
1903               unsigned int           width,
1904               unsigned int           height,
1905               unsigned int           tileWidth,
1906               unsigned int           tileHeight,
1907               FPXColorspace          colorspace,
1908               FPXBackground          backgroundColor,
1909               FPXCompressionOption   compressOption,
1910               FPXAffineMatrix*       affineMatrix,
1911               FPXContrastAdjustment* contrastValue,
1912               FPXColorTwistMatrix*   colorTwist,
1913               FPXFilteringValue*     filteringValue,
1914               FPXROI*                regionOfInterest,
1915               FPXResultAspectRatio*  resultAspectRatio,
1916               FPXImageHandle**       theFPX)
1917 {
1918   FicNom  file(_file);
1919   return CreateImageWithViewByFilename (
1920               file,
1921               width,
1922               height,
1923               tileWidth,
1924               tileHeight,
1925               colorspace,
1926               backgroundColor,
1927               compressOption,
1928               affineMatrix,
1929               contrastValue,
1930               colorTwist,
1931               filteringValue,
1932               regionOfInterest,
1933               resultAspectRatio,
1934               theFPX);
1935 }
1936 
FPX_CreateImageWithViewByStorage(IStorage * owningStorage,const char * storageName,unsigned int width,unsigned int height,unsigned int,unsigned int,FPXColorspace colorspace,FPXBackground backgroundColor,FPXCompressionOption compressOption,FPXAffineMatrix * affineMatrix,FPXContrastAdjustment * contrastValue,FPXColorTwistMatrix * colorTwist,FPXFilteringValue * filteringValue,FPXROI * regionOfInterest,FPXResultAspectRatio * resultAspectRatio,FPXImageHandle ** theFPX)1937 FPXStatus FPX_CreateImageWithViewByStorage (
1938               IStorage*              owningStorage,
1939               const char*            storageName,
1940               unsigned int           width,
1941               unsigned int           height,
1942               unsigned int           /*tileWidth*/,
1943               unsigned int           /*tileHeight*/,
1944               FPXColorspace          colorspace,
1945               FPXBackground          backgroundColor,
1946               FPXCompressionOption   compressOption,
1947               FPXAffineMatrix*       affineMatrix,
1948               FPXContrastAdjustment* contrastValue,
1949               FPXColorTwistMatrix*   colorTwist,
1950               FPXFilteringValue*     filteringValue,
1951               FPXROI*                regionOfInterest,
1952               FPXResultAspectRatio*  resultAspectRatio,
1953               FPXImageHandle**       theFPX)
1954 {
1955   FPXStatus status = FPX_OK;
1956 
1957   // Convert the color space into a Baseline space
1958   FPXBaselineColorSpace baseSpace;
1959   baseSpace = AnalyseFPXColorSpace (colorspace);
1960 
1961   // Convert the background color into a Baseline (32 bits per pixel, 8 bits per channel) value
1962   // CHG_WIN_COLOR - Use different byte ordering for Windows
1963 #ifdef _WINDOWS
1964   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) <<  0) |
1965                   ((unsigned char)(backgroundColor.color2_value) <<  8) |
1966                   ((unsigned char)(backgroundColor.color3_value) << 16) |
1967                   ((unsigned char)(backgroundColor.color4_value) << 24);
1968   backColor = backColor << (8 * (4 - colorspace.numberOfComponents));
1969 #else
1970   unsigned long backColor = ((unsigned char)(backgroundColor.color1_value) << 24) |
1971                   ((unsigned char)(backgroundColor.color2_value) << 16) |
1972                   ((unsigned char)(backgroundColor.color3_value) <<  8) |
1973                    (unsigned char)(backgroundColor.color4_value);
1974   backColor = backColor >> (8 * (4 - colorspace.numberOfComponents));
1975 #endif
1976 
1977 // BEGIN: djk 052297 AI17850: handle sub-storages correctly
1978   const CLSID clsidFpxRoot = ID_ImageView;
1979   OLEStorage* theowningStorage = NULL;
1980   OLEStorage* theSubStorage = NULL;
1981 
1982   if (storageName)
1983   {
1984     // Create an object wrap around the storage
1985     theowningStorage = new OLEStorage(
1986       (OLEStorage *)(NULL),
1987       owningStorage);
1988     if (!theowningStorage)
1989     {
1990       // Couldn't create storage wrapper
1991       return FPX_MEMORY_ALLOCATION_FAILED;
1992     }
1993 
1994     // Create the sub-storage as an FPX Root
1995     Boolean bRes;
1996     bRes = theowningStorage->CreateStorage(
1997       (CLSID) clsidFpxRoot,
1998       (const char*) storageName,
1999       &theSubStorage);
2000 
2001     // We're done with the parent storage now; release it
2002     status = theowningStorage->getFPXStatus();
2003     delete theowningStorage; theowningStorage = NULL;
2004 
2005     // See if we actually got the sub-storage
2006     if (!bRes)
2007       return status;
2008 
2009     // Create the ImageView
2010     *theFPX = new PFlashPixImageView(
2011       theSubStorage,
2012       (const char*) NULL,
2013       width,
2014       height,
2015       (float) DEFAULT_RESOLUTION,
2016       baseSpace,
2017       backColor,
2018       compressOption,
2019       TRUE,
2020       colorspace.isUncalibrated);
2021   }
2022   else
2023   {
2024     // The specified storage is to become an FPX Root.
2025     // Create an object wrap around the storage and set the CLSID for FPX
2026     theowningStorage = new OLEStorage(
2027       (CLSID) clsidFpxRoot,
2028       (OLEStorage *)(NULL),
2029       owningStorage);
2030     if (!theowningStorage)
2031     {
2032       // Couldn't create storage wrapper
2033       return FPX_MEMORY_ALLOCATION_FAILED;
2034     }
2035 
2036     // Create the ImageView at the specified storage
2037     *theFPX = new PFlashPixImageView(
2038       theowningStorage,
2039       (const char*) NULL,
2040       width,
2041       height,
2042       (float) DEFAULT_RESOLUTION,
2043       baseSpace,
2044       backColor,
2045       compressOption,
2046       TRUE,
2047       colorspace.isUncalibrated);
2048   }
2049 
2050   // See if we actually got the ImageView
2051   if (*theFPX == NULL)
2052   {
2053     // Couldn't create ImageView; clean up
2054     delete theSubStorage; theSubStorage = NULL;
2055     delete theowningStorage; theowningStorage = NULL;
2056     status = FPX_MEMORY_ALLOCATION_FAILED;
2057   }
2058 // END: djk 052297 AI17850: handle sub-storages correctly
2059   else {
2060     PFileFlashPixIO* image =  (PFileFlashPixIO*)((*theFPX)->GetImage());
2061     if (image == NULL)
2062       status = FPX_FILE_NOT_FOUND;
2063     else {
2064       status = image->OpenImage();
2065 
2066       (*theFPX)->SetImageAffineMatrix (affineMatrix);
2067       (*theFPX)->SetImageContrastAdjustment (contrastValue);
2068       (*theFPX)->SetImageColorTwistMatrix (colorTwist);
2069       (*theFPX)->SetImageFilteringValue (filteringValue);
2070       (*theFPX)->SetImageROI (regionOfInterest);
2071       (*theFPX)->SetImageResultAspectRatio (resultAspectRatio);
2072     }
2073   }
2074 
2075   if ((status != FPX_OK) && (*theFPX)) {
2076     delete *theFPX;
2077     *theFPX = NULL;
2078   }
2079 
2080   return status;
2081 }
2082 
2083 /********************************************************************************
2084    ICC PROFILE
2085  *******************************************************************************/
2086 
FPX_SetICCProfile(FPXImageHandle * theFPX,FPXStr * theProfile,unsigned short profileIndex)2087 FPXStatus FPX_SetICCProfile(
2088               FPXImageHandle *theFPX,
2089               FPXStr *        theProfile,
2090               unsigned short  profileIndex)
2091 {
2092   FPXStatus status = FPX_OK;
2093 
2094   if (!theFPX)  {
2095     status = FPX_INVALID_FPX_HANDLE;
2096     return status;
2097   }
2098 
2099   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
2100   PFlashPixFile* filePtr = (PFlashPixFile*)(image->GetCurrentFile());
2101 
2102   if ( !filePtr->SetICCProfile(profileIndex, FPXStrToLPSTR(*theProfile)) )
2103     return FPX_ERROR;
2104 
2105   return status;
2106 }
2107 
FPX_GetICCProfile(FPXImageHandle * theFPX,FPXStr * theProfile,unsigned short profileIndex)2108 FPXStatus FPX_GetICCProfile(
2109               FPXImageHandle *theFPX,
2110               FPXStr *        theProfile,
2111               unsigned short  profileIndex)
2112 {
2113   char *profileStream;
2114 
2115   FPXStatus status = FPX_OK;
2116 
2117   if (!theFPX)  {
2118     status = FPX_INVALID_FPX_HANDLE;
2119     return status;
2120   }
2121 
2122   PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
2123   PFlashPixFile* filePtr = (PFlashPixFile*)(image->GetCurrentFile());
2124 
2125   if ( filePtr->GetICCProfile(profileIndex, &profileStream) )
2126     status=FPX_Strcpy(theProfile, profileStream);
2127   else
2128     return FPX_ERROR;
2129 
2130   return status;
2131 }
2132 
2133 /***************************************************************************
2134     HIERARCHY GENERATION AND FLAT IMAGES HANDLING routines
2135  ***************************************************************************/
2136 
FPX_DoNotComputeHierarchy(FPXImageHandle * theFPX)2137 FPXStatus FPX_DoNotComputeHierarchy (
2138               FPXImageHandle*  theFPX)
2139 {
2140   FPXStatus status = FPX_OK;
2141   if (!theFPX)
2142     status = FPX_INVALID_FPX_HANDLE;
2143   else {
2144     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
2145     image->SetAutomaticDecimation(FALSE);
2146   }
2147   return status;
2148 }
2149 
FPX_GenerateHierarchy(FPXImageHandle * theFPX)2150 FPXStatus FPX_GenerateHierarchy (
2151               FPXImageHandle*  theFPX)
2152 {
2153   FPXStatus status = FPX_OK;
2154   if (!theFPX)
2155     status = FPX_INVALID_FPX_HANDLE;
2156   else {
2157     PFileFlashPixIO* image =  (PFileFlashPixIO*)(theFPX->GetImage());
2158     image->RegenerateHierarchy();
2159     status = FPX_FlushModifiedTiles(theFPX);
2160   }
2161   return status;
2162 }
2163 
2164 /********************************************************************************
2165    PATH
2166  *******************************************************************************/
2167 
2168 /*
2169  *  CAUTION: these functions are not implemented in Baseline
2170  */
2171 
FPX_SetPath(FPXImageHandle * theFPX,unsigned short thePathIndex,FPXPath * thePath)2172 FPXStatus FPX_SetPath(
2173               FPXImageHandle *theFPX,
2174               unsigned short  thePathIndex,
2175               FPXPath*        thePath)
2176 {
2177 //   FPXImageHandle *handle = theFPX;
2178 //   short     p = thePathIndex;
2179 //   FPXPath*  path= thePath;
2180   return FPX_UNIMPLEMENTED_FUNCTION;
2181 }
2182 
FPX_GetPath(FPXImageHandle * theFPX,unsigned short thePathIndex,FPXPath ** thePath)2183 FPXStatus FPX_GetPath(
2184               FPXImageHandle *theFPX,
2185               unsigned short  thePathIndex,
2186               FPXPath**       thePath)
2187 {
2188 //   FPXImageHandle *handle = theFPX;
2189 //   short  p = thePathIndex;
2190 //   FPXPath**   path= thePath;
2191   return FPX_UNIMPLEMENTED_FUNCTION;
2192 }
2193 
2194 /********************************************************************************
2195    IMAGE WITH VIEW
2196  *******************************************************************************/
2197 
FPX_SetImageROI(FPXImageHandle * theFPX,FPXROI * theROI)2198 FPXStatus FPX_SetImageROI (
2199               FPXImageHandle*  theFPX,
2200               FPXROI*          theROI)
2201 {
2202 
2203   FPXStatus status;
2204   if( ( status = theFPX->SetImageROI(theROI)) == FPX_OK)
2205     status = theFPX->SaveImageROI();
2206   return status;
2207 
2208   //return theFPX->SetImageROI(theROI);
2209 }
2210 
FPX_GetImageROI(FPXImageHandle * theFPX,FPXROI * theROI)2211 FPXStatus FPX_GetImageROI (
2212               FPXImageHandle*  theFPX,
2213               FPXROI*          theROI)
2214 {
2215   return theFPX->GetImageROI(theROI);
2216 }
2217 
FPX_SetImageFilteringValue(FPXImageHandle * theFPX,FPXFilteringValue * theFiltering)2218 FPXStatus FPX_SetImageFilteringValue (
2219               FPXImageHandle*    theFPX,
2220               FPXFilteringValue* theFiltering)
2221 {
2222   FPXStatus status;
2223   if( ( status = theFPX->SetImageFilteringValue(theFiltering)) == FPX_OK)
2224     status = theFPX->SaveImageFilteringValue();
2225   return status;
2226 
2227 }
2228 
FPX_GetImageFilteringValue(FPXImageHandle * theFPX,FPXFilteringValue * theFiltering)2229 FPXStatus FPX_GetImageFilteringValue (
2230               FPXImageHandle*     theFPX,
2231               FPXFilteringValue*  theFiltering)
2232 {
2233   return theFPX->GetImageFilteringValue(theFiltering);
2234 }
2235 
FPX_SetImageAffineMatrix(FPXImageHandle * theFPX,FPXAffineMatrix * theAffineMatrix)2236 FPXStatus FPX_SetImageAffineMatrix (
2237               FPXImageHandle*   theFPX,
2238               FPXAffineMatrix*  theAffineMatrix)
2239 {
2240   FPXStatus status;
2241   if( ( status = theFPX->SetImageAffineMatrix(theAffineMatrix)) == FPX_OK)
2242     status = theFPX->SaveImageAffineMatrix();
2243   return status;
2244 }
2245 
FPX_GetImageAffineMatrix(FPXImageHandle * theFPX,FPXAffineMatrix * theAffineMatrix)2246 FPXStatus FPX_GetImageAffineMatrix (
2247               FPXImageHandle*   theFPX,
2248               FPXAffineMatrix*  theAffineMatrix)
2249 {
2250   return theFPX->GetImageAffineMatrix(theAffineMatrix);
2251 }
2252 
FPX_SetImageResultAspectRatio(FPXImageHandle * theFPX,FPXResultAspectRatio * theAspectRatio)2253 FPXStatus FPX_SetImageResultAspectRatio (
2254               FPXImageHandle*       theFPX,
2255               FPXResultAspectRatio* theAspectRatio)
2256 {
2257 /**
2258   FPXStatus status;
2259   if( ( status = theFPX->SetImageResultAspectRatio(theAspectRatio)) == FPX_OK)
2260     status = theFPX->SaveImageResultAspectRatio();
2261   return status;
2262 **/
2263   return theFPX->SetImageResultAspectRatio(theAspectRatio);
2264 }
2265 
FPX_GetImageResultAspectRatio(FPXImageHandle * theFPX,FPXResultAspectRatio * theAspectRatio)2266 FPXStatus FPX_GetImageResultAspectRatio (
2267               FPXImageHandle*        theFPX,
2268               FPXResultAspectRatio*  theAspectRatio)
2269 {
2270   return theFPX->GetImageResultAspectRatio(theAspectRatio);
2271 }
2272 
FPX_SetImageColorTwistMatrix(FPXImageHandle * theFPX,FPXColorTwistMatrix * theColorTwistMatrix)2273 FPXStatus FPX_SetImageColorTwistMatrix (
2274               FPXImageHandle*       theFPX,
2275               FPXColorTwistMatrix*  theColorTwistMatrix)
2276 {
2277   FPXStatus status;
2278   if( ( status = theFPX->SetImageColorTwistMatrix(theColorTwistMatrix)) == FPX_OK)
2279     status = theFPX->SaveImageColorTwistMatrix();
2280   return status;
2281 }
2282 
FPX_GetImageColorTwistMatrix(FPXImageHandle * theFPX,FPXColorTwistMatrix * theColorTwistMatrix)2283 FPXStatus FPX_GetImageColorTwistMatrix (
2284               FPXImageHandle*       theFPX,
2285               FPXColorTwistMatrix*  theColorTwistMatrix)
2286 {
2287   return theFPX->GetImageColorTwistMatrix(theColorTwistMatrix);
2288 }
2289 
FPX_SetImageContrastAdjustment(FPXImageHandle * theFPX,FPXContrastAdjustment * theContrastAdjustment)2290 FPXStatus FPX_SetImageContrastAdjustment (
2291               FPXImageHandle*        theFPX,
2292               FPXContrastAdjustment* theContrastAdjustment)
2293 {
2294   FPXStatus status;
2295   if( ( status = theFPX->SetImageContrastAdjustment(theContrastAdjustment)) == FPX_OK)
2296     status = theFPX->SaveImageContrastAdjustment();
2297   return status;
2298 }
2299 
FPX_GetImageContrastAdjustment(FPXImageHandle * theFPX,FPXContrastAdjustment * theContrastAdjustment)2300 FPXStatus FPX_GetImageContrastAdjustment (
2301               FPXImageHandle*         theFPX,
2302               FPXContrastAdjustment*  theContrastAdjustment)
2303 {
2304   return theFPX->GetImageContrastAdjustment(theContrastAdjustment);
2305 }
2306 
FPX_SetSummaryInformation(FPXImageHandle * theFPX,FPXSummaryInformation * theSummary)2307 FPXStatus FPX_SetSummaryInformation(
2308               FPXImageHandle *        theFPX,
2309               FPXSummaryInformation * theSummary)
2310 {
2311   FPXStatus status = FPX_OK;
2312 
2313   if (!theFPX)  {
2314     status = FPX_INVALID_FPX_HANDLE;
2315     return status;
2316   }
2317 
2318   PFileFlashPixView* filePtr = theFPX->GetCurrentFile();
2319 
2320   if (filePtr) {
2321     OLEProperty* aProp;
2322 
2323     if (theSummary->title_valid)
2324       if (filePtr->SetSummaryInfoProperty (PID_TITLE, TYP_TITLE, &aProp))
2325         *aProp = (FPXStr)(theSummary->title);
2326 
2327     if (theSummary->subject_valid)
2328       if (filePtr->SetSummaryInfoProperty (PID_SUBJECT, TYP_SUBJECT, &aProp))
2329         *aProp = (FPXStr)(theSummary->subject);
2330 
2331     if (theSummary->author_valid)
2332       if (filePtr->SetSummaryInfoProperty (PID_AUTHOR, TYP_AUTHOR, &aProp))
2333         *aProp = (FPXStr)theSummary->author;
2334 
2335     if (theSummary->keywords_valid)
2336       if (filePtr->SetSummaryInfoProperty (PID_KEYWORDS, TYP_KEYWORDS, &aProp))
2337         *aProp = (FPXStr)theSummary->keywords;
2338 
2339     if (theSummary->comments_valid)
2340       if (filePtr->SetSummaryInfoProperty (PID_COMMENTS, TYP_COMMENTS, &aProp))
2341         *aProp = (FPXStr)theSummary->comments;
2342 
2343     if (theSummary->OLEtemplate_valid)
2344       if (filePtr->SetSummaryInfoProperty (PID_TEMPLATE, TYP_TEMPLATE, &aProp))
2345         *aProp = (FPXStr)(theSummary->OLEtemplate);
2346 
2347     if (theSummary->last_author_valid)
2348       if (filePtr->SetSummaryInfoProperty (PID_LASTAUTHOR, TYP_LASTAUTHOR, &aProp))
2349         *aProp = (FPXStr)(theSummary->last_author);
2350 
2351     if (theSummary->rev_number_valid)
2352       if (filePtr->SetSummaryInfoProperty (PID_REV_NUMBER, TYP_REV_NUMBER, &aProp))
2353         *aProp = (FPXStr)(theSummary->rev_number);
2354 
2355     if (theSummary->edit_time_valid)
2356       if (filePtr->SetSummaryInfoProperty (PID_EDITTIME, TYP_EDITTIME, &aProp))
2357         *aProp = theSummary->edit_time;
2358 
2359     if (theSummary->last_printed_valid)
2360       if (filePtr->SetSummaryInfoProperty (PID_LASTPRINTED, TYP_LASTPRINTED, &aProp))
2361         *aProp = theSummary->last_printed;
2362 
2363     if (theSummary->create_dtm_valid)
2364       if (filePtr->SetSummaryInfoProperty (PID_CREATE_DTM, TYP_CREATE_DTM, &aProp))
2365         *aProp = theSummary->create_dtm;
2366 
2367     if (theSummary->last_save_dtm_valid)
2368       if (filePtr->SetSummaryInfoProperty (PID_LASTSAVE_DTM, TYP_LASTSAVE_DTM, &aProp))
2369         *aProp = theSummary->last_save_dtm;
2370 
2371     if (theSummary->page_count_valid)
2372       if (filePtr->SetSummaryInfoProperty (PID_PAGECOUNT, TYP_PAGECOUNT, &aProp))
2373         *aProp = (int32_t)(theSummary->page_count);
2374 
2375     if (theSummary->word_count_valid)
2376       if (filePtr->SetSummaryInfoProperty (PID_WORDCOUNT, TYP_WORDCOUNT, &aProp))
2377         *aProp = (int32_t)(theSummary->word_count);
2378 
2379     if (theSummary->char_count_valid)
2380       if (filePtr->SetSummaryInfoProperty (PID_CHARCOUNT, TYP_CHARCOUNT, &aProp))
2381         *aProp = (int32_t)(theSummary->char_count);
2382 
2383     if (theSummary->thumbnail_valid)
2384       if (filePtr->SetSummaryInfoProperty (PID_THUMBNAIL, TYP_THUMBNAIL, &aProp))
2385         *aProp = (FPXThumbnail *)&(theSummary->thumbnail);
2386 
2387     if (theSummary->appname_valid)
2388       if (filePtr->SetSummaryInfoProperty (PID_APPNAME, TYP_APPNAME, &aProp))
2389         *aProp = (FPXStr)(theSummary->appname);
2390 
2391     if (theSummary->security_valid)
2392       if (filePtr->SetSummaryInfoProperty (PID_SECURITY, TYP_SECURITY, &aProp))
2393         *aProp = (int32_t)(theSummary->security);
2394 
2395     filePtr->Commit();
2396   } else
2397     status = FPX_INVALID_FPX_HANDLE;
2398 
2399   return status;
2400 }
2401 
FPX_GetSummaryInformation(FPXImageHandle * theFPX,FPXSummaryInformation * theSummary)2402 FPXStatus FPX_GetSummaryInformation(
2403               FPXImageHandle *        theFPX,
2404               FPXSummaryInformation * theSummary)
2405 {
2406   FPXStatus status = FPX_OK;
2407 
2408   if (!theFPX)  {
2409     status = FPX_INVALID_FPX_HANDLE;
2410     return status;
2411   }
2412 
2413   PFileFlashPixView* filePtr = theFPX->GetCurrentFile();
2414 
2415   if (filePtr) {
2416     OLEProperty* aProp;
2417 
2418     if (filePtr->GetSummaryInfoProperty (PID_TITLE, &aProp)) {
2419       theSummary->title = (FPXStr)(*aProp);
2420       theSummary->title_valid = TRUE;
2421     } else
2422       theSummary->title_valid = FALSE;
2423 
2424     if (filePtr->GetSummaryInfoProperty (PID_SUBJECT, &aProp)) {
2425       theSummary->subject = (FPXStr)(*aProp);
2426       theSummary->subject_valid = TRUE;
2427     } else
2428       theSummary->subject_valid = FALSE;
2429 
2430     if (filePtr->GetSummaryInfoProperty (PID_AUTHOR, &aProp)) {
2431       theSummary->author = (FPXStr)(*aProp);
2432       theSummary->author_valid = TRUE;
2433     } else
2434       theSummary->author_valid = FALSE;
2435 
2436     if (filePtr->GetSummaryInfoProperty (PID_KEYWORDS, &aProp)) {
2437       theSummary->keywords = (FPXStr)(*aProp);
2438       theSummary->keywords_valid = TRUE;
2439     } else
2440       theSummary->keywords_valid = FALSE;
2441 
2442     if (filePtr->GetSummaryInfoProperty (PID_COMMENTS, &aProp)) {
2443       theSummary->comments = (FPXStr)(*aProp);
2444       theSummary->comments_valid = TRUE;
2445     } else
2446       theSummary->comments_valid = FALSE;
2447 
2448     if (filePtr->GetSummaryInfoProperty (PID_TEMPLATE, &aProp)) {
2449       theSummary->OLEtemplate = (FPXStr)(*aProp);
2450       theSummary->OLEtemplate_valid = TRUE;
2451     } else
2452       theSummary->OLEtemplate_valid = FALSE;
2453 
2454     if (filePtr->GetSummaryInfoProperty (PID_LASTAUTHOR, &aProp)) {
2455       theSummary->last_author = (FPXStr)(*aProp);
2456       theSummary->last_author_valid = TRUE;
2457     } else
2458       theSummary->last_author_valid = FALSE;
2459 
2460     if (filePtr->GetSummaryInfoProperty (PID_REV_NUMBER, &aProp)) {
2461       theSummary->rev_number = (FPXStr)(*aProp);
2462       theSummary->rev_number_valid = TRUE;
2463     } else
2464       theSummary->rev_number_valid = FALSE;
2465 
2466     if (filePtr->GetSummaryInfoProperty (PID_EDITTIME, &aProp)) {
2467       theSummary->edit_time = (FPXfiletime)(*aProp);
2468       theSummary->edit_time_valid = TRUE;
2469     } else
2470       theSummary->edit_time_valid = FALSE;
2471 
2472     if (filePtr->GetSummaryInfoProperty (PID_LASTPRINTED, &aProp)) {
2473       theSummary->last_printed = (FPXfiletime)(*aProp);
2474       theSummary->last_printed_valid = TRUE;
2475     } else
2476       theSummary->last_printed_valid = FALSE;
2477 
2478     if (filePtr->GetSummaryInfoProperty (PID_CREATE_DTM, &aProp)) {
2479       theSummary->create_dtm = (FPXfiletime)(*aProp);
2480       theSummary->create_dtm_valid = TRUE;
2481     } else
2482       theSummary->create_dtm_valid = FALSE;
2483 
2484     if (filePtr->GetSummaryInfoProperty (PID_LASTSAVE_DTM, &aProp)) {
2485       theSummary->last_save_dtm = (FPXfiletime)(*aProp);
2486       theSummary->last_save_dtm_valid = TRUE;
2487     } else
2488       theSummary->last_save_dtm_valid = FALSE;
2489 
2490     if (filePtr->GetSummaryInfoProperty (PID_PAGECOUNT, &aProp)) {
2491       theSummary->page_count = (int32_t)(*aProp);
2492       theSummary->page_count_valid = TRUE;
2493     } else
2494       theSummary->page_count_valid = FALSE;
2495 
2496     if (filePtr->GetSummaryInfoProperty (PID_WORDCOUNT, &aProp)) {
2497       theSummary->word_count = (int32_t)(*aProp);
2498       theSummary->word_count_valid = TRUE;
2499     } else
2500       theSummary->word_count_valid = FALSE;
2501 
2502     if (filePtr->GetSummaryInfoProperty (PID_CHARCOUNT, &aProp)) {
2503       theSummary->char_count = (int32_t)(*aProp);
2504       theSummary->char_count_valid = TRUE;
2505     } else
2506       theSummary->char_count_valid = FALSE;
2507 
2508     if (filePtr->GetSummaryInfoProperty (PID_THUMBNAIL, &aProp)) {
2509       theSummary->thumbnail = *(const FPXThumbnail *)(*aProp);
2510       theSummary->thumbnail_valid = TRUE;
2511     } else
2512       theSummary->thumbnail_valid = FALSE;
2513 
2514     if (filePtr->GetSummaryInfoProperty (PID_APPNAME, &aProp)) {
2515       theSummary->appname = (FPXStr)(*aProp);
2516       theSummary->appname_valid = TRUE;
2517     } else
2518       theSummary->appname_valid = FALSE;
2519 
2520     if (filePtr->GetSummaryInfoProperty (PID_SECURITY, &aProp)) {
2521       theSummary->security = (int32_t)(*aProp);
2522       theSummary->security_valid = TRUE;
2523     } else
2524       theSummary->security_valid = FALSE;
2525 
2526   }
2527 
2528   return status;
2529 }
2530 
2531 // CHG_GBLINFO - added call to return a struct containing data from the Global
2532 //  Info property set
FPX_GetGlobalInformation(FPXImageHandle * theFPX,FPXGlobalInformation * theGlobalInfo)2533 FPXStatus FPX_GetGlobalInformation(
2534               FPXImageHandle *        theFPX,
2535               FPXGlobalInformation *  theGlobalInfo)
2536 {
2537   FPXStatus status = FPX_OK;
2538 
2539   if (!theFPX)  {
2540     status = FPX_INVALID_FPX_HANDLE;
2541     return status;
2542   }
2543 
2544   PFileFlashPixView* filePtr = theFPX->GetCurrentFile();
2545 
2546   if (filePtr) {
2547     OLEProperty* aProp;
2548 
2549     if (filePtr->GetGlobalInfoProperty (PID_VisibleOutputs, &aProp)) {
2550       theGlobalInfo->visible_outputs = (FPXLongArray)(*aProp);
2551       theGlobalInfo->visible_outputs_valid = TRUE;
2552     } else
2553       theGlobalInfo->visible_outputs_valid = FALSE;
2554 
2555     if (filePtr->GetGlobalInfoProperty (PID_MaxImageIndex, &aProp)) {
2556       theGlobalInfo->max_image_index = (uint32_t)(*aProp);
2557       theGlobalInfo->max_image_index_valid = TRUE;
2558     } else
2559       theGlobalInfo->max_image_index_valid = FALSE;
2560 
2561     if (filePtr->GetGlobalInfoProperty (PID_MaxTransfoIndex, &aProp)) {
2562       theGlobalInfo->max_transform_index = (uint32_t)(*aProp);
2563       theGlobalInfo->max_transform_index_valid = TRUE;
2564     } else
2565       theGlobalInfo->max_transform_index_valid = FALSE;
2566 
2567     if (filePtr->GetGlobalInfoProperty (PID_MaxOperatorIndex, &aProp)) {
2568       theGlobalInfo->max_operation_index = (uint32_t)(*aProp);
2569       theGlobalInfo->max_operation_index_valid = TRUE;
2570     } else
2571       theGlobalInfo->max_operation_index_valid = FALSE;
2572   }
2573   return status;
2574 }
2575 
2576 //////////////////////////////////////////////////////////////////////////////
2577 // EXTENSION LIST MANAGEMENT
2578 //////////////////////////////////////////////////////////////////////////////
2579 
FPX_GetExtensionDescription(FPXImageHandle * theFPX,LPWSTR extensionName,FPXExtensionDescription * theDescription)2580 FPXStatus FPX_GetExtensionDescription (
2581               FPXImageHandle*             theFPX,
2582               LPWSTR                      extensionName,
2583               FPXExtensionDescription*    theDescription)
2584 {
2585   FPXStatus status = FPX_OK;
2586 
2587   if (!theFPX)  {
2588     status = FPX_INVALID_FPX_HANDLE;
2589     return status;
2590   }
2591 
2592   PFileFlashPixView* filePtr =  (PFileFlashPixView *)(theFPX->GetCurrentFile());
2593 
2594   if (filePtr) {
2595     OLEProperty* aProp;
2596     short extensionNumber;
2597 
2598     // Get the extension number matching the extension name, return false if fails
2599     if ( filePtr->GetExtensionNumber(extensionName, &extensionNumber) ) {
2600 
2601       if (filePtr->GetExtensionProperty (PID_ExtensionClassID(extensionNumber), &aProp))
2602         theDescription->extensionClassID = *(CLSID*)(*aProp);
2603 
2604       if (filePtr->GetExtensionProperty (PID_ExtensionPersistence(extensionNumber), &aProp))
2605         theDescription->extensionPersistence = (FPXExtensionPersistence)(WORD)(*aProp);
2606 
2607       if (filePtr->GetExtensionProperty (PID_ExtensionCreationDate(extensionNumber), &aProp)) {
2608         theDescription->extensionCreationDate = (FILETIME)(*aProp);
2609         theDescription->extensionCreationDateIsValid = TRUE;
2610       } else
2611         theDescription->extensionCreationDateIsValid = FALSE;
2612 
2613       if (filePtr->GetExtensionProperty (PID_ExtensionModificationDate(extensionNumber), &aProp)) {
2614         theDescription->extensionModificationDate = (FILETIME)(*aProp);
2615         theDescription->extensionModificationDateIsValid = TRUE;
2616       } else
2617         theDescription->extensionModificationDateIsValid = FALSE;
2618 
2619       if (filePtr->GetExtensionProperty (PID_CreateApplication(extensionNumber), &aProp)) {
2620         theDescription->creatingApplication = (FPXWideStr)(*aProp);
2621         theDescription->creatingApplicationIsValid = TRUE;
2622       } else
2623         theDescription->creatingApplicationIsValid = FALSE;
2624 
2625       if (filePtr->GetExtensionProperty (PID_ExtensionDescription(extensionNumber), &aProp)) {
2626         theDescription->extensionDescription = (FPXWideStr)(*aProp);
2627         theDescription->extensionDescriptionIsValid = TRUE;
2628       } else
2629         theDescription->extensionDescriptionIsValid = FALSE;
2630 
2631       if (filePtr->GetExtensionProperty (PID_StorageStreamPathName(extensionNumber), &aProp)) {
2632         theDescription->streamPathName = (FPXWideStrArray)(*aProp);
2633         theDescription->streamPathNameIsValid = TRUE;
2634       } else
2635         theDescription->streamPathNameIsValid = FALSE;
2636 
2637       if (filePtr->GetExtensionProperty (PID_FPXStreamPathName(extensionNumber), &aProp)) {
2638         theDescription->fpxStreamPathName = (FPXWideStrArray)(*aProp);
2639         theDescription->fpxStreamPathNameIsValid = TRUE;
2640       } else
2641         theDescription->fpxStreamPathNameIsValid = FALSE;
2642 
2643       if (filePtr->GetExtensionProperty (PID_FPXStreamFieldOffset(extensionNumber), &aProp)) {
2644         theDescription->fpxStreamOffset = (FPXLongArray)(*aProp);
2645         theDescription->fpxStreamOffsetIsValid = TRUE;
2646       } else
2647         theDescription->fpxStreamOffsetIsValid = FALSE;
2648 
2649       if (filePtr->GetExtensionProperty (PID_PropertySetPathName(extensionNumber), &aProp)) {
2650         theDescription->propertySetPathName = (FPXWideStrArray)(*aProp);
2651         theDescription->propertySetPathNameIsValid = TRUE;
2652       } else
2653         theDescription->propertySetPathNameIsValid = FALSE;
2654 
2655       if (filePtr->GetExtensionProperty (PID_PropertySetFormatID(extensionNumber), &aProp)) {
2656         theDescription->propertySetFormatID = (FPXClsIDArray)(*aProp);
2657         theDescription->propertySetFormatIDIsValid = TRUE;
2658       } else
2659         theDescription->propertySetFormatIDIsValid = FALSE;
2660 
2661       if (filePtr->GetExtensionProperty (PID_PropertySetIDCodes(extensionNumber), &aProp)) {
2662         theDescription->propertySetIDCodes = (FPXWideStrArray)(*aProp);
2663         theDescription->propertySetIDCodesIsValid = TRUE;
2664       } else
2665         theDescription->propertySetIDCodesIsValid = FALSE;
2666 
2667     }
2668     else
2669       return FPX_EXTENSION_FAILED;
2670   }
2671   else
2672     return FPX_INVALID_FPX_HANDLE;
2673 
2674 
2675   return status;
2676 }
2677 
FPX_SetExtensionDescription(FPXImageHandle * theFPX,LPWSTR extensionName,FPXExtensionDescription * theDescription)2678 FPXStatus FPX_SetExtensionDescription (
2679               FPXImageHandle*             theFPX,
2680               LPWSTR                        extensionName,
2681               FPXExtensionDescription*    theDescription)
2682 {
2683   FPXStatus status = FPX_OK;
2684 
2685   if (!theFPX)  {
2686     status = FPX_INVALID_FPX_HANDLE;
2687     return status;
2688   }
2689 
2690   PFileFlashPixView* filePtr =  (PFileFlashPixView *)(theFPX->GetCurrentFile());
2691 
2692   if (filePtr) {
2693     OLEProperty* aProp;
2694     short extensionNumber;
2695 
2696     // Get the extension number matching the extension name, return false if fails
2697     if ( filePtr->GetExtensionNumber(extensionName, &extensionNumber) ) {
2698 
2699       if (filePtr->SetExtensionProperty (PID_ExtensionClassID(extensionNumber), TYP_ExtensionClassID, &aProp))
2700         *aProp = &theDescription->extensionClassID;
2701 
2702       if (filePtr->SetExtensionProperty (PID_ExtensionPersistence(extensionNumber), TYP_ExtensionPersistence, &aProp))
2703         *aProp = (WORD)theDescription->extensionPersistence;
2704 
2705       if ( theDescription->extensionCreationDateIsValid )
2706         if (filePtr->SetExtensionProperty (PID_ExtensionCreationDate(extensionNumber), TYP_ExtensionCreationDate, &aProp))
2707           *aProp = (FPXfiletime)theDescription->extensionCreationDate;
2708 
2709       if ( theDescription->extensionModificationDateIsValid )
2710         if (filePtr->SetExtensionProperty (PID_ExtensionModificationDate(extensionNumber), TYP_ExtensionModificationDate, &aProp))
2711           *aProp = (FPXfiletime)theDescription->extensionModificationDate;
2712 
2713       if ( theDescription->creatingApplicationIsValid )
2714         if (filePtr->SetExtensionProperty (PID_CreateApplication(extensionNumber), TYP_CreateApplication, &aProp))
2715           *aProp = (FPXWideStr)theDescription->creatingApplication;
2716 
2717       if ( theDescription->extensionDescriptionIsValid )
2718         if (filePtr->SetExtensionProperty (PID_ExtensionDescription(extensionNumber), TYP_ExtensionDescription, &aProp))
2719           *aProp = (FPXWideStr)theDescription->extensionDescription;
2720 
2721       if ( theDescription->streamPathNameIsValid )
2722         if (filePtr->SetExtensionProperty (PID_StorageStreamPathName(extensionNumber),TYP_StorageStreamPathName, &aProp))
2723           *aProp = (FPXWideStrArray)theDescription->streamPathName;
2724 
2725       if ( theDescription->fpxStreamPathNameIsValid )
2726         if (filePtr->SetExtensionProperty (PID_FPXStreamPathName(extensionNumber), TYP_FPXStreamPathName, &aProp))
2727           *aProp = (FPXWideStrArray)theDescription->fpxStreamPathName;
2728 
2729       if ( theDescription->fpxStreamOffsetIsValid )
2730         if (filePtr->SetExtensionProperty (PID_FPXStreamFieldOffset(extensionNumber), TYP_FPXStreamFieldOffset, &aProp))
2731           *aProp = (FPXLongArray)theDescription->fpxStreamOffset;
2732 
2733       if ( theDescription->propertySetPathNameIsValid )
2734         if (filePtr->SetExtensionProperty (PID_PropertySetPathName(extensionNumber), TYP_PropertySetPathName, &aProp))
2735           *aProp = (FPXWideStrArray)theDescription->propertySetPathName;
2736 
2737       if ( theDescription->propertySetFormatIDIsValid )
2738         if (filePtr->SetExtensionProperty (PID_PropertySetFormatID(extensionNumber), TYP_PropertySetFormatID, &aProp))
2739           *aProp = (FPXClsIDArray)theDescription->propertySetFormatID;
2740 
2741       if ( theDescription->propertySetIDCodesIsValid )
2742         if (filePtr->SetExtensionProperty (PID_PropertySetIDCodes(extensionNumber), TYP_PropertySetIDCodes, &aProp))
2743           *aProp = (FPXWideStrArray)theDescription->propertySetIDCodes;
2744 
2745     }
2746     else if ( filePtr->SetExtensionNumber(&extensionNumber) ) {
2747 
2748       if (filePtr->SetExtensionProperty (PID_ExtensionClassID(extensionNumber), TYP_ExtensionClassID, &aProp))
2749         *aProp = &theDescription->extensionClassID;
2750 
2751       if (filePtr->SetExtensionProperty (PID_ExtensionPersistence(extensionNumber), TYP_ExtensionPersistence, &aProp))
2752         *aProp = (WORD)theDescription->extensionPersistence;
2753 
2754       if ( theDescription->extensionCreationDateIsValid )
2755         if (filePtr->SetExtensionProperty (PID_ExtensionCreationDate(extensionNumber), TYP_ExtensionCreationDate, &aProp))
2756           *aProp = (FPXfiletime)theDescription->extensionCreationDate;
2757 
2758       if ( theDescription->extensionModificationDateIsValid )
2759         if (filePtr->SetExtensionProperty (PID_ExtensionModificationDate(extensionNumber), TYP_ExtensionModificationDate, &aProp))
2760           *aProp = (FPXfiletime)theDescription->extensionModificationDate;
2761 
2762       if ( theDescription->creatingApplicationIsValid )
2763         if (filePtr->SetExtensionProperty (PID_CreateApplication(extensionNumber), TYP_CreateApplication, &aProp))
2764           *aProp = (FPXWideStr)theDescription->creatingApplication;
2765 
2766       if ( theDescription->extensionDescriptionIsValid )
2767         if (filePtr->SetExtensionProperty (PID_ExtensionDescription(extensionNumber), TYP_ExtensionDescription, &aProp))
2768           *aProp = (FPXWideStr)theDescription->extensionDescription;
2769 
2770       if ( theDescription->streamPathNameIsValid )
2771         if (filePtr->SetExtensionProperty (PID_StorageStreamPathName(extensionNumber),TYP_StorageStreamPathName, &aProp))
2772           *aProp = (FPXWideStrArray)theDescription->streamPathName;
2773 
2774       if ( theDescription->fpxStreamPathNameIsValid )
2775         if (filePtr->SetExtensionProperty (PID_FPXStreamPathName(extensionNumber), TYP_FPXStreamPathName, &aProp))
2776           *aProp = (FPXWideStrArray)theDescription->fpxStreamPathName;
2777 
2778       if ( theDescription->fpxStreamOffsetIsValid )
2779         if (filePtr->SetExtensionProperty (PID_FPXStreamFieldOffset(extensionNumber), TYP_FPXStreamFieldOffset, &aProp))
2780           *aProp = (FPXLongArray)theDescription->fpxStreamOffset;
2781 
2782       if ( theDescription->propertySetPathNameIsValid )
2783         if (filePtr->SetExtensionProperty (PID_PropertySetPathName(extensionNumber), TYP_PropertySetPathName, &aProp))
2784           *aProp = (FPXWideStrArray)theDescription->propertySetPathName;
2785 
2786       if ( theDescription->propertySetFormatIDIsValid )
2787         if (filePtr->SetExtensionProperty (PID_PropertySetFormatID(extensionNumber), TYP_PropertySetFormatID, &aProp))
2788           *aProp = (FPXClsIDArray)theDescription->propertySetFormatID;
2789 
2790       if ( theDescription->propertySetIDCodesIsValid )
2791         if (filePtr->SetExtensionProperty (PID_PropertySetIDCodes(extensionNumber), TYP_PropertySetIDCodes, &aProp))
2792           *aProp = (FPXWideStrArray)theDescription->propertySetIDCodes;
2793 
2794     }
2795     else
2796       return FPX_EXTENSION_FAILED;
2797   }
2798   else
2799     return FPX_INVALID_FPX_HANDLE;
2800 
2801   return status;
2802 }
2803 
FPX_GetStreamPointer(FPXImageHandle * theFPX,char * streamName,IStream ** oleStream)2804 FPXStatus FPX_GetStreamPointer (
2805               FPXImageHandle*             theFPX,
2806               char*                       streamName,
2807               IStream**                   oleStream)
2808 {
2809   FPXStatus status = FPX_OK;
2810 
2811   if (!theFPX)  {
2812     status = FPX_INVALID_FPX_HANDLE;
2813     return status;
2814   }
2815 
2816   PFileFlashPixView* filePtr =  (PFileFlashPixView *)(theFPX->GetCurrentFile());
2817 
2818   if (filePtr) {
2819     OLEStream * currentStream;
2820     long    streamLength;
2821 
2822     OLEStorage * rootStorage = filePtr->GetRootStorage();
2823     if ( rootStorage ) {
2824       if ( rootStorage->OpenStream(streamName, &currentStream, OLE_READWRITE_MODE) ) {
2825         currentStream->GetEndOfFile(&streamLength);
2826         currentStream->CopyTo(*oleStream, streamLength);
2827       }
2828       else
2829         status = FPX_EXTENSION_FAILED;
2830     }
2831     else
2832       status = FPX_EXTENSION_FAILED;
2833   }
2834   else
2835     status = FPX_INVALID_FPX_HANDLE;
2836 
2837   return status;
2838 }
2839 
FPX_GetStoragePointer(FPXImageHandle * theFPX,const char * storageName,IStorage ** oleStorage)2840 FPXStatus FPX_GetStoragePointer (
2841               FPXImageHandle*             theFPX,
2842               const char*                 storageName,
2843               IStorage**                  oleStorage)
2844 {
2845   FPXStatus status = FPX_OK;
2846 
2847   if (!theFPX)  {
2848     status = FPX_INVALID_FPX_HANDLE;
2849     return status;
2850   }
2851 
2852   PFileFlashPixView* filePtr =  (PFileFlashPixView *)(theFPX->GetCurrentFile());
2853 
2854   if (filePtr) {
2855     OLEStorage * currentStorage;
2856 
2857     OLEStorage * rootStorage = filePtr->GetRootStorage();
2858     if ( rootStorage ) {
2859       if ( rootStorage->OpenStorage(storageName, &currentStorage, OLE_READWRITE_MODE) ) {
2860         currentStorage->CopyTo(*oleStorage);
2861       }
2862       else
2863         status = FPX_EXTENSION_FAILED;
2864     }
2865     else
2866       status = FPX_EXTENSION_FAILED;
2867   }
2868   else
2869     status = FPX_INVALID_FPX_HANDLE;
2870 
2871   return status;
2872 }
2873 
FPX_GetPropertySetPointer(FPXImageHandle * theFPX,char * propertySetName,IStream ** olePropertySet)2874 FPXStatus FPX_GetPropertySetPointer (
2875               FPXImageHandle*             theFPX,
2876               char*                       propertySetName,
2877               IStream**                   olePropertySet)
2878 {
2879   FPXStatus status = FPX_OK;
2880 
2881   if (!theFPX)  {
2882     status = FPX_INVALID_FPX_HANDLE;
2883     return status;
2884   }
2885 
2886   PFileFlashPixView* filePtr =  (PFileFlashPixView *)(theFPX->GetCurrentFile());
2887 
2888   if (filePtr) {
2889     OLEPropertySet * currentPropertySet;
2890     long    propertySetLength;
2891 
2892     OLEStorage * rootStorage = filePtr->GetRootStorage();
2893     if ( rootStorage ) {
2894       if ( rootStorage->OpenPropertySet(propertySetName, &currentPropertySet, OLE_READWRITE_MODE) ) {
2895         currentPropertySet->GetEndOfFile(&propertySetLength);
2896         currentPropertySet->CopyTo(*olePropertySet, propertySetLength);
2897       }
2898       else
2899         status = FPX_EXTENSION_FAILED;
2900     }
2901     else
2902       status = FPX_EXTENSION_FAILED;
2903   }
2904   else
2905     status = FPX_INVALID_FPX_HANDLE;
2906 
2907   return status;
2908 }
2909 
2910 //  - EOF ----------------------------------------------------------------------
2911