blob: dfc2942d70edf501410746fc709ffb523899bb98 [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% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 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/colorspace.h"
47#include "MagickCore/exception.h"
48#include "MagickCore/exception-private.h"
49#include "MagickCore/image.h"
50#include "MagickCore/image-private.h"
51#include "MagickCore/list.h"
52#include "MagickCore/magick.h"
53#include "MagickCore/memory_.h"
54#include "MagickCore/module.h"
55#include "MagickCore/monitor.h"
56#include "MagickCore/monitor-private.h"
57#include "MagickCore/pixel-accessor.h"
58#include "MagickCore/quantum-private.h"
cristyac245f82012-05-05 17:13:57 +000059#include "MagickCore/resource_.h"
cristy4c08aed2011-07-01 19:47:50 +000060#include "MagickCore/static.h"
61#include "MagickCore/string_.h"
62#include "MagickCore/string-private.h"
cristyccfffb42012-05-06 01:17:48 +000063#include "MagickCore/thread-private.h"
cristy3ed852e2009-09-05 21:47:34 +000064
65/*
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67% %
68% %
69% %
70% R e a d H A L D I m a g e %
71% %
72% %
73% %
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75%
76% ReadHALDImage() creates a Hald color lookup table image and returns it. It
77% allocates the memory necessary for the new Image structure and returns a
78% pointer to the new image.
79%
80% The format of the ReadHALDImage method is:
81%
82% Image *ReadHALDImage(const ImageInfo *image_info,
83% ExceptionInfo *exception)
84%
85% A description of each parameter follows:
86%
87% o image_info: the image info.
88%
89% o exception: return any errors or warnings in this structure.
90%
91*/
92static Image *ReadHALDImage(const ImageInfo *image_info,
93 ExceptionInfo *exception)
94{
95 Image
96 *image;
97
cristy3ed852e2009-09-05 21:47:34 +000098 MagickBooleanType
99 status;
100
101 size_t
102 cube_size,
103 level;
104
cristyebc891a2011-04-24 23:04:16 +0000105 ssize_t
106 y;
107
cristy3ed852e2009-09-05 21:47:34 +0000108 /*
109 Create HALD color lookup table image.
110 */
111 assert(image_info != (const ImageInfo *) NULL);
112 assert(image_info->signature == MagickSignature);
113 if (image_info->debug != MagickFalse)
114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
115 image_info->filename);
116 assert(exception != (ExceptionInfo *) NULL);
117 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000118 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000119 level=0;
120 if (*image_info->filename != '\0')
cristye27293e2009-12-18 02:53:20 +0000121 level=StringToUnsignedLong(image_info->filename);
cristy3ed852e2009-09-05 21:47:34 +0000122 if (level < 2)
123 level=8;
124 status=MagickTrue;
125 cube_size=level*level;
cristybb503372010-05-27 20:51:26 +0000126 image->columns=(size_t) (level*cube_size);
127 image->rows=(size_t) (level*cube_size);
cristy78778cb2012-01-17 14:48:47 +0000128#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000129 #pragma omp parallel for schedule(static,8) shared(status) \
cristyccfffb42012-05-06 01:17:48 +0000130 IsConcurrent(image->columns,image->rows)
cristy78778cb2012-01-17 14:48:47 +0000131#endif
cristybb503372010-05-27 20:51:26 +0000132 for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level)
cristy3ed852e2009-09-05 21:47:34 +0000133 {
cristybb503372010-05-27 20:51:26 +0000134 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000135 blue,
136 green,
137 red;
138
cristy4c08aed2011-07-01 19:47:50 +0000139 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000140 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000141
142 if (status == MagickFalse)
143 continue;
cristybb503372010-05-27 20:51:26 +0000144 q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,
cristyaa740112010-03-30 17:58:44 +0000145 exception);
cristyacd2ed22011-08-30 01:44:23 +0000146 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000147 {
148 status=MagickFalse;
149 continue;
150 }
cristybb503372010-05-27 20:51:26 +0000151 blue=y/(ssize_t) level;
152 for (green=0; green < (ssize_t) cube_size; green++)
cristy3ed852e2009-09-05 21:47:34 +0000153 {
cristybb503372010-05-27 20:51:26 +0000154 for (red=0; red < (ssize_t) cube_size; red++)
cristy3ed852e2009-09-05 21:47:34 +0000155 {
cristy4c08aed2011-07-01 19:47:50 +0000156 SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q);
cristy78778cb2012-01-17 14:48:47 +0000157 SetPixelGreen(image,ClampToQuantum(QuantumRange*green/(cube_size-1.0)),
158 q);
cristy4c08aed2011-07-01 19:47:50 +0000159 SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q);
160 SetPixelAlpha(image,OpaqueAlpha,q);
cristyed231572011-07-14 02:18:59 +0000161 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000162 }
163 }
cristyaa740112010-03-30 17:58:44 +0000164 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000165 status=MagickFalse;
166 }
cristy3ed852e2009-09-05 21:47:34 +0000167 return(GetFirstImageInList(image));
168}
169
170/*
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172% %
173% %
174% %
175% R e g i s t e r H A L D I m a g e %
176% %
177% %
178% %
179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180%
181% RegisterHALDImage() adds attributes for the Hald color lookup table image
182% format to the list of supported formats. The attributes include the image
183% format tag, a method to read and/or write the format, whether the format
184% supports the saving of more than one frame to the same file or blob, whether
185% the format supports native in-memory I/O, and a brief description of the
186% format.
187%
188% The format of the RegisterHALDImage method is:
189%
cristybb503372010-05-27 20:51:26 +0000190% size_t RegisterHALDImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000191%
192*/
cristybb503372010-05-27 20:51:26 +0000193ModuleExport size_t RegisterHALDImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000194{
195 MagickInfo
196 *entry;
197
198 entry=SetMagickInfo("HALD");
199 entry->decoder=(DecodeImageHandler *) ReadHALDImage;
200 entry->adjoin=MagickFalse;
cristy009d7392010-07-25 22:08:41 +0000201 entry->format_type=ImplicitFormatType;
cristy3ed852e2009-09-05 21:47:34 +0000202 entry->raw=MagickTrue;
203 entry->endian_support=MagickTrue;
204 entry->description=ConstantString("Identity Hald color lookup table image");
205 (void) RegisterMagickInfo(entry);
206 return(MagickImageCoderSignature);
207}
208
209/*
210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211% %
212% %
213% %
214% U n r e g i s t e r H A L D I m a g e %
215% %
216% %
217% %
218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219%
220% UnregisterHALDImage() removes format registrations made by the
221% HALD module from the list of supported formats.
222%
223% The format of the UnregisterHALDImage method is:
224%
225% UnregisterHALDImage(void)
226%
227*/
228ModuleExport void UnregisterHALDImage(void)
229{
230 (void) UnregisterMagickInfo("HALD");
231}