cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % N N U U L L % |
| 7 | % NN N U U L L % |
| 8 | % N N N U U L L % |
| 9 | % N NN U U L L % |
| 10 | % N N UUU LLLLL LLLLL % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Image Of Uniform Color. % |
| 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" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/color.h" |
| 47 | #include "MagickCore/color-private.h" |
| 48 | #include "MagickCore/colorspace-private.h" |
| 49 | #include "MagickCore/exception.h" |
| 50 | #include "MagickCore/exception-private.h" |
| 51 | #include "MagickCore/image.h" |
| 52 | #include "MagickCore/image-private.h" |
| 53 | #include "MagickCore/list.h" |
| 54 | #include "MagickCore/magick.h" |
| 55 | #include "MagickCore/memory_.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 | WriteNULLImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 70 | % % |
| 71 | % % |
| 72 | % % |
| 73 | % R e a d N U L L I m a g e % |
| 74 | % % |
| 75 | % % |
| 76 | % % |
| 77 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 78 | % |
| 79 | % ReadNULLImage creates a constant image and initializes it to the |
| 80 | % X server color as specified by the filename. It allocates the memory |
| 81 | % necessary for the new Image structure and returns a pointer to the new |
| 82 | % image. |
| 83 | % |
| 84 | % The format of the ReadNULLImage method is: |
| 85 | % |
| 86 | % Image *ReadNULLImage(const ImageInfo *image_info, |
| 87 | % ExceptionInfo *exception) |
| 88 | % |
| 89 | % A description of each parameter follows: |
| 90 | % |
| 91 | % o image_info: the image info. |
| 92 | % |
| 93 | % o exception: return any errors or warnings in this structure. |
| 94 | % |
| 95 | */ |
| 96 | static Image *ReadNULLImage(const ImageInfo *image_info, |
| 97 | ExceptionInfo *exception) |
| 98 | { |
| 99 | Image |
| 100 | *image; |
| 101 | |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 102 | MagickBooleanType |
| 103 | status; |
| 104 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 105 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | background; |
| 107 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 108 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | x; |
| 110 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 111 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | *q; |
| 113 | |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 114 | ssize_t |
| 115 | y; |
| 116 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 117 | /* |
| 118 | Initialize Image structure. |
| 119 | */ |
| 120 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 121 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | if (image_info->debug != MagickFalse) |
| 123 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 124 | image_info->filename); |
| 125 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 126 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 127 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | if (image->columns == 0) |
| 129 | image->columns=1; |
| 130 | if (image->rows == 0) |
| 131 | image->rows=1; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 132 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 133 | if (status == MagickFalse) |
| 134 | return(DestroyImageList(image)); |
dirk | bfdd5bc | 2014-11-04 19:47:44 +0000 | [diff] [blame] | 135 | ConformPixelInfo(image,&image->background_color,&background,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 136 | image->alpha_trait=BlendPixelTrait; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 137 | background.alpha=(double) TransparentAlpha; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 138 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 139 | { |
| 140 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 141 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 142 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 143 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 144 | { |
cristy | 11a06d3 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 145 | SetPixelViaPixelInfo(image,&background,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 146 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 147 | } |
| 148 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 149 | break; |
| 150 | } |
| 151 | return(GetFirstImageInList(image)); |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 156 | % % |
| 157 | % % |
| 158 | % % |
| 159 | % R e g i s t e r N U L L I m a g e % |
| 160 | % % |
| 161 | % % |
| 162 | % % |
| 163 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 164 | % |
| 165 | % RegisterNULLImage() adds attributes for the NULL image format to |
| 166 | % the list of supported formats. The attributes include the image format |
| 167 | % tag, a method to read and/or write the format, whether the format |
| 168 | % supports the saving of more than one frame to the same file or blob, |
| 169 | % whether the format supports native in-memory I/O, and a brief |
| 170 | % description of the format. |
| 171 | % |
| 172 | % The format of the RegisterNULLImage method is: |
| 173 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 174 | % size_t RegisterNULLImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | % |
| 176 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 177 | ModuleExport size_t RegisterNULLImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 178 | { |
| 179 | MagickInfo |
| 180 | *entry; |
| 181 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 182 | entry=AcquireMagickInfo("NULL","NULL","Constant image of uniform color"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | entry->decoder=(DecodeImageHandler *) ReadNULLImage; |
| 184 | entry->encoder=(EncodeImageHandler *) WriteNULLImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 185 | entry->flags^=CoderAdjoinFlag; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 186 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 187 | (void) RegisterMagickInfo(entry); |
| 188 | return(MagickImageCoderSignature); |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 193 | % % |
| 194 | % % |
| 195 | % % |
| 196 | % U n r e g i s t e r N U L L I m a g e % |
| 197 | % % |
| 198 | % % |
| 199 | % % |
| 200 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 201 | % |
| 202 | % UnregisterNULLImage() removes format registrations made by the |
| 203 | % NULL module from the list of supported formats. |
| 204 | % |
| 205 | % The format of the UnregisterNULLImage method is: |
| 206 | % |
| 207 | % UnregisterNULLImage(void) |
| 208 | % |
| 209 | */ |
| 210 | ModuleExport void UnregisterNULLImage(void) |
| 211 | { |
| 212 | (void) UnregisterMagickInfo("NULL"); |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 217 | % % |
| 218 | % % |
| 219 | % % |
| 220 | % W r i t e N U L L I m a g e % |
| 221 | % % |
| 222 | % % |
| 223 | % % |
| 224 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 225 | % |
| 226 | % WriteNULLImage writes no output at all. It is useful when specified |
| 227 | % as an output format when profiling. |
| 228 | % |
| 229 | % The format of the WriteNULLImage method is: |
| 230 | % |
| 231 | % MagickBooleanType WriteNULLImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 232 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | % |
| 234 | % A description of each parameter follows. |
| 235 | % |
| 236 | % o image_info: the image info. |
| 237 | % |
| 238 | % o image: The image. |
| 239 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 240 | % o exception: return any errors or warnings in this structure. |
| 241 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 242 | */ |
| 243 | static MagickBooleanType WriteNULLImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 244 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | { |
| 246 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 247 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 248 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 249 | assert(image->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 250 | assert(exception != (ExceptionInfo *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 251 | if (image->debug != MagickFalse) |
| 252 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 253 | return(MagickTrue); |
| 254 | } |