2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write FlashPIX Image Format %
20 % Copyright 1999-2012 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 *);
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % IsFPX() returns MagickTrue if the image format type, identified by the
99 % magick string, is FPX.
101 % The format of the IsFPX method is:
103 % MagickBooleanType IsFPX(const unsigned char *magick,const size_t length)
105 % A description of each parameter follows:
107 % o magick: compare image format pattern against these bytes.
109 % o length: Specifies the length of the magick string.
112 static MagickBooleanType IsFPX(const unsigned char *magick,const size_t length)
116 if (memcmp(magick,"\320\317\021\340",4) == 0)
121 #if defined(MAGICKCORE_FPX_DELEGATE)
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 % R e a d F P X I m a g e %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % ReadFPXImage() reads a FlashPix image file and returns it. It
134 % allocates the memory necessary for the new Image structure and returns a
135 % pointer to the new image. This method was contributed by BillR@corbis.com.
137 % The format of the ReadFPXImage method is:
139 % Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
141 % A description of each parameter follows:
143 % o image_info: the image info.
145 % o exception: return any errors or warnings in this structure.
148 static Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
153 FPXImageComponentDesc
168 FPXSummaryInformation
187 register unsigned char
214 assert(image_info != (const ImageInfo *) NULL);
215 assert(image_info->signature == MagickSignature);
216 if (image_info->debug != MagickFalse)
217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
218 image_info->filename);
219 assert(exception != (ExceptionInfo *) NULL);
220 assert(exception->signature == MagickSignature);
221 image=AcquireImage(image_info,exception);
222 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
223 if (status == MagickFalse)
225 image=DestroyImageList(image);
226 return((Image *) NULL);
228 (void) CloseBlob(image);
230 Initialize FPX toolkit.
232 fpx_status=FPX_InitSystem();
233 if (fpx_status != FPX_OK)
234 ThrowReaderException(CoderError,"UnableToInitializeFPXLibrary");
235 memory_limit=20000000;
236 fpx_status=FPX_SetToolkitMemoryLimit(&memory_limit);
237 if (fpx_status != FPX_OK)
240 ThrowReaderException(CoderError,"UnableToInitializeFPXLibrary");
244 flashpix=(FPXImageHandle *) NULL;
246 #if defined(macintosh)
250 FilenameToFSSpec(image->filename,&fsspec);
251 fpx_status=FPX_OpenImageByFilename((const FSSpec &) fsspec,(char *) NULL,
253 fpx_status=FPX_OpenImageByFilename(image->filename,(char *) NULL,
255 &width,&height,&tile_width,&tile_height,&colorspace,&flashpix);
257 if (fpx_status == FPX_LOW_MEMORY_ERROR)
260 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
262 if (fpx_status != FPX_OK)
265 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
267 image=DestroyImageList(image);
268 return((Image *) NULL);
270 if (colorspace.numberOfComponents == 0)
273 ThrowReaderException(CorruptImageError,"ImageTypeNotSupported");
275 if (image_info->view == (char *) NULL)
281 Get the aspect ratio.
283 aspect_ratio=(float) width/height;
284 fpx_status=FPX_GetImageResultAspectRatio(flashpix,&aspect_ratio);
285 if (fpx_status != FPX_OK)
286 ThrowReaderException(DelegateError,"UnableToReadAspectRatio");
287 if (width != (size_t) floor((aspect_ratio*height)+0.5))
290 fpx_status=FPX_GetSummaryInformation(flashpix,&summary_info);
291 if (fpx_status != FPX_OK)
294 ThrowReaderException(DelegateError,"UnableToReadSummaryInfo");
296 if (summary_info.title_valid)
297 if ((summary_info.title.length != 0) &&
298 (summary_info.title.ptr != (unsigned char *) NULL))
307 if (~summary_info.title.length >= (MaxTextExtent-1))
308 label=(char *) AcquireQuantumMemory(summary_info.title.length+
309 MaxTextExtent,sizeof(*label));
310 if (label == (char *) NULL)
313 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
315 (void) CopyMagickString(label,(char *) summary_info.title.ptr,
316 summary_info.title.length+1);
317 (void) SetImageProperty(image,"label",label,exception);
318 label=DestroyString(label);
320 if (summary_info.comments_valid)
321 if ((summary_info.comments.length != 0) &&
322 (summary_info.comments.ptr != (unsigned char *) NULL))
330 comments=(char *) NULL;
331 if (~summary_info.comments.length >= (MaxTextExtent-1))
332 comments=(char *) AcquireQuantumMemory(summary_info.comments.length+
333 MaxTextExtent,sizeof(*comments));
334 if (comments == (char *) NULL)
337 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
339 (void) CopyMagickString(comments,(char *) summary_info.comments.ptr,
340 summary_info.comments.length+1);
341 (void) SetImageProperty(image,"comment",comments,exception);
342 comments=DestroyString(comments);
345 Determine resolution by scene specification.
348 if (((width >> i) < tile_width) || ((height >> i) < tile_height))
351 if (image_info->number_scenes != 0)
352 while (scene > image_info->scene)
358 if (image_info->size != (char *) NULL)
359 while ((width > image->columns) || (height > image->rows))
366 image->columns=width;
368 if ((colorspace.numberOfComponents % 2) == 0)
369 image->matte=MagickTrue;
370 if (colorspace.numberOfComponents == 1)
373 Create linear colormap.
375 if (AcquireImageColormap(image,MaxColormapSize,exception) == MagickFalse)
378 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
381 if (image_info->ping != MagickFalse)
383 (void) FPX_CloseImage(flashpix);
385 return(GetFirstImageInList(image));
388 Allocate memory for the image and pixel buffer.
390 pixels=(unsigned char *) AcquireQuantumMemory(image->columns,(tile_height+
391 1UL)*colorspace.numberOfComponents*sizeof(*pixels));
392 if (pixels == (unsigned char *) NULL)
395 (void) FPX_CloseImage(flashpix);
396 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
399 Initialize FlashPix image description.
401 fpx_info.numberOfComponents=colorspace.numberOfComponents;
402 for (i=0; i < 4; i++)
404 fpx_info.components[i].myColorType.myDataType=DATA_TYPE_UNSIGNED_BYTE;
405 fpx_info.components[i].horzSubSampFactor=1;
406 fpx_info.components[i].vertSubSampFactor=1;
407 fpx_info.components[i].columnStride=fpx_info.numberOfComponents;
408 fpx_info.components[i].lineStride=image->columns*
409 fpx_info.components[i].columnStride;
410 fpx_info.components[i].theData=pixels+i;
412 fpx_info.components[0].myColorType.myColor=fpx_info.numberOfComponents > 2 ?
413 NIFRGB_R : MONOCHROME;
414 red_component=(&fpx_info.components[0]);
415 fpx_info.components[1].myColorType.myColor=fpx_info.numberOfComponents > 2 ?
417 green_component=(&fpx_info.components[1]);
418 fpx_info.components[2].myColorType.myColor=NIFRGB_B;
419 blue_component=(&fpx_info.components[2]);
420 fpx_info.components[3].myColorType.myColor=ALPHA;
421 alpha_component=(&fpx_info.components[fpx_info.numberOfComponents-1]);
422 FPX_SetResampleMethod(FPX_LINEAR_INTERPOLATION);
424 Initialize image pixels.
426 for (y=0; y < (ssize_t) image->rows; y++)
428 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
429 if (q == (Quantum *) NULL)
431 if ((y % tile_height) == 0)
434 Read FPX image tile (with or without viewing affine)..
436 if (image_info->view != (char *) NULL)
437 fpx_status=FPX_ReadImageRectangle(flashpix,0,y,image->columns,y+
438 tile_height-1,scene,&fpx_info);
440 fpx_status=FPX_ReadImageTransformRectangle(flashpix,0.0F,
441 (float) y/image->rows,(float) image->columns/image->rows,
442 (float) (y+tile_height-1)/image->rows,(ssize_t) image->columns,
443 (ssize_t) tile_height,&fpx_info);
444 if (fpx_status == FPX_LOW_MEMORY_ERROR)
446 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
447 (void) FPX_CloseImage(flashpix);
449 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
453 Transfer a FPX pixels.
455 r=red_component->theData+(y % tile_height)*red_component->lineStride;
456 g=green_component->theData+(y % tile_height)*green_component->lineStride;
457 b=blue_component->theData+(y % tile_height)*blue_component->lineStride;
458 a=alpha_component->theData+(y % tile_height)*alpha_component->lineStride;
459 for (x=0; x < (ssize_t) image->columns; x++)
461 if (fpx_info.numberOfComponents > 2)
463 SetPixelRed(image,ScaleCharToQuantum(*r),q);
464 SetPixelGreen(image,ScaleCharToQuantum(*g),q);
465 SetPixelBlue(image,ScaleCharToQuantum(*b),q);
469 index=ScaleCharToQuantum(*r);
470 SetPixelBlack(image,index,q);
471 SetPixelRed(image,index,q);
472 SetPixelGreen(image,index,q);
473 SetPixelBlue(image,index,q);
475 SetPixelAlpha(image,OpaqueAlpha,q);
476 if (image->matte != MagickFalse)
477 SetPixelAlpha(image,ScaleCharToQuantum(*a),q);
478 q+=GetPixelChannels(image);
479 r+=red_component->columnStride;
480 g+=green_component->columnStride;
481 b+=blue_component->columnStride;
482 a+=alpha_component->columnStride;
484 if (SyncAuthenticPixels(image,exception) == MagickFalse)
486 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
488 if (status == MagickFalse)
491 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
492 (void) FPX_CloseImage(flashpix);
494 return(GetFirstImageInList(image));
499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503 % R e g i s t e r F P X I m a g e %
507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 % RegisterFPXImage() adds attributes for the FPX image format to
510 % the list of supported formats. The attributes include the image format
511 % tag, a method to read and/or write the format, whether the format
512 % supports the saving of more than one frame to the same file or blob,
513 % whether the format supports native in-memory I/O, and a brief
514 % description of the format.
516 % The format of the RegisterFPXImage method is:
518 % size_t RegisterFPXImage(void)
521 ModuleExport size_t RegisterFPXImage(void)
526 entry=SetMagickInfo("FPX");
527 #if defined(MAGICKCORE_FPX_DELEGATE)
528 entry->decoder=(DecodeImageHandler *) ReadFPXImage;
529 entry->encoder=(EncodeImageHandler *) WriteFPXImage;
531 entry->adjoin=MagickFalse;
532 entry->seekable_stream=MagickTrue;
533 entry->blob_support=MagickFalse;
534 entry->magick=(IsImageFormatHandler *) IsFPX;
535 entry->description=ConstantString("FlashPix Format");
536 entry->module=ConstantString("FPX");
537 (void) RegisterMagickInfo(entry);
538 return(MagickImageCoderSignature);
542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 % U n r e g i s t e r F P X I m a g e %
550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
552 % UnregisterFPXImage() removes format registrations made by the
553 % FPX module from the list of supported formats.
555 % The format of the UnregisterFPXImage method is:
557 % UnregisterFPXImage(void)
560 ModuleExport void UnregisterFPXImage(void)
562 (void) UnregisterMagickInfo("FPX");
565 #if defined(MAGICKCORE_FPX_DELEGATE)
567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571 % W r i t e F P X I m a g e %
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 % WriteFPXImage() writes an image in the FlashPix image format. This
578 % method was contributed by BillR@corbis.com.
580 % The format of the WriteFPXImage method is:
582 % MagickBooleanType WriteFPXImage(const ImageInfo *image_info,
583 % Image *image,ExceptionInfo *exception)
585 % A description of each parameter follows.
587 % o image_info: the image info.
589 % o image: The image.
591 % o exception: return any errors or warnings in this structure.
595 static void ColorTwistMultiply(FPXColorTwistMatrix first,
596 FPXColorTwistMatrix second,FPXColorTwistMatrix *color_twist)
601 assert(color_twist != (FPXColorTwistMatrix *) NULL);
602 color_twist->byy=(first.byy*second.byy)+(first.byc1*second.bc1y)+
603 (first.byc2*second.bc2y)+(first.dummy1_zero*second.dummy4_zero);
604 color_twist->byc1=(first.byy*second.byc1)+(first.byc1*second.bc1c1)+
605 (first.byc2*second.bc2c1)+(first.dummy1_zero*second.dummy5_zero);
606 color_twist->byc2=(first.byy*second.byc2)+(first.byc1*second.bc1c2)+
607 (first.byc2*second.bc2c2)+(first.dummy1_zero*second.dummy6_zero);
608 color_twist->dummy1_zero=(first.byy*second.dummy1_zero)+
609 (first.byc1*second.dummy2_zero)+(first.byc2*second.dummy3_zero)+
610 (first.dummy1_zero*second.dummy7_one);
611 color_twist->bc1y=(first.bc1y*second.byy)+(first.bc1c1*second.bc1y)+
612 (first.bc1c2*second.bc2y)+(first.dummy2_zero*second.dummy4_zero);
613 color_twist->bc1c1=(first.bc1y*second.byc1)+(first.bc1c1*second.bc1c1)+
614 (first.bc1c2*second.bc2c1)+(first.dummy2_zero*second.dummy5_zero);
615 color_twist->bc1c2=(first.bc1y*second.byc2)+(first.bc1c1*second.bc1c2)+
616 (first.bc1c2*second.bc2c2)+(first.dummy2_zero*second.dummy6_zero);
617 color_twist->dummy2_zero=(first.bc1y*second.dummy1_zero)+
618 (first.bc1c1*second.dummy2_zero)+(first.bc1c2*second.dummy3_zero)+
619 (first.dummy2_zero*second.dummy7_one);
620 color_twist->bc2y=(first.bc2y*second.byy)+(first.bc2c1*second.bc1y)+
621 (first.bc2c2*second.bc2y)+(first.dummy3_zero*second.dummy4_zero);
622 color_twist->bc2c1=(first.bc2y*second.byc1)+(first.bc2c1*second.bc1c1)+
623 (first.bc2c2*second.bc2c1)+(first.dummy3_zero*second.dummy5_zero);
624 color_twist->bc2c2=(first.bc2y*second.byc2)+(first.bc2c1*second.bc1c2)+
625 (first.bc2c2*second.bc2c2)+(first.dummy3_zero*second.dummy6_zero);
626 color_twist->dummy3_zero=(first.bc2y*second.dummy1_zero)+
627 (first.bc2c1*second.dummy2_zero)+(first.bc2c2*second.dummy3_zero)+
628 (first.dummy3_zero*second.dummy7_one);
629 color_twist->dummy4_zero=(first.dummy4_zero*second.byy)+
630 (first.dummy5_zero*second.bc1y)+(first.dummy6_zero*second.bc2y)+
631 (first.dummy7_one*second.dummy4_zero);
632 color_twist->dummy5_zero=(first.dummy4_zero*second.byc1)+
633 (first.dummy5_zero*second.bc1c1)+(first.dummy6_zero*second.bc2c1)+
634 (first.dummy7_one*second.dummy5_zero);
635 color_twist->dummy6_zero=(first.dummy4_zero*second.byc2)+
636 (first.dummy5_zero*second.bc1c2)+(first.dummy6_zero*second.bc2c2)+
637 (first.dummy7_one*second.dummy6_zero);
638 color_twist->dummy7_one=(first.dummy4_zero*second.dummy1_zero)+
639 (first.dummy5_zero*second.dummy2_zero)+
640 (first.dummy6_zero*second.dummy3_zero)+(first.dummy7_one*second.dummy7_one);
643 static void SetBrightness(double brightness,FPXColorTwistMatrix *color_twist)
650 Set image brightness in color twist matrix.
652 assert(color_twist != (FPXColorTwistMatrix *) NULL);
653 brightness=sqrt((double) brightness);
654 effect.byy=brightness;
657 effect.dummy1_zero=0.0;
659 effect.bc1c1=brightness;
661 effect.dummy2_zero=0.0;
664 effect.bc2c2=brightness;
665 effect.dummy3_zero=0.0;
666 effect.dummy4_zero=0.0;
667 effect.dummy5_zero=0.0;
668 effect.dummy6_zero=0.0;
669 effect.dummy7_one=1.0;
670 ColorTwistMultiply(*color_twist,effect,&result);
674 static void SetColorBalance(double red,double green,double blue,
675 FPXColorTwistMatrix *color_twist)
686 Set image color balance in color twist matrix.
688 assert(color_twist != (FPXColorTwistMatrix *) NULL);
689 red=sqrt((double) red)-1.0;
690 green=sqrt((double) green)-1.0;
691 blue=sqrt((double) blue)-1.0;
694 red_effect.byc2=0.299*red;
695 red_effect.dummy1_zero=0.0;
696 red_effect.bc1y=(-0.299)*red;
697 red_effect.bc1c1=1.0-0.299*red;
698 red_effect.bc1c2=(-0.299)*red;
699 red_effect.dummy2_zero=0.0;
700 red_effect.bc2y=0.701*red;
701 red_effect.bc2c1=0.0;
702 red_effect.bc2c2=1.0+0.402*red;
703 red_effect.dummy3_zero=0.0;
704 red_effect.dummy4_zero=0.0;
705 red_effect.dummy5_zero=0.0;
706 red_effect.dummy6_zero=0.0;
707 red_effect.dummy7_one=1.0;
708 green_effect.byy=1.0;
709 green_effect.byc1=(-0.114)*green;
710 green_effect.byc2=(-0.299)*green;
711 green_effect.dummy1_zero=0.0;
712 green_effect.bc1y=(-0.587)*green;
713 green_effect.bc1c1=1.0-0.473*green;
714 green_effect.bc1c2=0.299*green;
715 green_effect.dummy2_zero=0.0;
716 green_effect.bc2y=(-0.587)*green;
717 green_effect.bc2c1=0.114*green;
718 green_effect.bc2c2=1.0-0.288*green;
719 green_effect.dummy3_zero=0.0;
720 green_effect.dummy4_zero=0.0;
721 green_effect.dummy5_zero=0.0;
722 green_effect.dummy6_zero=0.0;
723 green_effect.dummy7_one=1.0;
725 blue_effect.byc1=0.114*blue;
726 blue_effect.byc2=0.0;
727 blue_effect.dummy1_zero=0.0;
728 blue_effect.bc1y=0.886*blue;
729 blue_effect.bc1c1=1.0+0.772*blue;
730 blue_effect.bc1c2=0.0;
731 blue_effect.dummy2_zero=0.0;
732 blue_effect.bc2y=(-0.114)*blue;
733 blue_effect.bc2c1=(-0.114)*blue;
734 blue_effect.bc2c2=1.0-0.114*blue;
735 blue_effect.dummy3_zero=0.0;
736 blue_effect.dummy4_zero=0.0;
737 blue_effect.dummy5_zero=0.0;
738 blue_effect.dummy6_zero=0.0;
739 blue_effect.dummy7_one=1.0;
740 ColorTwistMultiply(red_effect,green_effect,&rg_effect);
741 ColorTwistMultiply(rg_effect,blue_effect,&rgb_effect);
742 ColorTwistMultiply(*color_twist,rgb_effect,&result);
746 static void SetSaturation(double saturation,FPXColorTwistMatrix *color_twist)
753 Set image saturation in color twist matrix.
755 assert(color_twist != (FPXColorTwistMatrix *) NULL);
759 effect.dummy1_zero=0.0;
761 effect.bc1c1=saturation;
763 effect.dummy2_zero=0.0;
766 effect.bc2c2=saturation;
767 effect.dummy3_zero=0.0;
768 effect.dummy4_zero=0.0;
769 effect.dummy5_zero=0.0;
770 effect.dummy6_zero=0.0;
771 effect.dummy7_one=1.0;
772 ColorTwistMultiply(*color_twist,effect,&result);
776 static MagickBooleanType WriteFPXImage(const ImageInfo *image_info,Image *image,
777 ExceptionInfo *exception)
787 { NIFRGB_R, DATA_TYPE_UNSIGNED_BYTE },
788 { NIFRGB_G, DATA_TYPE_UNSIGNED_BYTE },
789 { NIFRGB_B, DATA_TYPE_UNSIGNED_BYTE },
790 { ALPHA, DATA_TYPE_UNSIGNED_BYTE }
810 FPXSummaryInformation
822 register const Quantum
845 assert(image_info != (const ImageInfo *) NULL);
846 assert(image_info->signature == MagickSignature);
847 assert(image != (Image *) NULL);
848 assert(image->signature == MagickSignature);
849 if (image->debug != MagickFalse)
850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
851 assert(exception != (ExceptionInfo *) NULL);
852 assert(exception->signature == MagickSignature);
853 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
854 if (status == MagickFalse)
856 (void) CloseBlob(image);
858 Initialize FPX toolkit.
861 if (IsRGBColorspace(image->colorspace) == MagickFalse)
862 (void) TransformImageColorspace(image,RGBColorspace,exception);
863 memory_limit=20000000;
864 fpx_status=FPX_SetToolkitMemoryLimit(&memory_limit);
865 if (fpx_status != FPX_OK)
866 ThrowWriterException(DelegateError,"UnableToInitializeFPXLibrary");
869 colorspace.numberOfComponents=3;
870 if (image->matte != MagickFalse)
871 colorspace.numberOfComponents=4;
872 if ((image_info->type != TrueColorType) &&
873 (IsImageGray(image,exception) != MagickFalse))
875 colorspace.numberOfComponents=1;
876 colorspace.theComponents[0].myColor=MONOCHROME;
878 background_color.color1_value=0;
879 background_color.color2_value=0;
880 background_color.color3_value=0;
881 background_color.color4_value=0;
883 if (image->compression == JPEGCompression)
884 compression=JPEG_UNSPECIFIED;
885 if (image_info->compression == JPEGCompression)
886 compression=JPEG_UNSPECIFIED;
888 #if defined(macintosh)
892 FilenameToFSSpec(filename,&fsspec);
893 fpx_status=FPX_CreateImageByFilename((const FSSpec &) fsspec,image->columns,
895 fpx_status=FPX_CreateImageByFilename(image->filename,image->columns,
897 image->rows,tile_width,tile_height,colorspace,background_color,
898 compression,&flashpix);
900 if (fpx_status != FPX_OK)
902 if (compression == JPEG_UNSPECIFIED)
905 Initialize the compression by quality for the entire image.
907 fpx_status=FPX_SetJPEGCompression(flashpix,(unsigned short)
908 image->quality == UndefinedCompressionQuality ? 75 : image->quality);
909 if (fpx_status != FPX_OK)
910 ThrowWriterException(DelegateError,"UnableToSetJPEGLevel");
913 Set image summary info.
915 summary_info.title_valid=MagickFalse;
916 summary_info.subject_valid=MagickFalse;
917 summary_info.author_valid=MagickFalse;
918 summary_info.comments_valid=MagickFalse;
919 summary_info.keywords_valid=MagickFalse;
920 summary_info.OLEtemplate_valid=MagickFalse;
921 summary_info.last_author_valid=MagickFalse;
922 summary_info.rev_number_valid=MagickFalse;
923 summary_info.edit_time_valid=MagickFalse;
924 summary_info.last_printed_valid=MagickFalse;
925 summary_info.create_dtm_valid=MagickFalse;
926 summary_info.last_save_dtm_valid=MagickFalse;
927 summary_info.page_count_valid=MagickFalse;
928 summary_info.word_count_valid=MagickFalse;
929 summary_info.char_count_valid=MagickFalse;
930 summary_info.thumbnail_valid=MagickFalse;
931 summary_info.appname_valid=MagickFalse;
932 summary_info.security_valid=MagickFalse;
933 label=GetImageProperty(image,"label",exception);
934 if (label != (const char *) NULL)
939 summary_info.title_valid=MagickTrue;
940 length=strlen(label);
941 summary_info.title.length=length;
942 if (~length >= (MaxTextExtent-1))
943 summary_info.title.ptr=(unsigned char *) AcquireQuantumMemory(
944 length+MaxTextExtent,sizeof(*summary_info.title.ptr));
945 if (summary_info.title.ptr == (unsigned char *) NULL)
946 ThrowWriterException(DelegateError,"UnableToSetImageTitle");
947 (void) CopyMagickString((char *) summary_info.title.ptr,label,
950 comment=GetImageProperty(image,"comment",exception);
951 if (comment != (const char *) NULL)
956 summary_info.comments_valid=MagickTrue;
957 summary_info.comments.ptr=(unsigned char *) AcquireString(comment);
958 summary_info.comments.length=strlen(comment);
960 fpx_status=FPX_SetSummaryInformation(flashpix,&summary_info);
961 if (fpx_status != FPX_OK)
962 ThrowWriterException(DelegateError,"UnableToSetSummaryInfo");
964 Initialize FlashPix image description.
966 quantum_info=AcquireQuantumInfo(image_info,image);
967 if (quantum_info == (QuantumInfo *) NULL)
968 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
969 pixels=GetQuantumPixels(quantum_info);
970 fpx_info.numberOfComponents=colorspace.numberOfComponents;
971 for (i=0; i < (ssize_t) fpx_info.numberOfComponents; i++)
973 fpx_info.components[i].myColorType.myDataType=DATA_TYPE_UNSIGNED_BYTE;
974 fpx_info.components[i].horzSubSampFactor=1;
975 fpx_info.components[i].vertSubSampFactor=1;
976 fpx_info.components[i].columnStride=fpx_info.numberOfComponents;
977 fpx_info.components[i].lineStride=
978 image->columns*fpx_info.components[i].columnStride;
979 fpx_info.components[i].theData=pixels+i;
981 fpx_info.components[0].myColorType.myColor=fpx_info.numberOfComponents != 1
982 ? NIFRGB_R : MONOCHROME;
983 fpx_info.components[1].myColorType.myColor=NIFRGB_G;
984 fpx_info.components[2].myColorType.myColor=NIFRGB_B;
985 fpx_info.components[3].myColorType.myColor=ALPHA;
989 quantum_type=RGBQuantum;
990 if (image->matte != MagickFalse)
991 quantum_type=RGBAQuantum;
992 if (fpx_info.numberOfComponents == 1)
993 quantum_type=GrayQuantum;
994 for (y=0; y < (ssize_t) image->rows; y++)
996 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
997 if (p == (const Quantum *) NULL)
999 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1000 quantum_type,pixels,exception);
1001 fpx_status=FPX_WriteImageLine(flashpix,&fpx_info);
1002 if (fpx_status != FPX_OK)
1004 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1006 if (status == MagickFalse)
1009 quantum_info=DestroyQuantumInfo(quantum_info);
1010 if (image_info->view != (char *) NULL)
1018 FPXContrastAdjustment
1024 FPXResultAspectRatio
1039 Initialize default viewing parameters.
1042 contrast_valid=MagickFalse;
1043 color_twist.byy=1.0;
1044 color_twist.byc1=0.0;
1045 color_twist.byc2=0.0;
1046 color_twist.dummy1_zero=0.0;
1047 color_twist.bc1y=0.0;
1048 color_twist.bc1c1=1.0;
1049 color_twist.bc1c2=0.0;
1050 color_twist.dummy2_zero=0.0;
1051 color_twist.bc2y=0.0;
1052 color_twist.bc2c1=0.0;
1053 color_twist.bc2c2=1.0;
1054 color_twist.dummy3_zero=0.0;
1055 color_twist.dummy4_zero=0.0;
1056 color_twist.dummy5_zero=0.0;
1057 color_twist.dummy6_zero=0.0;
1058 color_twist.dummy7_one=1.0;
1059 color_twist_valid=MagickFalse;
1061 sharpen_valid=MagickFalse;
1062 aspect_ratio=(double) image->columns/image->rows;
1063 aspect_ratio_valid=MagickFalse;
1064 view_rect.left=(float) 0.1;
1065 view_rect.width=aspect_ratio-0.2;
1066 view_rect.top=(float) 0.1;
1067 view_rect.height=(float) 0.8; /* 1.0-0.2 */
1068 view_rect_valid=MagickFalse;
1085 affine_valid=MagickFalse;
1091 SetBrightness(0.5,&color_twist);
1092 SetSaturation(0.5,&color_twist);
1093 SetColorBalance(0.5,1.0,1.0,&color_twist);
1094 color_twist_valid=MagickTrue;
1098 fpx_status=FPX_SetImageAffineMatrix(flashpix,&affine);
1099 if (fpx_status != FPX_OK)
1100 ThrowWriterException(DelegateError,"UnableToSetAffineMatrix");
1102 if (aspect_ratio_valid)
1104 fpx_status=FPX_SetImageResultAspectRatio(flashpix,&aspect_ratio);
1105 if (fpx_status != FPX_OK)
1106 ThrowWriterException(DelegateError,"UnableToSetAspectRatio");
1108 if (color_twist_valid)
1110 fpx_status=FPX_SetImageColorTwistMatrix(flashpix,&color_twist);
1111 if (fpx_status != FPX_OK)
1112 ThrowWriterException(DelegateError,"UnableToSetColorTwist");
1116 fpx_status=FPX_SetImageContrastAdjustment(flashpix,&contrast);
1117 if (fpx_status != FPX_OK)
1118 ThrowWriterException(DelegateError,"UnableToSetContrast");
1122 fpx_status=FPX_SetImageFilteringValue(flashpix,&sharpen);
1123 if (fpx_status != FPX_OK)
1124 ThrowWriterException(DelegateError,"UnableToSetFilteringValue");
1126 if (view_rect_valid)
1128 fpx_status=FPX_SetImageROI(flashpix,&view_rect);
1129 if (fpx_status != FPX_OK)
1130 ThrowWriterException(DelegateError,"UnableToSetRegionOfInterest");
1133 (void) FPX_CloseImage(flashpix);