]> granicus.if.org Git - imagemagick/blob - coders/hald.c
ddd870dcfa46f786eb3d4a07ef837f8b0c7c06fa
[imagemagick] / coders / hald.c
1 /*
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-2011 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 \f
39 /*
40   Include declarations.
41 */
42 #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"
59 #include "MagickCore/static.h"
60 #include "MagickCore/string_.h"
61 #include "MagickCore/string-private.h"
62 \f
63 /*
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %                                                                             %
66 %                                                                             %
67 %                                                                             %
68 %   R e a d H A L D I m a g e                                                 %
69 %                                                                             %
70 %                                                                             %
71 %                                                                             %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %
74 %  ReadHALDImage() creates a Hald color lookup table image and returns it.  It
75 %  allocates the memory necessary for the new Image structure and returns a
76 %  pointer to the new image.
77 %
78 %  The format of the ReadHALDImage method is:
79 %
80 %      Image *ReadHALDImage(const ImageInfo *image_info,
81 %        ExceptionInfo *exception)
82 %
83 %  A description of each parameter follows:
84 %
85 %    o image_info: the image info.
86 %
87 %    o exception: return any errors or warnings in this structure.
88 %
89 */
90 static Image *ReadHALDImage(const ImageInfo *image_info,
91   ExceptionInfo *exception)
92 {
93   Image
94     *image;
95
96   MagickBooleanType
97     status;
98
99   size_t
100     cube_size,
101     level;
102
103   ssize_t
104     y;
105
106   /*
107     Create HALD color lookup table image.
108   */
109   assert(image_info != (const ImageInfo *) NULL);
110   assert(image_info->signature == MagickSignature);
111   if (image_info->debug != MagickFalse)
112     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
113       image_info->filename);
114   assert(exception != (ExceptionInfo *) NULL);
115   assert(exception->signature == MagickSignature);
116   image=AcquireImage(image_info);
117   level=0;
118   if (*image_info->filename != '\0')
119     level=StringToUnsignedLong(image_info->filename);
120   if (level < 2)
121     level=8;
122   status=MagickTrue;
123   cube_size=level*level;
124   image->columns=(size_t) (level*cube_size);
125   image->rows=(size_t) (level*cube_size);
126   for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level)
127   {
128     ssize_t
129       blue,
130       green,
131       red;
132
133     register Quantum
134       *restrict q;
135
136     if (status == MagickFalse)
137       continue;
138     q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,
139       exception);
140     if (q == (Quantum *) NULL)
141       {
142         status=MagickFalse;
143         continue;
144       }
145     blue=y/(ssize_t) level;
146     for (green=0; green < (ssize_t) cube_size; green++)
147     {
148       for (red=0; red < (ssize_t) cube_size; red++)
149       {
150         SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q);
151         SetPixelGreen(image,ClampToQuantum(QuantumRange*green/
152           (cube_size-1.0)),q);
153         SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q);
154         SetPixelAlpha(image,OpaqueAlpha,q);
155         q+=GetPixelChannels(image);
156       }
157     }
158     if (SyncAuthenticPixels(image,exception) == MagickFalse)
159       status=MagickFalse;
160   }
161   return(GetFirstImageInList(image));
162 }
163 \f
164 /*
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 %                                                                             %
167 %                                                                             %
168 %                                                                             %
169 %   R e g i s t e r H A L D I m a g e                                         %
170 %                                                                             %
171 %                                                                             %
172 %                                                                             %
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 %
175 %  RegisterHALDImage() adds attributes for the Hald color lookup table image
176 %  format to the list of supported formats.  The attributes include the image
177 %  format tag, a method to read and/or write the format, whether the format
178 %  supports the saving of more than one frame to the same file or blob, whether
179 %  the format supports native in-memory I/O, and a brief description of the
180 %  format.
181 %
182 %  The format of the RegisterHALDImage method is:
183 %
184 %      size_t RegisterHALDImage(void)
185 %
186 */
187 ModuleExport size_t RegisterHALDImage(void)
188 {
189   MagickInfo
190     *entry;
191
192   entry=SetMagickInfo("HALD");
193   entry->decoder=(DecodeImageHandler *) ReadHALDImage;
194   entry->adjoin=MagickFalse;
195   entry->format_type=ImplicitFormatType;
196   entry->raw=MagickTrue;
197   entry->endian_support=MagickTrue;
198   entry->description=ConstantString("Identity Hald color lookup table image");
199   (void) RegisterMagickInfo(entry);
200   return(MagickImageCoderSignature);
201 }
202 \f
203 /*
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 %                                                                             %
206 %                                                                             %
207 %                                                                             %
208 %   U n r e g i s t e r H A L D I m a g e                                     %
209 %                                                                             %
210 %                                                                             %
211 %                                                                             %
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 %
214 %  UnregisterHALDImage() removes format registrations made by the
215 %  HALD module from the list of supported formats.
216 %
217 %  The format of the UnregisterHALDImage method is:
218 %
219 %      UnregisterHALDImage(void)
220 %
221 */
222 ModuleExport void UnregisterHALDImage(void)
223 {
224   (void) UnregisterMagickInfo("HALD");
225 }