blob: 5f748dfa53611ed3a28f24e221d80edea94b9db3 [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"
cristyfd58c252011-04-28 12:42:51 +000055#include "magick/pixel.h"
cristy3ed852e2009-09-05 21:47:34 +000056#include "magick/pixel-private.h"
57#include "magick/quantum-private.h"
58#include "magick/static.h"
59#include "magick/string_.h"
60#include "magick/module.h"
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*/
91static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
92{
93 Image
94 *image;
95
96 IndexPacket
97 index,
98 *indexes;
99
100 MagickBooleanType
101 status;
102
103 MagickPixelPacket
104 color;
105
cristy3ed852e2009-09-05 21:47:34 +0000106 PixelPacket
107 pixel;
108
cristybb503372010-05-27 20:51:26 +0000109 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000110 x;
111
112 register PixelPacket
113 *q;
114
cristyc6da28e2011-04-28 01:41:35 +0000115 ssize_t
116 y;
117
cristy3ed852e2009-09-05 21:47:34 +0000118 /*
119 Initialize Image structure.
120 */
121 assert(image_info != (const ImageInfo *) NULL);
122 assert(image_info->signature == MagickSignature);
123 if (image_info->debug != MagickFalse)
124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
125 image_info->filename);
126 assert(exception != (ExceptionInfo *) NULL);
127 assert(exception->signature == MagickSignature);
128 image=AcquireImage(image_info);
129 if (image->columns == 0)
130 image->columns=1;
131 if (image->rows == 0)
132 image->rows=1;
133 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
134 status=QueryMagickColor((char *) image_info->filename,&color,exception);
135 if (status == MagickFalse)
136 {
137 image=DestroyImage(image);
138 return((Image *) NULL);
139 }
140 image->colorspace=color.colorspace;
141 image->matte=color.matte;
142 index=0;
143 SetPixelPacket(image,&color,&pixel,&index);
cristybb503372010-05-27 20:51:26 +0000144 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000145 {
146 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
147 if (q == (PixelPacket *) NULL)
148 break;
cristybb503372010-05-27 20:51:26 +0000149 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000150 *q++=pixel;
151 if (image->colorspace == CMYKColorspace)
152 {
153 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +0000154 for (x=0; x < (ssize_t) image->columns; x++)
cristy519bf9a2011-04-28 23:37:21 +0000155 SetIndexPixelComponent(indexes+x,index);
cristy3ed852e2009-09-05 21:47:34 +0000156 }
157 if (SyncAuthenticPixels(image,exception) == MagickFalse)
158 break;
159 }
160 return(GetFirstImageInList(image));
161}
162
163/*
164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165% %
166% %
167% %
168% R e g i s t e r X C I m a g e %
169% %
170% %
171% %
172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173%
174% RegisterXCImage() adds attributes for the XC image format to
175% the list of supported formats. The attributes include the image format
176% tag, a method to read and/or write the format, whether the format
177% supports the saving of more than one frame to the same file or blob,
178% whether the format supports native in-memory I/O, and a brief
179% description of the format.
180%
181% The format of the RegisterXCImage method is:
182%
cristybb503372010-05-27 20:51:26 +0000183% size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000184%
185*/
cristybb503372010-05-27 20:51:26 +0000186ModuleExport size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000187{
188 MagickInfo
189 *entry;
190
191 entry=SetMagickInfo("XC");
192 entry->decoder=(DecodeImageHandler *) ReadXCImage;
193 entry->adjoin=MagickFalse;
cristy009d7392010-07-25 22:08:41 +0000194 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000195 entry->raw=MagickTrue;
196 entry->endian_support=MagickTrue;
197 entry->description=ConstantString("Constant image uniform color");
198 entry->module=ConstantString("XC");
199 (void) RegisterMagickInfo(entry);
cristyc05417c2010-09-21 16:30:32 +0000200 entry=SetMagickInfo("CANVAS");
201 entry->decoder=(DecodeImageHandler *) ReadXCImage;
202 entry->adjoin=MagickFalse;
203 entry->format_type=ImplicitFormatType;
204 entry->raw=MagickTrue;
205 entry->endian_support=MagickTrue;
206 entry->description=ConstantString("Constant image uniform color");
207 entry->module=ConstantString("XC");
208 (void) RegisterMagickInfo(entry);
cristy3ed852e2009-09-05 21:47:34 +0000209 return(MagickImageCoderSignature);
210}
211
212/*
213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214% %
215% %
216% %
217% U n r e g i s t e r X C I m a g e %
218% %
219% %
220% %
221%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222%
223% UnregisterXCImage() removes format registrations made by the
224% XC module from the list of supported formats.
225%
226% The format of the UnregisterXCImage method is:
227%
228% UnregisterXCImage(void)
229%
230*/
231ModuleExport void UnregisterXCImage(void)
232{
cristyc05417c2010-09-21 16:30:32 +0000233 (void) UnregisterMagickInfo("CANVAS");
cristy3ed852e2009-09-05 21:47:34 +0000234 (void) UnregisterMagickInfo("XC");
235}