2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write FlashPIX Image Format %
20 % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/property.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/blob-private.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colormap.h"
51 #include "MagickCore/colorspace.h"
52 #include "MagickCore/colorspace-private.h"
53 #include "MagickCore/constitute.h"
54 #include "MagickCore/exception.h"
55 #include "MagickCore/exception-private.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/image-private.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/magick.h"
61 #include "MagickCore/memory_.h"
62 #include "MagickCore/monitor.h"
63 #include "MagickCore/monitor-private.h"
64 #include "MagickCore/pixel.h"
65 #include "MagickCore/pixel-accessor.h"
66 #include "MagickCore/property.h"
67 #include "MagickCore/quantum-private.h"
68 #include "MagickCore/static.h"
69 #include "MagickCore/string_.h"
70 #include "MagickCore/module.h"
71 #if defined(MAGICKCORE_FPX_DELEGATE)
72 #if !defined(vms) && !defined(macintosh) && !defined(MAGICKCORE_WINDOWS_SUPPORT)
79 #if defined(MAGICKCORE_FPX_DELEGATE)
83 static MagickBooleanType
84 WriteFPXImage(const ImageInfo *,Image *,ExceptionInfo *);
87 #if defined(MAGICKCORE_FPX_DELEGATE)
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 % R e a d F P X I m a g e %
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 % ReadFPXImage() reads a FlashPix image file and returns it. It
100 % allocates the memory necessary for the new Image structure and returns a
101 % pointer to the new image. This method was contributed by BillR@corbis.com.
103 % The format of the ReadFPXImage method is:
105 % Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
107 % A description of each parameter follows:
109 % o image_info: the image info.
111 % o exception: return any errors or warnings in this structure.
114 static Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
119 FPXImageComponentDesc
134 FPXSummaryInformation
153 register unsigned char
180 assert(image_info != (const ImageInfo *) NULL);
181 assert(image_info->signature == MagickSignature);
182 if (image_info->debug != MagickFalse)
183 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
184 image_info->filename);
185 assert(exception != (ExceptionInfo *) NULL);
186 assert(exception->signature == MagickSignature);
187 image=AcquireImage(image_info,exception);
188 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
189 if (status == MagickFalse)
191 image=DestroyImageList(image);
192 return((Image *) NULL);
194 (void) CloseBlob(image);
196 Initialize FPX toolkit.
198 fpx_status=FPX_InitSystem();
199 if (fpx_status != FPX_OK)
200 ThrowReaderException(CoderError,"UnableToInitializeFPXLibrary");
201 memory_limit=20000000;
202 fpx_status=FPX_SetToolkitMemoryLimit(&memory_limit);
203 if (fpx_status != FPX_OK)
206 ThrowReaderException(CoderError,"UnableToInitializeFPXLibrary");
210 flashpix=(FPXImageHandle *) NULL;
212 #if defined(macintosh)
216 FilenameToFSSpec(image->filename,&fsspec);
217 fpx_status=FPX_OpenImageByFilename((const FSSpec &) fsspec,(char *) NULL,
219 fpx_status=FPX_OpenImageByFilename(image->filename,(char *) NULL,
221 &width,&height,&tile_width,&tile_height,&colorspace,&flashpix);
223 if (fpx_status == FPX_LOW_MEMORY_ERROR)
226 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
228 if (fpx_status != FPX_OK)
231 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
233 image=DestroyImageList(image);
234 return((Image *) NULL);
236 if (colorspace.numberOfComponents == 0)
239 ThrowReaderException(CorruptImageError,"ImageTypeNotSupported");
241 if (image_info->view == (char *) NULL)
247 Get the aspect ratio.
249 aspect_ratio=(float) width/height;
250 fpx_status=FPX_GetImageResultAspectRatio(flashpix,&aspect_ratio);
251 if (fpx_status != FPX_OK)
252 ThrowReaderException(DelegateError,"UnableToReadAspectRatio");
253 if (width != (size_t) floor((aspect_ratio*height)+0.5))
256 fpx_status=FPX_GetSummaryInformation(flashpix,&summary_info);
257 if (fpx_status != FPX_OK)
260 ThrowReaderException(DelegateError,"UnableToReadSummaryInfo");
262 if (summary_info.title_valid)
263 if ((summary_info.title.length != 0) &&
264 (summary_info.title.ptr != (unsigned char *) NULL))
273 if (~summary_info.title.length >= (MaxTextExtent-1))
274 label=(char *) AcquireQuantumMemory(summary_info.title.length+
275 MaxTextExtent,sizeof(*label));
276 if (label == (char *) NULL)
279 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
281 (void) CopyMagickString(label,(char *) summary_info.title.ptr,
282 summary_info.title.length+1);
283 (void) SetImageProperty(image,"label",label,exception);
284 label=DestroyString(label);
286 if (summary_info.comments_valid)
287 if ((summary_info.comments.length != 0) &&
288 (summary_info.comments.ptr != (unsigned char *) NULL))
296 comments=(char *) NULL;
297 if (~summary_info.comments.length >= (MaxTextExtent-1))
298 comments=(char *) AcquireQuantumMemory(summary_info.comments.length+
299 MaxTextExtent,sizeof(*comments));
300 if (comments == (char *) NULL)
303 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
305 (void) CopyMagickString(comments,(char *) summary_info.comments.ptr,
306 summary_info.comments.length+1);
307 (void) SetImageProperty(image,"comment",comments,exception);
308 comments=DestroyString(comments);
311 Determine resolution by scene specification.
314 if (((width >> i) < tile_width) || ((height >> i) < tile_height))
317 if (image_info->number_scenes != 0)
318 while (scene > image_info->scene)
324 if (image_info->size != (char *) NULL)
325 while ((width > image->columns) || (height > image->rows))
332 image->columns=width;
334 if ((colorspace.numberOfComponents % 2) == 0)
335 image->alpha_trait=BlendPixelTrait;
336 if (colorspace.numberOfComponents == 1)
339 Create linear colormap.
341 if (AcquireImageColormap(image,MaxColormapSize,exception) == MagickFalse)
344 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
347 if (image_info->ping != MagickFalse)
349 (void) FPX_CloseImage(flashpix);
351 return(GetFirstImageInList(image));
353 status=SetImageExtent(image,image->columns,image->rows,exception);
354 if (status == MagickFalse)
355 return(DestroyImageList(image));
357 Allocate memory for the image and pixel buffer.
359 pixels=(unsigned char *) AcquireQuantumMemory(image->columns,(tile_height+
360 1UL)*colorspace.numberOfComponents*sizeof(*pixels));
361 if (pixels == (unsigned char *) NULL)
364 (void) FPX_CloseImage(flashpix);
365 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
368 Initialize FlashPix image description.
370 fpx_info.numberOfComponents=colorspace.numberOfComponents;
371 for (i=0; i < 4; i++)
373 fpx_info.components[i].myColorType.myDataType=DATA_TYPE_UNSIGNED_BYTE;
374 fpx_info.components[i].horzSubSampFactor=1;
375 fpx_info.components[i].vertSubSampFactor=1;
376 fpx_info.components[i].columnStride=fpx_info.numberOfComponents;
377 fpx_info.components[i].lineStride=image->columns*
378 fpx_info.components[i].columnStride;
379 fpx_info.components[i].theData=pixels+i;
381 fpx_info.components[0].myColorType.myColor=fpx_info.numberOfComponents > 2 ?
382 NIFRGB_R : MONOCHROME;
383 red_component=(&fpx_info.components[0]);
384 fpx_info.components[1].myColorType.myColor=fpx_info.numberOfComponents > 2 ?
386 green_component=(&fpx_info.components[1]);
387 fpx_info.components[2].myColorType.myColor=NIFRGB_B;
388 blue_component=(&fpx_info.components[2]);
389 fpx_info.components[3].myColorType.myColor=ALPHA;
390 alpha_component=(&fpx_info.components[fpx_info.numberOfComponents-1]);
391 FPX_SetResampleMethod(FPX_LINEAR_INTERPOLATION);
393 Initialize image pixels.
395 for (y=0; y < (ssize_t) image->rows; y++)
397 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
398 if (q == (Quantum *) NULL)
400 if ((y % tile_height) == 0)
403 Read FPX image tile (with or without viewing affine)..
405 if (image_info->view != (char *) NULL)
406 fpx_status=FPX_ReadImageRectangle(flashpix,0,y,image->columns,y+
407 tile_height-1,scene,&fpx_info);
409 fpx_status=FPX_ReadImageTransformRectangle(flashpix,0.0F,
410 (float) y/image->rows,(float) image->columns/image->rows,
411 (float) (y+tile_height-1)/image->rows,(ssize_t) image->columns,
412 (ssize_t) tile_height,&fpx_info);
413 if (fpx_status == FPX_LOW_MEMORY_ERROR)
415 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
416 (void) FPX_CloseImage(flashpix);
418 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
422 Transfer a FPX pixels.
424 r=red_component->theData+(y % tile_height)*red_component->lineStride;
425 g=green_component->theData+(y % tile_height)*green_component->lineStride;
426 b=blue_component->theData+(y % tile_height)*blue_component->lineStride;
427 a=alpha_component->theData+(y % tile_height)*alpha_component->lineStride;
428 for (x=0; x < (ssize_t) image->columns; x++)
430 if (fpx_info.numberOfComponents > 2)
432 SetPixelRed(image,ScaleCharToQuantum(*r),q);
433 SetPixelGreen(image,ScaleCharToQuantum(*g),q);
434 SetPixelBlue(image,ScaleCharToQuantum(*b),q);
438 index=ScaleCharToQuantum(*r);
439 SetPixelBlack(image,index,q);
440 SetPixelRed(image,index,q);
441 SetPixelGreen(image,index,q);
442 SetPixelBlue(image,index,q);
444 SetPixelAlpha(image,OpaqueAlpha,q);
445 if (image->alpha_trait != UndefinedPixelTrait)
446 SetPixelAlpha(image,ScaleCharToQuantum(*a),q);
447 q+=GetPixelChannels(image);
448 r+=red_component->columnStride;
449 g+=green_component->columnStride;
450 b+=blue_component->columnStride;
451 a+=alpha_component->columnStride;
453 if (SyncAuthenticPixels(image,exception) == MagickFalse)
455 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
457 if (status == MagickFalse)
460 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
461 (void) FPX_CloseImage(flashpix);
463 return(GetFirstImageInList(image));
468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 % R e g i s t e r F P X I m a g e %
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 % RegisterFPXImage() adds attributes for the FPX image format to
479 % the list of supported formats. The attributes include the image format
480 % tag, a method to read and/or write the format, whether the format
481 % supports the saving of more than one frame to the same file or blob,
482 % whether the format supports native in-memory I/O, and a brief
483 % description of the format.
485 % The format of the RegisterFPXImage method is:
487 % size_t RegisterFPXImage(void)
490 ModuleExport size_t RegisterFPXImage(void)
495 entry=SetMagickInfo("FPX");
496 #if defined(MAGICKCORE_FPX_DELEGATE)
497 entry->decoder=(DecodeImageHandler *) ReadFPXImage;
498 entry->encoder=(EncodeImageHandler *) WriteFPXImage;
500 entry->flags^=Adjoin;
501 entry->flags|=SeekableStream;
502 entry->flags^=BlobSupport;
503 entry->description=ConstantString("FlashPix Format");
504 entry->module=ConstantString("FPX");
505 (void) RegisterMagickInfo(entry);
506 return(MagickImageCoderSignature);
510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
514 % U n r e g i s t e r F P X I m a g e %
518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520 % UnregisterFPXImage() removes format registrations made by the
521 % FPX module from the list of supported formats.
523 % The format of the UnregisterFPXImage method is:
525 % UnregisterFPXImage(void)
528 ModuleExport void UnregisterFPXImage(void)
530 (void) UnregisterMagickInfo("FPX");
533 #if defined(MAGICKCORE_FPX_DELEGATE)
535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 % W r i t e F P X I m a g e %
543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
545 % WriteFPXImage() writes an image in the FlashPix image format. This
546 % method was contributed by BillR@corbis.com.
548 % The format of the WriteFPXImage method is:
550 % MagickBooleanType WriteFPXImage(const ImageInfo *image_info,
551 % Image *image,ExceptionInfo *exception)
553 % A description of each parameter follows.
555 % o image_info: the image info.
557 % o image: The image.
559 % o exception: return any errors or warnings in this structure.
563 static void ColorTwistMultiply(FPXColorTwistMatrix first,
564 FPXColorTwistMatrix second,FPXColorTwistMatrix *color_twist)
569 assert(color_twist != (FPXColorTwistMatrix *) NULL);
570 color_twist->byy=(first.byy*second.byy)+(first.byc1*second.bc1y)+
571 (first.byc2*second.bc2y)+(first.dummy1_zero*second.dummy4_zero);
572 color_twist->byc1=(first.byy*second.byc1)+(first.byc1*second.bc1c1)+
573 (first.byc2*second.bc2c1)+(first.dummy1_zero*second.dummy5_zero);
574 color_twist->byc2=(first.byy*second.byc2)+(first.byc1*second.bc1c2)+
575 (first.byc2*second.bc2c2)+(first.dummy1_zero*second.dummy6_zero);
576 color_twist->dummy1_zero=(first.byy*second.dummy1_zero)+
577 (first.byc1*second.dummy2_zero)+(first.byc2*second.dummy3_zero)+
578 (first.dummy1_zero*second.dummy7_one);
579 color_twist->bc1y=(first.bc1y*second.byy)+(first.bc1c1*second.bc1y)+
580 (first.bc1c2*second.bc2y)+(first.dummy2_zero*second.dummy4_zero);
581 color_twist->bc1c1=(first.bc1y*second.byc1)+(first.bc1c1*second.bc1c1)+
582 (first.bc1c2*second.bc2c1)+(first.dummy2_zero*second.dummy5_zero);
583 color_twist->bc1c2=(first.bc1y*second.byc2)+(first.bc1c1*second.bc1c2)+
584 (first.bc1c2*second.bc2c2)+(first.dummy2_zero*second.dummy6_zero);
585 color_twist->dummy2_zero=(first.bc1y*second.dummy1_zero)+
586 (first.bc1c1*second.dummy2_zero)+(first.bc1c2*second.dummy3_zero)+
587 (first.dummy2_zero*second.dummy7_one);
588 color_twist->bc2y=(first.bc2y*second.byy)+(first.bc2c1*second.bc1y)+
589 (first.bc2c2*second.bc2y)+(first.dummy3_zero*second.dummy4_zero);
590 color_twist->bc2c1=(first.bc2y*second.byc1)+(first.bc2c1*second.bc1c1)+
591 (first.bc2c2*second.bc2c1)+(first.dummy3_zero*second.dummy5_zero);
592 color_twist->bc2c2=(first.bc2y*second.byc2)+(first.bc2c1*second.bc1c2)+
593 (first.bc2c2*second.bc2c2)+(first.dummy3_zero*second.dummy6_zero);
594 color_twist->dummy3_zero=(first.bc2y*second.dummy1_zero)+
595 (first.bc2c1*second.dummy2_zero)+(first.bc2c2*second.dummy3_zero)+
596 (first.dummy3_zero*second.dummy7_one);
597 color_twist->dummy4_zero=(first.dummy4_zero*second.byy)+
598 (first.dummy5_zero*second.bc1y)+(first.dummy6_zero*second.bc2y)+
599 (first.dummy7_one*second.dummy4_zero);
600 color_twist->dummy5_zero=(first.dummy4_zero*second.byc1)+
601 (first.dummy5_zero*second.bc1c1)+(first.dummy6_zero*second.bc2c1)+
602 (first.dummy7_one*second.dummy5_zero);
603 color_twist->dummy6_zero=(first.dummy4_zero*second.byc2)+
604 (first.dummy5_zero*second.bc1c2)+(first.dummy6_zero*second.bc2c2)+
605 (first.dummy7_one*second.dummy6_zero);
606 color_twist->dummy7_one=(first.dummy4_zero*second.dummy1_zero)+
607 (first.dummy5_zero*second.dummy2_zero)+
608 (first.dummy6_zero*second.dummy3_zero)+(first.dummy7_one*second.dummy7_one);
611 static void SetBrightness(double brightness,FPXColorTwistMatrix *color_twist)
618 Set image brightness in color twist matrix.
620 assert(color_twist != (FPXColorTwistMatrix *) NULL);
621 brightness=sqrt((double) brightness);
622 effect.byy=brightness;
625 effect.dummy1_zero=0.0;
627 effect.bc1c1=brightness;
629 effect.dummy2_zero=0.0;
632 effect.bc2c2=brightness;
633 effect.dummy3_zero=0.0;
634 effect.dummy4_zero=0.0;
635 effect.dummy5_zero=0.0;
636 effect.dummy6_zero=0.0;
637 effect.dummy7_one=1.0;
638 ColorTwistMultiply(*color_twist,effect,&result);
642 static void SetColorBalance(double red,double green,double blue,
643 FPXColorTwistMatrix *color_twist)
654 Set image color balance in color twist matrix.
656 assert(color_twist != (FPXColorTwistMatrix *) NULL);
657 red=sqrt((double) red)-1.0;
658 green=sqrt((double) green)-1.0;
659 blue=sqrt((double) blue)-1.0;
662 red_effect.byc2=0.299*red;
663 red_effect.dummy1_zero=0.0;
664 red_effect.bc1y=(-0.299)*red;
665 red_effect.bc1c1=1.0-0.299*red;
666 red_effect.bc1c2=(-0.299)*red;
667 red_effect.dummy2_zero=0.0;
668 red_effect.bc2y=0.701*red;
669 red_effect.bc2c1=0.0;
670 red_effect.bc2c2=1.0+0.402*red;
671 red_effect.dummy3_zero=0.0;
672 red_effect.dummy4_zero=0.0;
673 red_effect.dummy5_zero=0.0;
674 red_effect.dummy6_zero=0.0;
675 red_effect.dummy7_one=1.0;
676 green_effect.byy=1.0;
677 green_effect.byc1=(-0.114)*green;
678 green_effect.byc2=(-0.299)*green;
679 green_effect.dummy1_zero=0.0;
680 green_effect.bc1y=(-0.587)*green;
681 green_effect.bc1c1=1.0-0.473*green;
682 green_effect.bc1c2=0.299*green;
683 green_effect.dummy2_zero=0.0;
684 green_effect.bc2y=(-0.587)*green;
685 green_effect.bc2c1=0.114*green;
686 green_effect.bc2c2=1.0-0.288*green;
687 green_effect.dummy3_zero=0.0;
688 green_effect.dummy4_zero=0.0;
689 green_effect.dummy5_zero=0.0;
690 green_effect.dummy6_zero=0.0;
691 green_effect.dummy7_one=1.0;
693 blue_effect.byc1=0.114*blue;
694 blue_effect.byc2=0.0;
695 blue_effect.dummy1_zero=0.0;
696 blue_effect.bc1y=0.886*blue;
697 blue_effect.bc1c1=1.0+0.772*blue;
698 blue_effect.bc1c2=0.0;
699 blue_effect.dummy2_zero=0.0;
700 blue_effect.bc2y=(-0.114)*blue;
701 blue_effect.bc2c1=(-0.114)*blue;
702 blue_effect.bc2c2=1.0-0.114*blue;
703 blue_effect.dummy3_zero=0.0;
704 blue_effect.dummy4_zero=0.0;
705 blue_effect.dummy5_zero=0.0;
706 blue_effect.dummy6_zero=0.0;
707 blue_effect.dummy7_one=1.0;
708 ColorTwistMultiply(red_effect,green_effect,&rg_effect);
709 ColorTwistMultiply(rg_effect,blue_effect,&rgb_effect);
710 ColorTwistMultiply(*color_twist,rgb_effect,&result);
714 static void SetSaturation(double saturation,FPXColorTwistMatrix *color_twist)
721 Set image saturation in color twist matrix.
723 assert(color_twist != (FPXColorTwistMatrix *) NULL);
727 effect.dummy1_zero=0.0;
729 effect.bc1c1=saturation;
731 effect.dummy2_zero=0.0;
734 effect.bc2c2=saturation;
735 effect.dummy3_zero=0.0;
736 effect.dummy4_zero=0.0;
737 effect.dummy5_zero=0.0;
738 effect.dummy6_zero=0.0;
739 effect.dummy7_one=1.0;
740 ColorTwistMultiply(*color_twist,effect,&result);
744 static MagickBooleanType WriteFPXImage(const ImageInfo *image_info,Image *image,
745 ExceptionInfo *exception)
755 { NIFRGB_R, DATA_TYPE_UNSIGNED_BYTE },
756 { NIFRGB_G, DATA_TYPE_UNSIGNED_BYTE },
757 { NIFRGB_B, DATA_TYPE_UNSIGNED_BYTE },
758 { ALPHA, DATA_TYPE_UNSIGNED_BYTE }
778 FPXSummaryInformation
790 register const Quantum
813 assert(image_info != (const ImageInfo *) NULL);
814 assert(image_info->signature == MagickSignature);
815 assert(image != (Image *) NULL);
816 assert(image->signature == MagickSignature);
817 if (image->debug != MagickFalse)
818 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
819 assert(exception != (ExceptionInfo *) NULL);
820 assert(exception->signature == MagickSignature);
821 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
822 if (status == MagickFalse)
824 (void) TransformImageColorspace(image,sRGBColorspace,exception);
825 (void) CloseBlob(image);
827 Initialize FPX toolkit.
830 memory_limit=20000000;
831 fpx_status=FPX_SetToolkitMemoryLimit(&memory_limit);
832 if (fpx_status != FPX_OK)
833 ThrowWriterException(DelegateError,"UnableToInitializeFPXLibrary");
836 colorspace.numberOfComponents=3;
837 if (image->alpha_trait != UndefinedPixelTrait)
838 colorspace.numberOfComponents=4;
839 if ((image_info->type != TrueColorType) &&
840 (IsImageGray(image,exception) != MagickFalse))
842 colorspace.numberOfComponents=1;
843 colorspace.theComponents[0].myColor=MONOCHROME;
845 background_color.color1_value=0;
846 background_color.color2_value=0;
847 background_color.color3_value=0;
848 background_color.color4_value=0;
850 if (image->compression == JPEGCompression)
851 compression=JPEG_UNSPECIFIED;
852 if (image_info->compression == JPEGCompression)
853 compression=JPEG_UNSPECIFIED;
855 #if defined(macintosh)
859 FilenameToFSSpec(filename,&fsspec);
860 fpx_status=FPX_CreateImageByFilename((const FSSpec &) fsspec,image->columns,
862 fpx_status=FPX_CreateImageByFilename(image->filename,image->columns,
864 image->rows,tile_width,tile_height,colorspace,background_color,
865 compression,&flashpix);
867 if (fpx_status != FPX_OK)
869 if (compression == JPEG_UNSPECIFIED)
872 Initialize the compression by quality for the entire image.
874 fpx_status=FPX_SetJPEGCompression(flashpix,(unsigned short)
875 image->quality == UndefinedCompressionQuality ? 75 : image->quality);
876 if (fpx_status != FPX_OK)
877 ThrowWriterException(DelegateError,"UnableToSetJPEGLevel");
880 Set image summary info.
882 summary_info.title_valid=MagickFalse;
883 summary_info.subject_valid=MagickFalse;
884 summary_info.author_valid=MagickFalse;
885 summary_info.comments_valid=MagickFalse;
886 summary_info.keywords_valid=MagickFalse;
887 summary_info.OLEtemplate_valid=MagickFalse;
888 summary_info.last_author_valid=MagickFalse;
889 summary_info.rev_number_valid=MagickFalse;
890 summary_info.edit_time_valid=MagickFalse;
891 summary_info.last_printed_valid=MagickFalse;
892 summary_info.create_dtm_valid=MagickFalse;
893 summary_info.last_save_dtm_valid=MagickFalse;
894 summary_info.page_count_valid=MagickFalse;
895 summary_info.word_count_valid=MagickFalse;
896 summary_info.char_count_valid=MagickFalse;
897 summary_info.thumbnail_valid=MagickFalse;
898 summary_info.appname_valid=MagickFalse;
899 summary_info.security_valid=MagickFalse;
900 summary_info.title.ptr=(unsigned char *) NULL;
901 label=GetImageProperty(image,"label",exception);
902 if (label != (const char *) NULL)
907 summary_info.title_valid=MagickTrue;
908 length=strlen(label);
909 summary_info.title.length=length;
910 if (~length >= (MaxTextExtent-1))
911 summary_info.title.ptr=(unsigned char *) AcquireQuantumMemory(
912 length+MaxTextExtent,sizeof(*summary_info.title.ptr));
913 if (summary_info.title.ptr == (unsigned char *) NULL)
914 ThrowWriterException(DelegateError,"UnableToSetImageTitle");
915 (void) CopyMagickString((char *) summary_info.title.ptr,label,
918 comment=GetImageProperty(image,"comment",exception);
919 if (comment != (const char *) NULL)
924 summary_info.comments_valid=MagickTrue;
925 summary_info.comments.ptr=(unsigned char *) AcquireString(comment);
926 summary_info.comments.length=strlen(comment);
928 fpx_status=FPX_SetSummaryInformation(flashpix,&summary_info);
929 if (fpx_status != FPX_OK)
930 ThrowWriterException(DelegateError,"UnableToSetSummaryInfo");
932 Initialize FlashPix image description.
934 quantum_info=AcquireQuantumInfo(image_info,image);
935 if (quantum_info == (QuantumInfo *) NULL)
936 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
937 pixels=GetQuantumPixels(quantum_info);
938 fpx_info.numberOfComponents=colorspace.numberOfComponents;
939 for (i=0; i < (ssize_t) fpx_info.numberOfComponents; i++)
941 fpx_info.components[i].myColorType.myDataType=DATA_TYPE_UNSIGNED_BYTE;
942 fpx_info.components[i].horzSubSampFactor=1;
943 fpx_info.components[i].vertSubSampFactor=1;
944 fpx_info.components[i].columnStride=fpx_info.numberOfComponents;
945 fpx_info.components[i].lineStride=
946 image->columns*fpx_info.components[i].columnStride;
947 fpx_info.components[i].theData=pixels+i;
949 fpx_info.components[0].myColorType.myColor=fpx_info.numberOfComponents != 1 ?
950 NIFRGB_R : MONOCHROME;
951 fpx_info.components[1].myColorType.myColor=NIFRGB_G;
952 fpx_info.components[2].myColorType.myColor=NIFRGB_B;
953 fpx_info.components[3].myColorType.myColor=ALPHA;
957 quantum_type=RGBQuantum;
958 if (image->alpha_trait != UndefinedPixelTrait)
959 quantum_type=RGBAQuantum;
960 if (fpx_info.numberOfComponents == 1)
961 quantum_type=GrayQuantum;
962 for (y=0; y < (ssize_t) image->rows; y++)
964 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
965 if (p == (const Quantum *) NULL)
967 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
968 quantum_type,pixels,exception);
969 fpx_status=FPX_WriteImageLine(flashpix,&fpx_info);
970 if (fpx_status != FPX_OK)
972 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
974 if (status == MagickFalse)
977 quantum_info=DestroyQuantumInfo(quantum_info);
978 if (image_info->view != (char *) NULL)
986 FPXContrastAdjustment
1007 Initialize default viewing parameters.
1010 contrast_valid=MagickTrue;
1011 color_twist.byy=1.0;
1012 color_twist.byc1=0.0;
1013 color_twist.byc2=0.0;
1014 color_twist.dummy1_zero=0.0;
1015 color_twist.bc1y=0.0;
1016 color_twist.bc1c1=1.0;
1017 color_twist.bc1c2=0.0;
1018 color_twist.dummy2_zero=0.0;
1019 color_twist.bc2y=0.0;
1020 color_twist.bc2c1=0.0;
1021 color_twist.bc2c2=1.0;
1022 color_twist.dummy3_zero=0.0;
1023 color_twist.dummy4_zero=0.0;
1024 color_twist.dummy5_zero=0.0;
1025 color_twist.dummy6_zero=0.0;
1026 color_twist.dummy7_one=1.0;
1027 color_twist_valid=MagickTrue;
1029 sharpen_valid=MagickTrue;
1030 aspect_ratio=(double) image->columns/image->rows;
1031 aspect_ratio_valid=MagickTrue;
1032 view_rect.left=(float) 0.1;
1033 view_rect.width=aspect_ratio-0.2;
1034 view_rect.top=(float) 0.1;
1035 view_rect.height=(float) 0.8; /* 1.0-0.2 */
1036 view_rect_valid=MagickTrue;
1053 affine_valid=MagickTrue;
1059 SetBrightness(0.5,&color_twist);
1060 SetSaturation(0.5,&color_twist);
1061 SetColorBalance(0.5,1.0,1.0,&color_twist);
1062 color_twist_valid=MagickTrue;
1064 if (affine_valid != MagickFalse)
1066 fpx_status=FPX_SetImageAffineMatrix(flashpix,&affine);
1067 if (fpx_status != FPX_OK)
1068 ThrowWriterException(DelegateError,"UnableToSetAffineMatrix");
1070 if (aspect_ratio_valid != MagickFalse)
1072 fpx_status=FPX_SetImageResultAspectRatio(flashpix,&aspect_ratio);
1073 if (fpx_status != FPX_OK)
1074 ThrowWriterException(DelegateError,"UnableToSetAspectRatio");
1076 if (color_twist_valid != MagickFalse)
1078 fpx_status=FPX_SetImageColorTwistMatrix(flashpix,&color_twist);
1079 if (fpx_status != FPX_OK)
1080 ThrowWriterException(DelegateError,"UnableToSetColorTwist");
1082 if (contrast_valid != MagickFalse)
1084 fpx_status=FPX_SetImageContrastAdjustment(flashpix,&contrast);
1085 if (fpx_status != FPX_OK)
1086 ThrowWriterException(DelegateError,"UnableToSetContrast");
1088 if (sharpen_valid != MagickFalse)
1090 fpx_status=FPX_SetImageFilteringValue(flashpix,&sharpen);
1091 if (fpx_status != FPX_OK)
1092 ThrowWriterException(DelegateError,"UnableToSetFilteringValue");
1094 if (view_rect_valid != MagickFalse)
1096 fpx_status=FPX_SetImageROI(flashpix,&view_rect);
1097 if (fpx_status != FPX_OK)
1098 ThrowWriterException(DelegateError,"UnableToSetRegionOfInterest");
1101 (void) FPX_CloseImage(flashpix);