cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % X X CCCC % |
| 7 | % X X C % |
| 8 | % X C % |
| 9 | % X X C % |
| 10 | % X X CCCC % |
| 11 | % % |
| 12 | % % |
| 13 | % Read Constant Color Image. % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 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/exception.h" |
| 49 | #include "magick/exception-private.h" |
| 50 | #include "magick/image.h" |
| 51 | #include "magick/image-private.h" |
| 52 | #include "magick/list.h" |
| 53 | #include "magick/magick.h" |
| 54 | #include "magick/memory_.h" |
cristy | fd58c25 | 2011-04-28 12:42:51 +0000 | [diff] [blame] | 55 | #include "magick/pixel.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 64 | % % |
| 65 | % % |
| 66 | % % |
| 67 | % R e a d X C I m a g e % |
| 68 | % % |
| 69 | % % |
| 70 | % % |
| 71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 72 | % |
| 73 | % ReadXCImage creates a constant image and initializes it to the |
| 74 | % X server color as specified by the filename. It allocates the memory |
| 75 | % necessary for the new Image structure and returns a pointer to the new |
| 76 | % image. |
| 77 | % |
| 78 | % The format of the ReadXCImage method is: |
| 79 | % |
| 80 | % Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 81 | % |
| 82 | % A description of each parameter follows: |
| 83 | % |
| 84 | % o image: The image. |
| 85 | % |
| 86 | % o image_info: the image info. |
| 87 | % |
| 88 | % o exception: return any errors or warnings in this structure. |
| 89 | % |
| 90 | */ |
| 91 | static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 92 | { |
| 93 | Image |
| 94 | *image; |
| 95 | |
| 96 | IndexPacket |
| 97 | index, |
| 98 | *indexes; |
| 99 | |
| 100 | MagickBooleanType |
| 101 | status; |
| 102 | |
| 103 | MagickPixelPacket |
| 104 | color; |
| 105 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | PixelPacket |
| 107 | pixel; |
| 108 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 109 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | x; |
| 111 | |
| 112 | register PixelPacket |
| 113 | *q; |
| 114 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 115 | ssize_t |
| 116 | y; |
| 117 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 118 | /* |
| 119 | Initialize Image structure. |
| 120 | */ |
| 121 | assert(image_info != (const ImageInfo *) NULL); |
| 122 | assert(image_info->signature == MagickSignature); |
| 123 | if (image_info->debug != MagickFalse) |
| 124 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 125 | image_info->filename); |
| 126 | assert(exception != (ExceptionInfo *) NULL); |
| 127 | assert(exception->signature == MagickSignature); |
| 128 | image=AcquireImage(image_info); |
| 129 | if (image->columns == 0) |
| 130 | image->columns=1; |
| 131 | if (image->rows == 0) |
| 132 | image->rows=1; |
| 133 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
| 134 | status=QueryMagickColor((char *) image_info->filename,&color,exception); |
| 135 | if (status == MagickFalse) |
| 136 | { |
| 137 | image=DestroyImage(image); |
| 138 | return((Image *) NULL); |
| 139 | } |
| 140 | image->colorspace=color.colorspace; |
| 141 | image->matte=color.matte; |
| 142 | index=0; |
| 143 | SetPixelPacket(image,&color,&pixel,&index); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 144 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | { |
| 146 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
| 147 | if (q == (PixelPacket *) NULL) |
| 148 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 149 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | *q++=pixel; |
| 151 | if (image->colorspace == CMYKColorspace) |
| 152 | { |
| 153 | indexes=GetAuthenticIndexQueue(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 154 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 519bf9a | 2011-04-28 23:37:21 +0000 | [diff] [blame] | 155 | SetIndexPixelComponent(indexes+x,index); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 156 | } |
| 157 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 158 | break; |
| 159 | } |
| 160 | return(GetFirstImageInList(image)); |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 165 | % % |
| 166 | % % |
| 167 | % % |
| 168 | % R e g i s t e r X C I m a g e % |
| 169 | % % |
| 170 | % % |
| 171 | % % |
| 172 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 173 | % |
| 174 | % RegisterXCImage() adds attributes for the XC image format to |
| 175 | % the list of supported formats. The attributes include the image format |
| 176 | % tag, a method to read and/or write the format, whether the format |
| 177 | % supports the saving of more than one frame to the same file or blob, |
| 178 | % whether the format supports native in-memory I/O, and a brief |
| 179 | % description of the format. |
| 180 | % |
| 181 | % The format of the RegisterXCImage method is: |
| 182 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 183 | % size_t RegisterXCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | % |
| 185 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 186 | ModuleExport size_t RegisterXCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 187 | { |
| 188 | MagickInfo |
| 189 | *entry; |
| 190 | |
| 191 | entry=SetMagickInfo("XC"); |
| 192 | entry->decoder=(DecodeImageHandler *) ReadXCImage; |
| 193 | entry->adjoin=MagickFalse; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 194 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 195 | entry->raw=MagickTrue; |
| 196 | entry->endian_support=MagickTrue; |
| 197 | entry->description=ConstantString("Constant image uniform color"); |
| 198 | entry->module=ConstantString("XC"); |
| 199 | (void) RegisterMagickInfo(entry); |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 200 | entry=SetMagickInfo("CANVAS"); |
| 201 | entry->decoder=(DecodeImageHandler *) ReadXCImage; |
| 202 | entry->adjoin=MagickFalse; |
| 203 | entry->format_type=ImplicitFormatType; |
| 204 | entry->raw=MagickTrue; |
| 205 | entry->endian_support=MagickTrue; |
| 206 | entry->description=ConstantString("Constant image uniform color"); |
| 207 | entry->module=ConstantString("XC"); |
| 208 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | return(MagickImageCoderSignature); |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 214 | % % |
| 215 | % % |
| 216 | % % |
| 217 | % U n r e g i s t e r X C I m a g e % |
| 218 | % % |
| 219 | % % |
| 220 | % % |
| 221 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 222 | % |
| 223 | % UnregisterXCImage() removes format registrations made by the |
| 224 | % XC module from the list of supported formats. |
| 225 | % |
| 226 | % The format of the UnregisterXCImage method is: |
| 227 | % |
| 228 | % UnregisterXCImage(void) |
| 229 | % |
| 230 | */ |
| 231 | ModuleExport void UnregisterXCImage(void) |
| 232 | { |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 233 | (void) UnregisterMagickInfo("CANVAS"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | (void) UnregisterMagickInfo("XC"); |
| 235 | } |