/src/imagemagick/MagickCore/quantum-export.c
Line | Count | Source |
1 | | /* |
2 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3 | | % % |
4 | | % % |
5 | | % % |
6 | | % QQQ U U AAA N N TTTTT U U M M % |
7 | | % Q Q U U A A NN N T U U MM MM % |
8 | | % Q Q U U AAAAA N N N T U U M M M % |
9 | | % Q QQ U U A A N NN T U U M M % |
10 | | % QQQQ UUU A A N N T UUU M M % |
11 | | % % |
12 | | % EEEEE X X PPPP OOO RRRR TTTTT % |
13 | | % E X X P P O O R R T % |
14 | | % EEE X PPPP O O RRRR T % |
15 | | % E X X P O O R R T % |
16 | | % EEEEE X X P OOO R R T % |
17 | | % % |
18 | | % MagickCore Methods to Export Quantum Pixels % |
19 | | % % |
20 | | % Software Design % |
21 | | % Cristy % |
22 | | % October 1998 % |
23 | | % % |
24 | | % % |
25 | | % Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization % |
26 | | % dedicated to making software imaging solutions freely available. % |
27 | | % % |
28 | | % You may not use this file except in compliance with the License. You may % |
29 | | % obtain a copy of the License at % |
30 | | % % |
31 | | % https://imagemagick.org/license/ % |
32 | | % % |
33 | | % Unless required by applicable law or agreed to in writing, software % |
34 | | % distributed under the License is distributed on an "AS IS" BASIS, % |
35 | | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
36 | | % See the License for the specific language governing permissions and % |
37 | | % limitations under the License. % |
38 | | % % |
39 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
40 | | % |
41 | | % |
42 | | */ |
43 | | |
44 | | /* |
45 | | Include declarations. |
46 | | */ |
47 | | #include "MagickCore/studio.h" |
48 | | #include "MagickCore/property.h" |
49 | | #include "MagickCore/blob.h" |
50 | | #include "MagickCore/blob-private.h" |
51 | | #include "MagickCore/color-private.h" |
52 | | #include "MagickCore/exception.h" |
53 | | #include "MagickCore/exception-private.h" |
54 | | #include "MagickCore/cache.h" |
55 | | #include "MagickCore/constitute.h" |
56 | | #include "MagickCore/delegate.h" |
57 | | #include "MagickCore/geometry.h" |
58 | | #include "MagickCore/list.h" |
59 | | #include "MagickCore/magick.h" |
60 | | #include "MagickCore/memory_.h" |
61 | | #include "MagickCore/monitor.h" |
62 | | #include "MagickCore/option.h" |
63 | | #include "MagickCore/pixel.h" |
64 | | #include "MagickCore/pixel-accessor.h" |
65 | | #include "MagickCore/quantum.h" |
66 | | #include "MagickCore/quantum-private.h" |
67 | | #include "MagickCore/resource_.h" |
68 | | #include "MagickCore/semaphore.h" |
69 | | #include "MagickCore/statistic.h" |
70 | | #include "MagickCore/stream.h" |
71 | | #include "MagickCore/string_.h" |
72 | | #include "MagickCore/utility.h" |
73 | | |
74 | | /* |
75 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
76 | | % % |
77 | | % % |
78 | | % % |
79 | | + E x p o r t Q u a n t u m P i x e l s % |
80 | | % % |
81 | | % % |
82 | | % % |
83 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
84 | | % |
85 | | % ExportQuantumPixels() transfers one or more pixel components from the image |
86 | | % pixel cache to a user supplied buffer. The pixels are returned in network |
87 | | % byte order. It returns the number of exported pixels. |
88 | | % |
89 | | % The format of the ExportQuantumPixels method is: |
90 | | % |
91 | | % size_t ExportQuantumPixels(const Image *image,CacheView *image_view, |
92 | | % QuantumInfo *quantum_info,const QuantumType quantum_type, |
93 | | % unsigned char *magick_restrict pixels,ExceptionInfo *exception) |
94 | | % |
95 | | % A description of each parameter follows: |
96 | | % |
97 | | % o image: the image. |
98 | | % |
99 | | % o image_view: the image cache view. |
100 | | % |
101 | | % o quantum_info: the quantum info. |
102 | | % |
103 | | % o quantum_type: Declare which pixel components to transfer (RGB, RGBA, |
104 | | % etc). |
105 | | % |
106 | | % o pixels: The components are transferred to this buffer. |
107 | | % |
108 | | % o exception: return any errors or warnings in this structure. |
109 | | % |
110 | | */ |
111 | | |
112 | | static inline unsigned char *PopQuantumDoublePixel(QuantumInfo *quantum_info, |
113 | | const double pixel,unsigned char *magick_restrict pixels) |
114 | 14.3k | { |
115 | 14.3k | double |
116 | 14.3k | *p; |
117 | | |
118 | 14.3k | unsigned char |
119 | 14.3k | quantum[8]; |
120 | | |
121 | 14.3k | (void) memset(quantum,0,sizeof(quantum)); |
122 | 14.3k | p=(double *) quantum; |
123 | 14.3k | *p=(double) (pixel*quantum_info->state.inverse_scale+quantum_info->minimum); |
124 | 14.3k | if (quantum_info->endian == LSBEndian) |
125 | 13.3k | { |
126 | 13.3k | *pixels++=quantum[0]; |
127 | 13.3k | *pixels++=quantum[1]; |
128 | 13.3k | *pixels++=quantum[2]; |
129 | 13.3k | *pixels++=quantum[3]; |
130 | 13.3k | *pixels++=quantum[4]; |
131 | 13.3k | *pixels++=quantum[5]; |
132 | 13.3k | *pixels++=quantum[6]; |
133 | 13.3k | *pixels++=quantum[7]; |
134 | 13.3k | return(pixels); |
135 | 13.3k | } |
136 | 1.00k | *pixels++=quantum[7]; |
137 | 1.00k | *pixels++=quantum[6]; |
138 | 1.00k | *pixels++=quantum[5]; |
139 | 1.00k | *pixels++=quantum[4]; |
140 | 1.00k | *pixels++=quantum[3]; |
141 | 1.00k | *pixels++=quantum[2]; |
142 | 1.00k | *pixels++=quantum[1]; |
143 | 1.00k | *pixels++=quantum[0]; |
144 | 1.00k | return(pixels); |
145 | 14.3k | } |
146 | | |
147 | | static inline unsigned char *PopQuantumFloatPixel(QuantumInfo *quantum_info, |
148 | | const float pixel,unsigned char *magick_restrict pixels) |
149 | 530k | { |
150 | 530k | float |
151 | 530k | *p; |
152 | | |
153 | 530k | unsigned char |
154 | 530k | quantum[4]; |
155 | | |
156 | 530k | (void) memset(quantum,0,sizeof(quantum)); |
157 | 530k | p=(float *) quantum; |
158 | 530k | *p=(float) ((double) pixel*quantum_info->state.inverse_scale+ |
159 | 530k | quantum_info->minimum); |
160 | 530k | if (quantum_info->endian == LSBEndian) |
161 | 146k | { |
162 | 146k | *pixels++=quantum[0]; |
163 | 146k | *pixels++=quantum[1]; |
164 | 146k | *pixels++=quantum[2]; |
165 | 146k | *pixels++=quantum[3]; |
166 | 146k | return(pixels); |
167 | 146k | } |
168 | 383k | *pixels++=quantum[3]; |
169 | 383k | *pixels++=quantum[2]; |
170 | 383k | *pixels++=quantum[1]; |
171 | 383k | *pixels++=quantum[0]; |
172 | 383k | return(pixels); |
173 | 530k | } |
174 | | |
175 | | static inline unsigned char *PopQuantumPixel(QuantumInfo *quantum_info, |
176 | | const QuantumAny pixel,unsigned char *magick_restrict pixels) |
177 | 100M | { |
178 | 100M | ssize_t |
179 | 100M | i; |
180 | | |
181 | 100M | size_t |
182 | 100M | quantum_bits; |
183 | | |
184 | 100M | if (quantum_info->state.bits == 0UL) |
185 | 280k | quantum_info->state.bits=8U; |
186 | 203M | for (i=(ssize_t) quantum_info->depth; i > 0L; ) |
187 | 102M | { |
188 | 102M | quantum_bits=(size_t) i; |
189 | 102M | if (quantum_bits > quantum_info->state.bits) |
190 | 2.77M | quantum_bits=quantum_info->state.bits; |
191 | 102M | i-=(ssize_t) quantum_bits; |
192 | 102M | if (i < 0) |
193 | 0 | i=0; |
194 | 102M | if (quantum_info->state.bits == 8UL) |
195 | 15.6M | *pixels='\0'; |
196 | 102M | quantum_info->state.bits-=quantum_bits; |
197 | 102M | *pixels|=(((pixel >> i) &~ (((QuantumAny) ~0UL) << quantum_bits)) << |
198 | 102M | quantum_info->state.bits); |
199 | 102M | if (quantum_info->state.bits == 0UL) |
200 | 15.4M | { |
201 | 15.4M | pixels++; |
202 | 15.4M | quantum_info->state.bits=8UL; |
203 | 15.4M | } |
204 | 102M | } |
205 | 100M | return(pixels); |
206 | 100M | } |
207 | | |
208 | | static inline unsigned char *PopQuantumLongPixel(QuantumInfo *quantum_info, |
209 | | const size_t pixel,unsigned char *magick_restrict pixels) |
210 | 0 | { |
211 | 0 | ssize_t |
212 | 0 | i; |
213 | |
|
214 | 0 | size_t |
215 | 0 | quantum_bits; |
216 | |
|
217 | 0 | if (quantum_info->state.bits == 0U) |
218 | 0 | quantum_info->state.bits=32UL; |
219 | 0 | for (i=(ssize_t) quantum_info->depth; i > 0; ) |
220 | 0 | { |
221 | 0 | quantum_bits=(size_t) i; |
222 | 0 | if (quantum_bits > quantum_info->state.bits) |
223 | 0 | quantum_bits=quantum_info->state.bits; |
224 | 0 | quantum_info->state.pixel|=(((pixel >> ((ssize_t) quantum_info->depth-i)) & |
225 | 0 | quantum_info->state.mask[quantum_bits]) << (32U- |
226 | 0 | quantum_info->state.bits)); |
227 | 0 | i-=(ssize_t) quantum_bits; |
228 | 0 | quantum_info->state.bits-=quantum_bits; |
229 | 0 | if (quantum_info->state.bits == 0U) |
230 | 0 | { |
231 | 0 | pixels=PopLongPixel(quantum_info->endian,quantum_info->state.pixel, |
232 | 0 | pixels); |
233 | 0 | quantum_info->state.pixel=0U; |
234 | 0 | quantum_info->state.bits=32U; |
235 | 0 | } |
236 | 0 | } |
237 | 0 | return(pixels); |
238 | 0 | } |
239 | | |
240 | | static void ExportPixelChannel(const Image *image,QuantumInfo *quantum_info, |
241 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
242 | | unsigned char *magick_restrict q,PixelChannel channel) |
243 | 489k | { |
244 | 489k | QuantumAny |
245 | 489k | range; |
246 | | |
247 | 489k | ssize_t |
248 | 489k | x; |
249 | | |
250 | 489k | p+=(ptrdiff_t) image->channel_map[channel].offset; |
251 | 489k | switch (quantum_info->depth) |
252 | 489k | { |
253 | 115k | case 8: |
254 | 115k | { |
255 | 115k | unsigned char |
256 | 115k | pixel; |
257 | | |
258 | 1.10M | for (x=0; x < (ssize_t) number_pixels; x++) |
259 | 987k | { |
260 | 987k | pixel=ScaleQuantumToChar(*p); |
261 | 987k | q=PopCharPixel(pixel,q); |
262 | 987k | p+=(ptrdiff_t) GetPixelChannels(image); |
263 | 987k | q+=(ptrdiff_t) quantum_info->pad; |
264 | 987k | } |
265 | 115k | break; |
266 | 0 | } |
267 | 120k | case 16: |
268 | 120k | { |
269 | 120k | unsigned short |
270 | 120k | pixel; |
271 | | |
272 | 120k | if (quantum_info->format == FloatingPointQuantumFormat) |
273 | 0 | { |
274 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
275 | 0 | { |
276 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(*p)); |
277 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
278 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
279 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
280 | 0 | } |
281 | 0 | break; |
282 | 0 | } |
283 | 6.03M | for (x=0; x < (ssize_t) number_pixels; x++) |
284 | 5.91M | { |
285 | 5.91M | pixel=ScaleQuantumToShort(*p); |
286 | 5.91M | q=PopShortPixel(quantum_info->endian,pixel,q); |
287 | 5.91M | p+=(ptrdiff_t) GetPixelChannels(image); |
288 | 5.91M | q+=(ptrdiff_t) quantum_info->pad; |
289 | 5.91M | } |
290 | 120k | break; |
291 | 120k | } |
292 | 5.30k | case 32: |
293 | 5.30k | { |
294 | 5.30k | unsigned int |
295 | 5.30k | pixel; |
296 | | |
297 | 5.30k | if (quantum_info->format == FloatingPointQuantumFormat) |
298 | 3.16k | { |
299 | 7.85k | for (x=0; x < (ssize_t) number_pixels; x++) |
300 | 4.69k | { |
301 | 4.69k | q=PopQuantumFloatPixel(quantum_info,(float) *p,q); |
302 | 4.69k | p+=(ptrdiff_t) GetPixelChannels(image); |
303 | 4.69k | q+=(ptrdiff_t) quantum_info->pad; |
304 | 4.69k | } |
305 | 3.16k | break; |
306 | 3.16k | } |
307 | 5.83k | for (x=0; x < (ssize_t) number_pixels; x++) |
308 | 3.68k | { |
309 | 3.68k | pixel=ScaleQuantumToLong(*p); |
310 | 3.68k | q=PopLongPixel(quantum_info->endian,pixel,q); |
311 | 3.68k | p+=(ptrdiff_t) GetPixelChannels(image); |
312 | 3.68k | q+=(ptrdiff_t) quantum_info->pad; |
313 | 3.68k | } |
314 | 2.14k | break; |
315 | 5.30k | } |
316 | 2.94k | case 64: |
317 | 2.94k | { |
318 | 2.94k | if (quantum_info->format == FloatingPointQuantumFormat) |
319 | 1.46k | { |
320 | 4.38k | for (x=0; x < (ssize_t) number_pixels; x++) |
321 | 2.91k | { |
322 | 2.91k | q=PopQuantumDoublePixel(quantum_info,(double) *p,q); |
323 | 2.91k | p+=(ptrdiff_t) GetPixelChannels(image); |
324 | 2.91k | q+=(ptrdiff_t) quantum_info->pad; |
325 | 2.91k | } |
326 | 1.46k | break; |
327 | 1.46k | } |
328 | 1.47k | magick_fallthrough; |
329 | 1.47k | } |
330 | 246k | default: |
331 | 246k | { |
332 | 246k | range=GetQuantumRange(quantum_info->depth); |
333 | 97.8M | for (x=0; x < (ssize_t) number_pixels; x++) |
334 | 97.5M | { |
335 | 97.5M | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(*p,range),q); |
336 | 97.5M | p+=(ptrdiff_t) GetPixelChannels(image); |
337 | 97.5M | q+=(ptrdiff_t) quantum_info->pad; |
338 | 97.5M | } |
339 | 246k | break; |
340 | 1.47k | } |
341 | 489k | } |
342 | 489k | } |
343 | | |
344 | | static void ExportAlphaQuantum(const Image *image,QuantumInfo *quantum_info, |
345 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
346 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
347 | 260k | { |
348 | 260k | if (image->alpha_trait == UndefinedPixelTrait) |
349 | 0 | { |
350 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
351 | 0 | "ImageDoesNotHaveAnAlphaChannel","`%s'",image->filename); |
352 | 0 | return; |
353 | 0 | } |
354 | 260k | ExportPixelChannel(image,quantum_info,number_pixels,p,q,AlphaPixelChannel); |
355 | 260k | } |
356 | | |
357 | | static void ExportBGRQuantum(const Image *image,QuantumInfo *quantum_info, |
358 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
359 | | unsigned char *magick_restrict q) |
360 | 0 | { |
361 | 0 | QuantumAny |
362 | 0 | range; |
363 | |
|
364 | 0 | ssize_t |
365 | 0 | x; |
366 | |
|
367 | 0 | ssize_t |
368 | 0 | bit; |
369 | |
|
370 | 0 | switch (quantum_info->depth) |
371 | 0 | { |
372 | 0 | case 8: |
373 | 0 | { |
374 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
375 | 0 | { |
376 | 0 | q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q); |
377 | 0 | q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q); |
378 | 0 | q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q); |
379 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
380 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
381 | 0 | } |
382 | 0 | break; |
383 | 0 | } |
384 | 0 | case 10: |
385 | 0 | { |
386 | 0 | unsigned int |
387 | 0 | pixel; |
388 | |
|
389 | 0 | range=GetQuantumRange(quantum_info->depth); |
390 | 0 | if (quantum_info->pack == MagickFalse) |
391 | 0 | { |
392 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
393 | 0 | { |
394 | 0 | pixel=(unsigned int) ( |
395 | 0 | ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 | |
396 | 0 | ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 | |
397 | 0 | ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2); |
398 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
399 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
400 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
401 | 0 | } |
402 | 0 | break; |
403 | 0 | } |
404 | 0 | if (quantum_info->quantum == 32UL) |
405 | 0 | { |
406 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
407 | 0 | { |
408 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
409 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
410 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
411 | 0 | range); |
412 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
413 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
414 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
415 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
416 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
417 | 0 | } |
418 | 0 | break; |
419 | 0 | } |
420 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
421 | 0 | { |
422 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
423 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
424 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
425 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
426 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
427 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
428 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
429 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
430 | 0 | } |
431 | 0 | break; |
432 | 0 | } |
433 | 0 | case 12: |
434 | 0 | { |
435 | 0 | unsigned int |
436 | 0 | pixel; |
437 | |
|
438 | 0 | range=GetQuantumRange(quantum_info->depth); |
439 | 0 | if (quantum_info->pack == MagickFalse) |
440 | 0 | { |
441 | 0 | for (x=0; x < (3*(ssize_t) number_pixels-1); x+=2) |
442 | 0 | { |
443 | 0 | switch (x % 3) |
444 | 0 | { |
445 | 0 | default: |
446 | 0 | case 0: |
447 | 0 | { |
448 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p), |
449 | 0 | range); |
450 | 0 | break; |
451 | 0 | } |
452 | 0 | case 1: |
453 | 0 | { |
454 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
455 | 0 | range); |
456 | 0 | break; |
457 | 0 | } |
458 | 0 | case 2: |
459 | 0 | { |
460 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p), |
461 | 0 | range); |
462 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
463 | 0 | break; |
464 | 0 | } |
465 | 0 | } |
466 | 0 | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4), |
467 | 0 | q); |
468 | 0 | switch ((x+1) % 3) |
469 | 0 | { |
470 | 0 | default: |
471 | 0 | case 0: |
472 | 0 | { |
473 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p), |
474 | 0 | range); |
475 | 0 | break; |
476 | 0 | } |
477 | 0 | case 1: |
478 | 0 | { |
479 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
480 | 0 | range); |
481 | 0 | break; |
482 | 0 | } |
483 | 0 | case 2: |
484 | 0 | { |
485 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p), |
486 | 0 | range); |
487 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
488 | 0 | break; |
489 | 0 | } |
490 | 0 | } |
491 | 0 | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4), |
492 | 0 | q); |
493 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
494 | 0 | } |
495 | 0 | for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++) |
496 | 0 | { |
497 | 0 | switch ((x+bit) % 3) |
498 | 0 | { |
499 | 0 | default: |
500 | 0 | case 0: |
501 | 0 | { |
502 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p), |
503 | 0 | range); |
504 | 0 | break; |
505 | 0 | } |
506 | 0 | case 1: |
507 | 0 | { |
508 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
509 | 0 | range); |
510 | 0 | break; |
511 | 0 | } |
512 | 0 | case 2: |
513 | 0 | { |
514 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p), |
515 | 0 | range); |
516 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
517 | 0 | break; |
518 | 0 | } |
519 | 0 | } |
520 | 0 | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4), |
521 | 0 | q); |
522 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
523 | 0 | } |
524 | 0 | if (bit != 0) |
525 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
526 | 0 | break; |
527 | 0 | } |
528 | 0 | if (quantum_info->quantum == 32UL) |
529 | 0 | { |
530 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
531 | 0 | { |
532 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
533 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
534 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
535 | 0 | range); |
536 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
537 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
538 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
539 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
540 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
541 | 0 | } |
542 | 0 | break; |
543 | 0 | } |
544 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
545 | 0 | { |
546 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
547 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
548 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
549 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
550 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
551 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
552 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
553 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
554 | 0 | } |
555 | 0 | break; |
556 | 0 | } |
557 | 0 | case 16: |
558 | 0 | { |
559 | 0 | unsigned short |
560 | 0 | pixel; |
561 | |
|
562 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
563 | 0 | { |
564 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
565 | 0 | { |
566 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
567 | 0 | GetPixelBlue(image,p)); |
568 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
569 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
570 | 0 | GetPixelGreen(image,p)); |
571 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
572 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
573 | 0 | GetPixelRed(image,p)); |
574 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
575 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
576 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
577 | 0 | } |
578 | 0 | break; |
579 | 0 | } |
580 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
581 | 0 | { |
582 | 0 | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
583 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
584 | 0 | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
585 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
586 | 0 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
587 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
588 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
589 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
590 | 0 | } |
591 | 0 | break; |
592 | 0 | } |
593 | 0 | case 32: |
594 | 0 | { |
595 | 0 | unsigned int |
596 | 0 | pixel; |
597 | |
|
598 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
599 | 0 | { |
600 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
601 | 0 | { |
602 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q); |
603 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q); |
604 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q); |
605 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
606 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
607 | 0 | } |
608 | 0 | break; |
609 | 0 | } |
610 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
611 | 0 | { |
612 | 0 | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
613 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
614 | 0 | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
615 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
616 | 0 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
617 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
618 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
619 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
620 | 0 | } |
621 | 0 | break; |
622 | 0 | } |
623 | 0 | case 64: |
624 | 0 | { |
625 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
626 | 0 | { |
627 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
628 | 0 | { |
629 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q); |
630 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q); |
631 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q); |
632 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
633 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
634 | 0 | } |
635 | 0 | break; |
636 | 0 | } |
637 | 0 | magick_fallthrough; |
638 | 0 | } |
639 | 0 | default: |
640 | 0 | { |
641 | 0 | range=GetQuantumRange(quantum_info->depth); |
642 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
643 | 0 | { |
644 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
645 | 0 | range),q); |
646 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
647 | 0 | range),q); |
648 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
649 | 0 | range),q); |
650 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
651 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
652 | 0 | } |
653 | 0 | break; |
654 | 0 | } |
655 | 0 | } |
656 | 0 | } |
657 | | |
658 | | static void ExportBGRAQuantum(const Image *image,QuantumInfo *quantum_info, |
659 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
660 | | unsigned char *magick_restrict q) |
661 | 0 | { |
662 | 0 | QuantumAny |
663 | 0 | range; |
664 | |
|
665 | 0 | ssize_t |
666 | 0 | x; |
667 | |
|
668 | 0 | switch (quantum_info->depth) |
669 | 0 | { |
670 | 0 | case 8: |
671 | 0 | { |
672 | 0 | unsigned char |
673 | 0 | pixel; |
674 | |
|
675 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
676 | 0 | { |
677 | 0 | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
678 | 0 | q=PopCharPixel(pixel,q); |
679 | 0 | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
680 | 0 | q=PopCharPixel(pixel,q); |
681 | 0 | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
682 | 0 | q=PopCharPixel(pixel,q); |
683 | 0 | pixel=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
684 | 0 | q=PopCharPixel(pixel,q); |
685 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
686 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
687 | 0 | } |
688 | 0 | break; |
689 | 0 | } |
690 | 0 | case 10: |
691 | 0 | { |
692 | 0 | unsigned int |
693 | 0 | pixel; |
694 | |
|
695 | 0 | range=GetQuantumRange(quantum_info->depth); |
696 | 0 | if (quantum_info->pack == MagickFalse) |
697 | 0 | { |
698 | 0 | ssize_t |
699 | 0 | i; |
700 | |
|
701 | 0 | size_t |
702 | 0 | quantum; |
703 | |
|
704 | 0 | ssize_t |
705 | 0 | n; |
706 | |
|
707 | 0 | n=0; |
708 | 0 | quantum=0; |
709 | 0 | pixel=0; |
710 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
711 | 0 | { |
712 | 0 | for (i=0; i < 4; i++) |
713 | 0 | { |
714 | 0 | switch (i) |
715 | 0 | { |
716 | 0 | case 0: quantum=(size_t) GetPixelRed(image,p); break; |
717 | 0 | case 1: quantum=(size_t) GetPixelGreen(image,p); break; |
718 | 0 | case 2: quantum=(size_t) GetPixelBlue(image,p); break; |
719 | 0 | case 3: quantum=(size_t) GetPixelAlpha(image,p); break; |
720 | 0 | } |
721 | 0 | switch (n % 3) |
722 | 0 | { |
723 | 0 | case 0: |
724 | 0 | { |
725 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
726 | 0 | range) << 22); |
727 | 0 | break; |
728 | 0 | } |
729 | 0 | case 1: |
730 | 0 | { |
731 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
732 | 0 | range) << 12); |
733 | 0 | break; |
734 | 0 | } |
735 | 0 | case 2: |
736 | 0 | { |
737 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
738 | 0 | range) << 2); |
739 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
740 | 0 | pixel=0; |
741 | 0 | break; |
742 | 0 | } |
743 | 0 | } |
744 | 0 | n++; |
745 | 0 | } |
746 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
747 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
748 | 0 | } |
749 | 0 | break; |
750 | 0 | } |
751 | 0 | if (quantum_info->quantum == 32UL) |
752 | 0 | { |
753 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
754 | 0 | { |
755 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
756 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
757 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
758 | 0 | range); |
759 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
760 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
761 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
762 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p), |
763 | 0 | range); |
764 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
765 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
766 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
767 | 0 | } |
768 | 0 | break; |
769 | 0 | } |
770 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
771 | 0 | { |
772 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
773 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
774 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
775 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
776 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
777 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
778 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),range); |
779 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
780 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
781 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
782 | 0 | } |
783 | 0 | break; |
784 | 0 | } |
785 | 0 | case 16: |
786 | 0 | { |
787 | 0 | unsigned short |
788 | 0 | pixel; |
789 | |
|
790 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
791 | 0 | { |
792 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
793 | 0 | { |
794 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
795 | 0 | GetPixelBlue(image,p)); |
796 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
797 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
798 | 0 | GetPixelGreen(image,p)); |
799 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
800 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
801 | 0 | GetPixelRed(image,p)); |
802 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
803 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
804 | 0 | GetPixelAlpha(image,p)); |
805 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
806 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
807 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
808 | 0 | } |
809 | 0 | break; |
810 | 0 | } |
811 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
812 | 0 | { |
813 | 0 | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
814 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
815 | 0 | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
816 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
817 | 0 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
818 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
819 | 0 | pixel=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
820 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
821 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
822 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
823 | 0 | } |
824 | 0 | break; |
825 | 0 | } |
826 | 0 | case 32: |
827 | 0 | { |
828 | 0 | unsigned int |
829 | 0 | pixel; |
830 | |
|
831 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
832 | 0 | { |
833 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
834 | 0 | { |
835 | 0 | float |
836 | 0 | float_pixel; |
837 | |
|
838 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q); |
839 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q); |
840 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q); |
841 | 0 | float_pixel=(float) GetPixelAlpha(image,p); |
842 | 0 | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
843 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
844 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
845 | 0 | } |
846 | 0 | break; |
847 | 0 | } |
848 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
849 | 0 | { |
850 | 0 | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
851 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
852 | 0 | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
853 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
854 | 0 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
855 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
856 | 0 | pixel=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
857 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
858 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
859 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
860 | 0 | } |
861 | 0 | break; |
862 | 0 | } |
863 | 0 | case 64: |
864 | 0 | { |
865 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
866 | 0 | { |
867 | 0 | double |
868 | 0 | pixel; |
869 | |
|
870 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
871 | 0 | { |
872 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q); |
873 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q); |
874 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q); |
875 | 0 | pixel=(double) GetPixelAlpha(image,p); |
876 | 0 | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
877 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
878 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
879 | 0 | } |
880 | 0 | break; |
881 | 0 | } |
882 | 0 | magick_fallthrough; |
883 | 0 | } |
884 | 0 | default: |
885 | 0 | { |
886 | 0 | range=GetQuantumRange(quantum_info->depth); |
887 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
888 | 0 | { |
889 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
890 | 0 | range),q); |
891 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
892 | 0 | range),q); |
893 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
894 | 0 | range),q); |
895 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p), |
896 | 0 | range),q); |
897 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
898 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
899 | 0 | } |
900 | 0 | break; |
901 | 0 | } |
902 | 0 | } |
903 | 0 | } |
904 | | |
905 | | static void ExportBGROQuantum(const Image *image,QuantumInfo *quantum_info, |
906 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
907 | | unsigned char *magick_restrict q) |
908 | 0 | { |
909 | 0 | QuantumAny |
910 | 0 | range; |
911 | |
|
912 | 0 | ssize_t |
913 | 0 | x; |
914 | |
|
915 | 0 | switch (quantum_info->depth) |
916 | 0 | { |
917 | 0 | case 8: |
918 | 0 | { |
919 | 0 | unsigned char |
920 | 0 | pixel; |
921 | |
|
922 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
923 | 0 | { |
924 | 0 | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
925 | 0 | q=PopCharPixel(pixel,q); |
926 | 0 | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
927 | 0 | q=PopCharPixel(pixel,q); |
928 | 0 | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
929 | 0 | q=PopCharPixel(pixel,q); |
930 | 0 | pixel=ScaleQuantumToChar(GetPixelOpacity(image,p)); |
931 | 0 | q=PopCharPixel(pixel,q); |
932 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
933 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
934 | 0 | } |
935 | 0 | break; |
936 | 0 | } |
937 | 0 | case 10: |
938 | 0 | { |
939 | 0 | unsigned int |
940 | 0 | pixel; |
941 | |
|
942 | 0 | range=GetQuantumRange(quantum_info->depth); |
943 | 0 | if (quantum_info->pack == MagickFalse) |
944 | 0 | { |
945 | 0 | ssize_t |
946 | 0 | i; |
947 | |
|
948 | 0 | size_t |
949 | 0 | quantum; |
950 | |
|
951 | 0 | ssize_t |
952 | 0 | n; |
953 | |
|
954 | 0 | n=0; |
955 | 0 | quantum=0; |
956 | 0 | pixel=0; |
957 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
958 | 0 | { |
959 | 0 | for (i=0; i < 4; i++) |
960 | 0 | { |
961 | 0 | switch (i) |
962 | 0 | { |
963 | 0 | case 0: quantum=(size_t) GetPixelRed(image,p); break; |
964 | 0 | case 1: quantum=(size_t) GetPixelGreen(image,p); break; |
965 | 0 | case 2: quantum=(size_t) GetPixelBlue(image,p); break; |
966 | 0 | case 3: quantum=(size_t) GetPixelOpacity(image,p); break; |
967 | 0 | } |
968 | 0 | switch (n % 3) |
969 | 0 | { |
970 | 0 | case 0: |
971 | 0 | { |
972 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
973 | 0 | range) << 22); |
974 | 0 | break; |
975 | 0 | } |
976 | 0 | case 1: |
977 | 0 | { |
978 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
979 | 0 | range) << 12); |
980 | 0 | break; |
981 | 0 | } |
982 | 0 | case 2: |
983 | 0 | { |
984 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
985 | 0 | range) << 2); |
986 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
987 | 0 | pixel=0; |
988 | 0 | break; |
989 | 0 | } |
990 | 0 | } |
991 | 0 | n++; |
992 | 0 | } |
993 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
994 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
995 | 0 | } |
996 | 0 | break; |
997 | 0 | } |
998 | 0 | if (quantum_info->quantum == 32UL) |
999 | 0 | { |
1000 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1001 | 0 | { |
1002 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
1003 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
1004 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
1005 | 0 | range); |
1006 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
1007 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
1008 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
1009 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p), |
1010 | 0 | range); |
1011 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
1012 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1013 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1014 | 0 | } |
1015 | 0 | break; |
1016 | 0 | } |
1017 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1018 | 0 | { |
1019 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
1020 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
1021 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
1022 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
1023 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
1024 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
1025 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),range); |
1026 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
1027 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1028 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1029 | 0 | } |
1030 | 0 | break; |
1031 | 0 | } |
1032 | 0 | case 16: |
1033 | 0 | { |
1034 | 0 | unsigned short |
1035 | 0 | pixel; |
1036 | |
|
1037 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
1038 | 0 | { |
1039 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1040 | 0 | { |
1041 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1042 | 0 | GetPixelBlue(image,p)); |
1043 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1044 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1045 | 0 | GetPixelGreen(image,p)); |
1046 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1047 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1048 | 0 | GetPixelRed(image,p)); |
1049 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1050 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1051 | 0 | GetPixelOpacity(image,p)); |
1052 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1053 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1054 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1055 | 0 | } |
1056 | 0 | break; |
1057 | 0 | } |
1058 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1059 | 0 | { |
1060 | 0 | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
1061 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1062 | 0 | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
1063 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1064 | 0 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
1065 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1066 | 0 | pixel=ScaleQuantumToShort(GetPixelOpacity(image,p)); |
1067 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1068 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1069 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1070 | 0 | } |
1071 | 0 | break; |
1072 | 0 | } |
1073 | 0 | case 32: |
1074 | 0 | { |
1075 | 0 | unsigned int |
1076 | 0 | pixel; |
1077 | |
|
1078 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
1079 | 0 | { |
1080 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1081 | 0 | { |
1082 | 0 | float |
1083 | 0 | float_pixel; |
1084 | |
|
1085 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q); |
1086 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q); |
1087 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q); |
1088 | 0 | float_pixel=(float) GetPixelOpacity(image,p); |
1089 | 0 | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
1090 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1091 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1092 | 0 | } |
1093 | 0 | break; |
1094 | 0 | } |
1095 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1096 | 0 | { |
1097 | 0 | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
1098 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1099 | 0 | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
1100 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1101 | 0 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
1102 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1103 | 0 | pixel=ScaleQuantumToLong(GetPixelOpacity(image,p)); |
1104 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1105 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1106 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1107 | 0 | } |
1108 | 0 | break; |
1109 | 0 | } |
1110 | 0 | case 64: |
1111 | 0 | { |
1112 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
1113 | 0 | { |
1114 | 0 | double |
1115 | 0 | pixel; |
1116 | |
|
1117 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1118 | 0 | { |
1119 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q); |
1120 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q); |
1121 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q); |
1122 | 0 | pixel=(double) GetPixelOpacity(image,p); |
1123 | 0 | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
1124 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1125 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1126 | 0 | } |
1127 | 0 | break; |
1128 | 0 | } |
1129 | 0 | magick_fallthrough; |
1130 | 0 | } |
1131 | 0 | default: |
1132 | 0 | { |
1133 | 0 | range=GetQuantumRange(quantum_info->depth); |
1134 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1135 | 0 | { |
1136 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
1137 | 0 | range),q); |
1138 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
1139 | 0 | range),q); |
1140 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
1141 | 0 | range),q); |
1142 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p), |
1143 | 0 | range),q); |
1144 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1145 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1146 | 0 | } |
1147 | 0 | break; |
1148 | 0 | } |
1149 | 0 | } |
1150 | 0 | } |
1151 | | |
1152 | | static void ExportBlackQuantum(const Image *image,QuantumInfo *quantum_info, |
1153 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
1154 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
1155 | 1.20k | { |
1156 | 1.20k | if (image->colorspace != CMYKColorspace) |
1157 | 0 | { |
1158 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1159 | 0 | "ColorSeparatedImageRequired","`%s'",image->filename); |
1160 | 0 | return; |
1161 | 0 | } |
1162 | 1.20k | ExportPixelChannel(image,quantum_info,number_pixels,p,q,BlackPixelChannel); |
1163 | 1.20k | } |
1164 | | |
1165 | | static void ExportCbYCrYQuantum(const Image *image,QuantumInfo *quantum_info, |
1166 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
1167 | | unsigned char *magick_restrict q) |
1168 | 0 | { |
1169 | 0 | Quantum |
1170 | 0 | cbcr[4]; |
1171 | |
|
1172 | 0 | ssize_t |
1173 | 0 | i, |
1174 | 0 | x; |
1175 | |
|
1176 | 0 | unsigned int |
1177 | 0 | pixel; |
1178 | |
|
1179 | 0 | size_t |
1180 | 0 | quantum; |
1181 | |
|
1182 | 0 | ssize_t |
1183 | 0 | n; |
1184 | |
|
1185 | 0 | n=0; |
1186 | 0 | quantum=0; |
1187 | 0 | switch (quantum_info->depth) |
1188 | 0 | { |
1189 | 0 | case 10: |
1190 | 0 | { |
1191 | 0 | if (quantum_info->pack == MagickFalse) |
1192 | 0 | { |
1193 | 0 | for (x=0; x < (ssize_t) number_pixels; x+=2) |
1194 | 0 | { |
1195 | 0 | for (i=0; i < 4; i++) |
1196 | 0 | { |
1197 | 0 | switch (n % 3) |
1198 | 0 | { |
1199 | 0 | case 0: |
1200 | 0 | { |
1201 | 0 | quantum=(size_t) GetPixelRed(image,p); |
1202 | 0 | break; |
1203 | 0 | } |
1204 | 0 | case 1: |
1205 | 0 | { |
1206 | 0 | quantum=(size_t) GetPixelGreen(image,p); |
1207 | 0 | break; |
1208 | 0 | } |
1209 | 0 | case 2: |
1210 | 0 | { |
1211 | 0 | quantum=(size_t) GetPixelBlue(image,p); |
1212 | 0 | break; |
1213 | 0 | } |
1214 | 0 | } |
1215 | 0 | cbcr[i]=(Quantum) quantum; |
1216 | 0 | n++; |
1217 | 0 | } |
1218 | 0 | pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 | (size_t) |
1219 | 0 | (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2); |
1220 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1221 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1222 | 0 | pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 | (size_t) |
1223 | 0 | (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2); |
1224 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1225 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1226 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1227 | 0 | } |
1228 | 0 | break; |
1229 | 0 | } |
1230 | 0 | break; |
1231 | 0 | } |
1232 | 0 | default: |
1233 | 0 | { |
1234 | 0 | QuantumAny |
1235 | 0 | range; |
1236 | |
|
1237 | 0 | for (x=0; x < (ssize_t) number_pixels; x+=2) |
1238 | 0 | { |
1239 | 0 | for (i=0; i < 4; i++) |
1240 | 0 | { |
1241 | 0 | switch (n % 3) |
1242 | 0 | { |
1243 | 0 | case 0: |
1244 | 0 | { |
1245 | 0 | quantum=(size_t) GetPixelRed(image,p); |
1246 | 0 | break; |
1247 | 0 | } |
1248 | 0 | case 1: |
1249 | 0 | { |
1250 | 0 | quantum=(size_t) GetPixelGreen(image,p); |
1251 | 0 | break; |
1252 | 0 | } |
1253 | 0 | case 2: |
1254 | 0 | { |
1255 | 0 | quantum=(size_t) GetPixelBlue(image,p); |
1256 | 0 | break; |
1257 | 0 | } |
1258 | 0 | } |
1259 | 0 | cbcr[i]=(Quantum) quantum; |
1260 | 0 | n++; |
1261 | 0 | } |
1262 | 0 | range=GetQuantumRange(quantum_info->depth); |
1263 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[1],range),q); |
1264 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[0],range),q); |
1265 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[2],range),q); |
1266 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1267 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[3],range),q); |
1268 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[0],range),q); |
1269 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[2],range),q); |
1270 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1271 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1272 | 0 | } |
1273 | 0 | break; |
1274 | 0 | } |
1275 | 0 | } |
1276 | 0 | } |
1277 | | |
1278 | | static void ExportCMYKQuantum(const Image *image,QuantumInfo *quantum_info, |
1279 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
1280 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
1281 | 24.3k | { |
1282 | 24.3k | ssize_t |
1283 | 24.3k | x; |
1284 | | |
1285 | 24.3k | if (image->colorspace != CMYKColorspace) |
1286 | 0 | { |
1287 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1288 | 0 | "ColorSeparatedImageRequired","`%s'",image->filename); |
1289 | 0 | return; |
1290 | 0 | } |
1291 | 24.3k | switch (quantum_info->depth) |
1292 | 24.3k | { |
1293 | 4.62k | case 8: |
1294 | 4.62k | { |
1295 | 4.62k | unsigned char |
1296 | 4.62k | pixel; |
1297 | | |
1298 | 2.00M | for (x=0; x < (ssize_t) number_pixels; x++) |
1299 | 1.99M | { |
1300 | 1.99M | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
1301 | 1.99M | q=PopCharPixel(pixel,q); |
1302 | 1.99M | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1303 | 1.99M | q=PopCharPixel(pixel,q); |
1304 | 1.99M | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1305 | 1.99M | q=PopCharPixel(pixel,q); |
1306 | 1.99M | pixel=ScaleQuantumToChar(GetPixelBlack(image,p)); |
1307 | 1.99M | q=PopCharPixel(pixel,q); |
1308 | 1.99M | p+=(ptrdiff_t) GetPixelChannels(image); |
1309 | 1.99M | q+=(ptrdiff_t) quantum_info->pad; |
1310 | 1.99M | } |
1311 | 4.62k | break; |
1312 | 0 | } |
1313 | 7.84k | case 16: |
1314 | 7.84k | { |
1315 | 7.84k | unsigned short |
1316 | 7.84k | pixel; |
1317 | | |
1318 | 7.84k | if (quantum_info->format == FloatingPointQuantumFormat) |
1319 | 4.82k | { |
1320 | 97.8k | for (x=0; x < (ssize_t) number_pixels; x++) |
1321 | 93.0k | { |
1322 | 93.0k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1323 | 93.0k | GetPixelRed(image,p)); |
1324 | 93.0k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1325 | 93.0k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1326 | 93.0k | GetPixelGreen(image,p)); |
1327 | 93.0k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1328 | 93.0k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1329 | 93.0k | GetPixelBlue(image,p)); |
1330 | 93.0k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1331 | 93.0k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1332 | 93.0k | GetPixelBlack(image,p)); |
1333 | 93.0k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1334 | 93.0k | p+=(ptrdiff_t) GetPixelChannels(image); |
1335 | 93.0k | q+=(ptrdiff_t) quantum_info->pad; |
1336 | 93.0k | } |
1337 | 4.82k | break; |
1338 | 4.82k | } |
1339 | 55.7k | for (x=0; x < (ssize_t) number_pixels; x++) |
1340 | 52.6k | { |
1341 | 52.6k | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
1342 | 52.6k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1343 | 52.6k | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
1344 | 52.6k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1345 | 52.6k | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
1346 | 52.6k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1347 | 52.6k | pixel=ScaleQuantumToShort(GetPixelBlack(image,p)); |
1348 | 52.6k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1349 | 52.6k | p+=(ptrdiff_t) GetPixelChannels(image); |
1350 | 52.6k | q+=(ptrdiff_t) quantum_info->pad; |
1351 | 52.6k | } |
1352 | 3.02k | break; |
1353 | 7.84k | } |
1354 | 8.54k | case 32: |
1355 | 8.54k | { |
1356 | 8.54k | unsigned int |
1357 | 8.54k | pixel; |
1358 | | |
1359 | 8.54k | if (quantum_info->format == FloatingPointQuantumFormat) |
1360 | 1.90k | { |
1361 | 27.1k | for (x=0; x < (ssize_t) number_pixels; x++) |
1362 | 25.2k | { |
1363 | 25.2k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p), |
1364 | 25.2k | q); |
1365 | 25.2k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p), |
1366 | 25.2k | q); |
1367 | 25.2k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p), |
1368 | 25.2k | q); |
1369 | 25.2k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlack(image,p), |
1370 | 25.2k | q); |
1371 | 25.2k | p+=(ptrdiff_t) GetPixelChannels(image); |
1372 | 25.2k | q+=(ptrdiff_t) quantum_info->pad; |
1373 | 25.2k | } |
1374 | 1.90k | break; |
1375 | 1.90k | } |
1376 | 25.5k | for (x=0; x < (ssize_t) number_pixels; x++) |
1377 | 18.9k | { |
1378 | 18.9k | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
1379 | 18.9k | q=PopLongPixel(quantum_info->endian,pixel,q); |
1380 | 18.9k | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
1381 | 18.9k | q=PopLongPixel(quantum_info->endian,pixel,q); |
1382 | 18.9k | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
1383 | 18.9k | q=PopLongPixel(quantum_info->endian,pixel,q); |
1384 | 18.9k | pixel=ScaleQuantumToLong(GetPixelBlack(image,p)); |
1385 | 18.9k | q=PopLongPixel(quantum_info->endian,pixel,q); |
1386 | 18.9k | p+=(ptrdiff_t) GetPixelChannels(image); |
1387 | 18.9k | q+=(ptrdiff_t) quantum_info->pad; |
1388 | 18.9k | } |
1389 | 6.64k | break; |
1390 | 8.54k | } |
1391 | 1.13k | case 64: |
1392 | 1.13k | { |
1393 | 1.13k | if (quantum_info->format == FloatingPointQuantumFormat) |
1394 | 146 | { |
1395 | 842 | for (x=0; x < (ssize_t) number_pixels; x++) |
1396 | 696 | { |
1397 | 696 | q=PopQuantumDoublePixel(quantum_info,(double) |
1398 | 696 | GetPixelRed(image,p),q); |
1399 | 696 | q=PopQuantumDoublePixel(quantum_info,(double) |
1400 | 696 | GetPixelGreen(image,p),q); |
1401 | 696 | q=PopQuantumDoublePixel(quantum_info,(double) |
1402 | 696 | GetPixelBlue(image,p),q); |
1403 | 696 | q=PopQuantumDoublePixel(quantum_info,(double) |
1404 | 696 | GetPixelBlack(image,p),q); |
1405 | 696 | p+=(ptrdiff_t) GetPixelChannels(image); |
1406 | 696 | q+=(ptrdiff_t) quantum_info->pad; |
1407 | 696 | } |
1408 | 146 | break; |
1409 | 146 | } |
1410 | 987 | magick_fallthrough; |
1411 | 987 | } |
1412 | 3.14k | default: |
1413 | 3.14k | { |
1414 | 3.14k | QuantumAny |
1415 | 3.14k | range; |
1416 | | |
1417 | 3.14k | range=GetQuantumRange(quantum_info->depth); |
1418 | 67.7k | for (x=0; x < (ssize_t) number_pixels; x++) |
1419 | 64.6k | { |
1420 | 64.6k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
1421 | 64.6k | range),q); |
1422 | 64.6k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
1423 | 64.6k | range),q); |
1424 | 64.6k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
1425 | 64.6k | range),q); |
1426 | 64.6k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p), |
1427 | 64.6k | range),q); |
1428 | 64.6k | p+=(ptrdiff_t) GetPixelChannels(image); |
1429 | 64.6k | q+=(ptrdiff_t) quantum_info->pad; |
1430 | 64.6k | } |
1431 | 3.14k | break; |
1432 | 987 | } |
1433 | 24.3k | } |
1434 | 24.3k | } |
1435 | | |
1436 | | static void ExportCMYKAQuantum(const Image *image,QuantumInfo *quantum_info, |
1437 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
1438 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
1439 | 40.3k | { |
1440 | 40.3k | ssize_t |
1441 | 40.3k | x; |
1442 | | |
1443 | 40.3k | if (image->colorspace != CMYKColorspace) |
1444 | 0 | { |
1445 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1446 | 0 | "ColorSeparatedImageRequired","`%s'",image->filename); |
1447 | 0 | return; |
1448 | 0 | } |
1449 | 40.3k | switch (quantum_info->depth) |
1450 | 40.3k | { |
1451 | 6.46k | case 8: |
1452 | 6.46k | { |
1453 | 6.46k | unsigned char |
1454 | 6.46k | pixel; |
1455 | | |
1456 | 7.42M | for (x=0; x < (ssize_t) number_pixels; x++) |
1457 | 7.41M | { |
1458 | 7.41M | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
1459 | 7.41M | q=PopCharPixel(pixel,q); |
1460 | 7.41M | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1461 | 7.41M | q=PopCharPixel(pixel,q); |
1462 | 7.41M | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1463 | 7.41M | q=PopCharPixel(pixel,q); |
1464 | 7.41M | pixel=ScaleQuantumToChar(GetPixelBlack(image,p)); |
1465 | 7.41M | q=PopCharPixel(pixel,q); |
1466 | 7.41M | pixel=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
1467 | 7.41M | q=PopCharPixel(pixel,q); |
1468 | 7.41M | p+=(ptrdiff_t) GetPixelChannels(image); |
1469 | 7.41M | q+=(ptrdiff_t) quantum_info->pad; |
1470 | 7.41M | } |
1471 | 6.46k | break; |
1472 | 0 | } |
1473 | 10.5k | case 16: |
1474 | 10.5k | { |
1475 | 10.5k | unsigned short |
1476 | 10.5k | pixel; |
1477 | | |
1478 | 10.5k | if (quantum_info->format == FloatingPointQuantumFormat) |
1479 | 6.99k | { |
1480 | 123k | for (x=0; x < (ssize_t) number_pixels; x++) |
1481 | 116k | { |
1482 | 116k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1483 | 116k | GetPixelRed(image,p)); |
1484 | 116k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1485 | 116k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1486 | 116k | GetPixelGreen(image,p)); |
1487 | 116k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1488 | 116k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1489 | 116k | GetPixelBlue(image,p)); |
1490 | 116k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1491 | 116k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1492 | 116k | GetPixelBlack(image,p)); |
1493 | 116k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1494 | 116k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1495 | 116k | GetPixelAlpha(image,p)); |
1496 | 116k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1497 | 116k | p+=(ptrdiff_t) GetPixelChannels(image); |
1498 | 116k | q+=(ptrdiff_t) quantum_info->pad; |
1499 | 116k | } |
1500 | 6.99k | break; |
1501 | 6.99k | } |
1502 | 134k | for (x=0; x < (ssize_t) number_pixels; x++) |
1503 | 131k | { |
1504 | 131k | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
1505 | 131k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1506 | 131k | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
1507 | 131k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1508 | 131k | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
1509 | 131k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1510 | 131k | pixel=ScaleQuantumToShort(GetPixelBlack(image,p)); |
1511 | 131k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1512 | 131k | pixel=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
1513 | 131k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1514 | 131k | p+=(ptrdiff_t) GetPixelChannels(image); |
1515 | 131k | q+=(ptrdiff_t) quantum_info->pad; |
1516 | 131k | } |
1517 | 3.53k | break; |
1518 | 10.5k | } |
1519 | 21.6k | case 32: |
1520 | 21.6k | { |
1521 | 21.6k | unsigned int |
1522 | 21.6k | pixel; |
1523 | | |
1524 | 21.6k | if (quantum_info->format == FloatingPointQuantumFormat) |
1525 | 2.47k | { |
1526 | 7.95k | for (x=0; x < (ssize_t) number_pixels; x++) |
1527 | 5.48k | { |
1528 | 5.48k | q=PopQuantumFloatPixel(quantum_info,(float) |
1529 | 5.48k | GetPixelRed(image,p),q); |
1530 | 5.48k | q=PopQuantumFloatPixel(quantum_info,(float) |
1531 | 5.48k | GetPixelGreen(image,p),q); |
1532 | 5.48k | q=PopQuantumFloatPixel(quantum_info,(float) |
1533 | 5.48k | GetPixelBlue(image,p),q); |
1534 | 5.48k | q=PopQuantumFloatPixel(quantum_info,(float) |
1535 | 5.48k | GetPixelBlack(image,p),q); |
1536 | 5.48k | q=PopQuantumFloatPixel(quantum_info,(float) |
1537 | 5.48k | GetPixelAlpha(image,p),q); |
1538 | 5.48k | p+=(ptrdiff_t) GetPixelChannels(image); |
1539 | 5.48k | q+=(ptrdiff_t) quantum_info->pad; |
1540 | 5.48k | } |
1541 | 2.47k | break; |
1542 | 2.47k | } |
1543 | 25.7M | for (x=0; x < (ssize_t) number_pixels; x++) |
1544 | 25.6M | { |
1545 | 25.6M | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
1546 | 25.6M | q=PopLongPixel(quantum_info->endian,pixel,q); |
1547 | 25.6M | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
1548 | 25.6M | q=PopLongPixel(quantum_info->endian,pixel,q); |
1549 | 25.6M | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
1550 | 25.6M | q=PopLongPixel(quantum_info->endian,pixel,q); |
1551 | 25.6M | pixel=ScaleQuantumToLong(GetPixelBlack(image,p)); |
1552 | 25.6M | q=PopLongPixel(quantum_info->endian,pixel,q); |
1553 | 25.6M | pixel=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
1554 | 25.6M | q=PopLongPixel(quantum_info->endian,pixel,q); |
1555 | 25.6M | p+=(ptrdiff_t) GetPixelChannels(image); |
1556 | 25.6M | q+=(ptrdiff_t) quantum_info->pad; |
1557 | 25.6M | } |
1558 | 19.1k | break; |
1559 | 21.6k | } |
1560 | 125 | case 64: |
1561 | 125 | { |
1562 | 125 | if (quantum_info->format == FloatingPointQuantumFormat) |
1563 | 74 | { |
1564 | 332 | for (x=0; x < (ssize_t) number_pixels; x++) |
1565 | 258 | { |
1566 | 258 | q=PopQuantumDoublePixel(quantum_info,(double) |
1567 | 258 | GetPixelRed(image,p),q); |
1568 | 258 | q=PopQuantumDoublePixel(quantum_info,(double) |
1569 | 258 | GetPixelGreen(image,p),q); |
1570 | 258 | q=PopQuantumDoublePixel(quantum_info,(double) |
1571 | 258 | GetPixelBlue(image,p),q); |
1572 | 258 | q=PopQuantumDoublePixel(quantum_info,(double) |
1573 | 258 | GetPixelBlack(image,p),q); |
1574 | 258 | q=PopQuantumDoublePixel(quantum_info,(double) |
1575 | 258 | GetPixelAlpha(image,p),q); |
1576 | 258 | p+=(ptrdiff_t) GetPixelChannels(image); |
1577 | 258 | q+=(ptrdiff_t) quantum_info->pad; |
1578 | 258 | } |
1579 | 74 | break; |
1580 | 74 | } |
1581 | 51 | magick_fallthrough; |
1582 | 51 | } |
1583 | 1.60k | default: |
1584 | 1.60k | { |
1585 | 1.60k | QuantumAny |
1586 | 1.60k | range; |
1587 | | |
1588 | 1.60k | range=GetQuantumRange(quantum_info->depth); |
1589 | 172k | for (x=0; x < (ssize_t) number_pixels; x++) |
1590 | 170k | { |
1591 | 170k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
1592 | 170k | range),q); |
1593 | 170k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
1594 | 170k | range),q); |
1595 | 170k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
1596 | 170k | range),q); |
1597 | 170k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p), |
1598 | 170k | range),q); |
1599 | 170k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p), |
1600 | 170k | range),q); |
1601 | 170k | p+=(ptrdiff_t) GetPixelChannels(image); |
1602 | 170k | q+=(ptrdiff_t) quantum_info->pad; |
1603 | 170k | } |
1604 | 1.60k | break; |
1605 | 51 | } |
1606 | 40.3k | } |
1607 | 40.3k | } |
1608 | | |
1609 | | static void ExportCMYKOQuantum(const Image *image,QuantumInfo *quantum_info, |
1610 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
1611 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
1612 | 0 | { |
1613 | 0 | ssize_t |
1614 | 0 | x; |
1615 | |
|
1616 | 0 | if (image->colorspace != CMYKColorspace) |
1617 | 0 | { |
1618 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1619 | 0 | "ColorSeparatedImageRequired","`%s'",image->filename); |
1620 | 0 | return; |
1621 | 0 | } |
1622 | 0 | switch (quantum_info->depth) |
1623 | 0 | { |
1624 | 0 | case 8: |
1625 | 0 | { |
1626 | 0 | unsigned char |
1627 | 0 | pixel; |
1628 | |
|
1629 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1630 | 0 | { |
1631 | 0 | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
1632 | 0 | q=PopCharPixel(pixel,q); |
1633 | 0 | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1634 | 0 | q=PopCharPixel(pixel,q); |
1635 | 0 | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1636 | 0 | q=PopCharPixel(pixel,q); |
1637 | 0 | pixel=ScaleQuantumToChar(GetPixelBlack(image,p)); |
1638 | 0 | q=PopCharPixel(pixel,q); |
1639 | 0 | pixel=ScaleQuantumToChar(GetPixelOpacity(image,p)); |
1640 | 0 | q=PopCharPixel(pixel,q); |
1641 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1642 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1643 | 0 | } |
1644 | 0 | break; |
1645 | 0 | } |
1646 | 0 | case 16: |
1647 | 0 | { |
1648 | 0 | unsigned short |
1649 | 0 | pixel; |
1650 | |
|
1651 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
1652 | 0 | { |
1653 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1654 | 0 | { |
1655 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1656 | 0 | GetPixelRed(image,p)); |
1657 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1658 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1659 | 0 | GetPixelGreen(image,p)); |
1660 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1661 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1662 | 0 | GetPixelBlue(image,p)); |
1663 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1664 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1665 | 0 | GetPixelBlack(image,p)); |
1666 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1667 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1668 | 0 | GetPixelOpacity(image,p)); |
1669 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1670 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1671 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1672 | 0 | } |
1673 | 0 | break; |
1674 | 0 | } |
1675 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1676 | 0 | { |
1677 | 0 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
1678 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1679 | 0 | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
1680 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1681 | 0 | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
1682 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1683 | 0 | pixel=ScaleQuantumToShort(GetPixelBlack(image,p)); |
1684 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1685 | 0 | pixel=ScaleQuantumToShort(GetPixelOpacity(image,p)); |
1686 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
1687 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1688 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1689 | 0 | } |
1690 | 0 | break; |
1691 | 0 | } |
1692 | 0 | case 32: |
1693 | 0 | { |
1694 | 0 | unsigned int |
1695 | 0 | pixel; |
1696 | |
|
1697 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
1698 | 0 | { |
1699 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1700 | 0 | { |
1701 | 0 | float |
1702 | 0 | float_pixel; |
1703 | |
|
1704 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q); |
1705 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p), |
1706 | 0 | q); |
1707 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p), |
1708 | 0 | q); |
1709 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlack(image,p), |
1710 | 0 | q); |
1711 | 0 | float_pixel=(float) (GetPixelOpacity(image,p)); |
1712 | 0 | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
1713 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1714 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1715 | 0 | } |
1716 | 0 | break; |
1717 | 0 | } |
1718 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1719 | 0 | { |
1720 | 0 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
1721 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1722 | 0 | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
1723 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1724 | 0 | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
1725 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1726 | 0 | pixel=ScaleQuantumToLong(GetPixelBlack(image,p)); |
1727 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1728 | 0 | pixel=ScaleQuantumToLong(GetPixelOpacity(image,p)); |
1729 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
1730 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1731 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1732 | 0 | } |
1733 | 0 | break; |
1734 | 0 | } |
1735 | 0 | case 64: |
1736 | 0 | { |
1737 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
1738 | 0 | { |
1739 | 0 | double |
1740 | 0 | pixel; |
1741 | |
|
1742 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1743 | 0 | { |
1744 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
1745 | 0 | GetPixelRed(image,p),q); |
1746 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
1747 | 0 | GetPixelGreen(image,p),q); |
1748 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
1749 | 0 | GetPixelBlue(image,p),q); |
1750 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
1751 | 0 | GetPixelBlack(image,p),q); |
1752 | 0 | pixel=(double) (GetPixelOpacity(image,p)); |
1753 | 0 | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
1754 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1755 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1756 | 0 | } |
1757 | 0 | break; |
1758 | 0 | } |
1759 | 0 | magick_fallthrough; |
1760 | 0 | } |
1761 | 0 | default: |
1762 | 0 | { |
1763 | 0 | QuantumAny |
1764 | 0 | range; |
1765 | |
|
1766 | 0 | range=GetQuantumRange(quantum_info->depth); |
1767 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
1768 | 0 | { |
1769 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
1770 | 0 | range),q); |
1771 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
1772 | 0 | range),q); |
1773 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
1774 | 0 | range),q); |
1775 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p), |
1776 | 0 | range),q); |
1777 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny( |
1778 | 0 | GetPixelOpacity(image,p),range),q); |
1779 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1780 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
1781 | 0 | } |
1782 | 0 | break; |
1783 | 0 | } |
1784 | 0 | } |
1785 | 0 | } |
1786 | | |
1787 | | static void ExportGrayQuantum(const Image *image,QuantumInfo *quantum_info, |
1788 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
1789 | | unsigned char *magick_restrict q) |
1790 | 752k | { |
1791 | 752k | QuantumAny |
1792 | 752k | range; |
1793 | | |
1794 | 752k | ssize_t |
1795 | 752k | x; |
1796 | | |
1797 | 752k | switch (quantum_info->depth) |
1798 | 752k | { |
1799 | 429k | case 1: |
1800 | 429k | { |
1801 | 429k | double |
1802 | 429k | threshold; |
1803 | | |
1804 | 429k | unsigned char |
1805 | 429k | black, |
1806 | 429k | white; |
1807 | | |
1808 | 429k | ssize_t |
1809 | 429k | bit; |
1810 | | |
1811 | 429k | black=0x00; |
1812 | 429k | white=0x01; |
1813 | 429k | if (quantum_info->min_is_white != MagickFalse) |
1814 | 14.5k | { |
1815 | 14.5k | black=0x01; |
1816 | 14.5k | white=0x00; |
1817 | 14.5k | } |
1818 | 429k | threshold=(double) QuantumRange/2.0; |
1819 | 37.8M | for (x=((ssize_t) number_pixels-7); x > 0; x-=8) |
1820 | 37.4M | { |
1821 | 37.4M | *q='\0'; |
1822 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 7; |
1823 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1824 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 6; |
1825 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1826 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 5; |
1827 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1828 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 4; |
1829 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1830 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 3; |
1831 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1832 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 2; |
1833 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1834 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 1; |
1835 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1836 | 37.4M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 0; |
1837 | 37.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
1838 | 37.4M | q++; |
1839 | 37.4M | } |
1840 | 429k | if ((number_pixels % 8) != 0) |
1841 | 314k | { |
1842 | 314k | *q='\0'; |
1843 | 1.68M | for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--) |
1844 | 1.36M | { |
1845 | 1.36M | *q|=(GetPixelLuma(image,p) < threshold ? black : white) << bit; |
1846 | 1.36M | p+=(ptrdiff_t) GetPixelChannels(image); |
1847 | 1.36M | } |
1848 | 314k | q++; |
1849 | 314k | } |
1850 | 429k | break; |
1851 | 0 | } |
1852 | 8.58k | case 4: |
1853 | 8.58k | { |
1854 | 8.58k | unsigned char |
1855 | 8.58k | pixel; |
1856 | | |
1857 | 48.0k | for (x=0; x < ((ssize_t) number_pixels-1) ; x+=2) |
1858 | 39.4k | { |
1859 | 39.4k | pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
1860 | 39.4k | *q=(((pixel >> 4) & 0xf) << 4); |
1861 | 39.4k | p+=(ptrdiff_t) GetPixelChannels(image); |
1862 | 39.4k | pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
1863 | 39.4k | *q|=pixel >> 4; |
1864 | 39.4k | p+=(ptrdiff_t) GetPixelChannels(image); |
1865 | 39.4k | q++; |
1866 | 39.4k | } |
1867 | 8.58k | if ((number_pixels % 2) != 0) |
1868 | 5.61k | { |
1869 | 5.61k | pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
1870 | 5.61k | *q=(((pixel >> 4) & 0xf) << 4); |
1871 | 5.61k | p+=(ptrdiff_t) GetPixelChannels(image); |
1872 | 5.61k | q++; |
1873 | 5.61k | } |
1874 | 8.58k | break; |
1875 | 0 | } |
1876 | 248k | case 8: |
1877 | 248k | { |
1878 | 248k | unsigned char |
1879 | 248k | pixel; |
1880 | | |
1881 | 33.8M | for (x=0; x < (ssize_t) number_pixels; x++) |
1882 | 33.5M | { |
1883 | 33.5M | pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
1884 | 33.5M | q=PopCharPixel(pixel,q); |
1885 | 33.5M | p+=(ptrdiff_t) GetPixelChannels(image); |
1886 | 33.5M | q+=(ptrdiff_t) quantum_info->pad; |
1887 | 33.5M | } |
1888 | 248k | break; |
1889 | 0 | } |
1890 | 2.94k | case 10: |
1891 | 2.94k | { |
1892 | 2.94k | range=GetQuantumRange(quantum_info->depth); |
1893 | 2.94k | if (quantum_info->pack == MagickFalse) |
1894 | 1.55k | { |
1895 | 1.55k | unsigned int |
1896 | 1.55k | pixel; |
1897 | | |
1898 | 6.46k | for (x=0; x < ((ssize_t) number_pixels-2); x+=3) |
1899 | 4.90k | { |
1900 | 4.90k | pixel=(unsigned int) (ScaleQuantumToAny(ClampToQuantum( |
1901 | 4.90k | GetPixelLuma(image,p+2*GetPixelChannels(image))),range) << 22 | |
1902 | 4.90k | ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p+ |
1903 | 4.90k | GetPixelChannels(image))),range) << 12 | ScaleQuantumToAny( |
1904 | 4.90k | ClampToQuantum(GetPixelLuma(image,p)),range) << 2); |
1905 | 4.90k | q=PopLongPixel(quantum_info->endian,pixel,q); |
1906 | 4.90k | p+=(ptrdiff_t) 3*GetPixelChannels(image); |
1907 | 4.90k | q+=(ptrdiff_t) quantum_info->pad; |
1908 | 4.90k | } |
1909 | 1.55k | if (x < (ssize_t) number_pixels) |
1910 | 1.27k | { |
1911 | 1.27k | pixel=0U; |
1912 | 1.27k | if (x++ < ((ssize_t) number_pixels-1)) |
1913 | 819 | pixel|=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p+ |
1914 | 819 | GetPixelChannels(image))),range) << 12; |
1915 | 1.27k | if (x++ < (ssize_t) number_pixels) |
1916 | 819 | pixel|=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p)), |
1917 | 819 | range) << 2; |
1918 | 1.27k | q=PopLongPixel(quantum_info->endian,pixel,q); |
1919 | 1.27k | } |
1920 | 1.55k | break; |
1921 | 1.55k | } |
1922 | 14.6k | for (x=0; x < (ssize_t) number_pixels; x++) |
1923 | 13.2k | { |
1924 | 13.2k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum( |
1925 | 13.2k | GetPixelLuma(image,p)),range),q); |
1926 | 13.2k | p+=(ptrdiff_t) GetPixelChannels(image); |
1927 | 13.2k | q+=(ptrdiff_t) quantum_info->pad; |
1928 | 13.2k | } |
1929 | 1.38k | break; |
1930 | 2.94k | } |
1931 | 4.38k | case 12: |
1932 | 4.38k | { |
1933 | 4.38k | unsigned short |
1934 | 4.38k | pixel; |
1935 | | |
1936 | 4.38k | range=GetQuantumRange(quantum_info->depth); |
1937 | 4.38k | if (quantum_info->pack == MagickFalse) |
1938 | 2.96k | { |
1939 | 15.1k | for (x=0; x < (ssize_t) number_pixels; x++) |
1940 | 12.2k | { |
1941 | 12.2k | pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p))); |
1942 | 12.2k | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel >> 4), |
1943 | 12.2k | q); |
1944 | 12.2k | p+=(ptrdiff_t) GetPixelChannels(image); |
1945 | 12.2k | q+=(ptrdiff_t) quantum_info->pad; |
1946 | 12.2k | } |
1947 | 2.96k | break; |
1948 | 2.96k | } |
1949 | 79.4k | for (x=0; x < (ssize_t) number_pixels; x++) |
1950 | 78.0k | { |
1951 | 78.0k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum( |
1952 | 78.0k | GetPixelLuma(image,p)),range),q); |
1953 | 78.0k | p+=(ptrdiff_t) GetPixelChannels(image); |
1954 | 78.0k | q+=(ptrdiff_t) quantum_info->pad; |
1955 | 78.0k | } |
1956 | 1.42k | break; |
1957 | 4.38k | } |
1958 | 24.9k | case 16: |
1959 | 24.9k | { |
1960 | 24.9k | unsigned short |
1961 | 24.9k | pixel; |
1962 | | |
1963 | 24.9k | if (quantum_info->format == FloatingPointQuantumFormat) |
1964 | 4.70k | { |
1965 | 167k | for (x=0; x < (ssize_t) number_pixels; x++) |
1966 | 162k | { |
1967 | 162k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
1968 | 162k | GetPixelLuma(image,p)); |
1969 | 162k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1970 | 162k | p+=(ptrdiff_t) GetPixelChannels(image); |
1971 | 162k | q+=(ptrdiff_t) quantum_info->pad; |
1972 | 162k | } |
1973 | 4.70k | break; |
1974 | 4.70k | } |
1975 | 880k | for (x=0; x < (ssize_t) number_pixels; x++) |
1976 | 860k | { |
1977 | 860k | pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p))); |
1978 | 860k | q=PopShortPixel(quantum_info->endian,pixel,q); |
1979 | 860k | p+=(ptrdiff_t) GetPixelChannels(image); |
1980 | 860k | q+=(ptrdiff_t) quantum_info->pad; |
1981 | 860k | } |
1982 | 20.2k | break; |
1983 | 24.9k | } |
1984 | 19.9k | case 32: |
1985 | 19.9k | { |
1986 | 19.9k | unsigned int |
1987 | 19.9k | pixel; |
1988 | | |
1989 | 19.9k | if (quantum_info->format == FloatingPointQuantumFormat) |
1990 | 14.4k | { |
1991 | 64.5k | for (x=0; x < (ssize_t) number_pixels; x++) |
1992 | 50.1k | { |
1993 | 50.1k | float |
1994 | 50.1k | float_pixel; |
1995 | | |
1996 | 50.1k | float_pixel=(float) GetPixelLuma(image,p); |
1997 | 50.1k | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
1998 | 50.1k | p+=(ptrdiff_t) GetPixelChannels(image); |
1999 | 50.1k | q+=(ptrdiff_t) quantum_info->pad; |
2000 | 50.1k | } |
2001 | 14.4k | break; |
2002 | 14.4k | } |
2003 | 43.9k | for (x=0; x < (ssize_t) number_pixels; x++) |
2004 | 38.3k | { |
2005 | 38.3k | pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p))); |
2006 | 38.3k | q=PopLongPixel(quantum_info->endian,pixel,q); |
2007 | 38.3k | p+=(ptrdiff_t) GetPixelChannels(image); |
2008 | 38.3k | q+=(ptrdiff_t) quantum_info->pad; |
2009 | 38.3k | } |
2010 | 5.59k | break; |
2011 | 19.9k | } |
2012 | 2.27k | case 64: |
2013 | 2.27k | { |
2014 | 2.27k | if (quantum_info->format == FloatingPointQuantumFormat) |
2015 | 222 | { |
2016 | 1.47k | for (x=0; x < (ssize_t) number_pixels; x++) |
2017 | 1.24k | { |
2018 | 1.24k | double |
2019 | 1.24k | pixel; |
2020 | | |
2021 | 1.24k | pixel=GetPixelLuma(image,p); |
2022 | 1.24k | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
2023 | 1.24k | p+=(ptrdiff_t) GetPixelChannels(image); |
2024 | 1.24k | q+=(ptrdiff_t) quantum_info->pad; |
2025 | 1.24k | } |
2026 | 222 | break; |
2027 | 222 | } |
2028 | 2.05k | magick_fallthrough; |
2029 | 2.05k | } |
2030 | 12.8k | default: |
2031 | 12.8k | { |
2032 | 12.8k | range=GetQuantumRange(quantum_info->depth); |
2033 | 205k | for (x=0; x < (ssize_t) number_pixels; x++) |
2034 | 193k | { |
2035 | 193k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum( |
2036 | 193k | GetPixelLuma(image,p)),range),q); |
2037 | 193k | p+=(ptrdiff_t) GetPixelChannels(image); |
2038 | 193k | q+=(ptrdiff_t) quantum_info->pad; |
2039 | 193k | } |
2040 | 12.8k | break; |
2041 | 2.05k | } |
2042 | 752k | } |
2043 | 752k | } |
2044 | | |
2045 | | static void ExportGrayAlphaQuantum(const Image *image,QuantumInfo *quantum_info, |
2046 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
2047 | | unsigned char *magick_restrict q) |
2048 | 26.5k | { |
2049 | 26.5k | QuantumAny |
2050 | 26.5k | range; |
2051 | | |
2052 | 26.5k | ssize_t |
2053 | 26.5k | x; |
2054 | | |
2055 | 26.5k | switch (quantum_info->depth) |
2056 | 26.5k | { |
2057 | 2.39k | case 1: |
2058 | 2.39k | { |
2059 | 2.39k | double |
2060 | 2.39k | threshold; |
2061 | | |
2062 | 2.39k | unsigned char |
2063 | 2.39k | black, |
2064 | 2.39k | pixel, |
2065 | 2.39k | white; |
2066 | | |
2067 | 2.39k | ssize_t |
2068 | 2.39k | bit; |
2069 | | |
2070 | 2.39k | black=0x00; |
2071 | 2.39k | white=0x01; |
2072 | 2.39k | if (quantum_info->min_is_white != MagickFalse) |
2073 | 0 | { |
2074 | 0 | black=0x01; |
2075 | 0 | white=0x00; |
2076 | 0 | } |
2077 | 2.39k | threshold=(double) QuantumRange/2.0; |
2078 | 8.23k | for (x=((ssize_t) number_pixels-3); x > 0; x-=4) |
2079 | 5.84k | { |
2080 | 5.84k | *q='\0'; |
2081 | 5.84k | *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 7; |
2082 | 5.84k | pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ? |
2083 | 3.04k | 0x00 : 0x01); |
2084 | 5.84k | *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6); |
2085 | 5.84k | p+=(ptrdiff_t) GetPixelChannels(image); |
2086 | 5.84k | *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 5; |
2087 | 5.84k | pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ? |
2088 | 3.01k | 0x00 : 0x01); |
2089 | 5.84k | *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4); |
2090 | 5.84k | p+=(ptrdiff_t) GetPixelChannels(image); |
2091 | 5.84k | *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 3; |
2092 | 5.84k | pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ? |
2093 | 3.12k | 0x00 : 0x01); |
2094 | 5.84k | *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2); |
2095 | 5.84k | p+=(ptrdiff_t) GetPixelChannels(image); |
2096 | 5.84k | *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 1; |
2097 | 5.84k | pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ? |
2098 | 2.97k | 0x00 : 0x01); |
2099 | 5.84k | *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0); |
2100 | 5.84k | p+=(ptrdiff_t) GetPixelChannels(image); |
2101 | 5.84k | q++; |
2102 | 5.84k | } |
2103 | 2.39k | if ((number_pixels % 4) != 0) |
2104 | 1.73k | { |
2105 | 1.73k | *q='\0'; |
2106 | 4.19k | for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2) |
2107 | 2.46k | { |
2108 | 2.46k | *q|=(GetPixelLuma(image,p) > threshold ? black : white) << |
2109 | 2.46k | (7-bit); |
2110 | 2.46k | pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ? |
2111 | 1.67k | 0x00 : 0x01); |
2112 | 2.46k | *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char) |
2113 | 2.46k | (7-bit-1)); |
2114 | 2.46k | p+=(ptrdiff_t) GetPixelChannels(image); |
2115 | 2.46k | } |
2116 | 1.73k | q++; |
2117 | 1.73k | } |
2118 | 2.39k | break; |
2119 | 0 | } |
2120 | 1.71k | case 4: |
2121 | 1.71k | { |
2122 | 1.71k | unsigned char |
2123 | 1.71k | pixel; |
2124 | | |
2125 | 5.58k | for (x=0; x < (ssize_t) number_pixels ; x++) |
2126 | 3.87k | { |
2127 | 3.87k | pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
2128 | 3.87k | *q=(((pixel >> 4) & 0xf) << 4); |
2129 | 3.87k | pixel=(unsigned char) (16.0*QuantumScale*(double) |
2130 | 3.87k | GetPixelAlpha(image,p)+0.5); |
2131 | 3.87k | *q|=pixel & 0xf; |
2132 | 3.87k | p+=(ptrdiff_t) GetPixelChannels(image); |
2133 | 3.87k | q++; |
2134 | 3.87k | } |
2135 | 1.71k | break; |
2136 | 0 | } |
2137 | 2.59k | case 8: |
2138 | 2.59k | { |
2139 | 2.59k | unsigned char |
2140 | 2.59k | pixel; |
2141 | | |
2142 | 172k | for (x=0; x < (ssize_t) number_pixels; x++) |
2143 | 169k | { |
2144 | 169k | pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p))); |
2145 | 169k | q=PopCharPixel(pixel,q); |
2146 | 169k | pixel=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
2147 | 169k | q=PopCharPixel(pixel,q); |
2148 | 169k | p+=(ptrdiff_t) GetPixelChannels(image); |
2149 | 169k | q+=(ptrdiff_t) quantum_info->pad; |
2150 | 169k | } |
2151 | 2.59k | break; |
2152 | 0 | } |
2153 | 10.9k | case 16: |
2154 | 10.9k | { |
2155 | 10.9k | unsigned short |
2156 | 10.9k | pixel; |
2157 | | |
2158 | 10.9k | if (quantum_info->format == FloatingPointQuantumFormat) |
2159 | 4.86k | { |
2160 | 175k | for (x=0; x < (ssize_t) number_pixels; x++) |
2161 | 171k | { |
2162 | 171k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
2163 | 171k | GetPixelLuma(image,p)); |
2164 | 171k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2165 | 171k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
2166 | 171k | GetPixelAlpha(image,p)); |
2167 | 171k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2168 | 171k | p+=(ptrdiff_t) GetPixelChannels(image); |
2169 | 171k | q+=(ptrdiff_t) quantum_info->pad; |
2170 | 171k | } |
2171 | 4.86k | break; |
2172 | 4.86k | } |
2173 | 38.5k | for (x=0; x < (ssize_t) number_pixels; x++) |
2174 | 32.3k | { |
2175 | 32.3k | pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p))); |
2176 | 32.3k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2177 | 32.3k | pixel=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
2178 | 32.3k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2179 | 32.3k | p+=(ptrdiff_t) GetPixelChannels(image); |
2180 | 32.3k | q+=(ptrdiff_t) quantum_info->pad; |
2181 | 32.3k | } |
2182 | 6.12k | break; |
2183 | 10.9k | } |
2184 | 7.11k | case 32: |
2185 | 7.11k | { |
2186 | 7.11k | unsigned int |
2187 | 7.11k | pixel; |
2188 | | |
2189 | 7.11k | if (quantum_info->format == FloatingPointQuantumFormat) |
2190 | 4.46k | { |
2191 | 23.8k | for (x=0; x < (ssize_t) number_pixels; x++) |
2192 | 19.3k | { |
2193 | 19.3k | float |
2194 | 19.3k | float_pixel; |
2195 | | |
2196 | 19.3k | float_pixel=(float) GetPixelLuma(image,p); |
2197 | 19.3k | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
2198 | 19.3k | float_pixel=(float) (GetPixelAlpha(image,p)); |
2199 | 19.3k | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
2200 | 19.3k | p+=(ptrdiff_t) GetPixelChannels(image); |
2201 | 19.3k | q+=(ptrdiff_t) quantum_info->pad; |
2202 | 19.3k | } |
2203 | 4.46k | break; |
2204 | 4.46k | } |
2205 | 26.8k | for (x=0; x < (ssize_t) number_pixels; x++) |
2206 | 24.1k | { |
2207 | 24.1k | pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p))); |
2208 | 24.1k | q=PopLongPixel(quantum_info->endian,pixel,q); |
2209 | 24.1k | pixel=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
2210 | 24.1k | q=PopLongPixel(quantum_info->endian,pixel,q); |
2211 | 24.1k | p+=(ptrdiff_t) GetPixelChannels(image); |
2212 | 24.1k | q+=(ptrdiff_t) quantum_info->pad; |
2213 | 24.1k | } |
2214 | 2.65k | break; |
2215 | 7.11k | } |
2216 | 771 | case 64: |
2217 | 771 | { |
2218 | 771 | if (quantum_info->format == FloatingPointQuantumFormat) |
2219 | 305 | { |
2220 | 1.37k | for (x=0; x < (ssize_t) number_pixels; x++) |
2221 | 1.07k | { |
2222 | 1.07k | double |
2223 | 1.07k | pixel; |
2224 | | |
2225 | 1.07k | pixel=GetPixelLuma(image,p); |
2226 | 1.07k | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
2227 | 1.07k | pixel=(double) (GetPixelAlpha(image,p)); |
2228 | 1.07k | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
2229 | 1.07k | p+=(ptrdiff_t) GetPixelChannels(image); |
2230 | 1.07k | q+=(ptrdiff_t) quantum_info->pad; |
2231 | 1.07k | } |
2232 | 305 | break; |
2233 | 305 | } |
2234 | 466 | magick_fallthrough; |
2235 | 466 | } |
2236 | 1.40k | default: |
2237 | 1.40k | { |
2238 | 1.40k | range=GetQuantumRange(quantum_info->depth); |
2239 | 9.12k | for (x=0; x < (ssize_t) number_pixels; x++) |
2240 | 7.72k | { |
2241 | 7.72k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum( |
2242 | 7.72k | GetPixelLuma(image,p)),range),q); |
2243 | 7.72k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p), |
2244 | 7.72k | range),q); |
2245 | 7.72k | p+=(ptrdiff_t) GetPixelChannels(image); |
2246 | 7.72k | q+=(ptrdiff_t) quantum_info->pad; |
2247 | 7.72k | } |
2248 | 1.40k | break; |
2249 | 466 | } |
2250 | 26.5k | } |
2251 | 26.5k | } |
2252 | | |
2253 | | static void ExportIndexQuantum(const Image *image,QuantumInfo *quantum_info, |
2254 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
2255 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
2256 | 68.1k | { |
2257 | 68.1k | ssize_t |
2258 | 68.1k | x; |
2259 | | |
2260 | 68.1k | ssize_t |
2261 | 68.1k | bit; |
2262 | | |
2263 | 68.1k | if (image->storage_class != PseudoClass) |
2264 | 0 | { |
2265 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
2266 | 0 | "ColormappedImageRequired","`%s'",image->filename); |
2267 | 0 | return; |
2268 | 0 | } |
2269 | 68.1k | switch (quantum_info->depth) |
2270 | 68.1k | { |
2271 | 656 | case 1: |
2272 | 656 | { |
2273 | 656 | unsigned char |
2274 | 656 | pixel; |
2275 | | |
2276 | 1.39k | for (x=((ssize_t) number_pixels-7); x > 0; x-=8) |
2277 | 740 | { |
2278 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2279 | 740 | *q=((pixel & 0x01) << 7); |
2280 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2281 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2282 | 740 | *q|=((pixel & 0x01) << 6); |
2283 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2284 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2285 | 740 | *q|=((pixel & 0x01) << 5); |
2286 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2287 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2288 | 740 | *q|=((pixel & 0x01) << 4); |
2289 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2290 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2291 | 740 | *q|=((pixel & 0x01) << 3); |
2292 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2293 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2294 | 740 | *q|=((pixel & 0x01) << 2); |
2295 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2296 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2297 | 740 | *q|=((pixel & 0x01) << 1); |
2298 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2299 | 740 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2300 | 740 | *q|=((pixel & 0x01) << 0); |
2301 | 740 | p+=(ptrdiff_t) GetPixelChannels(image); |
2302 | 740 | q++; |
2303 | 740 | } |
2304 | 656 | if ((number_pixels % 8) != 0) |
2305 | 354 | { |
2306 | 354 | *q='\0'; |
2307 | 980 | for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--) |
2308 | 626 | { |
2309 | 626 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2310 | 626 | *q|=((pixel & 0x01) << (unsigned char) bit); |
2311 | 626 | p+=(ptrdiff_t) GetPixelChannels(image); |
2312 | 626 | } |
2313 | 354 | q++; |
2314 | 354 | } |
2315 | 656 | break; |
2316 | 0 | } |
2317 | 9.68k | case 4: |
2318 | 9.68k | { |
2319 | 9.68k | unsigned char |
2320 | 9.68k | pixel; |
2321 | | |
2322 | 1.05M | for (x=0; x < ((ssize_t) number_pixels-1) ; x+=2) |
2323 | 1.04M | { |
2324 | 1.04M | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2325 | 1.04M | *q=((pixel & 0xf) << 4); |
2326 | 1.04M | p+=(ptrdiff_t) GetPixelChannels(image); |
2327 | 1.04M | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2328 | 1.04M | *q|=((pixel & 0xf) << 0); |
2329 | 1.04M | p+=(ptrdiff_t) GetPixelChannels(image); |
2330 | 1.04M | q++; |
2331 | 1.04M | } |
2332 | 9.68k | if ((number_pixels % 2) != 0) |
2333 | 8.80k | { |
2334 | 8.80k | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2335 | 8.80k | *q=((pixel & 0xf) << 4); |
2336 | 8.80k | p+=(ptrdiff_t) GetPixelChannels(image); |
2337 | 8.80k | q++; |
2338 | 8.80k | } |
2339 | 9.68k | break; |
2340 | 0 | } |
2341 | 55.0k | case 8: |
2342 | 55.0k | { |
2343 | 12.5M | for (x=0; x < (ssize_t) number_pixels; x++) |
2344 | 12.4M | { |
2345 | 12.4M | q=PopCharPixel((unsigned char) ((ssize_t) GetPixelIndex(image,p)),q); |
2346 | 12.4M | p+=(ptrdiff_t) GetPixelChannels(image); |
2347 | 12.4M | q+=(ptrdiff_t) quantum_info->pad; |
2348 | 12.4M | } |
2349 | 55.0k | break; |
2350 | 0 | } |
2351 | 907 | case 16: |
2352 | 907 | { |
2353 | 907 | if (quantum_info->format == FloatingPointQuantumFormat) |
2354 | 0 | { |
2355 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2356 | 0 | { |
2357 | 0 | q=PopShortPixel(quantum_info->endian,SinglePrecisionToHalf( |
2358 | 0 | QuantumScale*(double) GetPixelIndex(image,p)),q); |
2359 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2360 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2361 | 0 | } |
2362 | 0 | break; |
2363 | 0 | } |
2364 | 4.65k | for (x=0; x < (ssize_t) number_pixels; x++) |
2365 | 3.75k | { |
2366 | 3.75k | q=PopShortPixel(quantum_info->endian,(unsigned short) |
2367 | 3.75k | GetPixelIndex(image,p),q); |
2368 | 3.75k | p+=(ptrdiff_t) GetPixelChannels(image); |
2369 | 3.75k | q+=(ptrdiff_t) quantum_info->pad; |
2370 | 3.75k | } |
2371 | 907 | break; |
2372 | 907 | } |
2373 | 1.39k | case 32: |
2374 | 1.39k | { |
2375 | 1.39k | if (quantum_info->format == FloatingPointQuantumFormat) |
2376 | 0 | { |
2377 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2378 | 0 | { |
2379 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelIndex(image,p),q); |
2380 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2381 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2382 | 0 | } |
2383 | 0 | break; |
2384 | 0 | } |
2385 | 46.5k | for (x=0; x < (ssize_t) number_pixels; x++) |
2386 | 45.1k | { |
2387 | 45.1k | q=PopLongPixel(quantum_info->endian,(unsigned int) |
2388 | 45.1k | GetPixelIndex(image,p),q); |
2389 | 45.1k | p+=(ptrdiff_t) GetPixelChannels(image); |
2390 | 45.1k | q+=(ptrdiff_t) quantum_info->pad; |
2391 | 45.1k | } |
2392 | 1.39k | break; |
2393 | 1.39k | } |
2394 | 0 | case 64: |
2395 | 0 | { |
2396 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
2397 | 0 | { |
2398 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2399 | 0 | { |
2400 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelIndex(image,p),q); |
2401 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2402 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2403 | 0 | } |
2404 | 0 | break; |
2405 | 0 | } |
2406 | 0 | magick_fallthrough; |
2407 | 0 | } |
2408 | 440 | default: |
2409 | 440 | { |
2410 | 4.66k | for (x=0; x < (ssize_t) number_pixels; x++) |
2411 | 4.22k | { |
2412 | 4.22k | q=PopQuantumPixel(quantum_info,(QuantumAny) GetPixelIndex(image,p),q); |
2413 | 4.22k | p+=(ptrdiff_t) GetPixelChannels(image); |
2414 | 4.22k | q+=(ptrdiff_t) quantum_info->pad; |
2415 | 4.22k | } |
2416 | 440 | break; |
2417 | 0 | } |
2418 | 68.1k | } |
2419 | 68.1k | } |
2420 | | |
2421 | | static void ExportIndexAlphaQuantum(const Image *image, |
2422 | | QuantumInfo *quantum_info,const MagickSizeType number_pixels, |
2423 | | const Quantum *magick_restrict p,unsigned char *magick_restrict q, |
2424 | | ExceptionInfo *exception) |
2425 | 3.57k | { |
2426 | 3.57k | ssize_t |
2427 | 3.57k | x; |
2428 | | |
2429 | 3.57k | ssize_t |
2430 | 3.57k | bit; |
2431 | | |
2432 | 3.57k | if (image->storage_class != PseudoClass) |
2433 | 0 | { |
2434 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
2435 | 0 | "ColormappedImageRequired","`%s'",image->filename); |
2436 | 0 | return; |
2437 | 0 | } |
2438 | 3.57k | switch (quantum_info->depth) |
2439 | 3.57k | { |
2440 | 0 | case 1: |
2441 | 0 | { |
2442 | 0 | unsigned char |
2443 | 0 | pixel; |
2444 | |
|
2445 | 0 | for (x=((ssize_t) number_pixels-3); x > 0; x-=4) |
2446 | 0 | { |
2447 | 0 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2448 | 0 | *q=((pixel & 0x01) << 7); |
2449 | 0 | pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum) |
2450 | 0 | TransparentAlpha ? 1 : 0); |
2451 | 0 | *q|=((pixel & 0x01) << 6); |
2452 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2453 | 0 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2454 | 0 | *q|=((pixel & 0x01) << 5); |
2455 | 0 | pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum) |
2456 | 0 | TransparentAlpha ? 1 : 0); |
2457 | 0 | *q|=((pixel & 0x01) << 4); |
2458 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2459 | 0 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2460 | 0 | *q|=((pixel & 0x01) << 3); |
2461 | 0 | pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum) |
2462 | 0 | TransparentAlpha ? 1 : 0); |
2463 | 0 | *q|=((pixel & 0x01) << 2); |
2464 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2465 | 0 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2466 | 0 | *q|=((pixel & 0x01) << 1); |
2467 | 0 | pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum) |
2468 | 0 | TransparentAlpha ? 1 : 0); |
2469 | 0 | *q|=((pixel & 0x01) << 0); |
2470 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2471 | 0 | q++; |
2472 | 0 | } |
2473 | 0 | if ((number_pixels % 4) != 0) |
2474 | 0 | { |
2475 | 0 | *q='\0'; |
2476 | 0 | for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2) |
2477 | 0 | { |
2478 | 0 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2479 | 0 | *q|=((pixel & 0x01) << (unsigned char) (bit+4)); |
2480 | 0 | pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum) |
2481 | 0 | TransparentAlpha ? 1 : 0); |
2482 | 0 | *q|=((pixel & 0x01) << (unsigned char) (bit+4-1)); |
2483 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2484 | 0 | } |
2485 | 0 | q++; |
2486 | 0 | } |
2487 | 0 | break; |
2488 | 0 | } |
2489 | 0 | case 4: |
2490 | 0 | { |
2491 | 0 | unsigned char |
2492 | 0 | pixel; |
2493 | |
|
2494 | 0 | for (x=0; x < (ssize_t) number_pixels ; x++) |
2495 | 0 | { |
2496 | 0 | pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p)); |
2497 | 0 | *q=((pixel & 0xf) << 4); |
2498 | 0 | pixel=(unsigned char) (16.0*QuantumScale*(double) |
2499 | 0 | GetPixelAlpha(image,p)+0.5); |
2500 | 0 | *q|=((pixel & 0xf) << 0); |
2501 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2502 | 0 | q++; |
2503 | 0 | } |
2504 | 0 | break; |
2505 | 0 | } |
2506 | 716 | case 8: |
2507 | 716 | { |
2508 | 716 | unsigned char |
2509 | 716 | pixel; |
2510 | | |
2511 | 6.64k | for (x=0; x < (ssize_t) number_pixels; x++) |
2512 | 5.92k | { |
2513 | 5.92k | q=PopCharPixel((unsigned char) ((ssize_t) GetPixelIndex(image,p)),q); |
2514 | 5.92k | pixel=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
2515 | 5.92k | q=PopCharPixel(pixel,q); |
2516 | 5.92k | p+=(ptrdiff_t) GetPixelChannels(image); |
2517 | 5.92k | q+=(ptrdiff_t) quantum_info->pad; |
2518 | 5.92k | } |
2519 | 716 | break; |
2520 | 0 | } |
2521 | 1.24k | case 16: |
2522 | 1.24k | { |
2523 | 1.24k | unsigned short |
2524 | 1.24k | pixel; |
2525 | | |
2526 | 1.24k | if (quantum_info->format == FloatingPointQuantumFormat) |
2527 | 0 | { |
2528 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2529 | 0 | { |
2530 | 0 | q=PopShortPixel(quantum_info->endian,(unsigned short) |
2531 | 0 | ((ssize_t) GetPixelIndex(image,p)),q); |
2532 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
2533 | 0 | GetPixelAlpha(image,p)); |
2534 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
2535 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2536 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2537 | 0 | } |
2538 | 0 | break; |
2539 | 0 | } |
2540 | 4.00k | for (x=0; x < (ssize_t) number_pixels; x++) |
2541 | 2.75k | { |
2542 | 2.75k | q=PopShortPixel(quantum_info->endian,(unsigned short) |
2543 | 2.75k | ((ssize_t) GetPixelIndex(image,p)),q); |
2544 | 2.75k | pixel=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
2545 | 2.75k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2546 | 2.75k | p+=(ptrdiff_t) GetPixelChannels(image); |
2547 | 2.75k | q+=(ptrdiff_t) quantum_info->pad; |
2548 | 2.75k | } |
2549 | 1.24k | break; |
2550 | 1.24k | } |
2551 | 1.61k | case 32: |
2552 | 1.61k | { |
2553 | 1.61k | unsigned int |
2554 | 1.61k | pixel; |
2555 | | |
2556 | 1.61k | if (quantum_info->format == FloatingPointQuantumFormat) |
2557 | 0 | { |
2558 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2559 | 0 | { |
2560 | 0 | float |
2561 | 0 | float_pixel; |
2562 | |
|
2563 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelIndex(image,p),q); |
2564 | 0 | float_pixel=(float) GetPixelAlpha(image,p); |
2565 | 0 | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
2566 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2567 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2568 | 0 | } |
2569 | 0 | break; |
2570 | 0 | } |
2571 | 8.47k | for (x=0; x < (ssize_t) number_pixels; x++) |
2572 | 6.86k | { |
2573 | 6.86k | q=PopLongPixel(quantum_info->endian,(unsigned int) |
2574 | 6.86k | GetPixelIndex(image,p),q); |
2575 | 6.86k | pixel=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
2576 | 6.86k | q=PopLongPixel(quantum_info->endian,pixel,q); |
2577 | 6.86k | p+=(ptrdiff_t) GetPixelChannels(image); |
2578 | 6.86k | q+=(ptrdiff_t) quantum_info->pad; |
2579 | 6.86k | } |
2580 | 1.61k | break; |
2581 | 1.61k | } |
2582 | 0 | case 64: |
2583 | 0 | { |
2584 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
2585 | 0 | { |
2586 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2587 | 0 | { |
2588 | 0 | double |
2589 | 0 | pixel; |
2590 | |
|
2591 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelIndex(image,p),q); |
2592 | 0 | pixel=(double) GetPixelAlpha(image,p); |
2593 | 0 | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
2594 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2595 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2596 | 0 | } |
2597 | 0 | break; |
2598 | 0 | } |
2599 | 0 | magick_fallthrough; |
2600 | 0 | } |
2601 | 0 | default: |
2602 | 0 | { |
2603 | 0 | QuantumAny |
2604 | 0 | range; |
2605 | |
|
2606 | 0 | range=GetQuantumRange(quantum_info->depth); |
2607 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2608 | 0 | { |
2609 | 0 | q=PopQuantumPixel(quantum_info,(QuantumAny) GetPixelIndex(image,p),q); |
2610 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p), |
2611 | 0 | range),q); |
2612 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2613 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2614 | 0 | } |
2615 | 0 | break; |
2616 | 0 | } |
2617 | 3.57k | } |
2618 | 3.57k | } |
2619 | | |
2620 | | static void ExportMultispectralQuantum(const Image *image, |
2621 | | QuantumInfo *quantum_info,const MagickSizeType number_pixels, |
2622 | | const Quantum *magick_restrict p,unsigned char *magick_restrict q, |
2623 | | ExceptionInfo *exception) |
2624 | 130k | { |
2625 | 130k | ssize_t |
2626 | 130k | i, |
2627 | 130k | x; |
2628 | | |
2629 | 130k | if (image->number_meta_channels == 0) |
2630 | 0 | { |
2631 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
2632 | 0 | "MultispectralImageRequired","`%s'",image->filename); |
2633 | 0 | return; |
2634 | 0 | } |
2635 | 130k | if (quantum_info->meta_channel != 0) |
2636 | 99.6k | { |
2637 | 99.6k | ExportPixelChannel(image,quantum_info,number_pixels,p,q, |
2638 | 99.6k | (PixelChannel) (MetaPixelChannels+quantum_info->meta_channel-1)); |
2639 | 99.6k | return; |
2640 | 99.6k | } |
2641 | 30.7k | switch (quantum_info->depth) |
2642 | 30.7k | { |
2643 | 10.8k | case 8: |
2644 | 10.8k | { |
2645 | 10.8k | unsigned char |
2646 | 10.8k | pixel; |
2647 | | |
2648 | 6.21M | for (x=0; x < (ssize_t) number_pixels; x++) |
2649 | 6.20M | { |
2650 | 42.3M | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2651 | 36.1M | { |
2652 | 36.1M | pixel=ScaleQuantumToChar(p[i]); |
2653 | 36.1M | q=PopCharPixel(pixel,q); |
2654 | 36.1M | } |
2655 | 6.20M | p+=(ptrdiff_t) GetPixelChannels(image); |
2656 | 6.20M | q+=(ptrdiff_t) quantum_info->pad; |
2657 | 6.20M | } |
2658 | 10.8k | break; |
2659 | 0 | } |
2660 | 7.09k | case 16: |
2661 | 7.09k | { |
2662 | 7.09k | unsigned short |
2663 | 7.09k | pixel; |
2664 | | |
2665 | 7.09k | if (quantum_info->format == FloatingPointQuantumFormat) |
2666 | 3.48k | { |
2667 | 14.9k | for (x=0; x < (ssize_t) number_pixels; x++) |
2668 | 11.5k | { |
2669 | 82.4k | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2670 | 70.9k | { |
2671 | 70.9k | pixel=SinglePrecisionToHalf(QuantumScale*(double) p[i]); |
2672 | 70.9k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2673 | 70.9k | } |
2674 | 11.5k | p+=(ptrdiff_t) GetPixelChannels(image); |
2675 | 11.5k | q+=(ptrdiff_t) quantum_info->pad; |
2676 | 11.5k | } |
2677 | 3.48k | break; |
2678 | 3.48k | } |
2679 | 107k | for (x=0; x < (ssize_t) number_pixels; x++) |
2680 | 103k | { |
2681 | 639k | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2682 | 535k | { |
2683 | 535k | pixel=ScaleQuantumToShort(p[i]); |
2684 | 535k | q=PopShortPixel(quantum_info->endian,pixel,q); |
2685 | 535k | } |
2686 | 103k | p+=(ptrdiff_t) GetPixelChannels(image); |
2687 | 103k | q+=(ptrdiff_t) quantum_info->pad; |
2688 | 103k | } |
2689 | 3.61k | break; |
2690 | 7.09k | } |
2691 | 11.2k | case 32: |
2692 | 11.2k | { |
2693 | 11.2k | unsigned int |
2694 | 11.2k | pixel; |
2695 | | |
2696 | 11.2k | if (quantum_info->format == FloatingPointQuantumFormat) |
2697 | 4.64k | { |
2698 | 38.1k | for (x=0; x < (ssize_t) number_pixels; x++) |
2699 | 33.5k | { |
2700 | 262k | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2701 | 228k | q=PopQuantumFloatPixel(quantum_info,(float) p[i],q); |
2702 | 33.5k | p+=(ptrdiff_t) GetPixelChannels(image); |
2703 | 33.5k | q+=(ptrdiff_t) quantum_info->pad; |
2704 | 33.5k | } |
2705 | 4.64k | break; |
2706 | 4.64k | } |
2707 | 1.23M | for (x=0; x < (ssize_t) number_pixels; x++) |
2708 | 1.22M | { |
2709 | 20.7M | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2710 | 19.5M | { |
2711 | 19.5M | pixel=ScaleQuantumToLong(p[i]); |
2712 | 19.5M | q=PopLongPixel(quantum_info->endian,pixel,q); |
2713 | 19.5M | } |
2714 | 1.22M | p+=(ptrdiff_t) GetPixelChannels(image); |
2715 | 1.22M | q+=(ptrdiff_t) quantum_info->pad; |
2716 | 1.22M | } |
2717 | 6.60k | break; |
2718 | 11.2k | } |
2719 | 242 | case 64: |
2720 | 242 | { |
2721 | 242 | if (quantum_info->format == FloatingPointQuantumFormat) |
2722 | 166 | { |
2723 | 874 | for (x=0; x < (ssize_t) number_pixels; x++) |
2724 | 708 | { |
2725 | 3.05k | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2726 | 2.34k | q=PopQuantumDoublePixel(quantum_info,(double) p[i],q); |
2727 | 708 | p+=(ptrdiff_t) GetPixelChannels(image); |
2728 | 708 | q+=(ptrdiff_t) quantum_info->pad; |
2729 | 708 | } |
2730 | 166 | break; |
2731 | 166 | } |
2732 | 76 | magick_fallthrough; |
2733 | 76 | } |
2734 | 1.40k | default: |
2735 | 1.40k | { |
2736 | 1.40k | QuantumAny |
2737 | 1.40k | range; |
2738 | | |
2739 | 1.40k | range=GetQuantumRange(quantum_info->depth); |
2740 | 76.4k | for (x=0; x < (ssize_t) number_pixels; x++) |
2741 | 75.0k | { |
2742 | 370k | for (i=0; i < (ssize_t) GetImageChannels(image); i++) |
2743 | 295k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(p[i],range),q); |
2744 | 75.0k | p+=(ptrdiff_t) GetPixelChannels(image); |
2745 | 75.0k | q+=(ptrdiff_t) quantum_info->pad; |
2746 | 75.0k | } |
2747 | 1.40k | break; |
2748 | 76 | } |
2749 | 30.7k | } |
2750 | 30.7k | } |
2751 | | |
2752 | | static void ExportOpacityQuantum(const Image *image,QuantumInfo *quantum_info, |
2753 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
2754 | | unsigned char *magick_restrict q,ExceptionInfo *exception) |
2755 | 0 | { |
2756 | 0 | QuantumAny |
2757 | 0 | range; |
2758 | |
|
2759 | 0 | ssize_t |
2760 | 0 | x; |
2761 | |
|
2762 | 0 | if (image->alpha_trait == UndefinedPixelTrait) |
2763 | 0 | { |
2764 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
2765 | 0 | "ImageDoesNotHaveAnAlphaChannel","`%s'",image->filename); |
2766 | 0 | return; |
2767 | 0 | } |
2768 | 0 | switch (quantum_info->depth) |
2769 | 0 | { |
2770 | 0 | case 8: |
2771 | 0 | { |
2772 | 0 | unsigned char |
2773 | 0 | pixel; |
2774 | |
|
2775 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2776 | 0 | { |
2777 | 0 | pixel=ScaleQuantumToChar(GetPixelOpacity(image,p)); |
2778 | 0 | q=PopCharPixel(pixel,q); |
2779 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2780 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2781 | 0 | } |
2782 | 0 | break; |
2783 | 0 | } |
2784 | 0 | case 16: |
2785 | 0 | { |
2786 | 0 | unsigned short |
2787 | 0 | pixel; |
2788 | |
|
2789 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
2790 | 0 | { |
2791 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2792 | 0 | { |
2793 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
2794 | 0 | GetPixelOpacity(image,p)); |
2795 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
2796 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2797 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2798 | 0 | } |
2799 | 0 | break; |
2800 | 0 | } |
2801 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2802 | 0 | { |
2803 | 0 | pixel=ScaleQuantumToShort(GetPixelOpacity(image,p)); |
2804 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
2805 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2806 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2807 | 0 | } |
2808 | 0 | break; |
2809 | 0 | } |
2810 | 0 | case 32: |
2811 | 0 | { |
2812 | 0 | unsigned int |
2813 | 0 | pixel; |
2814 | |
|
2815 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
2816 | 0 | { |
2817 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2818 | 0 | { |
2819 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelOpacity(image,p),q); |
2820 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2821 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2822 | 0 | } |
2823 | 0 | break; |
2824 | 0 | } |
2825 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2826 | 0 | { |
2827 | 0 | pixel=ScaleQuantumToLong(GetPixelOpacity(image,p)); |
2828 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
2829 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2830 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2831 | 0 | } |
2832 | 0 | break; |
2833 | 0 | } |
2834 | 0 | case 64: |
2835 | 0 | { |
2836 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
2837 | 0 | { |
2838 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2839 | 0 | { |
2840 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelOpacity(image,p),q); |
2841 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2842 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2843 | 0 | } |
2844 | 0 | break; |
2845 | 0 | } |
2846 | 0 | magick_fallthrough; |
2847 | 0 | } |
2848 | 0 | default: |
2849 | 0 | { |
2850 | 0 | range=GetQuantumRange(quantum_info->depth); |
2851 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2852 | 0 | { |
2853 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny( |
2854 | 0 | GetPixelOpacity(image,p),range),q); |
2855 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2856 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2857 | 0 | } |
2858 | 0 | break; |
2859 | 0 | } |
2860 | 0 | } |
2861 | 0 | } |
2862 | | |
2863 | | static void ExportRGBQuantum(const Image *image,QuantumInfo *quantum_info, |
2864 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
2865 | | unsigned char *magick_restrict q) |
2866 | 142k | { |
2867 | 142k | QuantumAny |
2868 | 142k | range; |
2869 | | |
2870 | 142k | ssize_t |
2871 | 142k | x; |
2872 | | |
2873 | 142k | ssize_t |
2874 | 142k | bit; |
2875 | | |
2876 | 142k | switch (quantum_info->depth) |
2877 | 142k | { |
2878 | 65.0k | case 8: |
2879 | 65.0k | { |
2880 | 24.8M | for (x=0; x < (ssize_t) number_pixels; x++) |
2881 | 24.7M | { |
2882 | 24.7M | q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q); |
2883 | 24.7M | q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q); |
2884 | 24.7M | q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q); |
2885 | 24.7M | p+=(ptrdiff_t) GetPixelChannels(image); |
2886 | 24.7M | q+=(ptrdiff_t) quantum_info->pad; |
2887 | 24.7M | } |
2888 | 65.0k | break; |
2889 | 0 | } |
2890 | 2.14k | case 10: |
2891 | 2.14k | { |
2892 | 2.14k | unsigned int |
2893 | 2.14k | pixel; |
2894 | | |
2895 | 2.14k | range=GetQuantumRange(quantum_info->depth); |
2896 | 2.14k | if (quantum_info->pack == MagickFalse) |
2897 | 1.55k | { |
2898 | 22.6k | for (x=0; x < (ssize_t) number_pixels; x++) |
2899 | 21.0k | { |
2900 | 21.0k | pixel=(unsigned int) ( |
2901 | 21.0k | ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 | |
2902 | 21.0k | ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 | |
2903 | 21.0k | ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2); |
2904 | 21.0k | q=PopLongPixel(quantum_info->endian,pixel,q); |
2905 | 21.0k | p+=(ptrdiff_t) GetPixelChannels(image); |
2906 | 21.0k | q+=(ptrdiff_t) quantum_info->pad; |
2907 | 21.0k | } |
2908 | 1.55k | break; |
2909 | 1.55k | } |
2910 | 594 | if (quantum_info->quantum == 32UL) |
2911 | 0 | { |
2912 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
2913 | 0 | { |
2914 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
2915 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
2916 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
2917 | 0 | range); |
2918 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
2919 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
2920 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
2921 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2922 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
2923 | 0 | } |
2924 | 0 | break; |
2925 | 0 | } |
2926 | 3.07k | for (x=0; x < (ssize_t) number_pixels; x++) |
2927 | 2.47k | { |
2928 | 2.47k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
2929 | 2.47k | q=PopQuantumPixel(quantum_info,pixel,q); |
2930 | 2.47k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
2931 | 2.47k | q=PopQuantumPixel(quantum_info,pixel,q); |
2932 | 2.47k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
2933 | 2.47k | q=PopQuantumPixel(quantum_info,pixel,q); |
2934 | 2.47k | p+=(ptrdiff_t) GetPixelChannels(image); |
2935 | 2.47k | q+=(ptrdiff_t) quantum_info->pad; |
2936 | 2.47k | } |
2937 | 594 | break; |
2938 | 594 | } |
2939 | 8.29k | case 12: |
2940 | 8.29k | { |
2941 | 8.29k | unsigned int |
2942 | 8.29k | pixel; |
2943 | | |
2944 | 8.29k | range=GetQuantumRange(quantum_info->depth); |
2945 | 8.29k | if (quantum_info->pack == MagickFalse) |
2946 | 7.92k | { |
2947 | 42.3k | for (x=0; x < (3*(ssize_t) number_pixels-1); x+=2) |
2948 | 34.3k | { |
2949 | 34.3k | switch (x % 3) |
2950 | 34.3k | { |
2951 | 0 | default: |
2952 | 16.1k | case 0: |
2953 | 16.1k | { |
2954 | 16.1k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p), |
2955 | 16.1k | range); |
2956 | 16.1k | break; |
2957 | 0 | } |
2958 | 9.11k | case 1: |
2959 | 9.11k | { |
2960 | 9.11k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
2961 | 9.11k | range); |
2962 | 9.11k | break; |
2963 | 0 | } |
2964 | 9.11k | case 2: |
2965 | 9.11k | { |
2966 | 9.11k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p), |
2967 | 9.11k | range); |
2968 | 9.11k | p+=(ptrdiff_t) GetPixelChannels(image); |
2969 | 9.11k | break; |
2970 | 0 | } |
2971 | 34.3k | } |
2972 | 34.3k | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4), |
2973 | 34.3k | q); |
2974 | 34.3k | switch ((x+1) % 3) |
2975 | 34.3k | { |
2976 | 0 | default: |
2977 | 9.11k | case 0: |
2978 | 9.11k | { |
2979 | 9.11k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p), |
2980 | 9.11k | range); |
2981 | 9.11k | break; |
2982 | 0 | } |
2983 | 16.1k | case 1: |
2984 | 16.1k | { |
2985 | 16.1k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
2986 | 16.1k | range); |
2987 | 16.1k | break; |
2988 | 0 | } |
2989 | 9.11k | case 2: |
2990 | 9.11k | { |
2991 | 9.11k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p), |
2992 | 9.11k | range); |
2993 | 9.11k | p+=(ptrdiff_t) GetPixelChannels(image); |
2994 | 9.11k | break; |
2995 | 0 | } |
2996 | 34.3k | } |
2997 | 34.3k | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4), |
2998 | 34.3k | q); |
2999 | 34.3k | q+=(ptrdiff_t) quantum_info->pad; |
3000 | 34.3k | } |
3001 | 14.9k | for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++) |
3002 | 7.02k | { |
3003 | 7.02k | switch ((x+bit) % 3) |
3004 | 7.02k | { |
3005 | 0 | default: |
3006 | 0 | case 0: |
3007 | 0 | { |
3008 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p), |
3009 | 0 | range); |
3010 | 0 | break; |
3011 | 0 | } |
3012 | 0 | case 1: |
3013 | 0 | { |
3014 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
3015 | 0 | range); |
3016 | 0 | break; |
3017 | 0 | } |
3018 | 7.02k | case 2: |
3019 | 7.02k | { |
3020 | 7.02k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p), |
3021 | 7.02k | range); |
3022 | 7.02k | p+=(ptrdiff_t) GetPixelChannels(image); |
3023 | 7.02k | break; |
3024 | 0 | } |
3025 | 7.02k | } |
3026 | 7.02k | q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4), |
3027 | 7.02k | q); |
3028 | 7.02k | q+=(ptrdiff_t) quantum_info->pad; |
3029 | 7.02k | } |
3030 | 7.92k | if (bit != 0) |
3031 | 7.02k | p+=(ptrdiff_t) GetPixelChannels(image); |
3032 | 7.92k | break; |
3033 | 7.92k | } |
3034 | 365 | if (quantum_info->quantum == 32UL) |
3035 | 0 | { |
3036 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3037 | 0 | { |
3038 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
3039 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3040 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
3041 | 0 | range); |
3042 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3043 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
3044 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3045 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3046 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3047 | 0 | } |
3048 | 0 | break; |
3049 | 0 | } |
3050 | 2.65k | for (x=0; x < (ssize_t) number_pixels; x++) |
3051 | 2.29k | { |
3052 | 2.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
3053 | 2.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3054 | 2.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
3055 | 2.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3056 | 2.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
3057 | 2.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3058 | 2.29k | p+=(ptrdiff_t) GetPixelChannels(image); |
3059 | 2.29k | q+=(ptrdiff_t) quantum_info->pad; |
3060 | 2.29k | } |
3061 | 365 | break; |
3062 | 365 | } |
3063 | 33.5k | case 16: |
3064 | 33.5k | { |
3065 | 33.5k | unsigned short |
3066 | 33.5k | pixel; |
3067 | | |
3068 | 33.5k | if (quantum_info->format == FloatingPointQuantumFormat) |
3069 | 5.28k | { |
3070 | 210k | for (x=0; x < (ssize_t) number_pixels; x++) |
3071 | 204k | { |
3072 | 204k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3073 | 204k | GetPixelRed(image,p)); |
3074 | 204k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3075 | 204k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3076 | 204k | GetPixelGreen(image,p)); |
3077 | 204k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3078 | 204k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3079 | 204k | GetPixelBlue(image,p)); |
3080 | 204k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3081 | 204k | p+=(ptrdiff_t) GetPixelChannels(image); |
3082 | 204k | q+=(ptrdiff_t) quantum_info->pad; |
3083 | 204k | } |
3084 | 5.28k | break; |
3085 | 5.28k | } |
3086 | 4.99M | for (x=0; x < (ssize_t) number_pixels; x++) |
3087 | 4.96M | { |
3088 | 4.96M | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
3089 | 4.96M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3090 | 4.96M | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
3091 | 4.96M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3092 | 4.96M | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
3093 | 4.96M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3094 | 4.96M | p+=(ptrdiff_t) GetPixelChannels(image); |
3095 | 4.96M | q+=(ptrdiff_t) quantum_info->pad; |
3096 | 4.96M | } |
3097 | 28.2k | break; |
3098 | 33.5k | } |
3099 | 26.9k | case 32: |
3100 | 26.9k | { |
3101 | 26.9k | unsigned int |
3102 | 26.9k | pixel; |
3103 | | |
3104 | 26.9k | if (quantum_info->format == FloatingPointQuantumFormat) |
3105 | 2.12k | { |
3106 | 16.0k | for (x=0; x < (ssize_t) number_pixels; x++) |
3107 | 13.8k | { |
3108 | 13.8k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p), |
3109 | 13.8k | q); |
3110 | 13.8k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p), |
3111 | 13.8k | q); |
3112 | 13.8k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p), |
3113 | 13.8k | q); |
3114 | 13.8k | p+=(ptrdiff_t) GetPixelChannels(image); |
3115 | 13.8k | q+=(ptrdiff_t) quantum_info->pad; |
3116 | 13.8k | } |
3117 | 2.12k | break; |
3118 | 2.12k | } |
3119 | 27.0M | for (x=0; x < (ssize_t) number_pixels; x++) |
3120 | 27.0M | { |
3121 | 27.0M | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
3122 | 27.0M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3123 | 27.0M | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
3124 | 27.0M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3125 | 27.0M | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
3126 | 27.0M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3127 | 27.0M | p+=(ptrdiff_t) GetPixelChannels(image); |
3128 | 27.0M | q+=(ptrdiff_t) quantum_info->pad; |
3129 | 27.0M | } |
3130 | 24.8k | break; |
3131 | 26.9k | } |
3132 | 1.36k | case 64: |
3133 | 1.36k | { |
3134 | 1.36k | if (quantum_info->format == FloatingPointQuantumFormat) |
3135 | 61 | { |
3136 | 223 | for (x=0; x < (ssize_t) number_pixels; x++) |
3137 | 162 | { |
3138 | 162 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q); |
3139 | 162 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q); |
3140 | 162 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q); |
3141 | 162 | p+=(ptrdiff_t) GetPixelChannels(image); |
3142 | 162 | q+=(ptrdiff_t) quantum_info->pad; |
3143 | 162 | } |
3144 | 61 | break; |
3145 | 61 | } |
3146 | 1.30k | magick_fallthrough; |
3147 | 1.30k | } |
3148 | 6.93k | default: |
3149 | 6.93k | { |
3150 | 6.93k | range=GetQuantumRange(quantum_info->depth); |
3151 | 265k | for (x=0; x < (ssize_t) number_pixels; x++) |
3152 | 258k | { |
3153 | 258k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
3154 | 258k | range),q); |
3155 | 258k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
3156 | 258k | range),q); |
3157 | 258k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
3158 | 258k | range),q); |
3159 | 258k | p+=(ptrdiff_t) GetPixelChannels(image); |
3160 | 258k | q+=(ptrdiff_t) quantum_info->pad; |
3161 | 258k | } |
3162 | 6.93k | break; |
3163 | 1.30k | } |
3164 | 142k | } |
3165 | 142k | } |
3166 | | |
3167 | | static void ExportRGBAQuantum(const Image *image,QuantumInfo *quantum_info, |
3168 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
3169 | | unsigned char *magick_restrict q) |
3170 | 56.2k | { |
3171 | 56.2k | QuantumAny |
3172 | 56.2k | range; |
3173 | | |
3174 | 56.2k | ssize_t |
3175 | 56.2k | x; |
3176 | | |
3177 | 56.2k | switch (quantum_info->depth) |
3178 | 56.2k | { |
3179 | 15.7k | case 8: |
3180 | 15.7k | { |
3181 | 15.7k | unsigned char |
3182 | 15.7k | pixel; |
3183 | | |
3184 | 6.67M | for (x=0; x < (ssize_t) number_pixels; x++) |
3185 | 6.65M | { |
3186 | 6.65M | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
3187 | 6.65M | q=PopCharPixel(pixel,q); |
3188 | 6.65M | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
3189 | 6.65M | q=PopCharPixel(pixel,q); |
3190 | 6.65M | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
3191 | 6.65M | q=PopCharPixel(pixel,q); |
3192 | 6.65M | pixel=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
3193 | 6.65M | q=PopCharPixel(pixel,q); |
3194 | 6.65M | p+=(ptrdiff_t) GetPixelChannels(image); |
3195 | 6.65M | q+=(ptrdiff_t) quantum_info->pad; |
3196 | 6.65M | } |
3197 | 15.7k | break; |
3198 | 0 | } |
3199 | 909 | case 10: |
3200 | 909 | { |
3201 | 909 | unsigned int |
3202 | 909 | pixel; |
3203 | | |
3204 | 909 | range=GetQuantumRange(quantum_info->depth); |
3205 | 909 | if (quantum_info->pack == MagickFalse) |
3206 | 427 | { |
3207 | 427 | ssize_t |
3208 | 427 | i; |
3209 | | |
3210 | 427 | size_t |
3211 | 427 | quantum; |
3212 | | |
3213 | 427 | ssize_t |
3214 | 427 | n; |
3215 | | |
3216 | 427 | n=0; |
3217 | 427 | quantum=0; |
3218 | 427 | pixel=0; |
3219 | 12.8k | for (x=0; x < (ssize_t) number_pixels; x++) |
3220 | 12.4k | { |
3221 | 62.0k | for (i=0; i < 4; i++) |
3222 | 49.6k | { |
3223 | 49.6k | switch (i) |
3224 | 49.6k | { |
3225 | 12.4k | case 0: quantum=(size_t) GetPixelRed(image,p); break; |
3226 | 12.4k | case 1: quantum=(size_t) GetPixelGreen(image,p); break; |
3227 | 12.4k | case 2: quantum=(size_t) GetPixelBlue(image,p); break; |
3228 | 12.4k | case 3: quantum=(size_t) GetPixelAlpha(image,p); break; |
3229 | 49.6k | } |
3230 | 49.6k | switch (n % 3) |
3231 | 49.6k | { |
3232 | 16.7k | case 0: |
3233 | 16.7k | { |
3234 | 16.7k | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
3235 | 16.7k | range) << 22); |
3236 | 16.7k | break; |
3237 | 0 | } |
3238 | 16.4k | case 1: |
3239 | 16.4k | { |
3240 | 16.4k | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
3241 | 16.4k | range) << 12); |
3242 | 16.4k | break; |
3243 | 0 | } |
3244 | 16.3k | case 2: |
3245 | 16.3k | { |
3246 | 16.3k | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
3247 | 16.3k | range) << 2); |
3248 | 16.3k | q=PopLongPixel(quantum_info->endian,pixel,q); |
3249 | 16.3k | pixel=0; |
3250 | 16.3k | break; |
3251 | 0 | } |
3252 | 49.6k | } |
3253 | 49.6k | n++; |
3254 | 49.6k | } |
3255 | 12.4k | p+=(ptrdiff_t) GetPixelChannels(image); |
3256 | 12.4k | q+=(ptrdiff_t) quantum_info->pad; |
3257 | 12.4k | } |
3258 | 427 | break; |
3259 | 427 | } |
3260 | 482 | if (quantum_info->quantum == 32UL) |
3261 | 0 | { |
3262 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3263 | 0 | { |
3264 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
3265 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3266 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
3267 | 0 | range); |
3268 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3269 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
3270 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3271 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p), |
3272 | 0 | range); |
3273 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3274 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3275 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3276 | 0 | } |
3277 | 0 | break; |
3278 | 0 | } |
3279 | 6.77k | for (x=0; x < (ssize_t) number_pixels; x++) |
3280 | 6.29k | { |
3281 | 6.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
3282 | 6.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3283 | 6.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
3284 | 6.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3285 | 6.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
3286 | 6.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3287 | 6.29k | pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),range); |
3288 | 6.29k | q=PopQuantumPixel(quantum_info,pixel,q); |
3289 | 6.29k | p+=(ptrdiff_t) GetPixelChannels(image); |
3290 | 6.29k | q+=(ptrdiff_t) quantum_info->pad; |
3291 | 6.29k | } |
3292 | 482 | break; |
3293 | 482 | } |
3294 | 27.2k | case 16: |
3295 | 27.2k | { |
3296 | 27.2k | unsigned short |
3297 | 27.2k | pixel; |
3298 | | |
3299 | 27.2k | if (quantum_info->format == FloatingPointQuantumFormat) |
3300 | 3.53k | { |
3301 | 29.0k | for (x=0; x < (ssize_t) number_pixels; x++) |
3302 | 25.4k | { |
3303 | 25.4k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3304 | 25.4k | GetPixelRed(image,p)); |
3305 | 25.4k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3306 | 25.4k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3307 | 25.4k | GetPixelGreen(image,p)); |
3308 | 25.4k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3309 | 25.4k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3310 | 25.4k | GetPixelBlue(image,p)); |
3311 | 25.4k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3312 | 25.4k | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3313 | 25.4k | GetPixelAlpha(image,p)); |
3314 | 25.4k | q=PopShortPixel(quantum_info->endian,pixel,q); |
3315 | 25.4k | p+=(ptrdiff_t) GetPixelChannels(image); |
3316 | 25.4k | q+=(ptrdiff_t) quantum_info->pad; |
3317 | 25.4k | } |
3318 | 3.53k | break; |
3319 | 3.53k | } |
3320 | 2.57M | for (x=0; x < (ssize_t) number_pixels; x++) |
3321 | 2.55M | { |
3322 | 2.55M | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
3323 | 2.55M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3324 | 2.55M | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
3325 | 2.55M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3326 | 2.55M | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
3327 | 2.55M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3328 | 2.55M | pixel=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
3329 | 2.55M | q=PopShortPixel(quantum_info->endian,pixel,q); |
3330 | 2.55M | p+=(ptrdiff_t) GetPixelChannels(image); |
3331 | 2.55M | q+=(ptrdiff_t) quantum_info->pad; |
3332 | 2.55M | } |
3333 | 23.6k | break; |
3334 | 27.2k | } |
3335 | 10.6k | case 32: |
3336 | 10.6k | { |
3337 | 10.6k | unsigned int |
3338 | 10.6k | pixel; |
3339 | | |
3340 | 10.6k | if (quantum_info->format == FloatingPointQuantumFormat) |
3341 | 1.80k | { |
3342 | 11.3k | for (x=0; x < (ssize_t) number_pixels; x++) |
3343 | 9.55k | { |
3344 | 9.55k | float |
3345 | 9.55k | float_pixel; |
3346 | | |
3347 | 9.55k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q); |
3348 | 9.55k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q); |
3349 | 9.55k | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q); |
3350 | 9.55k | float_pixel=(float) GetPixelAlpha(image,p); |
3351 | 9.55k | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
3352 | 9.55k | p+=(ptrdiff_t) GetPixelChannels(image); |
3353 | 9.55k | q+=(ptrdiff_t) quantum_info->pad; |
3354 | 9.55k | } |
3355 | 1.80k | break; |
3356 | 1.80k | } |
3357 | 2.05M | for (x=0; x < (ssize_t) number_pixels; x++) |
3358 | 2.04M | { |
3359 | 2.04M | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
3360 | 2.04M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3361 | 2.04M | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
3362 | 2.04M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3363 | 2.04M | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
3364 | 2.04M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3365 | 2.04M | pixel=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
3366 | 2.04M | q=PopLongPixel(quantum_info->endian,pixel,q); |
3367 | 2.04M | p+=(ptrdiff_t) GetPixelChannels(image); |
3368 | 2.04M | q+=(ptrdiff_t) quantum_info->pad; |
3369 | 2.04M | } |
3370 | 8.81k | break; |
3371 | 10.6k | } |
3372 | 95 | case 64: |
3373 | 95 | { |
3374 | 95 | if (quantum_info->format == FloatingPointQuantumFormat) |
3375 | 95 | { |
3376 | 95 | double |
3377 | 95 | pixel; |
3378 | | |
3379 | 379 | for (x=0; x < (ssize_t) number_pixels; x++) |
3380 | 284 | { |
3381 | 284 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q); |
3382 | 284 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q); |
3383 | 284 | q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q); |
3384 | 284 | pixel=(double) GetPixelAlpha(image,p); |
3385 | 284 | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
3386 | 284 | p+=(ptrdiff_t) GetPixelChannels(image); |
3387 | 284 | q+=(ptrdiff_t) quantum_info->pad; |
3388 | 284 | } |
3389 | 95 | break; |
3390 | 95 | } |
3391 | 0 | magick_fallthrough; |
3392 | 0 | } |
3393 | 1.64k | default: |
3394 | 1.64k | { |
3395 | 1.64k | range=GetQuantumRange(quantum_info->depth); |
3396 | 22.5k | for (x=0; x < (ssize_t) number_pixels; x++) |
3397 | 20.9k | { |
3398 | 20.9k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
3399 | 20.9k | range),q); |
3400 | 20.9k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
3401 | 20.9k | range),q); |
3402 | 20.9k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
3403 | 20.9k | range),q); |
3404 | 20.9k | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p), |
3405 | 20.9k | range),q); |
3406 | 20.9k | p+=(ptrdiff_t) GetPixelChannels(image); |
3407 | 20.9k | q+=(ptrdiff_t) quantum_info->pad; |
3408 | 20.9k | } |
3409 | 1.64k | break; |
3410 | 0 | } |
3411 | 56.2k | } |
3412 | 56.2k | } |
3413 | | |
3414 | | static void ExportRGBOQuantum(const Image *image,QuantumInfo *quantum_info, |
3415 | | const MagickSizeType number_pixels,const Quantum *magick_restrict p, |
3416 | | unsigned char *magick_restrict q) |
3417 | 0 | { |
3418 | 0 | QuantumAny |
3419 | 0 | range; |
3420 | |
|
3421 | 0 | ssize_t |
3422 | 0 | x; |
3423 | |
|
3424 | 0 | switch (quantum_info->depth) |
3425 | 0 | { |
3426 | 0 | case 8: |
3427 | 0 | { |
3428 | 0 | unsigned char |
3429 | 0 | pixel; |
3430 | |
|
3431 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3432 | 0 | { |
3433 | 0 | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
3434 | 0 | q=PopCharPixel(pixel,q); |
3435 | 0 | pixel=ScaleQuantumToChar(GetPixelGreen(image,p)); |
3436 | 0 | q=PopCharPixel(pixel,q); |
3437 | 0 | pixel=ScaleQuantumToChar(GetPixelBlue(image,p)); |
3438 | 0 | q=PopCharPixel(pixel,q); |
3439 | 0 | pixel=ScaleQuantumToChar(GetPixelOpacity(image,p)); |
3440 | 0 | q=PopCharPixel(pixel,q); |
3441 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3442 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3443 | 0 | } |
3444 | 0 | break; |
3445 | 0 | } |
3446 | 0 | case 10: |
3447 | 0 | { |
3448 | 0 | unsigned int |
3449 | 0 | pixel; |
3450 | |
|
3451 | 0 | range=GetQuantumRange(quantum_info->depth); |
3452 | 0 | if (quantum_info->pack == MagickFalse) |
3453 | 0 | { |
3454 | 0 | ssize_t |
3455 | 0 | i; |
3456 | |
|
3457 | 0 | size_t |
3458 | 0 | quantum; |
3459 | |
|
3460 | 0 | ssize_t |
3461 | 0 | n; |
3462 | |
|
3463 | 0 | n=0; |
3464 | 0 | quantum=0; |
3465 | 0 | pixel=0; |
3466 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3467 | 0 | { |
3468 | 0 | for (i=0; i < 4; i++) |
3469 | 0 | { |
3470 | 0 | switch (i) |
3471 | 0 | { |
3472 | 0 | case 0: quantum=(size_t) GetPixelRed(image,p); break; |
3473 | 0 | case 1: quantum=(size_t) GetPixelGreen(image,p); break; |
3474 | 0 | case 2: quantum=(size_t) GetPixelBlue(image,p); break; |
3475 | 0 | case 3: quantum=(size_t) GetPixelOpacity(image,p); break; |
3476 | 0 | } |
3477 | 0 | switch (n % 3) |
3478 | 0 | { |
3479 | 0 | case 0: |
3480 | 0 | { |
3481 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
3482 | 0 | range) << 22); |
3483 | 0 | break; |
3484 | 0 | } |
3485 | 0 | case 1: |
3486 | 0 | { |
3487 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
3488 | 0 | range) << 12); |
3489 | 0 | break; |
3490 | 0 | } |
3491 | 0 | case 2: |
3492 | 0 | { |
3493 | 0 | pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum, |
3494 | 0 | range) << 2); |
3495 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
3496 | 0 | pixel=0; |
3497 | 0 | break; |
3498 | 0 | } |
3499 | 0 | } |
3500 | 0 | n++; |
3501 | 0 | } |
3502 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3503 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3504 | 0 | } |
3505 | 0 | break; |
3506 | 0 | } |
3507 | 0 | if (quantum_info->quantum == 32UL) |
3508 | 0 | { |
3509 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3510 | 0 | { |
3511 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
3512 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3513 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p), |
3514 | 0 | range); |
3515 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3516 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
3517 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3518 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p), |
3519 | 0 | range); |
3520 | 0 | q=PopQuantumLongPixel(quantum_info,pixel,q); |
3521 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3522 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3523 | 0 | } |
3524 | 0 | break; |
3525 | 0 | } |
3526 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3527 | 0 | { |
3528 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range); |
3529 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
3530 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range); |
3531 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
3532 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range); |
3533 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
3534 | 0 | pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),range); |
3535 | 0 | q=PopQuantumPixel(quantum_info,pixel,q); |
3536 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3537 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3538 | 0 | } |
3539 | 0 | break; |
3540 | 0 | } |
3541 | 0 | case 16: |
3542 | 0 | { |
3543 | 0 | unsigned short |
3544 | 0 | pixel; |
3545 | |
|
3546 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
3547 | 0 | { |
3548 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3549 | 0 | { |
3550 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3551 | 0 | GetPixelRed(image,p)); |
3552 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3553 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3554 | 0 | GetPixelGreen(image,p)); |
3555 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3556 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3557 | 0 | GetPixelBlue(image,p)); |
3558 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3559 | 0 | pixel=SinglePrecisionToHalf(QuantumScale*(double) |
3560 | 0 | GetPixelOpacity(image,p)); |
3561 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3562 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3563 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3564 | 0 | } |
3565 | 0 | break; |
3566 | 0 | } |
3567 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3568 | 0 | { |
3569 | 0 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
3570 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3571 | 0 | pixel=ScaleQuantumToShort(GetPixelGreen(image,p)); |
3572 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3573 | 0 | pixel=ScaleQuantumToShort(GetPixelBlue(image,p)); |
3574 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3575 | 0 | pixel=ScaleQuantumToShort(GetPixelOpacity(image,p)); |
3576 | 0 | q=PopShortPixel(quantum_info->endian,pixel,q); |
3577 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3578 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3579 | 0 | } |
3580 | 0 | break; |
3581 | 0 | } |
3582 | 0 | case 32: |
3583 | 0 | { |
3584 | 0 | unsigned int |
3585 | 0 | pixel; |
3586 | |
|
3587 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
3588 | 0 | { |
3589 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3590 | 0 | { |
3591 | 0 | float |
3592 | 0 | float_pixel; |
3593 | |
|
3594 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p), |
3595 | 0 | q); |
3596 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p), |
3597 | 0 | q); |
3598 | 0 | q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p), |
3599 | 0 | q); |
3600 | 0 | float_pixel=(float) GetPixelOpacity(image,p); |
3601 | 0 | q=PopQuantumFloatPixel(quantum_info,float_pixel,q); |
3602 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3603 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3604 | 0 | } |
3605 | 0 | break; |
3606 | 0 | } |
3607 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3608 | 0 | { |
3609 | 0 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
3610 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
3611 | 0 | pixel=ScaleQuantumToLong(GetPixelGreen(image,p)); |
3612 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
3613 | 0 | pixel=ScaleQuantumToLong(GetPixelBlue(image,p)); |
3614 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
3615 | 0 | pixel=ScaleQuantumToLong(GetPixelOpacity(image,p)); |
3616 | 0 | q=PopLongPixel(quantum_info->endian,pixel,q); |
3617 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3618 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3619 | 0 | } |
3620 | 0 | break; |
3621 | 0 | } |
3622 | 0 | case 64: |
3623 | 0 | { |
3624 | 0 | if (quantum_info->format == FloatingPointQuantumFormat) |
3625 | 0 | { |
3626 | 0 | double |
3627 | 0 | pixel; |
3628 | |
|
3629 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3630 | 0 | { |
3631 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
3632 | 0 | GetPixelRed(image,p),q); |
3633 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
3634 | 0 | GetPixelGreen(image,p),q); |
3635 | 0 | q=PopQuantumDoublePixel(quantum_info,(double) |
3636 | 0 | GetPixelBlue(image,p),q); |
3637 | 0 | pixel=(double) GetPixelOpacity(image,p); |
3638 | 0 | q=PopQuantumDoublePixel(quantum_info,pixel,q); |
3639 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3640 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3641 | 0 | } |
3642 | 0 | break; |
3643 | 0 | } |
3644 | 0 | magick_fallthrough; |
3645 | 0 | } |
3646 | 0 | default: |
3647 | 0 | { |
3648 | 0 | range=GetQuantumRange(quantum_info->depth); |
3649 | 0 | for (x=0; x < (ssize_t) number_pixels; x++) |
3650 | 0 | { |
3651 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p), |
3652 | 0 | range),q); |
3653 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p), |
3654 | 0 | range),q); |
3655 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p), |
3656 | 0 | range),q); |
3657 | 0 | q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p), |
3658 | 0 | range),q); |
3659 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
3660 | 0 | q+=(ptrdiff_t) quantum_info->pad; |
3661 | 0 | } |
3662 | 0 | break; |
3663 | 0 | } |
3664 | 0 | } |
3665 | 0 | } |
3666 | | |
3667 | | MagickExport size_t ExportQuantumPixels(const Image *image, |
3668 | | CacheView *image_view,QuantumInfo *quantum_info, |
3669 | | const QuantumType quantum_type,unsigned char *magick_restrict pixels, |
3670 | | ExceptionInfo *exception) |
3671 | 1.63M | { |
3672 | 1.63M | const Quantum |
3673 | 1.63M | *magick_restrict p; |
3674 | | |
3675 | 1.63M | MagickSizeType |
3676 | 1.63M | number_pixels; |
3677 | | |
3678 | 1.63M | size_t |
3679 | 1.63M | extent; |
3680 | | |
3681 | 1.63M | ssize_t |
3682 | 1.63M | x; |
3683 | | |
3684 | 1.63M | unsigned char |
3685 | 1.63M | *magick_restrict q; |
3686 | | |
3687 | 1.63M | assert(image != (Image *) NULL); |
3688 | 1.63M | assert(image->signature == MagickCoreSignature); |
3689 | 1.63M | assert(quantum_info != (QuantumInfo *) NULL); |
3690 | 1.63M | assert(quantum_info->signature == MagickCoreSignature); |
3691 | 1.63M | assert(exception != (ExceptionInfo *) NULL); |
3692 | 1.63M | assert(exception->signature == MagickCoreSignature); |
3693 | 1.63M | if (IsEventLogging() != MagickFalse) |
3694 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
3695 | 1.63M | if (pixels == (unsigned char *) NULL) |
3696 | 0 | pixels=(unsigned char *) GetQuantumPixels(quantum_info); |
3697 | 1.63M | if (image_view == (CacheView *) NULL) |
3698 | 1.63M | { |
3699 | 1.63M | number_pixels=GetImageExtent(image); |
3700 | 1.63M | p=GetVirtualPixelQueue(image); |
3701 | 1.63M | } |
3702 | 0 | else |
3703 | 0 | { |
3704 | 0 | number_pixels=GetCacheViewExtent(image_view); |
3705 | 0 | p=GetCacheViewVirtualPixelQueue(image_view); |
3706 | 0 | } |
3707 | 1.63M | if (p == (Quantum *) NULL) |
3708 | 0 | return(0); |
3709 | 1.63M | if (quantum_info->alpha_type == AssociatedQuantumAlpha) |
3710 | 0 | { |
3711 | 0 | double |
3712 | 0 | Sa; |
3713 | |
|
3714 | 0 | Quantum |
3715 | 0 | *magick_restrict r; |
3716 | | |
3717 | | /* |
3718 | | Associate alpha. |
3719 | | */ |
3720 | 0 | if (image_view == (CacheView *) NULL) |
3721 | 0 | r=GetAuthenticPixelQueue(image); |
3722 | 0 | else |
3723 | 0 | r=GetCacheViewAuthenticPixelQueue(image_view); |
3724 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
3725 | 0 | { |
3726 | 0 | ssize_t |
3727 | 0 | i; |
3728 | |
|
3729 | 0 | Sa=QuantumScale*(double) GetPixelAlpha(image,r); |
3730 | 0 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
3731 | 0 | { |
3732 | 0 | PixelChannel channel = GetPixelChannelChannel(image,i); |
3733 | 0 | PixelTrait traits = GetPixelChannelTraits(image,channel); |
3734 | 0 | if ((traits & UpdatePixelTrait) == 0) |
3735 | 0 | continue; |
3736 | 0 | r[i]=ClampToQuantum(Sa*(double) r[i]); |
3737 | 0 | } |
3738 | 0 | r+=(ptrdiff_t) GetPixelChannels(image); |
3739 | 0 | } |
3740 | 0 | } |
3741 | 1.63M | if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum)) |
3742 | 2.42k | { |
3743 | 2.42k | Quantum |
3744 | 2.42k | quantum; |
3745 | | |
3746 | 2.42k | Quantum |
3747 | 2.42k | *magick_restrict r; |
3748 | | |
3749 | 2.42k | if (image_view == (CacheView *) NULL) |
3750 | 2.42k | r=GetAuthenticPixelQueue(image); |
3751 | 0 | else |
3752 | 0 | r=GetCacheViewAuthenticPixelQueue(image_view); |
3753 | 22.9k | for (x=0; x < (ssize_t) number_pixels; x++) |
3754 | 20.5k | { |
3755 | 20.5k | quantum=GetPixelRed(image,r); |
3756 | 20.5k | SetPixelRed(image,GetPixelGreen(image,r),r); |
3757 | 20.5k | SetPixelGreen(image,quantum,r); |
3758 | 20.5k | r+=(ptrdiff_t) GetPixelChannels(image); |
3759 | 20.5k | } |
3760 | 2.42k | } |
3761 | 1.63M | q=pixels; |
3762 | 1.63M | ResetQuantumState(quantum_info); |
3763 | 1.63M | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
3764 | 1.63M | switch (quantum_type) |
3765 | 1.63M | { |
3766 | 260k | case AlphaQuantum: |
3767 | 260k | { |
3768 | 260k | ExportAlphaQuantum(image,quantum_info,number_pixels,p,q,exception); |
3769 | 260k | break; |
3770 | 0 | } |
3771 | 0 | case BGRQuantum: |
3772 | 0 | { |
3773 | 0 | ExportBGRQuantum(image,quantum_info,number_pixels,p,q); |
3774 | 0 | break; |
3775 | 0 | } |
3776 | 0 | case BGRAQuantum: |
3777 | 0 | { |
3778 | 0 | ExportBGRAQuantum(image,quantum_info,number_pixels,p,q); |
3779 | 0 | break; |
3780 | 0 | } |
3781 | 0 | case BGROQuantum: |
3782 | 0 | { |
3783 | 0 | ExportBGROQuantum(image,quantum_info,number_pixels,p,q); |
3784 | 0 | break; |
3785 | 0 | } |
3786 | 1.20k | case BlackQuantum: |
3787 | 1.20k | { |
3788 | 1.20k | ExportBlackQuantum(image,quantum_info,number_pixels,p,q,exception); |
3789 | 1.20k | break; |
3790 | 0 | } |
3791 | 42.3k | case BlueQuantum: |
3792 | 42.3k | case YellowQuantum: |
3793 | 42.3k | { |
3794 | 42.3k | ExportPixelChannel(image,quantum_info,number_pixels,p,q,BluePixelChannel); |
3795 | 42.3k | break; |
3796 | 42.3k | } |
3797 | 24.3k | case CMYKQuantum: |
3798 | 24.3k | { |
3799 | 24.3k | ExportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception); |
3800 | 24.3k | break; |
3801 | 42.3k | } |
3802 | 40.3k | case CMYKAQuantum: |
3803 | 40.3k | { |
3804 | 40.3k | ExportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception); |
3805 | 40.3k | break; |
3806 | 42.3k | } |
3807 | 130k | case MultispectralQuantum: |
3808 | 130k | { |
3809 | 130k | ExportMultispectralQuantum(image,quantum_info,number_pixels,p,q,exception); |
3810 | 130k | break; |
3811 | 42.3k | } |
3812 | 0 | case CMYKOQuantum: |
3813 | 0 | { |
3814 | 0 | ExportCMYKOQuantum(image,quantum_info,number_pixels,p,q,exception); |
3815 | 0 | break; |
3816 | 42.3k | } |
3817 | 0 | case CbYCrYQuantum: |
3818 | 0 | { |
3819 | 0 | ExportCbYCrYQuantum(image,quantum_info,number_pixels,p,q); |
3820 | 0 | break; |
3821 | 42.3k | } |
3822 | 752k | case GrayQuantum: |
3823 | 752k | { |
3824 | 752k | ExportGrayQuantum(image,quantum_info,number_pixels,p,q); |
3825 | 752k | break; |
3826 | 42.3k | } |
3827 | 26.5k | case GrayAlphaQuantum: |
3828 | 26.5k | { |
3829 | 26.5k | ExportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q); |
3830 | 26.5k | break; |
3831 | 42.3k | } |
3832 | 42.3k | case GreenQuantum: |
3833 | 42.3k | case MagentaQuantum: |
3834 | 42.3k | { |
3835 | 42.3k | ExportPixelChannel(image,quantum_info,number_pixels,p,q, |
3836 | 42.3k | GreenPixelChannel); |
3837 | 42.3k | break; |
3838 | 42.3k | } |
3839 | 68.1k | case IndexQuantum: |
3840 | 68.1k | { |
3841 | 68.1k | ExportIndexQuantum(image,quantum_info,number_pixels,p,q,exception); |
3842 | 68.1k | break; |
3843 | 42.3k | } |
3844 | 3.57k | case IndexAlphaQuantum: |
3845 | 3.57k | { |
3846 | 3.57k | ExportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception); |
3847 | 3.57k | break; |
3848 | 42.3k | } |
3849 | 42.8k | case RedQuantum: |
3850 | 42.8k | case CyanQuantum: |
3851 | 42.8k | { |
3852 | 42.8k | ExportPixelChannel(image,quantum_info,number_pixels,p,q,RedPixelChannel); |
3853 | 42.8k | break; |
3854 | 42.8k | } |
3855 | 0 | case OpacityQuantum: |
3856 | 0 | { |
3857 | 0 | ExportOpacityQuantum(image,quantum_info,number_pixels,p,q,exception); |
3858 | 0 | break; |
3859 | 42.8k | } |
3860 | 141k | case RGBQuantum: |
3861 | 142k | case CbYCrQuantum: |
3862 | 142k | { |
3863 | 142k | ExportRGBQuantum(image,quantum_info,number_pixels,p,q); |
3864 | 142k | break; |
3865 | 141k | } |
3866 | 55.5k | case RGBAQuantum: |
3867 | 56.2k | case CbYCrAQuantum: |
3868 | 56.2k | { |
3869 | 56.2k | ExportRGBAQuantum(image,quantum_info,number_pixels,p,q); |
3870 | 56.2k | break; |
3871 | 55.5k | } |
3872 | 0 | case RGBOQuantum: |
3873 | 0 | { |
3874 | 0 | ExportRGBOQuantum(image,quantum_info,number_pixels,p,q); |
3875 | 0 | break; |
3876 | 55.5k | } |
3877 | 0 | default: |
3878 | 0 | break; |
3879 | 1.63M | } |
3880 | 1.63M | if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum)) |
3881 | 2.42k | { |
3882 | 2.42k | Quantum |
3883 | 2.42k | quantum; |
3884 | | |
3885 | 2.42k | Quantum |
3886 | 2.42k | *magick_restrict r; |
3887 | | |
3888 | 2.42k | if (image_view == (CacheView *) NULL) |
3889 | 2.42k | r=GetAuthenticPixelQueue(image); |
3890 | 0 | else |
3891 | 0 | r=GetCacheViewAuthenticPixelQueue(image_view); |
3892 | 22.9k | for (x=0; x < (ssize_t) number_pixels; x++) |
3893 | 20.5k | { |
3894 | 20.5k | quantum=GetPixelRed(image,r); |
3895 | 20.5k | SetPixelRed(image,GetPixelGreen(image,r),r); |
3896 | 20.5k | SetPixelGreen(image,quantum,r); |
3897 | 20.5k | r+=(ptrdiff_t) GetPixelChannels(image); |
3898 | 20.5k | } |
3899 | 2.42k | } |
3900 | 1.63M | return(extent); |
3901 | 1.63M | } |