blob: 7cd4c03df1fb9ea03907c8c06db735f6eadb7e3d [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% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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
105 long
106 y;
107
108 PixelPacket
109 pixel;
110
111 register long
112 x;
113
114 register PixelPacket
115 *q;
116
117 /*
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);
143 for (y=0; y < (long) image->rows; y++)
144 {
145 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
146 if (q == (PixelPacket *) NULL)
147 break;
148 for (x=0; x < (long) image->columns; x++)
149 *q++=pixel;
150 if (image->colorspace == CMYKColorspace)
151 {
152 indexes=GetAuthenticIndexQueue(image);
153 for (x=0; x < (long) image->columns; x++)
154 indexes[x]=index;
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% unsigned long RegisterXCImage(void)
183%
184*/
185ModuleExport unsigned long RegisterXCImage(void)
186{
187 MagickInfo
188 *entry;
189
190 entry=SetMagickInfo("XC");
191 entry->decoder=(DecodeImageHandler *) ReadXCImage;
192 entry->adjoin=MagickFalse;
193 entry->format_type=ExplicitFormatType;
194 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);
199 return(MagickImageCoderSignature);
200}
201
202/*
203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204% %
205% %
206% %
207% U n r e g i s t e r X C I m a g e %
208% %
209% %
210% %
211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212%
213% UnregisterXCImage() removes format registrations made by the
214% XC module from the list of supported formats.
215%
216% The format of the UnregisterXCImage method is:
217%
218% UnregisterXCImage(void)
219%
220*/
221ModuleExport void UnregisterXCImage(void)
222{
223 (void) UnregisterMagickInfo("XC");
224}