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 % Cristy %
17 % July 1992 %
18 % %
19 % %
20 % Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization %
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 % https://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 "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.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"
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 */
ReadXCImage(const ImageInfo * image_info,ExceptionInfo * exception)92 static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
93 {
94 Image
95 *image;
96
97 MagickBooleanType
98 status;
99
100 PixelInfo
101 pixel;
102
103 register ssize_t
104 x;
105
106 register Quantum
107 *q;
108
109 ssize_t
110 y;
111
112 /*
113 Initialize Image structure.
114 */
115 assert(image_info != (const ImageInfo *) NULL);
116 assert(image_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
122 image=AcquireImage(image_info,exception);
123 if (image->columns == 0)
124 image->columns=1;
125 if (image->rows == 0)
126 image->rows=1;
127 status=SetImageExtent(image,image->columns,image->rows,exception);
128 if (status == MagickFalse)
129 return(DestroyImageList(image));
130 (void) CopyMagickString(image->filename,image_info->filename,
131 MagickPathExtent);
132 if (*image_info->filename == '\0')
133 pixel=image->background_color;
134 else
135 {
136 status=QueryColorCompliance((char *) image_info->filename,AllCompliance,
137 &pixel,exception);
138 if (status == MagickFalse)
139 {
140 image=DestroyImage(image);
141 return((Image *) NULL);
142 }
143 }
144 (void) SetImageColorspace(image,pixel.colorspace,exception);
145 image->alpha_trait=pixel.alpha_trait;
146 for (y=0; y < (ssize_t) image->rows; y++)
147 {
148 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
149 if (q == (Quantum *) NULL)
150 break;
151 for (x=0; x < (ssize_t) image->columns; x++)
152 {
153 SetPixelViaPixelInfo(image,&pixel,q);
154 q+=GetPixelChannels(image);
155 }
156 if (SyncAuthenticPixels(image,exception) == MagickFalse)
157 break;
158 }
159 return(GetFirstImageInList(image));
160 }
161
162 /*
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 % %
165 % %
166 % %
167 % R e g i s t e r X C I m a g e %
168 % %
169 % %
170 % %
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 %
173 % RegisterXCImage() adds attributes for the XC image format to
174 % the list of supported formats. The attributes include the image format
175 % tag, a method to read and/or write the format, whether the format
176 % supports the saving of more than one frame to the same file or blob,
177 % whether the format supports native in-memory I/O, and a brief
178 % description of the format.
179 %
180 % The format of the RegisterXCImage method is:
181 %
182 % size_t RegisterXCImage(void)
183 %
184 */
RegisterXCImage(void)185 ModuleExport size_t RegisterXCImage(void)
186 {
187 MagickInfo
188 *entry;
189
190 entry=AcquireMagickInfo("XC","XC","Constant image uniform color");
191 entry->decoder=(DecodeImageHandler *) ReadXCImage;
192 entry->flags^=CoderAdjoinFlag;
193 entry->format_type=ImplicitFormatType;
194 entry->flags|=CoderRawSupportFlag;
195 entry->flags|=CoderEndianSupportFlag;
196 (void) RegisterMagickInfo(entry);
197 entry=AcquireMagickInfo("XC","CANVAS","Constant image uniform color");
198 entry->decoder=(DecodeImageHandler *) ReadXCImage;
199 entry->flags^=CoderAdjoinFlag;
200 entry->format_type=ImplicitFormatType;
201 entry->flags|=CoderRawSupportFlag;
202 entry->flags|=CoderEndianSupportFlag;
203 (void) RegisterMagickInfo(entry);
204 return(MagickImageCoderSignature);
205 }
206
207 /*
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 % %
210 % %
211 % %
212 % U n r e g i s t e r X C I m a g e %
213 % %
214 % %
215 % %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %
218 % UnregisterXCImage() removes format registrations made by the
219 % XC module from the list of supported formats.
220 %
221 % The format of the UnregisterXCImage method is:
222 %
223 % UnregisterXCImage(void)
224 %
225 */
UnregisterXCImage(void)226 ModuleExport void UnregisterXCImage(void)
227 {
228 (void) UnregisterMagickInfo("CANVAS");
229 (void) UnregisterMagickInfo("XC");
230 }
231