Menu

[d59cce]: / coders / identity.c  Maximize  Restore  History

Download this file

263 lines (233 with data), 8.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
% Copyright (C) 2009-2023 GraphicsMagick Group
%
% This program is covered by multiple licenses, which are described in
% Copyright.txt. You should have received a copy of Copyright.txt with this
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/colormap.h"
#include "magick/pixel_cache.h"
#include "magick/constitute.h"
#include "magick/magick.h"
#include "magick/monitor.h"
#include "magick/utility.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d I D E N T I T Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method ReadIdentityImage creates a Hald CLUT identity image. The argument
% to the IDENTITY filename (e.g. "identity:8") specifies the order of the
% identity image. The minimum order which may be specified is 2. Higher
% order LUTs contain more colors and are therefore more accurate, but consume
% more memory. Typical Hald CLUT identity images have an order of between 8
% (512x512) and 16 (4096x4096). An arbitrary maximum order of 40 (a
% 64000x64000 image) is enforced. The default order is 8.
%
% The format of the ReadIdentityImage method is:
%
% Image *ReadIdentityImage(const ImageInfo *image_info,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image: Method ReadIdentityImage returns a pointer to the image after
% creating it. A null image is returned if there is a memory shortage
% or if the image cannot be read.
%
% o image_info: Specifies a pointer to a ImageInfo structure.
%
% o exception: return any errors or warnings in this structure.
%
%
*/
static Image *ReadIdentityImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
#define IdentityImageText "[%s] Generating Hald CLUT identity image..."
Image
*image;
unsigned long
cube_size,
order,
row_count=0;
long
y;
unsigned int
status=MagickPass;
/*
Initialize Image structure.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=AllocateImage(image_info);
order=8;
if (image_info->filename[0] != '\0')
if ((status &= MagickAtoULChk(image_info->filename, &order)) != MagickPass)
ThrowReaderException(FileOpenError,UnableToOpenFile,image);
if (order > 40)
ThrowReaderException(FileOpenError,UnableToOpenFile,image);
if (order < 2)
order=8;
cube_size=order*order;
image->columns=image->rows=order*order*order;
if (image->columns*image->rows <= MaxColormapSize)
if (!AllocateImageColormap(image,(const unsigned long) image->columns*image->rows))
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
#if defined(HAVE_OPENMP)
# if defined(TUNE_OPENMP)
# pragma omp parallel for schedule(runtime) shared(row_count, status)
# else
# pragma omp parallel for shared(row_count, status)
# endif
#endif
for (y=0; y < (long) image->rows; y += order)
{
MagickPassFail
thread_status;
register PixelPacket
*q;
register IndexPacket
*indexes = (IndexPacket *) NULL;
register unsigned int
index = (unsigned int) y*image->columns;
#if defined(HAVE_OPENMP)
# pragma omp critical (GM_IdentityImage)
#endif
thread_status=status;
if (thread_status == MagickFail)
continue;
q=SetImagePixelsEx(image,0,y,image->columns,order,&image->exception);
if (q == (PixelPacket *) NULL)
thread_status=MagickFail;
if (image->storage_class == PseudoClass)
indexes=AccessMutableIndexes(image);
if (q != (PixelPacket *) NULL)
{
double
value;
unsigned int
red,
green,
blue;
blue=y/order;
for (green = 0; green < cube_size; green++)
{
for (red = 0; red < cube_size; red++)
{
value=MaxRGBDouble * (double)red / (double)(cube_size - 1);
q->red = RoundDoubleToQuantum(value);
value = MaxRGBDouble * (double)green / (double)(cube_size - 1);
q->green = RoundDoubleToQuantum(value);
value = MaxRGBDouble * (double)blue / (double)(cube_size - 1);
q->blue = RoundDoubleToQuantum(value);
q->opacity = OpaqueOpacity;
if (indexes != (IndexPacket *) NULL)
{
image->colormap[index]=*q;
*indexes++=index++;
}
q++;
}
}
if (!SyncImagePixelsEx(image,&image->exception))
thread_status=MagickFail;
}
#if defined(HAVE_OPENMP)
# pragma omp critical (GM_IdentityImage)
#endif
{
row_count++;
if (QuantumTick(row_count,image->rows))
if (!MagickMonitorFormatted(row_count,image->rows,&image->exception,
IdentityImageText,image->filename))
thread_status=MagickFail;
if (thread_status == MagickFail)
status=MagickFail;
}
}
if (status == MagickFail)
{
CopyException(exception,&image->exception);
DestroyImage(image);
image=(Image *) NULL;
}
else
{
StopTimer(&image->timer);
}
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r I D E N T I T Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method RegisterIDENTITYImage adds attributes for the Identity image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterIDENTITYImage method is:
%
% RegisterIDENTITYImage(void)
%
*/
ModuleExport void RegisterIDENTITYImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("IDENTITY");
entry->decoder=(DecoderHandler) ReadIdentityImage;
entry->adjoin=False;
entry->description="Hald CLUT identity image";
entry->module="IDENTITY";
entry->coder_class=PrimaryCoderClass;
entry->extension_treatment=IgnoreExtensionTreatment;
(void) RegisterMagickInfo(entry);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r I D E N T I T Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method UnregisterIDENTITYImage removes format registrations made by the
% IDENTITY module from the list of supported formats.
%
% The format of the UnregisterIDENTITYImage method is:
%
% UnregisterIDENTITYImage(void)
%
*/
ModuleExport void UnregisterIDENTITYImage(void)
{
(void) UnregisterMagickInfo("IDENTITY");
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.