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