blob: 602542bb22f42a1ddba6182baeb3a3e0cdfa2ba4 [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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
cristyfe676ee2013-11-18 13:03:38 +000020% Copyright 1999-2014 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#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"
cristy1b9a5f52013-10-16 01:37:17 +000048#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000049#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"
cristy3ed852e2009-09-05 21:47:34 +000062
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*/
92static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
93{
94 Image
95 *image;
96
cristy3ed852e2009-09-05 21:47:34 +000097 MagickBooleanType
98 status;
99
cristy4c08aed2011-07-01 19:47:50 +0000100 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000101 pixel;
102
cristybb503372010-05-27 20:51:26 +0000103 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000104 x;
105
cristy4c08aed2011-07-01 19:47:50 +0000106 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000107 *q;
108
cristyc6da28e2011-04-28 01:41:35 +0000109 ssize_t
110 y;
111
cristy3ed852e2009-09-05 21:47:34 +0000112 /*
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);
cristy9950d572011-10-01 18:22:35 +0000122 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000123 if (image->columns == 0)
124 image->columns=1;
125 if (image->rows == 0)
126 image->rows=1;
127 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
cristy3358e732012-07-16 12:34:08 +0000128 if (*image_info->filename == '\0')
129 pixel=image->background_color;
130 else
cristy3ed852e2009-09-05 21:47:34 +0000131 {
cristy3358e732012-07-16 12:34:08 +0000132 status=QueryColorCompliance((char *) image_info->filename,AllCompliance,
133 &pixel,exception);
134 if (status == MagickFalse)
135 {
136 image=DestroyImage(image);
137 return((Image *) NULL);
138 }
cristy3ed852e2009-09-05 21:47:34 +0000139 }
cristy1b9a5f52013-10-16 01:37:17 +0000140 (void) SetImageColorspace(image,pixel.colorspace,exception);
cristy8a46d822012-08-28 23:32:39 +0000141 image->alpha_trait=pixel.alpha_trait;
cristybb503372010-05-27 20:51:26 +0000142 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000143 {
144 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000145 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000146 break;
cristybb503372010-05-27 20:51:26 +0000147 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +0000148 {
cristy803640d2011-11-17 02:11:32 +0000149 SetPixelInfoPixel(image,&pixel,q);
cristyed231572011-07-14 02:18:59 +0000150 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000151 }
cristy3ed852e2009-09-05 21:47:34 +0000152 if (SyncAuthenticPixels(image,exception) == MagickFalse)
153 break;
154 }
155 return(GetFirstImageInList(image));
156}
157
158/*
159%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160% %
161% %
162% %
163% R e g i s t e r X C I m a g e %
164% %
165% %
166% %
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168%
169% RegisterXCImage() adds attributes for the XC image format to
170% the list of supported formats. The attributes include the image format
171% tag, a method to read and/or write the format, whether the format
172% supports the saving of more than one frame to the same file or blob,
173% whether the format supports native in-memory I/O, and a brief
174% description of the format.
175%
176% The format of the RegisterXCImage method is:
177%
cristybb503372010-05-27 20:51:26 +0000178% size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000179%
180*/
cristybb503372010-05-27 20:51:26 +0000181ModuleExport size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000182{
183 MagickInfo
184 *entry;
185
186 entry=SetMagickInfo("XC");
187 entry->decoder=(DecodeImageHandler *) ReadXCImage;
188 entry->adjoin=MagickFalse;
cristy009d7392010-07-25 22:08:41 +0000189 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000190 entry->raw=MagickTrue;
191 entry->endian_support=MagickTrue;
192 entry->description=ConstantString("Constant image uniform color");
193 entry->module=ConstantString("XC");
194 (void) RegisterMagickInfo(entry);
cristyc05417c2010-09-21 16:30:32 +0000195 entry=SetMagickInfo("CANVAS");
196 entry->decoder=(DecodeImageHandler *) ReadXCImage;
197 entry->adjoin=MagickFalse;
198 entry->format_type=ImplicitFormatType;
199 entry->raw=MagickTrue;
200 entry->endian_support=MagickTrue;
201 entry->description=ConstantString("Constant image uniform color");
202 entry->module=ConstantString("XC");
203 (void) RegisterMagickInfo(entry);
cristy3ed852e2009-09-05 21:47:34 +0000204 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*/
226ModuleExport void UnregisterXCImage(void)
227{
cristyc05417c2010-09-21 16:30:32 +0000228 (void) UnregisterMagickInfo("CANVAS");
cristy3ed852e2009-09-05 21:47:34 +0000229 (void) UnregisterMagickInfo("XC");
230}