/src/imagemagick/coders/hald.c
Line | Count | Source |
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 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 | | % https://imagemagick.org/license/ % |
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 "MagickCore/studio.h" |
43 | | #include "MagickCore/blob.h" |
44 | | #include "MagickCore/blob-private.h" |
45 | | #include "MagickCore/cache.h" |
46 | | #include "MagickCore/colormap.h" |
47 | | #include "MagickCore/colorspace.h" |
48 | | #include "MagickCore/exception.h" |
49 | | #include "MagickCore/exception-private.h" |
50 | | #include "MagickCore/image.h" |
51 | | #include "MagickCore/image-private.h" |
52 | | #include "MagickCore/list.h" |
53 | | #include "MagickCore/magick.h" |
54 | | #include "MagickCore/memory_.h" |
55 | | #include "MagickCore/module.h" |
56 | | #include "MagickCore/monitor.h" |
57 | | #include "MagickCore/monitor-private.h" |
58 | | #include "MagickCore/pixel-accessor.h" |
59 | | #include "MagickCore/quantum-private.h" |
60 | | #include "MagickCore/resource_.h" |
61 | | #include "MagickCore/static.h" |
62 | | #include "MagickCore/string_.h" |
63 | | #include "MagickCore/string-private.h" |
64 | | #include "MagickCore/thread-private.h" |
65 | | |
66 | | /* |
67 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
68 | | % % |
69 | | % % |
70 | | % % |
71 | | % R e a d H A L D I m a g e % |
72 | | % % |
73 | | % % |
74 | | % % |
75 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
76 | | % |
77 | | % ReadHALDImage() creates a Hald color lookup table image and returns it. It |
78 | | % allocates the memory necessary for the new Image structure and returns a |
79 | | % pointer to the new image. |
80 | | % |
81 | | % The format of the ReadHALDImage method is: |
82 | | % |
83 | | % Image *ReadHALDImage(const ImageInfo *image_info, |
84 | | % ExceptionInfo *exception) |
85 | | % |
86 | | % A description of each parameter follows: |
87 | | % |
88 | | % o image_info: the image info. |
89 | | % |
90 | | % o exception: return any errors or warnings in this structure. |
91 | | % |
92 | | */ |
93 | | static Image *ReadHALDImage(const ImageInfo *image_info, |
94 | | ExceptionInfo *exception) |
95 | 976 | { |
96 | 976 | Image |
97 | 976 | *image; |
98 | | |
99 | 976 | MagickBooleanType |
100 | 976 | status; |
101 | | |
102 | 976 | size_t |
103 | 976 | cube_size, |
104 | 976 | level; |
105 | | |
106 | 976 | ssize_t |
107 | 976 | i, |
108 | 976 | index, |
109 | 976 | y; |
110 | | |
111 | | /* |
112 | | Create HALD color lookup table image. |
113 | | */ |
114 | 976 | assert(image_info != (const ImageInfo *) NULL); |
115 | 976 | assert(image_info->signature == MagickCoreSignature); |
116 | 976 | assert(exception != (ExceptionInfo *) NULL); |
117 | 976 | assert(exception->signature == MagickCoreSignature); |
118 | 976 | if (IsEventLogging() != MagickFalse) |
119 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
120 | 0 | image_info->filename); |
121 | 976 | image=AcquireImage(image_info,exception); |
122 | 976 | level=0; |
123 | 976 | if (*image_info->filename != '\0') |
124 | 895 | level=StringToUnsignedLong(image_info->filename); |
125 | 976 | if (image_info->scene != 0) |
126 | 0 | level=image_info->scene; |
127 | 976 | if ((level < 2) || (level > 256)) |
128 | 631 | level=8; |
129 | 976 | status=MagickTrue; |
130 | 976 | cube_size=level*level; |
131 | 976 | image->columns=(size_t) (level*cube_size); |
132 | 976 | image->rows=(size_t) (level*cube_size); |
133 | 976 | if (((MagickSizeType) image->columns*image->rows) <= MaxColormapSize) |
134 | 329 | (void) AcquireImageColormap(image,(size_t) (image->columns*image->rows), |
135 | 329 | exception); |
136 | 976 | status=SetImageExtent(image,image->columns,image->rows,exception); |
137 | 976 | if (status == MagickFalse) |
138 | 16 | return(DestroyImageList(image)); |
139 | 960 | index=0; |
140 | 49.5k | for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level) |
141 | 48.6k | { |
142 | 48.6k | Quantum |
143 | 48.6k | *magick_restrict q; |
144 | | |
145 | 48.6k | ssize_t |
146 | 48.6k | blue, |
147 | 48.6k | green, |
148 | 48.6k | red; |
149 | | |
150 | 48.6k | if (status == MagickFalse) |
151 | 0 | continue; |
152 | 48.6k | q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,exception); |
153 | 48.6k | if (q == (Quantum *) NULL) |
154 | 0 | { |
155 | 0 | status=MagickFalse; |
156 | 0 | continue; |
157 | 0 | } |
158 | 48.6k | blue=y/(ssize_t) level; |
159 | 2.83M | for (green=0; green < (ssize_t) cube_size; green++) |
160 | 2.79M | { |
161 | 173M | for (red=0; red < (ssize_t) cube_size; red++) |
162 | 170M | { |
163 | 170M | SetPixelRed(image,ClampToQuantum((double) QuantumRange*red/ |
164 | 170M | (cube_size-1.0)),q); |
165 | 170M | SetPixelGreen(image,ClampToQuantum((double) QuantumRange*green/ |
166 | 170M | (cube_size-1.0)),q); |
167 | 170M | SetPixelBlue(image,ClampToQuantum((double) QuantumRange*blue/ |
168 | 170M | (cube_size-1.0)),q); |
169 | 170M | SetPixelAlpha(image,OpaqueAlpha,q); |
170 | 170M | if (image->storage_class == PseudoClass) |
171 | 5.14M | { |
172 | 5.14M | image->colormap[index].red= |
173 | 5.14M | ClampToQuantum((double) QuantumRange*red/(cube_size-1.0)); |
174 | 5.14M | image->colormap[index].green= |
175 | 5.14M | ClampToQuantum((double) QuantumRange*green/(cube_size-1.0)); |
176 | 5.14M | image->colormap[index].blue= |
177 | 5.14M | ClampToQuantum((double) QuantumRange*blue/(cube_size-1.0)); |
178 | 5.14M | image->colormap[index].alpha=OpaqueAlpha; |
179 | 5.14M | SetPixelIndex(image,(Quantum) index++,q); |
180 | 5.14M | } |
181 | 170M | q+=(ptrdiff_t) GetPixelChannels(image); |
182 | 170M | } |
183 | 2.79M | } |
184 | 48.6k | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
185 | 0 | status=MagickFalse; |
186 | 48.6k | } |
187 | 960 | if (CloseBlob(image) == MagickFalse) |
188 | 0 | status=MagickFalse; |
189 | 960 | if (status == MagickFalse) |
190 | 0 | return(DestroyImageList(image)); |
191 | 960 | if (image_info->scene != 0) |
192 | 0 | for (i=0; i < (ssize_t) image_info->scene; i++) |
193 | 0 | AppendImageToList(&image,CloneImage(image,0,0,MagickTrue,exception)); |
194 | 960 | return(GetFirstImageInList(image)); |
195 | 960 | } |
196 | | |
197 | | /* |
198 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
199 | | % % |
200 | | % % |
201 | | % % |
202 | | % R e g i s t e r H A L D I m a g e % |
203 | | % % |
204 | | % % |
205 | | % % |
206 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
207 | | % |
208 | | % RegisterHALDImage() adds attributes for the Hald color lookup table image |
209 | | % format to the list of supported formats. The attributes include the image |
210 | | % format tag, a method to read and/or write the format, whether the format |
211 | | % supports the saving of more than one frame to the same file or blob, whether |
212 | | % the format supports native in-memory I/O, and a brief description of the |
213 | | % format. |
214 | | % |
215 | | % The format of the RegisterHALDImage method is: |
216 | | % |
217 | | % size_t RegisterHALDImage(void) |
218 | | % |
219 | | */ |
220 | | ModuleExport size_t RegisterHALDImage(void) |
221 | 8 | { |
222 | 8 | MagickInfo |
223 | 8 | *entry; |
224 | | |
225 | 8 | entry=AcquireMagickInfo("HALD","HALD", |
226 | 8 | "Identity Hald color lookup table image"); |
227 | 8 | entry->decoder=(DecodeImageHandler *) ReadHALDImage; |
228 | 8 | entry->flags^=CoderAdjoinFlag; |
229 | 8 | entry->format_type=ImplicitFormatType; |
230 | 8 | entry->flags|=CoderRawSupportFlag; |
231 | 8 | entry->flags|=CoderEndianSupportFlag; |
232 | 8 | (void) RegisterMagickInfo(entry); |
233 | 8 | return(MagickImageCoderSignature); |
234 | 8 | } |
235 | | |
236 | | /* |
237 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
238 | | % % |
239 | | % % |
240 | | % % |
241 | | % U n r e g i s t e r H A L D I m a g e % |
242 | | % % |
243 | | % % |
244 | | % % |
245 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
246 | | % |
247 | | % UnregisterHALDImage() removes format registrations made by the |
248 | | % HALD module from the list of supported formats. |
249 | | % |
250 | | % The format of the UnregisterHALDImage method is: |
251 | | % |
252 | | % UnregisterHALDImage(void) |
253 | | % |
254 | | */ |
255 | | ModuleExport void UnregisterHALDImage(void) |
256 | 0 | { |
257 | 0 | (void) UnregisterMagickInfo("HALD"); |
258 | 0 | } |