blob: 95a028a4040fccbe2b314c1594063a134caede46 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% H H AAA L DDDD %
7% H H A A L D D %
8% HHHHH AAAAA L D D %
9% H H A A L D D %
10% H H A A LLLLL DDDD %
11% %
12% %
13% Create Identity Hald CLUT Image Format %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
20% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
21% 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/colorspace.h"
47#include "magick/exception.h"
48#include "magick/exception-private.h"
49#include "magick/image.h"
50#include "magick/image-private.h"
51#include "magick/list.h"
52#include "magick/magick.h"
53#include "magick/memory_.h"
54#include "magick/monitor.h"
55#include "magick/monitor-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 H A L D I m a g e %
67% %
68% %
69% %
70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71%
72% ReadHALDImage() creates a Hald color lookup table image and returns it. It
73% allocates the memory necessary for the new Image structure and returns a
74% pointer to the new image.
75%
76% The format of the ReadHALDImage method is:
77%
78% Image *ReadHALDImage(const ImageInfo *image_info,
79% ExceptionInfo *exception)
80%
81% A description of each parameter follows:
82%
83% o image_info: the image info.
84%
85% o exception: return any errors or warnings in this structure.
86%
87*/
88static Image *ReadHALDImage(const ImageInfo *image_info,
89 ExceptionInfo *exception)
90{
91 Image
92 *image;
93
94 long
95 y;
96
97 MagickBooleanType
98 status;
99
100 size_t
101 cube_size,
102 level;
103
104 CacheView
105 *image_view;
106
107 /*
108 Create HALD color lookup table image.
109 */
110 assert(image_info != (const ImageInfo *) NULL);
111 assert(image_info->signature == MagickSignature);
112 if (image_info->debug != MagickFalse)
113 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
114 image_info->filename);
115 assert(exception != (ExceptionInfo *) NULL);
116 assert(exception->signature == MagickSignature);
117 image=AcquireImage(image_info);
118 level=0;
119 if (*image_info->filename != '\0')
120 level=(unsigned long) atol(image_info->filename);
121 if (level < 2)
122 level=8;
123 status=MagickTrue;
124 cube_size=level*level;
125 image->columns=(unsigned long) (level*cube_size);
126 image->rows=(unsigned long) (level*cube_size);
127 image_view=AcquireCacheView(image);
cristyb28d6472009-10-17 20:13:35 +0000128#if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 200505)
cristye0f584d2009-10-11 00:59:14 +0000129 #pragma omp parallel for shared(status)
cristy3ed852e2009-09-05 21:47:34 +0000130#endif
131 for (y=0; y < (long) image->rows; y+=(long) level)
132 {
133 long
134 blue,
135 green,
136 red;
137
138 register PixelPacket
139 *__restrict q;
140
141 if (status == MagickFalse)
142 continue;
143 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,
144 (unsigned long) level,exception);
145 if (q == (PixelPacket *) NULL)
146 {
147 status=MagickFalse;
148 continue;
149 }
150 blue=y/(long) level;
151 for (green=0; green < (long) cube_size; green++)
152 {
153 for (red=0; red < (long) cube_size; red++)
154 {
155 q->red=RoundToQuantum(QuantumRange*red/(cube_size-1.0));
156 q->green=RoundToQuantum(QuantumRange*green/(cube_size-1.0));
157 q->blue=RoundToQuantum(QuantumRange*blue/(cube_size-1.0));
158 q->opacity=OpaqueOpacity;
159 q++;
160 }
161 }
162 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
163 status=MagickFalse;
164 }
165 image_view=DestroyCacheView(image_view);
166 return(GetFirstImageInList(image));
167}
168
169/*
170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171% %
172% %
173% %
174% R e g i s t e r H A L D I m a g e %
175% %
176% %
177% %
178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179%
180% RegisterHALDImage() adds attributes for the Hald color lookup table image
181% format to the list of supported formats. The attributes include the image
182% format tag, a method to read and/or write the format, whether the format
183% supports the saving of more than one frame to the same file or blob, whether
184% the format supports native in-memory I/O, and a brief description of the
185% format.
186%
187% The format of the RegisterHALDImage method is:
188%
189% unsigned long RegisterHALDImage(void)
190%
191*/
192ModuleExport unsigned long RegisterHALDImage(void)
193{
194 MagickInfo
195 *entry;
196
197 entry=SetMagickInfo("HALD");
198 entry->decoder=(DecodeImageHandler *) ReadHALDImage;
199 entry->adjoin=MagickFalse;
200 entry->format_type=ExplicitFormatType;
201 entry->raw=MagickTrue;
202 entry->endian_support=MagickTrue;
203 entry->description=ConstantString("Identity Hald color lookup table image");
204 (void) RegisterMagickInfo(entry);
205 return(MagickImageCoderSignature);
206}
207
208/*
209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210% %
211% %
212% %
213% U n r e g i s t e r H A L D I m a g e %
214% %
215% %
216% %
217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218%
219% UnregisterHALDImage() removes format registrations made by the
220% HALD module from the list of supported formats.
221%
222% The format of the UnregisterHALDImage method is:
223%
224% UnregisterHALDImage(void)
225%
226*/
227ModuleExport void UnregisterHALDImage(void)
228{
229 (void) UnregisterMagickInfo("HALD");
230}