cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC L IIIII PPPP % |
| 7 | % C L I P P % |
| 8 | % C L I PPPP % |
| 9 | % C L I P % |
| 10 | % CCCC LLLLL IIIII P % |
| 11 | % % |
| 12 | % % |
| 13 | % Write Clip Mask To MIFF File. % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
Cristy | f6ff9ea | 2016-12-05 09:53:35 -0500 | [diff] [blame] | 20 | % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame] | 26 | % https://www.imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
cristy | 1533866 | 2012-06-21 01:45:37 +0000 | [diff] [blame] | 43 | #include "MagickCore/attribute.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/constitute.h" |
| 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 49 | #include "MagickCore/list.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/magick.h" |
| 51 | #include "MagickCore/memory_.h" |
| 52 | #include "MagickCore/monitor.h" |
| 53 | #include "MagickCore/monitor-private.h" |
| 54 | #include "MagickCore/quantum-private.h" |
| 55 | #include "MagickCore/static.h" |
| 56 | #include "MagickCore/string_.h" |
| 57 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | Forward declarations. |
| 61 | */ |
| 62 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 63 | WriteCLIPImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 67 | % % |
| 68 | % % |
| 69 | % % |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 70 | % R e a d C L I P I m a g e % |
| 71 | % % |
| 72 | % % |
| 73 | % % |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 75 | % |
| 76 | % ReadCLIPImage returns the rendered clip path associated with the image. |
| 77 | % |
| 78 | % The format of the ReadCLIPImage method is: |
| 79 | % |
| 80 | % Image *ReadCLIPImage(const ImageInfo *image_info, |
| 81 | % ExceptionInfo *exception) |
| 82 | % |
| 83 | % A description of each parameter follows: |
| 84 | % |
| 85 | % o image_info: the image info. |
| 86 | % |
| 87 | % o exception: return any errors or warnings in this structure. |
| 88 | % |
| 89 | */ |
| 90 | static Image *ReadCLIPImage(const ImageInfo *image_info, |
| 91 | ExceptionInfo *exception) |
| 92 | { |
| 93 | Image |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 94 | *image; |
| 95 | |
| 96 | ImageInfo |
| 97 | *read_info; |
| 98 | |
| 99 | /* |
| 100 | Initialize Image structure. |
| 101 | */ |
| 102 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 103 | assert(image_info->signature == MagickCoreSignature); |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 104 | if (image_info->debug != MagickFalse) |
| 105 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 106 | image_info->filename); |
| 107 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 108 | assert(exception->signature == MagickCoreSignature); |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 109 | read_info=CloneImageInfo(image_info); |
| 110 | SetImageInfoBlob(read_info,(void *) NULL,0); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 111 | (void) CopyMagickString(read_info->magick,"MIFF",MagickPathExtent); |
cristy | 2042598 | 2015-03-15 22:14:05 +0000 | [diff] [blame] | 112 | image=ReadImage(read_info,exception); |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 113 | read_info=DestroyImageInfo(read_info); |
cristy | 2042598 | 2015-03-15 22:14:05 +0000 | [diff] [blame] | 114 | if (image != (Image *) NULL) |
| 115 | { |
| 116 | Image |
| 117 | *clip_image; |
| 118 | |
| 119 | (void) ClipImage(image,exception); |
Dirk Lemstra | 456becf | 2016-12-03 17:52:58 +0100 | [diff] [blame] | 120 | clip_image=GetImageMask(image,WritePixelMask,exception); |
cristy | 2042598 | 2015-03-15 22:14:05 +0000 | [diff] [blame] | 121 | if (clip_image == (Image *) NULL) |
| 122 | ThrowReaderException(CoderError,"ImageDoesNotHaveAClipMask"); |
| 123 | image=DestroyImage(image); |
| 124 | image=clip_image; |
| 125 | } |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 126 | return(GetFirstImageInList(image)); |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 131 | % % |
| 132 | % % |
| 133 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | % R e g i s t e r C L I P I m a g e % |
| 135 | % % |
| 136 | % % |
| 137 | % % |
| 138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 139 | % |
| 140 | % RegisterCLIPImage() adds attributes for the CLIP image format to |
| 141 | % the list of supported formats. The attributes include the image format |
| 142 | % tag, a method to read and/or write the format, whether the format |
| 143 | % supports the saving of more than one frame to the same file or blob, |
| 144 | % whether the format supports native in-memory I/O, and a brief |
| 145 | % description of the format. |
| 146 | % |
| 147 | % The format of the RegisterCLIPImage method is: |
| 148 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 149 | % size_t RegisterCLIPImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | % |
| 151 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 152 | ModuleExport size_t RegisterCLIPImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | { |
| 154 | MagickInfo |
| 155 | *entry; |
| 156 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 157 | entry=AcquireMagickInfo("CLIP","CLIP","Image Clip Mask"); |
cristy | a7f8906 | 2013-03-30 21:53:44 +0000 | [diff] [blame] | 158 | entry->decoder=(DecodeImageHandler *) ReadCLIPImage; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | entry->encoder=(EncodeImageHandler *) WriteCLIPImage; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 160 | (void) RegisterMagickInfo(entry); |
| 161 | return(MagickImageCoderSignature); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 166 | % % |
| 167 | % % |
| 168 | % % |
| 169 | % U n r e g i s t e r C L I P I m a g e % |
| 170 | % % |
| 171 | % % |
| 172 | % % |
| 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 174 | % |
| 175 | % UnregisterCLIPImage() removes format registrations made by the |
| 176 | % CLIP module from the list of supported formats. |
| 177 | % |
| 178 | % The format of the UnregisterCLIPImage method is: |
| 179 | % |
| 180 | % UnregisterCLIPImage(void) |
| 181 | % |
| 182 | */ |
| 183 | ModuleExport void UnregisterCLIPImage(void) |
| 184 | { |
| 185 | (void) UnregisterMagickInfo("CLIP"); |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 190 | % % |
| 191 | % % |
| 192 | % % |
| 193 | % W r i t e C L I P I m a g e % |
| 194 | % % |
| 195 | % % |
| 196 | % % |
| 197 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 198 | % |
| 199 | % WriteCLIPImage() writes an image of clip bytes to a file. It consists of |
| 200 | % data from the clip mask of the image. |
| 201 | % |
| 202 | % The format of the WriteCLIPImage method is: |
| 203 | % |
| 204 | % MagickBooleanType WriteCLIPImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 205 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | % |
| 207 | % A description of each parameter follows. |
| 208 | % |
| 209 | % o image_info: the image info. |
| 210 | % |
| 211 | % o image: The image. |
| 212 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 213 | % o exception: return any errors or warnings in this structure. |
| 214 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 215 | */ |
| 216 | static MagickBooleanType WriteCLIPImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 217 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 218 | { |
| 219 | Image |
| 220 | *clip_image; |
| 221 | |
| 222 | ImageInfo |
| 223 | *write_info; |
| 224 | |
| 225 | MagickBooleanType |
| 226 | status; |
| 227 | |
Dirk Lemstra | 456becf | 2016-12-03 17:52:58 +0100 | [diff] [blame] | 228 | if (image->write_mask == MagickFalse) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 229 | (void) ClipImage(image,exception); |
Dirk Lemstra | 456becf | 2016-12-03 17:52:58 +0100 | [diff] [blame] | 230 | if (image->write_mask == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 231 | ThrowWriterException(CoderError,"ImageDoesNotHaveAClipMask"); |
Dirk Lemstra | 456becf | 2016-12-03 17:52:58 +0100 | [diff] [blame] | 232 | clip_image=GetImageMask(image,WritePixelMask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | if (clip_image == (Image *) NULL) |
| 234 | return(MagickFalse); |
Cristy | e6fb02d | 2015-09-27 10:47:45 -0400 | [diff] [blame] | 235 | (void) CopyMagickString(clip_image->filename,image->filename, |
| 236 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 237 | write_info=CloneImageInfo(image_info); |
Cristy | e6fb02d | 2015-09-27 10:47:45 -0400 | [diff] [blame] | 238 | *write_info->magick='\0'; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 239 | (void) SetImageInfo(write_info,1,exception); |
Cristy | 60f21f2 | 2016-07-04 09:03:59 -0400 | [diff] [blame] | 240 | if ((*write_info->magick == '\0') || |
| 241 | (LocaleCompare(write_info->magick,"CLIP") == 0)) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 242 | (void) FormatLocaleString(clip_image->filename,MagickPathExtent,"miff:%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 243 | write_info->filename); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 244 | status=WriteImage(write_info,clip_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | clip_image=DestroyImage(clip_image); |
| 246 | write_info=DestroyImageInfo(write_info); |
| 247 | return(status); |
| 248 | } |