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 % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 20 | % Copyright 1999-2010 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 | */ |
| 42 | #include "magick/studio.h" |
| 43 | #include "magick/blob.h" |
| 44 | #include "magick/blob-private.h" |
| 45 | #include "magick/cache.h" |
| 46 | #include "magick/color.h" |
| 47 | #include "magick/color-private.h" |
| 48 | #include "magick/colorspace-private.h" |
| 49 | #include "magick/exception.h" |
| 50 | #include "magick/exception-private.h" |
| 51 | #include "magick/image.h" |
| 52 | #include "magick/image-private.h" |
| 53 | #include "magick/list.h" |
| 54 | #include "magick/magick.h" |
| 55 | #include "magick/memory_.h" |
| 56 | #include "magick/pixel-private.h" |
| 57 | #include "magick/quantum-private.h" |
| 58 | #include "magick/static.h" |
| 59 | #include "magick/string_.h" |
| 60 | #include "magick/module.h" |
| 61 | |
| 62 | /* |
| 63 | Forward declarations. |
| 64 | */ |
| 65 | static MagickBooleanType |
| 66 | WriteNULLImage(const ImageInfo *,Image *); |
| 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 | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 102 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | y; |
| 104 | |
| 105 | MagickPixelPacket |
| 106 | background; |
| 107 | |
| 108 | register IndexPacket |
| 109 | *indexes; |
| 110 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 111 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | x; |
| 113 | |
| 114 | register PixelPacket |
| 115 | *q; |
| 116 | |
| 117 | /* |
| 118 | Initialize Image structure. |
| 119 | */ |
| 120 | assert(image_info != (const ImageInfo *) NULL); |
| 121 | assert(image_info->signature == MagickSignature); |
| 122 | if (image_info->debug != MagickFalse) |
| 123 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 124 | image_info->filename); |
| 125 | assert(exception != (ExceptionInfo *) NULL); |
| 126 | assert(exception->signature == MagickSignature); |
| 127 | image=AcquireImage(image_info); |
| 128 | if (image->columns == 0) |
| 129 | image->columns=1; |
| 130 | if (image->rows == 0) |
| 131 | image->rows=1; |
| 132 | image->matte=MagickTrue; |
| 133 | GetMagickPixelPacket(image,&background); |
| 134 | background.opacity=(MagickRealType) TransparentOpacity; |
| 135 | if (image->colorspace == CMYKColorspace) |
| 136 | ConvertRGBToCMYK(&background); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 137 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 138 | { |
| 139 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 140 | if (q == (PixelPacket *) NULL) |
| 141 | break; |
| 142 | indexes=GetAuthenticIndexQueue(image); |
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 | { |
| 145 | SetPixelPacket(image,&background,q,indexes); |
| 146 | q++; |
| 147 | indexes++; |
| 148 | } |
| 149 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 150 | break; |
| 151 | } |
| 152 | return(GetFirstImageInList(image)); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 157 | % % |
| 158 | % % |
| 159 | % % |
| 160 | % R e g i s t e r N U L L I m a g e % |
| 161 | % % |
| 162 | % % |
| 163 | % % |
| 164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 165 | % |
| 166 | % RegisterNULLImage() adds attributes for the NULL image format to |
| 167 | % the list of supported formats. The attributes include the image format |
| 168 | % tag, a method to read and/or write the format, whether the format |
| 169 | % supports the saving of more than one frame to the same file or blob, |
| 170 | % whether the format supports native in-memory I/O, and a brief |
| 171 | % description of the format. |
| 172 | % |
| 173 | % The format of the RegisterNULLImage method is: |
| 174 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 175 | % size_t RegisterNULLImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | % |
| 177 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 178 | ModuleExport size_t RegisterNULLImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 179 | { |
| 180 | MagickInfo |
| 181 | *entry; |
| 182 | |
| 183 | entry=SetMagickInfo("NULL"); |
| 184 | entry->decoder=(DecodeImageHandler *) ReadNULLImage; |
| 185 | entry->encoder=(EncodeImageHandler *) WriteNULLImage; |
| 186 | entry->adjoin=MagickFalse; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 187 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | entry->description=ConstantString("Constant image of uniform color"); |
| 189 | entry->module=ConstantString("NULL"); |
| 190 | (void) RegisterMagickInfo(entry); |
| 191 | return(MagickImageCoderSignature); |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 196 | % % |
| 197 | % % |
| 198 | % % |
| 199 | % U n r e g i s t e r N U L L I m a g e % |
| 200 | % % |
| 201 | % % |
| 202 | % % |
| 203 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 204 | % |
| 205 | % UnregisterNULLImage() removes format registrations made by the |
| 206 | % NULL module from the list of supported formats. |
| 207 | % |
| 208 | % The format of the UnregisterNULLImage method is: |
| 209 | % |
| 210 | % UnregisterNULLImage(void) |
| 211 | % |
| 212 | */ |
| 213 | ModuleExport void UnregisterNULLImage(void) |
| 214 | { |
| 215 | (void) UnregisterMagickInfo("NULL"); |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 220 | % % |
| 221 | % % |
| 222 | % % |
| 223 | % W r i t e N U L L I m a g e % |
| 224 | % % |
| 225 | % % |
| 226 | % % |
| 227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 228 | % |
| 229 | % WriteNULLImage writes no output at all. It is useful when specified |
| 230 | % as an output format when profiling. |
| 231 | % |
| 232 | % The format of the WriteNULLImage method is: |
| 233 | % |
| 234 | % MagickBooleanType WriteNULLImage(const ImageInfo *image_info, |
| 235 | % Image *image) |
| 236 | % |
| 237 | % A description of each parameter follows. |
| 238 | % |
| 239 | % o image_info: the image info. |
| 240 | % |
| 241 | % o image: The image. |
| 242 | % |
| 243 | */ |
| 244 | static MagickBooleanType WriteNULLImage(const ImageInfo *image_info, |
| 245 | Image *image) |
| 246 | { |
| 247 | assert(image_info != (const ImageInfo *) NULL); |
| 248 | assert(image_info->signature == MagickSignature); |
| 249 | assert(image != (Image *) NULL); |
| 250 | assert(image->signature == MagickSignature); |
| 251 | if (image->debug != MagickFalse) |
| 252 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 253 | return(MagickTrue); |
| 254 | } |