blob: e84f9c80f3d9cd10ee9d435c62dd042e1983f52a [file] [log] [blame]
Cristyccc16402018-11-25 09:56:18 -05001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC U U BBBB EEEEE %
7% C U U B B E %
8% C U U BBBB EEE %
9% C U U B B E %
10% CCCC UUU BBBB EEEEE %
11% %
12% %
13% Cube LUT Image Format %
14% %
15% Software Design %
16% Cristy %
17% July 2018 %
18% %
19% %
20% Copyright 1999-2018 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/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*/
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^L
65/*
66 Forward declarations.
67*/
68static MagickBooleanType
69 WriteCUBEImage(const ImageInfo *,Image *,ExceptionInfo *);
70
71/*
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
76% R e a d H A L D I m a g e %
77% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% ReadCUBEImage() creates a Cube color lookup table image and returns it. It
83% allocates the memory necessary for the new Image structure and returns a
84% pointer to the new image.
85%
86% The format of the ReadCUBEImage method is:
87%
88% Image *ReadCUBEImage(const ImageInfo *image_info,
89% ExceptionInfo *exception)
90%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
95% o exception: return any errors or warnings in this structure.
96%
97*/
98static Image *ReadCUBEImage(const ImageInfo *image_info,
99 ExceptionInfo *exception)
100{
101 Image
102 *image;
103
104 MagickBooleanType
105 status;
106
107 size_t
108 cube_size,
109 level;
110
111 ssize_t
112 y;
113
114 /*
115 Create CUBE color lookup table image.
116 */
117 assert(image_info != (const ImageInfo *) NULL);
118 assert(image_info->signature == MagickCoreSignature);
119 if (image_info->debug != MagickFalse)
120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
121 image_info->filename);
122 assert(exception != (ExceptionInfo *) NULL);
123 assert(exception->signature == MagickCoreSignature);
124 image=AcquireImage(image_info,exception);
125 level=0;
126 if (*image_info->filename != '\0')
127 level=StringToUnsignedLong(image_info->filename);
128 if (level < 2)
129 level=8;
130 status=MagickTrue;
131 cube_size=level*level;
132 image->columns=(size_t) (level*cube_size);
133 image->rows=(size_t) (level*cube_size);
134 status=SetImageExtent(image,image->columns,image->rows,exception);
135 if (status == MagickFalse)
136 return(DestroyImageList(image));
137 for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level)
138 {
139 ssize_t
140 blue,
141 green,
142 red;
143
144 register Quantum
145 *magick_restrict q;
146
147 if (status == MagickFalse)
148 continue;
149 q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,exception);
150 if (q == (Quantum *) NULL)
151 {
152 status=MagickFalse;
153 continue;
154 }
155 blue=y/(ssize_t) level;
156 for (green=0; green < (ssize_t) cube_size; green++)
157 {
158 for (red=0; red < (ssize_t) cube_size; red++)
159 {
160 SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q);
161 SetPixelGreen(image,ClampToQuantum(QuantumRange*green/(cube_size-1.0)),
162 q);
163 SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q);
164 SetPixelAlpha(image,OpaqueAlpha,q);
165 q+=GetPixelChannels(image);
166 }
167 }
168 if (SyncAuthenticPixels(image,exception) == MagickFalse)
169 status=MagickFalse;
170 }
171 return(GetFirstImageInList(image));
172}
173
174/*
175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176% %
177% %
178% %
179% R e g i s t e r H A L D I m a g e %
180% %
181% %
182% %
183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184%
185% RegisterCUBEImage() adds attributes for the Hald color lookup table image
186% format to the list of supported formats. The attributes include the image
187% format tag, a method to read and/or write the format, whether the format
188% supports the saving of more than one frame to the same file or blob, whether
189% the format supports native in-memory I/O, and a brief description of the
190% format.
191%
192% The format of the RegisterCUBEImage method is:
193%
194% size_t RegisterCUBEImage(void)
195%
196*/
197ModuleExport size_t RegisterCUBEImage(void)
198{
199 MagickInfo
200 *entry;
201
202 entry=AcquireMagickInfo("CUBE","CUBE",
203 "Identity Cube color lookup table image");
204 entry->decoder=(DecodeImageHandler *) ReadCUBEImage;
205 entry->encoder=(EncodeImageHandler *) WriteCUBEImage;
206 entry->flags^=CoderAdjoinFlag;
207 entry->format_type=ImplicitFormatType;
208 entry->flags|=CoderRawSupportFlag;
209 entry->flags|=CoderEndianSupportFlag;
210 (void) RegisterMagickInfo(entry);
211 return(MagickImageCoderSignature);
212}
213
214/*
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216% %
217% %
218% %
219% U n r e g i s t e r H A L D I m a g e %
220% %
221% %
222% %
223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224%
225% UnregisterCUBEImage() removes format registrations made by the
226% CUBE module from the list of supported formats.
227%
228% The format of the UnregisterCUBEImage method is:
229%
230% UnregisterCUBEImage(void)
231%
232*/
233ModuleExport void UnregisterCUBEImage(void)
234{
235 (void) UnregisterMagickInfo("CUBE");
236}
237
238/*
239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240% %
241% %
242% %
243% W r i t e C U B E I m a g e %
244% %
245% %
246% %
247%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248%
249% WriteCUBEImage an image in the Cube coloe lookup table image format.
250%
251% The format of the WriteCUBEImage method is:
252%
253% MagickBooleanType WriteCUBEImage(const ImageInfo *image_info,
254% Image *image,ExceptionInfo *exception)
255%
256% A description of each parameter follows.
257%
258% o image_info: the image info.
259%
260% o image: The image.
261%
262% o exception: return any errors or warnings in this structure.
263%
264*/
265static MagickBooleanType WriteCUBEImage(const ImageInfo *image_info,
266 Image *image,ExceptionInfo *exception)
267{
268 assert(image_info != (const ImageInfo *) NULL);
269 assert(image_info->signature == MagickCoreSignature);
270 assert(image != (Image *) NULL);
271 assert(image->signature == MagickCoreSignature);
272 assert(exception != (ExceptionInfo *) NULL);
273 (void) exception;
274 if (image->debug != MagickFalse)
275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
276 return(MagickTrue);
277}