blob: 589819bbd8f11bd086307c9aaa3c3769eccafa0b [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% %
cristy45ef08f2012-12-07 13:13:34 +000020% Copyright 1999-2013 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"
48#include "MagickCore/exception.h"
49#include "MagickCore/exception-private.h"
50#include "MagickCore/image.h"
51#include "MagickCore/image-private.h"
52#include "MagickCore/list.h"
53#include "MagickCore/magick.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/pixel.h"
56#include "MagickCore/pixel-accessor.h"
57#include "MagickCore/quantum-private.h"
58#include "MagickCore/static.h"
59#include "MagickCore/string_.h"
60#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000061
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
cristy3ed852e2009-09-05 21:47:34 +000096 MagickBooleanType
97 status;
98
cristy4c08aed2011-07-01 19:47:50 +000099 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000100 pixel;
101
cristybb503372010-05-27 20:51:26 +0000102 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000103 x;
104
cristy4c08aed2011-07-01 19:47:50 +0000105 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000106 *q;
107
cristyc6da28e2011-04-28 01:41:35 +0000108 ssize_t
109 y;
110
cristy3ed852e2009-09-05 21:47:34 +0000111 /*
112 Initialize Image structure.
113 */
114 assert(image_info != (const ImageInfo *) NULL);
115 assert(image_info->signature == MagickSignature);
116 if (image_info->debug != MagickFalse)
117 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
118 image_info->filename);
119 assert(exception != (ExceptionInfo *) NULL);
120 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000121 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000122 if (image->columns == 0)
123 image->columns=1;
124 if (image->rows == 0)
125 image->rows=1;
126 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
cristy3358e732012-07-16 12:34:08 +0000127 if (*image_info->filename == '\0')
128 pixel=image->background_color;
129 else
cristy3ed852e2009-09-05 21:47:34 +0000130 {
cristy3358e732012-07-16 12:34:08 +0000131 status=QueryColorCompliance((char *) image_info->filename,AllCompliance,
132 &pixel,exception);
133 if (status == MagickFalse)
134 {
135 image=DestroyImage(image);
136 return((Image *) NULL);
137 }
cristy3ed852e2009-09-05 21:47:34 +0000138 }
cristye47e2912012-05-16 11:23:37 +0000139 SetImageColorspace(image,pixel.colorspace,exception);
cristy8a46d822012-08-28 23:32:39 +0000140 image->alpha_trait=pixel.alpha_trait;
cristybb503372010-05-27 20:51:26 +0000141 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000142 {
143 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000144 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000145 break;
cristybb503372010-05-27 20:51:26 +0000146 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +0000147 {
cristy803640d2011-11-17 02:11:32 +0000148 SetPixelInfoPixel(image,&pixel,q);
cristyed231572011-07-14 02:18:59 +0000149 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000150 }
cristy3ed852e2009-09-05 21:47:34 +0000151 if (SyncAuthenticPixels(image,exception) == MagickFalse)
152 break;
153 }
154 return(GetFirstImageInList(image));
155}
156
157/*
158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159% %
160% %
161% %
162% R e g i s t e r X C I m a g e %
163% %
164% %
165% %
166%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167%
168% RegisterXCImage() adds attributes for the XC image format to
169% the list of supported formats. The attributes include the image format
170% tag, a method to read and/or write the format, whether the format
171% supports the saving of more than one frame to the same file or blob,
172% whether the format supports native in-memory I/O, and a brief
173% description of the format.
174%
175% The format of the RegisterXCImage method is:
176%
cristybb503372010-05-27 20:51:26 +0000177% size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000178%
179*/
cristybb503372010-05-27 20:51:26 +0000180ModuleExport size_t RegisterXCImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000181{
182 MagickInfo
183 *entry;
184
185 entry=SetMagickInfo("XC");
186 entry->decoder=(DecodeImageHandler *) ReadXCImage;
187 entry->adjoin=MagickFalse;
cristy009d7392010-07-25 22:08:41 +0000188 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000189 entry->raw=MagickTrue;
190 entry->endian_support=MagickTrue;
191 entry->description=ConstantString("Constant image uniform color");
192 entry->module=ConstantString("XC");
193 (void) RegisterMagickInfo(entry);
cristyc05417c2010-09-21 16:30:32 +0000194 entry=SetMagickInfo("CANVAS");
195 entry->decoder=(DecodeImageHandler *) ReadXCImage;
196 entry->adjoin=MagickFalse;
197 entry->format_type=ImplicitFormatType;
198 entry->raw=MagickTrue;
199 entry->endian_support=MagickTrue;
200 entry->description=ConstantString("Constant image uniform color");
201 entry->module=ConstantString("XC");
202 (void) RegisterMagickInfo(entry);
cristy3ed852e2009-09-05 21:47:34 +0000203 return(MagickImageCoderSignature);
204}
205
206/*
207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208% %
209% %
210% %
211% U n r e g i s t e r X C I m a g e %
212% %
213% %
214% %
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216%
217% UnregisterXCImage() removes format registrations made by the
218% XC module from the list of supported formats.
219%
220% The format of the UnregisterXCImage method is:
221%
222% UnregisterXCImage(void)
223%
224*/
225ModuleExport void UnregisterXCImage(void)
226{
cristyc05417c2010-09-21 16:30:32 +0000227 (void) UnregisterMagickInfo("CANVAS");
cristy3ed852e2009-09-05 21:47:34 +0000228 (void) UnregisterMagickInfo("XC");
229}