blob: d8cb1d28389a961464ab45ac71b2ff8d9bf68070 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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"
55#include "magick/pixel-private.h"
56#include "magick/quantum-private.h"
57#include "magick/static.h"
58#include "magick/string_.h"
59#include "magick/module.h"
60
61/*
62%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63% %
64% %
65% %
66% R e a d X C I m a g e %
67% %
68% %
69% %
70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71%
72% ReadXCImage creates a constant image and initializes it to the
73% X server color as specified by the filename. It allocates the memory
74% necessary for the new Image structure and returns a pointer to the new
75% image.
76%
77% The format of the ReadXCImage method is:
78%
79% Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
80%
81% A description of each parameter follows:
82%
83% o image: The image.
84%
85% o image_info: the image info.
86%
87% o exception: return any errors or warnings in this structure.
88%
89*/
90static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
91{
92 Image
93 *image;
94
95 IndexPacket
96 index,
97 *indexes;
98
99 MagickBooleanType
100 status;
101
102 MagickPixelPacket
103 color;
104
cristy3ed852e2009-09-05 21:47:34 +0000105 PixelPacket
106 pixel;
107
cristybb503372010-05-27 20:51:26 +0000108 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000109 x;
110
111 register PixelPacket
112 *q;
113
cristyc6da28e2011-04-28 01:41:35 +0000114 ssize_t
115 y;
116
cristy3ed852e2009-09-05 21:47:34 +0000117 /*
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 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
133 status=QueryMagickColor((char *) image_info->filename,&color,exception);
134 if (status == MagickFalse)
135 {
136 image=DestroyImage(image);
137 return((Image *) NULL);
138 }
139 image->colorspace=color.colorspace;
140 image->matte=color.matte;
141 index=0;
142 SetPixelPacket(image,&color,&pixel,&index);
cristybb503372010-05-27 20:51:26 +0000143 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000144 {
145 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
146 if (q == (PixelPacket *) NULL)
147 break;
cristybb503372010-05-27 20:51:26 +0000148 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000149 *q++=pixel;
150 if (image->colorspace == CMYKColorspace)
151 {
152 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +0000153 for (x=0; x < (ssize_t) image->columns; x++)
cristyc6da28e2011-04-28 01:41:35 +0000154 SetIndexPixelComponetn(indexes+x,index);
cristy3ed852e2009-09-05 21:47:34 +0000155 }
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%
cristybb503372010-05-27 20:51:26 +0000182% size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000183%
184*/
cristybb503372010-05-27 20:51:26 +0000185ModuleExport size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000186{
187 MagickInfo
188 *entry;
189
190 entry=SetMagickInfo("XC");
191 entry->decoder=(DecodeImageHandler *) ReadXCImage;
192 entry->adjoin=MagickFalse;
cristy009d7392010-07-25 22:08:41 +0000193 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000194 entry->raw=MagickTrue;
195 entry->endian_support=MagickTrue;
196 entry->description=ConstantString("Constant image uniform color");
197 entry->module=ConstantString("XC");
198 (void) RegisterMagickInfo(entry);
cristyc05417c2010-09-21 16:30:32 +0000199 entry=SetMagickInfo("CANVAS");
200 entry->decoder=(DecodeImageHandler *) ReadXCImage;
201 entry->adjoin=MagickFalse;
202 entry->format_type=ImplicitFormatType;
203 entry->raw=MagickTrue;
204 entry->endian_support=MagickTrue;
205 entry->description=ConstantString("Constant image uniform color");
206 entry->module=ConstantString("XC");
207 (void) RegisterMagickInfo(entry);
cristy3ed852e2009-09-05 21:47:34 +0000208 return(MagickImageCoderSignature);
209}
210
211/*
212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213% %
214% %
215% %
216% U n r e g i s t e r X C I m a g e %
217% %
218% %
219% %
220%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221%
222% UnregisterXCImage() removes format registrations made by the
223% XC module from the list of supported formats.
224%
225% The format of the UnregisterXCImage method is:
226%
227% UnregisterXCImage(void)
228%
229*/
230ModuleExport void UnregisterXCImage(void)
231{
cristyc05417c2010-09-21 16:30:32 +0000232 (void) UnregisterMagickInfo("CANVAS");
cristy3ed852e2009-09-05 21:47:34 +0000233 (void) UnregisterMagickInfo("XC");
234}