]> 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 %                                John Cristy                                  %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2010 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 "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/module.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/quantum-private.h"
58 #include "magick/static.h"
59 #include "magick/string_.h"
60 #include "magick/string-private.h"
61 \f
62 /*
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %                                                                             %
65 %                                                                             %
66 %                                                                             %
67 %   R e a d H A L D I m a g e                                                 %
68 %                                                                             %
69 %                                                                             %
70 %                                                                             %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %
73 %  ReadHALDImage() creates a Hald color lookup table image and returns it.  It
74 %  allocates the memory necessary for the new Image structure and returns a
75 %  pointer to the new image.
76 %
77 %  The format of the ReadHALDImage method is:
78 %
79 %      Image *ReadHALDImage(const ImageInfo *image_info,
80 %        ExceptionInfo *exception)
81 %
82 %  A description of each parameter follows:
83 %
84 %    o image_info: the image info.
85 %
86 %    o exception: return any errors or warnings in this structure.
87 %
88 */
89 static Image *ReadHALDImage(const ImageInfo *image_info,
90   ExceptionInfo *exception)
91 {
92   Image
93     *image;
94
95   long
96     y;
97
98   MagickBooleanType
99     status;
100
101   size_t
102     cube_size,
103     level;
104
105   CacheView
106     *image_view;
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);
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=(unsigned long) (level*cube_size);
127   image->rows=(unsigned long) (level*cube_size);
128   image_view=AcquireCacheView(image);
129 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (_OPENMP > 202001)
130   #pragma omp parallel for shared(status)
131 #endif
132   for (y=0; y < (long) image->rows; y+=(long) level)
133   {
134     long
135       blue,
136       green,
137       red;
138
139     register PixelPacket
140       *restrict q;
141
142     if (status == MagickFalse)
143       continue;
144     q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,
145       (unsigned long) level,exception);
146     if (q == (PixelPacket *) NULL)
147       {
148         status=MagickFalse;
149         continue;
150       }
151     blue=y/(long) level;
152     for (green=0; green < (long) cube_size; green++)
153     {
154       for (red=0; red < (long) cube_size; red++)
155       {
156         q->red=ClampToQuantum(QuantumRange*red/(cube_size-1.0));
157         q->green=ClampToQuantum(QuantumRange*green/(cube_size-1.0));
158         q->blue=ClampToQuantum(QuantumRange*blue/(cube_size-1.0));
159         SetOpacityPixelComponent(q,OpaqueOpacity);
160         q++;
161       }
162     }
163     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
164       status=MagickFalse;
165   }
166   image_view=DestroyCacheView(image_view);
167   return(GetFirstImageInList(image));
168 }
169 \f
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 %
190 %      unsigned long RegisterHALDImage(void)
191 %
192 */
193 ModuleExport unsigned long RegisterHALDImage(void)
194 {
195   MagickInfo
196     *entry;
197
198   entry=SetMagickInfo("HALD");
199   entry->decoder=(DecodeImageHandler *) ReadHALDImage;
200   entry->adjoin=MagickFalse;
201   entry->format_type=ExplicitFormatType;
202   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 \f
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 */
228 ModuleExport void UnregisterHALDImage(void)
229 {
230   (void) UnregisterMagickInfo("HALD");
231 }