2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write FlashPIX Image Format %
20 % Copyright 1999-2011 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/property.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colorspace.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/geometry.h"
54 #include "MagickCore/image.h"
55 #include "MagickCore/image-private.h"
56 #include "MagickCore/list.h"
57 #include "MagickCore/magick.h"
58 #include "MagickCore/memory_.h"
59 #include "MagickCore/monitor.h"
60 #include "MagickCore/monitor-private.h"
61 #include "MagickCore/pixel.h"
62 #include "MagickCore/quantum-private.h"
63 #include "MagickCore/static.h"
64 #include "MagickCore/string_.h"
65 #include "MagickCore/module.h"
66 #if defined(MAGICKCORE_FPX_DELEGATE)
67 #if !defined(vms) && !defined(macintosh) && !defined(MAGICKCORE_WINDOWS_SUPPORT)
74 #if defined(MAGICKCORE_FPX_DELEGATE)
78 static MagickBooleanType
79 WriteFPXImage(const ImageInfo *,Image *);
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 % IsFPX() returns MagickTrue if the image format type, identified by the
94 % magick string, is FPX.
96 % The format of the IsFPX method is:
98 % MagickBooleanType IsFPX(const unsigned char *magick,const size_t length)
100 % A description of each parameter follows:
102 % o magick: compare image format pattern against these bytes.
104 % o length: Specifies the length of the magick string.
107 static MagickBooleanType IsFPX(const unsigned char *magick,const size_t length)
111 if (memcmp(magick,"\320\317\021\340",4) == 0)
116 #if defined(MAGICKCORE_FPX_DELEGATE)
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 % R e a d F P X I m a g e %
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 % ReadFPXImage() reads a FlashPix image file and returns it. It
129 % allocates the memory necessary for the new Image structure and returns a
130 % pointer to the new image. This method was contributed by BillR@corbis.com.
132 % The format of the ReadFPXImage method is:
134 % Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
136 % A description of each parameter follows:
138 % o image_info: the image info.
140 % o exception: return any errors or warnings in this structure.
143 static Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
148 FPXImageComponentDesc
163 FPXSummaryInformation
182 register unsigned char
209 assert(image_info != (const ImageInfo *) NULL);
210 assert(image_info->signature == MagickSignature);
211 if (image_info->debug != MagickFalse)
212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
213 image_info->filename);
214 assert(exception != (ExceptionInfo *) NULL);
215 assert(exception->signature == MagickSignature);
216 image=AcquireImage(image_info);
217 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
218 if (status == MagickFalse)
220 image=DestroyImageList(image);
221 return((Image *) NULL);
223 (void) CloseBlob(image);
225 Initialize FPX toolkit.
227 fpx_status=FPX_InitSystem();
228 if (fpx_status != FPX_OK)
229 ThrowReaderException(CoderError,"UnableToInitializeFPXLibrary");
230 memory_limit=20000000;
231 fpx_status=FPX_SetToolkitMemoryLimit(&memory_limit);
232 if (fpx_status != FPX_OK)
235 ThrowReaderException(CoderError,"UnableToInitializeFPXLibrary");
239 flashpix=(FPXImageHandle *) NULL;
241 #if defined(macintosh)
245 FilenameToFSSpec(image->filename,&fsspec);
246 fpx_status=FPX_OpenImageByFilename((const FSSpec &) fsspec,(char *) NULL,
248 fpx_status=FPX_OpenImageByFilename(image->filename,(char *) NULL,
250 &width,&height,&tile_width,&tile_height,&colorspace,&flashpix);
252 if (fpx_status == FPX_LOW_MEMORY_ERROR)
255 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
257 if (fpx_status != FPX_OK)
260 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
262 image=DestroyImageList(image);
263 return((Image *) NULL);
265 if (colorspace.numberOfComponents == 0)
268 ThrowReaderException(CorruptImageError,"ImageTypeNotSupported");
270 if (image_info->view == (char *) NULL)
276 Get the aspect ratio.
278 aspect_ratio=(float) width/height;
279 fpx_status=FPX_GetImageResultAspectRatio(flashpix,&aspect_ratio);
280 if (fpx_status != FPX_OK)
281 ThrowReaderException(DelegateError,"UnableToReadAspectRatio");
282 if (width != (size_t) floor((aspect_ratio*height)+0.5))
285 fpx_status=FPX_GetSummaryInformation(flashpix,&summary_info);
286 if (fpx_status != FPX_OK)
289 ThrowReaderException(DelegateError,"UnableToReadSummaryInfo");
291 if (summary_info.title_valid)
292 if ((summary_info.title.length != 0) &&
293 (summary_info.title.ptr != (unsigned char *) NULL))
302 if (~summary_info.title.length >= (MaxTextExtent-1))
303 label=(char *) AcquireQuantumMemory(summary_info.title.length+
304 MaxTextExtent,sizeof(*label));
305 if (label == (char *) NULL)
308 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
310 (void) CopyMagickString(label,(char *) summary_info.title.ptr,
311 summary_info.title.length+1);
312 (void) SetImageProperty(image,"label",label);
313 label=DestroyString(label);
315 if (summary_info.comments_valid)
316 if ((summary_info.comments.length != 0) &&
317 (summary_info.comments.ptr != (unsigned char *) NULL))
325 comments=(char *) NULL;
326 if (~summary_info.comments.length >= (MaxTextExtent-1))
327 comments=(char *) AcquireQuantumMemory(summary_info.comments.length+
328 MaxTextExtent,sizeof(*comments));
329 if (comments == (char *) NULL)
332 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
334 (void) CopyMagickString(comments,(char *) summary_info.comments.ptr,
335 summary_info.comments.length+1);
336 (void) SetImageProperty(image,"comment",comments);
337 comments=DestroyString(comments);
340 Determine resolution by scene specification.
343 if (((width >> i) < tile_width) || ((height >> i) < tile_height))
346 if (image_info->number_scenes != 0)
347 while (scene > image_info->scene)
353 if (image_info->size != (char *) NULL)
354 while ((width > image->columns) || (height > image->rows))
361 image->columns=width;
363 if ((colorspace.numberOfComponents % 2) == 0)
364 image->matte=MagickTrue;
365 if (colorspace.numberOfComponents == 1)
368 Create linear colormap.
370 if (AcquireImageColormap(image,MaxColormapSize) == MagickFalse)
373 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
376 if (image_info->ping != MagickFalse)
378 (void) FPX_CloseImage(flashpix);
380 return(GetFirstImageInList(image));
383 Allocate memory for the image and pixel buffer.
385 pixels=(unsigned char *) AcquireQuantumMemory(image->columns,(tile_height+
386 1UL)*colorspace.numberOfComponents*sizeof(*pixels));
387 if (pixels == (unsigned char *) NULL)
390 (void) FPX_CloseImage(flashpix);
391 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
394 Initialize FlashPix image description.
396 fpx_info.numberOfComponents=colorspace.numberOfComponents;
397 for (i=0; i < 4; i++)
399 fpx_info.components[i].myColorType.myDataType=DATA_TYPE_UNSIGNED_BYTE;
400 fpx_info.components[i].horzSubSampFactor=1;
401 fpx_info.components[i].vertSubSampFactor=1;
402 fpx_info.components[i].columnStride=fpx_info.numberOfComponents;
403 fpx_info.components[i].lineStride=image->columns*
404 fpx_info.components[i].columnStride;
405 fpx_info.components[i].theData=pixels+i;
407 fpx_info.components[0].myColorType.myColor=fpx_info.numberOfComponents > 2 ?
408 NIFRGB_R : MONOCHROME;
409 red_component=(&fpx_info.components[0]);
410 fpx_info.components[1].myColorType.myColor=fpx_info.numberOfComponents > 2 ?
412 green_component=(&fpx_info.components[1]);
413 fpx_info.components[2].myColorType.myColor=NIFRGB_B;
414 blue_component=(&fpx_info.components[2]);
415 fpx_info.components[3].myColorType.myColor=ALPHA;
416 alpha_component=(&fpx_info.components[fpx_info.numberOfComponents-1]);
417 FPX_SetResampleMethod(FPX_LINEAR_INTERPOLATION);
419 Initialize image pixels.
421 for (y=0; y < (ssize_t) image->rows; y++)
423 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
424 if (q == (const Quantum *) NULL)
426 if ((y % tile_height) == 0)
429 Read FPX image tile (with or without viewing affine)..
431 if (image_info->view != (char *) NULL)
432 fpx_status=FPX_ReadImageRectangle(flashpix,0,y,image->columns,y+
433 tile_height-1,scene,&fpx_info);
435 fpx_status=FPX_ReadImageTransformRectangle(flashpix,0.0F,
436 (float) y/image->rows,(float) image->columns/image->rows,
437 (float) (y+tile_height-1)/image->rows,(ssize_t) image->columns,
438 (ssize_t) tile_height,&fpx_info);
439 if (fpx_status == FPX_LOW_MEMORY_ERROR)
441 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
442 (void) FPX_CloseImage(flashpix);
444 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
448 Transfer a FPX pixels.
450 r=red_component->theData+(y % tile_height)*red_component->lineStride;
451 g=green_component->theData+(y % tile_height)*green_component->lineStride;
452 b=blue_component->theData+(y % tile_height)*blue_component->lineStride;
453 a=alpha_component->theData+(y % tile_height)*alpha_component->lineStride;
454 for (x=0; x < (ssize_t) image->columns; x++)
456 if (fpx_info.numberOfComponents > 2)
458 SetPixelRed(image,ScaleCharToQuantum(*r),q);
459 SetPixelGreen(image,ScaleCharToQuantum(*g),q);
460 SetPixelBlue(image,ScaleCharToQuantum(*b),q);
464 index=ScaleCharToQuantum(*r);
465 SetPixelBlack(image,index,q);
466 SetPixelRed(image,index,q);
467 SetPixelGreen(image,index,q);
468 SetPixelBlue(image,index,q);
470 SetPixelAlpha(image,OpaqueAlpha,q);
471 if (image->matte != MagickFalse)
472 SetPixelAlpha(image,ScaleCharToQuantum(*a),q);
473 q+=GetPixelChannels(image);
474 r+=red_component->columnStride;
475 g+=green_component->columnStride;
476 b+=blue_component->columnStride;
477 a+=alpha_component->columnStride;
479 if (SyncAuthenticPixels(image,exception) == MagickFalse)
481 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
483 if (status == MagickFalse)
486 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
487 (void) FPX_CloseImage(flashpix);
489 return(GetFirstImageInList(image));
494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 % R e g i s t e r F P X I m a g e %
502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
504 % RegisterFPXImage() adds attributes for the FPX image format to
505 % the list of supported formats. The attributes include the image format
506 % tag, a method to read and/or write the format, whether the format
507 % supports the saving of more than one frame to the same file or blob,
508 % whether the format supports native in-memory I/O, and a brief
509 % description of the format.
511 % The format of the RegisterFPXImage method is:
513 % size_t RegisterFPXImage(void)
516 ModuleExport size_t RegisterFPXImage(void)
521 entry=SetMagickInfo("FPX");
522 #if defined(MAGICKCORE_FPX_DELEGATE)
523 entry->decoder=(DecodeImageHandler *) ReadFPXImage;
524 entry->encoder=(EncodeImageHandler *) WriteFPXImage;
526 entry->adjoin=MagickFalse;
527 entry->seekable_stream=MagickTrue;
528 entry->blob_support=MagickFalse;
529 entry->magick=(IsImageFormatHandler *) IsFPX;
530 entry->description=ConstantString("FlashPix Format");
531 entry->module=ConstantString("FPX");
532 (void) RegisterMagickInfo(entry);
533 return(MagickImageCoderSignature);
537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 % U n r e g i s t e r F P X I m a g e %
545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 % UnregisterFPXImage() removes format registrations made by the
548 % FPX module from the list of supported formats.
550 % The format of the UnregisterFPXImage method is:
552 % UnregisterFPXImage(void)
555 ModuleExport void UnregisterFPXImage(void)
557 (void) UnregisterMagickInfo("FPX");
560 #if defined(MAGICKCORE_FPX_DELEGATE)
562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566 % W r i t e F P X I m a g e %
570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
572 % WriteFPXImage() writes an image in the FlashPix image format. This
573 % method was contributed by BillR@corbis.com.
575 % The format of the WriteFPXImage method is:
577 % MagickBooleanType WriteFPXImage(const ImageInfo *image_info,Image *image)
579 % A description of each parameter follows.
581 % o image_info: the image info.
583 % o image: The image.
587 static void ColorTwistMultiply(FPXColorTwistMatrix first,
588 FPXColorTwistMatrix second,FPXColorTwistMatrix *color_twist)
593 assert(color_twist != (FPXColorTwistMatrix *) NULL);
594 color_twist->byy=(first.byy*second.byy)+(first.byc1*second.bc1y)+
595 (first.byc2*second.bc2y)+(first.dummy1_zero*second.dummy4_zero);
596 color_twist->byc1=(first.byy*second.byc1)+(first.byc1*second.bc1c1)+
597 (first.byc2*second.bc2c1)+(first.dummy1_zero*second.dummy5_zero);
598 color_twist->byc2=(first.byy*second.byc2)+(first.byc1*second.bc1c2)+
599 (first.byc2*second.bc2c2)+(first.dummy1_zero*second.dummy6_zero);
600 color_twist->dummy1_zero=(first.byy*second.dummy1_zero)+
601 (first.byc1*second.dummy2_zero)+(first.byc2*second.dummy3_zero)+
602 (first.dummy1_zero*second.dummy7_one);
603 color_twist->bc1y=(first.bc1y*second.byy)+(first.bc1c1*second.bc1y)+
604 (first.bc1c2*second.bc2y)+(first.dummy2_zero*second.dummy4_zero);
605 color_twist->bc1c1=(first.bc1y*second.byc1)+(first.bc1c1*second.bc1c1)+
606 (first.bc1c2*second.bc2c1)+(first.dummy2_zero*second.dummy5_zero);
607 color_twist->bc1c2=(first.bc1y*second.byc2)+(first.bc1c1*second.bc1c2)+
608 (first.bc1c2*second.bc2c2)+(first.dummy2_zero*second.dummy6_zero);
609 color_twist->dummy2_zero=(first.bc1y*second.dummy1_zero)+
610 (first.bc1c1*second.dummy2_zero)+(first.bc1c2*second.dummy3_zero)+
611 (first.dummy2_zero*second.dummy7_one);
612 color_twist->bc2y=(first.bc2y*second.byy)+(first.bc2c1*second.bc1y)+
613 (first.bc2c2*second.bc2y)+(first.dummy3_zero*second.dummy4_zero);
614 color_twist->bc2c1=(first.bc2y*second.byc1)+(first.bc2c1*second.bc1c1)+
615 (first.bc2c2*second.bc2c1)+(first.dummy3_zero*second.dummy5_zero);
616 color_twist->bc2c2=(first.bc2y*second.byc2)+(first.bc2c1*second.bc1c2)+
617 (first.bc2c2*second.bc2c2)+(first.dummy3_zero*second.dummy6_zero);
618 color_twist->dummy3_zero=(first.bc2y*second.dummy1_zero)+
619 (first.bc2c1*second.dummy2_zero)+(first.bc2c2*second.dummy3_zero)+
620 (first.dummy3_zero*second.dummy7_one);
621 color_twist->dummy4_zero=(first.dummy4_zero*second.byy)+
622 (first.dummy5_zero*second.bc1y)+(first.dummy6_zero*second.bc2y)+
623 (first.dummy7_one*second.dummy4_zero);
624 color_twist->dummy5_zero=(first.dummy4_zero*second.byc1)+
625 (first.dummy5_zero*second.bc1c1)+(first.dummy6_zero*second.bc2c1)+
626 (first.dummy7_one*second.dummy5_zero);
627 color_twist->dummy6_zero=(first.dummy4_zero*second.byc2)+
628 (first.dummy5_zero*second.bc1c2)+(first.dummy6_zero*second.bc2c2)+
629 (first.dummy7_one*second.dummy6_zero);
630 color_twist->dummy7_one=(first.dummy4_zero*second.dummy1_zero)+
631 (first.dummy5_zero*second.dummy2_zero)+
632 (first.dummy6_zero*second.dummy3_zero)+(first.dummy7_one*second.dummy7_one);
635 static void SetBrightness(double brightness,FPXColorTwistMatrix *color_twist)
642 Set image brightness in color twist matrix.
644 assert(color_twist != (FPXColorTwistMatrix *) NULL);
645 brightness=sqrt((double) brightness);
646 effect.byy=brightness;
649 effect.dummy1_zero=0.0;
651 effect.bc1c1=brightness;
653 effect.dummy2_zero=0.0;
656 effect.bc2c2=brightness;
657 effect.dummy3_zero=0.0;
658 effect.dummy4_zero=0.0;
659 effect.dummy5_zero=0.0;
660 effect.dummy6_zero=0.0;
661 effect.dummy7_one=1.0;
662 ColorTwistMultiply(*color_twist,effect,&result);
666 static void SetColorBalance(double red,double green,double blue,
667 FPXColorTwistMatrix *color_twist)
678 Set image color balance in color twist matrix.
680 assert(color_twist != (FPXColorTwistMatrix *) NULL);
681 red=sqrt((double) red)-1.0;
682 green=sqrt((double) green)-1.0;
683 blue=sqrt((double) blue)-1.0;
686 red_effect.byc2=0.299*red;
687 red_effect.dummy1_zero=0.0;
688 red_effect.bc1y=(-0.299)*red;
689 red_effect.bc1c1=1.0-0.299*red;
690 red_effect.bc1c2=(-0.299)*red;
691 red_effect.dummy2_zero=0.0;
692 red_effect.bc2y=0.701*red;
693 red_effect.bc2c1=0.0;
694 red_effect.bc2c2=1.0+0.402*red;
695 red_effect.dummy3_zero=0.0;
696 red_effect.dummy4_zero=0.0;
697 red_effect.dummy5_zero=0.0;
698 red_effect.dummy6_zero=0.0;
699 red_effect.dummy7_one=1.0;
700 green_effect.byy=1.0;
701 green_effect.byc1=(-0.114)*green;
702 green_effect.byc2=(-0.299)*green;
703 green_effect.dummy1_zero=0.0;
704 green_effect.bc1y=(-0.587)*green;
705 green_effect.bc1c1=1.0-0.473*green;
706 green_effect.bc1c2=0.299*green;
707 green_effect.dummy2_zero=0.0;
708 green_effect.bc2y=(-0.587)*green;
709 green_effect.bc2c1=0.114*green;
710 green_effect.bc2c2=1.0-0.288*green;
711 green_effect.dummy3_zero=0.0;
712 green_effect.dummy4_zero=0.0;
713 green_effect.dummy5_zero=0.0;
714 green_effect.dummy6_zero=0.0;
715 green_effect.dummy7_one=1.0;
717 blue_effect.byc1=0.114*blue;
718 blue_effect.byc2=0.0;
719 blue_effect.dummy1_zero=0.0;
720 blue_effect.bc1y=0.886*blue;
721 blue_effect.bc1c1=1.0+0.772*blue;
722 blue_effect.bc1c2=0.0;
723 blue_effect.dummy2_zero=0.0;
724 blue_effect.bc2y=(-0.114)*blue;
725 blue_effect.bc2c1=(-0.114)*blue;
726 blue_effect.bc2c2=1.0-0.114*blue;
727 blue_effect.dummy3_zero=0.0;
728 blue_effect.dummy4_zero=0.0;
729 blue_effect.dummy5_zero=0.0;
730 blue_effect.dummy6_zero=0.0;
731 blue_effect.dummy7_one=1.0;
732 ColorTwistMultiply(red_effect,green_effect,&rg_effect);
733 ColorTwistMultiply(rg_effect,blue_effect,&rgb_effect);
734 ColorTwistMultiply(*color_twist,rgb_effect,&result);
738 static void SetSaturation(double saturation,FPXColorTwistMatrix *color_twist)
745 Set image saturation in color twist matrix.
747 assert(color_twist != (FPXColorTwistMatrix *) NULL);
751 effect.dummy1_zero=0.0;
753 effect.bc1c1=saturation;
755 effect.dummy2_zero=0.0;
758 effect.bc2c2=saturation;
759 effect.dummy3_zero=0.0;
760 effect.dummy4_zero=0.0;
761 effect.dummy5_zero=0.0;
762 effect.dummy6_zero=0.0;
763 effect.dummy7_one=1.0;
764 ColorTwistMultiply(*color_twist,effect,&result);
768 static MagickBooleanType WriteFPXImage(const ImageInfo *image_info,Image *image)
778 { NIFRGB_R, DATA_TYPE_UNSIGNED_BYTE },
779 { NIFRGB_G, DATA_TYPE_UNSIGNED_BYTE },
780 { NIFRGB_B, DATA_TYPE_UNSIGNED_BYTE },
781 { ALPHA, DATA_TYPE_UNSIGNED_BYTE }
801 FPXSummaryInformation
813 register const Quantum
836 assert(image_info != (const ImageInfo *) NULL);
837 assert(image_info->signature == MagickSignature);
838 assert(image != (Image *) NULL);
839 assert(image->signature == MagickSignature);
840 if (image->debug != MagickFalse)
841 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
842 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
843 if (status == MagickFalse)
845 (void) CloseBlob(image);
847 Initialize FPX toolkit.
850 if (IsRGBColorspace(image->colorspace) == MagickFalse)
851 (void) TransformImageColorspace(image,RGBColorspace);
852 memory_limit=20000000;
853 fpx_status=FPX_SetToolkitMemoryLimit(&memory_limit);
854 if (fpx_status != FPX_OK)
855 ThrowWriterException(DelegateError,"UnableToInitializeFPXLibrary");
858 colorspace.numberOfComponents=3;
859 if (image->matte != MagickFalse)
860 colorspace.numberOfComponents=4;
861 if ((image_info->type != TrueColorType) &&
862 IsImageGray(image,&image->exception))
864 colorspace.numberOfComponents=1;
865 colorspace.theComponents[0].myColor=MONOCHROME;
867 background_color.color1_value=0;
868 background_color.color2_value=0;
869 background_color.color3_value=0;
870 background_color.color4_value=0;
872 if (image->compression == JPEGCompression)
873 compression=JPEG_UNSPECIFIED;
874 if (image_info->compression == JPEGCompression)
875 compression=JPEG_UNSPECIFIED;
877 #if defined(macintosh)
881 FilenameToFSSpec(filename,&fsspec);
882 fpx_status=FPX_CreateImageByFilename((const FSSpec &) fsspec,image->columns,
884 fpx_status=FPX_CreateImageByFilename(image->filename,image->columns,
886 image->rows,tile_width,tile_height,colorspace,background_color,
887 compression,&flashpix);
889 if (fpx_status != FPX_OK)
891 if (compression == JPEG_UNSPECIFIED)
894 Initialize the compression by quality for the entire image.
896 fpx_status=FPX_SetJPEGCompression(flashpix,(unsigned short)
897 image->quality == UndefinedCompressionQuality ? 75 : image->quality);
898 if (fpx_status != FPX_OK)
899 ThrowWriterException(DelegateError,"UnableToSetJPEGLevel");
902 Set image summary info.
904 summary_info.title_valid=MagickFalse;
905 summary_info.subject_valid=MagickFalse;
906 summary_info.author_valid=MagickFalse;
907 summary_info.comments_valid=MagickFalse;
908 summary_info.keywords_valid=MagickFalse;
909 summary_info.OLEtemplate_valid=MagickFalse;
910 summary_info.last_author_valid=MagickFalse;
911 summary_info.rev_number_valid=MagickFalse;
912 summary_info.edit_time_valid=MagickFalse;
913 summary_info.last_printed_valid=MagickFalse;
914 summary_info.create_dtm_valid=MagickFalse;
915 summary_info.last_save_dtm_valid=MagickFalse;
916 summary_info.page_count_valid=MagickFalse;
917 summary_info.word_count_valid=MagickFalse;
918 summary_info.char_count_valid=MagickFalse;
919 summary_info.thumbnail_valid=MagickFalse;
920 summary_info.appname_valid=MagickFalse;
921 summary_info.security_valid=MagickFalse;
922 label=GetImageProperty(image,"label");
923 if (label != (const char *) NULL)
931 summary_info.title_valid=MagickTrue;
932 length=strlen(label);
933 summary_info.title.length=length;
934 if (~length >= (MaxTextExtent-1))
935 summary_info.title.ptr=(unsigned char *) AcquireQuantumMemory(
936 length+MaxTextExtent,sizeof(*summary_info.title.ptr));
937 if (summary_info.title.ptr == (unsigned char *) NULL)
938 ThrowWriterException(DelegateError,"UnableToSetImageTitle");
939 (void) CopyMagickString((char *) summary_info.title.ptr,label,
942 comment=GetImageProperty(image,"comment");
943 if (comment != (const char *) NULL)
948 summary_info.comments_valid=MagickTrue;
949 summary_info.comments.ptr=(unsigned char *) AcquireString(comment);
950 summary_info.comments.length=strlen(comment);
952 fpx_status=FPX_SetSummaryInformation(flashpix,&summary_info);
953 if (fpx_status != FPX_OK)
954 ThrowWriterException(DelegateError,"UnableToSetSummaryInfo");
956 Initialize FlashPix image description.
958 quantum_info=AcquireQuantumInfo(image_info,image);
959 if (quantum_info == (QuantumInfo *) NULL)
960 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
961 pixels=GetQuantumPixels(quantum_info);
962 fpx_info.numberOfComponents=colorspace.numberOfComponents;
963 for (i=0; i < (ssize_t) fpx_info.numberOfComponents; i++)
965 fpx_info.components[i].myColorType.myDataType=DATA_TYPE_UNSIGNED_BYTE;
966 fpx_info.components[i].horzSubSampFactor=1;
967 fpx_info.components[i].vertSubSampFactor=1;
968 fpx_info.components[i].columnStride=fpx_info.numberOfComponents;
969 fpx_info.components[i].lineStride=
970 image->columns*fpx_info.components[i].columnStride;
971 fpx_info.components[i].theData=pixels+i;
973 fpx_info.components[0].myColorType.myColor=fpx_info.numberOfComponents != 1
974 ? NIFRGB_R : MONOCHROME;
975 fpx_info.components[1].myColorType.myColor=NIFRGB_G;
976 fpx_info.components[2].myColorType.myColor=NIFRGB_B;
977 fpx_info.components[3].myColorType.myColor=ALPHA;
981 quantum_type=RGBQuantum;
982 if (image->matte != MagickFalse)
983 quantum_type=RGBAQuantum;
984 if (fpx_info.numberOfComponents == 1)
985 quantum_type=GrayQuantum;
986 for (y=0; y < (ssize_t) image->rows; y++)
988 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
989 if (p == (const Quantum *) NULL)
991 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
992 quantum_type,pixels,&image->exception);
993 fpx_status=FPX_WriteImageLine(flashpix,&fpx_info);
994 if (fpx_status != FPX_OK)
996 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
998 if (status == MagickFalse)
1001 quantum_info=DestroyQuantumInfo(quantum_info);
1002 if (image_info->view != (char *) NULL)
1010 FPXContrastAdjustment
1016 FPXResultAspectRatio
1031 Initialize default viewing parameters.
1034 contrast_valid=MagickFalse;
1035 color_twist.byy=1.0;
1036 color_twist.byc1=0.0;
1037 color_twist.byc2=0.0;
1038 color_twist.dummy1_zero=0.0;
1039 color_twist.bc1y=0.0;
1040 color_twist.bc1c1=1.0;
1041 color_twist.bc1c2=0.0;
1042 color_twist.dummy2_zero=0.0;
1043 color_twist.bc2y=0.0;
1044 color_twist.bc2c1=0.0;
1045 color_twist.bc2c2=1.0;
1046 color_twist.dummy3_zero=0.0;
1047 color_twist.dummy4_zero=0.0;
1048 color_twist.dummy5_zero=0.0;
1049 color_twist.dummy6_zero=0.0;
1050 color_twist.dummy7_one=1.0;
1051 color_twist_valid=MagickFalse;
1053 sharpen_valid=MagickFalse;
1054 aspect_ratio=(double) image->columns/image->rows;
1055 aspect_ratio_valid=MagickFalse;
1056 view_rect.left=(float) 0.1;
1057 view_rect.width=aspect_ratio-0.2;
1058 view_rect.top=(float) 0.1;
1059 view_rect.height=(float) 0.8; /* 1.0-0.2 */
1060 view_rect_valid=MagickFalse;
1077 affine_valid=MagickFalse;
1083 SetBrightness(0.5,&color_twist);
1084 SetSaturation(0.5,&color_twist);
1085 SetColorBalance(0.5,1.0,1.0,&color_twist);
1086 color_twist_valid=MagickTrue;
1090 fpx_status=FPX_SetImageAffineMatrix(flashpix,&affine);
1091 if (fpx_status != FPX_OK)
1092 ThrowWriterException(DelegateError,"UnableToSetAffineMatrix");
1094 if (aspect_ratio_valid)
1096 fpx_status=FPX_SetImageResultAspectRatio(flashpix,&aspect_ratio);
1097 if (fpx_status != FPX_OK)
1098 ThrowWriterException(DelegateError,"UnableToSetAspectRatio");
1100 if (color_twist_valid)
1102 fpx_status=FPX_SetImageColorTwistMatrix(flashpix,&color_twist);
1103 if (fpx_status != FPX_OK)
1104 ThrowWriterException(DelegateError,"UnableToSetColorTwist");
1108 fpx_status=FPX_SetImageContrastAdjustment(flashpix,&contrast);
1109 if (fpx_status != FPX_OK)
1110 ThrowWriterException(DelegateError,"UnableToSetContrast");
1114 fpx_status=FPX_SetImageFilteringValue(flashpix,&sharpen);
1115 if (fpx_status != FPX_OK)
1116 ThrowWriterException(DelegateError,"UnableToSetFilteringValue");
1118 if (view_rect_valid)
1120 fpx_status=FPX_SetImageROI(flashpix,&view_rect);
1121 if (fpx_status != FPX_OK)
1122 ThrowWriterException(DelegateError,"UnableToSetRegionOfInterest");
1125 (void) FPX_CloseImage(flashpix);