pixel.c

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

Generated on 19 Nov 2009 for MagickCore by  doxygen 1.6.1