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-2008 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=