00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "magick/studio.h"
00048 #include "magick/property.h"
00049 #include "magick/blob.h"
00050 #include "magick/blob-private.h"
00051 #include "magick/color-private.h"
00052 #include "magick/exception.h"
00053 #include "magick/exception-private.h"
00054 #include "magick/cache.h"
00055 #include "magick/constitute.h"
00056 #include "magick/delegate.h"
00057 #include "magick/geometry.h"
00058 #include "magick/list.h"
00059 #include "magick/magick.h"
00060 #include "magick/memory_.h"
00061 #include "magick/monitor.h"
00062 #include "magick/option.h"
00063 #include "magick/pixel.h"
00064 #include "magick/pixel-private.h"
00065 #include "magick/quantum.h"
00066 #include "magick/quantum-private.h"
00067 #include "magick/resource_.h"
00068 #include "magick/semaphore.h"
00069 #include "magick/statistic.h"
00070 #include "magick/stream.h"
00071 #include "magick/string_.h"
00072 #include "magick/utility.h"
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 static inline IndexPacket PushColormapIndex(Image *image,
00114 const unsigned long index,MagickBooleanType *range_exception)
00115 {
00116 if (index < image->colors)
00117 return((IndexPacket) index);
00118 *range_exception=MagickTrue;
00119 return((IndexPacket) 0);
00120 }
00121
00122 static inline const unsigned char *PushDoublePixel(
00123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
00124 {
00125 unsigned char
00126 quantum[8];
00127
00128 if (quantum_state->endian != LSBEndian)
00129 {
00130 quantum[7]=(*pixels++);
00131 quantum[6]=(*pixels++);
00132 quantum[5]=(*pixels++);
00133 quantum[5]=(*pixels++);
00134 quantum[3]=(*pixels++);
00135 quantum[2]=(*pixels++);
00136 quantum[1]=(*pixels++);
00137 quantum[0]=(*pixels++);
00138 *pixel=(*((double *) quantum));
00139 *pixel-=quantum_state->minimum;
00140 *pixel*=quantum_state->scale;
00141 return(pixels);
00142 }
00143 quantum[0]=(*pixels++);
00144 quantum[1]=(*pixels++);
00145 quantum[2]=(*pixels++);
00146 quantum[3]=(*pixels++);
00147 quantum[4]=(*pixels++);
00148 quantum[5]=(*pixels++);
00149 quantum[6]=(*pixels++);
00150 quantum[7]=(*pixels++);
00151 *pixel=(*((double *) quantum));
00152 *pixel-=quantum_state->minimum;
00153 *pixel*=quantum_state->scale;
00154 return(pixels);
00155 }
00156
00157 static inline const unsigned char *PushFloatPixel(
00158 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
00159 {
00160 unsigned char
00161 quantum[4];
00162
00163 if (quantum_state->endian != LSBEndian)
00164 {
00165 quantum[3]=(*pixels++);
00166 quantum[2]=(*pixels++);
00167 quantum[1]=(*pixels++);
00168 quantum[0]=(*pixels++);
00169 *pixel=(*((float *) quantum));
00170 *pixel-=quantum_state->minimum;
00171 *pixel*=quantum_state->scale;
00172 return(pixels);
00173 }
00174 quantum[0]=(*pixels++);
00175 quantum[1]=(*pixels++);
00176 quantum[2]=(*pixels++);
00177 quantum[3]=(*pixels++);
00178 *pixel=(*((float *) quantum));
00179 *pixel-=quantum_state->minimum;
00180 *pixel*=quantum_state->scale;
00181 return(pixels);
00182 }
00183
00184 static inline const unsigned char *PushQuantumPixel(QuantumState *quantum_state,
00185 const unsigned long depth,const unsigned char *pixels,QuantumAny *quantum)
00186 {
00187 register long
00188 i;
00189
00190 register unsigned long
00191 quantum_bits;
00192
00193 *quantum=(QuantumAny) 0;
00194 for (i=(long) depth; i > 0L; )
00195 {
00196 if (quantum_state->bits == 0UL)
00197 {
00198 quantum_state->pixel=(*pixels++);
00199 quantum_state->bits=8UL;
00200 }
00201 quantum_bits=(unsigned long) i;
00202 if (quantum_bits > quantum_state->bits)
00203 quantum_bits=quantum_state->bits;
00204 i-=quantum_bits;
00205 quantum_state->bits-=quantum_bits;
00206 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
00207 quantum_state->bits) &~ ((~0UL) << quantum_bits));
00208 }
00209 return(pixels);
00210 }
00211
00212 static inline const unsigned char *PushQuantumLongPixel(
00213 QuantumState *quantum_state,const unsigned long depth,
00214 const unsigned char *pixels,unsigned long *quantum)
00215 {
00216 register long
00217 i;
00218
00219 register unsigned long
00220 quantum_bits;
00221
00222 *quantum=0UL;
00223 for (i=(long) depth; i > 0; )
00224 {
00225 if (quantum_state->bits == 0)
00226 {
00227 pixels=PushLongPixel(quantum_state->endian,pixels,
00228 &quantum_state->pixel);
00229 quantum_state->bits=32UL;
00230 }
00231 quantum_bits=(unsigned long) i;
00232 if (quantum_bits > quantum_state->bits)
00233 quantum_bits=quantum_state->bits;
00234 *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
00235 quantum_state->mask[quantum_bits]) << (depth-i));
00236 i-=quantum_bits;
00237 quantum_state->bits-=quantum_bits;
00238 }
00239 return(pixels);
00240 }
00241
00242 MagickExport size_t ImportQuantumPixels(Image *image,ViewInfo *image_view,
00243 const QuantumInfo *quantum_info,const QuantumType quantum_type,
00244 const unsigned char *pixels,ExceptionInfo *exception)
00245 {
00246 EndianType
00247 endian;
00248
00249 long
00250 bit;
00251
00252 MagickSizeType
00253 number_pixels;
00254
00255 QuantumAny
00256 pixel,
00257 scale;
00258
00259 QuantumState
00260 quantum_state;
00261
00262 register const unsigned char
00263 *p;
00264
00265 register IndexPacket
00266 *indexes;
00267
00268 register long
00269 x;
00270
00271 register PixelPacket
00272 *q;
00273
00274 size_t
00275 extent;
00276
00277 assert(image != (Image *) NULL);
00278 assert(image->signature == MagickSignature);
00279 if (image->debug != MagickFalse)
00280 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00281 assert(quantum_info != (QuantumInfo *) NULL);
00282 assert(quantum_info->signature == MagickSignature);
00283 if (pixels == (const unsigned char *) NULL)
00284 pixels=GetQuantumPixels(quantum_info);
00285 x=0;
00286 p=pixels;
00287 number_pixels=GetImageExtent(image);
00288 q=GetAuthenticPixelQueue(image);
00289 indexes=GetAuthenticIndexQueue(image);
00290 if (image_view != (ViewInfo *) NULL)
00291 {
00292 number_pixels=GetCacheViewExtent(image_view);
00293 q=GetCacheViewAuthenticPixelQueue(image_view);
00294 indexes=GetCacheViewAuthenticIndexQueue(image_view);
00295 }
00296 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
00297 extent=GetQuantumExtent(image,quantum_info,quantum_type);
00298 endian=quantum_state.endian;
00299 switch (quantum_type)
00300 {
00301 case IndexQuantum:
00302 {
00303 MagickBooleanType
00304 range_exception;
00305
00306 if (image->storage_class != PseudoClass)
00307 {
00308 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
00309 "ColormappedImageRequired","`%s'",image->filename);
00310 return(extent);
00311 }
00312 range_exception=MagickFalse;
00313 switch (quantum_info->depth)
00314 {
00315 case 1:
00316 {
00317 register unsigned char
00318 pixel;
00319
00320 for (x=0; x < ((long) number_pixels-7); x+=8)
00321 {
00322 for (bit=0; bit < 8; bit++)
00323 {
00324 if (quantum_info->min_is_white == MagickFalse)
00325 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
00326 0x00 : 0x01);
00327 else
00328 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
00329 0x00 : 0x01);
00330 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
00331 *q=image->colormap[(long) indexes[x+bit]];
00332 q++;
00333 }
00334 p++;
00335 }
00336 for (bit=0; bit < (long) (number_pixels % 8); bit++)
00337 {
00338 if (quantum_info->min_is_white == MagickFalse)
00339 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
00340 0x00 : 0x01);
00341 else
00342 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
00343 0x00 : 0x01);
00344 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
00345 *q=image->colormap[(long) indexes[x+bit]];
00346 q++;
00347 }
00348 break;
00349 }
00350 case 4:
00351 {
00352 register unsigned char
00353 pixel;
00354
00355 for (x=0; x < ((long) number_pixels-1); x+=2)
00356 {
00357 pixel=(unsigned char) ((*p >> 4) & 0xf);
00358 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00359 *q=image->colormap[(long) indexes[x]];
00360 q++;
00361 pixel=(unsigned char) ((*p) & 0xf);
00362 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
00363 *q=image->colormap[(long) indexes[x+1]];
00364 p++;
00365 q++;
00366 }
00367 for (bit=0; bit < (long) (number_pixels % 2); bit++)
00368 {
00369 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
00370 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
00371 *q=image->colormap[(long) indexes[x+bit]];
00372 q++;
00373 }
00374 break;
00375 }
00376 case 8:
00377 {
00378 unsigned char
00379 pixel;
00380
00381 for (x=0; x < (long) number_pixels; x++)
00382 {
00383 p=PushCharPixel(p,&pixel);
00384 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00385 *q=image->colormap[(long) indexes[x]];
00386 p+=quantum_info->pad;
00387 q++;
00388 }
00389 break;
00390 }
00391 case 16:
00392 {
00393 unsigned short
00394 pixel;
00395
00396 for (x=0; x < (long) number_pixels; x++)
00397 {
00398 p=PushShortPixel(endian,p,&pixel);
00399 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00400 *q=image->colormap[(long) indexes[x]];
00401 p+=quantum_info->pad;
00402 q++;
00403 }
00404 break;
00405 }
00406 case 32:
00407 {
00408 unsigned long
00409 pixel;
00410
00411 if (quantum_info->format == FloatingPointQuantumFormat)
00412 {
00413 float
00414 pixel;
00415
00416 for (x=0; x < (long) number_pixels; x++)
00417 {
00418 p=PushFloatPixel(&quantum_state,p,&pixel);
00419 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
00420 &range_exception);
00421 *q=image->colormap[(long) indexes[x]];
00422 p+=quantum_info->pad;
00423 q++;
00424 }
00425 break;
00426 }
00427 for (x=0; x < (long) number_pixels; x++)
00428 {
00429 p=PushLongPixel(endian,p,&pixel);
00430 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00431 *q=image->colormap[(long) indexes[x]];
00432 p+=quantum_info->pad;
00433 q++;
00434 }
00435 break;
00436 }
00437 case 64:
00438 {
00439 if (quantum_info->format == FloatingPointQuantumFormat)
00440 {
00441 double
00442 pixel;
00443
00444 for (x=0; x < (long) number_pixels; x++)
00445 {
00446 p=PushDoublePixel(&quantum_state,p,&pixel);
00447 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
00448 &range_exception);
00449 *q=image->colormap[(long) indexes[x]];
00450 p+=quantum_info->pad;
00451 q++;
00452 }
00453 break;
00454 }
00455 }
00456 default:
00457 {
00458 for (x=0; x < (long) number_pixels; x++)
00459 {
00460 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
00461 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00462 *q=image->colormap[(long) indexes[x]];
00463 p+=quantum_info->pad;
00464 q++;
00465 }
00466 break;
00467 }
00468 }
00469 if (range_exception != MagickFalse)
00470 (void) ThrowMagickException(exception,GetMagickModule(),
00471 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
00472 break;
00473 }
00474 case IndexAlphaQuantum:
00475 {
00476 MagickBooleanType
00477 range_exception;
00478
00479 if (image->storage_class != PseudoClass)
00480 {
00481 (void) ThrowMagickException(exception,GetMagickModule(),
00482 ImageError,"ColormappedImageRequired","`%s'",image->filename);
00483 return(extent);
00484 }
00485 range_exception=MagickFalse;
00486 switch (quantum_info->depth)
00487 {
00488 case 1:
00489 {
00490 register unsigned char
00491 pixel;
00492
00493 for (x=0; x < ((long) number_pixels-3); x+=4)
00494 {
00495 for (bit=0; bit < 8; bit+=2)
00496 {
00497 if (quantum_info->min_is_white == MagickFalse)
00498 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
00499 0x00 : 0x01);
00500 else
00501 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
00502 0x00 : 0x01);
00503 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
00504 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
00505 q->green=q->red;
00506 q->blue=q->red;
00507 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
00508 == 0 ? TransparentOpacity : OpaqueOpacity);
00509 q++;
00510 }
00511 }
00512 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
00513 {
00514 if (quantum_info->min_is_white == MagickFalse)
00515 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
00516 0x00 : 0x01);
00517 else
00518 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
00519 0x00 : 0x01);
00520 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
00521 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
00522 q->green=q->red;
00523 q->blue=q->red;
00524 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
00525 0 ? TransparentOpacity : OpaqueOpacity);
00526 q++;
00527 }
00528 break;
00529 }
00530 case 4:
00531 {
00532 register unsigned char
00533 pixel;
00534
00535 for (x=0; x < (long) number_pixels; x++)
00536 {
00537 pixel=(unsigned char) ((*p >> 4) & 0xf);
00538 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00539 *q=image->colormap[(long) indexes[x]];
00540 q->opacity=(Quantum) (QuantumRange-(QuantumRange*((int) (*p) &
00541 0xf)/15));
00542 p++;
00543 q++;
00544 }
00545 break;
00546 }
00547 case 8:
00548 {
00549 unsigned char
00550 pixel;
00551
00552 for (x=0; x < (long) number_pixels; x++)
00553 {
00554 p=PushCharPixel(p,&pixel);
00555 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00556 *q=image->colormap[(long) indexes[x]];
00557 p=PushCharPixel(p,&pixel);
00558 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
00559 p+=quantum_info->pad;
00560 q++;
00561 }
00562 break;
00563 }
00564 case 16:
00565 {
00566 unsigned short
00567 pixel;
00568
00569 for (x=0; x < (long) number_pixels; x++)
00570 {
00571 p=PushShortPixel(endian,p,&pixel);
00572 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00573 *q=image->colormap[(long) indexes[x]];
00574 p=PushShortPixel(endian,p,&pixel);
00575 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
00576 p+=quantum_info->pad;
00577 q++;
00578 }
00579 break;
00580 }
00581 case 32:
00582 {
00583 unsigned long
00584 pixel;
00585
00586 if (quantum_info->format == FloatingPointQuantumFormat)
00587 {
00588 float
00589 pixel;
00590
00591 for (x=0; x < (long) number_pixels; x++)
00592 {
00593 p=PushFloatPixel(&quantum_state,p,&pixel);
00594 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
00595 &range_exception);
00596 *q=image->colormap[(long) indexes[x]];
00597 p=PushFloatPixel(&quantum_state,p,&pixel);
00598 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
00599 p+=quantum_info->pad;
00600 q++;
00601 }
00602 break;
00603 }
00604 for (x=0; x < (long) number_pixels; x++)
00605 {
00606 p=PushLongPixel(endian,p,&pixel);
00607 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00608 *q=image->colormap[(long) indexes[x]];
00609 p=PushLongPixel(endian,p,&pixel);
00610 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
00611 p+=quantum_info->pad;
00612 q++;
00613 }
00614 break;
00615 }
00616 case 64:
00617 {
00618 if (quantum_info->format == FloatingPointQuantumFormat)
00619 {
00620 double
00621 pixel;
00622
00623 for (x=0; x < (long) number_pixels; x++)
00624 {
00625 p=PushDoublePixel(&quantum_state,p,&pixel);
00626 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
00627 &range_exception);
00628 *q=image->colormap[(long) indexes[x]];
00629 p=PushDoublePixel(&quantum_state,p,&pixel);
00630 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
00631 p+=quantum_info->pad;
00632 q++;
00633 }
00634 break;
00635 }
00636 }
00637 default:
00638 {
00639 scale=GetQuantumScale(image->depth);
00640 for (x=0; x < (long) number_pixels; x++)
00641 {
00642 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
00643 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
00644 *q=image->colormap[(long) indexes[x]];
00645 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
00646 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,
00647 image->depth,scale));
00648 p+=quantum_info->pad;
00649 q++;
00650 }
00651 break;
00652 }
00653 }
00654 if (range_exception != MagickFalse)
00655 (void) ThrowMagickException(exception,GetMagickModule(),
00656 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
00657 break;
00658 }
00659 case GrayQuantum:
00660 {
00661 switch (quantum_info->depth)
00662 {
00663 case 1:
00664 {
00665 register Quantum
00666 black,
00667 white;
00668
00669 black=0;
00670 white=(Quantum) QuantumRange;
00671 if (quantum_info->min_is_white != MagickFalse)
00672 {
00673 black=(Quantum) QuantumRange;
00674 white=0;
00675 }
00676 for (x=0; x < ((long) number_pixels-7); x+=8)
00677 {
00678 for (bit=0; bit < 8; bit++)
00679 {
00680 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
00681 q->green=q->red;
00682 q->blue=q->red;
00683 q++;
00684 }
00685 p++;
00686 }
00687 for (bit=0; bit < (long) (number_pixels % 8); bit++)
00688 {
00689 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
00690 q->green=q->red;
00691 q->blue=q->red;
00692 q++;
00693 }
00694 if (bit != 0)
00695 p++;
00696 break;
00697 }
00698 case 4:
00699 {
00700 register unsigned char
00701 pixel;
00702
00703 scale=GetQuantumScale(image->depth);
00704 for (x=0; x < ((long) number_pixels-1); x+=2)
00705 {
00706 pixel=(unsigned char) ((*p >> 4) & 0xf);
00707 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
00708 q->green=q->red;
00709 q->blue=q->red;
00710 q++;
00711 pixel=(unsigned char) ((*p) & 0xf);
00712 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
00713 q->green=q->red;
00714 q->blue=q->red;
00715 p++;
00716 q++;
00717 }
00718 for (bit=0; bit < (long) (number_pixels % 2); bit++)
00719 {
00720 pixel=(unsigned char) (*p++ >> 4);
00721 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
00722 q->green=q->red;
00723 q->blue=q->red;
00724 q++;
00725 }
00726 break;
00727 }
00728 case 8:
00729 {
00730 unsigned char
00731 pixel;
00732
00733 if (quantum_info->min_is_white != MagickFalse)
00734 {
00735 for (x=0; x < (long) number_pixels; x++)
00736 {
00737 p=PushCharPixel(p,&pixel);
00738 q->red=(Quantum) (QuantumRange-q->red);
00739 q->green=q->red;
00740 q->blue=q->red;
00741 p+=quantum_info->pad;
00742 q++;
00743 }
00744 break;
00745 }
00746 for (x=0; x < (long) number_pixels; x++)
00747 {
00748 p=PushCharPixel(p,&pixel);
00749 q->red=ScaleCharToQuantum(pixel);
00750 q->green=q->red;
00751 q->blue=q->red;
00752 p+=quantum_info->pad;
00753 q++;
00754 }
00755 break;
00756 }
00757 case 10:
00758 {
00759 scale=GetQuantumScale(image->depth);
00760 if (quantum_info->pack == MagickFalse)
00761 {
00762 if (image->endian != LSBEndian)
00763 {
00764 for (x=0; x < (long) number_pixels/3; x++)
00765 {
00766 p=PushLongPixel(endian,p,&pixel);
00767 q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,image->depth,
00768 scale);
00769 q->green=q->red;
00770 q->blue=q->red;
00771 q++;
00772 q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,image->depth,
00773 scale);
00774 q->green=q->red;
00775 q->blue=q->red;
00776 q++;
00777 q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,image->depth,
00778 scale);
00779 q->green=q->red;
00780 q->blue=q->red;
00781 p+=quantum_info->pad;
00782 q++;
00783 }
00784 break;
00785 }
00786 for (x=0; x < (long) number_pixels/3; x++)
00787 {
00788 p=PushLongPixel(endian,p,&pixel);
00789 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,image->depth,
00790 scale);
00791 q->green=q->red;
00792 q->blue=q->red;
00793 q++;
00794 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,image->depth,
00795 scale);
00796 q->green=q->red;
00797 q->blue=q->red;
00798 q++;
00799 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,image->depth,
00800 scale);
00801 q->green=q->red;
00802 q->blue=q->red;
00803 p+=quantum_info->pad;
00804 q++;
00805 }
00806 break;
00807 }
00808 for (x=0; x < (long) number_pixels; x++)
00809 {
00810 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
00811 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
00812 q->green=q->red;
00813 q->blue=q->red;
00814 p+=quantum_info->pad;
00815 q++;
00816 }
00817 break;
00818 }
00819 case 12:
00820 {
00821 scale=GetQuantumScale(image->depth);
00822 if (quantum_info->pack == MagickFalse)
00823 {
00824 unsigned short
00825 pixel;
00826
00827 for (x=0; x < (long) (number_pixels-1); x+=2)
00828 {
00829 p=PushShortPixel(endian,p,&pixel);
00830 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),image->depth,
00831 scale);
00832 q->green=q->red;
00833 q->blue=q->red;
00834 q++;
00835 p=PushShortPixel(endian,p,&pixel);
00836 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),image->depth,
00837 scale);
00838 q->green=q->red;
00839 q->blue=q->red;
00840 p+=quantum_info->pad;
00841 q++;
00842 }
00843 for (bit=0; bit < (long) (number_pixels % 2); bit++)
00844 {
00845 p=PushShortPixel(endian,p,&pixel);
00846 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),image->depth,
00847 scale);
00848 q->green=q->red;
00849 q->blue=q->red;
00850 p+=quantum_info->pad;
00851 q++;
00852 }
00853 if (bit != 0)
00854 p++;
00855 break;
00856 }
00857 for (x=0; x < (long) number_pixels; x++)
00858 {
00859 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
00860 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
00861 q->green=q->red;
00862 q->blue=q->red;
00863 p+=quantum_info->pad;
00864 q++;
00865 }
00866 break;
00867 }
00868 case 16:
00869 {
00870 unsigned short
00871 pixel;
00872
00873 if (quantum_info->min_is_white != MagickFalse)
00874 {
00875 for (x=0; x < (long) number_pixels; x++)
00876 {
00877 p=PushShortPixel(endian,p,&pixel);
00878 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
00879 q->green=q->red;
00880 q->blue=q->red;
00881 p+=quantum_info->pad;
00882 q++;
00883 }
00884 break;
00885 }
00886 for (x=0; x < (long) number_pixels; x++)
00887 {
00888 p=PushShortPixel(endian,p,&pixel);
00889 q->red=ScaleShortToQuantum(pixel);
00890 q->green=q->red;
00891 q->blue=q->red;
00892 p+=quantum_info->pad;
00893 q++;
00894 }
00895 break;
00896 }
00897 case 32:
00898 {
00899 unsigned long
00900 pixel;
00901
00902 if (quantum_info->format == FloatingPointQuantumFormat)
00903 {
00904 float
00905 pixel;
00906
00907 for (x=0; x < (long) number_pixels; x++)
00908 {
00909 p=PushFloatPixel(&quantum_state,p,&pixel);
00910 q->red=RoundToQuantum(pixel);
00911 q->green=q->red;
00912 q->blue=q->red;
00913 p+=quantum_info->pad;
00914 q++;
00915 }
00916 break;
00917 }
00918 for (x=0; x < (long) number_pixels; x++)
00919 {
00920 p=PushLongPixel(endian,p,&pixel);
00921 q->red=ScaleLongToQuantum(pixel);
00922 q->green=q->red;
00923 q->blue=q->red;
00924 p+=quantum_info->pad;
00925 q++;
00926 }
00927 break;
00928 }
00929 case 64:
00930 {
00931 if (quantum_info->format == FloatingPointQuantumFormat)
00932 {
00933 double
00934 pixel;
00935
00936 for (x=0; x < (long) number_pixels; x++)
00937 {
00938 p=PushDoublePixel(&quantum_state,p,&pixel);
00939 q->red=RoundToQuantum(pixel);
00940 q->green=q->red;
00941 q->blue=q->red;
00942 p+=quantum_info->pad;
00943 q++;
00944 }
00945 break;
00946 }
00947 }
00948 default:
00949 {
00950 scale=GetQuantumScale(image->depth);
00951 for (x=0; x < (long) number_pixels; x++)
00952 {
00953 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
00954 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
00955 q->green=q->red;
00956 q->blue=q->red;
00957 p+=quantum_info->pad;
00958 q++;
00959 }
00960 break;
00961 }
00962 }
00963 break;
00964 }
00965 case GrayAlphaQuantum:
00966 {
00967 switch (quantum_info->depth)
00968 {
00969 case 1:
00970 {
00971 register unsigned char
00972 pixel;
00973
00974 for (x=0; x < ((long) number_pixels-3); x+=4)
00975 {
00976 for (bit=0; bit < 8; bit+=2)
00977 {
00978 pixel=(unsigned char)
00979 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
00980 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
00981 q->green=q->red;
00982 q->blue=q->red;
00983 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
00984 == 0 ? TransparentOpacity : OpaqueOpacity);
00985 q++;
00986 }
00987 p++;
00988 }
00989 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
00990 {
00991 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
00992 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
00993 q->green=q->red;
00994 q->blue=q->red;
00995 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
00996 ? TransparentOpacity : OpaqueOpacity);
00997 q++;
00998 }
00999 if (bit != 0)
01000 p++;
01001 break;
01002 }
01003 case 4:
01004 {
01005 register unsigned char
01006 pixel;
01007
01008 scale=GetQuantumScale(image->depth);
01009 for (x=0; x < (long) number_pixels; x++)
01010 {
01011 pixel=(unsigned char) ((*p >> 4) & 0xf);
01012 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
01013 q->green=q->red;
01014 q->blue=q->red;
01015 q->opacity=(Quantum) (QuantumRange-(QuantumRange*((*p) & 0xf)/15));
01016 p++;
01017 q++;
01018 }
01019 break;
01020 }
01021 case 8:
01022 {
01023 unsigned char
01024 pixel;
01025
01026 for (x=0; x < (long) number_pixels; x++)
01027 {
01028 p=PushCharPixel(p,&pixel);
01029 q->red=ScaleCharToQuantum(pixel);
01030 q->green=q->red;
01031 q->blue=q->red;
01032 p=PushCharPixel(p,&pixel);
01033 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
01034 p+=quantum_info->pad;
01035 q++;
01036 }
01037 break;
01038 }
01039 case 10:
01040 {
01041 scale=GetQuantumScale(image->depth);
01042 for (x=0; x < (long) number_pixels; x++)
01043 {
01044 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
01045 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
01046 q->green=q->red;
01047 q->blue=q->red;
01048 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
01049 q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
01050 p+=quantum_info->pad;
01051 q++;
01052 }
01053 break;
01054 }
01055 case 12:
01056 {
01057 scale=GetQuantumScale(image->depth);
01058 for (x=0; x < (long) number_pixels; x++)
01059 {
01060 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
01061 q->red=ScaleAnyToQuantum(pixel,image->depth,scale);
01062 q->green=q->red;
01063 q->blue=q->red;
01064 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
01065 q->opacity=ScaleAnyToQuantum(pixel,image->depth,scale);
01066 p+=quantum_info->pad;
01067 q++;
01068 }
01069 break;
01070 }
01071 case 16:
01072 {
01073 unsigned short
01074 pixel;
01075
01076 for (x=0; x < (long) number_pixels; x++)
01077 {
01078 p=PushShortPixel(endian,p,&pixel);
01079 q->red=ScaleShortToQuantum(pixel);
01080 q->green=q->red;
01081 q->blue=q->red;
01082 p=PushShortPixel(endian,p,&pixel);
01083 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
01084 p+=quantum_info->pad;
01085 q++;
01086