]> granicus.if.org Git - imagemagick/blob - coders/hald.c
(no commit message)
[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 %                                   Cristy                                    %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2014 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/resource_.h"
60 #include "MagickCore/static.h"
61 #include "MagickCore/string_.h"
62 #include "MagickCore/string-private.h"
63 #include "MagickCore/thread-private.h"
64 \f
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 */
92 static Image *ReadHALDImage(const ImageInfo *image_info,
93   ExceptionInfo *exception)
94 {
95   Image
96     *image;
97
98   MagickBooleanType
99     status;
100
101   size_t
102     cube_size,
103     level;
104
105   ssize_t
106     y;
107
108   /*
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);
118   image=AcquireImage(image_info,exception);
119   level=0;
120   if (*image_info->filename != '\0')
121     level=StringToUnsignedLong(image_info->filename);
122   if (level < 2)
123     level=8;
124   status=MagickTrue;
125   cube_size=level*level;
126   image->columns=(size_t) (level*cube_size);
127   image->rows=(size_t) (level*cube_size);
128   for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level)
129   {
130     ssize_t
131       blue,
132       green,
133       red;
134
135     register Quantum
136       *restrict q;
137
138     if (status == MagickFalse)
139       continue;
140     q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,
141       exception);
142     if (q == (Quantum *) NULL)
143       {
144         status=MagickFalse;
145         continue;
146       }
147     blue=y/(ssize_t) level;
148     for (green=0; green < (ssize_t) cube_size; green++)
149     {
150       for (red=0; red < (ssize_t) cube_size; red++)
151       {
152         SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q);
153         SetPixelGreen(image,ClampToQuantum(QuantumRange*green/(cube_size-1.0)),
154           q);
155         SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q);
156         SetPixelAlpha(image,OpaqueAlpha,q);
157         q+=GetPixelChannels(image);
158       }
159     }
160     if (SyncAuthenticPixels(image,exception) == MagickFalse)
161       status=MagickFalse;
162   }
163   return(GetFirstImageInList(image));
164 }
165 \f
166 /*
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 %                                                                             %
169 %                                                                             %
170 %                                                                             %
171 %   R e g i s t e r H A L D I m a g e                                         %
172 %                                                                             %
173 %                                                                             %
174 %                                                                             %
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 %
177 %  RegisterHALDImage() adds attributes for the Hald color lookup table image
178 %  format to the list of supported formats.  The attributes include the image
179 %  format tag, a method to read and/or write the format, whether the format
180 %  supports the saving of more than one frame to the same file or blob, whether
181 %  the format supports native in-memory I/O, and a brief description of the
182 %  format.
183 %
184 %  The format of the RegisterHALDImage method is:
185 %
186 %      size_t RegisterHALDImage(void)
187 %
188 */
189 ModuleExport size_t RegisterHALDImage(void)
190 {
191   MagickInfo
192     *entry;
193
194   entry=SetMagickInfo("HALD");
195   entry->decoder=(DecodeImageHandler *) ReadHALDImage;
196   entry->adjoin=MagickFalse;
197   entry->format_type=ImplicitFormatType;
198   entry->raw=MagickTrue;
199   entry->endian_support=MagickTrue;
200   entry->description=ConstantString("Identity Hald color lookup table image");
201   (void) RegisterMagickInfo(entry);
202   return(MagickImageCoderSignature);
203 }
204 \f
205 /*
206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 %                                                                             %
208 %                                                                             %
209 %                                                                             %
210 %   U n r e g i s t e r H A L D I m a g e                                     %
211 %                                                                             %
212 %                                                                             %
213 %                                                                             %
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 %
216 %  UnregisterHALDImage() removes format registrations made by the
217 %  HALD module from the list of supported formats.
218 %
219 %  The format of the UnregisterHALDImage method is:
220 %
221 %      UnregisterHALDImage(void)
222 %
223 */
224 ModuleExport void UnregisterHALDImage(void)
225 {
226   (void) UnregisterMagickInfo("HALD");
227 }