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 | */ |
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/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/image.h" |
| 51 | #include "MagickCore/image-private.h" |
| 52 | #include "MagickCore/list.h" |
| 53 | #include "MagickCore/magick.h" |
| 54 | #include "MagickCore/memory_.h" |
| 55 | #include "MagickCore/pixel.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 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 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 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 96 | MagickBooleanType |
| 97 | status; |
| 98 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 99 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 100 | color; |
| 101 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 102 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | pixel; |
| 104 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 105 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | x; |
| 107 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 108 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | *q; |
| 110 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 111 | ssize_t |
| 112 | y; |
| 113 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 114 | /* |
| 115 | Initialize Image structure. |
| 116 | */ |
| 117 | assert(image_info != (const ImageInfo *) NULL); |
| 118 | assert(image_info->signature == MagickSignature); |
| 119 | if (image_info->debug != MagickFalse) |
| 120 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 121 | image_info->filename); |
| 122 | assert(exception != (ExceptionInfo *) NULL); |
| 123 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 124 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | if (image->columns == 0) |
| 126 | image->columns=1; |
| 127 | if (image->rows == 0) |
| 128 | image->rows=1; |
| 129 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
cristy | 269c941 | 2011-10-13 23:41:15 +0000 | [diff] [blame] | 130 | status=QueryColorCompliance((char *) image_info->filename,AllCompliance, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 131 | &color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 132 | if (status == MagickFalse) |
| 133 | { |
| 134 | image=DestroyImage(image); |
| 135 | return((Image *) NULL); |
| 136 | } |
| 137 | image->colorspace=color.colorspace; |
| 138 | image->matte=color.matte; |
cristy | 28af11e | 2011-11-17 17:17:42 +0000 | [diff] [blame] | 139 | GetPixelInfo(image,&pixel); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 140 | SetPixelInfo(image,&color,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 141 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 142 | { |
| 143 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 144 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 146 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 147 | { |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 148 | SetPixelInfoPixel(image,&pixel,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 149 | if (image->colorspace == CMYKColorspace) |
| 150 | SetPixelBlack(image,pixel.black,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 151 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 152 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 154 | break; |
| 155 | } |
| 156 | return(GetFirstImageInList(image)); |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 161 | % % |
| 162 | % % |
| 163 | % % |
| 164 | % R e g i s t e r X C I m a g e % |
| 165 | % % |
| 166 | % % |
| 167 | % % |
| 168 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 169 | % |
| 170 | % RegisterXCImage() adds attributes for the XC image format to |
| 171 | % the list of supported formats. The attributes include the image format |
| 172 | % tag, a method to read and/or write the format, whether the format |
| 173 | % supports the saving of more than one frame to the same file or blob, |
| 174 | % whether the format supports native in-memory I/O, and a brief |
| 175 | % description of the format. |
| 176 | % |
| 177 | % The format of the RegisterXCImage method is: |
| 178 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 179 | % size_t RegisterXCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | % |
| 181 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 182 | ModuleExport size_t RegisterXCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | { |
| 184 | MagickInfo |
| 185 | *entry; |
| 186 | |
| 187 | entry=SetMagickInfo("XC"); |
| 188 | entry->decoder=(DecodeImageHandler *) ReadXCImage; |
| 189 | entry->adjoin=MagickFalse; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 190 | entry->format_type=ImplicitFormatType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 191 | entry->raw=MagickTrue; |
| 192 | entry->endian_support=MagickTrue; |
| 193 | entry->description=ConstantString("Constant image uniform color"); |
| 194 | entry->module=ConstantString("XC"); |
| 195 | (void) RegisterMagickInfo(entry); |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 196 | entry=SetMagickInfo("CANVAS"); |
| 197 | entry->decoder=(DecodeImageHandler *) ReadXCImage; |
| 198 | entry->adjoin=MagickFalse; |
| 199 | entry->format_type=ImplicitFormatType; |
| 200 | entry->raw=MagickTrue; |
| 201 | entry->endian_support=MagickTrue; |
| 202 | entry->description=ConstantString("Constant image uniform color"); |
| 203 | entry->module=ConstantString("XC"); |
| 204 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 205 | return(MagickImageCoderSignature); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 210 | % % |
| 211 | % % |
| 212 | % % |
| 213 | % U n r e g i s t e r X C I m a g e % |
| 214 | % % |
| 215 | % % |
| 216 | % % |
| 217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 218 | % |
| 219 | % UnregisterXCImage() removes format registrations made by the |
| 220 | % XC module from the list of supported formats. |
| 221 | % |
| 222 | % The format of the UnregisterXCImage method is: |
| 223 | % |
| 224 | % UnregisterXCImage(void) |
| 225 | % |
| 226 | */ |
| 227 | ModuleExport void UnregisterXCImage(void) |
| 228 | { |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 229 | (void) UnregisterMagickInfo("CANVAS"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 230 | (void) UnregisterMagickInfo("XC"); |
| 231 | } |