cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % M M AAA TTTTT TTTTT EEEEE % |
| 7 | % MM MM A A T T E % |
| 8 | % M M M AAAAA T T EEE % |
| 9 | % M M A A T T E % |
| 10 | % M M A A T T EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % Write Matte Channel 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 | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 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 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 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 | 8941c70 | 2012-06-21 01:30:15 +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/cache.h" |
| 47 | #include "MagickCore/constitute.h" |
| 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/image-private.h" |
| 51 | #include "MagickCore/list.h" |
| 52 | #include "MagickCore/magick.h" |
| 53 | #include "MagickCore/memory_.h" |
| 54 | #include "MagickCore/monitor.h" |
| 55 | #include "MagickCore/monitor-private.h" |
| 56 | #include "MagickCore/pixel-accessor.h" |
| 57 | #include "MagickCore/quantum-private.h" |
| 58 | #include "MagickCore/static.h" |
| 59 | #include "MagickCore/string_.h" |
| 60 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | Forward declarations. |
| 64 | */ |
| 65 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 66 | WriteMATTEImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 70 | % % |
| 71 | % % |
| 72 | % % |
| 73 | % R e g i s t e r M A T T E I m a g e % |
| 74 | % % |
| 75 | % % |
| 76 | % % |
| 77 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 78 | % |
| 79 | % RegisterMATTEImage() adds attributes for the MATTE image format to |
| 80 | % the list of supported formats. The attributes include the image format |
| 81 | % tag, a method to read and/or write the format, whether the format |
| 82 | % supports the saving of more than one frame to the same file or blob, |
| 83 | % whether the format supports native in-memory I/O, and a brief |
| 84 | % description of the format. |
| 85 | % |
| 86 | % The format of the RegisterMATTEImage method is: |
| 87 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 88 | % size_t RegisterMATTEImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 89 | % |
| 90 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 91 | ModuleExport size_t RegisterMATTEImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 92 | { |
| 93 | MagickInfo |
| 94 | *entry; |
| 95 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 96 | entry=AcquireMagickInfo("MATTE","MATTE","MATTE format"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 97 | entry->encoder=(EncodeImageHandler *) WriteMATTEImage; |
| 98 | entry->format_type=ExplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 99 | (void) RegisterMagickInfo(entry); |
| 100 | return(MagickImageCoderSignature); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 105 | % % |
| 106 | % % |
| 107 | % % |
| 108 | % U n r e g i s t e r M A T T E I m a g e % |
| 109 | % % |
| 110 | % % |
| 111 | % % |
| 112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 113 | % |
| 114 | % UnregisterMATTEImage() removes format registrations made by the |
| 115 | % MATTE module from the list of supported formats. |
| 116 | % |
| 117 | % The format of the UnregisterMATTEImage method is: |
| 118 | % |
| 119 | % UnregisterMATTEImage(void) |
| 120 | % |
| 121 | */ |
| 122 | ModuleExport void UnregisterMATTEImage(void) |
| 123 | { |
| 124 | (void) UnregisterMagickInfo("MATTE"); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 129 | % % |
| 130 | % % |
| 131 | % % |
| 132 | % W r i t e M A T T E I m a g e % |
| 133 | % % |
| 134 | % % |
| 135 | % % |
| 136 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 137 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 138 | % WriteMATTEImage() writes an image of matte bytes to a file. It consists of |
| 139 | % data from the matte component of the image [0..255]. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | % |
| 141 | % The format of the WriteMATTEImage method is: |
| 142 | % |
| 143 | % MagickBooleanType WriteMATTEImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 144 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | % |
| 146 | % A description of each parameter follows. |
| 147 | % |
| 148 | % o image_info: the image info. |
| 149 | % |
| 150 | % o image: The image. |
| 151 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 152 | % o exception: return any errors or warnings in this structure. |
| 153 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 154 | */ |
| 155 | static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 156 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | Image |
| 159 | *matte_image; |
| 160 | |
cristy | 6f4e48c | 2015-02-25 12:11:24 +0000 | [diff] [blame] | 161 | ImageInfo |
| 162 | *write_info; |
| 163 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 164 | MagickBooleanType |
| 165 | status; |
| 166 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 167 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 168 | *p; |
| 169 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 170 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | x; |
| 172 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 173 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 174 | *q; |
| 175 | |
cristy | 524222d | 2011-04-25 00:37:06 +0000 | [diff] [blame] | 176 | ssize_t |
| 177 | y; |
| 178 | |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 179 | if (image->alpha_trait == UndefinedPixelTrait) |
cristy | b496b77 | 2013-05-27 14:13:40 +0000 | [diff] [blame] | 180 | ThrowWriterException(CoderError,"ImageDoesNotHaveAnAlphaChannel"); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 181 | matte_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | if (matte_image == (Image *) NULL) |
| 183 | return(MagickFalse); |
cristy | def23e5 | 2015-01-22 11:52:01 +0000 | [diff] [blame] | 184 | (void) SetImageType(matte_image,TrueColorAlphaType,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 185 | matte_image->alpha_trait=UndefinedPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | /* |
| 187 | Convert image to matte pixels. |
| 188 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 189 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | { |
| 191 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 192 | q=QueueAuthenticPixels(matte_image,0,y,matte_image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 193 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 194 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 195 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 196 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 197 | SetPixelRed(matte_image,GetPixelAlpha(image,p),q); |
| 198 | SetPixelGreen(matte_image,GetPixelAlpha(image,p),q); |
| 199 | SetPixelBlue(matte_image,GetPixelAlpha(image,p),q); |
| 200 | SetPixelAlpha(matte_image,OpaqueAlpha,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 201 | p+=GetPixelChannels(image); |
| 202 | q+=GetPixelChannels(matte_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 203 | } |
| 204 | if (SyncAuthenticPixels(matte_image,exception) == MagickFalse) |
| 205 | break; |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 206 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 524222d | 2011-04-25 00:37:06 +0000 | [diff] [blame] | 207 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 208 | if (status == MagickFalse) |
| 209 | break; |
| 210 | } |
cristy | 6f4e48c | 2015-02-25 12:11:24 +0000 | [diff] [blame] | 211 | write_info=CloneImageInfo(image_info); |
cristy | f1aa02e | 2015-03-31 13:54:11 +0000 | [diff] [blame] | 212 | if (LocaleCompare(write_info->magick,"MATTE") == 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 213 | (void) FormatLocaleString(matte_image->filename,MagickPathExtent, |
cristy | f1aa02e | 2015-03-31 13:54:11 +0000 | [diff] [blame] | 214 | "MIFF:%s",image->filename); |
cristy | 6f4e48c | 2015-02-25 12:11:24 +0000 | [diff] [blame] | 215 | status=WriteImage(write_info,matte_image,exception); |
| 216 | write_info=DestroyImageInfo(write_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 217 | matte_image=DestroyImage(matte_image); |
| 218 | return(status); |
| 219 | } |