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 % |
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 | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 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" |
cristy | 1b9a5f5 | 2013-10-16 01:37:17 +0000 | [diff] [blame] | 48 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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.h" |
| 57 | #include "MagickCore/pixel-accessor.h" |
| 58 | #include "MagickCore/quantum-private.h" |
| 59 | #include "MagickCore/static.h" |
| 60 | #include "MagickCore/string_.h" |
| 61 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 65 | % % |
| 66 | % % |
| 67 | % % |
| 68 | % R e a d X C I m a g e % |
| 69 | % % |
| 70 | % % |
| 71 | % % |
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | % |
| 74 | % ReadXCImage creates a constant image and initializes it to the |
| 75 | % X server color as specified by the filename. It allocates the memory |
| 76 | % necessary for the new Image structure and returns a pointer to the new |
| 77 | % image. |
| 78 | % |
| 79 | % The format of the ReadXCImage method is: |
| 80 | % |
| 81 | % Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 82 | % |
| 83 | % A description of each parameter follows: |
| 84 | % |
| 85 | % o image: The image. |
| 86 | % |
| 87 | % o image_info: the image info. |
| 88 | % |
| 89 | % o exception: return any errors or warnings in this structure. |
| 90 | % |
| 91 | */ |
| 92 | static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 93 | { |
| 94 | Image |
| 95 | *image; |
| 96 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 97 | MagickBooleanType |
| 98 | status; |
| 99 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 100 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | pixel; |
| 102 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 103 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 104 | x; |
| 105 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 106 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 107 | *q; |
| 108 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 109 | ssize_t |
| 110 | y; |
| 111 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | /* |
| 113 | Initialize Image structure. |
| 114 | */ |
| 115 | assert(image_info != (const ImageInfo *) NULL); |
| 116 | assert(image_info->signature == MagickSignature); |
| 117 | if (image_info->debug != MagickFalse) |
| 118 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 119 | image_info->filename); |
| 120 | assert(exception != (ExceptionInfo *) NULL); |
| 121 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 122 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | if (image->columns == 0) |
| 124 | image->columns=1; |
| 125 | if (image->rows == 0) |
| 126 | image->rows=1; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 127 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 128 | if (status == MagickFalse) |
| 129 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 130 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
cristy | 3358e73 | 2012-07-16 12:34:08 +0000 | [diff] [blame] | 131 | if (*image_info->filename == '\0') |
| 132 | pixel=image->background_color; |
| 133 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | { |
cristy | 3358e73 | 2012-07-16 12:34:08 +0000 | [diff] [blame] | 135 | status=QueryColorCompliance((char *) image_info->filename,AllCompliance, |
| 136 | &pixel,exception); |
| 137 | if (status == MagickFalse) |
| 138 | { |
| 139 | image=DestroyImage(image); |
| 140 | return((Image *) NULL); |
| 141 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 142 | } |
cristy | 1b9a5f5 | 2013-10-16 01:37:17 +0000 | [diff] [blame] | 143 | (void) SetImageColorspace(image,pixel.colorspace,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 144 | image->alpha_trait=pixel.alpha_trait; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 145 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 146 | { |
| 147 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 148 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 149 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 150 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 151 | { |
cristy | 11a06d3 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 152 | SetPixelViaPixelInfo(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 153 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 154 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 156 | break; |
| 157 | } |
| 158 | return(GetFirstImageInList(image)); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 163 | % % |
| 164 | % % |
| 165 | % % |
| 166 | % R e g i s t e r X C I m a g e % |
| 167 | % % |
| 168 | % % |
| 169 | % % |
| 170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 171 | % |
| 172 | % RegisterXCImage() adds attributes for the XC image format to |
| 173 | % the list of supported formats. The attributes include the image format |
| 174 | % tag, a method to read and/or write the format, whether the format |
| 175 | % supports the saving of more than one frame to the same file or blob, |
| 176 | % whether the format supports native in-memory I/O, and a brief |
| 177 | % description of the format. |
| 178 | % |
| 179 | % The format of the RegisterXCImage method is: |
| 180 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 181 | % size_t RegisterXCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | % |
| 183 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 184 | ModuleExport size_t RegisterXCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | { |
| 186 | MagickInfo |
| 187 | *entry; |
| 188 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame^] | 189 | entry=AcquireMagickInfo("XC","XC","Constant image uniform color"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | entry->decoder=(DecodeImageHandler *) ReadXCImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 191 | entry->flags^=CoderAdjoinFlag; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 192 | entry->format_type=ImplicitFormatType; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 193 | entry->flags|=CoderRawSupportFlag; |
| 194 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 195 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame^] | 196 | entry=AcquireMagickInfo("XC","CANVAS","Constant image uniform color"); |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 197 | entry->decoder=(DecodeImageHandler *) ReadXCImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 198 | entry->flags^=CoderAdjoinFlag; |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 199 | entry->format_type=ImplicitFormatType; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 200 | entry->flags|=CoderRawSupportFlag; |
| 201 | entry->flags|=CoderEndianSupportFlag; |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 202 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 203 | return(MagickImageCoderSignature); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 208 | % % |
| 209 | % % |
| 210 | % % |
| 211 | % U n r e g i s t e r X C I m a g e % |
| 212 | % % |
| 213 | % % |
| 214 | % % |
| 215 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 216 | % |
| 217 | % UnregisterXCImage() removes format registrations made by the |
| 218 | % XC module from the list of supported formats. |
| 219 | % |
| 220 | % The format of the UnregisterXCImage method is: |
| 221 | % |
| 222 | % UnregisterXCImage(void) |
| 223 | % |
| 224 | */ |
| 225 | ModuleExport void UnregisterXCImage(void) |
| 226 | { |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 227 | (void) UnregisterMagickInfo("CANVAS"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 228 | (void) UnregisterMagickInfo("XC"); |
| 229 | } |