|
MagickCore
6.7.7
|
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % QQQ U U AAA N N TTTTT U U M M % 00007 % Q Q U U A A NN N T U U MM MM % 00008 % Q Q U U AAAAA N N N T U U M M M % 00009 % Q QQ U U A A N NN T U U M M % 00010 % QQQQ UUU A A N N T UUU M M % 00011 % % 00012 % IIIII M M PPPP OOO RRRR TTTTT % 00013 % I MM MM P P O O R R T % 00014 % I M M M PPPP O O RRRR T % 00015 % I M M P O O R R T % 00016 % IIIII M M P OOO R R T % 00017 % % 00018 % MagickCore Methods to Import Quantum Pixels % 00019 % % 00020 % Software Design % 00021 % John Cristy % 00022 % October 1998 % 00023 % % 00024 % % 00025 % Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization % 00026 % dedicated to making software imaging solutions freely available. % 00027 % % 00028 % You may not use this file except in compliance with the License. You may % 00029 % obtain a copy of the License at % 00030 % % 00031 % http://www.imagemagick.org/script/license.php % 00032 % % 00033 % Unless required by applicable law or agreed to in writing, software % 00034 % distributed under the License is distributed on an "AS IS" BASIS, % 00035 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00036 % See the License for the specific language governing permissions and % 00037 % limitations under the License. % 00038 % % 00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00040 % 00041 % 00042 */ 00043 00044 /* 00045 Include declarations. 00046 */ 00047 #include "MagickCore/studio.h" 00048 #include "MagickCore/property.h" 00049 #include "MagickCore/blob.h" 00050 #include "MagickCore/blob-private.h" 00051 #include "MagickCore/color-private.h" 00052 #include "MagickCore/exception.h" 00053 #include "MagickCore/exception-private.h" 00054 #include "MagickCore/cache.h" 00055 #include "MagickCore/constitute.h" 00056 #include "MagickCore/delegate.h" 00057 #include "MagickCore/geometry.h" 00058 #include "MagickCore/list.h" 00059 #include "MagickCore/magick.h" 00060 #include "MagickCore/memory_.h" 00061 #include "MagickCore/monitor.h" 00062 #include "MagickCore/option.h" 00063 #include "MagickCore/pixel.h" 00064 #include "MagickCore/pixel-accessor.h" 00065 #include "MagickCore/quantum.h" 00066 #include "MagickCore/quantum-private.h" 00067 #include "MagickCore/resource_.h" 00068 #include "MagickCore/semaphore.h" 00069 #include "MagickCore/statistic.h" 00070 #include "MagickCore/stream.h" 00071 #include "MagickCore/string_.h" 00072 #include "MagickCore/utility.h" 00073 00074 /* 00075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00076 % % 00077 % % 00078 % % 00079 % I m p o r t Q u a n t u m P i x e l s % 00080 % % 00081 % % 00082 % % 00083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00084 % 00085 % ImportQuantumPixels() transfers one or more pixel components from a user 00086 % supplied buffer into the image pixel cache of an image. The pixels are 00087 % expected in network byte order. It returns MagickTrue if the pixels are 00088 % successfully transferred, otherwise MagickFalse. 00089 % 00090 % The format of the ImportQuantumPixels method is: 00091 % 00092 % size_t ImportQuantumPixels(const Image *image,CacheView *image_view, 00093 % QuantumInfo *quantum_info,const QuantumType quantum_type, 00094 % const unsigned char *pixels,ExceptionInfo *exception) 00095 % 00096 % A description of each parameter follows: 00097 % 00098 % o image: the image. 00099 % 00100 % o image_view: the image cache view. 00101 % 00102 % o quantum_info: the quantum info. 00103 % 00104 % o quantum_type: Declare which pixel components to transfer (red, green, 00105 % blue, opacity, RGB, or RGBA). 00106 % 00107 % o pixels: The pixel components are transferred from this buffer. 00108 % 00109 % o exception: return any errors or warnings in this structure. 00110 % 00111 */ 00112 00113 static inline Quantum PushColormapIndex(const Image *image,const size_t index, 00114 MagickBooleanType *range_exception) 00115 { 00116 if (index < image->colors) 00117 return((Quantum) index); 00118 *range_exception=MagickTrue; 00119 return((Quantum) 0); 00120 } 00121 00122 static inline const unsigned char *PushDoublePixel(QuantumInfo *quantum_info, 00123 const unsigned char *pixels,double *pixel) 00124 { 00125 double 00126 *p; 00127 00128 unsigned char 00129 quantum[8]; 00130 00131 if (quantum_info->endian != LSBEndian) 00132 { 00133 quantum[7]=(*pixels++); 00134 quantum[6]=(*pixels++); 00135 quantum[5]=(*pixels++); 00136 quantum[5]=(*pixels++); 00137 quantum[3]=(*pixels++); 00138 quantum[2]=(*pixels++); 00139 quantum[1]=(*pixels++); 00140 quantum[0]=(*pixels++); 00141 p=(double *) quantum; 00142 *pixel=(*p); 00143 *pixel-=quantum_info->minimum; 00144 *pixel*=quantum_info->scale; 00145 return(pixels); 00146 } 00147 quantum[0]=(*pixels++); 00148 quantum[1]=(*pixels++); 00149 quantum[2]=(*pixels++); 00150 quantum[3]=(*pixels++); 00151 quantum[4]=(*pixels++); 00152 quantum[5]=(*pixels++); 00153 quantum[6]=(*pixels++); 00154 quantum[7]=(*pixels++); 00155 p=(double *) quantum; 00156 *pixel=(*p); 00157 *pixel-=quantum_info->minimum; 00158 *pixel*=quantum_info->scale; 00159 return(pixels); 00160 } 00161 00162 static inline const unsigned char *PushFloatPixel(QuantumInfo *quantum_info, 00163 const unsigned char *pixels,float *pixel) 00164 { 00165 float 00166 *p; 00167 00168 unsigned char 00169 quantum[4]; 00170 00171 if (quantum_info->endian != LSBEndian) 00172 { 00173 quantum[3]=(*pixels++); 00174 quantum[2]=(*pixels++); 00175 quantum[1]=(*pixels++); 00176 quantum[0]=(*pixels++); 00177 p=(float *) quantum; 00178 *pixel=(*p); 00179 *pixel-=quantum_info->minimum; 00180 *pixel*=quantum_info->scale; 00181 return(pixels); 00182 } 00183 quantum[0]=(*pixels++); 00184 quantum[1]=(*pixels++); 00185 quantum[2]=(*pixels++); 00186 quantum[3]=(*pixels++); 00187 p=(float *) quantum; 00188 *pixel=(*p); 00189 *pixel-=quantum_info->minimum; 00190 *pixel*=quantum_info->scale; 00191 return(pixels); 00192 } 00193 00194 static inline const unsigned char *PushQuantumPixel(QuantumInfo *quantum_info, 00195 const unsigned char *pixels,unsigned int *quantum) 00196 { 00197 register ssize_t 00198 i; 00199 00200 register size_t 00201 quantum_bits; 00202 00203 *quantum=(QuantumAny) 0; 00204 for (i=(ssize_t) quantum_info->depth; i > 0L; ) 00205 { 00206 if (quantum_info->state.bits == 0UL) 00207 { 00208 quantum_info->state.pixel=(*pixels++); 00209 quantum_info->state.bits=8UL; 00210 } 00211 quantum_bits=(size_t) i; 00212 if (quantum_bits > quantum_info->state.bits) 00213 quantum_bits=quantum_info->state.bits; 00214 i-=(ssize_t) quantum_bits; 00215 quantum_info->state.bits-=quantum_bits; 00216 *quantum=(unsigned int) ((*quantum << quantum_bits) | 00217 ((quantum_info->state.pixel >> quantum_info->state.bits) &~ ((~0UL) << 00218 quantum_bits))); 00219 } 00220 return(pixels); 00221 } 00222 00223 static inline const unsigned char *PushQuantumLongPixel( 00224 QuantumInfo *quantum_info,const unsigned char *pixels,unsigned int *quantum) 00225 { 00226 register ssize_t 00227 i; 00228 00229 register size_t 00230 quantum_bits; 00231 00232 *quantum=0UL; 00233 for (i=(ssize_t) quantum_info->depth; i > 0; ) 00234 { 00235 if (quantum_info->state.bits == 0) 00236 { 00237 pixels=PushLongPixel(quantum_info->endian,pixels, 00238 &quantum_info->state.pixel); 00239 quantum_info->state.bits=32U; 00240 } 00241 quantum_bits=(size_t) i; 00242 if (quantum_bits > quantum_info->state.bits) 00243 quantum_bits=quantum_info->state.bits; 00244 *quantum|=(((quantum_info->state.pixel >> (32U-quantum_info->state.bits)) & 00245 quantum_info->state.mask[quantum_bits]) << (quantum_info->depth-i)); 00246 i-=(ssize_t) quantum_bits; 00247 quantum_info->state.bits-=quantum_bits; 00248 } 00249 return(pixels); 00250 } 00251 00252 static void ImportAlphaQuantum(const Image *image,QuantumInfo *quantum_info, 00253 const MagickSizeType number_pixels,const unsigned char *restrict p, 00254 Quantum *restrict q,ExceptionInfo *exception) 00255 { 00256 QuantumAny 00257 range; 00258 00259 register ssize_t 00260 x; 00261 00262 unsigned int 00263 pixel; 00264 00265 switch (quantum_info->depth) 00266 { 00267 case 8: 00268 { 00269 unsigned char 00270 pixel; 00271 00272 for (x=0; x < (ssize_t) number_pixels; x++) 00273 { 00274 p=PushCharPixel(p,&pixel); 00275 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q); 00276 p+=quantum_info->pad; 00277 q+=GetPixelChannels(image); 00278 } 00279 break; 00280 } 00281 case 16: 00282 { 00283 unsigned short 00284 pixel; 00285 00286 if (quantum_info->format == FloatingPointQuantumFormat) 00287 { 00288 for (x=0; x < (ssize_t) number_pixels; x++) 00289 { 00290 p=PushShortPixel(quantum_info->endian,p,&pixel); 00291 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* 00292 HalfToSinglePrecision(pixel)),q); 00293 p+=quantum_info->pad; 00294 q+=GetPixelChannels(image); 00295 } 00296 break; 00297 } 00298 for (x=0; x < (ssize_t) number_pixels; x++) 00299 { 00300 p=PushShortPixel(quantum_info->endian,p,&pixel); 00301 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q); 00302 p+=quantum_info->pad; 00303 q+=GetPixelChannels(image); 00304 } 00305 break; 00306 } 00307 case 32: 00308 { 00309 unsigned int 00310 pixel; 00311 00312 if (quantum_info->format == FloatingPointQuantumFormat) 00313 { 00314 float 00315 pixel; 00316 00317 for (x=0; x < (ssize_t) number_pixels; x++) 00318 { 00319 p=PushFloatPixel(quantum_info,p,&pixel); 00320 SetPixelAlpha(image,ClampToQuantum(pixel),q); 00321 p+=quantum_info->pad; 00322 q+=GetPixelChannels(image); 00323 } 00324 break; 00325 } 00326 for (x=0; x < (ssize_t) number_pixels; x++) 00327 { 00328 p=PushLongPixel(quantum_info->endian,p,&pixel); 00329 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q); 00330 p+=quantum_info->pad; 00331 q+=GetPixelChannels(image); 00332 } 00333 break; 00334 } 00335 case 64: 00336 { 00337 if (quantum_info->format == FloatingPointQuantumFormat) 00338 { 00339 double 00340 pixel; 00341 00342 for (x=0; x < (ssize_t) number_pixels; x++) 00343 { 00344 p=PushDoublePixel(quantum_info,p,&pixel); 00345 SetPixelAlpha(image,ClampToQuantum(pixel),q); 00346 p+=quantum_info->pad; 00347 q+=GetPixelChannels(image); 00348 } 00349 break; 00350 } 00351 } 00352 default: 00353 { 00354 range=GetQuantumRange(quantum_info->depth); 00355 for (x=0; x < (ssize_t) number_pixels; x++) 00356 { 00357 p=PushQuantumPixel(quantum_info,p,&pixel); 00358 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 00359 p+=quantum_info->pad; 00360 q+=GetPixelChannels(image); 00361 } 00362 break; 00363 } 00364 } 00365 } 00366 00367 static void ImportBGRQuantum(const Image *image,QuantumInfo *quantum_info, 00368 const MagickSizeType number_pixels,const unsigned char *restrict p, 00369 Quantum *restrict q,ExceptionInfo *exception) 00370 { 00371 QuantumAny 00372 range; 00373 00374 register ssize_t 00375 x; 00376 00377 ssize_t 00378 bit; 00379 00380 unsigned int 00381 pixel; 00382 00383 switch (quantum_info->depth) 00384 { 00385 case 8: 00386 { 00387 unsigned char 00388 pixel; 00389 00390 for (x=0; x < (ssize_t) number_pixels; x++) 00391 { 00392 p=PushCharPixel(p,&pixel); 00393 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 00394 p=PushCharPixel(p,&pixel); 00395 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 00396 p=PushCharPixel(p,&pixel); 00397 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 00398 SetPixelAlpha(image,OpaqueAlpha,q); 00399 p+=quantum_info->pad; 00400 q+=GetPixelChannels(image); 00401 } 00402 break; 00403 } 00404 case 10: 00405 { 00406 range=GetQuantumRange(quantum_info->depth); 00407 if (quantum_info->pack == MagickFalse) 00408 { 00409 for (x=0; x < (ssize_t) number_pixels; x++) 00410 { 00411 p=PushLongPixel(quantum_info->endian,p,&pixel); 00412 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q); 00413 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range), 00414 q); 00415 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q); 00416 p+=quantum_info->pad; 00417 q+=GetPixelChannels(image); 00418 } 00419 break; 00420 } 00421 if (quantum_info->quantum == 32U) 00422 { 00423 for (x=0; x < (ssize_t) number_pixels; x++) 00424 { 00425 p=PushQuantumLongPixel(quantum_info,p,&pixel); 00426 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 00427 p=PushQuantumLongPixel(quantum_info,p,&pixel); 00428 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 00429 p=PushQuantumLongPixel(quantum_info,p,&pixel); 00430 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 00431 q+=GetPixelChannels(image); 00432 } 00433 break; 00434 } 00435 for (x=0; x < (ssize_t) number_pixels; x++) 00436 { 00437 p=PushQuantumPixel(quantum_info,p,&pixel); 00438 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 00439 p=PushQuantumPixel(quantum_info,p,&pixel); 00440 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 00441 p=PushQuantumPixel(quantum_info,p,&pixel); 00442 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 00443 q+=GetPixelChannels(image); 00444 } 00445 break; 00446 } 00447 case 12: 00448 { 00449 range=GetQuantumRange(quantum_info->depth); 00450 if (quantum_info->pack == MagickFalse) 00451 { 00452 unsigned short 00453 pixel; 00454 00455 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2) 00456 { 00457 p=PushShortPixel(quantum_info->endian,p,&pixel); 00458 switch (x % 3) 00459 { 00460 default: 00461 case 0: 00462 { 00463 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00464 range),q); 00465 break; 00466 } 00467 case 1: 00468 { 00469 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00470 range),q); 00471 break; 00472 } 00473 case 2: 00474 { 00475 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00476 range),q); 00477 q+=GetPixelChannels(image); 00478 break; 00479 } 00480 } 00481 p=PushShortPixel(quantum_info->endian,p,&pixel); 00482 switch ((x+1) % 3) 00483 { 00484 default: 00485 case 0: 00486 { 00487 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00488 range),q); 00489 break; 00490 } 00491 case 1: 00492 { 00493 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00494 range),q); 00495 break; 00496 } 00497 case 2: 00498 { 00499 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00500 range),q); 00501 q+=GetPixelChannels(image); 00502 break; 00503 } 00504 } 00505 p+=quantum_info->pad; 00506 } 00507 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++) 00508 { 00509 p=PushShortPixel(quantum_info->endian,p,&pixel); 00510 switch ((x+bit) % 3) 00511 { 00512 default: 00513 case 0: 00514 { 00515 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00516 range),q); 00517 break; 00518 } 00519 case 1: 00520 { 00521 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00522 range),q); 00523 break; 00524 } 00525 case 2: 00526 { 00527 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 00528 range),q); 00529 q+=GetPixelChannels(image); 00530 break; 00531 } 00532 } 00533 p+=quantum_info->pad; 00534 } 00535 if (bit != 0) 00536 p++; 00537 break; 00538 } 00539 if (quantum_info->quantum == 32U) 00540 { 00541 for (x=0; x < (ssize_t) number_pixels; x++) 00542 { 00543 p=PushQuantumLongPixel(quantum_info,p,&pixel); 00544 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 00545 p=PushQuantumLongPixel(quantum_info,p,&pixel); 00546 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 00547 p=PushQuantumLongPixel(quantum_info,p,&pixel); 00548 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 00549 q+=GetPixelChannels(image); 00550 } 00551 break; 00552 } 00553 for (x=0; x < (ssize_t) number_pixels; x++) 00554 { 00555 p=PushQuantumPixel(quantum_info,p,&pixel); 00556 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 00557 p=PushQuantumPixel(quantum_info,p,&pixel); 00558 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 00559 p=PushQuantumPixel(quantum_info,p,&pixel); 00560 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 00561 q+=GetPixelChannels(image); 00562 } 00563 break; 00564 } 00565 case 16: 00566 { 00567 unsigned short 00568 pixel; 00569 00570 if (quantum_info->format == FloatingPointQuantumFormat) 00571 { 00572 for (x=0; x < (ssize_t) number_pixels; x++) 00573 { 00574 p=PushShortPixel(quantum_info->endian,p,&pixel); 00575 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 00576 HalfToSinglePrecision(pixel)),q); 00577 p=PushShortPixel(quantum_info->endian,p,&pixel); 00578 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 00579 HalfToSinglePrecision(pixel)),q); 00580 p=PushShortPixel(quantum_info->endian,p,&pixel); 00581 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 00582 HalfToSinglePrecision(pixel)),q); 00583 p+=quantum_info->pad; 00584 q+=GetPixelChannels(image); 00585 } 00586 break; 00587 } 00588 for (x=0; x < (ssize_t) number_pixels; x++) 00589 { 00590 p=PushShortPixel(quantum_info->endian,p,&pixel); 00591 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 00592 p=PushShortPixel(quantum_info->endian,p,&pixel); 00593 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 00594 p=PushShortPixel(quantum_info->endian,p,&pixel); 00595 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 00596 p+=quantum_info->pad; 00597 q+=GetPixelChannels(image); 00598 } 00599 break; 00600 } 00601 case 32: 00602 { 00603 unsigned int 00604 pixel; 00605 00606 if (quantum_info->format == FloatingPointQuantumFormat) 00607 { 00608 float 00609 pixel; 00610 00611 for (x=0; x < (ssize_t) number_pixels; x++) 00612 { 00613 p=PushFloatPixel(quantum_info,p,&pixel); 00614 SetPixelRed(image,ClampToQuantum(pixel),q); 00615 p=PushFloatPixel(quantum_info,p,&pixel); 00616 SetPixelGreen(image,ClampToQuantum(pixel),q); 00617 p=PushFloatPixel(quantum_info,p,&pixel); 00618 SetPixelBlue(image,ClampToQuantum(pixel),q); 00619 p+=quantum_info->pad; 00620 q+=GetPixelChannels(image); 00621 } 00622 break; 00623 } 00624 for (x=0; x < (ssize_t) number_pixels; x++) 00625 { 00626 p=PushLongPixel(quantum_info->endian,p,&pixel); 00627 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 00628 p=PushLongPixel(quantum_info->endian,p,&pixel); 00629 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 00630 p=PushLongPixel(quantum_info->endian,p,&pixel); 00631 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 00632 p+=quantum_info->pad; 00633 q+=GetPixelChannels(image); 00634 } 00635 break; 00636 } 00637 case 64: 00638 { 00639 if (quantum_info->format == FloatingPointQuantumFormat) 00640 { 00641 double 00642 pixel; 00643 00644 for (x=0; x < (ssize_t) number_pixels; x++) 00645 { 00646 p=PushDoublePixel(quantum_info,p,&pixel); 00647 SetPixelRed(image,ClampToQuantum(pixel),q); 00648 p=PushDoublePixel(quantum_info,p,&pixel); 00649 SetPixelGreen(image,ClampToQuantum(pixel),q); 00650 p=PushDoublePixel(quantum_info,p,&pixel); 00651 SetPixelBlue(image,ClampToQuantum(pixel),q); 00652 p+=quantum_info->pad; 00653 q+=GetPixelChannels(image); 00654 } 00655 break; 00656 } 00657 } 00658 default: 00659 { 00660 range=GetQuantumRange(quantum_info->depth); 00661 for (x=0; x < (ssize_t) number_pixels; x++) 00662 { 00663 p=PushQuantumPixel(quantum_info,p,&pixel); 00664 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 00665 p=PushQuantumPixel(quantum_info,p,&pixel); 00666 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 00667 p=PushQuantumPixel(quantum_info,p,&pixel); 00668 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 00669 q+=GetPixelChannels(image); 00670 } 00671 break; 00672 } 00673 } 00674 } 00675 00676 static void ImportBGRAQuantum(const Image *image,QuantumInfo *quantum_info, 00677 const MagickSizeType number_pixels,const unsigned char *restrict p, 00678 Quantum *restrict q,ExceptionInfo *exception) 00679 { 00680 QuantumAny 00681 range; 00682 00683 register ssize_t 00684 x; 00685 00686 unsigned int 00687 pixel; 00688 00689 switch (quantum_info->depth) 00690 { 00691 case 8: 00692 { 00693 unsigned char 00694 pixel; 00695 00696 for (x=0; x < (ssize_t) number_pixels; x++) 00697 { 00698 p=PushCharPixel(p,&pixel); 00699 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 00700 p=PushCharPixel(p,&pixel); 00701 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 00702 p=PushCharPixel(p,&pixel); 00703 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 00704 p=PushCharPixel(p,&pixel); 00705 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q); 00706 p+=quantum_info->pad; 00707 q+=GetPixelChannels(image); 00708 } 00709 break; 00710 } 00711 case 10: 00712 { 00713 pixel=0; 00714 if (quantum_info->pack == MagickFalse) 00715 { 00716 register ssize_t 00717 i; 00718 00719 size_t 00720 quantum; 00721 00722 ssize_t 00723 n; 00724 00725 n=0; 00726 quantum=0; 00727 for (x=0; x < (ssize_t) number_pixels; x++) 00728 { 00729 for (i=0; i < 4; i++) 00730 { 00731 switch (n % 3) 00732 { 00733 case 0: 00734 { 00735 p=PushLongPixel(quantum_info->endian,p,&pixel); 00736 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 00737 (((pixel >> 22) & 0x3ff) << 6))); 00738 break; 00739 } 00740 case 1: 00741 { 00742 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 00743 (((pixel >> 12) & 0x3ff) << 6))); 00744 break; 00745 } 00746 case 2: 00747 { 00748 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 00749 (((pixel >> 2) & 0x3ff) << 6))); 00750 break; 00751 } 00752 } 00753 switch (i) 00754 { 00755 case 0: SetPixelRed(image,(Quantum) quantum,q); break; 00756 case 1: SetPixelGreen(image,(Quantum) quantum,q); break; 00757 case 2: SetPixelBlue(image,(Quantum) quantum,q); break; 00758 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break; 00759 } 00760 n++; 00761 } 00762 p+=quantum_info->pad; 00763 q+=GetPixelChannels(image); 00764 } 00765 break; 00766 } 00767 for (x=0; x < (ssize_t) number_pixels; x++) 00768 { 00769 p=PushQuantumPixel(quantum_info,p,&pixel); 00770 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q); 00771 p=PushQuantumPixel(quantum_info,p,&pixel); 00772 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)), 00773 q); 00774 p=PushQuantumPixel(quantum_info,p,&pixel); 00775 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)), 00776 q); 00777 p=PushQuantumPixel(quantum_info,p,&pixel); 00778 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)), 00779 q); 00780 q+=GetPixelChannels(image); 00781 } 00782 break; 00783 } 00784 case 16: 00785 { 00786 unsigned short 00787 pixel; 00788 00789 if (quantum_info->format == FloatingPointQuantumFormat) 00790 { 00791 for (x=0; x < (ssize_t) number_pixels; x++) 00792 { 00793 p=PushShortPixel(quantum_info->endian,p,&pixel); 00794 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 00795 HalfToSinglePrecision(pixel)),q); 00796 p=PushShortPixel(quantum_info->endian,p,&pixel); 00797 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 00798 HalfToSinglePrecision(pixel)),q); 00799 p=PushShortPixel(quantum_info->endian,p,&pixel); 00800 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 00801 HalfToSinglePrecision(pixel)),q); 00802 p=PushShortPixel(quantum_info->endian,p,&pixel); 00803 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* 00804 HalfToSinglePrecision(pixel)),q); 00805 p+=quantum_info->pad; 00806 q+=GetPixelChannels(image); 00807 } 00808 break; 00809 } 00810 for (x=0; x < (ssize_t) number_pixels; x++) 00811 { 00812 p=PushShortPixel(quantum_info->endian,p,&pixel); 00813 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 00814 p=PushShortPixel(quantum_info->endian,p,&pixel); 00815 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 00816 p=PushShortPixel(quantum_info->endian,p,&pixel); 00817 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 00818 p=PushShortPixel(quantum_info->endian,p,&pixel); 00819 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q); 00820 p+=quantum_info->pad; 00821 q+=GetPixelChannels(image); 00822 } 00823 break; 00824 } 00825 case 32: 00826 { 00827 unsigned int 00828 pixel; 00829 00830 if (quantum_info->format == FloatingPointQuantumFormat) 00831 { 00832 float 00833 pixel; 00834 00835 for (x=0; x < (ssize_t) number_pixels; x++) 00836 { 00837 p=PushFloatPixel(quantum_info,p,&pixel); 00838 SetPixelRed(image,ClampToQuantum(pixel),q); 00839 p=PushFloatPixel(quantum_info,p,&pixel); 00840 SetPixelGreen(image,ClampToQuantum(pixel),q); 00841 p=PushFloatPixel(quantum_info,p,&pixel); 00842 SetPixelBlue(image,ClampToQuantum(pixel),q); 00843 p=PushFloatPixel(quantum_info,p,&pixel); 00844 SetPixelAlpha(image,ClampToQuantum(pixel),q); 00845 p+=quantum_info->pad; 00846 q+=GetPixelChannels(image); 00847 } 00848 break; 00849 } 00850 for (x=0; x < (ssize_t) number_pixels; x++) 00851 { 00852 p=PushLongPixel(quantum_info->endian,p,&pixel); 00853 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 00854 p=PushLongPixel(quantum_info->endian,p,&pixel); 00855 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 00856 p=PushLongPixel(quantum_info->endian,p,&pixel); 00857 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 00858 p=PushLongPixel(quantum_info->endian,p,&pixel); 00859 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q); 00860 p+=quantum_info->pad; 00861 q+=GetPixelChannels(image); 00862 } 00863 break; 00864 } 00865 case 64: 00866 { 00867 if (quantum_info->format == FloatingPointQuantumFormat) 00868 { 00869 double 00870 pixel; 00871 00872 for (x=0; x < (ssize_t) number_pixels; x++) 00873 { 00874 p=PushDoublePixel(quantum_info,p,&pixel); 00875 SetPixelRed(image,ClampToQuantum(pixel),q); 00876 p=PushDoublePixel(quantum_info,p,&pixel); 00877 SetPixelGreen(image,ClampToQuantum(pixel),q); 00878 p=PushDoublePixel(quantum_info,p,&pixel); 00879 SetPixelBlue(image,ClampToQuantum(pixel),q); 00880 p=PushDoublePixel(quantum_info,p,&pixel); 00881 SetPixelAlpha(image,ClampToQuantum(pixel),q); 00882 p+=quantum_info->pad; 00883 q+=GetPixelChannels(image); 00884 } 00885 break; 00886 } 00887 } 00888 default: 00889 { 00890 range=GetQuantumRange(quantum_info->depth); 00891 for (x=0; x < (ssize_t) number_pixels; x++) 00892 { 00893 p=PushQuantumPixel(quantum_info,p,&pixel); 00894 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 00895 p=PushQuantumPixel(quantum_info,p,&pixel); 00896 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 00897 p=PushQuantumPixel(quantum_info,p,&pixel); 00898 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 00899 p=PushQuantumPixel(quantum_info,p,&pixel); 00900 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 00901 q+=GetPixelChannels(image); 00902 } 00903 break; 00904 } 00905 } 00906 } 00907 00908 static void ImportBlackQuantum(const Image *image,QuantumInfo *quantum_info, 00909 const MagickSizeType number_pixels,const unsigned char *restrict p, 00910 Quantum *restrict q,ExceptionInfo *exception) 00911 { 00912 QuantumAny 00913 range; 00914 00915 register ssize_t 00916 x; 00917 00918 unsigned int 00919 pixel; 00920 00921 if (image->colorspace != CMYKColorspace) 00922 { 00923 (void) ThrowMagickException(exception,GetMagickModule(),ImageError, 00924 "ColorSeparatedImageRequired","'%s'",image->filename); 00925 return; 00926 } 00927 switch (quantum_info->depth) 00928 { 00929 case 8: 00930 { 00931 unsigned char 00932 pixel; 00933 00934 for (x=0; x < (ssize_t) number_pixels; x++) 00935 { 00936 p=PushCharPixel(p,&pixel); 00937 SetPixelBlack(image,ScaleCharToQuantum(pixel),q); 00938 p+=quantum_info->pad; 00939 q+=GetPixelChannels(image); 00940 } 00941 break; 00942 } 00943 case 16: 00944 { 00945 unsigned short 00946 pixel; 00947 00948 if (quantum_info->format == FloatingPointQuantumFormat) 00949 { 00950 for (x=0; x < (ssize_t) number_pixels; x++) 00951 { 00952 p=PushShortPixel(quantum_info->endian,p,&pixel); 00953 SetPixelBlack(image,ClampToQuantum((MagickRealType) QuantumRange* 00954 HalfToSinglePrecision(pixel)),q); 00955 p+=quantum_info->pad; 00956 q+=GetPixelChannels(image); 00957 } 00958 break; 00959 } 00960 for (x=0; x < (ssize_t) number_pixels; x++) 00961 { 00962 p=PushShortPixel(quantum_info->endian,p,&pixel); 00963 SetPixelBlack(image,ScaleShortToQuantum(pixel),q); 00964 p+=quantum_info->pad; 00965 q+=GetPixelChannels(image); 00966 } 00967 break; 00968 } 00969 case 32: 00970 { 00971 unsigned int 00972 pixel; 00973 00974 if (quantum_info->format == FloatingPointQuantumFormat) 00975 { 00976 float 00977 pixel; 00978 00979 for (x=0; x < (ssize_t) number_pixels; x++) 00980 { 00981 p=PushFloatPixel(quantum_info,p,&pixel); 00982 SetPixelBlack(image,ClampToQuantum(pixel),q); 00983 p+=quantum_info->pad; 00984 q+=GetPixelChannels(image); 00985 } 00986 break; 00987 } 00988 for (x=0; x < (ssize_t) number_pixels; x++) 00989 { 00990 p=PushLongPixel(quantum_info->endian,p,&pixel); 00991 SetPixelBlack(image,ScaleLongToQuantum(pixel),q); 00992 p+=quantum_info->pad; 00993 q+=GetPixelChannels(image); 00994 } 00995 break; 00996 } 00997 case 64: 00998 { 00999 if (quantum_info->format == FloatingPointQuantumFormat) 01000 { 01001 double 01002 pixel; 01003 01004 for (x=0; x < (ssize_t) number_pixels; x++) 01005 { 01006 p=PushDoublePixel(quantum_info,p,&pixel); 01007 SetPixelBlack(image,ClampToQuantum(pixel),q); 01008 p+=quantum_info->pad; 01009 q+=GetPixelChannels(image); 01010 } 01011 break; 01012 } 01013 } 01014 default: 01015 { 01016 range=GetQuantumRange(quantum_info->depth); 01017 for (x=0; x < (ssize_t) number_pixels; x++) 01018 { 01019 p=PushQuantumPixel(quantum_info,p,&pixel); 01020 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q); 01021 p+=quantum_info->pad; 01022 q+=GetPixelChannels(image); 01023 } 01024 break; 01025 } 01026 } 01027 } 01028 01029 static void ImportBlueQuantum(const Image *image,QuantumInfo *quantum_info, 01030 const MagickSizeType number_pixels,const unsigned char *restrict p, 01031 Quantum *restrict q,ExceptionInfo *exception) 01032 { 01033 QuantumAny 01034 range; 01035 01036 register ssize_t 01037 x; 01038 01039 unsigned int 01040 pixel; 01041 01042 switch (quantum_info->depth) 01043 { 01044 case 8: 01045 { 01046 unsigned char 01047 pixel; 01048 01049 for (x=0; x < (ssize_t) number_pixels; x++) 01050 { 01051 p=PushCharPixel(p,&pixel); 01052 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 01053 p+=quantum_info->pad; 01054 q+=GetPixelChannels(image); 01055 } 01056 break; 01057 } 01058 case 16: 01059 { 01060 unsigned short 01061 pixel; 01062 01063 if (quantum_info->format == FloatingPointQuantumFormat) 01064 { 01065 for (x=0; x < (ssize_t) number_pixels; x++) 01066 { 01067 p=PushShortPixel(quantum_info->endian,p,&pixel); 01068 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 01069 HalfToSinglePrecision(pixel)),q); 01070 p+=quantum_info->pad; 01071 q+=GetPixelChannels(image); 01072 } 01073 break; 01074 } 01075 for (x=0; x < (ssize_t) number_pixels; x++) 01076 { 01077 p=PushShortPixel(quantum_info->endian,p,&pixel); 01078 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 01079 p+=quantum_info->pad; 01080 q+=GetPixelChannels(image); 01081 } 01082 break; 01083 } 01084 case 32: 01085 { 01086 unsigned int 01087 pixel; 01088 01089 if (quantum_info->format == FloatingPointQuantumFormat) 01090 { 01091 float 01092 pixel; 01093 01094 for (x=0; x < (ssize_t) number_pixels; x++) 01095 { 01096 p=PushFloatPixel(quantum_info,p,&pixel); 01097 SetPixelBlue(image,ClampToQuantum(pixel),q); 01098 p+=quantum_info->pad; 01099 q+=GetPixelChannels(image); 01100 } 01101 break; 01102 } 01103 for (x=0; x < (ssize_t) number_pixels; x++) 01104 { 01105 p=PushLongPixel(quantum_info->endian,p,&pixel); 01106 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 01107 p+=quantum_info->pad; 01108 q+=GetPixelChannels(image); 01109 } 01110 break; 01111 } 01112 case 64: 01113 { 01114 if (quantum_info->format == FloatingPointQuantumFormat) 01115 { 01116 double 01117 pixel; 01118 01119 for (x=0; x < (ssize_t) number_pixels; x++) 01120 { 01121 p=PushDoublePixel(quantum_info,p,&pixel); 01122 SetPixelBlue(image,ClampToQuantum(pixel),q); 01123 p+=quantum_info->pad; 01124 q+=GetPixelChannels(image); 01125 } 01126 break; 01127 } 01128 } 01129 default: 01130 { 01131 range=GetQuantumRange(quantum_info->depth); 01132 for (x=0; x < (ssize_t) number_pixels; x++) 01133 { 01134 p=PushQuantumPixel(quantum_info,p,&pixel); 01135 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 01136 p+=quantum_info->pad; 01137 q+=GetPixelChannels(image); 01138 } 01139 break; 01140 } 01141 } 01142 } 01143 01144 static void ImportCbYCrYQuantum(const Image *image,QuantumInfo *quantum_info, 01145 const MagickSizeType number_pixels,const unsigned char *restrict p, 01146 Quantum *restrict q,ExceptionInfo *exception) 01147 { 01148 QuantumAny 01149 range; 01150 01151 register ssize_t 01152 x; 01153 01154 unsigned int 01155 pixel; 01156 01157 switch (quantum_info->depth) 01158 { 01159 case 10: 01160 { 01161 Quantum 01162 cbcr[4]; 01163 01164 pixel=0; 01165 if (quantum_info->pack == MagickFalse) 01166 { 01167 register ssize_t 01168 i; 01169 01170 size_t 01171 quantum; 01172 01173 ssize_t 01174 n; 01175 01176 n=0; 01177 quantum=0; 01178 for (x=0; x < (ssize_t) number_pixels; x+=2) 01179 { 01180 for (i=0; i < 4; i++) 01181 { 01182 switch (n % 3) 01183 { 01184 case 0: 01185 { 01186 p=PushLongPixel(quantum_info->endian,p,&pixel); 01187 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 01188 (((pixel >> 22) & 0x3ff) << 6))); 01189 break; 01190 } 01191 case 1: 01192 { 01193 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 01194 (((pixel >> 12) & 0x3ff) << 6))); 01195 break; 01196 } 01197 case 2: 01198 { 01199 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 01200 (((pixel >> 2) & 0x3ff) << 6))); 01201 break; 01202 } 01203 } 01204 cbcr[i]=(Quantum) (quantum); 01205 n++; 01206 } 01207 p+=quantum_info->pad; 01208 SetPixelRed(image,cbcr[1],q); 01209 SetPixelGreen(image,cbcr[0],q); 01210 SetPixelBlue(image,cbcr[2],q); 01211 q+=GetPixelChannels(image); 01212 SetPixelRed(image,cbcr[3],q); 01213 SetPixelGreen(image,cbcr[0],q); 01214 SetPixelBlue(image,cbcr[2],q); 01215 q+=GetPixelChannels(image); 01216 } 01217 break; 01218 } 01219 } 01220 default: 01221 { 01222 range=GetQuantumRange(quantum_info->depth); 01223 for (x=0; x < (ssize_t) number_pixels; x++) 01224 { 01225 p=PushQuantumPixel(quantum_info,p,&pixel); 01226 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 01227 p=PushQuantumPixel(quantum_info,p,&pixel); 01228 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 01229 q+=GetPixelChannels(image); 01230 } 01231 break; 01232 } 01233 } 01234 } 01235 01236 static void ImportCMYKQuantum(const Image *image,QuantumInfo *quantum_info, 01237 const MagickSizeType number_pixels,const unsigned char *restrict p, 01238 Quantum *restrict q,ExceptionInfo *exception) 01239 { 01240 QuantumAny 01241 range; 01242 01243 register ssize_t 01244 x; 01245 01246 unsigned int 01247 pixel; 01248 01249 if (image->colorspace != CMYKColorspace) 01250 { 01251 (void) ThrowMagickException(exception,GetMagickModule(),ImageError, 01252 "ColorSeparatedImageRequired","'%s'",image->filename); 01253 return; 01254 } 01255 switch (quantum_info->depth) 01256 { 01257 case 8: 01258 { 01259 unsigned char 01260 pixel; 01261 01262 for (x=0; x < (ssize_t) number_pixels; x++) 01263 { 01264 p=PushCharPixel(p,&pixel); 01265 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 01266 p=PushCharPixel(p,&pixel); 01267 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 01268 p=PushCharPixel(p,&pixel); 01269 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 01270 p=PushCharPixel(p,&pixel); 01271 SetPixelBlack(image,ScaleCharToQuantum(pixel),q); 01272 p+=quantum_info->pad; 01273 q+=GetPixelChannels(image); 01274 } 01275 break; 01276 } 01277 case 16: 01278 { 01279 unsigned short 01280 pixel; 01281 01282 if (quantum_info->format == FloatingPointQuantumFormat) 01283 { 01284 for (x=0; x < (ssize_t) number_pixels; x++) 01285 { 01286 p=PushShortPixel(quantum_info->endian,p,&pixel); 01287 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 01288 HalfToSinglePrecision(pixel)),q); 01289 p=PushShortPixel(quantum_info->endian,p,&pixel); 01290 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 01291 HalfToSinglePrecision(pixel)),q); 01292 p=PushShortPixel(quantum_info->endian,p,&pixel); 01293 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 01294 HalfToSinglePrecision(pixel)),q); 01295 p=PushShortPixel(quantum_info->endian,p,&pixel); 01296 SetPixelBlack(image,ClampToQuantum((MagickRealType) QuantumRange* 01297 HalfToSinglePrecision(pixel)),q); 01298 p+=quantum_info->pad; 01299 q+=GetPixelChannels(image); 01300 } 01301 break; 01302 } 01303 for (x=0; x < (ssize_t) number_pixels; x++) 01304 { 01305 p=PushShortPixel(quantum_info->endian,p,&pixel); 01306 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 01307 p=PushShortPixel(quantum_info->endian,p,&pixel); 01308 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 01309 p=PushShortPixel(quantum_info->endian,p,&pixel); 01310 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 01311 p=PushShortPixel(quantum_info->endian,p,&pixel); 01312 SetPixelBlack(image,ScaleShortToQuantum(pixel),q); 01313 p+=quantum_info->pad; 01314 q+=GetPixelChannels(image); 01315 } 01316 break; 01317 } 01318 case 32: 01319 { 01320 unsigned int 01321 pixel; 01322 01323 if (quantum_info->format == FloatingPointQuantumFormat) 01324 { 01325 float 01326 pixel; 01327 01328 for (x=0; x < (ssize_t) number_pixels; x++) 01329 { 01330 p=PushFloatPixel(quantum_info,p,&pixel); 01331 SetPixelRed(image,ClampToQuantum(pixel),q); 01332 p=PushFloatPixel(quantum_info,p,&pixel); 01333 SetPixelGreen(image,ClampToQuantum(pixel),q); 01334 p=PushFloatPixel(quantum_info,p,&pixel); 01335 SetPixelBlue(image,ClampToQuantum(pixel),q); 01336 p=PushFloatPixel(quantum_info,p,&pixel); 01337 SetPixelBlack(image,ClampToQuantum(pixel),q); 01338 p+=quantum_info->pad; 01339 q+=GetPixelChannels(image); 01340 } 01341 break; 01342 } 01343 for (x=0; x < (ssize_t) number_pixels; x++) 01344 { 01345 p=PushLongPixel(quantum_info->endian,p,&pixel); 01346 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 01347 p=PushLongPixel(quantum_info->endian,p,&pixel); 01348 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 01349 p=PushLongPixel(quantum_info->endian,p,&pixel); 01350 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 01351 p=PushLongPixel(quantum_info->endian,p,&pixel); 01352 SetPixelBlack(image,ScaleLongToQuantum(pixel),q); 01353 p+=quantum_info->pad; 01354 q+=GetPixelChannels(image); 01355 } 01356 break; 01357 } 01358 case 64: 01359 { 01360 if (quantum_info->format == FloatingPointQuantumFormat) 01361 { 01362 double 01363 pixel; 01364 01365 for (x=0; x < (ssize_t) number_pixels; x++) 01366 { 01367 p=PushDoublePixel(quantum_info,p,&pixel); 01368 SetPixelRed(image,ClampToQuantum(pixel),q); 01369 p=PushDoublePixel(quantum_info,p,&pixel); 01370 SetPixelGreen(image,ClampToQuantum(pixel),q); 01371 p=PushDoublePixel(quantum_info,p,&pixel); 01372 SetPixelBlue(image,ClampToQuantum(pixel),q); 01373 p=PushDoublePixel(quantum_info,p,&pixel); 01374 SetPixelBlack(image,ClampToQuantum(pixel),q); 01375 p+=quantum_info->pad; 01376 q+=GetPixelChannels(image); 01377 } 01378 break; 01379 } 01380 } 01381 default: 01382 { 01383 range=GetQuantumRange(quantum_info->depth); 01384 for (x=0; x < (ssize_t) number_pixels; x++) 01385 { 01386 p=PushQuantumPixel(quantum_info,p,&pixel); 01387 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 01388 p=PushQuantumPixel(quantum_info,p,&pixel); 01389 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 01390 p=PushQuantumPixel(quantum_info,p,&pixel); 01391 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 01392 p=PushQuantumPixel(quantum_info,p,&pixel); 01393 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q); 01394 q+=GetPixelChannels(image); 01395 } 01396 break; 01397 } 01398 } 01399 } 01400 01401 static void ImportCMYKAQuantum(const Image *image,QuantumInfo *quantum_info, 01402 const MagickSizeType number_pixels,const unsigned char *restrict p, 01403 Quantum *restrict q,ExceptionInfo *exception) 01404 { 01405 QuantumAny 01406 range; 01407 01408 register ssize_t 01409 x; 01410 01411 unsigned int 01412 pixel; 01413 01414 if (image->colorspace != CMYKColorspace) 01415 { 01416 (void) ThrowMagickException(exception,GetMagickModule(),ImageError, 01417 "ColorSeparatedImageRequired","'%s'",image->filename); 01418 return; 01419 } 01420 switch (quantum_info->depth) 01421 { 01422 case 8: 01423 { 01424 unsigned char 01425 pixel; 01426 01427 for (x=0; x < (ssize_t) number_pixels; x++) 01428 { 01429 p=PushCharPixel(p,&pixel); 01430 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 01431 p=PushCharPixel(p,&pixel); 01432 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 01433 p=PushCharPixel(p,&pixel); 01434 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 01435 p=PushCharPixel(p,&pixel); 01436 SetPixelBlack(image,ScaleCharToQuantum(pixel),q); 01437 p=PushCharPixel(p,&pixel); 01438 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q); 01439 p+=quantum_info->pad; 01440 q+=GetPixelChannels(image); 01441 } 01442 break; 01443 } 01444 case 16: 01445 { 01446 unsigned short 01447 pixel; 01448 01449 if (quantum_info->format == FloatingPointQuantumFormat) 01450 { 01451 for (x=0; x < (ssize_t) number_pixels; x++) 01452 { 01453 p=PushShortPixel(quantum_info->endian,p,&pixel); 01454 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 01455 HalfToSinglePrecision(pixel)),q); 01456 p=PushShortPixel(quantum_info->endian,p,&pixel); 01457 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 01458 HalfToSinglePrecision(pixel)),q); 01459 p=PushShortPixel(quantum_info->endian,p,&pixel); 01460 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 01461 HalfToSinglePrecision(pixel)),q); 01462 p=PushShortPixel(quantum_info->endian,p,&pixel); 01463 SetPixelBlack(image,ClampToQuantum((MagickRealType) QuantumRange* 01464 HalfToSinglePrecision(pixel)),q); 01465 p=PushShortPixel(quantum_info->endian,p,&pixel); 01466 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* 01467 HalfToSinglePrecision(pixel)),q); 01468 p+=quantum_info->pad; 01469 q+=GetPixelChannels(image); 01470 } 01471 break; 01472 } 01473 for (x=0; x < (ssize_t) number_pixels; x++) 01474 { 01475 p=PushShortPixel(quantum_info->endian,p,&pixel); 01476 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 01477 p=PushShortPixel(quantum_info->endian,p,&pixel); 01478 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 01479 p=PushShortPixel(quantum_info->endian,p,&pixel); 01480 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 01481 p=PushShortPixel(quantum_info->endian,p,&pixel); 01482 SetPixelBlack(image,ScaleShortToQuantum(pixel),q); 01483 p=PushShortPixel(quantum_info->endian,p,&pixel); 01484 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q); 01485 p+=quantum_info->pad; 01486 q+=GetPixelChannels(image); 01487 } 01488 break; 01489 } 01490 case 32: 01491 { 01492 unsigned int 01493 pixel; 01494 01495 if (quantum_info->format == FloatingPointQuantumFormat) 01496 { 01497 float 01498 pixel; 01499 01500 for (x=0; x < (ssize_t) number_pixels; x++) 01501 { 01502 p=PushFloatPixel(quantum_info,p,&pixel); 01503 SetPixelRed(image,ClampToQuantum(pixel),q); 01504 p=PushFloatPixel(quantum_info,p,&pixel); 01505 SetPixelGreen(image,ClampToQuantum(pixel),q); 01506 p=PushFloatPixel(quantum_info,p,&pixel); 01507 SetPixelBlue(image,ClampToQuantum(pixel),q); 01508 p=PushFloatPixel(quantum_info,p,&pixel); 01509 SetPixelBlack(image,ClampToQuantum(pixel),q); 01510 p=PushFloatPixel(quantum_info,p,&pixel); 01511 SetPixelAlpha(image,ClampToQuantum(pixel),q); 01512 p+=quantum_info->pad; 01513 q+=GetPixelChannels(image); 01514 } 01515 break; 01516 } 01517 for (x=0; x < (ssize_t) number_pixels; x++) 01518 { 01519 p=PushLongPixel(quantum_info->endian,p,&pixel); 01520 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 01521 p=PushLongPixel(quantum_info->endian,p,&pixel); 01522 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 01523 p=PushLongPixel(quantum_info->endian,p,&pixel); 01524 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 01525 p=PushLongPixel(quantum_info->endian,p,&pixel); 01526 SetPixelBlack(image,ScaleLongToQuantum(pixel),q); 01527 p=PushLongPixel(quantum_info->endian,p,&pixel); 01528 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q); 01529 p+=quantum_info->pad; 01530 q+=GetPixelChannels(image); 01531 } 01532 break; 01533 } 01534 case 64: 01535 { 01536 if (quantum_info->format == FloatingPointQuantumFormat) 01537 { 01538 double 01539 pixel; 01540 01541 for (x=0; x < (ssize_t) number_pixels; x++) 01542 { 01543 p=PushDoublePixel(quantum_info,p,&pixel); 01544 SetPixelRed(image,ClampToQuantum(pixel),q); 01545 p=PushDoublePixel(quantum_info,p,&pixel); 01546 SetPixelGreen(image,ClampToQuantum(pixel),q); 01547 p=PushDoublePixel(quantum_info,p,&pixel); 01548 SetPixelBlue(image,ClampToQuantum(pixel),q); 01549 p=PushDoublePixel(quantum_info,p,&pixel); 01550 SetPixelBlack(image,ClampToQuantum(pixel),q); 01551 p=PushDoublePixel(quantum_info,p,&pixel); 01552 SetPixelAlpha(image,ClampToQuantum(pixel),q); 01553 p=PushDoublePixel(quantum_info,p,&pixel); 01554 p+=quantum_info->pad; 01555 q+=GetPixelChannels(image); 01556 } 01557 break; 01558 } 01559 } 01560 default: 01561 { 01562 range=GetQuantumRange(quantum_info->depth); 01563 for (x=0; x < (ssize_t) number_pixels; x++) 01564 { 01565 p=PushQuantumPixel(quantum_info,p,&pixel); 01566 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 01567 p=PushQuantumPixel(quantum_info,p,&pixel); 01568 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 01569 p=PushQuantumPixel(quantum_info,p,&pixel); 01570 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 01571 p=PushQuantumPixel(quantum_info,p,&pixel); 01572 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q); 01573 p=PushQuantumPixel(quantum_info,p,&pixel); 01574 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 01575 q+=GetPixelChannels(image); 01576 } 01577 break; 01578 } 01579 } 01580 } 01581 01582 static void ImportGrayQuantum(const Image *image,QuantumInfo *quantum_info, 01583 const MagickSizeType number_pixels,const unsigned char *restrict p, 01584 Quantum *restrict q,ExceptionInfo *exception) 01585 { 01586 QuantumAny 01587 range; 01588 01589 register ssize_t 01590 x; 01591 01592 ssize_t 01593 bit; 01594 01595 unsigned int 01596 pixel; 01597 01598 switch (quantum_info->depth) 01599 { 01600 case 1: 01601 { 01602 register Quantum 01603 black, 01604 white; 01605 01606 black=0; 01607 white=(Quantum) QuantumRange; 01608 if (quantum_info->min_is_white != MagickFalse) 01609 { 01610 black=(Quantum) QuantumRange; 01611 white=0; 01612 } 01613 for (x=0; x < ((ssize_t) number_pixels-7); x+=8) 01614 { 01615 for (bit=0; bit < 8; bit++) 01616 { 01617 SetPixelGray(image,((*p) & (1 << (7-bit))) == 0 ? black : white,q); 01618 q+=GetPixelChannels(image); 01619 } 01620 p++; 01621 } 01622 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++) 01623 { 01624 SetPixelGray(image,((*p) & (0x01 << (7-bit))) == 0 ? black : white,q); 01625 q+=GetPixelChannels(image); 01626 } 01627 if (bit != 0) 01628 p++; 01629 break; 01630 } 01631 case 4: 01632 { 01633 register unsigned char 01634 pixel; 01635 01636 range=GetQuantumRange(quantum_info->depth); 01637 for (x=0; x < ((ssize_t) number_pixels-1); x+=2) 01638 { 01639 pixel=(unsigned char) ((*p >> 4) & 0xf); 01640 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01641 q+=GetPixelChannels(image); 01642 pixel=(unsigned char) ((*p) & 0xf); 01643 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01644 p++; 01645 q+=GetPixelChannels(image); 01646 } 01647 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++) 01648 { 01649 pixel=(unsigned char) (*p++ >> 4); 01650 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01651 q+=GetPixelChannels(image); 01652 } 01653 break; 01654 } 01655 case 8: 01656 { 01657 unsigned char 01658 pixel; 01659 01660 if (quantum_info->min_is_white != MagickFalse) 01661 { 01662 for (x=0; x < (ssize_t) number_pixels; x++) 01663 { 01664 p=PushCharPixel(p,&pixel); 01665 SetPixelGray(image,ScaleCharToQuantum(pixel),q); 01666 SetPixelAlpha(image,OpaqueAlpha,q); 01667 p+=quantum_info->pad; 01668 q+=GetPixelChannels(image); 01669 } 01670 break; 01671 } 01672 for (x=0; x < (ssize_t) number_pixels; x++) 01673 { 01674 p=PushCharPixel(p,&pixel); 01675 SetPixelGray(image,ScaleCharToQuantum(pixel),q); 01676 SetPixelAlpha(image,OpaqueAlpha,q); 01677 p+=quantum_info->pad; 01678 q+=GetPixelChannels(image); 01679 } 01680 break; 01681 } 01682 case 10: 01683 { 01684 range=GetQuantumRange(quantum_info->depth); 01685 if (quantum_info->pack == MagickFalse) 01686 { 01687 if (image->endian != LSBEndian) 01688 { 01689 for (x=0; x < (ssize_t) (number_pixels-2); x+=3) 01690 { 01691 p=PushLongPixel(quantum_info->endian,p,&pixel); 01692 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff, 01693 range),q); 01694 q+=GetPixelChannels(image); 01695 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff, 01696 range),q); 01697 q+=GetPixelChannels(image); 01698 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff, 01699 range),q); 01700 p+=quantum_info->pad; 01701 q+=GetPixelChannels(image); 01702 } 01703 p=PushLongPixel(quantum_info->endian,p,&pixel); 01704 if (x++ < (ssize_t) (number_pixels-1)) 01705 { 01706 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff, 01707 range),q); 01708 q+=GetPixelChannels(image); 01709 } 01710 if (x++ < (ssize_t) number_pixels) 01711 { 01712 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff, 01713 range),q); 01714 q+=GetPixelChannels(image); 01715 } 01716 break; 01717 } 01718 for (x=0; x < (ssize_t) (number_pixels-2); x+=3) 01719 { 01720 p=PushLongPixel(quantum_info->endian,p,&pixel); 01721 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range), 01722 q); 01723 q+=GetPixelChannels(image); 01724 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range), 01725 q); 01726 q+=GetPixelChannels(image); 01727 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range), 01728 q); 01729 p+=quantum_info->pad; 01730 q+=GetPixelChannels(image); 01731 } 01732 p=PushLongPixel(quantum_info->endian,p,&pixel); 01733 if (x++ < (ssize_t) (number_pixels-1)) 01734 { 01735 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range), 01736 q); 01737 q+=GetPixelChannels(image); 01738 } 01739 if (x++ < (ssize_t) number_pixels) 01740 { 01741 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range), 01742 q); 01743 q+=GetPixelChannels(image); 01744 } 01745 break; 01746 } 01747 for (x=0; x < (ssize_t) number_pixels; x++) 01748 { 01749 p=PushQuantumPixel(quantum_info,p,&pixel); 01750 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01751 p+=quantum_info->pad; 01752 q+=GetPixelChannels(image); 01753 } 01754 break; 01755 } 01756 case 12: 01757 { 01758 range=GetQuantumRange(quantum_info->depth); 01759 if (quantum_info->pack == MagickFalse) 01760 { 01761 unsigned short 01762 pixel; 01763 01764 for (x=0; x < (ssize_t) (number_pixels-1); x+=2) 01765 { 01766 p=PushShortPixel(quantum_info->endian,p,&pixel); 01767 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 01768 range),q); 01769 q+=GetPixelChannels(image); 01770 p=PushShortPixel(quantum_info->endian,p,&pixel); 01771 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 01772 range),q); 01773 p+=quantum_info->pad; 01774 q+=GetPixelChannels(image); 01775 } 01776 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++) 01777 { 01778 p=PushShortPixel(quantum_info->endian,p,&pixel); 01779 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 01780 range),q); 01781 p+=quantum_info->pad; 01782 q+=GetPixelChannels(image); 01783 } 01784 if (bit != 0) 01785 p++; 01786 break; 01787 } 01788 for (x=0; x < (ssize_t) number_pixels; x++) 01789 { 01790 p=PushQuantumPixel(quantum_info,p,&pixel); 01791 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01792 p+=quantum_info->pad; 01793 q+=GetPixelChannels(image); 01794 } 01795 break; 01796 } 01797 case 16: 01798 { 01799 unsigned short 01800 pixel; 01801 01802 if (quantum_info->min_is_white != MagickFalse) 01803 { 01804 for (x=0; x < (ssize_t) number_pixels; x++) 01805 { 01806 p=PushShortPixel(quantum_info->endian,p,&pixel); 01807 SetPixelGray(image,ScaleShortToQuantum(pixel),q); 01808 p+=quantum_info->pad; 01809 q+=GetPixelChannels(image); 01810 } 01811 break; 01812 } 01813 if (quantum_info->format == FloatingPointQuantumFormat) 01814 { 01815 for (x=0; x < (ssize_t) number_pixels; x++) 01816 { 01817 p=PushShortPixel(quantum_info->endian,p,&pixel); 01818 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange* 01819 HalfToSinglePrecision(pixel)),q); 01820 p+=quantum_info->pad; 01821 q+=GetPixelChannels(image); 01822 } 01823 break; 01824 } 01825 for (x=0; x < (ssize_t) number_pixels; x++) 01826 { 01827 p=PushShortPixel(quantum_info->endian,p,&pixel); 01828 SetPixelGray(image,ScaleShortToQuantum(pixel),q); 01829 p+=quantum_info->pad; 01830 q+=GetPixelChannels(image); 01831 } 01832 break; 01833 } 01834 case 32: 01835 { 01836 unsigned int 01837 pixel; 01838 01839 if (quantum_info->format == FloatingPointQuantumFormat) 01840 { 01841 float 01842 pixel; 01843 01844 for (x=0; x < (ssize_t) number_pixels; x++) 01845 { 01846 p=PushFloatPixel(quantum_info,p,&pixel); 01847 SetPixelGray(image,ClampToQuantum(pixel),q); 01848 p+=quantum_info->pad; 01849 q+=GetPixelChannels(image); 01850 } 01851 break; 01852 } 01853 for (x=0; x < (ssize_t) number_pixels; x++) 01854 { 01855 p=PushLongPixel(quantum_info->endian,p,&pixel); 01856 SetPixelGray(image,ScaleLongToQuantum(pixel),q); 01857 p+=quantum_info->pad; 01858 q+=GetPixelChannels(image); 01859 } 01860 break; 01861 } 01862 case 64: 01863 { 01864 if (quantum_info->format == FloatingPointQuantumFormat) 01865 { 01866 double 01867 pixel; 01868 01869 for (x=0; x < (ssize_t) number_pixels; x++) 01870 { 01871 p=PushDoublePixel(quantum_info,p,&pixel); 01872 SetPixelGray(image,ClampToQuantum(pixel),q); 01873 p+=quantum_info->pad; 01874 q+=GetPixelChannels(image); 01875 } 01876 break; 01877 } 01878 } 01879 default: 01880 { 01881 range=GetQuantumRange(quantum_info->depth); 01882 for (x=0; x < (ssize_t) number_pixels; x++) 01883 { 01884 p=PushQuantumPixel(quantum_info,p,&pixel); 01885 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01886 p+=quantum_info->pad; 01887 q+=GetPixelChannels(image); 01888 } 01889 break; 01890 } 01891 } 01892 } 01893 01894 static void ImportGrayAlphaQuantum(const Image *image,QuantumInfo *quantum_info, 01895 const MagickSizeType number_pixels,const unsigned char *restrict p, 01896 Quantum *restrict q,ExceptionInfo *exception) 01897 { 01898 QuantumAny 01899 range; 01900 01901 register ssize_t 01902 x; 01903 01904 ssize_t 01905 bit; 01906 01907 unsigned int 01908 pixel; 01909 01910 switch (quantum_info->depth) 01911 { 01912 case 1: 01913 { 01914 register unsigned char 01915 pixel; 01916 01917 for (x=((ssize_t) number_pixels-3); x > 0; x-=4) 01918 { 01919 for (bit=0; bit < 8; bit+=2) 01920 { 01921 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01); 01922 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q); 01923 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ? 01924 TransparentAlpha : OpaqueAlpha,q); 01925 q+=GetPixelChannels(image); 01926 } 01927 p++; 01928 } 01929 if ((number_pixels % 4) != 0) 01930 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2) 01931 { 01932 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01); 01933 SetPixelGray(image,(Quantum) (pixel != 0 ? 0 : QuantumRange),q); 01934 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ? 01935 TransparentAlpha : OpaqueAlpha,q); 01936 q+=GetPixelChannels(image); 01937 } 01938 if (bit != 0) 01939 p++; 01940 break; 01941 } 01942 case 4: 01943 { 01944 register unsigned char 01945 pixel; 01946 01947 range=GetQuantumRange(quantum_info->depth); 01948 for (x=0; x < (ssize_t) number_pixels; x++) 01949 { 01950 pixel=(unsigned char) ((*p >> 4) & 0xf); 01951 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01952 pixel=(unsigned char) ((*p) & 0xf); 01953 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 01954 p++; 01955 q+=GetPixelChannels(image); 01956 } 01957 break; 01958 } 01959 case 8: 01960 { 01961 unsigned char 01962 pixel; 01963 01964 for (x=0; x < (ssize_t) number_pixels; x++) 01965 { 01966 p=PushCharPixel(p,&pixel); 01967 SetPixelGray(image,ScaleCharToQuantum(pixel),q); 01968 p=PushCharPixel(p,&pixel); 01969 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q); 01970 p+=quantum_info->pad; 01971 q+=GetPixelChannels(image); 01972 } 01973 break; 01974 } 01975 case 10: 01976 { 01977 range=GetQuantumRange(quantum_info->depth); 01978 for (x=0; x < (ssize_t) number_pixels; x++) 01979 { 01980 p=PushQuantumPixel(quantum_info,p,&pixel); 01981 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01982 p=PushQuantumPixel(quantum_info,p,&pixel); 01983 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 01984 p+=quantum_info->pad; 01985 q+=GetPixelChannels(image); 01986 } 01987 break; 01988 } 01989 case 12: 01990 { 01991 range=GetQuantumRange(quantum_info->depth); 01992 for (x=0; x < (ssize_t) number_pixels; x++) 01993 { 01994 p=PushQuantumPixel(quantum_info,p,&pixel); 01995 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 01996 p=PushQuantumPixel(quantum_info,p,&pixel); 01997 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 01998 p+=quantum_info->pad; 01999 q+=GetPixelChannels(image); 02000 } 02001 break; 02002 } 02003 case 16: 02004 { 02005 unsigned short 02006 pixel; 02007 02008 if (quantum_info->format == FloatingPointQuantumFormat) 02009 { 02010 for (x=0; x < (ssize_t) number_pixels; x++) 02011 { 02012 p=PushShortPixel(quantum_info->endian,p,&pixel); 02013 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange* 02014 HalfToSinglePrecision(pixel)),q); 02015 p=PushShortPixel(quantum_info->endian,p,&pixel); 02016 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* 02017 HalfToSinglePrecision(pixel)),q); 02018 p+=quantum_info->pad; 02019 q+=GetPixelChannels(image); 02020 } 02021 break; 02022 } 02023 for (x=0; x < (ssize_t) number_pixels; x++) 02024 { 02025 p=PushShortPixel(quantum_info->endian,p,&pixel); 02026 SetPixelGray(image,ScaleShortToQuantum(pixel),q); 02027 p=PushShortPixel(quantum_info->endian,p,&pixel); 02028 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q); 02029 p+=quantum_info->pad; 02030 q+=GetPixelChannels(image); 02031 } 02032 break; 02033 } 02034 case 32: 02035 { 02036 unsigned int 02037 pixel; 02038 02039 if (quantum_info->format == FloatingPointQuantumFormat) 02040 { 02041 float 02042 pixel; 02043 02044 for (x=0; x < (ssize_t) number_pixels; x++) 02045 { 02046 p=PushFloatPixel(quantum_info,p,&pixel); 02047 SetPixelGray(image,ClampToQuantum(pixel),q); 02048 p=PushFloatPixel(quantum_info,p,&pixel); 02049 SetPixelAlpha(image,ClampToQuantum(pixel),q); 02050 p+=quantum_info->pad; 02051 q+=GetPixelChannels(image); 02052 } 02053 break; 02054 } 02055 for (x=0; x < (ssize_t) number_pixels; x++) 02056 { 02057 p=PushLongPixel(quantum_info->endian,p,&pixel); 02058 SetPixelGray(image,ScaleLongToQuantum(pixel),q); 02059 p=PushLongPixel(quantum_info->endian,p,&pixel); 02060 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q); 02061 p+=quantum_info->pad; 02062 q+=GetPixelChannels(image); 02063 } 02064 break; 02065 } 02066 case 64: 02067 { 02068 if (quantum_info->format == FloatingPointQuantumFormat) 02069 { 02070 double 02071 pixel; 02072 02073 for (x=0; x < (ssize_t) number_pixels; x++) 02074 { 02075 p=PushDoublePixel(quantum_info,p,&pixel); 02076 SetPixelGray(image,ClampToQuantum(pixel),q); 02077 p=PushDoublePixel(quantum_info,p,&pixel); 02078 SetPixelAlpha(image,ClampToQuantum(pixel),q); 02079 p+=quantum_info->pad; 02080 q+=GetPixelChannels(image); 02081 } 02082 break; 02083 } 02084 } 02085 default: 02086 { 02087 range=GetQuantumRange(quantum_info->depth); 02088 for (x=0; x < (ssize_t) number_pixels; x++) 02089 { 02090 p=PushQuantumPixel(quantum_info,p,&pixel); 02091 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q); 02092 p=PushQuantumPixel(quantum_info,p,&pixel); 02093 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 02094 p+=quantum_info->pad; 02095 q+=GetPixelChannels(image); 02096 } 02097 break; 02098 } 02099 } 02100 } 02101 02102 static void ImportGreenQuantum(const Image *image,QuantumInfo *quantum_info, 02103 const MagickSizeType number_pixels,const unsigned char *restrict p, 02104 Quantum *restrict q,ExceptionInfo *exception) 02105 { 02106 QuantumAny 02107 range; 02108 02109 register ssize_t 02110 x; 02111 02112 unsigned int 02113 pixel; 02114 02115 switch (quantum_info->depth) 02116 { 02117 case 8: 02118 { 02119 unsigned char 02120 pixel; 02121 02122 for (x=0; x < (ssize_t) number_pixels; x++) 02123 { 02124 p=PushCharPixel(p,&pixel); 02125 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 02126 p+=quantum_info->pad; 02127 q+=GetPixelChannels(image); 02128 } 02129 break; 02130 } 02131 case 16: 02132 { 02133 unsigned short 02134 pixel; 02135 02136 if (quantum_info->format == FloatingPointQuantumFormat) 02137 { 02138 for (x=0; x < (ssize_t) number_pixels; x++) 02139 { 02140 p=PushShortPixel(quantum_info->endian,p,&pixel); 02141 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 02142 HalfToSinglePrecision(pixel)),q); 02143 p+=quantum_info->pad; 02144 q+=GetPixelChannels(image); 02145 } 02146 break; 02147 } 02148 for (x=0; x < (ssize_t) number_pixels; x++) 02149 { 02150 p=PushShortPixel(quantum_info->endian,p,&pixel); 02151 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 02152 p+=quantum_info->pad; 02153 q+=GetPixelChannels(image); 02154 } 02155 break; 02156 } 02157 case 32: 02158 { 02159 unsigned int 02160 pixel; 02161 02162 if (quantum_info->format == FloatingPointQuantumFormat) 02163 { 02164 float 02165 pixel; 02166 02167 for (x=0; x < (ssize_t) number_pixels; x++) 02168 { 02169 p=PushFloatPixel(quantum_info,p,&pixel); 02170 SetPixelGreen(image,ClampToQuantum(pixel),q); 02171 p+=quantum_info->pad; 02172 q+=GetPixelChannels(image); 02173 } 02174 break; 02175 } 02176 for (x=0; x < (ssize_t) number_pixels; x++) 02177 { 02178 p=PushLongPixel(quantum_info->endian,p,&pixel); 02179 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 02180 p+=quantum_info->pad; 02181 q+=GetPixelChannels(image); 02182 } 02183 break; 02184 } 02185 case 64: 02186 { 02187 if (quantum_info->format == FloatingPointQuantumFormat) 02188 { 02189 double 02190 pixel; 02191 02192 for (x=0; x < (ssize_t) number_pixels; x++) 02193 { 02194 p=PushDoublePixel(quantum_info,p,&pixel); 02195 SetPixelGreen(image,ClampToQuantum(pixel),q); 02196 p+=quantum_info->pad; 02197 q+=GetPixelChannels(image); 02198 } 02199 break; 02200 } 02201 } 02202 default: 02203 { 02204 range=GetQuantumRange(quantum_info->depth); 02205 for (x=0; x < (ssize_t) number_pixels; x++) 02206 { 02207 p=PushQuantumPixel(quantum_info,p,&pixel); 02208 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 02209 p+=quantum_info->pad; 02210 q+=GetPixelChannels(image); 02211 } 02212 break; 02213 } 02214 } 02215 } 02216 02217 static void ImportIndexQuantum(const Image *image,QuantumInfo *quantum_info, 02218 const MagickSizeType number_pixels,const unsigned char *restrict p, 02219 Quantum *restrict q,ExceptionInfo *exception) 02220 { 02221 MagickBooleanType 02222 range_exception; 02223 02224 register ssize_t 02225 x; 02226 02227 ssize_t 02228 bit; 02229 02230 unsigned int 02231 pixel; 02232 02233 if (image->storage_class != PseudoClass) 02234 { 02235 (void) ThrowMagickException(exception,GetMagickModule(),ImageError, 02236 "ColormappedImageRequired","'%s'",image->filename); 02237 return; 02238 } 02239 range_exception=MagickFalse; 02240 switch (quantum_info->depth) 02241 { 02242 case 1: 02243 { 02244 register unsigned char 02245 pixel; 02246 02247 for (x=0; x < ((ssize_t) number_pixels-7); x+=8) 02248 { 02249 for (bit=0; bit < 8; bit++) 02250 { 02251 if (quantum_info->min_is_white == MagickFalse) 02252 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 02253 0x00 : 0x01); 02254 else 02255 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 02256 0x00 : 0x01); 02257 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception), 02258 q); 02259 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02260 GetPixelIndex(image,q),q); 02261 q+=GetPixelChannels(image); 02262 } 02263 p++; 02264 } 02265 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++) 02266 { 02267 if (quantum_info->min_is_white == MagickFalse) 02268 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01); 02269 else 02270 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01); 02271 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02272 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02273 GetPixelIndex(image,q),q); 02274 q+=GetPixelChannels(image); 02275 } 02276 break; 02277 } 02278 case 4: 02279 { 02280 register unsigned char 02281 pixel; 02282 02283 for (x=0; x < ((ssize_t) number_pixels-1); x+=2) 02284 { 02285 pixel=(unsigned char) ((*p >> 4) & 0xf); 02286 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02287 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02288 GetPixelIndex(image,q),q); 02289 q+=GetPixelChannels(image); 02290 pixel=(unsigned char) ((*p) & 0xf); 02291 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02292 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02293 GetPixelIndex(image,q),q); 02294 p++; 02295 q+=GetPixelChannels(image); 02296 } 02297 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++) 02298 { 02299 pixel=(unsigned char) ((*p++ >> 4) & 0xf); 02300 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02301 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02302 GetPixelIndex(image,q),q); 02303 q+=GetPixelChannels(image); 02304 } 02305 break; 02306 } 02307 case 8: 02308 { 02309 unsigned char 02310 pixel; 02311 02312 for (x=0; x < (ssize_t) number_pixels; x++) 02313 { 02314 p=PushCharPixel(p,&pixel); 02315 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02316 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02317 GetPixelIndex(image,q),q); 02318 p+=quantum_info->pad; 02319 q+=GetPixelChannels(image); 02320 } 02321 break; 02322 } 02323 case 16: 02324 { 02325 unsigned short 02326 pixel; 02327 02328 if (quantum_info->format == FloatingPointQuantumFormat) 02329 { 02330 for (x=0; x < (ssize_t) number_pixels; x++) 02331 { 02332 p=PushShortPixel(quantum_info->endian,p,&pixel); 02333 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum( 02334 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)), 02335 &range_exception),q); 02336 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02337 GetPixelIndex(image,q),q); 02338 p+=quantum_info->pad; 02339 q+=GetPixelChannels(image); 02340 } 02341 break; 02342 } 02343 for (x=0; x < (ssize_t) number_pixels; x++) 02344 { 02345 p=PushShortPixel(quantum_info->endian,p,&pixel); 02346 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02347 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02348 GetPixelIndex(image,q),q); 02349 p+=quantum_info->pad; 02350 q+=GetPixelChannels(image); 02351 } 02352 break; 02353 } 02354 case 32: 02355 { 02356 unsigned int 02357 pixel; 02358 02359 if (quantum_info->format == FloatingPointQuantumFormat) 02360 { 02361 float 02362 pixel; 02363 02364 for (x=0; x < (ssize_t) number_pixels; x++) 02365 { 02366 p=PushFloatPixel(quantum_info,p,&pixel); 02367 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel), 02368 &range_exception),q); 02369 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02370 GetPixelIndex(image,q),q); 02371 p+=quantum_info->pad; 02372 q+=GetPixelChannels(image); 02373 } 02374 break; 02375 } 02376 for (x=0; x < (ssize_t) number_pixels; x++) 02377 { 02378 p=PushLongPixel(quantum_info->endian,p,&pixel); 02379 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02380 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02381 GetPixelIndex(image,q),q); 02382 p+=quantum_info->pad; 02383 q+=GetPixelChannels(image); 02384 } 02385 break; 02386 } 02387 case 64: 02388 { 02389 if (quantum_info->format == FloatingPointQuantumFormat) 02390 { 02391 double 02392 pixel; 02393 02394 for (x=0; x < (ssize_t) number_pixels; x++) 02395 { 02396 p=PushDoublePixel(quantum_info,p,&pixel); 02397 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel), 02398 &range_exception),q); 02399 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02400 GetPixelIndex(image,q),q); 02401 p+=quantum_info->pad; 02402 q+=GetPixelChannels(image); 02403 } 02404 break; 02405 } 02406 } 02407 default: 02408 { 02409 for (x=0; x < (ssize_t) number_pixels; x++) 02410 { 02411 p=PushQuantumPixel(quantum_info,p,&pixel); 02412 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02413 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02414 GetPixelIndex(image,q),q); 02415 p+=quantum_info->pad; 02416 q+=GetPixelChannels(image); 02417 } 02418 break; 02419 } 02420 } 02421 if (range_exception != MagickFalse) 02422 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError, 02423 "InvalidColormapIndex","'%s'",image->filename); 02424 } 02425 02426 static void ImportIndexAlphaQuantum(const Image *image, 02427 QuantumInfo *quantum_info,const MagickSizeType number_pixels, 02428 const unsigned char *restrict p,Quantum *restrict q,ExceptionInfo *exception) 02429 { 02430 MagickBooleanType 02431 range_exception; 02432 02433 QuantumAny 02434 range; 02435 02436 register ssize_t 02437 x; 02438 02439 ssize_t 02440 bit; 02441 02442 unsigned int 02443 pixel; 02444 02445 if (image->storage_class != PseudoClass) 02446 { 02447 (void) ThrowMagickException(exception,GetMagickModule(),ImageError, 02448 "ColormappedImageRequired","'%s'",image->filename); 02449 return; 02450 } 02451 range_exception=MagickFalse; 02452 switch (quantum_info->depth) 02453 { 02454 case 1: 02455 { 02456 register unsigned char 02457 pixel; 02458 02459 for (x=((ssize_t) number_pixels-3); x > 0; x-=4) 02460 { 02461 for (bit=0; bit < 8; bit+=2) 02462 { 02463 if (quantum_info->min_is_white == MagickFalse) 02464 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01); 02465 else 02466 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01); 02467 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q); 02468 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ? 02469 TransparentAlpha : OpaqueAlpha,q); 02470 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q); 02471 q+=GetPixelChannels(image); 02472 } 02473 } 02474 if ((number_pixels % 4) != 0) 02475 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2) 02476 { 02477 if (quantum_info->min_is_white == MagickFalse) 02478 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01); 02479 else 02480 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01); 02481 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q); 02482 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q); 02483 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ? 02484 TransparentAlpha : OpaqueAlpha,q); 02485 q+=GetPixelChannels(image); 02486 } 02487 break; 02488 } 02489 case 4: 02490 { 02491 register unsigned char 02492 pixel; 02493 02494 range=GetQuantumRange(quantum_info->depth); 02495 for (x=0; x < (ssize_t) number_pixels; x++) 02496 { 02497 pixel=(unsigned char) ((*p >> 4) & 0xf); 02498 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02499 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02500 GetPixelIndex(image,q),q); 02501 pixel=(unsigned char) ((*p) & 0xf); 02502 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 02503 p++; 02504 q+=GetPixelChannels(image); 02505 } 02506 break; 02507 } 02508 case 8: 02509 { 02510 unsigned char 02511 pixel; 02512 02513 for (x=0; x < (ssize_t) number_pixels; x++) 02514 { 02515 p=PushCharPixel(p,&pixel); 02516 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02517 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02518 GetPixelIndex(image,q),q); 02519 p=PushCharPixel(p,&pixel); 02520 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q); 02521 p+=quantum_info->pad; 02522 q+=GetPixelChannels(image); 02523 } 02524 break; 02525 } 02526 case 16: 02527 { 02528 unsigned short 02529 pixel; 02530 02531 if (quantum_info->format == FloatingPointQuantumFormat) 02532 { 02533 for (x=0; x < (ssize_t) number_pixels; x++) 02534 { 02535 p=PushShortPixel(quantum_info->endian,p,&pixel); 02536 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum( 02537 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)), 02538 &range_exception),q); 02539 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02540 GetPixelIndex(image,q),q); 02541 p=PushShortPixel(quantum_info->endian,p,&pixel); 02542 SetPixelAlpha(image,ClampToQuantum((MagickRealType) 02543 QuantumRange*HalfToSinglePrecision(pixel)),q); 02544 p+=quantum_info->pad; 02545 q+=GetPixelChannels(image); 02546 } 02547 break; 02548 } 02549 for (x=0; x < (ssize_t) number_pixels; x++) 02550 { 02551 p=PushShortPixel(quantum_info->endian,p,&pixel); 02552 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02553 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02554 GetPixelIndex(image,q),q); 02555 p=PushShortPixel(quantum_info->endian,p,&pixel); 02556 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q); 02557 p+=quantum_info->pad; 02558 q+=GetPixelChannels(image); 02559 } 02560 break; 02561 } 02562 case 32: 02563 { 02564 unsigned int 02565 pixel; 02566 02567 if (quantum_info->format == FloatingPointQuantumFormat) 02568 { 02569 float 02570 pixel; 02571 02572 for (x=0; x < (ssize_t) number_pixels; x++) 02573 { 02574 p=PushFloatPixel(quantum_info,p,&pixel); 02575 SetPixelIndex(image,PushColormapIndex(image, 02576 ClampToQuantum(pixel),&range_exception),q); 02577 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02578 GetPixelIndex(image,q),q); 02579 p=PushFloatPixel(quantum_info,p,&pixel); 02580 SetPixelAlpha(image,ClampToQuantum(pixel),q); 02581 p+=quantum_info->pad; 02582 q+=GetPixelChannels(image); 02583 } 02584 break; 02585 } 02586 for (x=0; x < (ssize_t) number_pixels; x++) 02587 { 02588 p=PushLongPixel(quantum_info->endian,p,&pixel); 02589 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02590 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02591 GetPixelIndex(image,q),q); 02592 p=PushLongPixel(quantum_info->endian,p,&pixel); 02593 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q); 02594 p+=quantum_info->pad; 02595 q+=GetPixelChannels(image); 02596 } 02597 break; 02598 } 02599 case 64: 02600 { 02601 if (quantum_info->format == FloatingPointQuantumFormat) 02602 { 02603 double 02604 pixel; 02605 02606 for (x=0; x < (ssize_t) number_pixels; x++) 02607 { 02608 p=PushDoublePixel(quantum_info,p,&pixel); 02609 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel), 02610 &range_exception),q); 02611 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02612 GetPixelIndex(image,q),q); 02613 p=PushDoublePixel(quantum_info,p,&pixel); 02614 SetPixelAlpha(image,ClampToQuantum(pixel),q); 02615 p+=quantum_info->pad; 02616 q+=GetPixelChannels(image); 02617 } 02618 break; 02619 } 02620 } 02621 default: 02622 { 02623 range=GetQuantumRange(quantum_info->depth); 02624 for (x=0; x < (ssize_t) number_pixels; x++) 02625 { 02626 p=PushQuantumPixel(quantum_info,p,&pixel); 02627 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q); 02628 SetPixelInfoPixel(image,image->colormap+(ssize_t) 02629 GetPixelIndex(image,q),q); 02630 p=PushQuantumPixel(quantum_info,p,&pixel); 02631 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 02632 p+=quantum_info->pad; 02633 q+=GetPixelChannels(image); 02634 } 02635 break; 02636 } 02637 } 02638 if (range_exception != MagickFalse) 02639 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError, 02640 "InvalidColormapIndex","'%s'",image->filename); 02641 } 02642 02643 static void ImportOpacityQuantum(const Image *image,QuantumInfo *quantum_info, 02644 const MagickSizeType number_pixels,const unsigned char *restrict p, 02645 Quantum *restrict q,ExceptionInfo *exception) 02646 { 02647 QuantumAny 02648 range; 02649 02650 register ssize_t 02651 x; 02652 02653 unsigned int 02654 pixel; 02655 02656 switch (quantum_info->depth) 02657 { 02658 case 8: 02659 { 02660 unsigned char 02661 pixel; 02662 02663 for (x=0; x < (ssize_t) number_pixels; x++) 02664 { 02665 p=PushCharPixel(p,&pixel); 02666 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q); 02667 p+=quantum_info->pad; 02668 q+=GetPixelChannels(image); 02669 } 02670 break; 02671 } 02672 case 16: 02673 { 02674 unsigned short 02675 pixel; 02676 02677 if (quantum_info->format == FloatingPointQuantumFormat) 02678 { 02679 for (x=0; x < (ssize_t) number_pixels; x++) 02680 { 02681 p=PushShortPixel(quantum_info->endian,p,&pixel); 02682 SetPixelOpacity(image,ClampToQuantum((MagickRealType) QuantumRange* 02683 HalfToSinglePrecision(pixel)),q); 02684 p+=quantum_info->pad; 02685 q+=GetPixelChannels(image); 02686 } 02687 break; 02688 } 02689 for (x=0; x < (ssize_t) number_pixels; x++) 02690 { 02691 p=PushShortPixel(quantum_info->endian,p,&pixel); 02692 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q); 02693 p+=quantum_info->pad; 02694 q+=GetPixelChannels(image); 02695 } 02696 break; 02697 } 02698 case 32: 02699 { 02700 unsigned int 02701 pixel; 02702 02703 if (quantum_info->format == FloatingPointQuantumFormat) 02704 { 02705 float 02706 pixel; 02707 02708 for (x=0; x < (ssize_t) number_pixels; x++) 02709 { 02710 p=PushFloatPixel(quantum_info,p,&pixel); 02711 SetPixelOpacity(image,ClampToQuantum(pixel),q); 02712 p+=quantum_info->pad; 02713 q+=GetPixelChannels(image); 02714 } 02715 break; 02716 } 02717 for (x=0; x < (ssize_t) number_pixels; x++) 02718 { 02719 p=PushLongPixel(quantum_info->endian,p,&pixel); 02720 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q); 02721 p+=quantum_info->pad; 02722 q+=GetPixelChannels(image); 02723 } 02724 break; 02725 } 02726 case 64: 02727 { 02728 if (quantum_info->format == FloatingPointQuantumFormat) 02729 { 02730 double 02731 pixel; 02732 02733 for (x=0; x < (ssize_t) number_pixels; x++) 02734 { 02735 p=PushDoublePixel(quantum_info,p,&pixel); 02736 SetPixelOpacity(image,ClampToQuantum(pixel),q); 02737 p+=quantum_info->pad; 02738 q+=GetPixelChannels(image); 02739 } 02740 break; 02741 } 02742 } 02743 default: 02744 { 02745 range=GetQuantumRange(quantum_info->depth); 02746 for (x=0; x < (ssize_t) number_pixels; x++) 02747 { 02748 p=PushQuantumPixel(quantum_info,p,&pixel); 02749 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q); 02750 p+=quantum_info->pad; 02751 q+=GetPixelChannels(image); 02752 } 02753 break; 02754 } 02755 } 02756 } 02757 static void ImportRedQuantum(const Image *image,QuantumInfo *quantum_info, 02758 const MagickSizeType number_pixels,const unsigned char *restrict p, 02759 Quantum *restrict q,ExceptionInfo *exception) 02760 { 02761 QuantumAny 02762 range; 02763 02764 register ssize_t 02765 x; 02766 02767 unsigned int 02768 pixel; 02769 02770 switch (quantum_info->depth) 02771 { 02772 case 8: 02773 { 02774 unsigned char 02775 pixel; 02776 02777 for (x=0; x < (ssize_t) number_pixels; x++) 02778 { 02779 p=PushCharPixel(p,&pixel); 02780 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 02781 p+=quantum_info->pad; 02782 q+=GetPixelChannels(image); 02783 } 02784 break; 02785 } 02786 case 16: 02787 { 02788 unsigned short 02789 pixel; 02790 02791 if (quantum_info->format == FloatingPointQuantumFormat) 02792 { 02793 for (x=0; x < (ssize_t) number_pixels; x++) 02794 { 02795 p=PushShortPixel(quantum_info->endian,p,&pixel); 02796 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 02797 HalfToSinglePrecision(pixel)),q); 02798 p+=quantum_info->pad; 02799 q+=GetPixelChannels(image); 02800 } 02801 break; 02802 } 02803 for (x=0; x < (ssize_t) number_pixels; x++) 02804 { 02805 p=PushShortPixel(quantum_info->endian,p,&pixel); 02806 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 02807 p+=quantum_info->pad; 02808 q+=GetPixelChannels(image); 02809 } 02810 break; 02811 } 02812 case 32: 02813 { 02814 unsigned int 02815 pixel; 02816 02817 if (quantum_info->format == FloatingPointQuantumFormat) 02818 { 02819 float 02820 pixel; 02821 02822 for (x=0; x < (ssize_t) number_pixels; x++) 02823 { 02824 p=PushFloatPixel(quantum_info,p,&pixel); 02825 SetPixelRed(image,ClampToQuantum(pixel),q); 02826 p+=quantum_info->pad; 02827 q+=GetPixelChannels(image); 02828 } 02829 break; 02830 } 02831 for (x=0; x < (ssize_t) number_pixels; x++) 02832 { 02833 p=PushLongPixel(quantum_info->endian,p,&pixel); 02834 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 02835 p+=quantum_info->pad; 02836 q+=GetPixelChannels(image); 02837 } 02838 break; 02839 } 02840 case 64: 02841 { 02842 if (quantum_info->format == FloatingPointQuantumFormat) 02843 { 02844 double 02845 pixel; 02846 02847 for (x=0; x < (ssize_t) number_pixels; x++) 02848 { 02849 p=PushDoublePixel(quantum_info,p,&pixel); 02850 SetPixelRed(image,ClampToQuantum(pixel),q); 02851 p+=quantum_info->pad; 02852 q+=GetPixelChannels(image); 02853 } 02854 break; 02855 } 02856 } 02857 default: 02858 { 02859 range=GetQuantumRange(quantum_info->depth); 02860 for (x=0; x < (ssize_t) number_pixels; x++) 02861 { 02862 p=PushQuantumPixel(quantum_info,p,&pixel); 02863 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 02864 p+=quantum_info->pad; 02865 q+=GetPixelChannels(image); 02866 } 02867 break; 02868 } 02869 } 02870 } 02871 02872 static void ImportRGBQuantum(const Image *image,QuantumInfo *quantum_info, 02873 const MagickSizeType number_pixels,const unsigned char *restrict p, 02874 Quantum *restrict q,ExceptionInfo *exception) 02875 { 02876 QuantumAny 02877 range; 02878 02879 register ssize_t 02880 x; 02881 02882 ssize_t 02883 bit; 02884 02885 unsigned int 02886 pixel; 02887 02888 switch (quantum_info->depth) 02889 { 02890 case 8: 02891 { 02892 unsigned char 02893 pixel; 02894 02895 for (x=0; x < (ssize_t) number_pixels; x++) 02896 { 02897 p=PushCharPixel(p,&pixel); 02898 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 02899 p=PushCharPixel(p,&pixel); 02900 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 02901 p=PushCharPixel(p,&pixel); 02902 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 02903 SetPixelAlpha(image,OpaqueAlpha,q); 02904 p+=quantum_info->pad; 02905 q+=GetPixelChannels(image); 02906 } 02907 break; 02908 } 02909 case 10: 02910 { 02911 range=GetQuantumRange(quantum_info->depth); 02912 if (quantum_info->pack == MagickFalse) 02913 { 02914 for (x=0; x < (ssize_t) number_pixels; x++) 02915 { 02916 p=PushLongPixel(quantum_info->endian,p,&pixel); 02917 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q); 02918 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range), 02919 q); 02920 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q); 02921 p+=quantum_info->pad; 02922 q+=GetPixelChannels(image); 02923 } 02924 break; 02925 } 02926 if (quantum_info->quantum == 32U) 02927 { 02928 for (x=0; x < (ssize_t) number_pixels; x++) 02929 { 02930 p=PushQuantumLongPixel(quantum_info,p,&pixel); 02931 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 02932 p=PushQuantumLongPixel(quantum_info,p,&pixel); 02933 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 02934 p=PushQuantumLongPixel(quantum_info,p,&pixel); 02935 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 02936 q+=GetPixelChannels(image); 02937 } 02938 break; 02939 } 02940 for (x=0; x < (ssize_t) number_pixels; x++) 02941 { 02942 p=PushQuantumPixel(quantum_info,p,&pixel); 02943 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 02944 p=PushQuantumPixel(quantum_info,p,&pixel); 02945 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 02946 p=PushQuantumPixel(quantum_info,p,&pixel); 02947 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 02948 q+=GetPixelChannels(image); 02949 } 02950 break; 02951 } 02952 case 12: 02953 { 02954 range=GetQuantumRange(quantum_info->depth); 02955 if (quantum_info->pack == MagickFalse) 02956 { 02957 unsigned short 02958 pixel; 02959 02960 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2) 02961 { 02962 p=PushShortPixel(quantum_info->endian,p,&pixel); 02963 switch (x % 3) 02964 { 02965 default: 02966 case 0: 02967 { 02968 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 02969 range),q); 02970 break; 02971 } 02972 case 1: 02973 { 02974 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 02975 range),q); 02976 break; 02977 } 02978 case 2: 02979 { 02980 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 02981 range),q); 02982 q+=GetPixelChannels(image); 02983 break; 02984 } 02985 } 02986 p=PushShortPixel(quantum_info->endian,p,&pixel); 02987 switch ((x+1) % 3) 02988 { 02989 default: 02990 case 0: 02991 { 02992 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 02993 range),q); 02994 break; 02995 } 02996 case 1: 02997 { 02998 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 02999 range),q); 03000 break; 03001 } 03002 case 2: 03003 { 03004 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 03005 range),q); 03006 q+=GetPixelChannels(image); 03007 break; 03008 } 03009 } 03010 p+=quantum_info->pad; 03011 } 03012 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++) 03013 { 03014 p=PushShortPixel(quantum_info->endian,p,&pixel); 03015 switch ((x+bit) % 3) 03016 { 03017 default: 03018 case 0: 03019 { 03020 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 03021 range),q); 03022 break; 03023 } 03024 case 1: 03025 { 03026 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 03027 range),q); 03028 break; 03029 } 03030 case 2: 03031 { 03032 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4), 03033 range),q); 03034 q+=GetPixelChannels(image); 03035 break; 03036 } 03037 } 03038 p+=quantum_info->pad; 03039 } 03040 if (bit != 0) 03041 p++; 03042 break; 03043 } 03044 if (quantum_info->quantum == 32U) 03045 { 03046 for (x=0; x < (ssize_t) number_pixels; x++) 03047 { 03048 p=PushQuantumLongPixel(quantum_info,p,&pixel); 03049 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 03050 p=PushQuantumLongPixel(quantum_info,p,&pixel); 03051 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 03052 p=PushQuantumLongPixel(quantum_info,p,&pixel); 03053 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 03054 q+=GetPixelChannels(image); 03055 } 03056 break; 03057 } 03058 for (x=0; x < (ssize_t) number_pixels; x++) 03059 { 03060 p=PushQuantumPixel(quantum_info,p,&pixel); 03061 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 03062 p=PushQuantumPixel(quantum_info,p,&pixel); 03063 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 03064 p=PushQuantumPixel(quantum_info,p,&pixel); 03065 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 03066 q+=GetPixelChannels(image); 03067 } 03068 break; 03069 } 03070 case 16: 03071 { 03072 unsigned short 03073 pixel; 03074 03075 if (quantum_info->format == FloatingPointQuantumFormat) 03076 { 03077 for (x=0; x < (ssize_t) number_pixels; x++) 03078 { 03079 p=PushShortPixel(quantum_info->endian,p,&pixel); 03080 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 03081 HalfToSinglePrecision(pixel)),q); 03082 p=PushShortPixel(quantum_info->endian,p,&pixel); 03083 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 03084 HalfToSinglePrecision(pixel)),q); 03085 p=PushShortPixel(quantum_info->endian,p,&pixel); 03086 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 03087 HalfToSinglePrecision(pixel)),q); 03088 p+=quantum_info->pad; 03089 q+=GetPixelChannels(image); 03090 } 03091 break; 03092 } 03093 for (x=0; x < (ssize_t) number_pixels; x++) 03094 { 03095 p=PushShortPixel(quantum_info->endian,p,&pixel); 03096 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 03097 p=PushShortPixel(quantum_info->endian,p,&pixel); 03098 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 03099 p=PushShortPixel(quantum_info->endian,p,&pixel); 03100 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 03101 p+=quantum_info->pad; 03102 q+=GetPixelChannels(image); 03103 } 03104 break; 03105 } 03106 case 32: 03107 { 03108 unsigned int 03109 pixel; 03110 03111 if (quantum_info->format == FloatingPointQuantumFormat) 03112 { 03113 float 03114 pixel; 03115 03116 for (x=0; x < (ssize_t) number_pixels; x++) 03117 { 03118 p=PushFloatPixel(quantum_info,p,&pixel); 03119 SetPixelRed(image,ClampToQuantum(pixel),q); 03120 p=PushFloatPixel(quantum_info,p,&pixel); 03121 SetPixelGreen(image,ClampToQuantum(pixel),q); 03122 p=PushFloatPixel(quantum_info,p,&pixel); 03123 SetPixelBlue(image,ClampToQuantum(pixel),q); 03124 p+=quantum_info->pad; 03125 q+=GetPixelChannels(image); 03126 } 03127 break; 03128 } 03129 for (x=0; x < (ssize_t) number_pixels; x++) 03130 { 03131 p=PushLongPixel(quantum_info->endian,p,&pixel); 03132 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 03133 p=PushLongPixel(quantum_info->endian,p,&pixel); 03134 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 03135 p=PushLongPixel(quantum_info->endian,p,&pixel); 03136 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 03137 p+=quantum_info->pad; 03138 q+=GetPixelChannels(image); 03139 } 03140 break; 03141 } 03142 case 64: 03143 { 03144 if (quantum_info->format == FloatingPointQuantumFormat) 03145 { 03146 double 03147 pixel; 03148 03149 for (x=0; x < (ssize_t) number_pixels; x++) 03150 { 03151 p=PushDoublePixel(quantum_info,p,&pixel); 03152 SetPixelRed(image,ClampToQuantum(pixel),q); 03153 p=PushDoublePixel(quantum_info,p,&pixel); 03154 SetPixelGreen(image,ClampToQuantum(pixel),q); 03155 p=PushDoublePixel(quantum_info,p,&pixel); 03156 SetPixelBlue(image,ClampToQuantum(pixel),q); 03157 p+=quantum_info->pad; 03158 q+=GetPixelChannels(image); 03159 } 03160 break; 03161 } 03162 } 03163 default: 03164 { 03165 range=GetQuantumRange(quantum_info->depth); 03166 for (x=0; x < (ssize_t) number_pixels; x++) 03167 { 03168 p=PushQuantumPixel(quantum_info,p,&pixel); 03169 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 03170 p=PushQuantumPixel(quantum_info,p,&pixel); 03171 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 03172 p=PushQuantumPixel(quantum_info,p,&pixel); 03173 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 03174 q+=GetPixelChannels(image); 03175 } 03176 break; 03177 } 03178 } 03179 } 03180 03181 static void ImportRGBAQuantum(const Image *image,QuantumInfo *quantum_info, 03182 const MagickSizeType number_pixels,const unsigned char *restrict p, 03183 Quantum *restrict q,ExceptionInfo *exception) 03184 { 03185 QuantumAny 03186 range; 03187 03188 register ssize_t 03189 x; 03190 03191 unsigned int 03192 pixel; 03193 03194 switch (quantum_info->depth) 03195 { 03196 case 8: 03197 { 03198 unsigned char 03199 pixel; 03200 03201 for (x=0; x < (ssize_t) number_pixels; x++) 03202 { 03203 p=PushCharPixel(p,&pixel); 03204 SetPixelRed(image,ScaleCharToQuantum(pixel),q); 03205 p=PushCharPixel(p,&pixel); 03206 SetPixelGreen(image,ScaleCharToQuantum(pixel),q); 03207 p=PushCharPixel(p,&pixel); 03208 SetPixelBlue(image,ScaleCharToQuantum(pixel),q); 03209 p=PushCharPixel(p,&pixel); 03210 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q); 03211 p+=quantum_info->pad; 03212 q+=GetPixelChannels(image); 03213 } 03214 break; 03215 } 03216 case 10: 03217 { 03218 pixel=0; 03219 if (quantum_info->pack == MagickFalse) 03220 { 03221 register ssize_t 03222 i; 03223 03224 size_t 03225 quantum; 03226 03227 ssize_t 03228 n; 03229 03230 n=0; 03231 quantum=0; 03232 for (x=0; x < (ssize_t) number_pixels; x++) 03233 { 03234 for (i=0; i < 4; i++) 03235 { 03236 switch (n % 3) 03237 { 03238 case 0: 03239 { 03240 p=PushLongPixel(quantum_info->endian,p,&pixel); 03241 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 03242 (((pixel >> 22) & 0x3ff) << 6))); 03243 break; 03244 } 03245 case 1: 03246 { 03247 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 03248 (((pixel >> 12) & 0x3ff) << 6))); 03249 break; 03250 } 03251 case 2: 03252 { 03253 quantum=(size_t) (ScaleShortToQuantum((unsigned short) 03254 (((pixel >> 2) & 0x3ff) << 6))); 03255 break; 03256 } 03257 } 03258 switch (i) 03259 { 03260 case 0: SetPixelRed(image,(Quantum) quantum,q); break; 03261 case 1: SetPixelGreen(image,(Quantum) quantum,q); break; 03262 case 2: SetPixelBlue(image,(Quantum) quantum,q); break; 03263 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break; 03264 } 03265 n++; 03266 } 03267 p+=quantum_info->pad; 03268 q+=GetPixelChannels(image); 03269 } 03270 break; 03271 } 03272 for (x=0; x < (ssize_t) number_pixels; x++) 03273 { 03274 p=PushQuantumPixel(quantum_info,p,&pixel); 03275 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q); 03276 p=PushQuantumPixel(quantum_info,p,&pixel); 03277 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)), 03278 q); 03279 p=PushQuantumPixel(quantum_info,p,&pixel); 03280 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)), 03281 q); 03282 p=PushQuantumPixel(quantum_info,p,&pixel); 03283 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)), 03284 q); 03285 q+=GetPixelChannels(image); 03286 } 03287 break; 03288 } 03289 case 16: 03290 { 03291 unsigned short 03292 pixel; 03293 03294 if (quantum_info->format == FloatingPointQuantumFormat) 03295 { 03296 for (x=0; x < (ssize_t) number_pixels; x++) 03297 { 03298 p=PushShortPixel(quantum_info->endian,p,&pixel); 03299 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* 03300 HalfToSinglePrecision(pixel)),q); 03301 p=PushShortPixel(quantum_info->endian,p,&pixel); 03302 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* 03303 HalfToSinglePrecision(pixel)),q); 03304 p=PushShortPixel(quantum_info->endian,p,&pixel); 03305 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* 03306 HalfToSinglePrecision(pixel)),q); 03307 p=PushShortPixel(quantum_info->endian,p,&pixel); 03308 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* 03309 HalfToSinglePrecision(pixel)),q); 03310 p+=quantum_info->pad; 03311 q+=GetPixelChannels(image); 03312 } 03313 break; 03314 } 03315 for (x=0; x < (ssize_t) number_pixels; x++) 03316 { 03317 p=PushShortPixel(quantum_info->endian,p,&pixel); 03318 SetPixelRed(image,ScaleShortToQuantum(pixel),q); 03319 p=PushShortPixel(quantum_info->endian,p,&pixel); 03320 SetPixelGreen(image,ScaleShortToQuantum(pixel),q); 03321 p=PushShortPixel(quantum_info->endian,p,&pixel); 03322 SetPixelBlue(image,ScaleShortToQuantum(pixel),q); 03323 p=PushShortPixel(quantum_info->endian,p,&pixel); 03324 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q); 03325 p+=quantum_info->pad; 03326 q+=GetPixelChannels(image); 03327 } 03328 break; 03329 } 03330 case 32: 03331 { 03332 unsigned int 03333 pixel; 03334 03335 if (quantum_info->format == FloatingPointQuantumFormat) 03336 { 03337 float 03338 pixel; 03339 03340 for (x=0; x < (ssize_t) number_pixels; x++) 03341 { 03342 p=PushFloatPixel(quantum_info,p,&pixel); 03343 SetPixelRed(image,ClampToQuantum(pixel),q); 03344 p=PushFloatPixel(quantum_info,p,&pixel); 03345 SetPixelGreen(image,ClampToQuantum(pixel),q); 03346 p=PushFloatPixel(quantum_info,p,&pixel); 03347 SetPixelBlue(image,ClampToQuantum(pixel),q); 03348 p=PushFloatPixel(quantum_info,p,&pixel); 03349 SetPixelAlpha(image,ClampToQuantum(pixel),q); 03350 p+=quantum_info->pad; 03351 q+=GetPixelChannels(image); 03352 } 03353 break; 03354 } 03355 for (x=0; x < (ssize_t) number_pixels; x++) 03356 { 03357 p=PushLongPixel(quantum_info->endian,p,&pixel); 03358 SetPixelRed(image,ScaleLongToQuantum(pixel),q); 03359 p=PushLongPixel(quantum_info->endian,p,&pixel); 03360 SetPixelGreen(image,ScaleLongToQuantum(pixel),q); 03361 p=PushLongPixel(quantum_info->endian,p,&pixel); 03362 SetPixelBlue(image,ScaleLongToQuantum(pixel),q); 03363 p=PushLongPixel(quantum_info->endian,p,&pixel); 03364 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q); 03365 p+=quantum_info->pad; 03366 q+=GetPixelChannels(image); 03367 } 03368 break; 03369 } 03370 case 64: 03371 { 03372 if (quantum_info->format == FloatingPointQuantumFormat) 03373 { 03374 double 03375 pixel; 03376 03377 for (x=0; x < (ssize_t) number_pixels; x++) 03378 { 03379 p=PushDoublePixel(quantum_info,p,&pixel); 03380 SetPixelRed(image,ClampToQuantum(pixel),q); 03381 p=PushDoublePixel(quantum_info,p,&pixel); 03382 SetPixelGreen(image,ClampToQuantum(pixel),q); 03383 p=PushDoublePixel(quantum_info,p,&pixel); 03384 SetPixelBlue(image,ClampToQuantum(pixel),q); 03385 p=PushDoublePixel(quantum_info,p,&pixel); 03386 SetPixelAlpha(image,ClampToQuantum(pixel),q); 03387 p+=quantum_info->pad; 03388 q+=GetPixelChannels(image); 03389 } 03390 break; 03391 } 03392 } 03393 default: 03394 { 03395 range=GetQuantumRange(quantum_info->depth); 03396 for (x=0; x < (ssize_t) number_pixels; x++) 03397 { 03398 p=PushQuantumPixel(quantum_info,p,&pixel); 03399 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q); 03400 p=PushQuantumPixel(quantum_info,p,&pixel); 03401 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q); 03402 p=PushQuantumPixel(quantum_info,p,&pixel); 03403 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q); 03404 p=PushQuantumPixel(quantum_info,p,&pixel); 03405 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q); 03406 q+=GetPixelChannels(image); 03407 } 03408 break; 03409 } 03410 } 03411 } 03412 03413 MagickExport size_t ImportQuantumPixels(const Image *image, 03414 CacheView *image_view,QuantumInfo *quantum_info, 03415 const QuantumType quantum_type,const unsigned char *pixels, 03416 ExceptionInfo *exception) 03417 { 03418 MagickSizeType 03419 number_pixels; 03420 03421 register const unsigned char 03422 *restrict p; 03423 03424 register ssize_t 03425 x; 03426 03427 register Quantum 03428 *restrict q; 03429 03430 size_t 03431 extent; 03432 03433 assert(image != (Image *) NULL); 03434 assert(image->signature == MagickSignature); 03435 if (image->debug != MagickFalse) 03436 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 03437 assert(quantum_info != (QuantumInfo *) NULL); 03438 assert(quantum_info->signature == MagickSignature); 03439 if (pixels == (const unsigned char *) NULL) 03440 pixels=GetQuantumPixels(quantum_info); 03441 x=0; 03442 p=pixels; 03443 if (image_view == (CacheView *) NULL) 03444 { 03445 number_pixels=GetImageExtent(image); 03446 q=GetAuthenticPixelQueue(image); 03447 } 03448 else 03449 { 03450 number_pixels=GetCacheViewExtent(image_view); 03451 q=GetCacheViewAuthenticPixelQueue(image_view); 03452 } 03453 ResetQuantumState(quantum_info); 03454 extent=GetQuantumExtent(image,quantum_info,quantum_type); 03455 switch (quantum_type) 03456 { 03457 case AlphaQuantum: 03458 { 03459 ImportAlphaQuantum(image,quantum_info,number_pixels,p,q,exception); 03460 break; 03461 } 03462 case BGRQuantum: 03463 { 03464 ImportBGRQuantum(image,quantum_info,number_pixels,p,q,exception); 03465 break; 03466 } 03467 case BGRAQuantum: 03468 case BGROQuantum: 03469 { 03470 ImportBGRAQuantum(image,quantum_info,number_pixels,p,q,exception); 03471 break; 03472 } 03473 case BlackQuantum: 03474 { 03475 ImportBlackQuantum(image,quantum_info,number_pixels,p,q,exception); 03476 break; 03477 } 03478 case BlueQuantum: 03479 case YellowQuantum: 03480 { 03481 ImportBlueQuantum(image,quantum_info,number_pixels,p,q,exception); 03482 break; 03483 } 03484 case CMYKQuantum: 03485 { 03486 ImportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception); 03487 break; 03488 } 03489 case CMYKAQuantum: 03490 case CMYKOQuantum: 03491 { 03492 ImportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception); 03493 break; 03494 } 03495 case CbYCrYQuantum: 03496 { 03497 ImportCbYCrYQuantum(image,quantum_info,number_pixels,p,q,exception); 03498 break; 03499 } 03500 case GrayQuantum: 03501 { 03502 ImportGrayQuantum(image,quantum_info,number_pixels,p,q,exception); 03503 break; 03504 } 03505 case GrayAlphaQuantum: 03506 { 03507 ImportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q,exception); 03508 break; 03509 } 03510 case GreenQuantum: 03511 case MagentaQuantum: 03512 { 03513 ImportGreenQuantum(image,quantum_info,number_pixels,p,q,exception); 03514 break; 03515 } 03516 case IndexQuantum: 03517 { 03518 ImportIndexQuantum(image,quantum_info,number_pixels,p,q,exception); 03519 break; 03520 } 03521 case IndexAlphaQuantum: 03522 { 03523 ImportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception); 03524 break; 03525 } 03526 case OpacityQuantum: 03527 { 03528 ImportOpacityQuantum(image,quantum_info,number_pixels,p,q,exception); 03529 break; 03530 } 03531 case RedQuantum: 03532 case CyanQuantum: 03533 { 03534 ImportRedQuantum(image,quantum_info,number_pixels,p,q,exception); 03535 break; 03536 } 03537 case RGBQuantum: 03538 case CbYCrQuantum: 03539 { 03540 ImportRGBQuantum(image,quantum_info,number_pixels,p,q,exception); 03541 break; 03542 } 03543 case RGBAQuantum: 03544 case RGBOQuantum: 03545 case CbYCrAQuantum: 03546 { 03547 ImportRGBAQuantum(image,quantum_info,number_pixels,p,q,exception); 03548 break; 03549 } 03550 default: 03551 break; 03552 } 03553 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum)) 03554 { 03555 Quantum 03556 quantum; 03557 03558 register Quantum 03559 *restrict q; 03560 03561 q=GetAuthenticPixelQueue(image); 03562 if (image_view != (CacheView *) NULL) 03563 q=GetCacheViewAuthenticPixelQueue(image_view); 03564 for (x=0; x < (ssize_t) number_pixels; x++) 03565 { 03566 quantum=GetPixelRed(image,q); 03567 SetPixelRed(image,GetPixelGreen(image,q),q); 03568 SetPixelGreen(image,quantum,q); 03569 q+=GetPixelChannels(image); 03570 } 03571 } 03572 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum)) 03573 { 03574 register Quantum 03575 *restrict q; 03576 03577 q=GetAuthenticPixelQueue(image); 03578 if (image_view != (CacheView *) NULL) 03579 q=GetCacheViewAuthenticPixelQueue(image_view); 03580 for (x=0; x < (ssize_t) number_pixels; x++) 03581 { 03582 SetPixelAlpha(image,GetPixelAlpha(image,q),q); 03583 q+=GetPixelChannels(image); 03584 } 03585 } 03586 if (quantum_info->alpha_type == DisassociatedQuantumAlpha) 03587 { 03588 MagickRealType 03589 gamma, 03590 Sa; 03591 03592 register Quantum 03593 *restrict q; 03594 03595 /* 03596 Disassociate alpha. 03597 */ 03598 q=GetAuthenticPixelQueue(image); 03599 if (image_view != (CacheView *) NULL) 03600 q=GetCacheViewAuthenticPixelQueue(image_view); 03601 for (x=0; x < (ssize_t) number_pixels; x++) 03602 { 03603 register ssize_t 03604 i; 03605 03606 if (GetPixelMask(image,q) != 0) 03607 { 03608 q+=GetPixelChannels(image); 03609 continue; 03610 } 03611 Sa=QuantumScale*GetPixelAlpha(image,q); 03612 gamma=1.0/(fabs(Sa) <= MagickEpsilon ? 1.0 : Sa); 03613 for (i=0; i < (ssize_t) GetPixelChannels(image); i++) 03614 { 03615 PixelChannel 03616 channel; 03617 03618 PixelTrait 03619 traits; 03620 03621 channel=GetPixelChannelMapChannel(image,i); 03622 traits=GetPixelChannelMapTraits(image,channel); 03623 if ((traits & UpdatePixelTrait) == 0) 03624 continue; 03625 q[i]=ClampToQuantum(gamma*q[i]); 03626 } 03627 q+=GetPixelChannels(image); 03628 } 03629 } 03630 return(extent); 03631 }