1 // ------------------------------------------------------------------------------------------------
2 //
3 // TOOLKIT GLOBAL MANAGEMENT
4 // MODULE : SystemIVUE.cpp
5 // LANGUAGE : C++
6 // AUTHOR : Philippe BOSSUT
7 // DATE : Wenesday 22 December 1993
8 // DESCRIPTION :
9 // COMMENT : This package is a part of the IVUE Toolkit I/O and the FlashPix Baseline I/O
10 // SCCSID : @(#)ri_sys.cpp 1.3 12:49:41 29 Apr 1997
11 // ------------------------------------------------------------------------------------------------
12 // Copyright (c) 1999 Digital Imaging Group, Inc.
13 // For conditions of distribution and use, see copyright notice
14 // in Flashpix.h
15 // ------------------------------------------------------------------------------------------------
16 #include "ri_sys.h"
17 // ------------------------------------------------------------------------------------------------
18
19 // Includes
20 // --------
21 #include <stdlib.h>
22 #include <string.h>
23 #include <math.h>
24
25 #ifndef Debug_h
26 #include "debug.h"
27 #endif
28 #ifndef Memoire_h
29 #include "b_memory.h"
30 #endif
31
32 #ifndef BufferDesc_h
33 #include "buffdesc.h"
34 #endif
35
36 #ifndef Compresseur_h
37 #include "fpxcompress.h"
38 #endif
39
40 #ifndef OLECommun_h
41 #include "olecomm.h"
42 #endif
43 #ifndef OLECore_h
44 #include "olecore.h"
45 #endif
46
47 #ifndef PHierarchicalImage_h
48 #include "ph_image.h"
49 #endif
50 #ifndef PTile_h
51 #include "ptile.h"
52 #endif
53
54
55 // Constants
56 // ---------
57 #define NB_MAX_ERRORS 5
58
59 // Variables
60 // ---------
61
62 short ErrorsList::nbErr = 0;
63 PSystemToolkit* GtheSystemToolkit = NULL;
64
65 // ------------------------------------------------------------------------------------------------
66
67 // ------------------------------------------------------------------------------------------------
68
69 // ------------------------------------------------------------------------------------------------
70 // Internal Functions
71 // ------------------------------------------------------------------------------------------------
72
73 // ------------------------------------------------------------------------------------------------
74 // Extern functions
75 // ------------------------------------------------------------------------------------------------
76 #include <stdlib.h>
77 /************************************************************************/
78 /* Purpose..: Allocate memory */
79 /* Input....: size of memory to allocate */
80 /* Return...: pointer to memory or 0L */
81 /************************************************************************/
FitsNew(size_t,void * p)82 void *FitsNew(size_t /* size */,void *p)
83 {
84 return p;
85 }
86
87 /************************************************************************/
88 /* Purpose..: Allocate memory */
89 /* Input....: size of memory to allocate */
90 /* Return...: pointer to memory or 0L */
91 /************************************************************************/
FitsNew(size_t size)92 void *FitsNew(size_t size)
93 {
94 return calloc(size, 1);
95 }
96
97 /************************************************************************/
98 /* Purpose..: Dispose memory */
99 /* Input....: pointer to memory or 0L (no action if 0L) */
100 /* Return...: --- */
101 /************************************************************************/
FitsDelete(void * ptr)102 void FitsDelete(void *ptr)
103 {
104 if (ptr) free(ptr);
105 }
106
107 /************************************************************************/
108 /* Purpose..: Check that GtheSystemToolkit is initalized */
109 /* Input....: */
110 /* Return...: true if initialized (GtheSystemToolkit != NULL) */
111 /************************************************************************/
GtheSystemToolkitInitialized(void)112 bool GtheSystemToolkitInitialized(void)
113 {
114 return (GtheSystemToolkit != NULL);
115 }
116
117 // ------------------------------------------------------------------------------------------------
118 // Methods of the PToolkitObject class
119 // ------------------------------------------------------------------------------------------------
120
121
operator new(size_t size)122 void* PToolkitObject::operator new (size_t size)
123 {
124 void *ptr;
125
126 // Call the redefined new to call calloc from Memoire.cp
127 ptr = FitsNew (size);
128
129 return ptr;
130 }
131
132
operator new(size_t size,void * p)133 void* PToolkitObject::operator new (size_t size, void *p)
134 {
135 // Call the redefined new to call calloc from Memoire.cp
136 return FitsNew (size, p);
137 }
138
139
operator delete(void * p)140 void PToolkitObject::operator delete (void *p)
141 {
142 // Call the redefined delete to call free from Memoire.cp
143 FitsDelete (p);
144 }
145
146
147 // ------------------------------------------------------------------------------------------------
148 // Methods of the PErrorsList class
149 // ------------------------------------------------------------------------------------------------
PErrorsList(OSErr err,FicNom file)150 PErrorsList::PErrorsList(OSErr err, FicNom file)
151
152 {
153 errorCode = err;
154 fileName = file;
155 nextError = NULL;
156 }
157
158
~PErrorsList()159 PErrorsList::~PErrorsList()
160 {
161 if (nextError != NULL)
162 delete nextError;
163 }
164
165
AddErrorToList(OSErr err,FicNom file)166 void PErrorsList::AddErrorToList(OSErr err, FicNom file)
167 {
168 PErrorsList* last;
169 PErrorsList* tmp = new PErrorsList(err, file);
170 if (tmp==NULL) {
171 return;
172 }
173
174 last = this;
175 while (last->nextError != NULL)
176 last = last->nextError;
177 last->nextError = tmp;
178 }
179
180
181 // ------------------------------------------------------------------------------------------------
182 // Methods of the PSystemToolkit class
183 // ------------------------------------------------------------------------------------------------
184
185 // Set the default values of all global options :
186
PSystemToolkit()187 PSystemToolkit::PSystemToolkit ()
188 {
189 register int i, n;
190
191 tousLesCodecs = new obj_TousLesCodecs; // Allocate standard compressors
192
193 openRootStorageList = new List; // Allocate list for opened OLE root storage
194
195 fnctWaitFunc = NULL; // Pointer to Wait & Break function
196 fnctProgFunc = NULL; // Pointer to Wait & Break function
197
198 unit = Unit_inch; // Unit used by the user in commands
199 ratio = (float) 1.0; // Conversion ratio
200
201 interleaving = Interleaving_Pixel; // Global interleaving mode
202
203 SetAntialias(Antialias_None); // Global antialiasing quality
204 convolution = Convolution_Gauss; // Global convolution quality
205 filter = NULL; // Pointer to convolution function
206
207 preserveBackground = true; // Transparency on images edges set
208 backgroundColor = 0; // Color of the background set to black
209 backgroundSpace = SPACE_32_BITS_RGB; // Default color space is RGB
210
211 userColorCode = ColorCode_RGB; // User color model
212 fileColorCode = ColorCode_RGB; // File color model
213
214 existAlpha = false;
215
216 for (i = 0; i < 8; i++) {
217 fnctModeltoRGB[i] = NULL; // Pointer to Model to RGB function
218 fnctRGBtoModel[i] = NULL; // Pointer to RGB to Model function
219 }
220
221 compression = Compression_None; // Global compression mode
222 fnctCompression = NULL; // Pointer to compression function
223 fnctDecompression = NULL; // Pointer to decompression function
224 compressionHandle = NULL; // Pointer to compression option handle
225 handleSize = 0; // Size in bytes of the compression handle
226 activeChannel = ActiveChannel_All; // All the channels are active
227
228 for (i = 0, n = 0; n < 1024; n++) { // Compute Log2 table : used everywhere for subimage level
229 if (n >> (i+1)) // computation
230 ++i;
231 tableLog2[n] = i;
232 }
233
234 GtheSystemToolkit = this;
235
236 SetTileSize (DEFAULT_TILE_SIZE); // Size of the tiles
237 lockedImage = NULL; // Pointer to in memory locked image
238
239 errorsList = NULL; // Pointer to the fatal errors list
240 PErrorsList::nbErr = 0;
241
242 manageOLE = FALSE;
243
244 }
245
~PSystemToolkit()246 PSystemToolkit::~PSystemToolkit ()
247 {
248 // Delete all the errors list
249 if (errorsList) delete errorsList;
250
251 // Release standard compressor
252 delete tousLesCodecs;
253
254 // Delete list for opened OLE root storage
255 if (openRootStorageList) delete openRootStorageList;
256
257 // Release the luts and the list of locked Block
258 PTile::ClearStaticArrays();
259 }
260
261
262 // Compute the available memory in the Toolkit
AvailableMemory(long * size)263 void PSystemToolkit::AvailableMemory (long* size)
264 {
265 *size = 2*tileSize;
266 }
267
268
269 // Purge all memory owned by the toolkit - including locked blocks, etc.
PurgeSystem()270 void PSystemToolkit::PurgeSystem ()
271 {
272 long usedMemory;
273
274 usedMemory = 2*tileSize;
275
276 LockImage(NULL);
277 if (usedMemory)
278 PTile::Purge(&usedMemory, true);
279 }
280
281
282 // This function purges the required amount of memory. In fact, it purges all blocks
283 // which are not modified (in write mode) nor locked and then, if necessary to reach
284 // the required amount, purges the modified tiles (after writing them on disk), and
285 // if necessary the compression buffers.
286 // If the passed parameter memoryToBePurged is NULL, PurgeSystemWithAmount() returns
287 // the memory purgeable by the system (standard behavior with PhotoShop or XPress).
PurgeSystemWithAmount(long memoryToBePurged)288 long PSystemToolkit::PurgeSystemWithAmount (long memoryToBePurged)
289 {
290 if (memoryToBePurged == 0) {
291 return PTile::GetPurgeableMemory();
292 } else {
293 long memoryRemaining = memoryToBePurged;
294 PTile::Purge(&memoryRemaining, false);
295 return (memoryToBePurged - memoryRemaining);
296 }
297 }
298
299
SetTileSize(long newTileSize)300 long PSystemToolkit::SetTileSize(long newTileSize)
301 {
302 register long status = 0;
303
304 if (newTileSize < MIN_TILE_SIZE)
305 status = 1;
306 else
307 tileSize = newTileSize;
308
309 // tileSize must be of the form (2^(2n))*sizeof(Pixel)
310 tileSize /= sizeof(Pixel);
311 long i = 0;
312 // Compute the log2 of tileSize
313 while (tileSize>>=1) i++;
314 tileWidth = 1<<(i>>1);
315 tileSize = tileWidth*tileWidth*sizeof(Pixel);
316
317 return(status);
318 }
319
320
SetWaitFunc(Typ_WaitFunc newWaitFunc)321 long PSystemToolkit::SetWaitFunc (Typ_WaitFunc newWaitFunc)
322 {
323 register long status = 0;
324
325 if (newWaitFunc == NULL)
326 status = -1;
327 else
328 fnctWaitFunc = newWaitFunc;
329
330 return(status);
331 }
332
333
SetProgFunc(FPXProgressFunction newProgFunc)334 long PSystemToolkit::SetProgFunc (FPXProgressFunction newProgFunc)
335 {
336 register long status = 0;
337
338 if (newProgFunc == NULL)
339 status = -1;
340 else
341 fnctProgFunc = newProgFunc;
342
343 return(status);
344 }
345
346
SetUnit(Typ_Unit newUnit)347 long PSystemToolkit::SetUnit (Typ_Unit newUnit)
348 {
349 unit = newUnit;
350 switch (unit) {
351 case Unit_mm:
352 ratio = (float) 1.0;
353 break;
354 case Unit_inch:
355 ratio = (float) 25.4;
356 break;
357 default:
358 ratio = (float) 1.0;
359 break;
360 }
361 return(0);
362 }
363
364
GetUnit(Typ_Unit * newUnit)365 long PSystemToolkit::GetUnit (Typ_Unit* newUnit)
366 {
367 *newUnit = unit;
368 return(0);
369 }
370
371
SetConvolution(Typ_Convolution newConvolution,Typ_Filter newFilter)372 long PSystemToolkit::SetConvolution (Typ_Convolution newConvolution, Typ_Filter newFilter)
373 {
374 register long status = 0;
375
376 if (newConvolution == Convolution_Other) {
377 if (newFilter == NULL)
378 status = -1;
379 else {
380 filter = newFilter;
381 convolution = newConvolution;
382 }
383 }
384 else
385 convolution = newConvolution;
386
387 return(status);
388 }
389
390
SetConvolution(Typ_Convolution newConvolution)391 long PSystemToolkit::SetConvolution (Typ_Convolution newConvolution)
392 {
393 register long status = 0;
394
395 if (newConvolution == Convolution_Other)
396 status = 1;
397 else
398 convolution = newConvolution;
399
400 return(status);
401 }
402
403
SetAntialias(Typ_Antialias newAntialias)404 long PSystemToolkit::SetAntialias(Typ_Antialias newAntialias)
405 {
406 antialias = newAntialias;
407 if (antialias == Antialias_None)
408 PRIImage::readInterpolated = false;
409 else
410 PRIImage::readInterpolated = true;
411 return 0;
412 }
413
414
PreserveBackground(Boolean preserve)415 long PSystemToolkit::PreserveBackground (Boolean preserve)
416 {
417 // Update flag
418 preserveBackground = preserve;
419
420 return(0);
421 }
422
423
SetBackgroundColor(Pixel color,FPXBaselineColorSpace colorSpace)424 long PSystemToolkit::SetBackgroundColor (Pixel color, FPXBaselineColorSpace colorSpace)
425 {
426 // Update color
427 backgroundColor = color;
428 // Convert the passed color into the required color space
429 ConvertPixelBuffer ((unsigned char*)(&backgroundColor), 1, colorSpace, backgroundSpace);
430 return(0);
431 }
432
433
SetUsedColorSpace(FPXBaselineColorSpace colorSpace)434 void PSystemToolkit::SetUsedColorSpace (FPXBaselineColorSpace colorSpace)
435 {
436 // Convert the background color into the new used space
437 ConvertPixelBuffer ((unsigned char*)(&backgroundColor), 1, backgroundSpace, colorSpace);
438 backgroundSpace = colorSpace;
439 }
440
441
SetToBackground(ptr_Pixel buffer,long width,long height)442 void PSystemToolkit::SetToBackground(ptr_Pixel buffer, long width, long height)
443 {
444 register long i = width * height;
445
446 // Set a pixel buffer to background color
447 while (i--)
448 *buffer++ = backgroundColor;
449 }
450
451
SetColorConversion(Typ_ColorCode colorCode,Typ_ModeltoRGB modeltoRGB,Typ_RGBtoModel RGBtoModel)452 long PSystemToolkit::SetColorConversion (Typ_ColorCode colorCode, Typ_ModeltoRGB modeltoRGB,
453 Typ_RGBtoModel RGBtoModel)
454 {
455 register long status = 0;
456
457 if (colorCode == ColorCode_RGB)
458 status = 1;
459 else if ((modeltoRGB == NULL) || (RGBtoModel == NULL))
460 status = -1;
461 else {
462 fnctModeltoRGB[colorCode] = modeltoRGB;
463 fnctRGBtoModel[colorCode] = RGBtoModel;
464 }
465
466 return(status);
467 }
468
469
SetCompression(Typ_Compression newidCompressor,Typ_Compressor newCompressor,Typ_Decompressor newDecompressor)470 long PSystemToolkit::SetCompression (Typ_Compression newidCompressor, Typ_Compressor newCompressor, Typ_Decompressor newDecompressor)
471 {
472 register long status = 0;
473
474 if (newidCompressor == Compression_Other) {
475 if ((newCompressor == NULL) || (newDecompressor == NULL))
476 status = -1;
477 else {
478 fnctCompression = newCompressor;
479 fnctDecompression = newDecompressor;
480 compression = newidCompressor;
481 }
482 }
483 else
484 compression = newidCompressor;
485
486 return(status);
487 }
488
489
SetCompressionHandle(void * newCompressionHandle,long newHandleSize)490 long PSystemToolkit::SetCompressionHandle(void* newCompressionHandle, long newHandleSize)
491 {
492 register long status = 0;
493
494 if (newCompressionHandle == NULL)
495 status = -1;
496 else if (newHandleSize <= 0)
497 status = -2;
498 else {
499 compressionHandle = newCompressionHandle;
500 handleSize = newHandleSize;
501 }
502
503 return(status);
504 }
505
506
AddErrorToList(short message,OSErr err,FicNom file)507 void PSystemToolkit::AddErrorToList(short message, OSErr err, FicNom file)
508 {
509
510 if (PErrorsList::nbErr >= NB_MAX_ERRORS) {
511 // Make room for a new error by purging the first/oldest error from the list
512 PErrorsList* oldest = errorsList;
513 errorsList = oldest->nextError;
514 delete oldest;
515 }
516
517 if (PErrorsList::nbErr < NB_MAX_ERRORS) {
518 if (errorsList == NULL) {
519 errorsList = new PErrorsList(err, file);
520 if (errorsList==NULL) {
521 return;
522 }
523 PErrorsList::nbErr = 1;
524 }
525 if (errorsList) {
526 errorsList->AddErrorToList(err, file);
527 PErrorsList::nbErr++;
528 }
529 }
530 }
531
532
DeleteErrorsList()533 void PSystemToolkit::DeleteErrorsList()
534 {
535 if (errorsList != NULL) {
536 delete errorsList;
537 errorsList = NULL;
538 PErrorsList::nbErr = 0;
539 }
540 }
541
542
GetLastErrorFromList(FicNom file)543 OSErr PSystemToolkit::GetLastErrorFromList( FicNom file)
544 {
545 PErrorsList* last;
546 OSErr lastError = 0;
547
548 if (errorsList != NULL) {
549 last = errorsList;
550 while (last->nextError != NULL)
551 last = last->nextError;
552 }
553 return lastError;
554 }
555
556
SetManageOLE(Boolean theManageOLEOption)557 void PSystemToolkit::SetManageOLE(Boolean theManageOLEOption)
558 {
559 // Caution: If manageOLE was already true, that means that the current PSystemToolkit object has
560 // already initialized OLE himself and do need to uninit it at the end too.
561 if (manageOLE == FALSE)
562 manageOLE = theManageOLEOption;
563 }
564
565
GetManageOLE()566 Boolean PSystemToolkit::GetManageOLE()
567 {
568 return manageOLE;
569 }
570
571
572 // ------------------------------------------------------------------------------------------------
573 // Global Methods
574 // ------------------------------------------------------------------------------------------------
575
Toolkit_ConvertToMm(float x)576 float Toolkit_ConvertToMm (float x)
577 {
578 // Convert from user Unit to mm
579 return (x * GtheSystemToolkit->Ratio());
580 }
581
582
Toolkit_ConvertToUnit(float x)583 float Toolkit_ConvertToUnit (float x)
584 {
585 // Convert from mm to user Unit
586 return (x / GtheSystemToolkit->Ratio());
587 }
588
589
590 // Convert a pixel buffer into an interleaved buffer according to the interleaving option
Toolkit_Interleave(Pixel * source,long width,long height)591 Boolean Toolkit_Interleave (Pixel* source, long width, long height)
592 {
593 unsigned char *src;
594 unsigned char *dest, *dst_1, *dst_2, *dst_3, *dst_4;
595 unsigned int size;
596 long incline, incchannel;
597
598 if (GtheSystemToolkit->interleaving == Interleaving_Pixel) // Nothing to do�
599 return false;
600
601 // allocate an intermediate buffer
602 size = (unsigned int)(width*height*sizeof(Pixel));
603 FastAllocArray(dest,unsigned char,size);
604 if (dest == NULL)
605 return true;
606
607 // update parameters according to the interleaving option
608 switch (GtheSystemToolkit->interleaving) {
609 case Interleaving_Line:
610 incchannel = width;
611 incline = 3*width;
612 break;
613 case Interleaving_Channel:
614 incchannel = width*height;
615 incline = 0;
616 break;
617 case Interleaving_Pixel:
618 break;
619 }
620
621 // init pointers
622 dst_1 = dest;
623 dst_2 = dst_1 + incchannel;
624 dst_3 = dst_2 + incchannel;
625 dst_4 = dst_3 + incchannel;
626 src = (unsigned char*)(source);
627
628 // copy loop
629 for (long i = 0; i < height; i++) {
630 for (long j = 0; j < width; j++) {
631 *dst_1++ = *src++;
632 *dst_2++ = *src++;
633 *dst_3++ = *src++;
634 *dst_4++ = *src++;
635 }
636 dst_1 += incline;
637 dst_2 += incline;
638 dst_3 += incline;
639 dst_4 += incline;
640 }
641
642 // recopy buffer after interleaving
643 memcpy (source, dest, size);
644
645 // free intermediate buffer
646 FastDeleteArray(dest, unsigned char);
647
648 return false;
649 }
650
651
652 // Convert an interleaved buffer into a pixel buffer according to the interleaving option
Toolkit_UnInterleave(Pixel * source,Pixel * dest,long sourceWidth,long sourceHeight,long destWidth,long destHeight)653 Boolean Toolkit_UnInterleave (Pixel* source, Pixel* dest, long sourceWidth, long sourceHeight, long destWidth, long destHeight)
654 {
655 unsigned char *src_1, *src_2, *src_3, *src_4;
656 unsigned char *ptrDest;
657 long incline, incchannel;
658 long i, j;
659
660 if (GtheSystemToolkit->interleaving == Interleaving_Pixel) { // Nothing to do�
661 // recopy buffer after interleaving
662 for (i = 0; i <destHeight; i++, dest += destWidth, source += sourceWidth)
663 memcpy (dest, source, destWidth*sizeof(Pixel));
664 return false;
665 }
666
667 // update parameters according to the interleaving option
668 switch (GtheSystemToolkit->interleaving) {
669 case Interleaving_Line:
670 incchannel = sourceWidth;
671 incline = 3*sourceWidth + (sourceWidth - destWidth);
672 break;
673 case Interleaving_Channel:
674 incchannel = sourceWidth*sourceHeight;
675 incline = (sourceWidth-destWidth);
676 break;
677 default:
678 {
679 }
680 }
681
682 // init pointers
683 src_1 = (unsigned char*)(source);
684 src_2 = src_1 + incchannel;
685 src_3 = src_2 + incchannel;
686 src_4 = src_3 + incchannel;
687
688 // copy loop
689 ptrDest = (unsigned char*)(dest);
690 for (i = 0; i < destHeight; i++) {
691 for (j = 0; j < destWidth; j++) {
692 *ptrDest++ = *src_1++;
693 *ptrDest++ = *src_2++;
694 *ptrDest++ = *src_3++;
695 *ptrDest++ = *src_4++;
696 }
697 src_1 += incline;
698 src_2 += incline;
699 src_3 += incline;
700 src_4 += incline;
701 }
702 return false;
703 }
704
705 // Copy a rectangle in an image according to interleaving option :
706 // Caution : both buffers must be sorted in the right interleaved mode as issued by
707 // IVUE_ReadPage(), IVUE_ReadPageLine(), IVUE_ReadRectangle().
708 //
709 // "rectangle" of size "recHeight"x"rectWidth" is to be inserted in "image" of size
710 // "imageHeight"x"imageWidth" starting at location line "j0" & column "i0" in "image"
711
Toolkit_CopyInterleaved(Pixel * image,long imageWidth,long imageHeight,Pixel * rectangle,long rectWidth,long rectHeight,long i0,long j0)712 Boolean Toolkit_CopyInterleaved (Pixel* image, long imageWidth, long imageHeight,
713 Pixel* rectangle, long rectWidth, long rectHeight,
714 long i0, long j0)
715 {
716 unsigned int size;
717 unsigned char *ima[4];
718 unsigned char *rect[4];
719 long i, j, increct, incima;
720 long cropWidth = rectWidth;
721
722 // rectangle must be included in image
723 if ((i0 < 0) || (j0 < 0))
724 return true;
725 if ((i0 + rectWidth) > imageWidth)
726 cropWidth = imageWidth - i0;
727 if (((j0 + rectHeight) > imageHeight))
728 rectHeight = imageHeight - j0;
729
730 short plan = Toolkit_ActiveChannel();
731 switch (GtheSystemToolkit->interleaving) {
732
733 case Interleaving_Pixel:
734 image += (j0*imageWidth) + i0;
735 if (plan == ActiveChannel_All) {
736 // copy lines of pixels
737 size = (unsigned int)(cropWidth*sizeof(Pixel));
738 for (i = 0; i < rectHeight; i++) {
739 memcpy (image, rectangle, size);
740 image += imageWidth;
741 rectangle += rectWidth;
742 }
743 } else {
744 for (i = 0; i < rectHeight; i++) {
745 register unsigned char *src, *dst;
746 src = (unsigned char *)(rectangle) + plan;
747 dst = (unsigned char *)(image) + plan;
748 for (j = 0; j < cropWidth; j++, src += sizeof(Pixel), dst += sizeof(Pixel))
749 *dst = *src;
750 image += imageWidth;
751 rectangle += rectWidth;
752 }
753 }
754 break;
755
756 case Interleaving_Line:
757 // copy line by line on each channel
758 ima[0] = (unsigned char *)(image);
759 ima[0] += (j0*imageWidth*4) + i0;
760 rect[0] = (unsigned char *)(rectangle);
761
762 size = (unsigned int)(cropWidth);
763 increct = 4*rectWidth;
764 incima = 4*imageWidth;
765 if (plan == ActiveChannel_All) {
766 for (j = 1; j < 4; j++) {
767 ima[j] = ima[j-1] + imageWidth;
768 rect[j] = rect[j-1] + rectWidth;
769 }
770 for (i = 0; i < rectHeight; i++) {
771 for (j = 0; j < 4; j++) {
772 memcpy (ima[j], rect[j], size);
773 ima[j] += incima;
774 rect[j] += increct;
775 }
776 }
777 } else {
778 ima[plan] = ima[0] + plan * imageWidth;
779 rect[plan] = rect[0] + plan * rectWidth;
780 for (i = 0; i < rectHeight; i++) {
781 memcpy (ima[plan], rect[plan], size);
782 ima[plan] += incima;
783 rect[plan] += increct;
784 }
785 }
786 break;
787
788 case Interleaving_Channel: {
789 if (plan == ActiveChannel_All) {
790 // copy line by line on each channel
791 ima[0] = (unsigned char *)(image);
792 ima[0] += (j0*imageWidth) + i0;
793 rect[0] = (unsigned char *)(rectangle);
794 for (j = 1; j < 4; j++) {
795 ima[j] = ima[j-1] + (imageWidth*imageHeight);
796 rect[j] = rect[j-1] + (rectWidth*rectHeight);
797 }
798 size = (unsigned int)(cropWidth);
799 increct = rectWidth;
800 incima = imageWidth;
801 for (i = 0; i < rectHeight; i++) {
802 for (j = 0; j < 4; j++) {
803 memcpy (ima[j], rect[j], size);
804 ima[j] += incima;
805 rect[j] += increct;
806 }
807 }
808 } else {
809 // Copy line by line the chosen channel which is unique in rect and image
810 ima[0] = (unsigned char *)(image);
811 ima[0] += (j0*imageWidth) + i0;
812 rect[0] = (unsigned char *)(rectangle);
813 size = (unsigned int)(cropWidth);
814 increct = rectWidth;
815 incima = imageWidth;
816 for (i = 0; i < rectHeight; i++) {
817 memcpy (ima[0], rect[0], size);
818 ima[0] += incima;
819 rect[0] += increct;
820 }
821 }
822 break;
823 }
824 }
825
826 return false;
827 }
828
829 // Fast Log2 computation : using predefined table in PSystemToolkit for fast subimage level computation
Toolkit_Log2(long x)830 short Toolkit_Log2 (long x)
831 {
832 return (GtheSystemToolkit->tableLog2[x]);
833 }
834
835
Toolkit_Compression()836 Typ_Compression Toolkit_Compression()
837 {
838 return (GtheSystemToolkit->compression);
839 }
840
841
Toolkit_Convolution()842 Typ_Convolution Toolkit_Convolution()
843 {
844 return (GtheSystemToolkit->convolution);
845 }
846
847
Toolkit_WriteOnBackground()848 Boolean Toolkit_WriteOnBackground()
849 {
850 return (!(GtheSystemToolkit->preserveBackground));
851 }
852
853
Toolkit_BackgroundColor()854 Pixel Toolkit_BackgroundColor()
855 {
856 return (GtheSystemToolkit->backgroundColor);
857 }
858
859
Toolkit_FileColorCode()860 Typ_ColorCode Toolkit_FileColorCode()
861 {
862 return (GtheSystemToolkit->fileColorCode);
863 }
864
865
Toolkit_UserColorCode()866 Typ_ColorCode Toolkit_UserColorCode()
867 {
868 return (GtheSystemToolkit->userColorCode);
869 }
870
871
Toolkit_ModeltoRGB(Typ_ColorCode code)872 Typ_ModeltoRGB Toolkit_ModeltoRGB(Typ_ColorCode code)
873 {
874 return (GtheSystemToolkit->fnctModeltoRGB[code]);
875 }
876
877
Toolkit_RGBtoModel(Typ_ColorCode code)878 Typ_RGBtoModel Toolkit_RGBtoModel(Typ_ColorCode code)
879 {
880 return (GtheSystemToolkit->fnctRGBtoModel[code]);
881 }
882
883
Toolkit_TileWidth()884 long Toolkit_TileWidth()
885 {
886 return (GtheSystemToolkit->tileWidth);
887 }
888
889
Toolkit_ActiveChannel()890 short Toolkit_ActiveChannel()
891 {
892 return (GtheSystemToolkit->activeChannel);
893 }
894
895
Toolkit_IsLockedIVUE(IVUE * ivue)896 Boolean Toolkit_IsLockedIVUE (IVUE* ivue)
897 {
898 return (GtheSystemToolkit->IsLockedImage(ivue));
899 }
900
901