/src/graphicsmagick/magick/import.c
Line | Count | Source |
1 | | /* |
2 | | Copyright (C) 2003 - 2023 GraphicsMagick Group |
3 | | Copyright (C) 2002 ImageMagick Studio |
4 | | |
5 | | This program is covered by multiple licenses, which are described in |
6 | | Copyright.txt. You should have received a copy of Copyright.txt with this |
7 | | package; otherwise see http://www.graphicsmagick.org/www/Copyright.html. |
8 | | |
9 | | Methods to import image pixels from common representations |
10 | | |
11 | | */ |
12 | | |
13 | | /* |
14 | | Include declarations. |
15 | | */ |
16 | | #include "magick/studio.h" |
17 | | #include "magick/bit_stream.h" |
18 | | #include "magick/colormap.h" |
19 | | #include "magick/constitute.h" |
20 | | #include "magick/floats.h" |
21 | | #include "magick/magick.h" |
22 | | #include "magick/pixel_cache.h" |
23 | | #include "magick/utility.h" |
24 | | |
25 | | /* |
26 | | Type definitions |
27 | | */ |
28 | | static const PixelPacket BlackPixel = {0, 0, 0, OpaqueOpacity}; |
29 | | |
30 | | static const PixelPacket WhitePixel = {MaxRGB, MaxRGB, MaxRGB, OpaqueOpacity}; |
31 | | |
32 | | /* |
33 | | Macros |
34 | | */ |
35 | | |
36 | | #if defined(WORDS_BIGENDIAN) |
37 | | # define MyEndianType MSBEndian |
38 | | #else |
39 | 31.9M | # define MyEndianType LSBEndian |
40 | | #endif |
41 | | |
42 | | #define ImportModulo8Quantum(quantum,quantum_size,p) \ |
43 | 138k | { \ |
44 | 138k | register unsigned int \ |
45 | 138k | shift; \ |
46 | 138k | \ |
47 | 138k | quantum=0; \ |
48 | 138k | if (LSBEndian != endian) \ |
49 | 138k | { \ |
50 | 132k | shift=quantum_size; \ |
51 | 132k | do \ |
52 | 136k | { \ |
53 | 136k | shift -= 8U; \ |
54 | 136k | quantum |= (((magick_uint32_t) *p++) << shift); \ |
55 | 136k | } while( shift > 0U); \ |
56 | 132k | } \ |
57 | 138k | else \ |
58 | 138k | { \ |
59 | 5.57k | shift=0U; \ |
60 | 21.0k | while ( shift < quantum_size ) \ |
61 | 15.4k | { \ |
62 | 15.4k | quantum |= (((magick_uint32_t) *p++) << shift); \ |
63 | 15.4k | shift += 8U; \ |
64 | 15.4k | } \ |
65 | 5.57k | } \ |
66 | 138k | } |
67 | | #define ImportUInt8Quantum(quantum,p) \ |
68 | 2.01G | { \ |
69 | 2.01G | quantum=(magick_uint32_t) *p++; \ |
70 | 2.01G | } |
71 | | #define ImportUInt16Quantum(endian,quantum,p) \ |
72 | 385M | { \ |
73 | 385M | if (LSBEndian != endian) \ |
74 | 385M | { \ |
75 | 28.9M | quantum=(((magick_uint32_t) *p++) << 8); \ |
76 | 28.9M | quantum|=((magick_uint32_t) *p++); \ |
77 | 28.9M | } \ |
78 | 385M | else \ |
79 | 385M | { \ |
80 | 356M | quantum=((magick_uint32_t) *p++); \ |
81 | 356M | quantum|=(((magick_uint32_t) *p++) << 8); \ |
82 | 356M | } \ |
83 | 385M | } |
84 | | /* |
85 | | This algorithm has been compared with several others and did best |
86 | | overall on SPARC, PowerPC, and Intel Xeon. |
87 | | */ |
88 | | #define ImportUInt32Quantum(endian,quantum,p) \ |
89 | 267M | { \ |
90 | 267M | if (LSBEndian != endian) \ |
91 | 267M | { \ |
92 | 264M | quantum=(((magick_uint32_t) *p++) << 24); \ |
93 | 264M | quantum|=(((magick_uint32_t) *p++) << 16); \ |
94 | 264M | quantum|=(((magick_uint32_t) *p++) << 8); \ |
95 | 264M | quantum|=((magick_uint32_t) *p++); \ |
96 | 264M | } \ |
97 | 267M | else \ |
98 | 267M | { \ |
99 | 2.79M | quantum=((magick_uint32_t) *p++); \ |
100 | 2.79M | quantum|=(((magick_uint32_t) *p++) << 8); \ |
101 | 2.79M | quantum|=(((magick_uint32_t) *p++) << 16); \ |
102 | 2.79M | quantum|=(((magick_uint32_t) *p++) << 24); \ |
103 | 2.79M | } \ |
104 | 267M | } |
105 | | /* |
106 | | Import a 64-bit unsigned value into a 32-bit quantum type. This |
107 | | approach is used since 64-bits is not supported internally and some |
108 | | CPUs may perform poorly when using a true 64-bit type. In this case |
109 | | the least significant 32 bits are entirely ignored. |
110 | | */ |
111 | | #define ImportUInt64Quantum(endian,quantum,p) \ |
112 | 24.3k | { \ |
113 | 24.3k | if (LSBEndian != endian) \ |
114 | 24.3k | { \ |
115 | 22.5k | quantum=(((magick_uint32_t) *p++) << 24); \ |
116 | 22.5k | quantum|=(((magick_uint32_t) *p++) << 16); \ |
117 | 22.5k | quantum|=(((magick_uint32_t) *p++) << 8); \ |
118 | 22.5k | quantum|=((magick_uint32_t) *p++); \ |
119 | 22.5k | p+=4; \ |
120 | 22.5k | } \ |
121 | 24.3k | else \ |
122 | 24.3k | { \ |
123 | 1.81k | p+=4; \ |
124 | 1.81k | quantum=((magick_uint32_t) *p++); \ |
125 | 1.81k | quantum|=(((magick_uint32_t) *p++) << 8); \ |
126 | 1.81k | quantum|=(((magick_uint32_t) *p++) << 16); \ |
127 | 1.81k | quantum|=(((magick_uint32_t) *p++) << 24); \ |
128 | 1.81k | } \ |
129 | 24.3k | } |
130 | | #define ImportFloat16Quantum(endian,value,p) \ |
131 | 16.9M | { \ |
132 | 16.9M | float float_value; \ |
133 | 16.9M | unsigned char c[2]; \ |
134 | 16.9M | if (MyEndianType == endian) \ |
135 | 16.9M | { \ |
136 | 16.9M | c[0]=*p++; \ |
137 | 16.9M | c[1]=*p++; \ |
138 | 16.9M | } \ |
139 | 16.9M | else \ |
140 | 16.9M | { \ |
141 | 0 | c[1]=*p++; \ |
142 | 0 | c[0]=*p++; \ |
143 | 0 | } \ |
144 | 16.9M | (void) _Gm_convert_fp16_to_fp32((const fp_16bits *)c, \ |
145 | 16.9M | &float_value); \ |
146 | 16.9M | value=float_value; \ |
147 | 16.9M | } |
148 | | #define ImportFloat24Quantum(endian,value,p) \ |
149 | 1.41M | { \ |
150 | 1.41M | float float_value; \ |
151 | 1.41M | unsigned char c[3]; \ |
152 | 1.41M | if (MyEndianType == endian) \ |
153 | 1.41M | { \ |
154 | 0 | c[0]=*p++; \ |
155 | 0 | c[1]=*p++; \ |
156 | 0 | c[2]=*p++; \ |
157 | 0 | } \ |
158 | 1.41M | else \ |
159 | 1.41M | { \ |
160 | 1.41M | c[2]=*p++; \ |
161 | 1.41M | c[1]=*p++; \ |
162 | 1.41M | c[0]=*p++; \ |
163 | 1.41M | } \ |
164 | 1.41M | (void) _Gm_convert_fp24_to_fp32((const fp_24bits *)c, \ |
165 | 1.41M | &float_value, \ |
166 | 1.41M | RANGE_LIMITED); \ |
167 | 1.41M | value=float_value; \ |
168 | 1.41M | } |
169 | | #define ImportFloat32Quantum(endian,value,p) \ |
170 | 11.1M | { \ |
171 | 11.1M | if (MyEndianType == endian) \ |
172 | 11.1M | { \ |
173 | 8.52M | value=*((float *) p); \ |
174 | 8.52M | p += sizeof(float); \ |
175 | 8.52M | } \ |
176 | 11.1M | else \ |
177 | 11.1M | { \ |
178 | 2.59M | union \ |
179 | 2.59M | { \ |
180 | 2.59M | float f; \ |
181 | 2.59M | unsigned char c[4]; \ |
182 | 2.59M | } fu_; \ |
183 | 2.59M | \ |
184 | 2.59M | fu_.c[3]=*p++; \ |
185 | 2.59M | fu_.c[2]=*p++; \ |
186 | 2.59M | fu_.c[1]=*p++; \ |
187 | 2.59M | fu_.c[0]=*p++; \ |
188 | 2.59M | value=fu_.f; \ |
189 | 2.59M | } \ |
190 | 11.1M | } |
191 | | #define ImportFloat64Quantum(endian,value,p) \ |
192 | 2.44M | { \ |
193 | 2.44M | if (MyEndianType == endian) \ |
194 | 2.44M | { \ |
195 | 2.00M | value=*((double *) p); \ |
196 | 2.00M | p += sizeof(double); \ |
197 | 2.00M | } \ |
198 | 2.44M | else \ |
199 | 2.44M | { \ |
200 | 444k | union \ |
201 | 444k | { \ |
202 | 444k | double d; \ |
203 | 444k | unsigned char c[8]; \ |
204 | 444k | } du_; \ |
205 | 444k | \ |
206 | 444k | du_.c[7]=*p++; \ |
207 | 444k | du_.c[6]=*p++; \ |
208 | 444k | du_.c[5]=*p++; \ |
209 | 444k | du_.c[4]=*p++; \ |
210 | 444k | du_.c[3]=*p++; \ |
211 | 444k | du_.c[2]=*p++; \ |
212 | 444k | du_.c[1]=*p++; \ |
213 | 444k | du_.c[0]=*p++; \ |
214 | 444k | value=du_.d; \ |
215 | 444k | } \ |
216 | 2.44M | } |
217 | | |
218 | | /* |
219 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
220 | | % % |
221 | | % % |
222 | | % % |
223 | | % I m p o r t I m a g e P i x e l A r e a % |
224 | | % % |
225 | | % % |
226 | | % % |
227 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
228 | | % |
229 | | % ImportImagePixelArea() transfers one or more pixel components from a user |
230 | | % supplied buffer into the default image pixel cache view. By default, |
231 | | % values are read in network (big-endian) byte/bit order. By setting the |
232 | | % 'endian' member of ExportPixelAreaOptions, 16, 32 and 64-bit values may |
233 | | % be output as little (LSBEndian), big (MSBEndian), or host native |
234 | | % (NativeEndian) endian values. This function is quite powerful in that |
235 | | % besides common native CPU type sizes, it can support any integer bit |
236 | | % depth from 1 to 32 (e.g. 13), 64-bits, as well as 32 and 64-bit float. |
237 | | % |
238 | | % MagickPass is returned if the pixels are successfully transferred, |
239 | | % otherwise MagickFail. |
240 | | % |
241 | | % The format of the ImportImagePixelArea method is: |
242 | | % |
243 | | % MagickPassFail ImportImagePixelArea(Image *image, |
244 | | % const QuantumType quantum_type, |
245 | | % const unsigned int quantum_size, |
246 | | % const unsigned char *source, |
247 | | % const ImportPixelAreaOptions *options, |
248 | | % ImportPixelAreaInfo *import_info) |
249 | | % |
250 | | % A description of each parameter follows: |
251 | | % |
252 | | % o status: Method PushImagePixels returns MagickPass if the pixels are |
253 | | % successfully transferred, otherwise MagickFail. |
254 | | % |
255 | | % o image: The image. |
256 | | % |
257 | | % o quantum_type: Declare which pixel components to transfer (AlphaQuantum, |
258 | | % BlackQuantum, BlueQuantum, CMYKAQuantum, CMYKQuantum, CyanQuantum, |
259 | | % GrayAlphaQuantum, GrayQuantum, GreenQuantum, IndexAlphaQuantum, |
260 | | % IndexQuantum, MagentaQuantum, RGBAQuantum, RGBQuantum, |
261 | | % RedQuantum, YellowQuantum) |
262 | | % |
263 | | % o quantum_size: Bits per quantum sample (range 1-32, and 64). |
264 | | % |
265 | | % o source: The pixel components are transferred from this buffer. |
266 | | % |
267 | | % o options: Additional options specific to quantum_type (may be NULL). |
268 | | % |
269 | | % o import_info : Populated with information regarding the pixels |
270 | | % imported (may be NULL) |
271 | | % |
272 | | */ |
273 | | MagickExport MagickPassFail ImportImagePixelArea(Image *image, |
274 | | const QuantumType quantum_type,const unsigned int quantum_size, |
275 | | const unsigned char *source,const ImportPixelAreaOptions *options, |
276 | | ImportPixelAreaInfo *import_info) |
277 | 22.2M | { |
278 | 22.2M | return ImportViewPixelArea(AccessDefaultCacheView(image), |
279 | 22.2M | quantum_type,quantum_size, |
280 | 22.2M | source,options,import_info); |
281 | 22.2M | } |
282 | | |
283 | | /* |
284 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
285 | | % % |
286 | | % % |
287 | | % % |
288 | | % I m p o r t V i e w P i x e l A r e a % |
289 | | % % |
290 | | % % |
291 | | % % |
292 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
293 | | % |
294 | | % ImportViewPixelArea() transfers one or more pixel components from a user |
295 | | % supplied buffer into the specified image pixel cache view of an image. By |
296 | | % default, values are read in network (big-endian) byte/bit order. By |
297 | | % setting the 'endian' member of ExportPixelAreaOptions, 16, 32 and 64-bit |
298 | | % values may be output as little (LSBEndian), big (MSBEndian), or host |
299 | | % native (NativeEndian) endian values. This function is quite powerful in |
300 | | % that besides common native CPU type sizes, it can support any integer bit |
301 | | % depth from 1 to 32 (e.g. 13), 64-bits, as well as 32 and 64-bit float. |
302 | | % |
303 | | % MagickPass is returned if the pixels are successfully transferred, |
304 | | % otherwise MagickFail. |
305 | | % |
306 | | % The format of the ImportViewPixelArea method is: |
307 | | % |
308 | | % MagickPassFail ImportViewPixelArea(ViewInfo *view, |
309 | | % const QuantumType quantum_type, |
310 | | % const unsigned int quantum_size, |
311 | | % const unsigned char *source, |
312 | | % const ImportPixelAreaOptions *options, |
313 | | % ImportPixelAreaInfo *import_info) |
314 | | % |
315 | | % A description of each parameter follows: |
316 | | % |
317 | | % o status: Method PushImagePixels returns MagickPass if the pixels are |
318 | | % successfully transferred, otherwise MagickFail. |
319 | | % |
320 | | % o view: The pixel view to import pixels into. |
321 | | % |
322 | | % o quantum_type: Declare which pixel components to transfer (AlphaQuantum, |
323 | | % BlackQuantum, BlueQuantum, CMYKAQuantum, CMYKQuantum, CyanQuantum, |
324 | | % GrayAlphaQuantum, GrayQuantum, GreenQuantum, IndexAlphaQuantum, |
325 | | % IndexQuantum, MagentaQuantum, RGBAQuantum, RGBQuantum, |
326 | | % RedQuantum, YellowQuantum) |
327 | | % |
328 | | % o quantum_size: Bits per quantum sample (range 1-32, and 64). |
329 | | % |
330 | | % o source: The pixel components are transferred from this buffer. |
331 | | % |
332 | | % o options: Additional options specific to quantum_type (may be NULL). |
333 | | % |
334 | | % o import_info : Populated with information regarding the pixels |
335 | | % imported (may be NULL) |
336 | | % |
337 | | */ |
338 | | static MagickPassFail |
339 | | ImportIndexQuantumType(const unsigned char *source, |
340 | | PixelPacket* restrict q, |
341 | | IndexPacket * restrict indexes, |
342 | | const unsigned long number_pixels, |
343 | | const unsigned int quantum_size, |
344 | | const QuantumSampleType sample_type, |
345 | | const unsigned int unsigned_maxvalue, |
346 | | const EndianType endian, |
347 | | Image *image, |
348 | | ImportPixelAreaInfo *import_info) |
349 | 215k | { |
350 | 215k | const unsigned char * restrict |
351 | 215k | p; |
352 | | |
353 | 215k | register unsigned long |
354 | 215k | x; |
355 | | |
356 | 215k | register magick_uint32_t |
357 | 215k | index; |
358 | | |
359 | 215k | assert(image->colors <= MaxColormapSize); |
360 | | |
361 | 215k | if ((image->storage_class != PseudoClass) || |
362 | 215k | (image->colors == 0) || |
363 | 215k | (indexes == (IndexPacket *) NULL)) |
364 | 0 | ThrowBinaryException3(ImageError,ImageIsNotColormapped, |
365 | 215k | UnableToImportImagePixels); |
366 | | |
367 | 215k | p=source; |
368 | 215k | if (sample_type == UnsignedQuantumSampleType) |
369 | 215k | { |
370 | 215k | switch (quantum_size) |
371 | 215k | { |
372 | 5.82k | case 1: |
373 | 5.82k | { |
374 | | /* |
375 | | Special fast support for two colors. |
376 | | */ |
377 | 5.82k | register unsigned int |
378 | 5.82k | bit = 8U; |
379 | | |
380 | 66.3k | for (x = number_pixels ; x != 0 ; --x ) |
381 | 60.5k | { |
382 | 60.5k | --bit; |
383 | 60.5k | index=(*p >> bit) & 0x01; |
384 | 60.5k | VerifyColormapIndex(image,index); |
385 | 60.5k | *indexes++=index; |
386 | 60.5k | *q++=image->colormap[index]; |
387 | 60.5k | if (bit == 0) |
388 | 6.57k | { |
389 | 6.57k | bit=8; |
390 | 6.57k | p++; |
391 | 6.57k | } |
392 | 60.5k | } |
393 | 5.82k | break; |
394 | 0 | } |
395 | 8.68k | case 4: |
396 | 8.68k | { |
397 | | /* |
398 | | Special fast support for 16 colors. |
399 | | */ |
400 | 8.68k | register unsigned int |
401 | 8.68k | state = 0; |
402 | | |
403 | 580k | for (x = number_pixels ; x != 0 ; --x ) |
404 | 572k | { |
405 | 572k | state ^= 1; /* Produces 1 0 1 0 ... */ |
406 | 572k | index=(IndexPacket) ((state ? (*p >> 4) : (*p++)) & 0xf); |
407 | 572k | VerifyColormapIndex(image,index); |
408 | 572k | *indexes++=index; |
409 | 572k | *q++=image->colormap[index]; |
410 | 572k | } |
411 | 8.68k | break; |
412 | 0 | } |
413 | 148k | case 8: |
414 | 148k | { |
415 | 148k | if (unsigned_maxvalue <= (unsigned int) (image->colors-1)) |
416 | 81.9k | { |
417 | | /* |
418 | | Special case for when it is impossible to |
419 | | overflow the colormap range. |
420 | | */ |
421 | 38.5M | for (x = number_pixels; x != 0; --x) |
422 | 38.4M | { |
423 | 38.4M | ImportUInt8Quantum(index,p); |
424 | 38.4M | *indexes++=index; |
425 | 38.4M | *q++=image->colormap[index]; |
426 | 38.4M | } |
427 | 81.9k | } |
428 | 66.2k | else |
429 | 66.2k | { |
430 | 2.86M | for (x = number_pixels; x != 0; --x) |
431 | 2.80M | { |
432 | 2.80M | ImportUInt8Quantum(index,p); |
433 | 2.80M | VerifyColormapIndex(image,index); |
434 | 2.80M | *indexes++=index; |
435 | 2.80M | *q++=image->colormap[index]; |
436 | 2.80M | } |
437 | 66.2k | } |
438 | 148k | break; |
439 | 0 | } |
440 | 9.54k | case 16: |
441 | 9.54k | { |
442 | 76.4k | for (x = number_pixels; x != 0; --x) |
443 | 66.9k | { |
444 | 66.9k | ImportUInt16Quantum(endian,index,p); |
445 | 66.9k | VerifyColormapIndex(image,index); |
446 | 66.9k | *indexes++=index; |
447 | 66.9k | *q++=image->colormap[index]; |
448 | 66.9k | } |
449 | 9.54k | break; |
450 | 0 | } |
451 | 0 | case 32: |
452 | 0 | { |
453 | 0 | for (x = number_pixels; x != 0; --x) |
454 | 0 | { |
455 | 0 | ImportUInt32Quantum(endian,index,p); |
456 | 0 | VerifyColormapIndex(image,index); |
457 | 0 | *indexes++=index; |
458 | 0 | *q++=image->colormap[index]; |
459 | 0 | } |
460 | 0 | break; |
461 | 0 | } |
462 | 0 | case 64: |
463 | 0 | { |
464 | 0 | for (x = number_pixels; x != 0; --x) |
465 | 0 | { |
466 | 0 | ImportUInt64Quantum(endian,index,p); |
467 | 0 | VerifyColormapIndex(image,index); |
468 | 0 | *indexes++=index; |
469 | 0 | *q++=image->colormap[index]; |
470 | 0 | } |
471 | 0 | break; |
472 | 0 | } |
473 | 43.7k | default: |
474 | 43.7k | { |
475 | | /* |
476 | | Arbitrary sample size |
477 | | */ |
478 | 43.7k | BitStreamReadHandle |
479 | 43.7k | stream; |
480 | | |
481 | 43.7k | MagickBitStreamInitializeRead(&stream,p); |
482 | 9.84M | for (x = number_pixels; x != 0; --x) |
483 | 9.80M | { |
484 | 9.80M | index=MagickBitStreamMSBRead(&stream,quantum_size); |
485 | 9.80M | VerifyColormapIndex(image,index); |
486 | 9.80M | *indexes++=index; |
487 | 9.80M | *q++=image->colormap[index]; |
488 | 9.80M | } |
489 | 43.7k | break; |
490 | 0 | } |
491 | 215k | } |
492 | 215k | } |
493 | | |
494 | 215k | if (import_info) |
495 | 68.4k | { |
496 | 68.4k | import_info->bytes_imported=p-source; |
497 | 68.4k | } |
498 | | |
499 | 215k | return MagickPass; |
500 | 215k | } |
501 | | |
502 | | static MagickPassFail |
503 | | ImportIndexAlphaQuantumType(const unsigned char *source, |
504 | | PixelPacket* restrict q, |
505 | | IndexPacket * restrict indexes, |
506 | | const unsigned long number_pixels, |
507 | | const unsigned int quantum_size, |
508 | | const QuantumSampleType sample_type, |
509 | | const unsigned int unsigned_scale, |
510 | | const EndianType endian, |
511 | | Image *image, |
512 | | ImportPixelAreaInfo *import_info) |
513 | 9.99k | { |
514 | 9.99k | const unsigned char * restrict |
515 | 9.99k | p; |
516 | | |
517 | 9.99k | register unsigned long |
518 | 9.99k | x; |
519 | | |
520 | 9.99k | register magick_uint32_t |
521 | 9.99k | index, |
522 | 9.99k | unsigned_value; |
523 | | |
524 | 9.99k | unsigned int |
525 | 9.99k | sample_bits; |
526 | | |
527 | 9.99k | assert(image->colors <= MaxColormapSize); |
528 | | |
529 | 9.99k | if ((image->storage_class != PseudoClass) || |
530 | 9.99k | (image->colors == 0) || |
531 | 9.99k | (indexes == (IndexPacket *) NULL)) |
532 | 0 | ThrowBinaryException3(ImageError,ImageIsNotColormapped, |
533 | 9.99k | UnableToImportImagePixels); |
534 | | |
535 | 9.99k | sample_bits=quantum_size; |
536 | 9.99k | p=source; |
537 | | |
538 | 9.99k | if (sample_type == UnsignedQuantumSampleType) |
539 | 9.99k | { |
540 | 9.99k | switch(quantum_size) |
541 | 9.99k | { |
542 | 8.70k | case 8: |
543 | 8.70k | { |
544 | 4.34M | for (x = number_pixels; x != 0; --x) |
545 | 4.33M | { |
546 | 4.33M | ImportUInt8Quantum(index,p); |
547 | 4.33M | VerifyColormapIndex(image,index); |
548 | 4.33M | *indexes++=index; |
549 | 4.33M | *q=image->colormap[index]; |
550 | | |
551 | 4.33M | ImportUInt8Quantum(unsigned_value,p); |
552 | 4.33M | SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(unsigned_value)); |
553 | 4.33M | q++; |
554 | 4.33M | } |
555 | 8.70k | break; |
556 | 0 | } |
557 | 0 | case 16: |
558 | 0 | { |
559 | 0 | for (x = number_pixels; x != 0; --x) |
560 | 0 | { |
561 | 0 | ImportUInt16Quantum(endian,index,p); |
562 | 0 | VerifyColormapIndex(image,index); |
563 | 0 | *indexes++=index; |
564 | 0 | *q=image->colormap[index]; |
565 | |
|
566 | 0 | ImportUInt16Quantum(endian,unsigned_value,p); |
567 | 0 | SetOpacitySample(q,MaxRGB-ScaleShortToQuantum(unsigned_value)); |
568 | 0 | q++; |
569 | 0 | } |
570 | 0 | break; |
571 | 0 | } |
572 | 0 | case 32: |
573 | 0 | { |
574 | 0 | for (x = number_pixels; x != 0; --x) |
575 | 0 | { |
576 | 0 | ImportUInt32Quantum(endian,index,p); |
577 | 0 | VerifyColormapIndex(image,index); |
578 | 0 | *indexes++=index; |
579 | 0 | *q=image->colormap[index]; |
580 | |
|
581 | 0 | ImportUInt32Quantum(endian,unsigned_value,p); |
582 | 0 | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
583 | 0 | q++; |
584 | 0 | } |
585 | 0 | break; |
586 | 0 | } |
587 | 0 | case 64: |
588 | 0 | { |
589 | 0 | for (x = number_pixels; x != 0; --x) |
590 | 0 | { |
591 | 0 | ImportUInt64Quantum(endian,index,p); |
592 | 0 | VerifyColormapIndex(image,index); |
593 | 0 | *indexes++=index; |
594 | 0 | *q=image->colormap[index]; |
595 | |
|
596 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
597 | 0 | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
598 | 0 | q++; |
599 | 0 | } |
600 | 0 | break; |
601 | 0 | } |
602 | 1.29k | default: |
603 | 1.29k | { |
604 | | /* |
605 | | Arbitrary sample size |
606 | | */ |
607 | 1.29k | BitStreamReadHandle |
608 | 1.29k | stream; |
609 | | |
610 | 1.29k | MagickBitStreamInitializeRead(&stream,p); |
611 | 4.98k | for (x = number_pixels; x != 0; --x) |
612 | 3.69k | { |
613 | 3.69k | index=MagickBitStreamMSBRead(&stream,quantum_size); |
614 | 3.69k | VerifyColormapIndex(image,index); |
615 | 3.69k | *indexes++=index; |
616 | 3.69k | *q=image->colormap[index]; |
617 | | |
618 | 3.69k | unsigned_value=MagickBitStreamMSBRead(&stream,quantum_size); |
619 | 3.69k | if (QuantumDepth > sample_bits) |
620 | 3.69k | unsigned_value *= unsigned_scale; |
621 | 0 | else if (QuantumDepth < sample_bits) |
622 | 0 | unsigned_value /= unsigned_scale; |
623 | 3.69k | SetOpacitySample(q,MaxRGB-unsigned_value); |
624 | 3.69k | q++; |
625 | 3.69k | } |
626 | 1.29k | break; |
627 | 0 | } |
628 | 9.99k | } |
629 | 9.99k | } |
630 | | |
631 | 9.99k | if (import_info) |
632 | 9.95k | { |
633 | 9.95k | import_info->bytes_imported=p-source; |
634 | 9.95k | } |
635 | | |
636 | 9.99k | return MagickPass; |
637 | 9.99k | } |
638 | | |
639 | | static MagickPassFail |
640 | | ImportGrayQuantumType(const unsigned char *source, |
641 | | PixelPacket* restrict q, |
642 | | IndexPacket * restrict indexes, |
643 | | const unsigned long number_pixels, |
644 | | const unsigned int quantum_size, |
645 | | const QuantumSampleType sample_type, |
646 | | const unsigned int unsigned_scale, |
647 | | const unsigned int unsigned_maxvalue, |
648 | | const MagickBool grayscale_miniswhite, |
649 | | const double double_minvalue, |
650 | | const double double_scale, |
651 | | const EndianType endian, |
652 | | Image *image, |
653 | | ImportPixelAreaInfo *import_info) |
654 | 16.1M | { |
655 | 16.1M | const unsigned char * restrict |
656 | 16.1M | p; |
657 | | |
658 | 16.1M | register unsigned long |
659 | 16.1M | x; |
660 | | |
661 | 16.1M | double |
662 | 16.1M | double_value; |
663 | | |
664 | 16.1M | register magick_uint32_t |
665 | 16.1M | index, |
666 | 16.1M | unsigned_value; |
667 | | |
668 | 16.1M | unsigned int |
669 | 16.1M | sample_bits; |
670 | | |
671 | 16.1M | sample_bits=quantum_size; |
672 | 16.1M | p=source; |
673 | | |
674 | 16.1M | if (sample_type == UnsignedQuantumSampleType) |
675 | 16.0M | { |
676 | 16.0M | if (DirectClass == image->storage_class) |
677 | 12.9M | { |
678 | | /* |
679 | | DirectClass representation. |
680 | | */ |
681 | 12.9M | switch (quantum_size) |
682 | 12.9M | { |
683 | 10.1M | case 1: |
684 | 10.1M | { |
685 | | /* |
686 | | Special fast support for bi-level gray. |
687 | | */ |
688 | 10.1M | register int |
689 | 10.1M | bit = 8; |
690 | | |
691 | 10.1M | PixelPacket |
692 | 10.1M | min_val, |
693 | 10.1M | max_val; |
694 | | |
695 | 10.1M | if (grayscale_miniswhite) |
696 | 4.74M | { |
697 | 4.74M | min_val=WhitePixel; |
698 | 4.74M | max_val=BlackPixel; |
699 | 4.74M | } |
700 | 5.35M | else |
701 | 5.35M | { |
702 | 5.35M | min_val=BlackPixel; |
703 | 5.35M | max_val=WhitePixel; |
704 | 5.35M | } |
705 | | |
706 | 4.32G | for (x = number_pixels ; x != 0 ; --x ) |
707 | 4.31G | { |
708 | 4.31G | --bit; |
709 | 4.31G | *q++=(((*p >> bit) & 0x01) ? max_val : min_val); |
710 | 4.31G | if (bit == 0) |
711 | 535M | { |
712 | 535M | bit=8; |
713 | 535M | p++; |
714 | 535M | } |
715 | 4.31G | } |
716 | 10.1M | if (bit != 8) |
717 | 7.98M | p++; |
718 | 10.1M | break; |
719 | 0 | } |
720 | 1.02M | case 8: |
721 | 1.02M | { |
722 | 1.02M | if (grayscale_miniswhite) |
723 | 465k | { |
724 | 173M | for (x = number_pixels; x != 0; --x) |
725 | 173M | { |
726 | 173M | SetGraySample(q,MaxRGB-ScaleCharToQuantum(*p++)); |
727 | 173M | SetOpacitySample(q,OpaqueOpacity); |
728 | 173M | q++; |
729 | 173M | } |
730 | 465k | } |
731 | 564k | else |
732 | 564k | { |
733 | 113M | for (x = number_pixels; x != 0; --x) |
734 | 113M | { |
735 | 113M | SetGraySample(q,ScaleCharToQuantum(*p++)); |
736 | 113M | SetOpacitySample(q,OpaqueOpacity); |
737 | 113M | q++; |
738 | 113M | } |
739 | 564k | } |
740 | 1.02M | break; |
741 | 0 | } |
742 | 58.5k | case 16: |
743 | 58.5k | { |
744 | 58.5k | if (grayscale_miniswhite) |
745 | 14.8k | { |
746 | 675k | for (x = number_pixels; x != 0; --x) |
747 | 660k | { |
748 | 660k | ImportUInt16Quantum(endian,unsigned_value,p); |
749 | 660k | SetGraySample(q,MaxRGB-ScaleShortToQuantum(unsigned_value)); |
750 | 660k | SetOpacitySample(q,OpaqueOpacity); |
751 | 660k | q++; |
752 | 660k | } |
753 | 14.8k | } |
754 | 43.7k | else |
755 | 43.7k | { |
756 | 16.0M | for (x = number_pixels; x != 0; --x) |
757 | 16.0M | { |
758 | 16.0M | ImportUInt16Quantum(endian,unsigned_value,p); |
759 | 16.0M | SetGraySample(q,ScaleShortToQuantum(unsigned_value)); |
760 | 16.0M | SetOpacitySample(q,OpaqueOpacity); |
761 | 16.0M | q++; |
762 | 16.0M | } |
763 | 43.7k | } |
764 | 58.5k | break; |
765 | 0 | } |
766 | 164k | case 32: |
767 | 164k | { |
768 | 164k | if (grayscale_miniswhite) |
769 | 1.75k | { |
770 | 108k | for (x = number_pixels; x != 0; --x) |
771 | 106k | { |
772 | 106k | ImportUInt32Quantum(endian,unsigned_value,p); |
773 | 106k | SetGraySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
774 | 106k | SetOpacitySample(q,OpaqueOpacity); |
775 | 106k | q++; |
776 | 106k | } |
777 | 1.75k | } |
778 | 162k | else |
779 | 162k | { |
780 | 89.0M | for (x = number_pixels; x != 0; --x) |
781 | 88.9M | { |
782 | 88.9M | ImportUInt32Quantum(endian,unsigned_value,p); |
783 | 88.9M | SetGraySample(q,ScaleLongToQuantum(unsigned_value)); |
784 | 88.9M | SetOpacitySample(q,OpaqueOpacity); |
785 | 88.9M | q++; |
786 | 88.9M | } |
787 | 162k | } |
788 | 164k | break; |
789 | 0 | } |
790 | 11.2k | case 64: |
791 | 11.2k | { |
792 | 11.2k | if (grayscale_miniswhite) |
793 | 0 | { |
794 | 0 | for (x = number_pixels; x != 0; --x) |
795 | 0 | { |
796 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
797 | 0 | SetGraySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
798 | 0 | SetOpacitySample(q,OpaqueOpacity); |
799 | 0 | q++; |
800 | 0 | } |
801 | 0 | } |
802 | 11.2k | else |
803 | 11.2k | { |
804 | 31.7k | for (x = number_pixels; x != 0; --x) |
805 | 20.5k | { |
806 | 20.5k | ImportUInt64Quantum(endian,unsigned_value,p); |
807 | 20.5k | SetGraySample(q,ScaleLongToQuantum(unsigned_value)); |
808 | 20.5k | SetOpacitySample(q,OpaqueOpacity); |
809 | 20.5k | q++; |
810 | 20.5k | } |
811 | 11.2k | } |
812 | 11.2k | break; |
813 | 0 | } |
814 | 1.63M | default: |
815 | 1.63M | { |
816 | 1.63M | BitStreamReadHandle |
817 | 1.63M | stream; |
818 | | |
819 | 1.63M | MagickBitStreamInitializeRead(&stream,p); |
820 | 229M | for (x = number_pixels; x != 0; --x) |
821 | 228M | { |
822 | 228M | unsigned_value=MagickBitStreamMSBRead(&stream,quantum_size); |
823 | 228M | if (QuantumDepth > sample_bits) |
824 | 224M | unsigned_value *= unsigned_scale; |
825 | 3.32M | else if (QuantumDepth < sample_bits) |
826 | 3.32M | unsigned_value /= unsigned_scale; |
827 | 228M | if (grayscale_miniswhite) |
828 | 69.0M | unsigned_value = MaxRGB-unsigned_value; |
829 | 228M | SetGraySample(q,unsigned_value); |
830 | 228M | SetOpacitySample(q,OpaqueOpacity); |
831 | 228M | q++; |
832 | 228M | } |
833 | 1.63M | break; |
834 | 0 | } |
835 | 12.9M | } |
836 | 12.9M | } |
837 | 3.01M | else |
838 | 3.01M | { |
839 | | /* |
840 | | PseudoClass representation. |
841 | | |
842 | | Note that this implementation assumes that the |
843 | | colormap is written in ascending levels of intensity |
844 | | as produced by AllocateImageColormap(). Some old |
845 | | code may assume that 'miniswhite' inverts the |
846 | | colormap order as well. |
847 | | */ |
848 | 3.01M | assert(image->colors <= MaxColormapSize); |
849 | | |
850 | 3.01M | if ((image->storage_class != PseudoClass) || |
851 | 3.01M | (image->colors == 0) || |
852 | 3.01M | (indexes == (IndexPacket *) NULL)) |
853 | 0 | ThrowBinaryException3(ImageError,ImageIsNotColormapped, |
854 | 3.01M | UnableToImportImagePixels); |
855 | | |
856 | 3.01M | switch (quantum_size) |
857 | 3.01M | { |
858 | 2.62M | case 1: |
859 | 2.62M | { |
860 | | /* |
861 | | Special fast support for bi-level gray. |
862 | | */ |
863 | 2.62M | register int |
864 | 2.62M | bit = 8; |
865 | | |
866 | 1.22G | for (x = number_pixels ; x != 0 ; --x ) |
867 | 1.21G | { |
868 | 1.21G | --bit; |
869 | 1.21G | index=(*p >> bit) & 0x01; |
870 | 1.21G | if (grayscale_miniswhite) |
871 | 1.15G | index ^= 0x01; |
872 | 1.21G | *indexes++=index; |
873 | 1.21G | *q++=image->colormap[index]; |
874 | 1.21G | if (bit == 0) |
875 | 151M | { |
876 | 151M | bit=8; |
877 | 151M | p++; |
878 | 151M | } |
879 | 1.21G | } |
880 | 2.62M | if (bit != 8) |
881 | 2.25M | p++; |
882 | 2.62M | break; |
883 | 0 | } |
884 | 344k | case 8: |
885 | 344k | { |
886 | 51.1M | for (x = number_pixels; x != 0; --x) |
887 | 50.8M | { |
888 | 50.8M | ImportUInt8Quantum(index,p); |
889 | 50.8M | VerifyColormapIndex(image,index); |
890 | 50.8M | if (grayscale_miniswhite) |
891 | 0 | index=(image->colors-1)-index; |
892 | 50.8M | *indexes++=index; |
893 | 50.8M | *q++=image->colormap[index]; |
894 | 50.8M | } |
895 | 344k | break; |
896 | 0 | } |
897 | 45.8k | case 16: |
898 | 45.8k | { |
899 | 6.00M | for (x = number_pixels; x != 0; --x) |
900 | 5.95M | { |
901 | 5.95M | ImportUInt16Quantum(endian,index,p); |
902 | 5.95M | VerifyColormapIndex(image,index); |
903 | 5.95M | if (grayscale_miniswhite) |
904 | 0 | index=(image->colors-1)-index; |
905 | 5.95M | *indexes++=index; |
906 | 5.95M | *q++=image->colormap[index]; |
907 | 5.95M | } |
908 | 45.8k | break; |
909 | 0 | } |
910 | 0 | case 32: |
911 | 0 | { |
912 | 0 | for (x = number_pixels; x != 0; --x) |
913 | 0 | { |
914 | 0 | ImportUInt32Quantum(endian,index,p); |
915 | 0 | VerifyColormapIndex(image,index); |
916 | 0 | if (grayscale_miniswhite) |
917 | 0 | index=(image->colors-1)-index; |
918 | 0 | *indexes++=index; |
919 | 0 | *q++=image->colormap[index]; |
920 | 0 | } |
921 | 0 | break; |
922 | 0 | } |
923 | 0 | case 64: |
924 | 0 | { |
925 | 0 | for (x = number_pixels; x != 0; --x) |
926 | 0 | { |
927 | 0 | ImportUInt64Quantum(endian,index,p); |
928 | 0 | VerifyColormapIndex(image,index); |
929 | 0 | if (grayscale_miniswhite) |
930 | 0 | index=(image->colors-1)-index; |
931 | 0 | *indexes++=index; |
932 | 0 | *q++=image->colormap[index]; |
933 | 0 | } |
934 | 0 | break; |
935 | 0 | } |
936 | 0 | default: |
937 | 0 | { |
938 | | /* |
939 | | Arbitrary sample size |
940 | | */ |
941 | 0 | BitStreamReadHandle |
942 | 0 | stream; |
943 | |
|
944 | 0 | register unsigned int |
945 | 0 | indexes_scale = 1U; |
946 | |
|
947 | 0 | if (unsigned_maxvalue > (image->colors-1)) |
948 | 0 | indexes_scale=(unsigned_maxvalue/(image->colors-1)); |
949 | |
|
950 | 0 | MagickBitStreamInitializeRead(&stream,p); |
951 | 0 | for (x = number_pixels; x != 0; --x) |
952 | 0 | { |
953 | 0 | index=MagickBitStreamMSBRead(&stream,quantum_size); |
954 | 0 | index /= indexes_scale; |
955 | 0 | VerifyColormapIndex(image,index); |
956 | 0 | if (grayscale_miniswhite) |
957 | 0 | index=(image->colors-1)-index; |
958 | 0 | *indexes++=index; |
959 | 0 | *q++=image->colormap[index]; |
960 | 0 | } |
961 | 0 | break; |
962 | 0 | } |
963 | 3.01M | } |
964 | 3.01M | } |
965 | 16.0M | } |
966 | 112k | else if (sample_type == FloatQuantumSampleType) |
967 | 112k | { |
968 | 112k | switch (quantum_size) |
969 | 112k | { |
970 | 4.17k | case 16: |
971 | 4.17k | { |
972 | 211k | for (x = number_pixels; x != 0; --x) |
973 | 206k | { |
974 | 206k | ImportFloat16Quantum(endian,double_value,p); |
975 | 206k | double_value -= double_minvalue; |
976 | 206k | double_value *= double_scale; |
977 | 206k | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
978 | 206k | q++; |
979 | 206k | } |
980 | 4.17k | break; |
981 | 0 | } |
982 | 2.37k | case 24: |
983 | 2.37k | { |
984 | 110k | for (x = number_pixels; x != 0; --x) |
985 | 107k | { |
986 | 107k | ImportFloat24Quantum(endian,double_value,p); |
987 | 107k | double_value -= double_minvalue; |
988 | 107k | double_value *= double_scale; |
989 | 107k | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
990 | 107k | q++; |
991 | 107k | } |
992 | 2.37k | break; |
993 | 0 | } |
994 | 54.4k | case 32: |
995 | 54.4k | { |
996 | 4.50M | for (x = number_pixels; x != 0; --x) |
997 | 4.44M | { |
998 | 4.44M | ImportFloat32Quantum(endian,double_value,p); |
999 | 4.44M | double_value -= double_minvalue; |
1000 | 4.44M | double_value *= double_scale; |
1001 | 4.44M | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
1002 | 4.44M | q++; |
1003 | 4.44M | } |
1004 | 54.4k | break; |
1005 | 0 | } |
1006 | 51.5k | case 64: |
1007 | 51.5k | { |
1008 | 1.52M | for (x = number_pixels; x != 0; --x) |
1009 | 1.47M | { |
1010 | 1.47M | ImportFloat64Quantum(endian,double_value,p); |
1011 | 1.47M | double_value -= double_minvalue; |
1012 | 1.47M | double_value *= double_scale; |
1013 | 1.47M | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
1014 | 1.47M | q++; |
1015 | 1.47M | } |
1016 | 51.5k | break; |
1017 | 0 | } |
1018 | 0 | default: |
1019 | 0 | break; |
1020 | 112k | } |
1021 | 112k | } |
1022 | | |
1023 | 16.1M | if (import_info) |
1024 | 6.76M | { |
1025 | 6.76M | import_info->bytes_imported=p-source; |
1026 | 6.76M | } |
1027 | | |
1028 | 16.1M | return MagickPass; |
1029 | 16.1M | } |
1030 | | |
1031 | | static MagickPassFail |
1032 | | ImportGrayAlphaQuantumType(const unsigned char *source, |
1033 | | PixelPacket* restrict q, |
1034 | | IndexPacket * restrict indexes, |
1035 | | const unsigned long number_pixels, |
1036 | | const unsigned int quantum_size, |
1037 | | const QuantumSampleType sample_type, |
1038 | | const unsigned int unsigned_scale, |
1039 | | const unsigned int unsigned_maxvalue, |
1040 | | const MagickBool grayscale_miniswhite, |
1041 | | const double double_minvalue, |
1042 | | const double double_scale, |
1043 | | const EndianType endian, |
1044 | | Image *image, |
1045 | | ImportPixelAreaInfo *import_info) |
1046 | 64.4k | { |
1047 | 64.4k | const unsigned char * restrict |
1048 | 64.4k | p; |
1049 | | |
1050 | 64.4k | register unsigned long |
1051 | 64.4k | x; |
1052 | | |
1053 | 64.4k | double |
1054 | 64.4k | double_value; |
1055 | | |
1056 | 64.4k | register magick_uint32_t |
1057 | 64.4k | index, |
1058 | 64.4k | unsigned_value; |
1059 | | |
1060 | 64.4k | unsigned int |
1061 | 64.4k | sample_bits; |
1062 | | |
1063 | 64.4k | sample_bits=quantum_size; |
1064 | 64.4k | p=source; |
1065 | | |
1066 | 64.4k | if (sample_type == UnsignedQuantumSampleType) |
1067 | 36.4k | { |
1068 | 36.4k | if (DirectClass == image->storage_class) |
1069 | 36.4k | { |
1070 | | /* |
1071 | | DirectClass representation. |
1072 | | */ |
1073 | 36.4k | switch (quantum_size) |
1074 | 36.4k | { |
1075 | 12.6k | case 8: |
1076 | 12.6k | { |
1077 | 12.6k | if (grayscale_miniswhite) |
1078 | 4.38k | { |
1079 | 1.09M | for (x = number_pixels; x != 0; --x) |
1080 | 1.08M | { |
1081 | 1.08M | ImportUInt8Quantum(unsigned_value,p); |
1082 | 1.08M | SetGraySample(q,MaxRGB-ScaleCharToQuantum(unsigned_value)); |
1083 | 1.08M | ImportUInt8Quantum(unsigned_value,p); |
1084 | 1.08M | SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(unsigned_value)); |
1085 | 1.08M | q++; |
1086 | 1.08M | } |
1087 | 4.38k | } |
1088 | 8.29k | else |
1089 | 8.29k | { |
1090 | 2.31M | for (x = number_pixels; x != 0; --x) |
1091 | 2.30M | { |
1092 | 2.30M | ImportUInt8Quantum(unsigned_value,p); |
1093 | 2.30M | SetGraySample(q,ScaleCharToQuantum(unsigned_value)); |
1094 | 2.30M | ImportUInt8Quantum(unsigned_value,p); |
1095 | 2.30M | SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(unsigned_value)); |
1096 | 2.30M | q++; |
1097 | 2.30M | } |
1098 | 8.29k | } |
1099 | 12.6k | break; |
1100 | 0 | } |
1101 | 6.84k | case 16: |
1102 | 6.84k | { |
1103 | 6.84k | if (grayscale_miniswhite) |
1104 | 1.11k | { |
1105 | 6.83k | for (x = number_pixels; x != 0; --x) |
1106 | 5.71k | { |
1107 | 5.71k | ImportUInt16Quantum(endian,unsigned_value,p); |
1108 | 5.71k | SetGraySample(q,MaxRGB-ScaleShortToQuantum(unsigned_value)); |
1109 | 5.71k | ImportUInt16Quantum(endian,unsigned_value,p); |
1110 | 5.71k | SetOpacitySample(q,MaxRGB-ScaleShortToQuantum(unsigned_value)); |
1111 | 5.71k | q++; |
1112 | 5.71k | } |
1113 | 1.11k | } |
1114 | 5.72k | else |
1115 | 5.72k | { |
1116 | 196k | for (x = number_pixels; x != 0; --x) |
1117 | 190k | { |
1118 | 190k | ImportUInt16Quantum(endian,unsigned_value,p); |
1119 | 190k | SetGraySample(q,ScaleShortToQuantum(unsigned_value)); |
1120 | 190k | ImportUInt16Quantum(endian,unsigned_value,p); |
1121 | 190k | SetOpacitySample(q,MaxRGB-ScaleShortToQuantum(unsigned_value)); |
1122 | 190k | q++; |
1123 | 190k | } |
1124 | 5.72k | } |
1125 | 6.84k | break; |
1126 | 0 | } |
1127 | 5.25k | case 32: |
1128 | 5.25k | { |
1129 | 5.25k | if (grayscale_miniswhite) |
1130 | 3.15k | { |
1131 | 397k | for (x = number_pixels; x != 0; --x) |
1132 | 394k | { |
1133 | 394k | ImportUInt32Quantum(endian,unsigned_value,p); |
1134 | 394k | SetGraySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
1135 | 394k | ImportUInt32Quantum(endian,unsigned_value,p); |
1136 | 394k | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
1137 | 394k | q++; |
1138 | 394k | } |
1139 | 3.15k | } |
1140 | 2.10k | else |
1141 | 2.10k | { |
1142 | 23.5k | for (x = number_pixels; x != 0; --x) |
1143 | 21.4k | { |
1144 | 21.4k | ImportUInt32Quantum(endian,unsigned_value,p); |
1145 | 21.4k | SetGraySample(q,ScaleLongToQuantum(unsigned_value)); |
1146 | 21.4k | ImportUInt32Quantum(endian,unsigned_value,p); |
1147 | 21.4k | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
1148 | 21.4k | q++; |
1149 | 21.4k | } |
1150 | 2.10k | } |
1151 | 5.25k | break; |
1152 | 0 | } |
1153 | 0 | case 64: |
1154 | 0 | { |
1155 | 0 | if (grayscale_miniswhite) |
1156 | 0 | { |
1157 | 0 | for (x = number_pixels; x != 0; --x) |
1158 | 0 | { |
1159 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
1160 | 0 | SetGraySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
1161 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
1162 | 0 | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
1163 | 0 | q++; |
1164 | 0 | } |
1165 | 0 | } |
1166 | 0 | else |
1167 | 0 | { |
1168 | 0 | for (x = number_pixels; x != 0; --x) |
1169 | 0 | { |
1170 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
1171 | 0 | SetGraySample(q,ScaleLongToQuantum(unsigned_value)); |
1172 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
1173 | 0 | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
1174 | 0 | q++; |
1175 | 0 | } |
1176 | 0 | } |
1177 | 0 | break; |
1178 | 0 | } |
1179 | 11.7k | default: |
1180 | 11.7k | { |
1181 | | /* |
1182 | | Arbitrary Depth. |
1183 | | */ |
1184 | 11.7k | BitStreamReadHandle |
1185 | 11.7k | stream; |
1186 | | |
1187 | 11.7k | MagickBitStreamInitializeRead(&stream,p); |
1188 | 1.64M | for (x = number_pixels; x != 0; --x) |
1189 | 1.63M | { |
1190 | 1.63M | unsigned_value=MagickBitStreamMSBRead(&stream,quantum_size); |
1191 | 1.63M | if (QuantumDepth > sample_bits) |
1192 | 1.62M | unsigned_value *= unsigned_scale; |
1193 | 7.58k | else if (QuantumDepth < sample_bits) |
1194 | 7.58k | unsigned_value /= unsigned_scale; |
1195 | 1.63M | if (grayscale_miniswhite) |
1196 | 554k | unsigned_value = MaxRGB-unsigned_value; |
1197 | 1.63M | SetGraySample(q,unsigned_value); |
1198 | | |
1199 | 1.63M | unsigned_value=MagickBitStreamMSBRead(&stream,quantum_size); |
1200 | 1.63M | if (QuantumDepth > sample_bits) |
1201 | 1.62M | unsigned_value *= unsigned_scale; |
1202 | 7.58k | else if (QuantumDepth < sample_bits) |
1203 | 7.58k | unsigned_value /= unsigned_scale; |
1204 | 1.63M | SetOpacitySample(q,MaxRGB-unsigned_value); |
1205 | 1.63M | q++; |
1206 | 1.63M | } |
1207 | 11.7k | break; |
1208 | 0 | } |
1209 | 36.4k | } |
1210 | 36.4k | } |
1211 | 0 | else |
1212 | 0 | { |
1213 | | /* |
1214 | | PseudoClass representation. |
1215 | | */ |
1216 | | /* |
1217 | | Input is organized as a gray level followed by opacity level |
1218 | | Colormap array is pre-stuffed with ascending or descending gray |
1219 | | levels according to the gray quantum representation. |
1220 | | */ |
1221 | 0 | register unsigned int |
1222 | 0 | indexes_scale = 1U; |
1223 | |
|
1224 | 0 | assert(image->colors <= MaxColormapSize); |
1225 | |
|
1226 | 0 | if ((image->storage_class != PseudoClass) || |
1227 | 0 | (image->colors == 0) || |
1228 | 0 | (indexes == (IndexPacket *) NULL)) |
1229 | 0 | ThrowBinaryException3(ImageError,ImageIsNotColormapped, |
1230 | 0 | UnableToImportImagePixels); |
1231 | |
|
1232 | 0 | if (unsigned_maxvalue > (image->colors-1)) |
1233 | 0 | indexes_scale=(unsigned_maxvalue/(image->colors-1)); |
1234 | |
|
1235 | 0 | if ( (quantum_size >= 8) && (quantum_size % 8U == 0U) ) |
1236 | 0 | { |
1237 | | /* |
1238 | | Modulo-8 sample sizes |
1239 | | */ |
1240 | 0 | if (indexes_scale == 1U) |
1241 | 0 | { |
1242 | 0 | for (x = number_pixels; x != 0; --x) |
1243 | 0 | { |
1244 | 0 | ImportModulo8Quantum(index,quantum_size,p); |
1245 | 0 | VerifyColormapIndex(image,index); |
1246 | 0 | if (grayscale_miniswhite) |
1247 | 0 | index=(image->colors-1)-index; |
1248 | 0 | *indexes++=index; |
1249 | 0 | *q=image->colormap[index]; |
1250 | |
|
1251 | 0 | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
1252 | 0 | if (QuantumDepth > sample_bits) |
1253 | 0 | unsigned_value *= unsigned_scale; |
1254 | 0 | else if (QuantumDepth < sample_bits) |
1255 | 0 | unsigned_value /= unsigned_scale; |
1256 | 0 | SetOpacitySample(q,MaxRGB-unsigned_value); |
1257 | 0 | q++; |
1258 | 0 | } |
1259 | 0 | } |
1260 | 0 | else |
1261 | 0 | { |
1262 | 0 | for (x = number_pixels; x != 0; --x) |
1263 | 0 | { |
1264 | 0 | ImportModulo8Quantum(index,quantum_size,p); |
1265 | 0 | index /= indexes_scale; |
1266 | 0 | VerifyColormapIndex(image,index); |
1267 | 0 | if (grayscale_miniswhite) |
1268 | 0 | index=(image->colors-1)-index; |
1269 | 0 | *indexes++=index; |
1270 | 0 | *q=image->colormap[index]; |
1271 | |
|
1272 | 0 | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
1273 | 0 | if (QuantumDepth > sample_bits) |
1274 | 0 | unsigned_value *= unsigned_scale; |
1275 | 0 | else if (QuantumDepth < sample_bits) |
1276 | 0 | unsigned_value /= unsigned_scale; |
1277 | 0 | SetOpacitySample(q,MaxRGB-unsigned_value); |
1278 | 0 | q++; |
1279 | 0 | } |
1280 | 0 | } |
1281 | 0 | } |
1282 | 0 | else |
1283 | 0 | { |
1284 | | /* |
1285 | | Arbitrary sample size |
1286 | | */ |
1287 | 0 | BitStreamReadHandle |
1288 | 0 | stream; |
1289 | |
|
1290 | 0 | MagickBitStreamInitializeRead(&stream,p); |
1291 | 0 | for (x = number_pixels; x != 0; --x) |
1292 | 0 | { |
1293 | 0 | index=MagickBitStreamMSBRead(&stream,quantum_size); |
1294 | 0 | index /= indexes_scale; |
1295 | 0 | VerifyColormapIndex(image,index); |
1296 | 0 | if (grayscale_miniswhite) |
1297 | 0 | index=(image->colors-1)-index; |
1298 | 0 | *indexes++=index; |
1299 | 0 | *q=image->colormap[index]; |
1300 | |
|
1301 | 0 | unsigned_value=MagickBitStreamMSBRead(&stream,quantum_size); |
1302 | 0 | if (QuantumDepth > sample_bits) |
1303 | 0 | unsigned_value *= unsigned_scale; |
1304 | 0 | else if (QuantumDepth < sample_bits) |
1305 | 0 | unsigned_value /= unsigned_scale; |
1306 | 0 | SetOpacitySample(q,MaxRGB-unsigned_value); |
1307 | 0 | q++; |
1308 | 0 | } |
1309 | 0 | } |
1310 | 0 | } |
1311 | 36.4k | } |
1312 | 27.9k | else if (sample_type == FloatQuantumSampleType) |
1313 | 27.9k | { |
1314 | 27.9k | switch (quantum_size) |
1315 | 27.9k | { |
1316 | 6.63k | case 16: |
1317 | 6.63k | { |
1318 | 322k | for (x = number_pixels; x != 0; --x) |
1319 | 316k | { |
1320 | 316k | ImportFloat16Quantum(endian,double_value,p); |
1321 | 316k | double_value -= double_minvalue; |
1322 | 316k | double_value *= double_scale; |
1323 | 316k | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
1324 | 316k | ImportFloat16Quantum(endian,double_value,p); |
1325 | 316k | double_value -= double_minvalue; |
1326 | 316k | double_value *= double_scale; |
1327 | 316k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
1328 | 316k | q++; |
1329 | 316k | } |
1330 | 6.63k | break; |
1331 | 0 | } |
1332 | 4.86k | case 24: |
1333 | 4.86k | { |
1334 | 199k | for (x = number_pixels; x != 0; --x) |
1335 | 194k | { |
1336 | 194k | ImportFloat24Quantum(endian,double_value,p); |
1337 | 194k | double_value -= double_minvalue; |
1338 | 194k | double_value *= double_scale; |
1339 | 194k | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
1340 | 194k | ImportFloat24Quantum(endian,double_value,p); |
1341 | 194k | double_value -= double_minvalue; |
1342 | 194k | double_value *= double_scale; |
1343 | 194k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
1344 | 194k | q++; |
1345 | 194k | } |
1346 | 4.86k | break; |
1347 | 0 | } |
1348 | 4.33k | case 32: |
1349 | 4.33k | { |
1350 | 73.2k | for (x = number_pixels; x != 0; --x) |
1351 | 68.8k | { |
1352 | 68.8k | ImportFloat32Quantum(endian,double_value,p); |
1353 | 68.8k | double_value -= double_minvalue; |
1354 | 68.8k | double_value *= double_scale; |
1355 | 68.8k | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
1356 | 68.8k | ImportFloat32Quantum(endian,double_value,p); |
1357 | 68.8k | double_value -= double_minvalue; |
1358 | 68.8k | double_value *= double_scale; |
1359 | 68.8k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
1360 | 68.8k | q++; |
1361 | 68.8k | } |
1362 | 4.33k | break; |
1363 | 0 | } |
1364 | 12.0k | case 64: |
1365 | 12.0k | { |
1366 | 146k | for (x = number_pixels; x != 0; --x) |
1367 | 134k | { |
1368 | 134k | ImportFloat64Quantum(endian,double_value,p); |
1369 | 134k | double_value -= double_minvalue; |
1370 | 134k | double_value *= double_scale; |
1371 | 134k | SetGraySample(q,RoundDoubleToQuantumN(double_value)); |
1372 | 134k | ImportFloat64Quantum(endian,double_value,p); |
1373 | 134k | double_value -= double_minvalue; |
1374 | 134k | double_value *= double_scale; |
1375 | 134k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
1376 | 134k | q++; |
1377 | 134k | } |
1378 | 12.0k | break; |
1379 | 0 | } |
1380 | 0 | default: |
1381 | 0 | break; |
1382 | 27.9k | } |
1383 | 27.9k | } |
1384 | | |
1385 | 64.4k | if (import_info) |
1386 | 58.0k | { |
1387 | 58.0k | import_info->bytes_imported=p-source; |
1388 | 58.0k | } |
1389 | | |
1390 | 64.4k | return MagickPass; |
1391 | 64.4k | } |
1392 | | |
1393 | | static MagickPassFail |
1394 | | ImportRedQuantumType(const unsigned char *source, |
1395 | | PixelPacket* restrict q, |
1396 | | const unsigned long number_pixels, |
1397 | | const unsigned int quantum_size, |
1398 | | const QuantumSampleType sample_type, |
1399 | | const unsigned int unsigned_scale, |
1400 | | const double double_minvalue, |
1401 | | const double double_scale, |
1402 | | const EndianType endian, |
1403 | | ImportPixelAreaInfo *import_info) |
1404 | 621k | { |
1405 | 621k | const unsigned char * restrict |
1406 | 621k | p; |
1407 | | |
1408 | 621k | register unsigned long |
1409 | 621k | x; |
1410 | | |
1411 | 621k | double |
1412 | 621k | double_value; |
1413 | | |
1414 | 621k | register magick_uint32_t |
1415 | 621k | unsigned_value; |
1416 | | |
1417 | 621k | unsigned int |
1418 | 621k | sample_bits; |
1419 | | |
1420 | 621k | sample_bits=quantum_size; |
1421 | 621k | p=source; |
1422 | | |
1423 | 621k | if (sample_type == UnsignedQuantumSampleType) |
1424 | 610k | { |
1425 | 610k | switch (quantum_size) |
1426 | 610k | { |
1427 | 577k | case 8: |
1428 | 577k | { |
1429 | 194M | for (x = number_pixels; x != 0; --x) |
1430 | 193M | { |
1431 | 193M | SetRedSample(q,ScaleCharToQuantum(*p++)); |
1432 | 193M | q++; |
1433 | 193M | } |
1434 | 577k | break; |
1435 | 0 | } |
1436 | 3.24k | case 16: |
1437 | 3.24k | { |
1438 | 254k | for (x = number_pixels; x != 0; --x) |
1439 | 251k | { |
1440 | 251k | ImportUInt16Quantum(endian,unsigned_value,p); |
1441 | 251k | SetRedSample(q,ScaleShortToQuantum(unsigned_value)); |
1442 | 251k | q++; |
1443 | 251k | } |
1444 | 3.24k | break; |
1445 | 0 | } |
1446 | 3.15k | case 32: |
1447 | 3.15k | { |
1448 | 184k | for (x = number_pixels; x != 0; --x) |
1449 | 181k | { |
1450 | 181k | ImportUInt32Quantum(endian,unsigned_value,p); |
1451 | 181k | SetRedSample(q,ScaleLongToQuantum(unsigned_value)); |
1452 | 181k | q++; |
1453 | 181k | } |
1454 | 3.15k | break; |
1455 | 0 | } |
1456 | 766 | case 64: |
1457 | 766 | { |
1458 | 2.65k | for (x = number_pixels; x != 0; --x) |
1459 | 1.89k | { |
1460 | 1.89k | ImportUInt64Quantum(endian,unsigned_value,p); |
1461 | 1.89k | SetRedSample(q,ScaleLongToQuantum(unsigned_value)); |
1462 | 1.89k | q++; |
1463 | 1.89k | } |
1464 | 766 | break; |
1465 | 0 | } |
1466 | 25.0k | default: |
1467 | 25.0k | { |
1468 | | /* |
1469 | | Arbitrary sample size |
1470 | | */ |
1471 | 25.0k | BitStreamReadHandle |
1472 | 25.0k | stream; |
1473 | | |
1474 | 25.0k | MagickBitStreamInitializeRead(&stream,p); |
1475 | 25.0k | if (QuantumDepth >= sample_bits) |
1476 | 23.6k | { |
1477 | | /* Scale up */ |
1478 | 17.3M | for (x = number_pixels; x != 0; --x) |
1479 | 17.2M | { |
1480 | 17.2M | SetRedSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
1481 | 17.2M | q++; |
1482 | 17.2M | } |
1483 | 23.6k | } |
1484 | 1.40k | else |
1485 | 1.40k | { |
1486 | | /* Scale down */ |
1487 | 51.8k | for (x = number_pixels; x != 0; --x) |
1488 | 50.4k | { |
1489 | 50.4k | SetRedSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
1490 | 50.4k | q++; |
1491 | 50.4k | } |
1492 | 1.40k | } |
1493 | 25.0k | break; |
1494 | 0 | } |
1495 | 610k | } |
1496 | 610k | } |
1497 | 11.6k | else if (sample_type == FloatQuantumSampleType) |
1498 | 11.6k | { |
1499 | 11.6k | switch (quantum_size) |
1500 | 11.6k | { |
1501 | 2.28k | case 16: |
1502 | 2.28k | { |
1503 | 11.5k | for (x = number_pixels; x != 0; --x) |
1504 | 9.30k | { |
1505 | 9.30k | ImportFloat16Quantum(endian,double_value,p); |
1506 | 9.30k | double_value -= double_minvalue; |
1507 | 9.30k | double_value *= double_scale; |
1508 | 9.30k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
1509 | 9.30k | q++; |
1510 | 9.30k | } |
1511 | 2.28k | break; |
1512 | 0 | } |
1513 | 1.28k | case 24: |
1514 | 1.28k | { |
1515 | 22.3k | for (x = number_pixels; x != 0; --x) |
1516 | 21.0k | { |
1517 | 21.0k | ImportFloat24Quantum(endian,double_value,p); |
1518 | 21.0k | double_value -= double_minvalue; |
1519 | 21.0k | double_value *= double_scale; |
1520 | 21.0k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
1521 | 21.0k | q++; |
1522 | 21.0k | } |
1523 | 1.28k | break; |
1524 | 0 | } |
1525 | 4.11k | case 32: |
1526 | 4.11k | { |
1527 | 83.7k | for (x = number_pixels; x != 0; --x) |
1528 | 79.6k | { |
1529 | 79.6k | ImportFloat32Quantum(endian,double_value,p); |
1530 | 79.6k | double_value -= double_minvalue; |
1531 | 79.6k | double_value *= double_scale; |
1532 | 79.6k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
1533 | 79.6k | q++; |
1534 | 79.6k | } |
1535 | 4.11k | break; |
1536 | 0 | } |
1537 | 3.95k | case 64: |
1538 | 3.95k | { |
1539 | 21.6k | for (x = number_pixels; x != 0; --x) |
1540 | 17.6k | { |
1541 | 17.6k | ImportFloat64Quantum(endian,double_value,p); |
1542 | 17.6k | double_value -= double_minvalue; |
1543 | 17.6k | double_value *= double_scale; |
1544 | 17.6k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
1545 | 17.6k | q++; |
1546 | 17.6k | } |
1547 | 3.95k | break; |
1548 | 0 | } |
1549 | 0 | default: |
1550 | 0 | break; |
1551 | 11.6k | } |
1552 | 11.6k | } |
1553 | | |
1554 | 621k | if (import_info) |
1555 | 27.8k | { |
1556 | 27.8k | import_info->bytes_imported=p-source; |
1557 | 27.8k | } |
1558 | | |
1559 | 621k | return MagickPass; |
1560 | 621k | } |
1561 | | |
1562 | | static MagickPassFail |
1563 | | ImportGreenQuantumType(const unsigned char *source, |
1564 | | PixelPacket* restrict q, |
1565 | | const unsigned long number_pixels, |
1566 | | const unsigned int quantum_size, |
1567 | | const QuantumSampleType sample_type, |
1568 | | const unsigned int unsigned_scale, |
1569 | | const double double_minvalue, |
1570 | | const double double_scale, |
1571 | | const EndianType endian, |
1572 | | ImportPixelAreaInfo *import_info) |
1573 | 309k | { |
1574 | 309k | const unsigned char * restrict |
1575 | 309k | p; |
1576 | | |
1577 | 309k | register unsigned long |
1578 | 309k | x; |
1579 | | |
1580 | 309k | double |
1581 | 309k | double_value; |
1582 | | |
1583 | 309k | register magick_uint32_t |
1584 | 309k | unsigned_value; |
1585 | | |
1586 | 309k | unsigned int |
1587 | 309k | sample_bits; |
1588 | | |
1589 | 309k | sample_bits=quantum_size; |
1590 | 309k | p=source; |
1591 | | |
1592 | 309k | if (sample_type == UnsignedQuantumSampleType) |
1593 | 299k | { |
1594 | 299k | switch (quantum_size) |
1595 | 299k | { |
1596 | 286k | case 8: |
1597 | 286k | { |
1598 | 92.7M | for (x = number_pixels; x != 0; --x) |
1599 | 92.4M | { |
1600 | 92.4M | SetGreenSample(q,ScaleCharToQuantum(*p++)); |
1601 | 92.4M | q++; |
1602 | 92.4M | } |
1603 | 286k | break; |
1604 | 0 | } |
1605 | 2.66k | case 16: |
1606 | 2.66k | { |
1607 | 12.8k | for (x = number_pixels; x != 0; --x) |
1608 | 10.1k | { |
1609 | 10.1k | ImportUInt16Quantum(endian,unsigned_value,p); |
1610 | 10.1k | SetGreenSample(q,ScaleShortToQuantum(unsigned_value)); |
1611 | 10.1k | q++; |
1612 | 10.1k | } |
1613 | 2.66k | break; |
1614 | 0 | } |
1615 | 1.53k | case 32: |
1616 | 1.53k | { |
1617 | 6.82k | for (x = number_pixels; x != 0; --x) |
1618 | 5.28k | { |
1619 | 5.28k | ImportUInt32Quantum(endian,unsigned_value,p); |
1620 | 5.28k | SetGreenSample(q,ScaleLongToQuantum(unsigned_value)); |
1621 | 5.28k | q++; |
1622 | 5.28k | } |
1623 | 1.53k | break; |
1624 | 0 | } |
1625 | 551 | case 64: |
1626 | 551 | { |
1627 | 1.89k | for (x = number_pixels; x != 0; --x) |
1628 | 1.34k | { |
1629 | 1.34k | ImportUInt64Quantum(endian,unsigned_value,p); |
1630 | 1.34k | SetGreenSample(q,ScaleLongToQuantum(unsigned_value)); |
1631 | 1.34k | q++; |
1632 | 1.34k | } |
1633 | 551 | break; |
1634 | 0 | } |
1635 | 8.40k | default: |
1636 | 8.40k | { |
1637 | | /* |
1638 | | Arbitrary sample size |
1639 | | */ |
1640 | 8.40k | BitStreamReadHandle |
1641 | 8.40k | stream; |
1642 | | |
1643 | 8.40k | MagickBitStreamInitializeRead(&stream,p); |
1644 | 8.40k | if (QuantumDepth >= sample_bits) |
1645 | 7.09k | { |
1646 | | /* Scale up */ |
1647 | 1.24M | for (x = number_pixels; x != 0; --x) |
1648 | 1.23M | { |
1649 | 1.23M | SetGreenSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
1650 | 1.23M | q++; |
1651 | 1.23M | } |
1652 | 7.09k | } |
1653 | 1.30k | else |
1654 | 1.30k | { |
1655 | | /* Scale down */ |
1656 | 4.20k | for (x = number_pixels; x != 0; --x) |
1657 | 2.90k | { |
1658 | 2.90k | SetGreenSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
1659 | 2.90k | q++; |
1660 | 2.90k | } |
1661 | 1.30k | } |
1662 | 8.40k | break; |
1663 | 0 | } |
1664 | 299k | } |
1665 | 299k | } |
1666 | 9.54k | else if (sample_type == FloatQuantumSampleType) |
1667 | 9.54k | { |
1668 | 9.54k | switch (quantum_size) |
1669 | 9.54k | { |
1670 | 2.04k | case 16: |
1671 | 2.04k | { |
1672 | 10.6k | for (x = number_pixels; x != 0; --x) |
1673 | 8.59k | { |
1674 | 8.59k | ImportFloat16Quantum(endian,double_value,p); |
1675 | 8.59k | double_value -= double_minvalue; |
1676 | 8.59k | double_value *= double_scale; |
1677 | 8.59k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
1678 | 8.59k | q++; |
1679 | 8.59k | } |
1680 | 2.04k | break; |
1681 | 0 | } |
1682 | 1.16k | case 24: |
1683 | 1.16k | { |
1684 | 12.4k | for (x = number_pixels; x != 0; --x) |
1685 | 11.2k | { |
1686 | 11.2k | ImportFloat24Quantum(endian,double_value,p); |
1687 | 11.2k | double_value -= double_minvalue; |
1688 | 11.2k | double_value *= double_scale; |
1689 | 11.2k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
1690 | 11.2k | q++; |
1691 | 11.2k | } |
1692 | 1.16k | break; |
1693 | 0 | } |
1694 | 2.99k | case 32: |
1695 | 2.99k | { |
1696 | 16.2k | for (x = number_pixels; x != 0; --x) |
1697 | 13.2k | { |
1698 | 13.2k | ImportFloat32Quantum(endian,double_value,p); |
1699 | 13.2k | double_value -= double_minvalue; |
1700 | 13.2k | double_value *= double_scale; |
1701 | 13.2k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
1702 | 13.2k | q++; |
1703 | 13.2k | } |
1704 | 2.99k | break; |
1705 | 0 | } |
1706 | 3.33k | case 64: |
1707 | 3.33k | { |
1708 | 19.5k | for (x = number_pixels; x != 0; --x) |
1709 | 16.1k | { |
1710 | 16.1k | ImportFloat64Quantum(endian,double_value,p); |
1711 | 16.1k | double_value -= double_minvalue; |
1712 | 16.1k | double_value *= double_scale; |
1713 | 16.1k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
1714 | 16.1k | q++; |
1715 | 16.1k | } |
1716 | 3.33k | break; |
1717 | 0 | } |
1718 | 0 | default: |
1719 | 0 | break; |
1720 | 9.54k | } |
1721 | 9.54k | } |
1722 | | |
1723 | 309k | if (import_info) |
1724 | 25.0k | { |
1725 | 25.0k | import_info->bytes_imported=p-source; |
1726 | 25.0k | } |
1727 | | |
1728 | 309k | return MagickPass; |
1729 | 309k | } |
1730 | | |
1731 | | static MagickPassFail |
1732 | | ImportBlueQuantumType(const unsigned char *source, |
1733 | | PixelPacket* restrict q, |
1734 | | const unsigned long number_pixels, |
1735 | | const unsigned int quantum_size, |
1736 | | const QuantumSampleType sample_type, |
1737 | | const unsigned int unsigned_scale, |
1738 | | const double double_minvalue, |
1739 | | const double double_scale, |
1740 | | const EndianType endian, |
1741 | | ImportPixelAreaInfo *import_info) |
1742 | 176k | { |
1743 | 176k | const unsigned char * restrict |
1744 | 176k | p; |
1745 | | |
1746 | 176k | register unsigned long |
1747 | 176k | x; |
1748 | | |
1749 | 176k | double |
1750 | 176k | double_value; |
1751 | | |
1752 | 176k | register magick_uint32_t |
1753 | 176k | unsigned_value; |
1754 | | |
1755 | 176k | unsigned int |
1756 | 176k | sample_bits; |
1757 | | |
1758 | 176k | sample_bits=quantum_size; |
1759 | 176k | p=source; |
1760 | | |
1761 | 176k | if (sample_type == UnsignedQuantumSampleType) |
1762 | 168k | { |
1763 | 168k | switch (quantum_size) |
1764 | 168k | { |
1765 | 158k | case 8: |
1766 | 158k | { |
1767 | 53.0M | for (x = number_pixels; x != 0; --x) |
1768 | 52.8M | { |
1769 | 52.8M | SetBlueSample(q,ScaleCharToQuantum(*p++)); |
1770 | 52.8M | q++; |
1771 | 52.8M | } |
1772 | 158k | break; |
1773 | 0 | } |
1774 | 1.93k | case 16: |
1775 | 1.93k | { |
1776 | 11.0k | for (x = number_pixels; x != 0; --x) |
1777 | 9.13k | { |
1778 | 9.13k | ImportUInt16Quantum(endian,unsigned_value,p); |
1779 | 9.13k | SetBlueSample(q,ScaleShortToQuantum(unsigned_value)); |
1780 | 9.13k | q++; |
1781 | 9.13k | } |
1782 | 1.93k | break; |
1783 | 0 | } |
1784 | 1.28k | case 32: |
1785 | 1.28k | { |
1786 | 5.71k | for (x = number_pixels; x != 0; --x) |
1787 | 4.43k | { |
1788 | 4.43k | ImportUInt32Quantum(endian,unsigned_value,p); |
1789 | 4.43k | SetBlueSample(q,ScaleLongToQuantum(unsigned_value)); |
1790 | 4.43k | q++; |
1791 | 4.43k | } |
1792 | 1.28k | break; |
1793 | 0 | } |
1794 | 264 | case 64: |
1795 | 264 | { |
1796 | 898 | for (x = number_pixels; x != 0; --x) |
1797 | 634 | { |
1798 | 634 | ImportUInt64Quantum(endian,unsigned_value,p); |
1799 | 634 | SetBlueSample(q,ScaleLongToQuantum(unsigned_value)); |
1800 | 634 | q++; |
1801 | 634 | } |
1802 | 264 | break; |
1803 | 0 | } |
1804 | 6.80k | default: |
1805 | 6.80k | { |
1806 | | /* |
1807 | | Arbitrary sample size |
1808 | | */ |
1809 | 6.80k | BitStreamReadHandle |
1810 | 6.80k | stream; |
1811 | | |
1812 | 6.80k | MagickBitStreamInitializeRead(&stream,p); |
1813 | 6.80k | if (QuantumDepth >= sample_bits) |
1814 | 5.50k | { |
1815 | | /* Scale up */ |
1816 | 891k | for (x = number_pixels; x != 0; --x) |
1817 | 886k | { |
1818 | 886k | SetBlueSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
1819 | 886k | q++; |
1820 | 886k | } |
1821 | 5.50k | } |
1822 | 1.30k | else |
1823 | 1.30k | { |
1824 | | /* Scale down */ |
1825 | 4.19k | for (x = number_pixels; x != 0; --x) |
1826 | 2.89k | { |
1827 | 2.89k | SetBlueSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
1828 | 2.89k | q++; |
1829 | 2.89k | } |
1830 | 1.30k | } |
1831 | 6.80k | break; |
1832 | 0 | } |
1833 | 168k | } |
1834 | | |
1835 | 168k | } |
1836 | 7.75k | else if (sample_type == FloatQuantumSampleType) |
1837 | 7.75k | { |
1838 | 7.75k | switch (quantum_size) |
1839 | 7.75k | { |
1840 | 1.76k | case 16: |
1841 | 1.76k | { |
1842 | 9.57k | for (x = number_pixels; x != 0; --x) |
1843 | 7.81k | { |
1844 | 7.81k | ImportFloat16Quantum(endian,double_value,p); |
1845 | 7.81k | double_value -= double_minvalue; |
1846 | 7.81k | double_value *= double_scale; |
1847 | 7.81k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
1848 | 7.81k | q++; |
1849 | 7.81k | } |
1850 | 1.76k | break; |
1851 | 0 | } |
1852 | 1.01k | case 24: |
1853 | 1.01k | { |
1854 | 11.7k | for (x = number_pixels; x != 0; --x) |
1855 | 10.7k | { |
1856 | 10.7k | ImportFloat24Quantum(endian,double_value,p); |
1857 | 10.7k | double_value -= double_minvalue; |
1858 | 10.7k | double_value *= double_scale; |
1859 | 10.7k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
1860 | 10.7k | q++; |
1861 | 10.7k | } |
1862 | 1.01k | break; |
1863 | 0 | } |
1864 | 2.48k | case 32: |
1865 | 2.48k | { |
1866 | 13.7k | for (x = number_pixels; x != 0; --x) |
1867 | 11.2k | { |
1868 | 11.2k | ImportFloat32Quantum(endian,double_value,p); |
1869 | 11.2k | double_value -= double_minvalue; |
1870 | 11.2k | double_value *= double_scale; |
1871 | 11.2k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
1872 | 11.2k | q++; |
1873 | 11.2k | } |
1874 | 2.48k | break; |
1875 | 0 | } |
1876 | 2.49k | case 64: |
1877 | 2.49k | { |
1878 | 14.5k | for (x = number_pixels; x != 0; --x) |
1879 | 12.0k | { |
1880 | 12.0k | ImportFloat64Quantum(endian,double_value,p); |
1881 | 12.0k | double_value -= double_minvalue; |
1882 | 12.0k | double_value *= double_scale; |
1883 | 12.0k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
1884 | 12.0k | q++; |
1885 | 12.0k | } |
1886 | 2.49k | break; |
1887 | 0 | } |
1888 | 0 | default: |
1889 | 0 | break; |
1890 | 7.75k | } |
1891 | 7.75k | } |
1892 | | |
1893 | 176k | if (import_info) |
1894 | 20.8k | { |
1895 | 20.8k | import_info->bytes_imported=p-source; |
1896 | 20.8k | } |
1897 | | |
1898 | 176k | return MagickPass; |
1899 | 176k | } |
1900 | | |
1901 | | static MagickPassFail |
1902 | | ImportAlphaQuantumType(const unsigned char *source, |
1903 | | PixelPacket* restrict q, |
1904 | | IndexPacket * restrict indexes, |
1905 | | const unsigned long number_pixels, |
1906 | | const unsigned int quantum_size, |
1907 | | const QuantumSampleType sample_type, |
1908 | | const unsigned int unsigned_scale, |
1909 | | const double double_minvalue, |
1910 | | const double double_scale, |
1911 | | const EndianType endian, |
1912 | | Image *image, |
1913 | | ImportPixelAreaInfo *import_info) |
1914 | 13.8k | { |
1915 | 13.8k | const unsigned char * restrict |
1916 | 13.8k | p; |
1917 | | |
1918 | 13.8k | register unsigned long |
1919 | 13.8k | x; |
1920 | | |
1921 | 13.8k | double |
1922 | 13.8k | double_value; |
1923 | | |
1924 | 13.8k | register magick_uint32_t |
1925 | 13.8k | unsigned_value; |
1926 | | |
1927 | 13.8k | unsigned int |
1928 | 13.8k | sample_bits; |
1929 | | |
1930 | 13.8k | sample_bits=quantum_size; |
1931 | 13.8k | p=source; |
1932 | | |
1933 | 13.8k | if (image->colorspace == CMYKColorspace) |
1934 | 4.46k | { |
1935 | 4.46k | if (indexes == (IndexPacket *) NULL) |
1936 | 0 | ThrowBinaryException3(ImageError,CMYKAImageLacksAlphaChannel, |
1937 | 4.46k | UnableToImportImagePixels); |
1938 | | |
1939 | 4.46k | if (sample_type == UnsignedQuantumSampleType) |
1940 | 1.26k | { |
1941 | 1.26k | if ( (quantum_size >= 8) && (quantum_size % 8U == 0U) ) |
1942 | 850 | { |
1943 | | /* |
1944 | | Modulo-8 sample sizes |
1945 | | */ |
1946 | 850 | if( QuantumDepth == sample_bits) |
1947 | 212 | { |
1948 | | /* Unity scale */ |
1949 | 1.82k | for (x = number_pixels; x != 0; --x) |
1950 | 1.61k | { |
1951 | 1.61k | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
1952 | 1.61k | *indexes++=(IndexPacket) MaxRGB-unsigned_value; |
1953 | 1.61k | } |
1954 | 212 | } |
1955 | 638 | else if (QuantumDepth > sample_bits) |
1956 | 154 | { |
1957 | | /* Scale up */ |
1958 | 647 | for (x = number_pixels; x != 0; --x) |
1959 | 493 | { |
1960 | 493 | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
1961 | 493 | *indexes++=(IndexPacket) MaxRGB-unsigned_value*unsigned_scale; |
1962 | 493 | } |
1963 | 154 | } |
1964 | 484 | else |
1965 | 484 | { |
1966 | | /* Scale down */ |
1967 | 2.71k | for (x = number_pixels; x != 0; --x) |
1968 | 2.23k | { |
1969 | 2.23k | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
1970 | 2.23k | *indexes++=(IndexPacket) MaxRGB-unsigned_value/unsigned_scale; |
1971 | 2.23k | } |
1972 | 484 | } |
1973 | 850 | } |
1974 | 415 | else |
1975 | 415 | { |
1976 | | /* |
1977 | | Arbitrary sample size |
1978 | | */ |
1979 | 415 | BitStreamReadHandle |
1980 | 415 | stream; |
1981 | | |
1982 | 415 | MagickBitStreamInitializeRead(&stream,p); |
1983 | 415 | if (QuantumDepth >= sample_bits) |
1984 | 326 | { |
1985 | | /* Scale up */ |
1986 | 2.87k | for (x = number_pixels; x != 0; --x) |
1987 | 2.54k | { |
1988 | 2.54k | *indexes++=(IndexPacket) MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale; |
1989 | 2.54k | } |
1990 | 326 | } |
1991 | 89 | else |
1992 | 89 | { |
1993 | | /* Scale down */ |
1994 | 414 | for (x = number_pixels; x != 0; --x) |
1995 | 325 | { |
1996 | 325 | *indexes++=(IndexPacket) MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale; |
1997 | 325 | } |
1998 | 89 | } |
1999 | 415 | } |
2000 | 1.26k | } |
2001 | 3.20k | else if (sample_type == FloatQuantumSampleType) |
2002 | 3.20k | { |
2003 | 3.20k | switch (quantum_size) |
2004 | 3.20k | { |
2005 | 702 | case 16: |
2006 | 702 | { |
2007 | 5.70k | for (x = number_pixels; x != 0; --x) |
2008 | 5.00k | { |
2009 | 5.00k | ImportFloat16Quantum(endian,double_value,p); |
2010 | 5.00k | double_value -= double_minvalue; |
2011 | 5.00k | double_value *= double_scale; |
2012 | 5.00k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
2013 | 5.00k | } |
2014 | 702 | break; |
2015 | 0 | } |
2016 | 437 | case 24: |
2017 | 437 | { |
2018 | 3.26k | for (x = number_pixels; x != 0; --x) |
2019 | 2.82k | { |
2020 | 2.82k | ImportFloat24Quantum(endian,double_value,p); |
2021 | 2.82k | double_value -= double_minvalue; |
2022 | 2.82k | double_value *= double_scale; |
2023 | 2.82k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
2024 | 2.82k | } |
2025 | 437 | break; |
2026 | 0 | } |
2027 | 807 | case 32: |
2028 | 807 | { |
2029 | 4.70k | for (x = number_pixels; x != 0; --x) |
2030 | 3.89k | { |
2031 | 3.89k | ImportFloat32Quantum(endian,double_value,p); |
2032 | 3.89k | double_value -= double_minvalue; |
2033 | 3.89k | double_value *= double_scale; |
2034 | 3.89k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
2035 | 3.89k | } |
2036 | 807 | break; |
2037 | 0 | } |
2038 | 1.25k | case 64: |
2039 | 1.25k | { |
2040 | 5.47k | for (x = number_pixels; x != 0; --x) |
2041 | 4.21k | { |
2042 | 4.21k | ImportFloat64Quantum(endian,double_value,p); |
2043 | 4.21k | double_value -= double_minvalue; |
2044 | 4.21k | double_value *= double_scale; |
2045 | 4.21k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
2046 | 4.21k | } |
2047 | 1.25k | break; |
2048 | 0 | } |
2049 | 0 | default: |
2050 | 0 | break; |
2051 | 3.20k | } |
2052 | 3.20k | } |
2053 | 4.46k | } |
2054 | 9.37k | else |
2055 | 9.37k | { |
2056 | | /* RGB */ |
2057 | 9.37k | if (sample_type == UnsignedQuantumSampleType) |
2058 | 6.27k | { |
2059 | 6.27k | if ( (quantum_size >= 8) && (quantum_size % 8U == 0U) ) |
2060 | 2.30k | { |
2061 | | /* |
2062 | | Modulo-8 sample sizes |
2063 | | */ |
2064 | 2.30k | if(QuantumDepth == sample_bits) |
2065 | 409 | { |
2066 | | /* Unity scale */ |
2067 | 2.21k | for (x = number_pixels; x != 0; --x) |
2068 | 1.80k | { |
2069 | 1.80k | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
2070 | 1.80k | SetOpacitySample(q,MaxRGB-unsigned_value); |
2071 | 1.80k | q++; |
2072 | 1.80k | } |
2073 | 409 | } |
2074 | 1.89k | else if (QuantumDepth > sample_bits) |
2075 | 1.40k | { |
2076 | | /* Scale up */ |
2077 | 131k | for (x = number_pixels; x != 0; --x) |
2078 | 130k | { |
2079 | 130k | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
2080 | 130k | SetOpacitySample(q,MaxRGB-unsigned_value*unsigned_scale); |
2081 | 130k | q++; |
2082 | 130k | } |
2083 | 1.40k | } |
2084 | 497 | else |
2085 | 497 | { |
2086 | | /* Scale down */ |
2087 | 2.35k | for (x = number_pixels; x != 0; --x) |
2088 | 1.86k | { |
2089 | 1.86k | ImportModulo8Quantum(unsigned_value,quantum_size,p); |
2090 | 1.86k | SetOpacitySample(q,MaxRGB-unsigned_value/unsigned_scale); |
2091 | 1.86k | q++; |
2092 | 1.86k | } |
2093 | 497 | } |
2094 | 2.30k | } |
2095 | 3.96k | else |
2096 | 3.96k | { |
2097 | | /* |
2098 | | Arbitrary sample size |
2099 | | */ |
2100 | 3.96k | BitStreamReadHandle |
2101 | 3.96k | stream; |
2102 | | |
2103 | 3.96k | MagickBitStreamInitializeRead(&stream,p); |
2104 | 3.96k | if (QuantumDepth >= sample_bits) |
2105 | 2.41k | { |
2106 | | /* Scale up */ |
2107 | 58.7k | for (x = number_pixels; x != 0; --x) |
2108 | 56.3k | { |
2109 | 56.3k | SetOpacitySample(q,MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2110 | 56.3k | q++; |
2111 | 56.3k | } |
2112 | 2.41k | } |
2113 | 1.55k | else |
2114 | 1.55k | { |
2115 | | /* Scale down */ |
2116 | 13.0k | for (x = number_pixels; x != 0; --x) |
2117 | 11.4k | { |
2118 | 11.4k | SetOpacitySample(q,MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2119 | 11.4k | q++; |
2120 | 11.4k | } |
2121 | 1.55k | } |
2122 | 3.96k | } |
2123 | 6.27k | } |
2124 | 3.10k | else if (sample_type == FloatQuantumSampleType) |
2125 | 3.10k | { |
2126 | 3.10k | switch (quantum_size) |
2127 | 3.10k | { |
2128 | 653 | case 16: |
2129 | 653 | { |
2130 | 4.54k | for (x = number_pixels; x != 0; --x) |
2131 | 3.88k | { |
2132 | 3.88k | ImportFloat16Quantum(endian,double_value,p); |
2133 | 3.88k | double_value -= double_minvalue; |
2134 | 3.88k | double_value *= double_scale; |
2135 | 3.88k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2136 | 3.88k | q++; |
2137 | 3.88k | } |
2138 | 653 | break; |
2139 | 0 | } |
2140 | 356 | case 24: |
2141 | 356 | { |
2142 | 4.49k | for (x = number_pixels; x != 0; --x) |
2143 | 4.13k | { |
2144 | 4.13k | ImportFloat24Quantum(endian,double_value,p); |
2145 | 4.13k | double_value -= double_minvalue; |
2146 | 4.13k | double_value *= double_scale; |
2147 | 4.13k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2148 | 4.13k | q++; |
2149 | 4.13k | } |
2150 | 356 | break; |
2151 | 0 | } |
2152 | 1.21k | case 32: |
2153 | 1.21k | { |
2154 | 3.17k | for (x = number_pixels; x != 0; --x) |
2155 | 1.96k | { |
2156 | 1.96k | ImportFloat32Quantum(endian,double_value,p); |
2157 | 1.96k | double_value -= double_minvalue; |
2158 | 1.96k | double_value *= double_scale; |
2159 | 1.96k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2160 | 1.96k | q++; |
2161 | 1.96k | } |
2162 | 1.21k | break; |
2163 | 0 | } |
2164 | 876 | case 64: |
2165 | 876 | { |
2166 | 7.46k | for (x = number_pixels; x != 0; --x) |
2167 | 6.58k | { |
2168 | 6.58k | ImportFloat64Quantum(endian,double_value,p); |
2169 | 6.58k | double_value -= double_minvalue; |
2170 | 6.58k | double_value *= double_scale; |
2171 | 6.58k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2172 | 6.58k | q++; |
2173 | 6.58k | } |
2174 | 876 | break; |
2175 | 0 | } |
2176 | 0 | default: |
2177 | 0 | break; |
2178 | 3.10k | } |
2179 | 3.10k | } |
2180 | 9.37k | } |
2181 | | |
2182 | 13.8k | if (import_info) |
2183 | 13.8k | { |
2184 | 13.8k | import_info->bytes_imported=p-source; |
2185 | 13.8k | } |
2186 | | |
2187 | 13.8k | return MagickPass; |
2188 | 13.8k | } |
2189 | | |
2190 | | static MagickPassFail |
2191 | | ImportBlackQuantumType(const unsigned char *source, |
2192 | | PixelPacket* restrict q, |
2193 | | const unsigned long number_pixels, |
2194 | | const unsigned int quantum_size, |
2195 | | const QuantumSampleType sample_type, |
2196 | | const unsigned int unsigned_scale, |
2197 | | const double double_minvalue, |
2198 | | const double double_scale, |
2199 | | const EndianType endian, |
2200 | | ImportPixelAreaInfo *import_info) |
2201 | 55.7k | { |
2202 | 55.7k | const unsigned char * restrict |
2203 | 55.7k | p; |
2204 | | |
2205 | 55.7k | register unsigned long |
2206 | 55.7k | x; |
2207 | | |
2208 | 55.7k | double |
2209 | 55.7k | double_value; |
2210 | | |
2211 | 55.7k | register magick_uint32_t |
2212 | 55.7k | unsigned_value; |
2213 | | |
2214 | 55.7k | unsigned int |
2215 | 55.7k | sample_bits; |
2216 | | |
2217 | 55.7k | sample_bits=quantum_size; |
2218 | 55.7k | p=source; |
2219 | | |
2220 | 55.7k | if (sample_type == UnsignedQuantumSampleType) |
2221 | 50.3k | { |
2222 | 50.3k | switch (quantum_size) |
2223 | 50.3k | { |
2224 | 46.8k | case 8: |
2225 | 46.8k | { |
2226 | 16.5M | for (x = number_pixels; x != 0; --x) |
2227 | 16.4M | { |
2228 | 16.4M | SetBlackSample(q,ScaleCharToQuantum(*p++)); |
2229 | 16.4M | q++; |
2230 | 16.4M | } |
2231 | 46.8k | break; |
2232 | 0 | } |
2233 | 989 | case 16: |
2234 | 989 | { |
2235 | 4.06k | for (x = number_pixels; x != 0; --x) |
2236 | 3.07k | { |
2237 | 3.07k | ImportUInt16Quantum(endian,unsigned_value,p); |
2238 | 3.07k | SetBlackSample(q,ScaleShortToQuantum(unsigned_value)); |
2239 | 3.07k | q++; |
2240 | 3.07k | } |
2241 | 989 | break; |
2242 | 0 | } |
2243 | 751 | case 32: |
2244 | 751 | { |
2245 | 3.74k | for (x = number_pixels; x != 0; --x) |
2246 | 2.99k | { |
2247 | 2.99k | ImportUInt32Quantum(endian,unsigned_value,p); |
2248 | 2.99k | SetBlackSample(q,ScaleLongToQuantum(unsigned_value)); |
2249 | 2.99k | q++; |
2250 | 2.99k | } |
2251 | 751 | break; |
2252 | 0 | } |
2253 | 0 | case 64: |
2254 | 0 | { |
2255 | 0 | for (x = number_pixels; x != 0; --x) |
2256 | 0 | { |
2257 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2258 | 0 | SetBlackSample(q,ScaleLongToQuantum(unsigned_value)); |
2259 | 0 | q++; |
2260 | 0 | } |
2261 | 0 | break; |
2262 | 0 | } |
2263 | 1.70k | default: |
2264 | 1.70k | { |
2265 | | /* |
2266 | | Arbitrary sample size |
2267 | | */ |
2268 | 1.70k | BitStreamReadHandle |
2269 | 1.70k | stream; |
2270 | | |
2271 | 1.70k | MagickBitStreamInitializeRead(&stream,p); |
2272 | 1.70k | if (QuantumDepth >= sample_bits) |
2273 | 871 | { |
2274 | | /* Scale up */ |
2275 | 5.41k | for (x = number_pixels; x != 0; --x) |
2276 | 4.54k | { |
2277 | 4.54k | SetBlackSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2278 | 4.54k | q++; |
2279 | 4.54k | } |
2280 | 871 | } |
2281 | 832 | else |
2282 | 832 | { |
2283 | | /* Scale down */ |
2284 | 2.92k | for (x = number_pixels; x != 0; --x) |
2285 | 2.08k | { |
2286 | 2.08k | SetBlackSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2287 | 2.08k | q++; |
2288 | 2.08k | } |
2289 | 832 | } |
2290 | 1.70k | break; |
2291 | 0 | } |
2292 | 50.3k | } |
2293 | 50.3k | } |
2294 | 5.45k | else if (sample_type == FloatQuantumSampleType) |
2295 | 5.45k | { |
2296 | 5.45k | switch (quantum_size) |
2297 | 5.45k | { |
2298 | 1.58k | case 16: |
2299 | 1.58k | { |
2300 | 8.81k | for (x = number_pixels; x != 0; --x) |
2301 | 7.23k | { |
2302 | 7.23k | ImportFloat16Quantum(endian,double_value,p); |
2303 | 7.23k | double_value -= double_minvalue; |
2304 | 7.23k | double_value *= double_scale; |
2305 | 7.23k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
2306 | 7.23k | q++; |
2307 | 7.23k | } |
2308 | 1.58k | break; |
2309 | 0 | } |
2310 | 740 | case 24: |
2311 | 740 | { |
2312 | 7.57k | for (x = number_pixels; x != 0; --x) |
2313 | 6.83k | { |
2314 | 6.83k | ImportFloat24Quantum(endian,double_value,p); |
2315 | 6.83k | double_value -= double_minvalue; |
2316 | 6.83k | double_value *= double_scale; |
2317 | 6.83k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
2318 | 6.83k | q++; |
2319 | 6.83k | } |
2320 | 740 | break; |
2321 | 0 | } |
2322 | 1.61k | case 32: |
2323 | 1.61k | { |
2324 | 9.69k | for (x = number_pixels; x != 0; --x) |
2325 | 8.08k | { |
2326 | 8.08k | ImportFloat32Quantum(endian,double_value,p); |
2327 | 8.08k | double_value -= double_minvalue; |
2328 | 8.08k | double_value *= double_scale; |
2329 | 8.08k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
2330 | 8.08k | q++; |
2331 | 8.08k | } |
2332 | 1.61k | break; |
2333 | 0 | } |
2334 | 1.52k | case 64: |
2335 | 1.52k | { |
2336 | 11.1k | for (x = number_pixels; x != 0; --x) |
2337 | 9.60k | { |
2338 | 9.60k | ImportFloat64Quantum(endian,double_value,p); |
2339 | 9.60k | double_value -= double_minvalue; |
2340 | 9.60k | double_value *= double_scale; |
2341 | 9.60k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
2342 | 9.60k | q++; |
2343 | 9.60k | } |
2344 | 1.52k | break; |
2345 | 0 | } |
2346 | 0 | default: |
2347 | 0 | break; |
2348 | 5.45k | } |
2349 | 5.45k | } |
2350 | | |
2351 | 55.7k | if (import_info) |
2352 | 12.3k | { |
2353 | 12.3k | import_info->bytes_imported=p-source; |
2354 | 12.3k | } |
2355 | | |
2356 | 55.7k | return MagickPass; |
2357 | 55.7k | } |
2358 | | |
2359 | | static MagickPassFail |
2360 | | ImportRGBQuantumType(const unsigned char *source, |
2361 | | PixelPacket* restrict q, |
2362 | | const unsigned long number_pixels, |
2363 | | const unsigned int quantum_size, |
2364 | | const QuantumSampleType sample_type, |
2365 | | const unsigned int unsigned_scale, |
2366 | | const double double_minvalue, |
2367 | | const double double_scale, |
2368 | | const EndianType endian, |
2369 | | ImportPixelAreaInfo *import_info) |
2370 | 4.19M | { |
2371 | 4.19M | const unsigned char * restrict |
2372 | 4.19M | p; |
2373 | | |
2374 | 4.19M | register unsigned long |
2375 | 4.19M | x; |
2376 | | |
2377 | 4.19M | double |
2378 | 4.19M | double_value; |
2379 | | |
2380 | 4.19M | register magick_uint32_t |
2381 | 4.19M | unsigned_value; |
2382 | | |
2383 | 4.19M | unsigned int |
2384 | 4.19M | sample_bits; |
2385 | | |
2386 | 4.19M | sample_bits=quantum_size; |
2387 | 4.19M | p=source; |
2388 | | |
2389 | 4.19M | if (sample_type == UnsignedQuantumSampleType) |
2390 | 4.17M | { |
2391 | 4.17M | switch (quantum_size) |
2392 | 4.17M | { |
2393 | 3.59M | case 8: |
2394 | 3.59M | { |
2395 | 640M | for (x = number_pixels; x != 0; --x) |
2396 | 636M | { |
2397 | 636M | ImportUInt8Quantum(unsigned_value,p); |
2398 | 636M | SetRedSample(q,ScaleCharToQuantum(unsigned_value)); |
2399 | 636M | ImportUInt8Quantum(unsigned_value,p); |
2400 | 636M | SetGreenSample(q,ScaleCharToQuantum(unsigned_value)); |
2401 | 636M | ImportUInt8Quantum(unsigned_value,p); |
2402 | 636M | SetBlueSample(q,ScaleCharToQuantum(unsigned_value)); |
2403 | 636M | SetOpacitySample(q,OpaqueOpacity); |
2404 | 636M | q++; |
2405 | 636M | } |
2406 | 3.59M | break; |
2407 | 0 | } |
2408 | 144k | case 16: |
2409 | 144k | { |
2410 | 25.1M | for (x = number_pixels; x != 0; --x) |
2411 | 24.9M | { |
2412 | 24.9M | ImportUInt16Quantum(endian,unsigned_value,p); |
2413 | 24.9M | SetRedSample(q,ScaleShortToQuantum(unsigned_value)); |
2414 | 24.9M | ImportUInt16Quantum(endian,unsigned_value,p); |
2415 | 24.9M | SetGreenSample(q,ScaleShortToQuantum(unsigned_value)); |
2416 | 24.9M | ImportUInt16Quantum(endian,unsigned_value,p); |
2417 | 24.9M | SetBlueSample(q,ScaleShortToQuantum(unsigned_value)); |
2418 | 24.9M | SetOpacitySample(q,OpaqueOpacity); |
2419 | 24.9M | q++; |
2420 | 24.9M | } |
2421 | 144k | break; |
2422 | 0 | } |
2423 | 257k | case 32: |
2424 | 257k | { |
2425 | 58.7M | for (x = number_pixels; x != 0; --x) |
2426 | 58.4M | { |
2427 | 58.4M | ImportUInt32Quantum(endian,unsigned_value,p); |
2428 | 58.4M | SetRedSample(q,ScaleLongToQuantum(unsigned_value)); |
2429 | 58.4M | ImportUInt32Quantum(endian,unsigned_value,p); |
2430 | 58.4M | SetGreenSample(q,ScaleLongToQuantum(unsigned_value)); |
2431 | 58.4M | ImportUInt32Quantum(endian,unsigned_value,p); |
2432 | 58.4M | SetBlueSample(q,ScaleLongToQuantum(unsigned_value)); |
2433 | 58.4M | SetOpacitySample(q,OpaqueOpacity); |
2434 | 58.4M | q++; |
2435 | 58.4M | } |
2436 | 257k | break; |
2437 | 0 | } |
2438 | 0 | case 64: |
2439 | 0 | { |
2440 | 0 | for (x = number_pixels; x != 0; --x) |
2441 | 0 | { |
2442 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2443 | 0 | SetRedSample(q,ScaleLongToQuantum(unsigned_value)); |
2444 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2445 | 0 | SetGreenSample(q,ScaleLongToQuantum(unsigned_value)); |
2446 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2447 | 0 | SetBlueSample(q,ScaleLongToQuantum(unsigned_value)); |
2448 | 0 | SetOpacitySample(q,OpaqueOpacity); |
2449 | 0 | q++; |
2450 | 0 | } |
2451 | 0 | break; |
2452 | 0 | } |
2453 | 178k | default: |
2454 | 178k | { |
2455 | | /* |
2456 | | Arbitrary sample size |
2457 | | */ |
2458 | 178k | BitStreamReadHandle |
2459 | 178k | stream; |
2460 | | |
2461 | 178k | MagickBitStreamInitializeRead(&stream,p); |
2462 | 178k | if (QuantumDepth >= sample_bits) |
2463 | 177k | { |
2464 | | /* Scale up */ |
2465 | 40.7M | for (x = number_pixels; x != 0; --x) |
2466 | 40.5M | { |
2467 | 40.5M | SetRedSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2468 | 40.5M | SetGreenSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2469 | 40.5M | SetBlueSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2470 | 40.5M | SetOpacitySample(q,OpaqueOpacity); |
2471 | 40.5M | q++; |
2472 | 40.5M | } |
2473 | 177k | } |
2474 | 1.67k | else if (QuantumDepth < sample_bits) |
2475 | 1.67k | { |
2476 | | /* Scale down */ |
2477 | 5.90k | for (x = number_pixels; x != 0; --x) |
2478 | 4.23k | { |
2479 | 4.23k | SetRedSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2480 | 4.23k | SetGreenSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2481 | 4.23k | SetBlueSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2482 | 4.23k | SetOpacitySample(q,OpaqueOpacity); |
2483 | 4.23k | q++; |
2484 | 4.23k | } |
2485 | 1.67k | } |
2486 | 178k | break; |
2487 | 0 | } |
2488 | 4.17M | } |
2489 | 4.17M | } |
2490 | 22.2k | else if (sample_type == FloatQuantumSampleType) |
2491 | 22.2k | { |
2492 | 22.2k | switch (quantum_size) |
2493 | 22.2k | { |
2494 | 1.93k | case 16: |
2495 | 1.93k | { |
2496 | 14.8k | for (x = number_pixels; x != 0; --x) |
2497 | 12.9k | { |
2498 | 12.9k | ImportFloat16Quantum(endian,double_value,p); |
2499 | 12.9k | double_value -= double_minvalue; |
2500 | 12.9k | double_value *= double_scale; |
2501 | 12.9k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2502 | 12.9k | ImportFloat16Quantum(endian,double_value,p); |
2503 | 12.9k | double_value -= double_minvalue; |
2504 | 12.9k | double_value *= double_scale; |
2505 | 12.9k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2506 | 12.9k | ImportFloat16Quantum(endian,double_value,p); |
2507 | 12.9k | double_value -= double_minvalue; |
2508 | 12.9k | double_value *= double_scale; |
2509 | 12.9k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2510 | 12.9k | SetOpacitySample(q,OpaqueOpacity); |
2511 | 12.9k | q++; |
2512 | 12.9k | } |
2513 | 1.93k | break; |
2514 | 0 | } |
2515 | 2.34k | case 24: |
2516 | 2.34k | { |
2517 | 26.5k | for (x = number_pixels; x != 0; --x) |
2518 | 24.2k | { |
2519 | 24.2k | ImportFloat24Quantum(endian,double_value,p); |
2520 | 24.2k | double_value -= double_minvalue; |
2521 | 24.2k | double_value *= double_scale; |
2522 | 24.2k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2523 | 24.2k | ImportFloat24Quantum(endian,double_value,p); |
2524 | 24.2k | double_value -= double_minvalue; |
2525 | 24.2k | double_value *= double_scale; |
2526 | 24.2k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2527 | 24.2k | ImportFloat24Quantum(endian,double_value,p); |
2528 | 24.2k | double_value -= double_minvalue; |
2529 | 24.2k | double_value *= double_scale; |
2530 | 24.2k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2531 | 24.2k | SetOpacitySample(q,OpaqueOpacity); |
2532 | 24.2k | q++; |
2533 | 24.2k | } |
2534 | 2.34k | break; |
2535 | 0 | } |
2536 | 14.3k | case 32: |
2537 | 14.3k | { |
2538 | 1.80M | for (x = number_pixels; x != 0; --x) |
2539 | 1.78M | { |
2540 | 1.78M | ImportFloat32Quantum(endian,double_value,p); |
2541 | 1.78M | double_value -= double_minvalue; |
2542 | 1.78M | double_value *= double_scale; |
2543 | 1.78M | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2544 | 1.78M | ImportFloat32Quantum(endian,double_value,p); |
2545 | 1.78M | double_value -= double_minvalue; |
2546 | 1.78M | double_value *= double_scale; |
2547 | 1.78M | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2548 | 1.78M | ImportFloat32Quantum(endian,double_value,p); |
2549 | 1.78M | double_value -= double_minvalue; |
2550 | 1.78M | double_value *= double_scale; |
2551 | 1.78M | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2552 | 1.78M | SetOpacitySample(q,OpaqueOpacity); |
2553 | 1.78M | q++; |
2554 | 1.78M | } |
2555 | 14.3k | break; |
2556 | 0 | } |
2557 | 3.64k | case 64: |
2558 | 3.64k | { |
2559 | 57.5k | for (x = number_pixels; x != 0; --x) |
2560 | 53.9k | { |
2561 | 53.9k | ImportFloat64Quantum(endian,double_value,p); |
2562 | 53.9k | double_value -= double_minvalue; |
2563 | 53.9k | double_value *= double_scale; |
2564 | 53.9k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2565 | 53.9k | ImportFloat64Quantum(endian,double_value,p); |
2566 | 53.9k | double_value -= double_minvalue; |
2567 | 53.9k | double_value *= double_scale; |
2568 | 53.9k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2569 | 53.9k | ImportFloat64Quantum(endian,double_value,p); |
2570 | 53.9k | double_value -= double_minvalue; |
2571 | 53.9k | double_value *= double_scale; |
2572 | 53.9k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2573 | 53.9k | SetOpacitySample(q,OpaqueOpacity); |
2574 | 53.9k | q++; |
2575 | 53.9k | } |
2576 | 3.64k | break; |
2577 | 0 | } |
2578 | 0 | default: |
2579 | 0 | break; |
2580 | 22.2k | } |
2581 | 22.2k | } |
2582 | | |
2583 | 4.19M | if (import_info) |
2584 | 2.61M | { |
2585 | 2.61M | import_info->bytes_imported=p-source; |
2586 | 2.61M | } |
2587 | | |
2588 | 4.19M | return MagickPass; |
2589 | 4.19M | } |
2590 | | |
2591 | | static MagickPassFail |
2592 | | ImportRGBAQuantumType(const unsigned char *source, |
2593 | | PixelPacket* restrict q, |
2594 | | const unsigned long number_pixels, |
2595 | | const unsigned int quantum_size, |
2596 | | const QuantumSampleType sample_type, |
2597 | | const unsigned int unsigned_scale, |
2598 | | const double double_minvalue, |
2599 | | const double double_scale, |
2600 | | const EndianType endian, |
2601 | | ImportPixelAreaInfo *import_info) |
2602 | 204k | { |
2603 | 204k | const unsigned char * restrict |
2604 | 204k | p; |
2605 | | |
2606 | 204k | register unsigned long |
2607 | 204k | x; |
2608 | | |
2609 | 204k | double |
2610 | 204k | double_value; |
2611 | | |
2612 | 204k | register magick_uint32_t |
2613 | 204k | unsigned_value; |
2614 | | |
2615 | 204k | unsigned int |
2616 | 204k | sample_bits; |
2617 | | |
2618 | 204k | sample_bits=quantum_size; |
2619 | 204k | p=source; |
2620 | | |
2621 | 204k | if (sample_type == UnsignedQuantumSampleType) |
2622 | 188k | { |
2623 | 188k | switch (quantum_size) |
2624 | 188k | { |
2625 | 97.8k | case 8: |
2626 | 97.8k | { |
2627 | 12.8M | for (x = number_pixels; x != 0; --x) |
2628 | 12.7M | { |
2629 | 12.7M | SetRedSample(q,ScaleCharToQuantum(*p++)); |
2630 | 12.7M | SetGreenSample(q,ScaleCharToQuantum(*p++)); |
2631 | 12.7M | SetBlueSample(q,ScaleCharToQuantum(*p++)); |
2632 | 12.7M | SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(*p++)); |
2633 | 12.7M | q++; |
2634 | 12.7M | } |
2635 | 97.8k | break; |
2636 | 0 | } |
2637 | 21.9k | case 16: |
2638 | 21.9k | { |
2639 | 2.30M | for (x = number_pixels; x != 0; --x) |
2640 | 2.27M | { |
2641 | 2.27M | ImportUInt16Quantum(endian,unsigned_value,p); |
2642 | 2.27M | SetRedSample(q,ScaleShortToQuantum(unsigned_value)); |
2643 | 2.27M | ImportUInt16Quantum(endian,unsigned_value,p); |
2644 | 2.27M | SetGreenSample(q,ScaleShortToQuantum(unsigned_value)); |
2645 | 2.27M | ImportUInt16Quantum(endian,unsigned_value,p); |
2646 | 2.27M | SetBlueSample(q,ScaleShortToQuantum(unsigned_value)); |
2647 | 2.27M | ImportUInt16Quantum(endian,unsigned_value,p); |
2648 | 2.27M | SetOpacitySample(q,MaxRGB-ScaleShortToQuantum(unsigned_value)); |
2649 | 2.27M | q++; |
2650 | 2.27M | } |
2651 | 21.9k | break; |
2652 | 0 | } |
2653 | 10.8k | case 32: |
2654 | 10.8k | { |
2655 | 90.0k | for (x = number_pixels; x != 0; --x) |
2656 | 79.1k | { |
2657 | 79.1k | ImportUInt32Quantum(endian,unsigned_value,p); |
2658 | 79.1k | SetRedSample(q,ScaleLongToQuantum(unsigned_value)); |
2659 | 79.1k | ImportUInt32Quantum(endian,unsigned_value,p); |
2660 | 79.1k | SetGreenSample(q,ScaleLongToQuantum(unsigned_value)); |
2661 | 79.1k | ImportUInt32Quantum(endian,unsigned_value,p); |
2662 | 79.1k | SetBlueSample(q,ScaleLongToQuantum(unsigned_value)); |
2663 | 79.1k | ImportUInt32Quantum(endian,unsigned_value,p); |
2664 | 79.1k | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
2665 | 79.1k | q++; |
2666 | 79.1k | } |
2667 | 10.8k | break; |
2668 | 0 | } |
2669 | 0 | case 64: |
2670 | 0 | { |
2671 | 0 | for (x = number_pixels; x != 0; --x) |
2672 | 0 | { |
2673 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2674 | 0 | SetRedSample(q,ScaleLongToQuantum(unsigned_value)); |
2675 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2676 | 0 | SetGreenSample(q,ScaleLongToQuantum(unsigned_value)); |
2677 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2678 | 0 | SetBlueSample(q,ScaleLongToQuantum(unsigned_value)); |
2679 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2680 | 0 | SetOpacitySample(q,MaxRGB-ScaleLongToQuantum(unsigned_value)); |
2681 | 0 | q++; |
2682 | 0 | } |
2683 | 0 | break; |
2684 | 0 | } |
2685 | 57.8k | default: |
2686 | 57.8k | { |
2687 | | /* |
2688 | | Arbitrary sample size |
2689 | | */ |
2690 | 57.8k | BitStreamReadHandle |
2691 | 57.8k | stream; |
2692 | | |
2693 | 57.8k | MagickBitStreamInitializeRead(&stream,p); |
2694 | 57.8k | if (QuantumDepth >= sample_bits) |
2695 | 56.3k | { |
2696 | | /* Scale up */ |
2697 | 13.9M | for (x = number_pixels; x != 0; --x) |
2698 | 13.8M | { |
2699 | 13.8M | SetRedSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2700 | 13.8M | SetGreenSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2701 | 13.8M | SetBlueSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2702 | 13.8M | SetOpacitySample(q,MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2703 | 13.8M | q++; |
2704 | 13.8M | } |
2705 | 56.3k | } |
2706 | 1.45k | else if (QuantumDepth < sample_bits) |
2707 | 1.45k | { |
2708 | | /* Scale down */ |
2709 | 28.6k | for (x = number_pixels; x != 0; --x) |
2710 | 27.2k | { |
2711 | 27.2k | SetRedSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2712 | 27.2k | SetGreenSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2713 | 27.2k | SetBlueSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2714 | 27.2k | SetOpacitySample(q,MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2715 | 27.2k | q++; |
2716 | 27.2k | } |
2717 | 1.45k | } |
2718 | 57.8k | break; |
2719 | 0 | } |
2720 | 188k | } |
2721 | 188k | } |
2722 | 15.5k | else if (sample_type == FloatQuantumSampleType) |
2723 | 15.5k | { |
2724 | 15.5k | switch (quantum_size) |
2725 | 15.5k | { |
2726 | 2.27k | case 16: |
2727 | 2.27k | { |
2728 | 19.2k | for (x = number_pixels; x != 0; --x) |
2729 | 17.0k | { |
2730 | 17.0k | ImportFloat16Quantum(endian,double_value,p); |
2731 | 17.0k | double_value -= double_minvalue; |
2732 | 17.0k | double_value *= double_scale; |
2733 | 17.0k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2734 | 17.0k | ImportFloat16Quantum(endian,double_value,p); |
2735 | 17.0k | double_value -= double_minvalue; |
2736 | 17.0k | double_value *= double_scale; |
2737 | 17.0k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2738 | 17.0k | ImportFloat16Quantum(endian,double_value,p); |
2739 | 17.0k | double_value -= double_minvalue; |
2740 | 17.0k | double_value *= double_scale; |
2741 | 17.0k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2742 | 17.0k | ImportFloat16Quantum(endian,double_value,p); |
2743 | 17.0k | double_value -= double_minvalue; |
2744 | 17.0k | double_value *= double_scale; |
2745 | 17.0k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2746 | 17.0k | q++; |
2747 | 17.0k | } |
2748 | 2.27k | break; |
2749 | 0 | } |
2750 | 3.51k | case 24: |
2751 | 3.51k | { |
2752 | 15.5k | for (x = number_pixels; x != 0; --x) |
2753 | 12.0k | { |
2754 | 12.0k | ImportFloat24Quantum(endian,double_value,p); |
2755 | 12.0k | double_value -= double_minvalue; |
2756 | 12.0k | double_value *= double_scale; |
2757 | 12.0k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2758 | 12.0k | ImportFloat24Quantum(endian,double_value,p); |
2759 | 12.0k | double_value -= double_minvalue; |
2760 | 12.0k | double_value *= double_scale; |
2761 | 12.0k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2762 | 12.0k | ImportFloat24Quantum(endian,double_value,p); |
2763 | 12.0k | double_value -= double_minvalue; |
2764 | 12.0k | double_value *= double_scale; |
2765 | 12.0k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2766 | 12.0k | ImportFloat24Quantum(endian,double_value,p); |
2767 | 12.0k | double_value -= double_minvalue; |
2768 | 12.0k | double_value *= double_scale; |
2769 | 12.0k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2770 | 12.0k | q++; |
2771 | 12.0k | } |
2772 | 3.51k | break; |
2773 | 0 | } |
2774 | 5.03k | case 32: |
2775 | 5.03k | { |
2776 | 21.8k | for (x = number_pixels; x != 0; --x) |
2777 | 16.8k | { |
2778 | 16.8k | ImportFloat32Quantum(endian,double_value,p); |
2779 | 16.8k | double_value -= double_minvalue; |
2780 | 16.8k | double_value *= double_scale; |
2781 | 16.8k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2782 | 16.8k | ImportFloat32Quantum(endian,double_value,p); |
2783 | 16.8k | double_value -= double_minvalue; |
2784 | 16.8k | double_value *= double_scale; |
2785 | 16.8k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2786 | 16.8k | ImportFloat32Quantum(endian,double_value,p); |
2787 | 16.8k | double_value -= double_minvalue; |
2788 | 16.8k | double_value *= double_scale; |
2789 | 16.8k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2790 | 16.8k | ImportFloat32Quantum(endian,double_value,p); |
2791 | 16.8k | double_value -= double_minvalue; |
2792 | 16.8k | double_value *= double_scale; |
2793 | 16.8k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2794 | 16.8k | q++; |
2795 | 16.8k | } |
2796 | 5.03k | break; |
2797 | 0 | } |
2798 | 4.67k | case 64: |
2799 | 4.67k | { |
2800 | 16.5k | for (x = number_pixels; x != 0; --x) |
2801 | 11.8k | { |
2802 | 11.8k | ImportFloat64Quantum(endian,double_value,p); |
2803 | 11.8k | double_value -= double_minvalue; |
2804 | 11.8k | double_value *= double_scale; |
2805 | 11.8k | SetRedSample(q,RoundDoubleToQuantumN(double_value)); |
2806 | 11.8k | ImportFloat64Quantum(endian,double_value,p); |
2807 | 11.8k | double_value -= double_minvalue; |
2808 | 11.8k | double_value *= double_scale; |
2809 | 11.8k | SetGreenSample(q,RoundDoubleToQuantumN(double_value)); |
2810 | 11.8k | ImportFloat64Quantum(endian,double_value,p); |
2811 | 11.8k | double_value -= double_minvalue; |
2812 | 11.8k | double_value *= double_scale; |
2813 | 11.8k | SetBlueSample(q,RoundDoubleToQuantumN(double_value)); |
2814 | 11.8k | ImportFloat64Quantum(endian,double_value,p); |
2815 | 11.8k | double_value -= double_minvalue; |
2816 | 11.8k | double_value *= double_scale; |
2817 | 11.8k | SetOpacitySample(q,MaxRGB-RoundDoubleToQuantumN(double_value)); |
2818 | 11.8k | q++; |
2819 | 11.8k | } |
2820 | 4.67k | break; |
2821 | 0 | } |
2822 | 0 | default: |
2823 | 0 | break; |
2824 | 15.5k | } |
2825 | 15.5k | } |
2826 | | |
2827 | 204k | if (import_info) |
2828 | 93.9k | { |
2829 | 93.9k | import_info->bytes_imported=p-source; |
2830 | 93.9k | } |
2831 | | |
2832 | 204k | return MagickPass; |
2833 | 204k | } |
2834 | | |
2835 | | static MagickPassFail |
2836 | | ImportCMYKQuantumType(const unsigned char *source, |
2837 | | PixelPacket* restrict q, |
2838 | | const unsigned long number_pixels, |
2839 | | const unsigned int quantum_size, |
2840 | | const QuantumSampleType sample_type, |
2841 | | const unsigned int unsigned_scale, |
2842 | | const double double_minvalue, |
2843 | | const double double_scale, |
2844 | | const EndianType endian, |
2845 | | ImportPixelAreaInfo *import_info) |
2846 | 162k | { |
2847 | 162k | const unsigned char * restrict |
2848 | 162k | p; |
2849 | | |
2850 | 162k | register unsigned long |
2851 | 162k | x; |
2852 | | |
2853 | 162k | double |
2854 | 162k | double_value; |
2855 | | |
2856 | 162k | register magick_uint32_t |
2857 | 162k | unsigned_value; |
2858 | | |
2859 | 162k | unsigned int |
2860 | 162k | sample_bits; |
2861 | | |
2862 | 162k | sample_bits=quantum_size; |
2863 | 162k | p=source; |
2864 | | |
2865 | 162k | if (sample_type == UnsignedQuantumSampleType) |
2866 | 143k | { |
2867 | 143k | switch (quantum_size) |
2868 | 143k | { |
2869 | 20.5k | case 8: |
2870 | 20.5k | { |
2871 | 4.10M | for (x = number_pixels; x != 0; --x) |
2872 | 4.08M | { |
2873 | 4.08M | SetCyanSample(q,ScaleCharToQuantum(*p++)); |
2874 | 4.08M | SetMagentaSample(q,ScaleCharToQuantum(*p++)); |
2875 | 4.08M | SetYellowSample(q,ScaleCharToQuantum(*p++)); |
2876 | 4.08M | SetBlackSample(q,ScaleCharToQuantum(*p++)); |
2877 | 4.08M | q++; |
2878 | 4.08M | } |
2879 | 20.5k | break; |
2880 | 0 | } |
2881 | 71.8k | case 16: |
2882 | 71.8k | { |
2883 | 69.5M | for (x = number_pixels; x != 0; --x) |
2884 | 69.5M | { |
2885 | 69.5M | ImportUInt16Quantum(endian,unsigned_value,p); |
2886 | 69.5M | SetCyanSample(q,ScaleShortToQuantum(unsigned_value)); |
2887 | 69.5M | ImportUInt16Quantum(endian,unsigned_value,p); |
2888 | 69.5M | SetMagentaSample(q,ScaleShortToQuantum(unsigned_value)); |
2889 | 69.5M | ImportUInt16Quantum(endian,unsigned_value,p); |
2890 | 69.5M | SetYellowSample(q,ScaleShortToQuantum(unsigned_value)); |
2891 | 69.5M | ImportUInt16Quantum(endian,unsigned_value,p); |
2892 | 69.5M | SetBlackSample(q,unsigned_value); |
2893 | 69.5M | q++; |
2894 | 69.5M | } |
2895 | 71.8k | break; |
2896 | 0 | } |
2897 | 4.74k | case 32: |
2898 | 4.74k | { |
2899 | 343k | for (x = number_pixels; x != 0; --x) |
2900 | 338k | { |
2901 | 338k | ImportUInt32Quantum(endian,unsigned_value,p); |
2902 | 338k | SetCyanSample(q,ScaleLongToQuantum(unsigned_value)); |
2903 | 338k | ImportUInt32Quantum(endian,unsigned_value,p); |
2904 | 338k | SetMagentaSample(q,ScaleLongToQuantum(unsigned_value)); |
2905 | 338k | ImportUInt32Quantum(endian,unsigned_value,p); |
2906 | 338k | SetYellowSample(q,ScaleLongToQuantum(unsigned_value)); |
2907 | 338k | ImportUInt32Quantum(endian,unsigned_value,p); |
2908 | 338k | SetBlackSample(q,unsigned_value); |
2909 | 338k | q++; |
2910 | 338k | } |
2911 | 4.74k | break; |
2912 | 0 | } |
2913 | 0 | case 64: |
2914 | 0 | { |
2915 | 0 | for (x = number_pixels; x != 0; --x) |
2916 | 0 | { |
2917 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2918 | 0 | SetCyanSample(q,ScaleLongToQuantum(unsigned_value)); |
2919 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2920 | 0 | SetMagentaSample(q,ScaleLongToQuantum(unsigned_value)); |
2921 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2922 | 0 | SetYellowSample(q,ScaleLongToQuantum(unsigned_value)); |
2923 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
2924 | 0 | SetBlackSample(q,unsigned_value); |
2925 | 0 | q++; |
2926 | 0 | } |
2927 | 0 | break; |
2928 | 0 | } |
2929 | 46.7k | default: |
2930 | 46.7k | { |
2931 | | /* |
2932 | | Arbitrary sample size |
2933 | | */ |
2934 | 46.7k | BitStreamReadHandle |
2935 | 46.7k | stream; |
2936 | | |
2937 | 46.7k | MagickBitStreamInitializeRead(&stream,p); |
2938 | 46.7k | if (QuantumDepth >= sample_bits) |
2939 | 44.1k | { |
2940 | | /* Scale up */ |
2941 | 25.9M | for (x = number_pixels; x != 0; --x) |
2942 | 25.9M | { |
2943 | 25.9M | SetCyanSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2944 | 25.9M | SetMagentaSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2945 | 25.9M | SetYellowSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2946 | 25.9M | SetBlackSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
2947 | 25.9M | q++; |
2948 | 25.9M | } |
2949 | 44.1k | } |
2950 | 2.64k | else if (QuantumDepth < sample_bits) |
2951 | 2.64k | { |
2952 | | /* Scale down */ |
2953 | 1.58M | for (x = number_pixels; x != 0; --x) |
2954 | 1.58M | { |
2955 | 1.58M | SetCyanSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2956 | 1.58M | SetMagentaSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2957 | 1.58M | SetYellowSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2958 | 1.58M | SetBlackSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
2959 | 1.58M | q++; |
2960 | 1.58M | } |
2961 | 2.64k | } |
2962 | 46.7k | break; |
2963 | 0 | } |
2964 | 143k | } |
2965 | 143k | } |
2966 | 18.9k | else if (sample_type == FloatQuantumSampleType) |
2967 | 18.9k | { |
2968 | 18.9k | switch (quantum_size) |
2969 | 18.9k | { |
2970 | 6.88k | case 16: |
2971 | 6.88k | { |
2972 | 3.97M | for (x = number_pixels; x != 0; --x) |
2973 | 3.96M | { |
2974 | 3.96M | ImportFloat16Quantum(endian,double_value,p); |
2975 | 3.96M | double_value -= double_minvalue; |
2976 | 3.96M | double_value *= double_scale; |
2977 | 3.96M | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
2978 | 3.96M | ImportFloat16Quantum(endian,double_value,p); |
2979 | 3.96M | double_value -= double_minvalue; |
2980 | 3.96M | double_value *= double_scale; |
2981 | 3.96M | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
2982 | 3.96M | ImportFloat16Quantum(endian,double_value,p); |
2983 | 3.96M | double_value -= double_minvalue; |
2984 | 3.96M | double_value *= double_scale; |
2985 | 3.96M | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
2986 | 3.96M | ImportFloat16Quantum(endian,double_value,p); |
2987 | 3.96M | double_value -= double_minvalue; |
2988 | 3.96M | double_value *= double_scale; |
2989 | 3.96M | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
2990 | 3.96M | q++; |
2991 | 3.96M | } |
2992 | 6.88k | break; |
2993 | 0 | } |
2994 | 2.81k | case 24: |
2995 | 2.81k | { |
2996 | 171k | for (x = number_pixels; x != 0; --x) |
2997 | 168k | { |
2998 | 168k | ImportFloat24Quantum(endian,double_value,p); |
2999 | 168k | double_value -= double_minvalue; |
3000 | 168k | double_value *= double_scale; |
3001 | 168k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3002 | 168k | ImportFloat24Quantum(endian,double_value,p); |
3003 | 168k | double_value -= double_minvalue; |
3004 | 168k | double_value *= double_scale; |
3005 | 168k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3006 | 168k | ImportFloat24Quantum(endian,double_value,p); |
3007 | 168k | double_value -= double_minvalue; |
3008 | 168k | double_value *= double_scale; |
3009 | 168k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3010 | 168k | ImportFloat24Quantum(endian,double_value,p); |
3011 | 168k | double_value -= double_minvalue; |
3012 | 168k | double_value *= double_scale; |
3013 | 168k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3014 | 168k | q++; |
3015 | 168k | } |
3016 | 2.81k | break; |
3017 | 0 | } |
3018 | 4.48k | case 32: |
3019 | 4.48k | { |
3020 | 32.5k | for (x = number_pixels; x != 0; --x) |
3021 | 28.0k | { |
3022 | 28.0k | ImportFloat32Quantum(endian,double_value,p); |
3023 | 28.0k | double_value -= double_minvalue; |
3024 | 28.0k | double_value *= double_scale; |
3025 | 28.0k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3026 | 28.0k | ImportFloat32Quantum(endian,double_value,p); |
3027 | 28.0k | double_value -= double_minvalue; |
3028 | 28.0k | double_value *= double_scale; |
3029 | 28.0k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3030 | 28.0k | ImportFloat32Quantum(endian,double_value,p); |
3031 | 28.0k | double_value -= double_minvalue; |
3032 | 28.0k | double_value *= double_scale; |
3033 | 28.0k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3034 | 28.0k | ImportFloat32Quantum(endian,double_value,p); |
3035 | 28.0k | double_value -= double_minvalue; |
3036 | 28.0k | double_value *= double_scale; |
3037 | 28.0k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3038 | 28.0k | q++; |
3039 | 28.0k | } |
3040 | 4.48k | break; |
3041 | 0 | } |
3042 | 4.74k | case 64: |
3043 | 4.74k | { |
3044 | 88.5k | for (x = number_pixels; x != 0; --x) |
3045 | 83.8k | { |
3046 | 83.8k | ImportFloat64Quantum(endian,double_value,p); |
3047 | 83.8k | double_value -= double_minvalue; |
3048 | 83.8k | double_value *= double_scale; |
3049 | 83.8k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3050 | 83.8k | ImportFloat64Quantum(endian,double_value,p); |
3051 | 83.8k | double_value -= double_minvalue; |
3052 | 83.8k | double_value *= double_scale; |
3053 | 83.8k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3054 | 83.8k | ImportFloat64Quantum(endian,double_value,p); |
3055 | 83.8k | double_value -= double_minvalue; |
3056 | 83.8k | double_value *= double_scale; |
3057 | 83.8k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3058 | 83.8k | ImportFloat64Quantum(endian,double_value,p); |
3059 | 83.8k | double_value -= double_minvalue; |
3060 | 83.8k | double_value *= double_scale; |
3061 | 83.8k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3062 | 83.8k | q++; |
3063 | 83.8k | } |
3064 | 4.74k | break; |
3065 | 0 | } |
3066 | 0 | default: |
3067 | 0 | break; |
3068 | 18.9k | } |
3069 | 18.9k | } |
3070 | | |
3071 | 162k | if (import_info) |
3072 | 72.0k | { |
3073 | 72.0k | import_info->bytes_imported=p-source; |
3074 | 72.0k | } |
3075 | | |
3076 | 162k | return MagickPass; |
3077 | 162k | } |
3078 | | |
3079 | | static MagickPassFail |
3080 | | ImportCMYKAQuantumType(const unsigned char *source, |
3081 | | PixelPacket* restrict q, |
3082 | | IndexPacket * restrict indexes, |
3083 | | const unsigned long number_pixels, |
3084 | | const unsigned int quantum_size, |
3085 | | const QuantumSampleType sample_type, |
3086 | | const unsigned int unsigned_scale, |
3087 | | const double double_minvalue, |
3088 | | const double double_scale, |
3089 | | const EndianType endian, |
3090 | | Image *image, |
3091 | | ImportPixelAreaInfo *import_info) |
3092 | 37.4k | { |
3093 | 37.4k | const unsigned char * restrict |
3094 | 37.4k | p; |
3095 | | |
3096 | 37.4k | register unsigned long |
3097 | 37.4k | x; |
3098 | | |
3099 | 37.4k | double |
3100 | 37.4k | double_value; |
3101 | | |
3102 | 37.4k | register magick_uint32_t |
3103 | 37.4k | unsigned_value; |
3104 | | |
3105 | 37.4k | unsigned int |
3106 | 37.4k | sample_bits; |
3107 | | |
3108 | 37.4k | sample_bits=quantum_size; |
3109 | 37.4k | p=source; |
3110 | | |
3111 | 37.4k | if (indexes == (IndexPacket *) NULL) |
3112 | 0 | ThrowBinaryException3(ImageError,CMYKAImageLacksAlphaChannel, |
3113 | 37.4k | UnableToImportImagePixels); |
3114 | | |
3115 | 37.4k | if (sample_type == UnsignedQuantumSampleType) |
3116 | 20.5k | { |
3117 | 20.5k | switch (quantum_size) |
3118 | 20.5k | { |
3119 | 4.00k | case 8: |
3120 | 4.00k | { |
3121 | 675k | for (x = number_pixels; x != 0; --x) |
3122 | 671k | { |
3123 | 671k | SetCyanSample(q,ScaleCharToQuantum(*p++)); |
3124 | 671k | SetMagentaSample(q,ScaleCharToQuantum(*p++)); |
3125 | 671k | SetYellowSample(q,ScaleCharToQuantum(*p++)); |
3126 | 671k | SetBlackSample(q,ScaleCharToQuantum(*p++)); |
3127 | 671k | *indexes++=(IndexPacket) MaxRGB-ScaleCharToQuantum(*p++); |
3128 | 671k | q++; |
3129 | 671k | } |
3130 | 4.00k | break; |
3131 | 0 | } |
3132 | 3.19k | case 16: |
3133 | 3.19k | { |
3134 | 79.0k | for (x = number_pixels; x != 0; --x) |
3135 | 75.8k | { |
3136 | 75.8k | ImportUInt16Quantum(endian,unsigned_value,p); |
3137 | 75.8k | SetCyanSample(q,ScaleShortToQuantum(unsigned_value)); |
3138 | 75.8k | ImportUInt16Quantum(endian,unsigned_value,p); |
3139 | 75.8k | SetMagentaSample(q,ScaleShortToQuantum(unsigned_value)); |
3140 | 75.8k | ImportUInt16Quantum(endian,unsigned_value,p); |
3141 | 75.8k | SetYellowSample(q,ScaleShortToQuantum(unsigned_value)); |
3142 | 75.8k | ImportUInt16Quantum(endian,unsigned_value,p); |
3143 | 75.8k | SetBlackSample(q,ScaleShortToQuantum(unsigned_value)); |
3144 | 75.8k | ImportUInt16Quantum(endian,unsigned_value,p); |
3145 | 75.8k | *indexes++=(IndexPacket) MaxRGB-ScaleShortToQuantum(unsigned_value); |
3146 | 75.8k | q++; |
3147 | 75.8k | } |
3148 | 3.19k | break; |
3149 | 0 | } |
3150 | 2.49k | case 32: |
3151 | 2.49k | { |
3152 | 20.8k | for (x = number_pixels; x != 0; --x) |
3153 | 18.3k | { |
3154 | 18.3k | ImportUInt32Quantum(endian,unsigned_value,p); |
3155 | 18.3k | SetCyanSample(q,ScaleLongToQuantum(unsigned_value)); |
3156 | 18.3k | ImportUInt32Quantum(endian,unsigned_value,p); |
3157 | 18.3k | SetMagentaSample(q,ScaleLongToQuantum(unsigned_value)); |
3158 | 18.3k | ImportUInt32Quantum(endian,unsigned_value,p); |
3159 | 18.3k | SetYellowSample(q,ScaleLongToQuantum(unsigned_value)); |
3160 | 18.3k | ImportUInt32Quantum(endian,unsigned_value,p); |
3161 | 18.3k | SetBlackSample(q,ScaleLongToQuantum(unsigned_value)); |
3162 | 18.3k | ImportUInt32Quantum(endian,unsigned_value,p); |
3163 | 18.3k | *indexes++=(IndexPacket) MaxRGB-ScaleLongToQuantum(unsigned_value); |
3164 | 18.3k | q++; |
3165 | 18.3k | } |
3166 | 2.49k | break; |
3167 | 0 | } |
3168 | 0 | case 64: |
3169 | 0 | { |
3170 | 0 | for (x = number_pixels; x != 0; --x) |
3171 | 0 | { |
3172 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
3173 | 0 | SetCyanSample(q,ScaleLongToQuantum(unsigned_value)); |
3174 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
3175 | 0 | SetMagentaSample(q,ScaleLongToQuantum(unsigned_value)); |
3176 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
3177 | 0 | SetYellowSample(q,ScaleLongToQuantum(unsigned_value)); |
3178 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
3179 | 0 | SetBlackSample(q,ScaleLongToQuantum(unsigned_value)); |
3180 | 0 | ImportUInt64Quantum(endian,unsigned_value,p); |
3181 | 0 | *indexes++=(IndexPacket) MaxRGB-ScaleLongToQuantum(unsigned_value); |
3182 | 0 | q++; |
3183 | 0 | } |
3184 | 0 | break; |
3185 | 0 | } |
3186 | 10.8k | default: |
3187 | 10.8k | { |
3188 | | /* |
3189 | | Arbitrary sample size |
3190 | | */ |
3191 | 10.8k | BitStreamReadHandle |
3192 | 10.8k | stream; |
3193 | | |
3194 | 10.8k | MagickBitStreamInitializeRead(&stream,p); |
3195 | 10.8k | if (QuantumDepth >= sample_bits) |
3196 | 9.98k | { |
3197 | | /* Scale up */ |
3198 | 1.01M | for (x = number_pixels; x != 0; --x) |
3199 | 1.00M | { |
3200 | 1.00M | SetCyanSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
3201 | 1.00M | SetMagentaSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
3202 | 1.00M | SetYellowSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
3203 | 1.00M | SetBlackSample(q,MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale); |
3204 | 1.00M | *indexes++=(IndexPacket) MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)*unsigned_scale; |
3205 | 1.00M | q++; |
3206 | 1.00M | } |
3207 | 9.98k | } |
3208 | 879 | else if (QuantumDepth < sample_bits) |
3209 | 879 | { |
3210 | | /* Scale down */ |
3211 | 4.83k | for (x = number_pixels; x != 0; --x) |
3212 | 3.95k | { |
3213 | 3.95k | SetCyanSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
3214 | 3.95k | SetMagentaSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
3215 | 3.95k | SetYellowSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
3216 | 3.95k | SetBlackSample(q,MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale); |
3217 | 3.95k | *indexes++=(IndexPacket) MaxRGB-MagickBitStreamMSBRead(&stream,quantum_size)/unsigned_scale; |
3218 | 3.95k | q++; |
3219 | 3.95k | } |
3220 | 879 | } |
3221 | 10.8k | break; |
3222 | 0 | } |
3223 | 20.5k | } |
3224 | 20.5k | } |
3225 | 16.8k | else if (sample_type == FloatQuantumSampleType) |
3226 | 16.8k | { |
3227 | 16.8k | switch (quantum_size) |
3228 | 16.8k | { |
3229 | 1.94k | case 16: |
3230 | 1.94k | { |
3231 | 22.9k | for (x = number_pixels; x != 0; --x) |
3232 | 21.0k | { |
3233 | 21.0k | ImportFloat16Quantum(endian,double_value,p); |
3234 | 21.0k | double_value -= double_minvalue; |
3235 | 21.0k | double_value *= double_scale; |
3236 | 21.0k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3237 | 21.0k | ImportFloat16Quantum(endian,double_value,p); |
3238 | 21.0k | double_value -= double_minvalue; |
3239 | 21.0k | double_value *= double_scale; |
3240 | 21.0k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3241 | 21.0k | ImportFloat16Quantum(endian,double_value,p); |
3242 | 21.0k | double_value -= double_minvalue; |
3243 | 21.0k | double_value *= double_scale; |
3244 | 21.0k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3245 | 21.0k | ImportFloat16Quantum(endian,double_value,p); |
3246 | 21.0k | double_value -= double_minvalue; |
3247 | 21.0k | double_value *= double_scale; |
3248 | 21.0k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3249 | 21.0k | ImportFloat16Quantum(endian,double_value,p); |
3250 | 21.0k | double_value -= double_minvalue; |
3251 | 21.0k | double_value *= double_scale; |
3252 | 21.0k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
3253 | 21.0k | q++; |
3254 | 21.0k | } |
3255 | 1.94k | break; |
3256 | 0 | } |
3257 | 3.09k | case 24: |
3258 | 3.09k | { |
3259 | 15.7k | for (x = number_pixels; x != 0; --x) |
3260 | 12.6k | { |
3261 | 12.6k | ImportFloat24Quantum(endian,double_value,p); |
3262 | 12.6k | double_value -= double_minvalue; |
3263 | 12.6k | double_value *= double_scale; |
3264 | 12.6k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3265 | 12.6k | ImportFloat24Quantum(endian,double_value,p); |
3266 | 12.6k | double_value -= double_minvalue; |
3267 | 12.6k | double_value *= double_scale; |
3268 | 12.6k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3269 | 12.6k | ImportFloat24Quantum(endian,double_value,p); |
3270 | 12.6k | double_value -= double_minvalue; |
3271 | 12.6k | double_value *= double_scale; |
3272 | 12.6k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3273 | 12.6k | ImportFloat24Quantum(endian,double_value,p); |
3274 | 12.6k | double_value -= double_minvalue; |
3275 | 12.6k | double_value *= double_scale; |
3276 | 12.6k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3277 | 12.6k | ImportFloat24Quantum(endian,double_value,p); |
3278 | 12.6k | double_value -= double_minvalue; |
3279 | 12.6k | double_value *= double_scale; |
3280 | 12.6k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
3281 | 12.6k | q++; |
3282 | 12.6k | } |
3283 | 3.09k | break; |
3284 | 0 | } |
3285 | 5.61k | case 32: |
3286 | 5.61k | { |
3287 | 28.5k | for (x = number_pixels; x != 0; --x) |
3288 | 22.9k | { |
3289 | 22.9k | ImportFloat32Quantum(endian,double_value,p); |
3290 | 22.9k | double_value -= double_minvalue; |
3291 | 22.9k | double_value *= double_scale; |
3292 | 22.9k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3293 | 22.9k | ImportFloat32Quantum(endian,double_value,p); |
3294 | 22.9k | double_value -= double_minvalue; |
3295 | 22.9k | double_value *= double_scale; |
3296 | 22.9k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3297 | 22.9k | ImportFloat32Quantum(endian,double_value,p); |
3298 | 22.9k | double_value -= double_minvalue; |
3299 | 22.9k | double_value *= double_scale; |
3300 | 22.9k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3301 | 22.9k | ImportFloat32Quantum(endian,double_value,p); |
3302 | 22.9k | double_value -= double_minvalue; |
3303 | 22.9k | double_value *= double_scale; |
3304 | 22.9k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3305 | 22.9k | ImportFloat32Quantum(endian,double_value,p); |
3306 | 22.9k | double_value -= double_minvalue; |
3307 | 22.9k | double_value *= double_scale; |
3308 | 22.9k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
3309 | 22.9k | q++; |
3310 | 22.9k | } |
3311 | 5.61k | break; |
3312 | 0 | } |
3313 | 6.22k | case 64: |
3314 | 6.22k | { |
3315 | 23.9k | for (x = number_pixels; x != 0; --x) |
3316 | 17.7k | { |
3317 | 17.7k | ImportFloat64Quantum(endian,double_value,p); |
3318 | 17.7k | double_value -= double_minvalue; |
3319 | 17.7k | double_value *= double_scale; |
3320 | 17.7k | SetCyanSample(q,RoundDoubleToQuantumN(double_value)); |
3321 | 17.7k | ImportFloat64Quantum(endian,double_value,p); |
3322 | 17.7k | double_value -= double_minvalue; |
3323 | 17.7k | double_value *= double_scale; |
3324 | 17.7k | SetMagentaSample(q,RoundDoubleToQuantumN(double_value)); |
3325 | 17.7k | ImportFloat64Quantum(endian,double_value,p); |
3326 | 17.7k | double_value -= double_minvalue; |
3327 | 17.7k | double_value *= double_scale; |
3328 | 17.7k | SetYellowSample(q,RoundDoubleToQuantumN(double_value)); |
3329 | 17.7k | ImportFloat64Quantum(endian,double_value,p); |
3330 | 17.7k | double_value -= double_minvalue; |
3331 | 17.7k | double_value *= double_scale; |
3332 | 17.7k | SetBlackSample(q,RoundDoubleToQuantumN(double_value)); |
3333 | 17.7k | ImportFloat64Quantum(endian,double_value,p); |
3334 | 17.7k | double_value -= double_minvalue; |
3335 | 17.7k | double_value *= double_scale; |
3336 | 17.7k | *indexes++=(IndexPacket) MaxRGB-RoundDoubleToQuantumN(double_value); |
3337 | 17.7k | q++; |
3338 | 17.7k | } |
3339 | 6.22k | break; |
3340 | 0 | } |
3341 | 0 | default: |
3342 | 0 | break; |
3343 | 16.8k | } |
3344 | 16.8k | } |
3345 | | |
3346 | 37.4k | if (import_info) |
3347 | 31.3k | { |
3348 | 31.3k | import_info->bytes_imported=p-source; |
3349 | 31.3k | } |
3350 | | |
3351 | 37.4k | return MagickPass; |
3352 | 37.4k | } |
3353 | | |
3354 | | static MagickPassFail |
3355 | | ImportCIEXYZQuantumType(const unsigned char *source, |
3356 | | PixelPacket* restrict q, |
3357 | | const unsigned long number_pixels, |
3358 | | const unsigned int quantum_size, |
3359 | | const QuantumSampleType sample_type, |
3360 | | const EndianType endian, |
3361 | | ImportPixelAreaInfo *import_info) |
3362 | 7.07k | { |
3363 | 7.07k | const unsigned char * restrict |
3364 | 7.07k | p; |
3365 | | |
3366 | 7.07k | register unsigned long |
3367 | 7.07k | x; |
3368 | | |
3369 | 7.07k | p=source; |
3370 | | |
3371 | 7.07k | if (sample_type == FloatQuantumSampleType) |
3372 | 7.07k | { |
3373 | 7.07k | double |
3374 | 7.07k | red, |
3375 | 7.07k | green, |
3376 | 7.07k | blue, |
3377 | 7.07k | x_sample, |
3378 | 7.07k | y_sample, |
3379 | 7.07k | z_sample; |
3380 | | |
3381 | 105k | for (x = number_pixels; x != 0; --x) |
3382 | 98.8k | { |
3383 | 98.8k | switch (quantum_size) |
3384 | 98.8k | { |
3385 | 0 | default: |
3386 | 98.8k | case 32: |
3387 | 98.8k | { |
3388 | 98.8k | ImportFloat32Quantum(endian,x_sample,p); |
3389 | 98.8k | ImportFloat32Quantum(endian,y_sample,p); |
3390 | 98.8k | ImportFloat32Quantum(endian,z_sample,p); |
3391 | 98.8k | break; |
3392 | 0 | } |
3393 | 0 | case 64: |
3394 | 0 | { |
3395 | 0 | ImportFloat64Quantum(endian,x_sample,p); |
3396 | 0 | ImportFloat64Quantum(endian,y_sample,p); |
3397 | 0 | ImportFloat64Quantum(endian,z_sample,p); |
3398 | 0 | break; |
3399 | 0 | } |
3400 | 98.8k | } |
3401 | | |
3402 | | /* Assume CCIR-709 primaries */ |
3403 | 98.8k | red = 2.690*x_sample + -1.276*y_sample + -0.414*z_sample; |
3404 | 98.8k | green = -1.022*x_sample + 1.978*y_sample + 0.044*z_sample; |
3405 | 98.8k | blue = 0.061*x_sample + -0.224*y_sample + 1.163*z_sample; |
3406 | | |
3407 | | /* assume 2.0 gamma for speed */ |
3408 | 98.8k | SetRedSample(q,(Quantum) ((red <= 0.0) ? 0.0 : (red >= 1.0) ? MaxRGB : |
3409 | 98.8k | ((MaxRGB * sqrt(red))+0.5))); |
3410 | 98.8k | SetGreenSample(q,(Quantum) ((green <= 0.0) ? 0.0 : (green >= 1.0) ? MaxRGB : |
3411 | 98.8k | ((MaxRGB * sqrt(green))+0.5))); |
3412 | 98.8k | SetBlueSample(q,(Quantum) ((blue <= 0.0) ? 0.0 : (blue >= 1.0) ? MaxRGB : |
3413 | 98.8k | ((MaxRGB * sqrt(blue))+0.5))); |
3414 | 98.8k | SetOpacitySample(q,OpaqueOpacity); |
3415 | 98.8k | q++; |
3416 | 98.8k | } |
3417 | 7.07k | } |
3418 | | |
3419 | 7.07k | if (import_info) |
3420 | 2.63k | { |
3421 | 2.63k | import_info->bytes_imported=p-source; |
3422 | 2.63k | } |
3423 | | |
3424 | 7.07k | return MagickPass; |
3425 | 7.07k | } |
3426 | | |
3427 | | static MagickPassFail |
3428 | | ImportCIEYQuantumType(const unsigned char *source, |
3429 | | PixelPacket* restrict q, |
3430 | | const unsigned long number_pixels, |
3431 | | const unsigned int quantum_size, |
3432 | | const QuantumSampleType sample_type, |
3433 | | const EndianType endian, |
3434 | | ImportPixelAreaInfo *import_info) |
3435 | 23.6k | { |
3436 | 23.6k | const unsigned char * restrict |
3437 | 23.6k | p; |
3438 | | |
3439 | 23.6k | register unsigned long |
3440 | 23.6k | x; |
3441 | | |
3442 | 23.6k | double |
3443 | 23.6k | double_value; |
3444 | | |
3445 | 23.6k | p=source; |
3446 | | |
3447 | 23.6k | if (sample_type == FloatQuantumSampleType) |
3448 | 23.6k | { |
3449 | 481k | for (x = number_pixels; x != 0; --x) |
3450 | 457k | { |
3451 | 457k | switch (quantum_size) |
3452 | 457k | { |
3453 | 0 | default: |
3454 | 457k | case 32: |
3455 | 457k | { |
3456 | 457k | ImportFloat32Quantum(endian,double_value,p); |
3457 | 457k | break; |
3458 | 0 | } |
3459 | 0 | case 64: |
3460 | 0 | { |
3461 | 0 | ImportFloat64Quantum(endian,double_value,p); |
3462 | 0 | break; |
3463 | 0 | } |
3464 | 457k | } |
3465 | | /* assume 2.0 gamma for speed */ |
3466 | 457k | SetGraySample(q,(Quantum) ((double_value <= 0.0) ? 0.0 : |
3467 | 457k | (double_value >= 1.0) ? MaxRGB : |
3468 | 457k | ((MaxRGB * sqrt(double_value))+0.5))); |
3469 | 457k | q++; |
3470 | 457k | } |
3471 | 23.6k | } |
3472 | | |
3473 | 23.6k | if (import_info) |
3474 | 17.3k | { |
3475 | 17.3k | import_info->bytes_imported=p-source; |
3476 | 17.3k | } |
3477 | | |
3478 | 23.6k | return MagickPass; |
3479 | 23.6k | } |
3480 | | |
3481 | | MagickExport MagickPassFail |
3482 | | ImportViewPixelArea(ViewInfo *view, |
3483 | | const QuantumType quantum_type, |
3484 | | const unsigned int quantum_size, |
3485 | | const unsigned char *source, |
3486 | | const ImportPixelAreaOptions *options, |
3487 | | ImportPixelAreaInfo *import_info) |
3488 | 22.2M | { |
3489 | 22.2M | Image |
3490 | 22.2M | *image; |
3491 | | |
3492 | 22.2M | unsigned int |
3493 | 22.2M | unsigned_scale = 1U; |
3494 | | |
3495 | 22.2M | IndexPacket |
3496 | 22.2M | * restrict indexes; |
3497 | | |
3498 | 22.2M | PixelPacket |
3499 | 22.2M | * restrict q; |
3500 | | |
3501 | 22.2M | MagickBool |
3502 | 22.2M | grayscale_miniswhite = MagickFalse; |
3503 | | |
3504 | 22.2M | QuantumSampleType |
3505 | 22.2M | sample_type = UnsignedQuantumSampleType; |
3506 | | |
3507 | 22.2M | unsigned int |
3508 | 22.2M | unsigned_maxvalue=MaxRGB, |
3509 | 22.2M | sample_bits; |
3510 | | |
3511 | 22.2M | unsigned long |
3512 | 22.2M | number_pixels; |
3513 | | |
3514 | 22.2M | double |
3515 | 22.2M | double_maxvalue=1.0, |
3516 | 22.2M | double_minvalue=0.0, |
3517 | 22.2M | double_scale; |
3518 | | |
3519 | 22.2M | EndianType |
3520 | 22.2M | endian=MSBEndian; |
3521 | | |
3522 | 22.2M | MagickPassFail |
3523 | 22.2M | status=MagickPass; |
3524 | | |
3525 | 22.2M | assert(view != (ViewInfo *) NULL); |
3526 | 22.2M | assert(source != (const unsigned char *) NULL); |
3527 | 22.2M | assert((options == (const ImportPixelAreaOptions *) NULL) || |
3528 | 22.2M | (options->signature == MagickSignature)); |
3529 | | |
3530 | | /* |
3531 | | Transfer any special options. |
3532 | | */ |
3533 | 22.2M | sample_bits=quantum_size; |
3534 | 22.2M | if (options) |
3535 | 19.9M | { |
3536 | 19.9M | sample_type=options->sample_type; |
3537 | 19.9M | double_minvalue=options->double_minvalue; |
3538 | 19.9M | double_maxvalue=options->double_maxvalue; |
3539 | 19.9M | grayscale_miniswhite=options->grayscale_miniswhite; |
3540 | | |
3541 | 19.9M | switch (options->endian) |
3542 | 19.9M | { |
3543 | 18.3M | case MSBEndian: |
3544 | 18.3M | case UndefinedEndian: |
3545 | 18.3M | { |
3546 | 18.3M | endian=MSBEndian; |
3547 | 18.3M | break; |
3548 | 18.3M | } |
3549 | 51.9k | case LSBEndian: |
3550 | 51.9k | { |
3551 | 51.9k | endian=LSBEndian; |
3552 | 51.9k | break; |
3553 | 18.3M | } |
3554 | 1.53M | case NativeEndian: |
3555 | 1.53M | { |
3556 | | #if defined(WORDS_BIGENDIAN) |
3557 | | endian=MSBEndian; |
3558 | | #else |
3559 | 1.53M | endian=LSBEndian; |
3560 | 1.53M | #endif |
3561 | 1.53M | break; |
3562 | 18.3M | } |
3563 | 19.9M | } |
3564 | 19.9M | } |
3565 | | |
3566 | 22.2M | if (import_info) |
3567 | 9.83M | { |
3568 | 9.83M | import_info->bytes_imported=0; |
3569 | 9.83M | } |
3570 | | |
3571 | 22.2M | if (!(((sample_type == FloatQuantumSampleType) && |
3572 | 292k | ((quantum_size == 16) || (quantum_size == 24) || |
3573 | 235k | (quantum_size == 32) || (quantum_size == 64))) || |
3574 | 21.9M | ((sample_type == UnsignedQuantumSampleType) && |
3575 | 21.9M | (((quantum_size > 0) && (quantum_size <= 32)) || |
3576 | 12.8k | (quantum_size == 64))))) |
3577 | 7.07k | { |
3578 | 7.07k | char quantum_size_str[MaxTextExtent]; |
3579 | 7.07k | FormatString(quantum_size_str,"%u",quantum_size); |
3580 | 7.07k | status=0; |
3581 | 7.07k | ThrowException(&GetCacheViewImage(view)->exception,CoderError, |
3582 | 7.07k | UnsupportedBitsPerSample,quantum_size_str); |
3583 | 7.07k | return MagickFail; |
3584 | 7.07k | } |
3585 | | |
3586 | | |
3587 | | /* printf("quantum_type=%d quantum_size=%u\n",(int) quantum_type, quantum_size); */ |
3588 | | |
3589 | 22.2M | { |
3590 | 22.2M | const double scale_denominator = double_maxvalue-double_minvalue; |
3591 | 22.2M | if (scale_denominator < MagickEpsilon) |
3592 | 6.26k | double_scale = 0.0; |
3593 | 22.2M | else |
3594 | 22.2M | double_scale=MaxRGBDouble/(scale_denominator); |
3595 | 22.2M | } |
3596 | 22.2M | if ((sample_type != FloatQuantumSampleType) && (sample_bits <= 32U)) |
3597 | 21.9M | { |
3598 | | /* Maximum value which may be represented by a sample */ |
3599 | 21.9M | unsigned_maxvalue=MaxValueGivenBits(sample_bits); |
3600 | | |
3601 | 21.9M | if (QuantumDepth == sample_bits) |
3602 | 371k | { |
3603 | 371k | } |
3604 | 21.5M | else if (QuantumDepth > sample_bits) |
3605 | 21.0M | { |
3606 | | /* Multiply to scale up */ |
3607 | 21.0M | unsigned_scale=(MaxRGB / (MaxRGB >> (QuantumDepth-sample_bits))); |
3608 | 21.0M | } |
3609 | 476k | #if QuantumDepth < 32 |
3610 | 476k | else if (QuantumDepth < sample_bits) |
3611 | 476k | { |
3612 | | /* Divide to scale down */ |
3613 | 476k | unsigned_scale=(unsigned_maxvalue/MaxRGB); |
3614 | 476k | } |
3615 | 21.9M | #endif |
3616 | 21.9M | } |
3617 | | |
3618 | 22.2M | image=GetCacheViewImage(view); |
3619 | 22.2M | number_pixels=(long) GetCacheViewArea(view); |
3620 | 22.2M | q=AccessCacheViewPixels(view); |
3621 | 22.2M | indexes=GetCacheViewIndexes(view); |
3622 | 22.2M | switch (quantum_type) |
3623 | 22.2M | { |
3624 | 0 | case UndefinedQuantum: |
3625 | 0 | { |
3626 | 0 | status=MagickFail; |
3627 | 0 | break; |
3628 | 0 | } |
3629 | 215k | case IndexQuantum: |
3630 | 215k | { |
3631 | 215k | status=ImportIndexQuantumType(source,q,indexes,number_pixels,quantum_size, |
3632 | 215k | sample_type,unsigned_maxvalue,endian,image, |
3633 | 215k | import_info); |
3634 | 215k | break; |
3635 | 0 | } |
3636 | 9.99k | case IndexAlphaQuantum: |
3637 | 9.99k | { |
3638 | 9.99k | status=ImportIndexAlphaQuantumType(source,q,indexes,number_pixels, |
3639 | 9.99k | quantum_size,sample_type,unsigned_scale, |
3640 | 9.99k | endian, |
3641 | 9.99k | image, |
3642 | 9.99k | import_info); |
3643 | 9.99k | break; |
3644 | 0 | } |
3645 | 16.1M | case GrayQuantum: |
3646 | 16.1M | { |
3647 | 16.1M | status=ImportGrayQuantumType(source,q,indexes,number_pixels,quantum_size, |
3648 | 16.1M | sample_type,unsigned_scale,unsigned_maxvalue, |
3649 | 16.1M | grayscale_miniswhite,double_minvalue, |
3650 | 16.1M | double_scale,endian,image,import_info); |
3651 | 16.1M | break; |
3652 | 0 | } |
3653 | 64.4k | case GrayAlphaQuantum: |
3654 | 64.4k | { |
3655 | 64.4k | status=ImportGrayAlphaQuantumType(source,q,indexes,number_pixels,quantum_size, |
3656 | 64.4k | sample_type,unsigned_scale,unsigned_maxvalue, |
3657 | 64.4k | grayscale_miniswhite,double_minvalue,double_scale, |
3658 | 64.4k | endian,image,import_info); |
3659 | 64.4k | break; |
3660 | 0 | } |
3661 | 335k | case RedQuantum: |
3662 | 621k | case CyanQuantum: |
3663 | 621k | { |
3664 | 621k | status=ImportRedQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3665 | 621k | unsigned_scale,double_minvalue,double_scale,endian, |
3666 | 621k | import_info); |
3667 | | |
3668 | 621k | break; |
3669 | 335k | } |
3670 | 182k | case GreenQuantum: |
3671 | 309k | case MagentaQuantum: |
3672 | 309k | { |
3673 | 309k | status=ImportGreenQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3674 | 309k | unsigned_scale,double_minvalue,double_scale,endian, |
3675 | 309k | import_info); |
3676 | 309k | break; |
3677 | 182k | } |
3678 | 92.3k | case BlueQuantum: |
3679 | 176k | case YellowQuantum: |
3680 | 176k | { |
3681 | 176k | status=ImportBlueQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3682 | 176k | unsigned_scale,double_minvalue,double_scale,endian, |
3683 | 176k | import_info); |
3684 | 176k | break; |
3685 | 92.3k | } |
3686 | 13.8k | case AlphaQuantum: |
3687 | 13.8k | { |
3688 | 13.8k | status=ImportAlphaQuantumType(source,q,indexes,number_pixels,quantum_size, |
3689 | 13.8k | sample_type,unsigned_scale,double_minvalue, |
3690 | 13.8k | double_scale,endian,image,import_info); |
3691 | 13.8k | break; |
3692 | 92.3k | } |
3693 | 55.7k | case BlackQuantum: |
3694 | 55.7k | { |
3695 | 55.7k | status=ImportBlackQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3696 | 55.7k | unsigned_scale,double_minvalue,double_scale,endian, |
3697 | 55.7k | import_info); |
3698 | 55.7k | break; |
3699 | 92.3k | } |
3700 | 4.19M | case RGBQuantum: |
3701 | 4.19M | { |
3702 | 4.19M | status=ImportRGBQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3703 | 4.19M | unsigned_scale,double_minvalue,double_scale,endian, |
3704 | 4.19M | import_info); |
3705 | 4.19M | break; |
3706 | 92.3k | } |
3707 | 204k | case RGBAQuantum: |
3708 | 204k | { |
3709 | 204k | status=ImportRGBAQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3710 | 204k | unsigned_scale,double_minvalue,double_scale,endian, |
3711 | 204k | import_info); |
3712 | 204k | break; |
3713 | 92.3k | } |
3714 | 162k | case CMYKQuantum: |
3715 | 162k | { |
3716 | 162k | status=ImportCMYKQuantumType(source,q,number_pixels,quantum_size, |
3717 | 162k | sample_type,unsigned_scale,double_minvalue, |
3718 | 162k | double_scale,endian,import_info); |
3719 | 162k | break; |
3720 | 92.3k | } |
3721 | 37.4k | case CMYKAQuantum: |
3722 | 37.4k | { |
3723 | 37.4k | status=ImportCMYKAQuantumType(source,q,indexes,number_pixels,quantum_size, |
3724 | 37.4k | sample_type,unsigned_scale,double_minvalue, |
3725 | 37.4k | double_scale,endian,image,import_info); |
3726 | 37.4k | break; |
3727 | 92.3k | } |
3728 | 7.07k | case CIEXYZQuantum: |
3729 | 7.07k | { |
3730 | 7.07k | status=ImportCIEXYZQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3731 | 7.07k | endian,import_info); |
3732 | 7.07k | break; |
3733 | 92.3k | } |
3734 | 23.6k | case CIEYQuantum: |
3735 | 23.6k | { |
3736 | 23.6k | status=ImportCIEYQuantumType(source,q,number_pixels,quantum_size,sample_type, |
3737 | 23.6k | endian,import_info); |
3738 | 23.6k | break; |
3739 | 92.3k | } |
3740 | 22.2M | } |
3741 | | |
3742 | 22.2M | return(status); |
3743 | 22.2M | } |
3744 | | |
3745 | | /* |
3746 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3747 | | % % |
3748 | | % % |
3749 | | % % |
3750 | | % I m p o r t P i x e l A r e a O p t i o n s I n i t % |
3751 | | % % |
3752 | | % % |
3753 | | % % |
3754 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3755 | | % |
3756 | | % ImportPixelAreaOptionsInit() initializes the options structure which is |
3757 | | % optionally passed to ImportPixelArea() |
3758 | | % |
3759 | | % The format of the ImportPixelAreaOptionsInit method is: |
3760 | | % |
3761 | | % void ImportPixelAreaOptionsInit(ImportPixelAreaOptions *options) |
3762 | | % |
3763 | | % A description of each parameter follows: |
3764 | | % |
3765 | | % o options: Options structure to initialize. |
3766 | | % |
3767 | | */ |
3768 | | MagickExport void ImportPixelAreaOptionsInit(ImportPixelAreaOptions *options) |
3769 | 218k | { |
3770 | 218k | assert(options != (ImportPixelAreaOptions *) NULL); |
3771 | 218k | (void) memset((void *) options, 0, sizeof(ImportPixelAreaOptions)); |
3772 | 218k | options->sample_type=UnsignedQuantumSampleType; |
3773 | 218k | options->double_minvalue=0.0; |
3774 | 218k | options->double_maxvalue=1.0; |
3775 | 218k | options->grayscale_miniswhite=MagickFalse; |
3776 | 218k | options->endian=MSBEndian; |
3777 | 218k | options->signature=MagickSignature; |
3778 | 218k | } |