Ignore:
Timestamp:
May 20, 2000, 3:48:23 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/glu/util/mipmap.c

    r2689 r3579  
    1 /* $Id: mipmap.c,v 1.1 2000-02-09 08:47:12 jeroen Exp $ */
     1/* $Id: mipmap.c,v 1.2 2000-05-20 13:47:55 jeroen Exp $ */
    22/*
    33** License Applicability. Except to the extent portions of this file are
     
    3333** compliant with the OpenGL(R) version 1.2.1 Specification.
    3434**
    35 ** $Date: 2000-02-09 08:47:12 $ $Revision: 1.1 $
    36 ** $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/util/mipmap.c,v 1.1 2000-02-09 08:47:12 jeroen Exp $
     35** $Date: 2000-05-20 13:47:55 $ $Revision: 1.2 $
     36** $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/util/mipmap.c,v 1.2 2000-05-20 13:47:55 jeroen Exp $
    3737*/
    3838
     
    39683968            halveImage_ushort(cmpts, width, height,
    39693969                              (GLushort *)usersImage, (GLushort *)dstImage,
    3970                               element_size, rowsize, group_size, myswap_bytes);
    3971             break;
    3972           case GL_SHORT:
    3973             halveImage_short(cmpts, width, height,
    3974                              (GLshort *)usersImage, (GLshort *)dstImage,
    3975                              element_size, rowsize, group_size, myswap_bytes);
    3976             break;
    3977           case GL_UNSIGNED_INT:
    3978             halveImage_uint(cmpts, width, height,
    3979                             (GLuint *)usersImage, (GLuint *)dstImage,
    3980                             element_size, rowsize, group_size, myswap_bytes);
    3981             break;
    3982           case GL_INT:
    3983             halveImage_int(cmpts, width, height,
    3984                            (GLint *)usersImage, (GLint *)dstImage,
    3985                            element_size, rowsize, group_size, myswap_bytes);
    3986             break;
    3987           case GL_FLOAT:
    3988             halveImage_float(cmpts, width, height,
    3989                              (GLfloat *)usersImage, (GLfloat *)dstImage,
    3990                              element_size, rowsize, group_size, myswap_bytes);
    3991             break;
    3992           case GL_UNSIGNED_BYTE_3_3_2:
    3993             assert(format == GL_RGB);
    3994             halveImagePackedPixel(3,extract332,shove332,
    3995                                   width,height,usersImage,dstImage,
    3996                                   element_size,rowsize,myswap_bytes);
    3997             break;
     3970                              element_size, rowsize, group_size, myswap_bytes);
     3971            break;
     3972          case GL_SHORT:
     3973            halveImage_short(cmpts, width, height,
     3974                             (GLshort *)usersImage, (GLshort *)dstImage,
     3975                             element_size, rowsize, group_size, myswap_bytes);
     3976            break;
     3977          case GL_UNSIGNED_INT:
     3978            halveImage_uint(cmpts, width, height,
     3979                            (GLuint *)usersImage, (GLuint *)dstImage,
     3980                            element_size, rowsize, group_size, myswap_bytes);
     3981            break;
     3982          case GL_INT:
     3983            halveImage_int(cmpts, width, height,
     3984                           (GLint *)usersImage, (GLint *)dstImage,
     3985                           element_size, rowsize, group_size, myswap_bytes);
     3986            break;
     3987          case GL_FLOAT:
     3988            halveImage_float(cmpts, width, height,
     3989                             (GLfloat *)usersImage, (GLfloat *)dstImage,
     3990                             element_size, rowsize, group_size, myswap_bytes);
     3991            break;
     3992          case GL_UNSIGNED_BYTE_3_3_2:
     3993            assert(format == GL_RGB);
     3994            halveImagePackedPixel(3,extract332,shove332,
     3995                                  width,height,usersImage,dstImage,
     3996                                  element_size,rowsize,myswap_bytes);
     3997            break;
    39983998          case GL_UNSIGNED_BYTE_2_3_3_REV:
    3999             assert(format == GL_RGB);
    4000             halveImagePackedPixel(3,extract233rev,shove233rev,
    4001                                   width,height,usersImage,dstImage,
    4002                                   element_size,rowsize,myswap_bytes);
    4003             break;
     3999            assert(format == GL_RGB);
     4000            halveImagePackedPixel(3,extract233rev,shove233rev,
     4001                                  width,height,usersImage,dstImage,
     4002                                  element_size,rowsize,myswap_bytes);
     4003            break;
    40044004          case GL_UNSIGNED_SHORT_5_6_5:
    4005             halveImagePackedPixel(3,extract565,shove565,
    4006                                   width,height,usersImage,dstImage,
    4007                                   element_size,rowsize,myswap_bytes);
    4008             break;
     4005            halveImagePackedPixel(3,extract565,shove565,
     4006                                  width,height,usersImage,dstImage,
     4007                                  element_size,rowsize,myswap_bytes);
     4008            break;
    40094009          case GL_UNSIGNED_SHORT_5_6_5_REV:
    4010             halveImagePackedPixel(3,extract565rev,shove565rev,
    4011                                   width,height,usersImage,dstImage,
    4012                                   element_size,rowsize,myswap_bytes);
    4013             break;
     4010            halveImagePackedPixel(3,extract565rev,shove565rev,
     4011                                  width,height,usersImage,dstImage,
     4012                                  element_size,rowsize,myswap_bytes);
     4013            break;
    40144014          case GL_UNSIGNED_SHORT_4_4_4_4:
    4015             halveImagePackedPixel(4,extract4444,shove4444,
    4016                                   width,height,usersImage,dstImage,
    4017                                   element_size,rowsize,myswap_bytes);
    4018             break;
     4015            halveImagePackedPixel(4,extract4444,shove4444,
     4016                                  width,height,usersImage,dstImage,
     4017                                  element_size,rowsize,myswap_bytes);
     4018            break;
    40194019          case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    4020             halveImagePackedPixel(4,extract4444rev,shove4444rev,
    4021                                   width,height,usersImage,dstImage,
    4022                                   element_size,rowsize,myswap_bytes);
    4023             break;
     4020            halveImagePackedPixel(4,extract4444rev,shove4444rev,
     4021                                  width,height,usersImage,dstImage,
     4022                                  element_size,rowsize,myswap_bytes);
     4023            break;
    40244024          case GL_UNSIGNED_SHORT_5_5_5_1:
    4025             halveImagePackedPixel(4,extract5551,shove5551,
    4026                                   width,height,usersImage,dstImage,
    4027                                   element_size,rowsize,myswap_bytes);
    4028             break;
     4025            halveImagePackedPixel(4,extract5551,shove5551,
     4026                                  width,height,usersImage,dstImage,
     4027                                  element_size,rowsize,myswap_bytes);
     4028            break;
    40294029          case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    4030             halveImagePackedPixel(4,extract1555rev,shove1555rev,
    4031                                   width,height,usersImage,dstImage,
    4032                                   element_size,rowsize,myswap_bytes);
    4033             break;
     4030            halveImagePackedPixel(4,extract1555rev,shove1555rev,
     4031                                  width,height,usersImage,dstImage,
     4032                                  element_size,rowsize,myswap_bytes);
     4033            break;
    40344034          case GL_UNSIGNED_INT_8_8_8_8:
    4035             halveImagePackedPixel(4,extract8888,shove8888,
    4036                                   width,height,usersImage,dstImage,
    4037                                   element_size,rowsize,myswap_bytes);
    4038             break;
     4035            halveImagePackedPixel(4,extract8888,shove8888,
     4036                                  width,height,usersImage,dstImage,
     4037                                  element_size,rowsize,myswap_bytes);
     4038            break;
    40394039          case GL_UNSIGNED_INT_8_8_8_8_REV:
    4040             halveImagePackedPixel(4,extract8888rev,shove8888rev,
    4041                                   width,height,usersImage,dstImage,
    4042                                   element_size,rowsize,myswap_bytes);
    4043             break;
     4040            halveImagePackedPixel(4,extract8888rev,shove8888rev,
     4041                                  width,height,usersImage,dstImage,
     4042                                  element_size,rowsize,myswap_bytes);
     4043            break;
    40444044          case GL_UNSIGNED_INT_10_10_10_2:
    4045             halveImagePackedPixel(4,extract1010102,shove1010102,
    4046                                   width,height,usersImage,dstImage,
    4047                                   element_size,rowsize,myswap_bytes);
    4048             break;
     4045            halveImagePackedPixel(4,extract1010102,shove1010102,
     4046                                  width,height,usersImage,dstImage,
     4047                                  element_size,rowsize,myswap_bytes);
     4048            break;
    40494049          case GL_UNSIGNED_INT_2_10_10_10_REV:
    4050             halveImagePackedPixel(4,extract2101010rev,shove2101010rev,
    4051                                   width,height,usersImage,dstImage,
    4052                                   element_size,rowsize,myswap_bytes);
    4053             break;
     4050            halveImagePackedPixel(4,extract2101010rev,shove2101010rev,
     4051                                  width,height,usersImage,dstImage,
     4052                                  element_size,rowsize,myswap_bytes);
     4053            break;
    40544054          default:
    4055             assert(0);
    4056             break;
    4057           }
    4058         newwidth = width/2;
    4059         newheight = height/2;
    4060         /* clamp to 1 */
    4061         if (newwidth < 1) newwidth= 1;
    4062         if (newheight < 1) newheight= 1;
    4063 
    4064         myswap_bytes = 0;
    4065         rowsize = newwidth * group_size;
    4066         memreq = image_size(newwidth, newheight, format, type);
    4067         /* Swap srcImage and dstImage */
    4068         __GLU_SWAP_IMAGE(srcImage,dstImage);
    4069         switch(type) {
    4070         case GL_UNSIGNED_BYTE:
    4071           dstImage = (GLubyte *)malloc(memreq);
    4072           break;
    4073         case GL_BYTE:
    4074           dstImage = (GLbyte *)malloc(memreq);
    4075           break;
    4076         case GL_UNSIGNED_SHORT:
    4077           dstImage = (GLushort *)malloc(memreq);
    4078           break;
    4079         case GL_SHORT:
    4080           dstImage = (GLshort *)malloc(memreq);
    4081           break;
    4082         case GL_UNSIGNED_INT:
    4083           dstImage = (GLuint *)malloc(memreq);
    4084           break;
    4085         case GL_INT:
    4086           dstImage = (GLint *)malloc(memreq);
    4087           break;
    4088         case GL_FLOAT:
    4089           dstImage = (GLfloat *)malloc(memreq);
    4090           break;
     4055            assert(0);
     4056            break;
     4057          }
     4058        newwidth = width/2;
     4059        newheight = height/2;
     4060        /* clamp to 1 */
     4061        if (newwidth < 1) newwidth= 1;
     4062        if (newheight < 1) newheight= 1;
     4063
     4064        myswap_bytes = 0;
     4065        rowsize = newwidth * group_size;
     4066        memreq = image_size(newwidth, newheight, format, type);
     4067        /* Swap srcImage and dstImage */
     4068        __GLU_SWAP_IMAGE(srcImage,dstImage);
     4069        switch(type) {
     4070        case GL_UNSIGNED_BYTE:
     4071          dstImage = (GLubyte *)malloc(memreq);
     4072          break;
     4073        case GL_BYTE:
     4074          dstImage = (GLbyte *)malloc(memreq);
     4075          break;
     4076        case GL_UNSIGNED_SHORT:
     4077          dstImage = (GLushort *)malloc(memreq);
     4078          break;
     4079        case GL_SHORT:
     4080          dstImage = (GLshort *)malloc(memreq);
     4081          break;
     4082        case GL_UNSIGNED_INT:
     4083          dstImage = (GLuint *)malloc(memreq);
     4084          break;
     4085        case GL_INT:
     4086          dstImage = (GLint *)malloc(memreq);
     4087          break;
     4088        case GL_FLOAT:
     4089          dstImage = (GLfloat *)malloc(memreq);
     4090          break;
    40914091        case GL_UNSIGNED_BYTE_3_3_2:
    40924092        case GL_UNSIGNED_BYTE_2_3_3_REV:
    4093           dstImage = (GLubyte *)malloc(memreq);
    4094           break;
     4093          dstImage = (GLubyte *)malloc(memreq);
     4094          break;
    40954095        case GL_UNSIGNED_SHORT_5_6_5:
    40964096        case GL_UNSIGNED_SHORT_5_6_5_REV:
     
    40994099        case GL_UNSIGNED_SHORT_5_5_5_1:
    41004100        case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    4101           dstImage = (GLushort *)malloc(memreq);
    4102           break;
     4101          dstImage = (GLushort *)malloc(memreq);
     4102          break;
    41034103        case GL_UNSIGNED_INT_8_8_8_8:
    41044104        case GL_UNSIGNED_INT_8_8_8_8_REV:
    41054105        case GL_UNSIGNED_INT_10_10_10_2:
    41064106        case GL_UNSIGNED_INT_2_10_10_10_REV:
    4107           dstImage = (GLuint *)malloc(memreq);
    4108           break;
    4109         default:
    4110           return GLU_INVALID_ENUM;
    4111         }
    4112         if (dstImage == NULL) {
    4113           glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    4114           glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    4115           glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    4116           glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    4117           glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    4118           return GLU_OUT_OF_MEMORY;
    4119         }
    4120         /* level userLevel+1 is in srcImage; level userLevel already saved */
    4121         level = userLevel+1;
     4107          dstImage = (GLuint *)malloc(memreq);
     4108          break;
     4109        default:
     4110          return GLU_INVALID_ENUM;
     4111        }
     4112        if (dstImage == NULL) {
     4113          glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     4114          glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     4115          glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     4116          glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     4117          glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     4118          return GLU_OUT_OF_MEMORY;
     4119        }
     4120        /* level userLevel+1 is in srcImage; level userLevel already saved */
     4121        level = userLevel+1;
    41224122    } else { /* user's image is *not* nice power-of-2 sized square */
    4123         memreq = image_size(newwidth, newheight, format, type);
    4124         switch(type) {
     4123        memreq = image_size(newwidth, newheight, format, type);
     4124        switch(type) {
    41254125            case GL_UNSIGNED_BYTE:
    41264126                dstImage = (GLubyte *)malloc(memreq);
     
    41474147            case GL_UNSIGNED_BYTE_2_3_3_REV:
    41484148                dstImage = (GLubyte *)malloc(memreq);
    4149                 break;
    4150             case GL_UNSIGNED_SHORT_5_6_5:
    4151             case GL_UNSIGNED_SHORT_5_6_5_REV:
    4152             case GL_UNSIGNED_SHORT_4_4_4_4:
    4153             case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    4154             case GL_UNSIGNED_SHORT_5_5_5_1:
    4155             case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    4156                 dstImage = (GLushort *)malloc(memreq);
    4157                 break;
    4158             case GL_UNSIGNED_INT_8_8_8_8:
    4159             case GL_UNSIGNED_INT_8_8_8_8_REV:
    4160             case GL_UNSIGNED_INT_10_10_10_2:
    4161             case GL_UNSIGNED_INT_2_10_10_10_REV:
    4162                 dstImage = (GLuint *)malloc(memreq);
    4163                 break;
     4149                break;
     4150            case GL_UNSIGNED_SHORT_5_6_5:
     4151            case GL_UNSIGNED_SHORT_5_6_5_REV:
     4152            case GL_UNSIGNED_SHORT_4_4_4_4:
     4153            case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     4154            case GL_UNSIGNED_SHORT_5_5_5_1:
     4155            case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     4156                dstImage = (GLushort *)malloc(memreq);
     4157                break;
     4158            case GL_UNSIGNED_INT_8_8_8_8:
     4159            case GL_UNSIGNED_INT_8_8_8_8_REV:
     4160            case GL_UNSIGNED_INT_10_10_10_2:
     4161            case GL_UNSIGNED_INT_2_10_10_10_REV:
     4162                dstImage = (GLuint *)malloc(memreq);
     4163                break;
    41644164            default:
    41654165                return GLU_INVALID_ENUM;
    41664166        }
    41674167
    4168         if (dstImage == NULL) {
    4169             glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    4170             glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    4171             glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    4172             glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    4173             glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    4174             return GLU_OUT_OF_MEMORY;
    4175         }
    4176 
    4177         switch(type) {
    4178         case GL_UNSIGNED_BYTE:
    4179             scale_internal_ubyte(cmpts, width, height,
    4180                                 (GLubyte *)usersImage, newwidth, newheight,
    4181                                 (GLubyte *)dstImage, element_size,
    4182                                 rowsize, group_size);
    4183             break;
    4184         case GL_BYTE:
    4185             scale_internal_byte(cmpts, width, height,
    4186                                 (GLbyte *)usersImage, newwidth, newheight,
    4187                                 (GLbyte *)dstImage, element_size,
    4188                                 rowsize, group_size);
    4189             break;
    4190         case GL_UNSIGNED_SHORT:
    4191             scale_internal_ushort(cmpts, width, height,
    4192                                   (GLushort *)usersImage, newwidth, newheight,
    4193                                   (GLushort *)dstImage, element_size,
    4194                                   rowsize, group_size, myswap_bytes);
    4195             break;
    4196         case GL_SHORT:
    4197             scale_internal_short(cmpts, width, height,
    4198                                 (GLshort *)usersImage, newwidth, newheight,
    4199                                 (GLshort *)dstImage, element_size,
    4200                                 rowsize, group_size, myswap_bytes);
    4201             break;
    4202         case GL_UNSIGNED_INT:
    4203             scale_internal_uint(cmpts, width, height,
    4204                                 (GLuint *)usersImage, newwidth, newheight,
    4205                                 (GLuint *)dstImage, element_size,
    4206                                 rowsize, group_size, myswap_bytes);
    4207             break;
    4208         case GL_INT:
    4209             scale_internal_int(cmpts, width, height,
    4210                                (GLint *)usersImage, newwidth, newheight,
    4211                                (GLint *)dstImage, element_size,
    4212                                rowsize, group_size, myswap_bytes);
    4213             break;
    4214         case GL_FLOAT:
    4215             scale_internal_float(cmpts, width, height,
    4216                                 (GLfloat *)usersImage, newwidth, newheight,
    4217                                 (GLfloat *)dstImage, element_size,
    4218                                 rowsize, group_size, myswap_bytes);
    4219             break;
     4168        if (dstImage == NULL) {
     4169            glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     4170            glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     4171            glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     4172            glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     4173            glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     4174            return GLU_OUT_OF_MEMORY;
     4175        }
     4176
     4177        switch(type) {
     4178        case GL_UNSIGNED_BYTE:
     4179            scale_internal_ubyte(cmpts, width, height,
     4180                                (GLubyte *)usersImage, newwidth, newheight,
     4181                                (GLubyte *)dstImage, element_size,
     4182                                rowsize, group_size);
     4183            break;
     4184        case GL_BYTE:
     4185            scale_internal_byte(cmpts, width, height,
     4186                                (GLbyte *)usersImage, newwidth, newheight,
     4187                                (GLbyte *)dstImage, element_size,
     4188                                rowsize, group_size);
     4189            break;
     4190        case GL_UNSIGNED_SHORT:
     4191            scale_internal_ushort(cmpts, width, height,
     4192                                  (GLushort *)usersImage, newwidth, newheight,
     4193                                  (GLushort *)dstImage, element_size,
     4194                                  rowsize, group_size, myswap_bytes);
     4195            break;
     4196        case GL_SHORT:
     4197            scale_internal_short(cmpts, width, height,
     4198                                (GLshort *)usersImage, newwidth, newheight,
     4199                                (GLshort *)dstImage, element_size,
     4200                                rowsize, group_size, myswap_bytes);
     4201            break;
     4202        case GL_UNSIGNED_INT:
     4203            scale_internal_uint(cmpts, width, height,
     4204                                (GLuint *)usersImage, newwidth, newheight,
     4205                                (GLuint *)dstImage, element_size,
     4206                                rowsize, group_size, myswap_bytes);
     4207            break;
     4208        case GL_INT:
     4209            scale_internal_int(cmpts, width, height,
     4210                               (GLint *)usersImage, newwidth, newheight,
     4211                               (GLint *)dstImage, element_size,
     4212                               rowsize, group_size, myswap_bytes);
     4213            break;
     4214        case GL_FLOAT:
     4215            scale_internal_float(cmpts, width, height,
     4216                                (GLfloat *)usersImage, newwidth, newheight,
     4217                                (GLfloat *)dstImage, element_size,
     4218                                rowsize, group_size, myswap_bytes);
     4219            break;
    42204220        case GL_UNSIGNED_BYTE_3_3_2:
    4221             scaleInternalPackedPixel(3,extract332,shove332,
    4222                                      width, height,(const void *)usersImage,
    4223                                      newwidth,newheight,(void *)dstImage,
    4224                                      element_size,rowsize,myswap_bytes);
    4225             break;
     4221            scaleInternalPackedPixel(3,extract332,shove332,
     4222                                     width, height,(const void *)usersImage,
     4223                                     newwidth,newheight,(void *)dstImage,
     4224                                     element_size,rowsize,myswap_bytes);
     4225            break;
    42264226        case GL_UNSIGNED_BYTE_2_3_3_REV:
    4227             scaleInternalPackedPixel(3,extract233rev,shove233rev,
    4228                                      width, height,(const void *)usersImage,
    4229                                      newwidth,newheight,(void *)dstImage,
    4230                                      element_size,rowsize,myswap_bytes);
    4231             break;
     4227            scaleInternalPackedPixel(3,extract233rev,shove233rev,
     4228                                     width, height,(const void *)usersImage,
     4229                                     newwidth,newheight,(void *)dstImage,
     4230                                     element_size,rowsize,myswap_bytes);
     4231            break;
    42324232        case GL_UNSIGNED_SHORT_5_6_5:
    4233             scaleInternalPackedPixel(3,extract565,shove565,
    4234                                      width, height,(const void *)usersImage,
    4235                                      newwidth,newheight,(void *)dstImage,
    4236                                      element_size,rowsize,myswap_bytes);
    4237             break;
     4233            scaleInternalPackedPixel(3,extract565,shove565,
     4234                                     width, height,(const void *)usersImage,
     4235                                     newwidth,newheight,(void *)dstImage,
     4236                                     element_size,rowsize,myswap_bytes);
     4237            break;
    42384238        case GL_UNSIGNED_SHORT_5_6_5_REV:
    4239             scaleInternalPackedPixel(3,extract565rev,shove565rev,
    4240                                      width, height,(const void *)usersImage,
    4241                                      newwidth,newheight,(void *)dstImage,
    4242                                      element_size,rowsize,myswap_bytes);
    4243             break;
     4239            scaleInternalPackedPixel(3,extract565rev,shove565rev,
     4240                                     width, height,(const void *)usersImage,
     4241                                     newwidth,newheight,(void *)dstImage,
     4242                                     element_size,rowsize,myswap_bytes);
     4243            break;
    42444244        case GL_UNSIGNED_SHORT_4_4_4_4:
    4245             scaleInternalPackedPixel(4,extract4444,shove4444,
    4246                                      width, height,(const void *)usersImage,
    4247                                      newwidth,newheight,(void *)dstImage,
    4248                                      element_size,rowsize,myswap_bytes);
    4249             break;
     4245            scaleInternalPackedPixel(4,extract4444,shove4444,
     4246                                     width, height,(const void *)usersImage,
     4247                                     newwidth,newheight,(void *)dstImage,
     4248                                     element_size,rowsize,myswap_bytes);
     4249            break;
    42504250        case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    4251             scaleInternalPackedPixel(4,extract4444rev,shove4444rev,
    4252                                      width, height,(const void *)usersImage,
    4253                                      newwidth,newheight,(void *)dstImage,
    4254                                      element_size,rowsize,myswap_bytes);
    4255             break;
     4251            scaleInternalPackedPixel(4,extract4444rev,shove4444rev,
     4252                                     width, height,(const void *)usersImage,
     4253                                     newwidth,newheight,(void *)dstImage,
     4254                                     element_size,rowsize,myswap_bytes);
     4255            break;
    42564256        case GL_UNSIGNED_SHORT_5_5_5_1:
    4257             scaleInternalPackedPixel(4,extract5551,shove5551,
    4258                                      width, height,(const void *)usersImage,
    4259                                      newwidth,newheight,(void *)dstImage,
    4260                                      element_size,rowsize,myswap_bytes);
    4261             break;
     4257            scaleInternalPackedPixel(4,extract5551,shove5551,
     4258                                     width, height,(const void *)usersImage,
     4259                                     newwidth,newheight,(void *)dstImage,
     4260                                     element_size,rowsize,myswap_bytes);
     4261            break;
    42624262        case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    4263             scaleInternalPackedPixel(4,extract1555rev,shove1555rev,
    4264                                      width, height,(const void *)usersImage,
    4265                                      newwidth,newheight,(void *)dstImage,
    4266                                      element_size,rowsize,myswap_bytes);
    4267             break;
     4263            scaleInternalPackedPixel(4,extract1555rev,shove1555rev,
     4264                                     width, height,(const void *)usersImage,
     4265                                     newwidth,newheight,(void *)dstImage,
     4266                                     element_size,rowsize,myswap_bytes);
     4267            break;
    42684268        case GL_UNSIGNED_INT_8_8_8_8:
    4269             scaleInternalPackedPixel(4,extract8888,shove8888,
    4270                                      width, height,(const void *)usersImage,
    4271                                      newwidth,newheight,(void *)dstImage,
    4272                                      element_size,rowsize,myswap_bytes);
    4273             break;
     4269            scaleInternalPackedPixel(4,extract8888,shove8888,
     4270                                     width, height,(const void *)usersImage,
     4271                                     newwidth,newheight,(void *)dstImage,
     4272                                     element_size,rowsize,myswap_bytes);
     4273            break;
    42744274        case GL_UNSIGNED_INT_8_8_8_8_REV:
    4275             scaleInternalPackedPixel(4,extract8888rev,shove8888rev,
    4276                                      width, height,(const void *)usersImage,
    4277                                      newwidth,newheight,(void *)dstImage,
    4278                                      element_size,rowsize,myswap_bytes);
    4279             break;
     4275            scaleInternalPackedPixel(4,extract8888rev,shove8888rev,
     4276                                     width, height,(const void *)usersImage,
     4277                                     newwidth,newheight,(void *)dstImage,
     4278                                     element_size,rowsize,myswap_bytes);
     4279            break;
    42804280        case GL_UNSIGNED_INT_10_10_10_2:
    4281             scaleInternalPackedPixel(4,extract1010102,shove1010102,
    4282                                      width, height,(const void *)usersImage,
    4283                                      newwidth,newheight,(void *)dstImage,
    4284                                      element_size,rowsize,myswap_bytes);
    4285             break;
     4281            scaleInternalPackedPixel(4,extract1010102,shove1010102,
     4282                                     width, height,(const void *)usersImage,
     4283                                     newwidth,newheight,(void *)dstImage,
     4284                                     element_size,rowsize,myswap_bytes);
     4285            break;
    42864286        case GL_UNSIGNED_INT_2_10_10_10_REV:
    4287             scaleInternalPackedPixel(4,extract2101010rev,shove2101010rev,
    4288                                      width, height,(const void *)usersImage,
    4289                                      newwidth,newheight,(void *)dstImage,
    4290                                      element_size,rowsize,myswap_bytes);
    4291             break;
     4287            scaleInternalPackedPixel(4,extract2101010rev,shove2101010rev,
     4288                                     width, height,(const void *)usersImage,
     4289                                     newwidth,newheight,(void *)dstImage,
     4290                                     element_size,rowsize,myswap_bytes);
     4291            break;
    42924292        default:
    4293             assert(0);
    4294             break;
    4295         }
    4296         myswap_bytes = 0;
    4297         rowsize = newwidth * group_size;
    4298         /* Swap dstImage and srcImage */
    4299         __GLU_SWAP_IMAGE(srcImage,dstImage);
    4300 
    4301         if(levels != 0) { /* use as little memory as possible */
     4293            assert(0);
     4294            break;
     4295        }
     4296        myswap_bytes = 0;
     4297        rowsize = newwidth * group_size;
     4298        /* Swap dstImage and srcImage */
     4299        __GLU_SWAP_IMAGE(srcImage,dstImage);
     4300
     4301        if(levels != 0) { /* use as little memory as possible */
    43024302          {
    4303              int nextWidth= newwidth/2;
    4304              int nextHeight= newheight/2;
    4305              if (nextWidth < 1) nextWidth= 1;
    4306              if (nextHeight < 1) nextHeight= 1;
    4307 
    4308           memreq = image_size(nextWidth, nextHeight, format, type);
     4303             int nextWidth= newwidth/2;
     4304             int nextHeight= newheight/2;
     4305             if (nextWidth < 1) nextWidth= 1;
     4306             if (nextHeight < 1) nextHeight= 1;
     4307
     4308          memreq = image_size(nextWidth, nextHeight, format, type);
    43094309          }
    43104310
    4311           switch(type) {
    4312           case GL_UNSIGNED_BYTE:
    4313             dstImage = (GLubyte *)malloc(memreq);
    4314             break;
    4315           case GL_BYTE:
    4316             dstImage = (GLbyte *)malloc(memreq);
    4317             break;
    4318           case GL_UNSIGNED_SHORT:
    4319             dstImage = (GLushort *)malloc(memreq);
    4320             break;
    4321           case GL_SHORT:
    4322             dstImage = (GLshort *)malloc(memreq);
    4323             break;
    4324           case GL_UNSIGNED_INT:
    4325             dstImage = (GLuint *)malloc(memreq);
    4326             break;
    4327           case GL_INT:
    4328             dstImage = (GLint *)malloc(memreq);
    4329             break;
    4330           case GL_FLOAT:
    4331             dstImage = (GLfloat *)malloc(memreq);
    4332             break;
     4311          switch(type) {
     4312          case GL_UNSIGNED_BYTE:
     4313            dstImage = (GLubyte *)malloc(memreq);
     4314            break;
     4315          case GL_BYTE:
     4316            dstImage = (GLbyte *)malloc(memreq);
     4317            break;
     4318          case GL_UNSIGNED_SHORT:
     4319            dstImage = (GLushort *)malloc(memreq);
     4320            break;
     4321          case GL_SHORT:
     4322            dstImage = (GLshort *)malloc(memreq);
     4323            break;
     4324          case GL_UNSIGNED_INT:
     4325            dstImage = (GLuint *)malloc(memreq);
     4326            break;
     4327          case GL_INT:
     4328            dstImage = (GLint *)malloc(memreq);
     4329            break;
     4330          case GL_FLOAT:
     4331            dstImage = (GLfloat *)malloc(memreq);
     4332            break;
    43334333          case GL_UNSIGNED_BYTE_3_3_2:
    43344334          case GL_UNSIGNED_BYTE_2_3_3_REV:
    4335             dstImage = (GLubyte *)malloc(memreq);
    4336             break;
     4335            dstImage = (GLubyte *)malloc(memreq);
     4336            break;
    43374337          case GL_UNSIGNED_SHORT_5_6_5:
    43384338          case GL_UNSIGNED_SHORT_5_6_5_REV:
    4339           case GL_UNSIGNED_SHORT_4_4_4_4:
    4340           case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    4341           case GL_UNSIGNED_SHORT_5_5_5_1:
    4342           case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    4343             dstImage = (GLushort *)malloc(memreq);
    4344             break;
    4345           case GL_UNSIGNED_INT_8_8_8_8:
    4346           case GL_UNSIGNED_INT_8_8_8_8_REV:
    4347           case GL_UNSIGNED_INT_10_10_10_2:
    4348           case GL_UNSIGNED_INT_2_10_10_10_REV:
    4349             dstImage = (GLuint *)malloc(memreq);
    4350             break;
    4351           default:
    4352             return GLU_INVALID_ENUM;
    4353           }
    4354           if (dstImage == NULL) {
    4355             glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    4356             glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    4357             glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    4358             glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    4359             glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    4360             return GLU_OUT_OF_MEMORY;
    4361           }
    4362         }
    4363         /* level userLevel is in srcImage; nothing saved yet */
    4364         level = userLevel;
     4339          case GL_UNSIGNED_SHORT_4_4_4_4:
     4340          case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     4341          case GL_UNSIGNED_SHORT_5_5_5_1:
     4342          case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     4343            dstImage = (GLushort *)malloc(memreq);
     4344            break;
     4345          case GL_UNSIGNED_INT_8_8_8_8:
     4346          case GL_UNSIGNED_INT_8_8_8_8_REV:
     4347          case GL_UNSIGNED_INT_10_10_10_2:
     4348          case GL_UNSIGNED_INT_2_10_10_10_REV:
     4349            dstImage = (GLuint *)malloc(memreq);
     4350            break;
     4351          default:
     4352            return GLU_INVALID_ENUM;
     4353          }
     4354          if (dstImage == NULL) {
     4355            glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     4356            glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     4357            glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     4358            glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     4359            glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     4360            return GLU_OUT_OF_MEMORY;
     4361          }
     4362        }
     4363        /* level userLevel is in srcImage; nothing saved yet */
     4364        level = userLevel;
    43654365    }
    43664366
     
    43684368    if (baseLevel <= level && level <= maxLevel) {
    43694369    glTexImage2D(target, level, internalFormat, newwidth, newheight, 0,
    4370                 format, type, (void *)srcImage);
     4370                format, type, (void *)srcImage);
    43714371    }
    43724372
    43734373    level++; /* update current level for the loop */
    43744374    for (; level <= levels; level++) {
    4375         switch(type) {
    4376             case GL_UNSIGNED_BYTE:
    4377                 halveImage_ubyte(cmpts, newwidth, newheight,
    4378                 (GLubyte *)srcImage, (GLubyte *)dstImage, element_size,
    4379                 rowsize, group_size);
    4380                 break;
    4381             case GL_BYTE:
    4382                 halveImage_byte(cmpts, newwidth, newheight,
    4383                 (GLbyte *)srcImage, (GLbyte *)dstImage, element_size,
    4384                 rowsize, group_size);
    4385                 break;
    4386             case GL_UNSIGNED_SHORT:
    4387                 halveImage_ushort(cmpts, newwidth, newheight,
    4388                 (GLushort *)srcImage, (GLushort *)dstImage, element_size,
    4389                 rowsize, group_size, myswap_bytes);
    4390                 break;
    4391             case GL_SHORT:
    4392                 halveImage_short(cmpts, newwidth, newheight,
    4393                 (GLshort *)srcImage, (GLshort *)dstImage, element_size,
    4394                 rowsize, group_size, myswap_bytes);
    4395                 break;
    4396             case GL_UNSIGNED_INT:
    4397                 halveImage_uint(cmpts, newwidth, newheight,
    4398                 (GLuint *)srcImage, (GLuint *)dstImage, element_size,
    4399                 rowsize, group_size, myswap_bytes);
    4400                 break;
    4401             case GL_INT:
    4402                 halveImage_int(cmpts, newwidth, newheight,
    4403                 (GLint *)srcImage, (GLint *)dstImage, element_size,
    4404                 rowsize, group_size, myswap_bytes);
    4405                 break;
    4406             case GL_FLOAT:
    4407                 halveImage_float(cmpts, newwidth, newheight,
    4408                 (GLfloat *)srcImage, (GLfloat *)dstImage, element_size,
    4409                 rowsize, group_size, myswap_bytes);
    4410                 break;
     4375        switch(type) {
     4376            case GL_UNSIGNED_BYTE:
     4377                halveImage_ubyte(cmpts, newwidth, newheight,
     4378                (GLubyte *)srcImage, (GLubyte *)dstImage, element_size,
     4379                rowsize, group_size);
     4380                break;
     4381            case GL_BYTE:
     4382                halveImage_byte(cmpts, newwidth, newheight,
     4383                (GLbyte *)srcImage, (GLbyte *)dstImage, element_size,
     4384                rowsize, group_size);
     4385                break;
     4386            case GL_UNSIGNED_SHORT:
     4387                halveImage_ushort(cmpts, newwidth, newheight,
     4388                (GLushort *)srcImage, (GLushort *)dstImage, element_size,
     4389                rowsize, group_size, myswap_bytes);
     4390                break;
     4391            case GL_SHORT:
     4392                halveImage_short(cmpts, newwidth, newheight,
     4393                (GLshort *)srcImage, (GLshort *)dstImage, element_size,
     4394                rowsize, group_size, myswap_bytes);
     4395                break;
     4396            case GL_UNSIGNED_INT:
     4397                halveImage_uint(cmpts, newwidth, newheight,
     4398                (GLuint *)srcImage, (GLuint *)dstImage, element_size,
     4399                rowsize, group_size, myswap_bytes);
     4400                break;
     4401            case GL_INT:
     4402                halveImage_int(cmpts, newwidth, newheight,
     4403                (GLint *)srcImage, (GLint *)dstImage, element_size,
     4404                rowsize, group_size, myswap_bytes);
     4405                break;
     4406            case GL_FLOAT:
     4407                halveImage_float(cmpts, newwidth, newheight,
     4408                (GLfloat *)srcImage, (GLfloat *)dstImage, element_size,
     4409                rowsize, group_size, myswap_bytes);
     4410                break;
    44114411            case GL_UNSIGNED_BYTE_3_3_2:
    4412                 halveImagePackedPixel(3,extract332,shove332,
    4413                                       newwidth,newheight,
    4414                                       srcImage,dstImage,element_size,rowsize,
    4415                                       myswap_bytes);
    4416                 break;
     4412                halveImagePackedPixel(3,extract332,shove332,
     4413                                      newwidth,newheight,
     4414                                      srcImage,dstImage,element_size,rowsize,
     4415                                      myswap_bytes);
     4416                break;
    44174417            case GL_UNSIGNED_BYTE_2_3_3_REV:
    4418                 halveImagePackedPixel(3,extract233rev,shove233rev,
    4419                                       newwidth,newheight,
    4420                                       srcImage,dstImage,element_size,rowsize,
    4421                                       myswap_bytes);
    4422                 break;
    4423             case GL_UNSIGNED_SHORT_5_6_5:
    4424                 halveImagePackedPixel(3,extract565,shove565,
    4425                                       newwidth,newheight,
    4426                                       srcImage,dstImage,element_size,rowsize,
    4427                                       myswap_bytes);
    4428                 break;
    4429             case GL_UNSIGNED_SHORT_5_6_5_REV:
    4430                 halveImagePackedPixel(3,extract565rev,shove565rev,
    4431                                       newwidth,newheight,
    4432                                       srcImage,dstImage,element_size,rowsize,
    4433                                       myswap_bytes);
    4434                 break;
     4418                halveImagePackedPixel(3,extract233rev,shove233rev,
     4419                                      newwidth,newheight,
     4420                                      srcImage,dstImage,element_size,rowsize,
     4421                                      myswap_bytes);
     4422                break;
     4423            case GL_UNSIGNED_SHORT_5_6_5:
     4424                halveImagePackedPixel(3,extract565,shove565,
     4425                                      newwidth,newheight,
     4426                                      srcImage,dstImage,element_size,rowsize,
     4427                                      myswap_bytes);
     4428                break;
     4429            case GL_UNSIGNED_SHORT_5_6_5_REV:
     4430                halveImagePackedPixel(3,extract565rev,shove565rev,
     4431                                      newwidth,newheight,
     4432                                      srcImage,dstImage,element_size,rowsize,
     4433                                      myswap_bytes);
     4434                break;
    44354435            case GL_UNSIGNED_SHORT_4_4_4_4:
    4436                 halveImagePackedPixel(4,extract4444,shove4444,
    4437                                       newwidth,newheight,
    4438                                       srcImage,dstImage,element_size,rowsize,
    4439                                       myswap_bytes);
    4440                 break;
     4436                halveImagePackedPixel(4,extract4444,shove4444,
     4437                                      newwidth,newheight,
     4438                                      srcImage,dstImage,element_size,rowsize,
     4439                                      myswap_bytes);
     4440                break;
    44414441            case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    4442                 halveImagePackedPixel(4,extract4444rev,shove4444rev,
    4443                                       newwidth,newheight,
    4444                                       srcImage,dstImage,element_size,rowsize,
    4445                                       myswap_bytes);
    4446                 break;
    4447             case GL_UNSIGNED_SHORT_5_5_5_1:             
    4448                 halveImagePackedPixel(4,extract5551,shove5551,
    4449                                       newwidth,newheight,
    4450                                       srcImage,dstImage,element_size,rowsize,
    4451                                       myswap_bytes);
    4452                 break;
    4453             case GL_UNSIGNED_SHORT_1_5_5_5_REV:                 
    4454                 halveImagePackedPixel(4,extract1555rev,shove1555rev,
    4455                                       newwidth,newheight,
    4456                                       srcImage,dstImage,element_size,rowsize,
    4457                                       myswap_bytes);
    4458                 break;
     4442                halveImagePackedPixel(4,extract4444rev,shove4444rev,
     4443                                      newwidth,newheight,
     4444                                      srcImage,dstImage,element_size,rowsize,
     4445                                      myswap_bytes);
     4446                break;
     4447            case GL_UNSIGNED_SHORT_5_5_5_1:
     4448                halveImagePackedPixel(4,extract5551,shove5551,
     4449                                      newwidth,newheight,
     4450                                      srcImage,dstImage,element_size,rowsize,
     4451                                      myswap_bytes);
     4452                break;
     4453            case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     4454                halveImagePackedPixel(4,extract1555rev,shove1555rev,
     4455                                      newwidth,newheight,
     4456                                      srcImage,dstImage,element_size,rowsize,
     4457                                      myswap_bytes);
     4458                break;
    44594459            case GL_UNSIGNED_INT_8_8_8_8:
    4460                 halveImagePackedPixel(4,extract8888,shove8888,
    4461                                       newwidth,newheight,
    4462                                       srcImage,dstImage,element_size,rowsize,
    4463                                       myswap_bytes);
    4464                 break;
     4460                halveImagePackedPixel(4,extract8888,shove8888,
     4461                                      newwidth,newheight,
     4462                                      srcImage,dstImage,element_size,rowsize,
     4463                                      myswap_bytes);
     4464                break;
    44654465            case GL_UNSIGNED_INT_8_8_8_8_REV:
    4466                 halveImagePackedPixel(4,extract8888rev,shove8888rev,
    4467                                       newwidth,newheight,
    4468                                       srcImage,dstImage,element_size,rowsize,
    4469                                       myswap_bytes);
    4470                 break;
     4466                halveImagePackedPixel(4,extract8888rev,shove8888rev,
     4467                                      newwidth,newheight,
     4468                                      srcImage,dstImage,element_size,rowsize,
     4469                                      myswap_bytes);
     4470                break;
    44714471            case GL_UNSIGNED_INT_10_10_10_2:
    4472                 halveImagePackedPixel(4,extract1010102,shove1010102,
    4473                                       newwidth,newheight,
    4474                                       srcImage,dstImage,element_size,rowsize,
    4475                                       myswap_bytes);
    4476                 break;
     4472                halveImagePackedPixel(4,extract1010102,shove1010102,
     4473                                      newwidth,newheight,
     4474                                      srcImage,dstImage,element_size,rowsize,
     4475                                      myswap_bytes);
     4476                break;
    44774477            case GL_UNSIGNED_INT_2_10_10_10_REV:
    4478                 halveImagePackedPixel(4,extract2101010rev,shove2101010rev,
    4479                                       newwidth,newheight,
    4480                                       srcImage,dstImage,element_size,rowsize,
    4481                                       myswap_bytes);
    4482                 break;
    4483             default:
    4484                 assert(0);
    4485                 break;
    4486         }
    4487 
    4488         __GLU_SWAP_IMAGE(srcImage,dstImage);
    4489 
    4490         if (newwidth > 1) { newwidth /= 2; rowsize /= 2;}
    4491         if (newheight > 1) newheight /= 2;
     4478                halveImagePackedPixel(4,extract2101010rev,shove2101010rev,
     4479                                      newwidth,newheight,
     4480                                      srcImage,dstImage,element_size,rowsize,
     4481                                      myswap_bytes);
     4482                break;
     4483            default:
     4484                assert(0);
     4485                break;
     4486        }
     4487
     4488        __GLU_SWAP_IMAGE(srcImage,dstImage);
     4489
     4490        if (newwidth > 1) { newwidth /= 2; rowsize /= 2;}
     4491        if (newheight > 1) newheight /= 2;
    44924492      {
    44934493       /* compute amount to pad per row, if any */
     
    44954495
    44964496       /* should row be padded? */
    4497        if (rowPad == 0) {       /* nope, row should not be padded */
    4498            /* call tex image with srcImage untouched since it's not padded */
    4499            if (baseLevel <= level && level <= maxLevel) {
    4500            glTexImage2D(target, level, internalFormat, newwidth, newheight, 0,
    4501            format, type, (void *) srcImage);
    4502            }
     4497       if (rowPad == 0) {       /* nope, row should not be padded */
     4498           /* call tex image with srcImage untouched since it's not padded */
     4499           if (baseLevel <= level && level <= maxLevel) {
     4500           glTexImage2D(target, level, internalFormat, newwidth, newheight, 0,
     4501           format, type, (void *) srcImage);
     4502           }
    45034503       }
    4504        else {                   /* yes, row should be padded */
    4505           /* compute length of new row in bytes, including padding */
    4506           int newRowLength= rowsize + psm.unpack_alignment - rowPad;
    4507           int ii; unsigned char *dstTrav, *srcTrav; /* indices for copying */
    4508 
    4509           /* allocate new image for mipmap of size newRowLength x newheight */
    4510           void *newMipmapImage= malloc((size_t) (newRowLength*newheight));
    4511           if (newMipmapImage == NULL) {
    4512              /* out of memory so return */
    4513              glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    4514              glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    4515              glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    4516              glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    4517              glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    4518              return GLU_OUT_OF_MEMORY;
    4519           }
    4520 
    4521           /* copy image from srcImage into newMipmapImage by rows */
    4522           for (ii= 0,
    4523                dstTrav= (unsigned char *) newMipmapImage,
    4524                srcTrav= (unsigned char *) srcImage;
    4525                ii< newheight;
    4526                ii++,
    4527                dstTrav+= newRowLength, /* make sure the correct distance... */
    4528                srcTrav+= rowsize) {    /* ...is skipped */
    4529              memcpy(dstTrav,(const void *)srcTrav,rowsize);
    4530              /* note that the pad bytes are not visited and will contain
    4531               * garbage, which is ok.
    4532               */
    4533           }
    4534 
    4535           /* ...and use this new image for mipmapping instead */
    4536           if (baseLevel <= level && level <= maxLevel) {
    4537           glTexImage2D(target, level, internalFormat, newwidth, newheight, 0,
    4538                        format, type, newMipmapImage);
    4539           }
    4540           free(newMipmapImage); /* don't forget to free it! */
     4504       else {                   /* yes, row should be padded */
     4505          /* compute length of new row in bytes, including padding */
     4506          int newRowLength= rowsize + psm.unpack_alignment - rowPad;
     4507          int ii; unsigned char *dstTrav, *srcTrav; /* indices for copying */
     4508
     4509          /* allocate new image for mipmap of size newRowLength x newheight */
     4510          void *newMipmapImage= malloc((size_t) (newRowLength*newheight));
     4511          if (newMipmapImage == NULL) {
     4512             /* out of memory so return */
     4513             glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     4514             glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     4515             glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     4516             glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     4517             glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     4518             return GLU_OUT_OF_MEMORY;
     4519          }
     4520
     4521          /* copy image from srcImage into newMipmapImage by rows */
     4522          for (ii= 0,
     4523               dstTrav= (unsigned char *) newMipmapImage,
     4524               srcTrav= (unsigned char *) srcImage;
     4525               ii< newheight;
     4526               ii++,
     4527               dstTrav+= newRowLength, /* make sure the correct distance... */
     4528               srcTrav+= rowsize) {    /* ...is skipped */
     4529             memcpy(dstTrav,(const void *)srcTrav,rowsize);
     4530             /* note that the pad bytes are not visited and will contain
     4531              * garbage, which is ok.
     4532              */
     4533          }
     4534
     4535          /* ...and use this new image for mipmapping instead */
     4536          if (baseLevel <= level && level <= maxLevel) {
     4537          glTexImage2D(target, level, internalFormat, newwidth, newheight, 0,
     4538                       format, type, newMipmapImage);
     4539          }
     4540          free(newMipmapImage); /* don't forget to free it! */
    45414541       } /* else */
    45424542      }
     
    45574557GLint GLAPI
    45584558gluBuild2DMipmapLevels(GLenum target, GLint internalFormat,
    4559                              GLsizei width, GLsizei height,
    4560                              GLenum format, GLenum type,
    4561                              GLint userLevel, GLint baseLevel, GLint maxLevel,
    4562                              const void *data)
     4559                             GLsizei width, GLsizei height,
     4560                             GLenum format, GLenum type,
     4561                             GLint userLevel, GLint baseLevel, GLint maxLevel,
     4562                             const void *data)
    45634563{
    45644564   int level, levels;
     
    45804580
    45814581   return gluBuild2DMipmapLevelsCore(target, internalFormat,
    4582                                      width, height,
    4583                                      width, height,
    4584                                      format, type,
    4585                                      userLevel, baseLevel, maxLevel,
    4586                                      data);
     4582                                     width, height,
     4583                                     width, height,
     4584                                     format, type,
     4585                                     userLevel, baseLevel, maxLevel,
     4586                                     data);
    45874587} /* gluBuild2DMipmapLevels() */
    45884588
    45894589GLint GLAPI
    45904590gluBuild2DMipmaps(GLenum target, GLint internalFormat,
    4591                         GLsizei width, GLsizei height,
    4592                         GLenum format, GLenum type,
    4593                         const void *data)
     4591                        GLsizei width, GLsizei height,
     4592                        GLenum format, GLenum type,
     4593                        const void *data)
    45944594{
    45954595   GLint widthPowerOf2, heightPowerOf2;
     
    46044604
    46054605   closestFit(target,width,height,internalFormat,format,type,
    4606               &widthPowerOf2,&heightPowerOf2);
     4606              &widthPowerOf2,&heightPowerOf2);
    46074607
    46084608   levels = computeLog(widthPowerOf2);
     
    46114611
    46124612   return gluBuild2DMipmapLevelsCore(target,internalFormat,
    4613                                      width, height,
    4614                                      widthPowerOf2,heightPowerOf2,
    4615                                      format,type,
    4616                                      0,0,levels,data);
     4613                                     width, height,
     4614                                     widthPowerOf2,heightPowerOf2,
     4615                                     format,type,
     4616                                     0,0,levels,data);
    46174617}  /* gluBuild2DMipmaps() */
    46184618
    46194619/*
    46204620** This routine is for the limited case in which
    4621 **      type == GL_UNSIGNED_BYTE && format != index  &&
    4622 **      unpack_alignment = 1 && unpack_swap_bytes == false
     4621**      type == GL_UNSIGNED_BYTE && format != index  &&
     4622**      unpack_alignment = 1 && unpack_swap_bytes == false
    46234623**
    46244624** so all of the work data can be kept as ubytes instead of shorts.
    46254625*/
    46264626int fastBuild2DMipmaps(const PixelStorageModes *psm,
    4627                        GLenum target, GLint components, GLint width,
    4628                      GLint height, GLenum format,
    4629                      GLenum type, const void *data)
     4627                       GLenum target, GLint components, GLint width,
     4628                     GLint height, GLenum format,
     4629                     GLenum type, const void *data)
    46304630{
    46314631    GLint newwidth, newheight;
     
    46494649#else
    46504650    closestFit(target,width,height,components,format,type,
    4651                &newwidth,&newheight);
     4651               &newwidth,&newheight);
    46524652#endif
    46534653    levels = computeLog(newwidth);
     
    46634663    */
    46644664    if (psm->unpack_skip_rows == 0 && psm->unpack_skip_pixels == 0) {
    4665         newImage = (GLubyte *)data;
    4666         newImage_width = width;
    4667         newImage_height = height;
     4665        newImage = (GLubyte *)data;
     4666        newImage_width = width;
     4667        newImage_height = height;
    46684668    } else {
    4669         GLint rowsize;
    4670         GLint groups_per_line;
    4671         GLint elements_per_line;
    4672         const GLubyte *start;
    4673         const GLubyte *iter;
    4674         GLubyte *iter2;
    4675         GLint i, j;
    4676 
    4677         newImage = (GLubyte *)
    4678             malloc(image_size(width, height, format, GL_UNSIGNED_BYTE));
    4679         newImage_width = width;
    4680         newImage_height = height;
    4681         if (newImage == NULL) {
    4682             return GLU_OUT_OF_MEMORY;
    4683         }
    4684 
    4685         /*
    4686         ** Abbreviated version of fill_image for this restricted case.
    4687         */
    4688         if (psm->unpack_row_length > 0) {
    4689             groups_per_line = psm->unpack_row_length;
    4690         } else {
    4691             groups_per_line = width;
    4692         }
    4693         rowsize = groups_per_line * cmpts;
    4694         elements_per_line = width * cmpts;
    4695         start = (GLubyte *) data + psm->unpack_skip_rows * rowsize +
    4696                 psm->unpack_skip_pixels * cmpts;
    4697         iter2 = newImage;
    4698 
    4699         for (i = 0; i < height; i++) {
    4700             iter = start;
    4701             for (j = 0; j < elements_per_line; j++) {
    4702                 *iter2 = *iter;
    4703                 iter++;
    4704                 iter2++;
    4705             }
    4706             start += rowsize;
    4707         }
     4669        GLint rowsize;
     4670        GLint groups_per_line;
     4671        GLint elements_per_line;
     4672        const GLubyte *start;
     4673        const GLubyte *iter;
     4674        GLubyte *iter2;
     4675        GLint i, j;
     4676
     4677        newImage = (GLubyte *)
     4678            malloc(image_size(width, height, format, GL_UNSIGNED_BYTE));
     4679        newImage_width = width;
     4680        newImage_height = height;
     4681        if (newImage == NULL) {
     4682            return GLU_OUT_OF_MEMORY;
     4683        }
     4684
     4685        /*
     4686        ** Abbreviated version of fill_image for this restricted case.
     4687        */
     4688        if (psm->unpack_row_length > 0) {
     4689            groups_per_line = psm->unpack_row_length;
     4690        } else {
     4691            groups_per_line = width;
     4692        }
     4693        rowsize = groups_per_line * cmpts;
     4694        elements_per_line = width * cmpts;
     4695        start = (GLubyte *) data + psm->unpack_skip_rows * rowsize +
     4696                psm->unpack_skip_pixels * cmpts;
     4697        iter2 = newImage;
     4698
     4699        for (i = 0; i < height; i++) {
     4700            iter = start;
     4701            for (j = 0; j < elements_per_line; j++) {
     4702                *iter2 = *iter;
     4703                iter++;
     4704                iter2++;
     4705            }
     4706            start += rowsize;
     4707        }
    47084708    }
    47094709
     
    47164716
    47174717    for (level = 0; level <= levels; level++) {
    4718         if (newImage_width == newwidth && newImage_height == newheight) {
    4719             /* Use newImage for this level */
    4720             glTexImage2D(target, level, components, newImage_width,
    4721                     newImage_height, 0, format, GL_UNSIGNED_BYTE,
    4722                     (void *) newImage);
    4723         } else {
    4724             if (otherImage == NULL) {
    4725                 memreq =
    4726                     image_size(newwidth, newheight, format, GL_UNSIGNED_BYTE);
    4727                 otherImage = (GLubyte *) malloc(memreq);
    4728                 if (otherImage == NULL) {
    4729                     glPixelStorei(GL_UNPACK_ALIGNMENT, psm->unpack_alignment);
    4730                     glPixelStorei(GL_UNPACK_SKIP_ROWS, psm->unpack_skip_rows);
    4731                     glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm->unpack_skip_pixels);
    4732                     glPixelStorei(GL_UNPACK_ROW_LENGTH,psm->unpack_row_length);
    4733                     glPixelStorei(GL_UNPACK_SWAP_BYTES,psm->unpack_swap_bytes);
    4734                     return GLU_OUT_OF_MEMORY;
    4735                 }
    4736             }
     4718        if (newImage_width == newwidth && newImage_height == newheight) {
     4719            /* Use newImage for this level */
     4720            glTexImage2D(target, level, components, newImage_width,
     4721                    newImage_height, 0, format, GL_UNSIGNED_BYTE,
     4722                    (void *) newImage);
     4723        } else {
     4724            if (otherImage == NULL) {
     4725                memreq =
     4726                    image_size(newwidth, newheight, format, GL_UNSIGNED_BYTE);
     4727                otherImage = (GLubyte *) malloc(memreq);
     4728                if (otherImage == NULL) {
     4729                    glPixelStorei(GL_UNPACK_ALIGNMENT, psm->unpack_alignment);
     4730                    glPixelStorei(GL_UNPACK_SKIP_ROWS, psm->unpack_skip_rows);
     4731                    glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm->unpack_skip_pixels);
     4732                    glPixelStorei(GL_UNPACK_ROW_LENGTH,psm->unpack_row_length);
     4733                    glPixelStorei(GL_UNPACK_SWAP_BYTES,psm->unpack_swap_bytes);
     4734                    return GLU_OUT_OF_MEMORY;
     4735                }
     4736            }
    47374737/*
    4738             scale_internal_ubyte(cmpts, newImage_width, newImage_height,
    4739                     newImage, newwidth, newheight, otherImage);
     4738            scale_internal_ubyte(cmpts, newImage_width, newImage_height,
     4739                    newImage, newwidth, newheight, otherImage);
    47404740*/
    4741             /* Swap newImage and otherImage */
    4742             imageTemp = otherImage;
    4743             otherImage = newImage;
    4744             newImage = imageTemp;
    4745 
    4746             newImage_width = newwidth;
    4747             newImage_height = newheight;
    4748             glTexImage2D(target, level, components, newImage_width,
    4749                     newImage_height, 0, format, GL_UNSIGNED_BYTE,
    4750                     (void *) newImage);
    4751         }
    4752         if (newwidth > 1) newwidth /= 2;
    4753         if (newheight > 1) newheight /= 2;
     4741            /* Swap newImage and otherImage */
     4742            imageTemp = otherImage;
     4743            otherImage = newImage;
     4744            newImage = imageTemp;
     4745
     4746            newImage_width = newwidth;
     4747            newImage_height = newheight;
     4748            glTexImage2D(target, level, components, newImage_width,
     4749                    newImage_height, 0, format, GL_UNSIGNED_BYTE,
     4750                    (void *) newImage);
     4751        }
     4752        if (newwidth > 1) newwidth /= 2;
     4753        if (newheight > 1) newheight /= 2;
    47544754    }
    47554755    glPixelStorei(GL_UNPACK_ALIGNMENT, psm->unpack_alignment);
     
    47604760
    47614761    if (newImage != (GLubyte *)data) {
    4762         free((GLbyte *) newImage);
     4762        free((GLbyte *) newImage);
    47634763    }
    47644764    if (otherImage && otherImage != (GLubyte *)data) {
    4765         free((GLbyte *) otherImage);
     4765        free((GLbyte *) otherImage);
    47664766    }
    47674767    return 0;
     
    47794779    /* If the type is packedpixels then answer is 1 (ignore format) */
    47804780    if (type == GL_UNSIGNED_BYTE_3_3_2 ||
    4781         type == GL_UNSIGNED_BYTE_2_3_3_REV ||
    4782         type == GL_UNSIGNED_SHORT_5_6_5 ||
    4783         type == GL_UNSIGNED_SHORT_5_6_5_REV ||
    4784         type == GL_UNSIGNED_SHORT_4_4_4_4 ||
    4785         type == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
    4786         type == GL_UNSIGNED_SHORT_5_5_5_1  ||
    4787         type == GL_UNSIGNED_SHORT_1_5_5_5_REV  ||
    4788         type == GL_UNSIGNED_INT_8_8_8_8 ||
    4789         type == GL_UNSIGNED_INT_8_8_8_8_REV ||
    4790         type == GL_UNSIGNED_INT_10_10_10_2 ||
    4791         type == GL_UNSIGNED_INT_2_10_10_10_REV) {
     4781        type == GL_UNSIGNED_BYTE_2_3_3_REV ||
     4782        type == GL_UNSIGNED_SHORT_5_6_5 ||
     4783        type == GL_UNSIGNED_SHORT_5_6_5_REV ||
     4784        type == GL_UNSIGNED_SHORT_4_4_4_4 ||
     4785        type == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
     4786        type == GL_UNSIGNED_SHORT_5_5_5_1  ||
     4787        type == GL_UNSIGNED_SHORT_1_5_5_5_REV  ||
     4788        type == GL_UNSIGNED_INT_8_8_8_8 ||
     4789        type == GL_UNSIGNED_INT_8_8_8_8_REV ||
     4790        type == GL_UNSIGNED_INT_10_10_10_2 ||
     4791        type == GL_UNSIGNED_INT_2_10_10_10_REV) {
    47924792        return 1;
    47934793    }
     
    47974797      case GL_RGB:
    47984798      case GL_BGR:
    4799         return 3;
     4799        return 3;
    48004800      case GL_LUMINANCE_ALPHA:
    4801         return 2;
     4801        return 2;
    48024802      case GL_RGBA:
    48034803      case GL_BGRA:
    4804         return 4;
     4804        return 4;
    48054805      default:
    4806         return 1;
     4806        return 1;
    48074807    }
    48084808}
     
    48154815    switch(type) {
    48164816      case GL_BITMAP:
    4817         return 1.0 / 8.0;
     4817        return 1.0 / 8.0;
    48184818      case GL_UNSIGNED_SHORT:
    4819         return(sizeof(GLushort));
     4819        return(sizeof(GLushort));
    48204820      case GL_SHORT:
    4821         return(sizeof(GLshort));
     4821        return(sizeof(GLshort));
    48224822      case GL_UNSIGNED_BYTE:
    4823         return(sizeof(GLubyte));
     4823        return(sizeof(GLubyte));
    48244824      case GL_BYTE:
    4825         return(sizeof(GLbyte));
     4825        return(sizeof(GLbyte));
    48264826      case GL_INT:
    4827         return(sizeof(GLint));
     4827        return(sizeof(GLint));
    48284828      case GL_UNSIGNED_INT:
    4829         return(sizeof(GLuint));
     4829        return(sizeof(GLuint));
    48304830      case GL_FLOAT:
    4831         return(sizeof(GLfloat));
     4831        return(sizeof(GLfloat));
    48324832      case GL_UNSIGNED_BYTE_3_3_2:
    4833       case GL_UNSIGNED_BYTE_2_3_3_REV: 
    4834         return(sizeof(GLubyte));
     4833      case GL_UNSIGNED_BYTE_2_3_3_REV:
     4834        return(sizeof(GLubyte));
    48354835      case GL_UNSIGNED_SHORT_5_6_5:
    48364836      case GL_UNSIGNED_SHORT_5_6_5_REV:
     
    48394839      case GL_UNSIGNED_SHORT_5_5_5_1:
    48404840      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    4841         return(sizeof(GLushort));
     4841        return(sizeof(GLushort));
    48424842      case GL_UNSIGNED_INT_8_8_8_8:
    48434843      case GL_UNSIGNED_INT_8_8_8_8_REV:
    48444844      case GL_UNSIGNED_INT_10_10_10_2:
    48454845      case GL_UNSIGNED_INT_2_10_10_10_REV:
    4846         return(sizeof(GLuint));
     4846        return(sizeof(GLuint));
    48474847      default:
    4848         return 4;
     4848        return 4;
    48494849    }
    48504850}
     
    48684868    components = elements_per_group(format,type);
    48694869    if (type == GL_BITMAP) {
    4870         bytes_per_row = (width + 7) / 8;
     4870        bytes_per_row = (width + 7) / 8;
    48714871    } else {
    4872         bytes_per_row = bytes_per_element(type) * width;
     4872        bytes_per_row = bytes_per_element(type) * width;
    48734873    }
    48744874    return bytes_per_row * height * components;
     
    48804880*/
    48814881static void fill_image(const PixelStorageModes *psm,
    4882                        GLint width, GLint height, GLenum format,
    4883                        GLenum type, GLboolean index_format,
    4884                        const void *userdata, GLushort *newimage)
     4882                       GLint width, GLint height, GLenum format,
     4883                       GLenum type, GLboolean index_format,
     4884                       const void *userdata, GLushort *newimage)
    48854885{
    48864886    GLint components;
     
    49004900    components = elements_per_group(format,type);
    49014901    if (psm->unpack_row_length > 0) {
    4902         groups_per_line = psm->unpack_row_length;
     4902        groups_per_line = psm->unpack_row_length;
    49034903    } else {
    4904         groups_per_line = width;
     4904        groups_per_line = width;
    49054905    }
    49064906
    49074907    /* All formats except GL_BITMAP fall out trivially */
    49084908    if (type == GL_BITMAP) {
    4909         GLint bit_offset;
    4910         GLint current_bit;
    4911 
    4912         rowsize = (groups_per_line * components + 7) / 8;
    4913         padding = (rowsize % psm->unpack_alignment);
    4914         if (padding) {
    4915             rowsize += psm->unpack_alignment - padding;
    4916         }
    4917         start = (GLubyte *) userdata + psm->unpack_skip_rows * rowsize +
    4918                 (psm->unpack_skip_pixels * components / 8);
    4919         elements_per_line = width * components;
    4920         iter2 = newimage;
    4921         for (i = 0; i < height; i++) {
    4922             iter = start;
    4923             bit_offset = (psm->unpack_skip_pixels * components) % 8;
    4924             for (j = 0; j < elements_per_line; j++) {
    4925                 /* Retrieve bit */
    4926                 if (psm->unpack_lsb_first) {
    4927                     current_bit = iter[0] & (1 << bit_offset);
    4928                 } else {
    4929                     current_bit = iter[0] & (1 << (7 - bit_offset));
    4930                 }
    4931                 if (current_bit) {
    4932                     if (index_format) {
    4933                         *iter2 = 1;
    4934                     } else {
    4935                         *iter2 = 65535;
    4936                     }
    4937                 } else {
    4938                     *iter2 = 0;
    4939                 }
    4940                 bit_offset++;
    4941                 if (bit_offset == 8) {
    4942                     bit_offset = 0;
    4943                     iter++;
    4944                 }
    4945                 iter2++;
    4946             }
    4947             start += rowsize;
    4948         }
     4909        GLint bit_offset;
     4910        GLint current_bit;
     4911
     4912        rowsize = (groups_per_line * components + 7) / 8;
     4913        padding = (rowsize % psm->unpack_alignment);
     4914        if (padding) {
     4915            rowsize += psm->unpack_alignment - padding;
     4916        }
     4917        start = (GLubyte *) userdata + psm->unpack_skip_rows * rowsize +
     4918                (psm->unpack_skip_pixels * components / 8);
     4919        elements_per_line = width * components;
     4920        iter2 = newimage;
     4921        for (i = 0; i < height; i++) {
     4922            iter = start;
     4923            bit_offset = (psm->unpack_skip_pixels * components) % 8;
     4924            for (j = 0; j < elements_per_line; j++) {
     4925                /* Retrieve bit */
     4926                if (psm->unpack_lsb_first) {
     4927                    current_bit = iter[0] & (1 << bit_offset);
     4928                } else {
     4929                    current_bit = iter[0] & (1 << (7 - bit_offset));
     4930                }
     4931                if (current_bit) {
     4932                    if (index_format) {
     4933                        *iter2 = 1;
     4934                    } else {
     4935                        *iter2 = 65535;
     4936                    }
     4937                } else {
     4938                    *iter2 = 0;
     4939                }
     4940                bit_offset++;
     4941                if (bit_offset == 8) {
     4942                    bit_offset = 0;
     4943                    iter++;
     4944                }
     4945                iter2++;
     4946            }
     4947            start += rowsize;
     4948        }
    49494949    } else {
    4950         element_size = bytes_per_element(type);
    4951         group_size = element_size * components;
    4952         if (element_size == 1) myswap_bytes = 0;
    4953 
    4954         rowsize = groups_per_line * group_size;
    4955         padding = (rowsize % psm->unpack_alignment);
    4956         if (padding) {
    4957             rowsize += psm->unpack_alignment - padding;
    4958         }
    4959         start = (GLubyte *) userdata + psm->unpack_skip_rows * rowsize +
    4960                 psm->unpack_skip_pixels * group_size;
    4961         elements_per_line = width * components;
    4962 
    4963         iter2 = newimage;
    4964         for (i = 0; i < height; i++) {
    4965             iter = start;
    4966             for (j = 0; j < elements_per_line; j++) {
    4967                 Type_Widget widget;
    4968                 float extractComponents[4];
    4969 
    4970                 switch(type) {
    4971                   case GL_UNSIGNED_BYTE_3_3_2:
    4972                     extract332(0,(void *)iter,extractComponents);
    4973                     for (k = 0; k < 3; k++) {
    4974                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    4975                     }
    4976                     break;
    4977                   case GL_UNSIGNED_BYTE_2_3_3_REV:
    4978                     extract233rev(0,(void *)iter,extractComponents);
    4979                     for (k = 0; k < 3; k++) {
    4980                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    4981                     }
    4982                     break;
    4983                   case GL_UNSIGNED_BYTE:
    4984                     if (index_format) {
    4985                         *iter2++ = *iter;
    4986                     } else {
    4987                         *iter2++ = (*iter) * 257;
    4988                     }
    4989                     break;
    4990                   case GL_BYTE:
    4991                     if (index_format) {
    4992                         *iter2++ = *((GLbyte *) iter);
    4993                     } else {
    4994                         /* rough approx */
    4995                         *iter2++ = (*((GLbyte *) iter)) * 516;
    4996                     }
    4997                     break;
    4998                   case GL_UNSIGNED_SHORT_5_6_5:                         
    4999                     extract565(myswap_bytes,(void *)iter,extractComponents);
    5000                     for (k = 0; k < 3; k++) {
    5001                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5002                     }
    5003                     break;
    5004                   case GL_UNSIGNED_SHORT_5_6_5_REV:                     
    5005                     extract565rev(myswap_bytes,(void *)iter,extractComponents);
    5006                     for (k = 0; k < 3; k++) {
    5007                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5008                     }
    5009                     break;
    5010                   case GL_UNSIGNED_SHORT_4_4_4_4:               
    5011                     extract4444(myswap_bytes,(void *)iter,extractComponents);
    5012                     for (k = 0; k < 4; k++) {
    5013                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5014                     }
    5015                     break;
    5016                   case GL_UNSIGNED_SHORT_4_4_4_4_REV:           
    5017                     extract4444rev(myswap_bytes,(void *)iter,extractComponents);
    5018                     for (k = 0; k < 4; k++) {
    5019                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5020                     }
    5021                     break;
    5022                   case GL_UNSIGNED_SHORT_5_5_5_1:               
    5023                     extract5551(myswap_bytes,(void *)iter,extractComponents);
    5024                     for (k = 0; k < 4; k++) {
    5025                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5026                     }
    5027                     break;
    5028                   case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    5029                     extract1555rev(myswap_bytes,(void *)iter,extractComponents);
    5030                     for (k = 0; k < 4; k++) {
    5031                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5032                     }
    5033                     break;
    5034                   case GL_UNSIGNED_SHORT:
    5035                   case GL_SHORT:
    5036                     if (myswap_bytes) {
    5037                         widget.ub[0] = iter[1];
    5038                         widget.ub[1] = iter[0];
    5039                     } else {
    5040                         widget.ub[0] = iter[0];
    5041                         widget.ub[1] = iter[1];
    5042                     }
    5043                     if (type == GL_SHORT) {
    5044                         if (index_format) {
    5045                             *iter2++ = widget.s[0];
    5046                         } else {
    5047                             /* rough approx */
    5048                             *iter2++ = widget.s[0]*2;
    5049                         }
    5050                     } else {
    5051                         *iter2++ = widget.us[0];
    5052                     }
    5053                     break;
    5054                   case GL_UNSIGNED_INT_8_8_8_8:         
    5055                     extract8888(myswap_bytes,(void *)iter,extractComponents);
    5056                     for (k = 0; k < 4; k++) {
    5057                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5058                     }
    5059                     break;
    5060                   case GL_UNSIGNED_INT_8_8_8_8_REV:             
    5061                     extract8888rev(myswap_bytes,(void *)iter,extractComponents);
    5062                     for (k = 0; k < 4; k++) {
    5063                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5064                     }
    5065                     break;
    5066                   case GL_UNSIGNED_INT_10_10_10_2:             
    5067                     extract1010102(myswap_bytes,(void *)iter,extractComponents);
    5068                     for (k = 0; k < 4; k++) {
    5069                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5070                     }
    5071                     break;
    5072                   case GL_UNSIGNED_INT_2_10_10_10_REV:
    5073                     extract2101010rev(myswap_bytes,(void *)iter,extractComponents);
    5074                     for (k = 0; k < 4; k++) {
    5075                       *iter2++ = (GLushort)(extractComponents[k]*65535);
    5076                     }
    5077                     break;
    5078                   case GL_INT:
    5079                   case GL_UNSIGNED_INT:
    5080                   case GL_FLOAT:
    5081                     if (myswap_bytes) {
    5082                         widget.ub[0] = iter[3];
    5083                         widget.ub[1] = iter[2];
    5084                         widget.ub[2] = iter[1];
    5085                         widget.ub[3] = iter[0];
    5086                     } else {
    5087                         widget.ub[0] = iter[0];
    5088                         widget.ub[1] = iter[1];
    5089                         widget.ub[2] = iter[2];
    5090                         widget.ub[3] = iter[3];
    5091                     }
    5092                     if (type == GL_FLOAT) {
    5093                         if (index_format) {
    5094                             *iter2++ = widget.f;
    5095                         } else {
    5096                             *iter2++ = 65535 * widget.f;
    5097                         }
    5098                     } else if (type == GL_UNSIGNED_INT) {
    5099                         if (index_format) {
    5100                             *iter2++ = widget.ui;
    5101                         } else {
    5102                             *iter2++ = widget.ui >> 16;
    5103                         }
    5104                     } else {
    5105                         if (index_format) {
    5106                             *iter2++ = widget.i;
    5107                         } else {
    5108                             *iter2++ = widget.i >> 15;
    5109                         }
    5110                     }
    5111                     break;
    5112                 }
    5113                 iter += element_size;
    5114             } /* for j */
    5115             start += rowsize;
     4950        element_size = bytes_per_element(type);
     4951        group_size = element_size * components;
     4952        if (element_size == 1) myswap_bytes = 0;
     4953
     4954        rowsize = groups_per_line * group_size;
     4955        padding = (rowsize % psm->unpack_alignment);
     4956        if (padding) {
     4957            rowsize += psm->unpack_alignment - padding;
     4958        }
     4959        start = (GLubyte *) userdata + psm->unpack_skip_rows * rowsize +
     4960                psm->unpack_skip_pixels * group_size;
     4961        elements_per_line = width * components;
     4962
     4963        iter2 = newimage;
     4964        for (i = 0; i < height; i++) {
     4965            iter = start;
     4966            for (j = 0; j < elements_per_line; j++) {
     4967                Type_Widget widget;
     4968                float extractComponents[4];
     4969
     4970                switch(type) {
     4971                  case GL_UNSIGNED_BYTE_3_3_2:
     4972                    extract332(0,(void *)iter,extractComponents);
     4973                    for (k = 0; k < 3; k++) {
     4974                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     4975                    }
     4976                    break;
     4977                  case GL_UNSIGNED_BYTE_2_3_3_REV:
     4978                    extract233rev(0,(void *)iter,extractComponents);
     4979                    for (k = 0; k < 3; k++) {
     4980                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     4981                    }
     4982                    break;
     4983                  case GL_UNSIGNED_BYTE:
     4984                    if (index_format) {
     4985                        *iter2++ = *iter;
     4986                    } else {
     4987                        *iter2++ = (*iter) * 257;
     4988                    }
     4989                    break;
     4990                  case GL_BYTE:
     4991                    if (index_format) {
     4992                        *iter2++ = *((GLbyte *) iter);
     4993                    } else {
     4994                        /* rough approx */
     4995                        *iter2++ = (*((GLbyte *) iter)) * 516;
     4996                    }
     4997                    break;
     4998                  case GL_UNSIGNED_SHORT_5_6_5:
     4999                    extract565(myswap_bytes,(void *)iter,extractComponents);
     5000                    for (k = 0; k < 3; k++) {
     5001                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5002                    }
     5003                    break;
     5004                  case GL_UNSIGNED_SHORT_5_6_5_REV:
     5005                    extract565rev(myswap_bytes,(void *)iter,extractComponents);
     5006                    for (k = 0; k < 3; k++) {
     5007                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5008                    }
     5009                    break;
     5010                  case GL_UNSIGNED_SHORT_4_4_4_4:
     5011                    extract4444(myswap_bytes,(void *)iter,extractComponents);
     5012                    for (k = 0; k < 4; k++) {
     5013                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5014                    }
     5015                    break;
     5016                  case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     5017                    extract4444rev(myswap_bytes,(void *)iter,extractComponents);
     5018                    for (k = 0; k < 4; k++) {
     5019                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5020                    }
     5021                    break;
     5022                  case GL_UNSIGNED_SHORT_5_5_5_1:
     5023                    extract5551(myswap_bytes,(void *)iter,extractComponents);
     5024                    for (k = 0; k < 4; k++) {
     5025                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5026                    }
     5027                    break;
     5028                  case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     5029                    extract1555rev(myswap_bytes,(void *)iter,extractComponents);
     5030                    for (k = 0; k < 4; k++) {
     5031                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5032                    }
     5033                    break;
     5034                  case GL_UNSIGNED_SHORT:
     5035                  case GL_SHORT:
     5036                    if (myswap_bytes) {
     5037                        widget.ub[0] = iter[1];
     5038                        widget.ub[1] = iter[0];
     5039                    } else {
     5040                        widget.ub[0] = iter[0];
     5041                        widget.ub[1] = iter[1];
     5042                    }
     5043                    if (type == GL_SHORT) {
     5044                        if (index_format) {
     5045                            *iter2++ = widget.s[0];
     5046                        } else {
     5047                            /* rough approx */
     5048                            *iter2++ = widget.s[0]*2;
     5049                        }
     5050                    } else {
     5051                        *iter2++ = widget.us[0];
     5052                    }
     5053                    break;
     5054                  case GL_UNSIGNED_INT_8_8_8_8:
     5055                    extract8888(myswap_bytes,(void *)iter,extractComponents);
     5056                    for (k = 0; k < 4; k++) {
     5057                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5058                    }
     5059                    break;
     5060                  case GL_UNSIGNED_INT_8_8_8_8_REV:
     5061                    extract8888rev(myswap_bytes,(void *)iter,extractComponents);
     5062                    for (k = 0; k < 4; k++) {
     5063                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5064                    }
     5065                    break;
     5066                  case GL_UNSIGNED_INT_10_10_10_2:
     5067                    extract1010102(myswap_bytes,(void *)iter,extractComponents);
     5068                    for (k = 0; k < 4; k++) {
     5069                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5070                    }
     5071                    break;
     5072                  case GL_UNSIGNED_INT_2_10_10_10_REV:
     5073                    extract2101010rev(myswap_bytes,(void *)iter,extractComponents);
     5074                    for (k = 0; k < 4; k++) {
     5075                      *iter2++ = (GLushort)(extractComponents[k]*65535);
     5076                    }
     5077                    break;
     5078                  case GL_INT:
     5079                  case GL_UNSIGNED_INT:
     5080                  case GL_FLOAT:
     5081                    if (myswap_bytes) {
     5082                        widget.ub[0] = iter[3];
     5083                        widget.ub[1] = iter[2];
     5084                        widget.ub[2] = iter[1];
     5085                        widget.ub[3] = iter[0];
     5086                    } else {
     5087                        widget.ub[0] = iter[0];
     5088                        widget.ub[1] = iter[1];
     5089                        widget.ub[2] = iter[2];
     5090                        widget.ub[3] = iter[3];
     5091                    }
     5092                    if (type == GL_FLOAT) {
     5093                        if (index_format) {
     5094                            *iter2++ = widget.f;
     5095                        } else {
     5096                            *iter2++ = 65535 * widget.f;
     5097                        }
     5098                    } else if (type == GL_UNSIGNED_INT) {
     5099                        if (index_format) {
     5100                            *iter2++ = widget.ui;
     5101                        } else {
     5102                            *iter2++ = widget.ui >> 16;
     5103                        }
     5104                    } else {
     5105                        if (index_format) {
     5106                            *iter2++ = widget.i;
     5107                        } else {
     5108                            *iter2++ = widget.i >> 15;
     5109                        }
     5110                    }
     5111                    break;
     5112                }
     5113                iter += element_size;
     5114            } /* for j */
     5115            start += rowsize;
    51165116#if 1
    5117             /* want 'iter' pointing at start, not within, row for assertion
    5118              * purposes
    5119              */
    5120             iter= start;       
     5117            /* want 'iter' pointing at start, not within, row for assertion
     5118             * purposes
     5119             */
     5120            iter= start;
    51215121#endif
    5122         } /* for i */
     5122        } /* for i */
    51235123
    51245124       /* iterators should be one byte past end */
    51255125       if (!isTypePackedPixel(type)) {
    5126           assert(iter2 == &newimage[width*height*components]);
     5126          assert(iter2 == &newimage[width*height*components]);
    51275127       }
    51285128       else {
    5129           assert(iter2 == &newimage[width*height*
    5130                                     elements_per_group(format,NULL)]);
     5129          assert(iter2 == &newimage[width*height*
     5130                                    elements_per_group(format,NULL)]);
    51315131       }
    51325132       assert( iter == &((GLubyte *)userdata)[rowsize*height] );
     
    51405140*/
    51415141static void empty_image(const PixelStorageModes *psm,
    5142                         GLint width, GLint height, GLenum format,
    5143                         GLenum type, GLboolean index_format,
    5144                         const GLushort *oldimage, void *userdata)
     5142                        GLint width, GLint height, GLenum format,
     5143                        GLenum type, GLboolean index_format,
     5144                        const GLushort *oldimage, void *userdata)
    51455145{
    51465146    GLint components;
     
    51605160    components = elements_per_group(format,type);
    51615161    if (psm->pack_row_length > 0) {
    5162         groups_per_line = psm->pack_row_length;
     5162        groups_per_line = psm->pack_row_length;
    51635163    } else {
    5164         groups_per_line = width;
     5164        groups_per_line = width;
    51655165    }
    51665166
    51675167    /* All formats except GL_BITMAP fall out trivially */
    51685168    if (type == GL_BITMAP) {
    5169         GLint bit_offset;
    5170         GLint current_bit;
    5171 
    5172         rowsize = (groups_per_line * components + 7) / 8;
    5173         padding = (rowsize % psm->pack_alignment);
    5174         if (padding) {
    5175             rowsize += psm->pack_alignment - padding;
    5176         }
    5177         start = (GLubyte *) userdata + psm->pack_skip_rows * rowsize +
    5178                 (psm->pack_skip_pixels * components / 8);
    5179         elements_per_line = width * components;
    5180         iter2 = oldimage;
    5181         for (i = 0; i < height; i++) {
    5182             iter = start;
    5183             bit_offset = (psm->pack_skip_pixels * components) % 8;
    5184             for (j = 0; j < elements_per_line; j++) {
    5185                 if (index_format) {
    5186                     current_bit = iter2[0] & 1;
    5187                 } else {
    5188                     if (iter2[0] > 32767) {
    5189                         current_bit = 1;
    5190                     } else {
    5191                         current_bit = 0;
    5192                     }
    5193                 }
    5194 
    5195                 if (current_bit) {
    5196                     if (psm->pack_lsb_first) {
    5197                         *iter |= (1 << bit_offset);
    5198                     } else {
    5199                         *iter |= (1 << (7 - bit_offset));
    5200                     }
    5201                 } else {
    5202                     if (psm->pack_lsb_first) {
    5203                         *iter &= ~(1 << bit_offset);
    5204                     } else {
    5205                         *iter &= ~(1 << (7 - bit_offset));
    5206                     }
    5207                 }
    5208 
    5209                 bit_offset++;
    5210                 if (bit_offset == 8) {
    5211                     bit_offset = 0;
    5212                     iter++;
    5213                 }
    5214                 iter2++;
    5215             }
    5216             start += rowsize;
    5217         }
     5169        GLint bit_offset;
     5170        GLint current_bit;
     5171
     5172        rowsize = (groups_per_line * components + 7) / 8;
     5173        padding = (rowsize % psm->pack_alignment);
     5174        if (padding) {
     5175            rowsize += psm->pack_alignment - padding;
     5176        }
     5177        start = (GLubyte *) userdata + psm->pack_skip_rows * rowsize +
     5178                (psm->pack_skip_pixels * components / 8);
     5179        elements_per_line = width * components;
     5180        iter2 = oldimage;
     5181        for (i = 0; i < height; i++) {
     5182            iter = start;
     5183            bit_offset = (psm->pack_skip_pixels * components) % 8;
     5184            for (j = 0; j < elements_per_line; j++) {
     5185                if (index_format) {
     5186                    current_bit = iter2[0] & 1;
     5187                } else {
     5188                    if (iter2[0] > 32767) {
     5189                        current_bit = 1;
     5190                    } else {
     5191                        current_bit = 0;
     5192                    }
     5193                }
     5194
     5195                if (current_bit) {
     5196                    if (psm->pack_lsb_first) {
     5197                        *iter |= (1 << bit_offset);
     5198                    } else {
     5199                        *iter |= (1 << (7 - bit_offset));
     5200                    }
     5201                } else {
     5202                    if (psm->pack_lsb_first) {
     5203                        *iter &= ~(1 << bit_offset);
     5204                    } else {
     5205                        *iter &= ~(1 << (7 - bit_offset));
     5206                    }
     5207                }
     5208
     5209                bit_offset++;
     5210                if (bit_offset == 8) {
     5211                    bit_offset = 0;
     5212                    iter++;
     5213                }
     5214                iter2++;
     5215            }
     5216            start += rowsize;
     5217        }
    52185218    } else {
    52195219        float shoveComponents[4];
    52205220
    5221         element_size = bytes_per_element(type);
    5222         group_size = element_size * components;
    5223         if (element_size == 1) myswap_bytes = 0;
    5224 
    5225         rowsize = groups_per_line * group_size;
    5226         padding = (rowsize % psm->pack_alignment);
    5227         if (padding) {
    5228             rowsize += psm->pack_alignment - padding;
    5229         }
    5230         start = (GLubyte *) userdata + psm->pack_skip_rows * rowsize +
    5231                 psm->pack_skip_pixels * group_size;
    5232         elements_per_line = width * components;
    5233 
    5234         iter2 = oldimage;
    5235         for (i = 0; i < height; i++) {
    5236             iter = start;
    5237             for (j = 0; j < elements_per_line; j++) {
    5238                 Type_Widget widget;
    5239 
    5240                 switch(type) {
    5241                   case GL_UNSIGNED_BYTE_3_3_2:
    5242                     for (k = 0; k < 3; k++) {
    5243                        shoveComponents[k]= *iter2++ / 65535.0;
    5244                     }
    5245                     shove332(shoveComponents,0,(void *)iter);
    5246                     break;
    5247                   case GL_UNSIGNED_BYTE_2_3_3_REV:
    5248                     for (k = 0; k < 3; k++) {
    5249                        shoveComponents[k]= *iter2++ / 65535.0;
    5250                     }
    5251                     shove233rev(shoveComponents,0,(void *)iter);
    5252                     break;
    5253                   case GL_UNSIGNED_BYTE:
    5254                     if (index_format) {
    5255                         *iter = *iter2++;
    5256                     } else {
    5257                         *iter = *iter2++ >> 8;
    5258                     }
    5259                     break;
    5260                   case GL_BYTE:
    5261                     if (index_format) {
    5262                         *((GLbyte *) iter) = *iter2++;
    5263                     } else {
    5264                         *((GLbyte *) iter) = *iter2++ >> 9;
    5265                     }
    5266                     break;
    5267                   case GL_UNSIGNED_SHORT_5_6_5:         
    5268                     for (k = 0; k < 3; k++) {
    5269                        shoveComponents[k]= *iter2++ / 65535.0;
    5270                     }
    5271                     shove565(shoveComponents,0,(void *)&widget.us[0]);
    5272                     if (myswap_bytes) {
    5273                        iter[0] = widget.ub[1];
    5274                        iter[1] = widget.ub[0];
    5275                     }
    5276                     else {
    5277                        *(GLushort *)iter = widget.us[0];
    5278                     }
    5279                     break;
    5280                   case GL_UNSIGNED_SHORT_5_6_5_REV:             
    5281                     for (k = 0; k < 3; k++) {
    5282                        shoveComponents[k]= *iter2++ / 65535.0;
    5283                     }
    5284                     shove565rev(shoveComponents,0,(void *)&widget.us[0]);
    5285                     if (myswap_bytes) {
    5286                        iter[0] = widget.ub[1];
    5287                        iter[1] = widget.ub[0];
    5288                     }
    5289                     else {
    5290                        *(GLushort *)iter = widget.us[0];
    5291                     }
    5292                     break;
     5221        element_size = bytes_per_element(type);
     5222        group_size = element_size * components;
     5223        if (element_size == 1) myswap_bytes = 0;
     5224
     5225        rowsize = groups_per_line * group_size;
     5226        padding = (rowsize % psm->pack_alignment);
     5227        if (padding) {
     5228            rowsize += psm->pack_alignment - padding;
     5229        }
     5230        start = (GLubyte *) userdata + psm->pack_skip_rows * rowsize +
     5231                psm->pack_skip_pixels * group_size;
     5232        elements_per_line = width * components;
     5233
     5234        iter2 = oldimage;
     5235        for (i = 0; i < height; i++) {
     5236            iter = start;
     5237            for (j = 0; j < elements_per_line; j++) {
     5238                Type_Widget widget;
     5239
     5240                switch(type) {
     5241                  case GL_UNSIGNED_BYTE_3_3_2:
     5242                    for (k = 0; k < 3; k++) {
     5243                       shoveComponents[k]= *iter2++ / 65535.0;
     5244                    }
     5245                    shove332(shoveComponents,0,(void *)iter);
     5246                    break;
     5247                  case GL_UNSIGNED_BYTE_2_3_3_REV:
     5248                    for (k = 0; k < 3; k++) {
     5249                       shoveComponents[k]= *iter2++ / 65535.0;
     5250                    }
     5251                    shove233rev(shoveComponents,0,(void *)iter);
     5252                    break;
     5253                  case GL_UNSIGNED_BYTE:
     5254                    if (index_format) {
     5255                        *iter = *iter2++;
     5256                    } else {
     5257                        *iter = *iter2++ >> 8;
     5258                    }
     5259                    break;
     5260                  case GL_BYTE:
     5261                    if (index_format) {
     5262                        *((GLbyte *) iter) = *iter2++;
     5263                    } else {
     5264                        *((GLbyte *) iter) = *iter2++ >> 9;
     5265                    }
     5266                    break;
     5267                  case GL_UNSIGNED_SHORT_5_6_5:
     5268                    for (k = 0; k < 3; k++) {
     5269                       shoveComponents[k]= *iter2++ / 65535.0;
     5270                    }
     5271                    shove565(shoveComponents,0,(void *)&widget.us[0]);
     5272                    if (myswap_bytes) {
     5273                       iter[0] = widget.ub[1];
     5274                       iter[1] = widget.ub[0];
     5275                    }
     5276                    else {
     5277                       *(GLushort *)iter = widget.us[0];
     5278                    }
     5279                    break;
     5280                  case GL_UNSIGNED_SHORT_5_6_5_REV:
     5281                    for (k = 0; k < 3; k++) {
     5282                       shoveComponents[k]= *iter2++ / 65535.0;
     5283                    }
     5284                    shove565rev(shoveComponents,0,(void *)&widget.us[0]);
     5285                    if (myswap_bytes) {
     5286                       iter[0] = widget.ub[1];
     5287                       iter[1] = widget.ub[0];
     5288                    }
     5289                    else {
     5290                       *(GLushort *)iter = widget.us[0];
     5291                    }
     5292                    break;
    52935293                  case GL_UNSIGNED_SHORT_4_4_4_4:
    5294                     for (k = 0; k < 4; k++) {
    5295                        shoveComponents[k]= *iter2++ / 65535.0;
    5296                     }
    5297                     shove4444(shoveComponents,0,(void *)&widget.us[0]);
    5298                     if (myswap_bytes) {
    5299                        iter[0] = widget.ub[1];
    5300                        iter[1] = widget.ub[0];
    5301                     } else {
    5302                        *(GLushort *)iter = widget.us[0];
    5303                     }
    5304                     break;
     5294                    for (k = 0; k < 4; k++) {
     5295                       shoveComponents[k]= *iter2++ / 65535.0;
     5296                    }
     5297                    shove4444(shoveComponents,0,(void *)&widget.us[0]);
     5298                    if (myswap_bytes) {
     5299                       iter[0] = widget.ub[1];
     5300                       iter[1] = widget.ub[0];
     5301                    } else {
     5302                       *(GLushort *)iter = widget.us[0];
     5303                    }
     5304                    break;
    53055305                  case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    5306                     for (k = 0; k < 4; k++) {
    5307                        shoveComponents[k]= *iter2++ / 65535.0;
    5308                     }
    5309                     shove4444rev(shoveComponents,0,(void *)&widget.us[0]);
    5310                     if (myswap_bytes) {
    5311                        iter[0] = widget.ub[1];
    5312                        iter[1] = widget.ub[0];
    5313                     } else {
    5314                        *(GLushort *)iter = widget.us[0];
    5315                     }
    5316                     break;
    5317                   case GL_UNSIGNED_SHORT_5_5_5_1:
    5318                     for (k = 0; k < 4; k++) {
    5319                        shoveComponents[k]= *iter2++ / 65535.0;
    5320                     }
    5321                     shove5551(shoveComponents,0,(void *)&widget.us[0]);
    5322                     if (myswap_bytes) {
    5323                        iter[0] = widget.ub[1];
    5324                        iter[1] = widget.ub[0];
    5325                     } else {
    5326                        *(GLushort *)iter = widget.us[0];
    5327                     }
    5328                     break;
    5329                   case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    5330                     for (k = 0; k < 4; k++) {
    5331                        shoveComponents[k]= *iter2++ / 65535.0;
    5332                     }
    5333                     shove1555rev(shoveComponents,0,(void *)&widget.us[0]);
    5334                     if (myswap_bytes) {
    5335                        iter[0] = widget.ub[1];
    5336                        iter[1] = widget.ub[0];
    5337                     } else {
    5338                        *(GLushort *)iter = widget.us[0];
    5339                     }
    5340                     break;
    5341                   case GL_UNSIGNED_SHORT:
    5342                   case GL_SHORT:
    5343                     if (type == GL_SHORT) {
    5344                         if (index_format) {
    5345                             widget.s[0] = *iter2++;
    5346                         } else {
    5347                             widget.s[0] = *iter2++ >> 1;
    5348                         }
    5349                     } else {
    5350                         widget.us[0] = *iter2++;
    5351                     }
    5352                     if (myswap_bytes) {
    5353                         iter[0] = widget.ub[1];
    5354                         iter[1] = widget.ub[0];
    5355                     } else {
    5356                         iter[0] = widget.ub[0];
    5357                         iter[1] = widget.ub[1];
    5358                     }
    5359                     break;
    5360                   case GL_UNSIGNED_INT_8_8_8_8:
    5361                     for (k = 0; k < 4; k++) {
    5362                        shoveComponents[k]= *iter2++ / 65535.0;
    5363                     }
    5364                     shove8888(shoveComponents,0,(void *)&widget.ui);
    5365                     if (myswap_bytes) {
    5366                         iter[3] = widget.ub[0];
    5367                         iter[2] = widget.ub[1];
    5368                         iter[1] = widget.ub[2];
    5369                         iter[0] = widget.ub[3];
    5370                     } else {
    5371                         *(GLuint *)iter= widget.ui;
    5372                     }
    5373 
    5374                     break;
    5375                   case GL_UNSIGNED_INT_8_8_8_8_REV:
    5376                     for (k = 0; k < 4; k++) {
    5377                        shoveComponents[k]= *iter2++ / 65535.0;
    5378                     }
    5379                     shove8888rev(shoveComponents,0,(void *)&widget.ui);
    5380                     if (myswap_bytes) {
    5381                         iter[3] = widget.ub[0];
    5382                         iter[2] = widget.ub[1];
    5383                         iter[1] = widget.ub[2];
    5384                         iter[0] = widget.ub[3];
    5385                     } else {
    5386                         *(GLuint *)iter= widget.ui;
    5387                     }
    5388                     break;
    5389                   case GL_UNSIGNED_INT_10_10_10_2:
    5390                     for (k = 0; k < 4; k++) {
    5391                        shoveComponents[k]= *iter2++ / 65535.0;
    5392                     }
    5393                     shove1010102(shoveComponents,0,(void *)&widget.ui);
    5394                     if (myswap_bytes) {
    5395                         iter[3] = widget.ub[0];
    5396                         iter[2] = widget.ub[1];
    5397                         iter[1] = widget.ub[2];
    5398                         iter[0] = widget.ub[3];
    5399                     } else {
    5400                         *(GLuint *)iter= widget.ui;
    5401                     }
    5402                     break;
    5403                   case GL_UNSIGNED_INT_2_10_10_10_REV:
    5404                     for (k = 0; k < 4; k++) {
    5405                        shoveComponents[k]= *iter2++ / 65535.0;
    5406                     }
    5407                     shove2101010rev(shoveComponents,0,(void *)&widget.ui);
    5408                     if (myswap_bytes) {
    5409                         iter[3] = widget.ub[0];
    5410                         iter[2] = widget.ub[1];
    5411                         iter[1] = widget.ub[2];
    5412                         iter[0] = widget.ub[3];
    5413                     } else {
    5414                         *(GLuint *)iter= widget.ui;
    5415                     }
    5416                     break;
    5417                   case GL_INT:
    5418                   case GL_UNSIGNED_INT:
    5419                   case GL_FLOAT:
    5420                     if (type == GL_FLOAT) {
    5421                         if (index_format) {
    5422                             widget.f = *iter2++;
    5423                         } else {
    5424                             widget.f = *iter2++ / (float) 65535.0;
    5425                         }
    5426                     } else if (type == GL_UNSIGNED_INT) {
    5427                         if (index_format) {
    5428                             widget.ui = *iter2++;
    5429                         } else {
    5430                             widget.ui = (unsigned int) *iter2++ * 65537;
    5431                         }
    5432                     } else {
    5433                         if (index_format) {
    5434                             widget.i = *iter2++;
    5435                         } else {
    5436                             widget.i = ((unsigned int) *iter2++ * 65537)/2;
    5437                         }
    5438                     }
    5439                     if (myswap_bytes) {
    5440                         iter[3] = widget.ub[0];
    5441                         iter[2] = widget.ub[1];
    5442                         iter[1] = widget.ub[2];
    5443                         iter[0] = widget.ub[3];
    5444                     } else {
    5445                         iter[0] = widget.ub[0];
    5446                         iter[1] = widget.ub[1];
    5447                         iter[2] = widget.ub[2];
    5448                         iter[3] = widget.ub[3];
    5449                     }
    5450                     break;
    5451                 }
    5452                 iter += element_size;
    5453             } /* for j */
    5454             start += rowsize;
     5306                    for (k = 0; k < 4; k++) {
     5307                       shoveComponents[k]= *iter2++ / 65535.0;
     5308                    }
     5309                    shove4444rev(shoveComponents,0,(void *)&widget.us[0]);
     5310                    if (myswap_bytes) {
     5311                       iter[0] = widget.ub[1];
     5312                       iter[1] = widget.ub[0];
     5313                    } else {
     5314                       *(GLushort *)iter = widget.us[0];
     5315                    }
     5316                    break;
     5317                  case GL_UNSIGNED_SHORT_5_5_5_1:
     5318                    for (k = 0; k < 4; k++) {
     5319                       shoveComponents[k]= *iter2++ / 65535.0;
     5320                    }
     5321                    shove5551(shoveComponents,0,(void *)&widget.us[0]);
     5322                    if (myswap_bytes) {
     5323                       iter[0] = widget.ub[1];
     5324                       iter[1] = widget.ub[0];
     5325                    } else {
     5326                       *(GLushort *)iter = widget.us[0];
     5327                    }
     5328                    break;
     5329                  case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     5330                    for (k = 0; k < 4; k++) {
     5331                       shoveComponents[k]= *iter2++ / 65535.0;
     5332                    }
     5333                    shove1555rev(shoveComponents,0,(void *)&widget.us[0]);
     5334                    if (myswap_bytes) {
     5335                       iter[0] = widget.ub[1];
     5336                       iter[1] = widget.ub[0];
     5337                    } else {
     5338                       *(GLushort *)iter = widget.us[0];
     5339                    }
     5340                    break;
     5341                  case GL_UNSIGNED_SHORT:
     5342                  case GL_SHORT:
     5343                    if (type == GL_SHORT) {
     5344                        if (index_format) {
     5345                            widget.s[0] = *iter2++;
     5346                        } else {
     5347                            widget.s[0] = *iter2++ >> 1;
     5348                        }
     5349                    } else {
     5350                        widget.us[0] = *iter2++;
     5351                    }
     5352                    if (myswap_bytes) {
     5353                        iter[0] = widget.ub[1];
     5354                        iter[1] = widget.ub[0];
     5355                    } else {
     5356                        iter[0] = widget.ub[0];
     5357                        iter[1] = widget.ub[1];
     5358                    }
     5359                    break;
     5360                  case GL_UNSIGNED_INT_8_8_8_8:
     5361                    for (k = 0; k < 4; k++) {
     5362                       shoveComponents[k]= *iter2++ / 65535.0;
     5363                    }
     5364                    shove8888(shoveComponents,0,(void *)&widget.ui);
     5365                    if (myswap_bytes) {
     5366                        iter[3] = widget.ub[0];
     5367                        iter[2] = widget.ub[1];
     5368                        iter[1] = widget.ub[2];
     5369                        iter[0] = widget.ub[3];
     5370                    } else {
     5371                        *(GLuint *)iter= widget.ui;
     5372                    }
     5373
     5374                    break;
     5375                  case GL_UNSIGNED_INT_8_8_8_8_REV:
     5376                    for (k = 0; k < 4; k++) {
     5377                       shoveComponents[k]= *iter2++ / 65535.0;
     5378                    }
     5379                    shove8888rev(shoveComponents,0,(void *)&widget.ui);
     5380                    if (myswap_bytes) {
     5381                        iter[3] = widget.ub[0];
     5382                        iter[2] = widget.ub[1];
     5383                        iter[1] = widget.ub[2];
     5384                        iter[0] = widget.ub[3];
     5385                    } else {
     5386                        *(GLuint *)iter= widget.ui;
     5387                    }
     5388                    break;
     5389                  case GL_UNSIGNED_INT_10_10_10_2:
     5390                    for (k = 0; k < 4; k++) {
     5391                       shoveComponents[k]= *iter2++ / 65535.0;
     5392                    }
     5393                    shove1010102(shoveComponents,0,(void *)&widget.ui);
     5394                    if (myswap_bytes) {
     5395                        iter[3] = widget.ub[0];
     5396                        iter[2] = widget.ub[1];
     5397                        iter[1] = widget.ub[2];
     5398                        iter[0] = widget.ub[3];
     5399                    } else {
     5400                        *(GLuint *)iter= widget.ui;
     5401                    }
     5402                    break;
     5403                  case GL_UNSIGNED_INT_2_10_10_10_REV:
     5404                    for (k = 0; k < 4; k++) {
     5405                       shoveComponents[k]= *iter2++ / 65535.0;
     5406                    }
     5407                    shove2101010rev(shoveComponents,0,(void *)&widget.ui);
     5408                    if (myswap_bytes) {
     5409                        iter[3] = widget.ub[0];
     5410                        iter[2] = widget.ub[1];
     5411                        iter[1] = widget.ub[2];
     5412                        iter[0] = widget.ub[3];
     5413                    } else {
     5414                        *(GLuint *)iter= widget.ui;
     5415                    }
     5416                    break;
     5417                  case GL_INT:
     5418                  case GL_UNSIGNED_INT:
     5419                  case GL_FLOAT:
     5420                    if (type == GL_FLOAT) {
     5421                        if (index_format) {
     5422                            widget.f = *iter2++;
     5423                        } else {
     5424                            widget.f = *iter2++ / (float) 65535.0;
     5425                        }
     5426                    } else if (type == GL_UNSIGNED_INT) {
     5427                        if (index_format) {
     5428                            widget.ui = *iter2++;
     5429                        } else {
     5430                            widget.ui = (unsigned int) *iter2++ * 65537;
     5431                        }
     5432                    } else {
     5433                        if (index_format) {
     5434                            widget.i = *iter2++;
     5435                        } else {
     5436                            widget.i = ((unsigned int) *iter2++ * 65537)/2;
     5437                        }
     5438                    }
     5439                    if (myswap_bytes) {
     5440                        iter[3] = widget.ub[0];
     5441                        iter[2] = widget.ub[1];
     5442                        iter[1] = widget.ub[2];
     5443                        iter[0] = widget.ub[3];
     5444                    } else {
     5445                        iter[0] = widget.ub[0];
     5446                        iter[1] = widget.ub[1];
     5447                        iter[2] = widget.ub[2];
     5448                        iter[3] = widget.ub[3];
     5449                    }
     5450                    break;
     5451                }
     5452                iter += element_size;
     5453            } /* for j */
     5454            start += rowsize;
    54555455#if 1
    5456             /* want 'iter' pointing at start, not within, row for assertion
    5457              * purposes
    5458              */
    5459             iter= start;       
     5456            /* want 'iter' pointing at start, not within, row for assertion
     5457             * purposes
     5458             */
     5459            iter= start;
    54605460#endif
    5461         } /* for i */
    5462 
    5463         /* iterators should be one byte past end */
    5464         if (!isTypePackedPixel(type)) {
    5465            assert(iter2 == &oldimage[width*height*components]);
    5466         }
    5467         else {
    5468            assert(iter2 == &oldimage[width*height*
    5469                                      elements_per_group(format,NULL)]);
    5470         }
    5471         assert( iter == &((GLubyte *)userdata)[rowsize*height] );
     5461        } /* for i */
     5462
     5463        /* iterators should be one byte past end */
     5464        if (!isTypePackedPixel(type)) {
     5465           assert(iter2 == &oldimage[width*height*components]);
     5466        }
     5467        else {
     5468           assert(iter2 == &oldimage[width*height*
     5469                                     elements_per_group(format,NULL)]);
     5470        }
     5471        assert( iter == &((GLubyte *)userdata)[rowsize*height] );
    54725472    } /* else */
    54735473} /* empty_image() */
     
    54785478 */
    54795479static void extract332(int isSwap,
    5480                        const void *packedPixel, GLfloat extractComponents[])
     5480                       const void *packedPixel, GLfloat extractComponents[])
    54815481{
    54825482   GLubyte ubyte= *(GLubyte *)packedPixel;
    54835483
    5484    isSwap= isSwap;              /* turn off warnings */
     5484   isSwap= isSwap;              /* turn off warnings */
    54855485
    54865486   /* 11100000 == 0xe0 */
     
    54905490   extractComponents[0]=   (float)((ubyte & 0xe0)  >> 5) / 7.0;
    54915491   extractComponents[1]=   (float)((ubyte & 0x1c)  >> 2) / 7.0; /* 7 = 2^3-1 */
    5492    extractComponents[2]=   (float)((ubyte & 0x03)      ) / 3.0; /* 3 = 2^2-1 */
     5492   extractComponents[2]=   (float)((ubyte & 0x03)      ) / 3.0; /* 3 = 2^2-1 */
    54935493} /* extract332() */
    54945494
    54955495static void shove332(const GLfloat shoveComponents[],
    5496                      int index, void *packedPixel)     
     5496                     int index, void *packedPixel)
    54975497{
    54985498   /* 11100000 == 0xe0 */
     
    55145514
    55155515static void extract233rev(int isSwap,
    5516                           const void *packedPixel, GLfloat extractComponents[])
     5516                          const void *packedPixel, GLfloat extractComponents[])
    55175517{
    55185518   GLubyte ubyte= *(GLubyte *)packedPixel;
    55195519
    5520    isSwap= isSwap;              /* turn off warnings */
     5520   isSwap= isSwap;              /* turn off warnings */
    55215521
    55225522   /* 0000,0111 == 0x07 */
     
    55305530
    55315531static void shove233rev(const GLfloat shoveComponents[],
    5532                         int index, void *packedPixel)   
     5532                        int index, void *packedPixel)
    55335533{
    55345534   /* 0000,0111 == 0x07 */
     
    55505550
    55515551static void extract565(int isSwap,
    5552                        const void *packedPixel, GLfloat extractComponents[])
     5552                       const void *packedPixel, GLfloat extractComponents[])
    55535553{
    55545554   GLushort ushort= *(GLushort *)packedPixel;
     
    55715571
    55725572static void shove565(const GLfloat shoveComponents[],
    5573                      int index,void *packedPixel)
     5573                     int index,void *packedPixel)
    55745574{
    55755575   /* 11111000,00000000 == 0xf800 */
     
    55915591
    55925592static void extract565rev(int isSwap,
    5593                           const void *packedPixel, GLfloat extractComponents[])
     5593                          const void *packedPixel, GLfloat extractComponents[])
    55945594{
    55955595   GLushort ushort= *(GLushort *)packedPixel;
     
    56125612
    56135613static void shove565rev(const GLfloat shoveComponents[],
    5614                         int index,void *packedPixel)
     5614                        int index,void *packedPixel)
    56155615{
    56165616   /* 00000000,00011111 == 0x001f */
     
    56325632
    56335633static void extract4444(int isSwap,const void *packedPixel,
    5634                         GLfloat extractComponents[])
     5634                        GLfloat extractComponents[])
    56355635{
    56365636   GLushort ushort;
     
    56555655
    56565656static void shove4444(const GLfloat shoveComponents[],
    5657                       int index,void *packedPixel)
     5657                      int index,void *packedPixel)
    56585658{
    56595659   assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0);
     
    56745674
    56755675static void extract4444rev(int isSwap,const void *packedPixel,
    5676                            GLfloat extractComponents[])
     5676                           GLfloat extractComponents[])
    56775677{
    56785678   GLushort ushort;
     
    56985698
    56995699static void shove4444rev(const GLfloat shoveComponents[],
    5700                         int index,void *packedPixel)
     5700                        int index,void *packedPixel)
    57015701{
    57025702   /* 00000000,00001111 == 0x000f */
     
    57225722
    57235723static void extract5551(int isSwap,const void *packedPixel,
    5724                         GLfloat extractComponents[])
     5724                        GLfloat extractComponents[])
    57255725{
    57265726   GLushort ushort;
     
    57455745
    57465746static void shove5551(const GLfloat shoveComponents[],
    5747                       int index,void *packedPixel)
     5747                      int index,void *packedPixel)
    57485748{
    57495749   /* 11111000,00000000 == 0xf800 */
     
    57695769
    57705770static void extract1555rev(int isSwap,const void *packedPixel,
    5771                            GLfloat extractComponents[])
     5771                           GLfloat extractComponents[])
    57725772{
    57735773   GLushort ushort;
     
    57935793
    57945794static void shove1555rev(const GLfloat shoveComponents[],
    5795                         int index,void *packedPixel)
     5795                        int index,void *packedPixel)
    57965796{
    57975797   /* 00000000,00011111 == 0x001F */
     
    58175817
    58185818static void extract8888(int isSwap,
    5819                         const void *packedPixel, GLfloat extractComponents[])
     5819                        const void *packedPixel, GLfloat extractComponents[])
    58205820{
    58215821   GLuint uint;
     
    58415841
    58425842static void shove8888(const GLfloat shoveComponents[],
    5843                       int index,void *packedPixel)
     5843                      int index,void *packedPixel)
    58445844{
    58455845   /* 11111111,00000000,00000000,00000000 == 0xff000000 */
     
    58655865
    58665866static void extract8888rev(int isSwap,
    5867                            const void *packedPixel,GLfloat extractComponents[])
     5867                           const void *packedPixel,GLfloat extractComponents[])
    58685868{
    58695869   GLuint uint;
     
    58895889
    58905890static void shove8888rev(const GLfloat shoveComponents[],
    5891                         int index,void *packedPixel)
     5891                        int index,void *packedPixel)
    58925892{
    58935893   /* 00000000,00000000,00000000,11111111 == 0x000000ff */
     
    59135913
    59145914static void extract1010102(int isSwap,
    5915                            const void *packedPixel,GLfloat extractComponents[])
     5915                           const void *packedPixel,GLfloat extractComponents[])
    59165916{
    59175917   GLuint uint;
     
    59375937
    59385938static void shove1010102(const GLfloat shoveComponents[],
    5939                         int index,void *packedPixel)
     5939                        int index,void *packedPixel)
    59405940{
    59415941   /* 11111111,11000000,00000000,00000000 == 0xffc00000 */
     
    59615961
    59625962static void extract2101010rev(int isSwap,
    5963                               const void *packedPixel,
    5964                               GLfloat extractComponents[])
     5963                              const void *packedPixel,
     5964                              GLfloat extractComponents[])
    59655965{
    59665966   GLuint uint;
     
    59875987
    59885988static void shove2101010rev(const GLfloat shoveComponents[],
    5989                             int index,void *packedPixel)
     5989                            int index,void *packedPixel)
    59905990{
    59915991   /* 00000000,00000000,00000011,11111111 == 0x000003FF */
     
    60116011
    60126012static void scaleInternalPackedPixel(int components,
    6013                                      void (*extractPackedPixel)
    6014                                      (int, const void *,GLfloat []),
    6015                                      void (*shovePackedPixel)
    6016                                      (const GLfloat [], int, void *),
    6017                                      GLint widthIn,GLint heightIn,
    6018                                      const void *dataIn,
    6019                                      GLint widthOut,GLint heightOut,
    6020                                      void *dataOut,
    6021                                      GLint pixelSizeInBytes,
    6022                                      GLint rowSizeInBytes,GLint isSwap)
     6013                                     void (*extractPackedPixel)
     6014                                     (int, const void *,GLfloat []),
     6015                                     void (*shovePackedPixel)
     6016                                     (const GLfloat [], int, void *),
     6017                                     GLint widthIn,GLint heightIn,
     6018                                     const void *dataIn,
     6019                                     GLint widthOut,GLint heightOut,
     6020                                     void *dataOut,
     6021                                     GLint pixelSizeInBytes,
     6022                                     GLint rowSizeInBytes,GLint isSwap)
    60236023{
    60246024    float x, convx;
     
    60466046
    60476047    if (widthIn == widthOut*2 && heightIn == heightOut*2) {
    6048         halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel,
    6049                               widthIn, heightIn, dataIn, dataOut,
    6050                               pixelSizeInBytes,rowSizeInBytes,isSwap);
    6051         return;
     6048        halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel,
     6049                              widthIn, heightIn, dataIn, dataOut,
     6050                              pixelSizeInBytes,rowSizeInBytes,isSwap);
     6051        return;
    60526052    }
    60536053    convy = (float) heightIn/heightOut;
     
    60666066
    60676067    for (i = 0; i < heightOut; i++) {
    6068         lowx_int = 0;
    6069         lowx_float = 0;
    6070         highx_int = convx_int;
    6071         highx_float = convx_float;
    6072 
    6073         for (j = 0; j < widthOut; j++) {
    6074             /*
    6075             ** Ok, now apply box filter to box that goes from (lowx, lowy)
    6076             ** to (highx, highy) on input data into this pixel on output
    6077             ** data.
    6078             */
    6079             totals[0] = totals[1] = totals[2] = totals[3] = 0.0;
    6080 
    6081             /* calculate the value for pixels in the 1st row */
    6082             xindex = lowx_int*pixelSizeInBytes;
    6083             if((highy_int>lowy_int) && (highx_int>lowx_int)) {
    6084 
    6085                 y_percent = 1-lowy_float;
    6086                 temp = (char *)dataIn + xindex + lowy_int * rowSizeInBytes;
    6087                 percent = y_percent * (1-lowx_float);
     6068        lowx_int = 0;
     6069        lowx_float = 0;
     6070        highx_int = convx_int;
     6071        highx_float = convx_float;
     6072
     6073        for (j = 0; j < widthOut; j++) {
     6074            /*
     6075            ** Ok, now apply box filter to box that goes from (lowx, lowy)
     6076            ** to (highx, highy) on input data into this pixel on output
     6077            ** data.
     6078            */
     6079            totals[0] = totals[1] = totals[2] = totals[3] = 0.0;
     6080
     6081            /* calculate the value for pixels in the 1st row */
     6082            xindex = lowx_int*pixelSizeInBytes;
     6083            if((highy_int>lowy_int) && (highx_int>lowx_int)) {
     6084
     6085                y_percent = 1-lowy_float;
     6086                temp = (char *)dataIn + xindex + lowy_int * rowSizeInBytes;
     6087                percent = y_percent * (1-lowx_float);
    60886088#if 0
    6089                 for (k = 0, temp_index = temp; k < components;
    6090                      k++, temp_index += element_size) {
    6091                     if (myswap_bytes) {
    6092                         totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
    6093                     } else {
    6094                         totals[k] += *(GLushort*)temp_index * percent;
    6095                     }
    6096                 }
     6089                for (k = 0, temp_index = temp; k < components;
     6090                     k++, temp_index += element_size) {
     6091                    if (myswap_bytes) {
     6092                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     6093                    } else {
     6094                        totals[k] += *(GLushort*)temp_index * percent;
     6095                    }
     6096                }
    60976097#else
    6098                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6099                 for (k = 0; k < components; k++) {
    6100                    totals[k]+= extractTotals[k] * percent;
    6101                 }
     6098                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6099                for (k = 0; k < components; k++) {
     6100                   totals[k]+= extractTotals[k] * percent;
     6101                }
    61026102#endif
    6103                 left = temp;
    6104                 for(l = lowx_int+1; l < highx_int; l++) {
    6105                     temp += pixelSizeInBytes;
     6103                left = temp;
     6104                for(l = lowx_int+1; l < highx_int; l++) {
     6105                    temp += pixelSizeInBytes;
    61066106#if 0
    6107                     for (k = 0, temp_index = temp; k < components;
    6108                         k++, temp_index += element_size) {
     6107                    for (k = 0, temp_index = temp; k < components;
     6108                        k++, temp_index += element_size) {
    61096109                        if (myswap_bytes) {
    61106110                            totals[k] +=
     
    61136113                            totals[k] += *(GLushort*)temp_index * y_percent;
    61146114                        }
    6115                     }
     6115                    }
    61166116#else
    6117                     (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6118                     for (k = 0; k < components; k++) {
    6119                        totals[k]+= extractTotals[k] * y_percent;
    6120                     }
     6117                    (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6118                    for (k = 0; k < components; k++) {
     6119                       totals[k]+= extractTotals[k] * y_percent;
     6120                    }
    61216121#endif
    6122                 }
    6123                 temp += pixelSizeInBytes;
    6124                 right = temp;
    6125                 percent = y_percent * highx_float;
     6122                }
     6123                temp += pixelSizeInBytes;
     6124                right = temp;
     6125                percent = y_percent * highx_float;
    61266126#if 0
    61276127                for (k = 0, temp_index = temp; k < components;
    6128                      k++, temp_index += element_size) {
     6128                     k++, temp_index += element_size) {
    61296129                    if (myswap_bytes) {
    61306130                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    61346134                }
    61356135#else
    6136                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6137                 for (k = 0; k < components; k++) {
    6138                    totals[k]+= extractTotals[k] * percent;
    6139                 }
     6136                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6137                for (k = 0; k < components; k++) {
     6138                   totals[k]+= extractTotals[k] * percent;
     6139                }
    61406140#endif
    61416141
    6142                 /* calculate the value for pixels in the last row */
    6143                
    6144                 y_percent = highy_float;
    6145                 percent = y_percent * (1-lowx_float);
    6146                 temp = (char *)dataIn + xindex + highy_int * rowSizeInBytes;
     6142                /* calculate the value for pixels in the last row */
     6143
     6144                y_percent = highy_float;
     6145                percent = y_percent * (1-lowx_float);
     6146                temp = (char *)dataIn + xindex + highy_int * rowSizeInBytes;
    61476147#if 0
    61486148                for (k = 0, temp_index = temp; k < components;
    6149                      k++, temp_index += element_size) {
     6149                     k++, temp_index += element_size) {
    61506150                    if (myswap_bytes) {
    61516151                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    61556155                }
    61566156#else
    6157                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6158                 for (k = 0; k < components; k++) {
    6159                    totals[k]+= extractTotals[k] * percent;
    6160                 }
     6157                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6158                for (k = 0; k < components; k++) {
     6159                   totals[k]+= extractTotals[k] * percent;
     6160                }
    61616161#endif
    6162                 for(l = lowx_int+1; l < highx_int; l++) {
     6162                for(l = lowx_int+1; l < highx_int; l++) {
    61636163                    temp += pixelSizeInBytes;
    61646164#if 0
    61656165                    for (k = 0, temp_index = temp; k < components;
    6166                         k++, temp_index += element_size) {
     6166                        k++, temp_index += element_size) {
    61676167                        if (myswap_bytes) {
    61686168                            totals[k] +=
     
    61736173                    }
    61746174#else
    6175                     (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6176                     for (k = 0; k < components; k++) {
    6177                        totals[k]+= extractTotals[k] * y_percent;
    6178                     }
     6175                    (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6176                    for (k = 0; k < components; k++) {
     6177                       totals[k]+= extractTotals[k] * y_percent;
     6178                    }
    61796179#endif
    61806180
    61816181                }
    61826182                temp += pixelSizeInBytes;
    6183                 percent = y_percent * highx_float;
     6183                percent = y_percent * highx_float;
    61846184#if 0
    61856185                for (k = 0, temp_index = temp; k < components;
    6186                      k++, temp_index += element_size) {
     6186                     k++, temp_index += element_size) {
    61876187                    if (myswap_bytes) {
    61886188                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    61926192                }
    61936193#else
    6194                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6195                 for (k = 0; k < components; k++) {
    6196                    totals[k]+= extractTotals[k] * percent;
    6197                 }
     6194                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6195                for (k = 0; k < components; k++) {
     6196                   totals[k]+= extractTotals[k] * percent;
     6197                }
    61986198#endif
    61996199
    6200                 /* calculate the value for pixels in the 1st and last column */
    6201                 for(m = lowy_int+1; m < highy_int; m++) {
    6202                     left += rowSizeInBytes;
    6203                     right += rowSizeInBytes;
     6200                /* calculate the value for pixels in the 1st and last column */
     6201                for(m = lowy_int+1; m < highy_int; m++) {
     6202                    left += rowSizeInBytes;
     6203                    right += rowSizeInBytes;
    62046204#if 0
    62056205                    for (k = 0; k < components;
    6206                          k++, left += element_size, right += element_size) {
     6206                         k++, left += element_size, right += element_size) {
    62076207                        if (myswap_bytes) {
    62086208                            totals[k] +=
    6209                                 __GLU_SWAP_2_BYTES(left) * (1-lowx_float) +
    6210                                 __GLU_SWAP_2_BYTES(right) * highx_float;
     6209                                __GLU_SWAP_2_BYTES(left) * (1-lowx_float) +
     6210                                __GLU_SWAP_2_BYTES(right) * highx_float;
    62116211                        } else {
    62126212                            totals[k] += *(GLushort*)left * (1-lowx_float)
    62136213                                       + *(GLushort*)right * highx_float;
    62146214                        }
    6215                     }
     6215                    }
    62166216#else
    6217                     (*extractPackedPixel)(isSwap,
    6218                                           (void *)left,extractTotals);
    6219                     (*extractPackedPixel)(isSwap,
    6220                                           (void *)right,extractMoreTotals);
    6221                     for (k = 0; k < components; k++) {
    6222                        totals[k]+= (extractTotals[k]*(1-lowx_float) +
    6223                                    extractMoreTotals[k]*highx_float);
    6224                     }
     6217                    (*extractPackedPixel)(isSwap,
     6218                                          (void *)left,extractTotals);
     6219                    (*extractPackedPixel)(isSwap,
     6220                                          (void *)right,extractMoreTotals);
     6221                    for (k = 0; k < components; k++) {
     6222                       totals[k]+= (extractTotals[k]*(1-lowx_float) +
     6223                                   extractMoreTotals[k]*highx_float);
     6224                    }
    62256225#endif
    6226                 }
    6227             } else if (highy_int > lowy_int) {
    6228                 x_percent = highx_float - lowx_float;
    6229                 percent = (1-lowy_float)*x_percent;
    6230                 temp = (char *)dataIn + xindex + lowy_int*rowSizeInBytes;
     6226                }
     6227            } else if (highy_int > lowy_int) {
     6228                x_percent = highx_float - lowx_float;
     6229                percent = (1-lowy_float)*x_percent;
     6230                temp = (char *)dataIn + xindex + lowy_int*rowSizeInBytes;
    62316231#if 0
    62326232                for (k = 0, temp_index = temp; k < components;
    6233                      k++, temp_index += element_size) {
     6233                     k++, temp_index += element_size) {
    62346234                    if (myswap_bytes) {
    62356235                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    62376237                        totals[k] += *(GLushort*)temp_index * percent;
    62386238                    }
    6239                 }
     6239                }
    62406240#else
    6241                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6242                 for (k = 0; k < components; k++) {
    6243                    totals[k]+= extractTotals[k] * percent;
    6244                 }
     6241                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6242                for (k = 0; k < components; k++) {
     6243                   totals[k]+= extractTotals[k] * percent;
     6244                }
    62456245#endif
    6246                 for(m = lowy_int+1; m < highy_int; m++) {
    6247                     temp += rowSizeInBytes;
     6246                for(m = lowy_int+1; m < highy_int; m++) {
     6247                    temp += rowSizeInBytes;
    62486248#if 0
    62496249                    for (k = 0, temp_index = temp; k < components;
    6250                          k++, temp_index += element_size) {
     6250                         k++, temp_index += element_size) {
    62516251                        if (myswap_bytes) {
    62526252                            totals[k] +=
    6253                                 __GLU_SWAP_2_BYTES(temp_index) * x_percent;
     6253                                __GLU_SWAP_2_BYTES(temp_index) * x_percent;
    62546254                        } else {
    62556255                            totals[k] += *(GLushort*)temp_index * x_percent;
    62566256                        }
    6257                     }
     6257                    }
    62586258#else
    6259                     (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6260                     for (k = 0; k < components; k++) {
    6261                        totals[k]+= extractTotals[k] * x_percent;
    6262                     }
     6259                    (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6260                    for (k = 0; k < components; k++) {
     6261                       totals[k]+= extractTotals[k] * x_percent;
     6262                    }
    62636263#endif
    6264                 }
    6265                 percent = x_percent * highy_float;
    6266                 temp += rowSizeInBytes;
     6264                }
     6265                percent = x_percent * highy_float;
     6266                temp += rowSizeInBytes;
    62676267#if 0
    62686268                for (k = 0, temp_index = temp; k < components;
    6269                      k++, temp_index += element_size) {
     6269                     k++, temp_index += element_size) {
    62706270                    if (myswap_bytes) {
    62716271                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    62756275                }
    62766276#else
    6277                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6278                 for (k = 0; k < components; k++) {
    6279                    totals[k]+= extractTotals[k] * percent;
    6280                 }
     6277                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6278                for (k = 0; k < components; k++) {
     6279                   totals[k]+= extractTotals[k] * percent;
     6280                }
    62816281#endif
    6282             } else if (highx_int > lowx_int) {
    6283                 y_percent = highy_float - lowy_float;
    6284                 percent = (1-lowx_float)*y_percent;
    6285                 temp = (char *)dataIn + xindex + lowy_int*rowSizeInBytes;
     6282            } else if (highx_int > lowx_int) {
     6283                y_percent = highy_float - lowy_float;
     6284                percent = (1-lowx_float)*y_percent;
     6285                temp = (char *)dataIn + xindex + lowy_int*rowSizeInBytes;
    62866286#if 0
    62876287                for (k = 0, temp_index = temp; k < components;
    6288                      k++, temp_index += element_size) {
     6288                     k++, temp_index += element_size) {
    62896289                    if (myswap_bytes) {
    62906290                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    62946294                }
    62956295#else
    6296                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6297                 for (k = 0; k < components; k++) {
    6298                    totals[k]+= extractTotals[k] * percent;
    6299                 }
     6296                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6297                for (k = 0; k < components; k++) {
     6298                   totals[k]+= extractTotals[k] * percent;
     6299                }
    63006300#endif
    6301                 for (l = lowx_int+1; l < highx_int; l++) {
     6301                for (l = lowx_int+1; l < highx_int; l++) {
    63026302                    temp += pixelSizeInBytes;
    63036303#if 0
    63046304                    for (k = 0, temp_index = temp; k < components;
    6305                          k++, temp_index += element_size) {
     6305                         k++, temp_index += element_size) {
    63066306                        if (myswap_bytes) {
    63076307                            totals[k] +=
    6308                                 __GLU_SWAP_2_BYTES(temp_index) * y_percent;
     6308                                __GLU_SWAP_2_BYTES(temp_index) * y_percent;
    63096309                        } else {
    63106310                            totals[k] += *(GLushort*)temp_index * y_percent;
    63116311                        }
    6312                     }
     6312                    }
    63136313#else
    6314                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6315                 for (k = 0; k < components; k++) {
    6316                    totals[k]+= extractTotals[k] * y_percent;
    6317                 }
     6314                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6315                for (k = 0; k < components; k++) {
     6316                   totals[k]+= extractTotals[k] * y_percent;
     6317                }
    63186318#endif
    6319                 }
    6320                 temp += pixelSizeInBytes;
    6321                 percent = y_percent * highx_float;
     6319                }
     6320                temp += pixelSizeInBytes;
     6321                percent = y_percent * highx_float;
    63226322#if 0
    63236323                for (k = 0, temp_index = temp; k < components;
    6324                      k++, temp_index += element_size) {
     6324                     k++, temp_index += element_size) {
    63256325                    if (myswap_bytes) {
    63266326                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    63286328                        totals[k] += *(GLushort*)temp_index * percent;
    63296329                    }
    6330                 }
     6330                }
    63316331#else
    6332                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6333                 for (k = 0; k < components; k++) {
    6334                    totals[k]+= extractTotals[k] * percent;
    6335                 }
     6332                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6333                for (k = 0; k < components; k++) {
     6334                   totals[k]+= extractTotals[k] * percent;
     6335                }
    63366336#endif
    6337             } else {
    6338                 percent = (highy_float-lowy_float)*(highx_float-lowx_float);
    6339                 temp = (char *)dataIn + xindex + lowy_int * rowSizeInBytes;
     6337            } else {
     6338                percent = (highy_float-lowy_float)*(highx_float-lowx_float);
     6339                temp = (char *)dataIn + xindex + lowy_int * rowSizeInBytes;
    63406340#if 0
    63416341                for (k = 0, temp_index = temp; k < components;
    6342                      k++, temp_index += element_size) {
     6342                     k++, temp_index += element_size) {
    63436343                    if (myswap_bytes) {
    63446344                        totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent;
     
    63486348                }
    63496349#else
    6350                 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6351                 for (k = 0; k < components; k++) {
    6352                    totals[k]+= extractTotals[k] * percent;
    6353                 }
     6350                (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6351                for (k = 0; k < components; k++) {
     6352                   totals[k]+= extractTotals[k] * percent;
     6353                }
    63546354#endif
    6355             }
    6356 
    6357             /* this is for the pixels in the body */
    6358             temp0 = (char *)dataIn + xindex + pixelSizeInBytes + (lowy_int+1)*rowSizeInBytes;
    6359             for (m = lowy_int+1; m < highy_int; m++) {
    6360                 temp = temp0;
    6361                 for(l = lowx_int+1; l < highx_int; l++) {
     6355            }
     6356
     6357            /* this is for the pixels in the body */
     6358            temp0 = (char *)dataIn + xindex + pixelSizeInBytes + (lowy_int+1)*rowSizeInBytes;
     6359            for (m = lowy_int+1; m < highy_int; m++) {
     6360                temp = temp0;
     6361                for(l = lowx_int+1; l < highx_int; l++) {
    63626362#if 0
    63636363                    for (k = 0, temp_index = temp; k < components;
    6364                          k++, temp_index += element_size) {
     6364                         k++, temp_index += element_size) {
    63656365                        if (myswap_bytes) {
    63666366                            totals[k] += __GLU_SWAP_2_BYTES(temp_index);
     
    63706370                    }
    63716371#else
    6372                     (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
    6373                     for (k = 0; k < components; k++) {
    6374                        totals[k]+= extractTotals[k];
    6375                     }
     6372                    (*extractPackedPixel)(isSwap,(void *)temp,extractTotals);
     6373                    for (k = 0; k < components; k++) {
     6374                       totals[k]+= extractTotals[k];
     6375                    }
    63766376#endif
    63776377                    temp += pixelSizeInBytes;
    63786378                }
    6379                 temp0 += rowSizeInBytes;
    6380             }
    6381 
    6382             outindex = (j + (i * widthOut)); /* * (components == 1) */
     6379                temp0 += rowSizeInBytes;
     6380            }
     6381
     6382            outindex = (j + (i * widthOut)); /* * (components == 1) */
    63836383#if 0
    6384             for (k = 0; k < components; k++) {
    6385                 dataout[outindex + k] = totals[k]/area;
    6386                 /*printf("totals[%d] = %f\n", k, totals[k]);*/
    6387             }
     6384            for (k = 0; k < components; k++) {
     6385                dataout[outindex + k] = totals[k]/area;
     6386                /*printf("totals[%d] = %f\n", k, totals[k]);*/
     6387            }
    63886388#else
    6389             for (k = 0; k < components; k++) {
    6390                 shoveTotals[k]= totals[k]/area;
    6391             }
    6392             (*shovePackedPixel)(shoveTotals,outindex,(void *)dataOut);
     6389            for (k = 0; k < components; k++) {
     6390                shoveTotals[k]= totals[k]/area;
     6391            }
     6392            (*shovePackedPixel)(shoveTotals,outindex,(void *)dataOut);
    63936393#endif
    6394             lowx_int = highx_int;
    6395             lowx_float = highx_float;
    6396             highx_int += convx_int;
    6397             highx_float += convx_float;
    6398             if(highx_float > 1) {
    6399                 highx_float -= 1.0;
    6400                 highx_int++;
    6401             }
    6402         }
    6403         lowy_int = highy_int;
    6404         lowy_float = highy_float;
    6405         highy_int += convy_int;
    6406         highy_float += convy_float;
    6407         if(highy_float > 1) {
    6408             highy_float -= 1.0;
    6409             highy_int++;
    6410         }
     6394            lowx_int = highx_int;
     6395            lowx_float = highx_float;
     6396            highx_int += convx_int;
     6397            highx_float += convx_float;
     6398            if(highx_float > 1) {
     6399                highx_float -= 1.0;
     6400                highx_int++;
     6401            }
     6402        }
     6403        lowy_int = highy_int;
     6404        lowy_float = highy_float;
     6405        highy_int += convy_int;
     6406        highy_float += convy_float;
     6407        if(highy_float > 1) {
     6408            highy_float -= 1.0;
     6409            highy_int++;
     6410        }
    64116411    }
    64126412
     
    64186418 */
    64196419static void halveImagePackedPixel(int components,
    6420                                   void (*extractPackedPixel)
    6421                                   (int, const void *,GLfloat []),
    6422                                   void (*shovePackedPixel)
    6423                                   (const GLfloat [],int, void *),
    6424                                   GLint width, GLint height,
    6425                                   const void *dataIn, void *dataOut,
    6426                                   GLint pixelSizeInBytes,
    6427                                   GLint rowSizeInBytes, GLint isSwap)
     6420                                  void (*extractPackedPixel)
     6421                                  (int, const void *,GLfloat []),
     6422                                  void (*shovePackedPixel)
     6423                                  (const GLfloat [],int, void *),
     6424                                  GLint width, GLint height,
     6425                                  const void *dataIn, void *dataOut,
     6426                                  GLint pixelSizeInBytes,
     6427                                  GLint rowSizeInBytes, GLint isSwap)
    64286428{
    64296429   /* handle case where there is only 1 column/row */
     
    64316431      assert(!(width == 1 && height == 1)); /* can't be 1x1 */
    64326432      halve1DimagePackedPixel(components,extractPackedPixel,shovePackedPixel,
    6433                               width,height,dataIn,dataOut,pixelSizeInBytes,
    6434                               rowSizeInBytes,isSwap);
     6433                              width,height,dataIn,dataOut,pixelSizeInBytes,
     6434                              rowSizeInBytes,isSwap);
    64356435      return;
    64366436   }
     
    64466446
    64476447      for (ii= 0; ii< halfHeight; ii++) {
    6448         for (jj= 0; jj< halfWidth; jj++) {
     6448        for (jj= 0; jj< halfWidth; jj++) {
    64496449#define BOX4 4
    6450             float totals[4];    /* 4 is maximum components */
    6451             float extractTotals[BOX4][4]; /* 4 is maximum components */
    6452             int cc;
    6453 
    6454             (*extractPackedPixel)(isSwap,(void *)src,
    6455                                   &extractTotals[0][0]);
    6456             (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes),
    6457                                   &extractTotals[1][0]);
    6458             (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes),
    6459                                   &extractTotals[2][0]);
    6460             (*extractPackedPixel)(isSwap,
    6461                                   (void*)(src+rowSizeInBytes+pixelSizeInBytes),
    6462                                   &extractTotals[3][0]);
    6463             for (cc = 0; cc < components; cc++) {
    6464                int kk;
    6465 
    6466                /* grab 4 pixels to average */
    6467                totals[cc]= 0.0;
    6468                /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    6469                 *              extractTotals[2][RED]+extractTotals[3][RED];
    6470                 * totals[RED]/= 4.0;
    6471                 */
    6472                for (kk = 0; kk < BOX4; kk++) {
    6473                   totals[cc]+= extractTotals[kk][cc];
    6474                }
    6475                totals[cc]/= (float)BOX4;
    6476             }
    6477             (*shovePackedPixel)(totals,outIndex,dataOut);
    6478 
    6479             outIndex++;
    6480             /* skip over to next square of 4 */
    6481             src+= pixelSizeInBytes + pixelSizeInBytes;
    6482         }
    6483         /* skip past pad bytes, if any, to get to next row */
    6484         src+= padBytes;
    6485 
    6486         /* src is at beginning of a row here, but it's the second row of
    6487           * the square block of 4 pixels that we just worked on so we
    6488           * need to go one more row.
    6489           * i.e.,
    6490           *                   OO...
    6491           *           here -->OO...
    6492           *       but want -->OO...
    6493           *                   OO...
    6494           *                   ...
    6495           */
    6496         src+= rowSizeInBytes;
     6450            float totals[4];    /* 4 is maximum components */
     6451            float extractTotals[BOX4][4]; /* 4 is maximum components */
     6452            int cc;
     6453
     6454            (*extractPackedPixel)(isSwap,(void *)src,
     6455                                  &extractTotals[0][0]);
     6456            (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes),
     6457                                  &extractTotals[1][0]);
     6458            (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes),
     6459                                  &extractTotals[2][0]);
     6460            (*extractPackedPixel)(isSwap,
     6461                                  (void*)(src+rowSizeInBytes+pixelSizeInBytes),
     6462                                  &extractTotals[3][0]);
     6463            for (cc = 0; cc < components; cc++) {
     6464               int kk;
     6465
     6466               /* grab 4 pixels to average */
     6467               totals[cc]= 0.0;
     6468               /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     6469                *              extractTotals[2][RED]+extractTotals[3][RED];
     6470                * totals[RED]/= 4.0;
     6471                */
     6472               for (kk = 0; kk < BOX4; kk++) {
     6473                  totals[cc]+= extractTotals[kk][cc];
     6474               }
     6475               totals[cc]/= (float)BOX4;
     6476            }
     6477            (*shovePackedPixel)(totals,outIndex,dataOut);
     6478
     6479            outIndex++;
     6480            /* skip over to next square of 4 */
     6481            src+= pixelSizeInBytes + pixelSizeInBytes;
     6482        }
     6483        /* skip past pad bytes, if any, to get to next row */
     6484        src+= padBytes;
     6485
     6486        /* src is at beginning of a row here, but it's the second row of
     6487          * the square block of 4 pixels that we just worked on so we
     6488          * need to go one more row.
     6489          * i.e.,
     6490          *                   OO...
     6491          *           here -->OO...
     6492          *       but want -->OO...
     6493          *                   OO...
     6494          *                   ...
     6495          */
     6496        src+= rowSizeInBytes;
    64976497      }
    64986498
     
    65046504
    65056505static void halve1DimagePackedPixel(int components,
    6506                                     void (*extractPackedPixel)
    6507                                     (int, const void *,GLfloat []),
    6508                                     void (*shovePackedPixel)
    6509                                     (const GLfloat [],int, void *),
    6510                                     GLint width, GLint height,
    6511                                     const void *dataIn, void *dataOut,
    6512                                     GLint pixelSizeInBytes,
    6513                                     GLint rowSizeInBytes, GLint isSwap)
     6506                                    void (*extractPackedPixel)
     6507                                    (int, const void *,GLfloat []),
     6508                                    void (*shovePackedPixel)
     6509                                    (const GLfloat [],int, void *),
     6510                                    GLint width, GLint height,
     6511                                    const void *dataIn, void *dataOut,
     6512                                    GLint pixelSizeInBytes,
     6513                                    GLint rowSizeInBytes, GLint isSwap)
    65146514{
    65156515   int halfWidth= width / 2;
     
    65196519
    65206520   assert(width == 1 || height == 1); /* must be 1D */
    6521    assert(width != height);     /* can't be square */
    6522 
    6523    if (height == 1) {   /* 1 row */
     6521   assert(width != height);     /* can't be square */
     6522
     6523   if (height == 1) {   /* 1 row */
    65246524      int outIndex= 0;
    65256525
    6526       assert(width != 1);       /* widthxheight can't be 1x1 */
     6526      assert(width != 1);       /* widthxheight can't be 1x1 */
    65276527      halfHeight= 1;
    65286528
     
    65316531      for (jj= 0; jj< halfWidth; jj++) {
    65326532#define BOX2 2
    6533          float totals[4];       /* 4 is maximum components */
    6534         float extractTotals[BOX2][4]; /* 4 is maximum components */
    6535         int cc;
    6536 
    6537         /* average two at a time, instead of four */
    6538         (*extractPackedPixel)(isSwap,(void*)src,
    6539                                &extractTotals[0][0]);
    6540         (*extractPackedPixel)(isSwap,(void*)(src+pixelSizeInBytes),
    6541                                &extractTotals[1][0]);                   
    6542         for (cc = 0; cc < components; cc++) {
    6543             int kk;
    6544 
    6545             /* grab 2 pixels to average */
    6546             totals[cc]= 0.0;
    6547             /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
    6548              * totals[RED]/= 2.0;
    6549              */
    6550             for (kk = 0; kk < BOX2; kk++) {
    6551                totals[cc]+= extractTotals[kk][cc];
    6552             }
    6553             totals[cc]/= (float)BOX2;
    6554         }
    6555         (*shovePackedPixel)(totals,outIndex,dataOut);
    6556 
    6557         outIndex++;
    6558         /* skip over to next group of 2 */
    6559         src+= pixelSizeInBytes + pixelSizeInBytes;
     6533         float totals[4];       /* 4 is maximum components */
     6534        float extractTotals[BOX2][4]; /* 4 is maximum components */
     6535        int cc;
     6536
     6537        /* average two at a time, instead of four */
     6538        (*extractPackedPixel)(isSwap,(void*)src,
     6539                               &extractTotals[0][0]);
     6540        (*extractPackedPixel)(isSwap,(void*)(src+pixelSizeInBytes),
     6541                               &extractTotals[1][0]);
     6542        for (cc = 0; cc < components; cc++) {
     6543            int kk;
     6544
     6545            /* grab 2 pixels to average */
     6546            totals[cc]= 0.0;
     6547            /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
     6548             * totals[RED]/= 2.0;
     6549             */
     6550            for (kk = 0; kk < BOX2; kk++) {
     6551               totals[cc]+= extractTotals[kk][cc];
     6552            }
     6553            totals[cc]/= (float)BOX2;
     6554        }
     6555        (*shovePackedPixel)(totals,outIndex,dataOut);
     6556
     6557        outIndex++;
     6558        /* skip over to next group of 2 */
     6559        src+= pixelSizeInBytes + pixelSizeInBytes;
    65606560      }
    65616561
    65626562      {
    6563         int padBytes= rowSizeInBytes - (width*pixelSizeInBytes);
    6564          src+= padBytes;        /* for assertion only */
     6563        int padBytes= rowSizeInBytes - (width*pixelSizeInBytes);
     6564         src+= padBytes;        /* for assertion only */
    65656565      }
    65666566      assert(src == &((char *)dataIn)[rowSizeInBytes]);
     
    65706570      int outIndex= 0;
    65716571
    6572       assert(height != 1);      /* widthxheight can't be 1x1 */
     6572      assert(height != 1);      /* widthxheight can't be 1x1 */
    65736573      halfWidth= 1;
    65746574      /* one vertical column with possible pad bytes per row */
     
    65776577      for (jj= 0; jj< halfHeight; jj++) {
    65786578#define BOX2 2
    6579          float totals[4];       /* 4 is maximum components */
    6580         float extractTotals[BOX2][4]; /* 4 is maximum components */
    6581         int cc;
    6582 
    6583         /* average two at a time, instead of four */
    6584         (*extractPackedPixel)(isSwap,(void*)src,
    6585                                &extractTotals[0][0]);
    6586         (*extractPackedPixel)(isSwap,(void*)(src+rowSizeInBytes),
    6587                                &extractTotals[1][0]);                   
    6588         for (cc = 0; cc < components; cc++) {
    6589             int kk;
    6590 
    6591             /* grab 2 pixels to average */
    6592             totals[cc]= 0.0;
    6593             /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
    6594              * totals[RED]/= 2.0;
    6595              */
    6596             for (kk = 0; kk < BOX2; kk++) {
    6597                totals[cc]+= extractTotals[kk][cc];
    6598             }
    6599             totals[cc]/= (float)BOX2;
    6600         }
    6601         (*shovePackedPixel)(totals,outIndex,dataOut);
    6602 
    6603         outIndex++;
    6604         src+= rowSizeInBytes + rowSizeInBytes; /* go to row after next */
     6579         float totals[4];       /* 4 is maximum components */
     6580        float extractTotals[BOX2][4]; /* 4 is maximum components */
     6581        int cc;
     6582
     6583        /* average two at a time, instead of four */
     6584        (*extractPackedPixel)(isSwap,(void*)src,
     6585                               &extractTotals[0][0]);
     6586        (*extractPackedPixel)(isSwap,(void*)(src+rowSizeInBytes),
     6587                               &extractTotals[1][0]);
     6588        for (cc = 0; cc < components; cc++) {
     6589            int kk;
     6590
     6591            /* grab 2 pixels to average */
     6592            totals[cc]= 0.0;
     6593            /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
     6594             * totals[RED]/= 2.0;
     6595             */
     6596            for (kk = 0; kk < BOX2; kk++) {
     6597               totals[cc]+= extractTotals[kk][cc];
     6598            }
     6599            totals[cc]/= (float)BOX2;
     6600        }
     6601        (*shovePackedPixel)(totals,outIndex,dataOut);
     6602
     6603        outIndex++;
     6604        src+= rowSizeInBytes + rowSizeInBytes; /* go to row after next */
    66056605      }
    66066606
     
    66136613
    66146614static GLint imageSize3D(GLint width, GLint height, GLint depth,
    6615                         GLenum format, GLenum type)
     6615                        GLenum format, GLenum type)
    66166616{
    66176617    int components= elements_per_group(format,type);
     
    66256625
    66266626static void fillImage3D(const PixelStorageModes *psm,
    6627                         GLint width, GLint height, GLint depth, GLenum format,
    6628                         GLenum type, GLboolean indexFormat,
    6629                         const void *userImage, GLushort *newImage)
     6627                        GLint width, GLint height, GLint depth, GLenum format,
     6628                        GLenum type, GLboolean indexFormat,
     6629                        const void *userImage, GLushort *newImage)
    66306630{
    66316631   int myswapBytes;
     
    66836683
    66846684      for (hh= 0; hh < height; hh++) {
    6685         iter= rowStart;
    6686 
    6687         for (ww= 0; ww < elementsPerLine; ww++) {
    6688             Type_Widget widget;
    6689             float extractComponents[4];
    6690 
    6691             switch(type) {
    6692             case GL_UNSIGNED_BYTE:
    6693               if (indexFormat) {
    6694                   *iter2++ = *iter;
    6695               } else {
    6696                   *iter2++ = (*iter) * 257;
    6697               }
    6698               break;
    6699             case GL_BYTE:
    6700               if (indexFormat) {
    6701                   *iter2++ = *((GLbyte *) iter);
    6702               } else {
    6703                   /* rough approx */
    6704                   *iter2++ = (*((GLbyte *) iter)) * 516;
    6705               }
    6706               break;
    6707             case GL_UNSIGNED_BYTE_3_3_2:
    6708               extract332(0,(void *)iter,extractComponents);
    6709               for (k = 0; k < 3; k++) {
    6710                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6711               }
    6712               break;
    6713             case GL_UNSIGNED_BYTE_2_3_3_REV:
    6714               extract233rev(0,(void *)iter,extractComponents);
    6715               for (k = 0; k < 3; k++) {
    6716                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6717               }
    6718               break;
    6719             case GL_UNSIGNED_SHORT_5_6_5:                               
    6720               extract565(myswapBytes,(void *)iter,extractComponents);
    6721               for (k = 0; k < 3; k++) {
    6722                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6723               }
    6724               break;
    6725             case GL_UNSIGNED_SHORT_5_6_5_REV:                           
    6726               extract565rev(myswapBytes,(void *)iter,extractComponents);
    6727               for (k = 0; k < 3; k++) {
    6728                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6729               }
    6730               break;
    6731             case GL_UNSIGNED_SHORT_4_4_4_4:             
    6732               extract4444(myswapBytes,(void *)iter,extractComponents);
    6733               for (k = 0; k < 4; k++) {
    6734                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6735               }
    6736               break;
    6737             case GL_UNSIGNED_SHORT_4_4_4_4_REV:         
    6738               extract4444rev(myswapBytes,(void *)iter,extractComponents);
    6739               for (k = 0; k < 4; k++) {
    6740                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6741               }
    6742               break;
    6743             case GL_UNSIGNED_SHORT_5_5_5_1:             
    6744               extract5551(myswapBytes,(void *)iter,extractComponents);
    6745               for (k = 0; k < 4; k++) {
    6746                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6747               }
    6748               break;
    6749             case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    6750               extract1555rev(myswapBytes,(void *)iter,extractComponents);
    6751               for (k = 0; k < 4; k++) {
    6752                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6753               }
    6754               break;
    6755             case GL_UNSIGNED_SHORT:
    6756             case GL_SHORT:
    6757               if (myswapBytes) {
    6758                   widget.ub[0] = iter[1];
    6759                   widget.ub[1] = iter[0];
    6760               } else {
    6761                   widget.ub[0] = iter[0];
    6762                   widget.ub[1] = iter[1];
    6763               }
    6764               if (type == GL_SHORT) {
    6765                   if (indexFormat) {
    6766                       *iter2++ = widget.s[0];
    6767                   } else {
    6768                       /* rough approx */
    6769                       *iter2++ = widget.s[0]*2;
    6770                   }
    6771               } else {
    6772                   *iter2++ = widget.us[0];
    6773               }
    6774               break;
    6775             case GL_UNSIGNED_INT_8_8_8_8:               
    6776               extract8888(myswapBytes,(void *)iter,extractComponents);
    6777               for (k = 0; k < 4; k++) {
    6778                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6779               }
    6780               break;
    6781             case GL_UNSIGNED_INT_8_8_8_8_REV:           
    6782               extract8888rev(myswapBytes,(void *)iter,extractComponents);
    6783               for (k = 0; k < 4; k++) {
    6784                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6785               }
    6786               break;
    6787             case GL_UNSIGNED_INT_10_10_10_2:           
    6788               extract1010102(myswapBytes,(void *)iter,extractComponents);
    6789               for (k = 0; k < 4; k++) {
    6790                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6791               }
    6792               break;
    6793             case GL_UNSIGNED_INT_2_10_10_10_REV:
    6794               extract2101010rev(myswapBytes,(void *)iter,extractComponents);
    6795               for (k = 0; k < 4; k++) {
    6796                 *iter2++ = (GLushort)(extractComponents[k]*65535);
    6797               }
    6798               break;
    6799             case GL_INT:
    6800             case GL_UNSIGNED_INT:
    6801             case GL_FLOAT:
    6802               if (myswapBytes) {
    6803                   widget.ub[0] = iter[3];
    6804                   widget.ub[1] = iter[2];
    6805                   widget.ub[2] = iter[1];
    6806                   widget.ub[3] = iter[0];
    6807               } else {
    6808                   widget.ub[0] = iter[0];
    6809                   widget.ub[1] = iter[1];
    6810                   widget.ub[2] = iter[2];
    6811                   widget.ub[3] = iter[3];
    6812               }
    6813               if (type == GL_FLOAT) {
    6814                   if (indexFormat) {
    6815                       *iter2++ = widget.f;
    6816                   } else {
    6817                       *iter2++ = 65535 * widget.f;
    6818                   }
    6819               } else if (type == GL_UNSIGNED_INT) {
    6820                   if (indexFormat) {
    6821                       *iter2++ = widget.ui;
    6822                   } else {
    6823                       *iter2++ = widget.ui >> 16;
    6824                   }
    6825               } else {
    6826                   if (indexFormat) {
    6827                       *iter2++ = widget.i;
    6828                   } else {
    6829                       *iter2++ = widget.i >> 15;
    6830                   }
    6831               }
    6832               break;
     6685        iter= rowStart;
     6686
     6687        for (ww= 0; ww < elementsPerLine; ww++) {
     6688            Type_Widget widget;
     6689            float extractComponents[4];
     6690
     6691            switch(type) {
     6692            case GL_UNSIGNED_BYTE:
     6693              if (indexFormat) {
     6694                  *iter2++ = *iter;
     6695              } else {
     6696                  *iter2++ = (*iter) * 257;
     6697              }
     6698              break;
     6699            case GL_BYTE:
     6700              if (indexFormat) {
     6701                  *iter2++ = *((GLbyte *) iter);
     6702              } else {
     6703                  /* rough approx */
     6704                  *iter2++ = (*((GLbyte *) iter)) * 516;
     6705              }
     6706              break;
     6707            case GL_UNSIGNED_BYTE_3_3_2:
     6708              extract332(0,(void *)iter,extractComponents);
     6709              for (k = 0; k < 3; k++) {
     6710                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6711              }
     6712              break;
     6713            case GL_UNSIGNED_BYTE_2_3_3_REV:
     6714              extract233rev(0,(void *)iter,extractComponents);
     6715              for (k = 0; k < 3; k++) {
     6716                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6717              }
     6718              break;
     6719            case GL_UNSIGNED_SHORT_5_6_5:
     6720              extract565(myswapBytes,(void *)iter,extractComponents);
     6721              for (k = 0; k < 3; k++) {
     6722                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6723              }
     6724              break;
     6725            case GL_UNSIGNED_SHORT_5_6_5_REV:
     6726              extract565rev(myswapBytes,(void *)iter,extractComponents);
     6727              for (k = 0; k < 3; k++) {
     6728                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6729              }
     6730              break;
     6731            case GL_UNSIGNED_SHORT_4_4_4_4:
     6732              extract4444(myswapBytes,(void *)iter,extractComponents);
     6733              for (k = 0; k < 4; k++) {
     6734                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6735              }
     6736              break;
     6737            case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     6738              extract4444rev(myswapBytes,(void *)iter,extractComponents);
     6739              for (k = 0; k < 4; k++) {
     6740                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6741              }
     6742              break;
     6743            case GL_UNSIGNED_SHORT_5_5_5_1:
     6744              extract5551(myswapBytes,(void *)iter,extractComponents);
     6745              for (k = 0; k < 4; k++) {
     6746                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6747              }
     6748              break;
     6749            case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     6750              extract1555rev(myswapBytes,(void *)iter,extractComponents);
     6751              for (k = 0; k < 4; k++) {
     6752                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6753              }
     6754              break;
     6755            case GL_UNSIGNED_SHORT:
     6756            case GL_SHORT:
     6757              if (myswapBytes) {
     6758                  widget.ub[0] = iter[1];
     6759                  widget.ub[1] = iter[0];
     6760              } else {
     6761                  widget.ub[0] = iter[0];
     6762                  widget.ub[1] = iter[1];
     6763              }
     6764              if (type == GL_SHORT) {
     6765                  if (indexFormat) {
     6766                      *iter2++ = widget.s[0];
     6767                  } else {
     6768                      /* rough approx */
     6769                      *iter2++ = widget.s[0]*2;
     6770                  }
     6771              } else {
     6772                  *iter2++ = widget.us[0];
     6773              }
     6774              break;
     6775            case GL_UNSIGNED_INT_8_8_8_8:
     6776              extract8888(myswapBytes,(void *)iter,extractComponents);
     6777              for (k = 0; k < 4; k++) {
     6778                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6779              }
     6780              break;
     6781            case GL_UNSIGNED_INT_8_8_8_8_REV:
     6782              extract8888rev(myswapBytes,(void *)iter,extractComponents);
     6783              for (k = 0; k < 4; k++) {
     6784                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6785              }
     6786              break;
     6787            case GL_UNSIGNED_INT_10_10_10_2:
     6788              extract1010102(myswapBytes,(void *)iter,extractComponents);
     6789              for (k = 0; k < 4; k++) {
     6790                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6791              }
     6792              break;
     6793            case GL_UNSIGNED_INT_2_10_10_10_REV:
     6794              extract2101010rev(myswapBytes,(void *)iter,extractComponents);
     6795              for (k = 0; k < 4; k++) {
     6796                *iter2++ = (GLushort)(extractComponents[k]*65535);
     6797              }
     6798              break;
     6799            case GL_INT:
     6800            case GL_UNSIGNED_INT:
     6801            case GL_FLOAT:
     6802              if (myswapBytes) {
     6803                  widget.ub[0] = iter[3];
     6804                  widget.ub[1] = iter[2];
     6805                  widget.ub[2] = iter[1];
     6806                  widget.ub[3] = iter[0];
     6807              } else {
     6808                  widget.ub[0] = iter[0];
     6809                  widget.ub[1] = iter[1];
     6810                  widget.ub[2] = iter[2];
     6811                  widget.ub[3] = iter[3];
     6812              }
     6813              if (type == GL_FLOAT) {
     6814                  if (indexFormat) {
     6815                      *iter2++ = widget.f;
     6816                  } else {
     6817                      *iter2++ = 65535 * widget.f;
     6818                  }
     6819              } else if (type == GL_UNSIGNED_INT) {
     6820                  if (indexFormat) {
     6821                      *iter2++ = widget.ui;
     6822                  } else {
     6823                      *iter2++ = widget.ui >> 16;
     6824                  }
     6825              } else {
     6826                  if (indexFormat) {
     6827                      *iter2++ = widget.i;
     6828                  } else {
     6829                      *iter2++ = widget.i >> 15;
     6830                  }
     6831              }
     6832              break;
    68336833            default:
    6834               assert(0);
    6835             }
    6836 
    6837             iter+= elementSize;
    6838         } /* for ww */
    6839         rowStart+= rowSize;
    6840 
    6841          iter= rowStart;        /* for assertion purposes */
     6834              assert(0);
     6835            }
     6836
     6837            iter+= elementSize;
     6838        } /* for ww */
     6839        rowStart+= rowSize;
     6840
     6841         iter= rowStart;        /* for assertion purposes */
    68426842      } /* for hh */
    68436843
     
    68516851   else {
    68526852      assert(iter2 == &newImage[width*height*depth*
    6853                                 elements_per_group(format,NULL)]);
     6853                                elements_per_group(format,NULL)]);
    68546854   }
    68556855   assert( iter == &((GLubyte *)userImage)[rowSize*height*depth] );
     
    68576857
    68586858static void scaleInternal3D(GLint components,
    6859                             GLint widthIn, GLint heightIn, GLint depthIn,
    6860                             const GLushort *dataIn,
    6861                             GLint widthOut, GLint heightOut, GLint depthOut,
    6862                             GLushort *dataOut)
     6859                            GLint widthIn, GLint heightIn, GLint depthIn,
     6860                            const GLushort *dataIn,
     6861                            GLint widthOut, GLint heightOut, GLint depthOut,
     6862                            GLushort *dataOut)
    68636863{
    68646864    float x, lowx, highx, convx, halfconvx;
     
    68826882       z = convz * (d+0.5);
    68836883       if (depthIn > depthOut) {
    6884            highz = z + halfconvz;
    6885            lowz = z - halfconvz;
     6884           highz = z + halfconvz;
     6885           lowz = z - halfconvz;
    68866886       } else {
    6887            highz = z + 0.5;
    6888            lowz = z - 0.5;
     6887           highz = z + 0.5;
     6888           lowz = z - 0.5;
    68896889       }
    68906890       for (i = 0; i < heightOut; i++) {
    6891            y = convy * (i+0.5);
    6892            if (heightIn > heightOut) {
    6893                highy = y + halfconvy;
    6894                lowy = y - halfconvy;
    6895            } else {
    6896                highy = y + 0.5;
    6897                lowy = y - 0.5;
    6898            }
    6899            for (j = 0; j < widthOut; j++) {
    6900                x = convx * (j+0.5);
    6901                if (widthIn > widthOut) {
    6902                    highx = x + halfconvx;
    6903                    lowx = x - halfconvx;
    6904                } else {
    6905                    highx = x + 0.5;
    6906                    lowx = x - 0.5;
    6907                }
    6908 
    6909                /*
    6910                ** Ok, now apply box filter to box that goes from (lowx, lowy,
    6911                ** lowz) to (highx, highy, highz) on input data into this pixel
    6912                ** on output data.
    6913                */
    6914                totals[0] = totals[1] = totals[2] = totals[3] = 0.0;
    6915                volume = 0.0;
    6916 
    6917                z = lowz;
    6918                zint = floor(z);
    6919                while (z < highz) {
    6920                   zindex = (zint + depthIn) % depthIn;
    6921                   if (highz < zint+1) {
    6922                       zpercent = highz - z;
    6923                   } else {
    6924                       zpercent = zint+1 - z;
    6925                   }
    6926 
    6927                   y = lowy;
    6928                   yint = floor(y);
    6929                   while (y < highy) {
    6930                       yindex = (yint + heightIn) % heightIn;
    6931                       if (highy < yint+1) {
    6932                           ypercent = highy - y;
    6933                       } else {
    6934                           ypercent = yint+1 - y;
    6935                       }
    6936 
    6937                       x = lowx;
    6938                       xint = floor(x);
    6939 
    6940                       while (x < highx) {
    6941                           xindex = (xint + widthIn) % widthIn;
    6942                           if (highx < xint+1) {
    6943                               xpercent = highx - x;
    6944                           } else {
    6945                               xpercent = xint+1 - x;
    6946                           }
    6947 
    6948                           percent = xpercent * ypercent * zpercent;
    6949                           volume += percent;
    6950 
    6951                           temp = (xindex + (yindex*widthIn) +
    6952                                   (zindex*widthIn*heightIn)) * components;
    6953                           for (k = 0; k < components; k++) {
    6954                               assert(0 <= (temp+k) &&
    6955                                      (temp+k) <
    6956                                      (widthIn*heightIn*depthIn*components));
    6957                               totals[k] += dataIn[temp + k] * percent;
    6958                           }
    6959 
    6960                           xint++;
    6961                           x = xint;
    6962                       } /* while x */
    6963 
    6964                       yint++;
    6965                       y = yint;
    6966                   } /* while y */
    6967 
    6968                   zint++;
    6969                   z = zint;
    6970                } /* while z */
    6971 
    6972                temp = (j + (i * widthOut) +
    6973                        (d*widthOut*heightOut)) * components;
    6974                for (k = 0; k < components; k++) {
    6975                    /* totals[] should be rounded in the case of enlarging an
    6976                     * RGB ramp when the type is 332 or 4444
    6977                     */
    6978                    assert(0 <= (temp+k) &&
    6979                           (temp+k) < (widthOut*heightOut*depthOut*components));
    6980                    dataOut[temp + k] = (totals[k]+0.5)/volume;
    6981                }
    6982            } /* for j */
     6891           y = convy * (i+0.5);
     6892           if (heightIn > heightOut) {
     6893               highy = y + halfconvy;
     6894               lowy = y - halfconvy;
     6895           } else {
     6896               highy = y + 0.5;
     6897               lowy = y - 0.5;
     6898           }
     6899           for (j = 0; j < widthOut; j++) {
     6900               x = convx * (j+0.5);
     6901               if (widthIn > widthOut) {
     6902                   highx = x + halfconvx;
     6903                   lowx = x - halfconvx;
     6904               } else {
     6905                   highx = x + 0.5;
     6906                   lowx = x - 0.5;
     6907               }
     6908
     6909               /*
     6910               ** Ok, now apply box filter to box that goes from (lowx, lowy,
     6911               ** lowz) to (highx, highy, highz) on input data into this pixel
     6912               ** on output data.
     6913               */
     6914               totals[0] = totals[1] = totals[2] = totals[3] = 0.0;
     6915               volume = 0.0;
     6916
     6917               z = lowz;
     6918               zint = floor(z);
     6919               while (z < highz) {
     6920                  zindex = (zint + depthIn) % depthIn;
     6921                  if (highz < zint+1) {
     6922                      zpercent = highz - z;
     6923                  } else {
     6924                      zpercent = zint+1 - z;
     6925                  }
     6926
     6927                  y = lowy;
     6928                  yint = floor(y);
     6929                  while (y < highy) {
     6930                      yindex = (yint + heightIn) % heightIn;
     6931                      if (highy < yint+1) {
     6932                          ypercent = highy - y;
     6933                      } else {
     6934                          ypercent = yint+1 - y;
     6935                      }
     6936
     6937                      x = lowx;
     6938                      xint = floor(x);
     6939
     6940                      while (x < highx) {
     6941                          xindex = (xint + widthIn) % widthIn;
     6942                          if (highx < xint+1) {
     6943                              xpercent = highx - x;
     6944                          } else {
     6945                              xpercent = xint+1 - x;
     6946                          }
     6947
     6948                          percent = xpercent * ypercent * zpercent;
     6949                          volume += percent;
     6950
     6951                          temp = (xindex + (yindex*widthIn) +
     6952                                  (zindex*widthIn*heightIn)) * components;
     6953                          for (k = 0; k < components; k++) {
     6954                              assert(0 <= (temp+k) &&
     6955                                     (temp+k) <
     6956                                     (widthIn*heightIn*depthIn*components));
     6957                              totals[k] += dataIn[temp + k] * percent;
     6958                          }
     6959
     6960                          xint++;
     6961                          x = xint;
     6962                      } /* while x */
     6963
     6964                      yint++;
     6965                      y = yint;
     6966                  } /* while y */
     6967
     6968                  zint++;
     6969                  z = zint;
     6970               } /* while z */
     6971
     6972               temp = (j + (i * widthOut) +
     6973                       (d*widthOut*heightOut)) * components;
     6974               for (k = 0; k < components; k++) {
     6975                   /* totals[] should be rounded in the case of enlarging an
     6976                    * RGB ramp when the type is 332 or 4444
     6977                    */
     6978                   assert(0 <= (temp+k) &&
     6979                          (temp+k) < (widthOut*heightOut*depthOut*components));
     6980                   dataOut[temp + k] = (totals[k]+0.5)/volume;
     6981               }
     6982           } /* for j */
    69836983       } /* for i */
    69846984    } /* for d */
     
    69866986
    69876987static void emptyImage3D(const PixelStorageModes *psm,
    6988                         GLint width, GLint height, GLint depth,
    6989                         GLenum format, GLenum type, GLboolean indexFormat,
    6990                         const GLushort *oldImage, void *userImage)
     6988                        GLint width, GLint height, GLint depth,
     6989                        GLenum format, GLenum type, GLboolean indexFormat,
     6990                        const GLushort *oldImage, void *userImage)
    69916991{
    69926992   int myswapBytes;
     
    70467046
    70477047      for (ii= 0; ii< height; ii++) {
    7048         iter = rowStart;
    7049 
    7050         for (jj = 0; jj < elementsPerLine; jj++) {
    7051             Type_Widget widget;
    7052             float shoveComponents[4];
    7053 
    7054             switch(type){
    7055             case GL_UNSIGNED_BYTE:
    7056               if (indexFormat) {
    7057                   *iter = *iter2++;
    7058               } else {
    7059                   *iter = *iter2++ >> 8;
    7060               }
    7061               break;
    7062             case GL_BYTE:
    7063               if (indexFormat) {
    7064                   *((GLbyte *) iter) = *iter2++;
    7065               } else {
    7066                   *((GLbyte *) iter) = *iter2++ >> 9;
    7067               }
    7068               break;
    7069             case GL_UNSIGNED_BYTE_3_3_2:
    7070               for (k = 0; k < 3; k++) {
    7071                 shoveComponents[k]= *iter2++ / 65535.0;
    7072               }
    7073               shove332(shoveComponents,0,(void *)iter);
    7074               break;
    7075             case GL_UNSIGNED_BYTE_2_3_3_REV:
    7076               for (k = 0; k < 3; k++) {
    7077                 shoveComponents[k]= *iter2++ / 65535.0;
    7078               }
    7079               shove233rev(shoveComponents,0,(void *)iter);
    7080               break;
    7081             case GL_UNSIGNED_SHORT_5_6_5:               
    7082               for (k = 0; k < 3; k++) {
    7083                 shoveComponents[k]= *iter2++ / 65535.0;
    7084               }
    7085               shove565(shoveComponents,0,(void *)&widget.us[0]);
    7086               if (myswapBytes) {
    7087                 iter[0] = widget.ub[1];
    7088                 iter[1] = widget.ub[0];
    7089               }
    7090               else {
    7091                 *(GLushort *)iter = widget.us[0];
    7092               }
    7093               break;
    7094             case GL_UNSIGNED_SHORT_5_6_5_REV:           
    7095               for (k = 0; k < 3; k++) {
    7096                 shoveComponents[k]= *iter2++ / 65535.0;
    7097               }
    7098               shove565rev(shoveComponents,0,(void *)&widget.us[0]);
    7099               if (myswapBytes) {
    7100                 iter[0] = widget.ub[1];
    7101                 iter[1] = widget.ub[0];
    7102               }
    7103               else {
    7104                 *(GLushort *)iter = widget.us[0];
    7105               }
    7106               break;
    7107             case GL_UNSIGNED_SHORT_4_4_4_4:
    7108               for (k = 0; k < 4; k++) {
    7109                 shoveComponents[k]= *iter2++ / 65535.0;
    7110               }
    7111               shove4444(shoveComponents,0,(void *)&widget.us[0]);
    7112               if (myswapBytes) {
    7113                 iter[0] = widget.ub[1];
    7114                 iter[1] = widget.ub[0];
    7115               } else {
    7116                 *(GLushort *)iter = widget.us[0];
    7117               }
    7118               break;
    7119             case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    7120               for (k = 0; k < 4; k++) {
    7121                 shoveComponents[k]= *iter2++ / 65535.0;
    7122               }
    7123               shove4444rev(shoveComponents,0,(void *)&widget.us[0]);
    7124               if (myswapBytes) {
    7125                 iter[0] = widget.ub[1];
    7126                 iter[1] = widget.ub[0];
    7127               } else {
    7128                 *(GLushort *)iter = widget.us[0];
    7129               }
    7130               break;
    7131             case GL_UNSIGNED_SHORT_5_5_5_1:
    7132               for (k = 0; k < 4; k++) {
    7133                 shoveComponents[k]= *iter2++ / 65535.0;
    7134               }
    7135               shove5551(shoveComponents,0,(void *)&widget.us[0]);
    7136               if (myswapBytes) {
    7137                 iter[0] = widget.ub[1];
    7138                 iter[1] = widget.ub[0];
    7139               } else {
    7140                 *(GLushort *)iter = widget.us[0];
    7141               }
    7142               break;
    7143             case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    7144               for (k = 0; k < 4; k++) {
    7145                 shoveComponents[k]= *iter2++ / 65535.0;
    7146               }
    7147               shove1555rev(shoveComponents,0,(void *)&widget.us[0]);
    7148               if (myswapBytes) {
    7149                 iter[0] = widget.ub[1];
    7150                 iter[1] = widget.ub[0];
    7151               } else {
    7152                 *(GLushort *)iter = widget.us[0];
    7153               }
    7154               break;
    7155             case GL_UNSIGNED_SHORT:
    7156             case GL_SHORT:
    7157               if (type == GL_SHORT) {
    7158                   if (indexFormat) {
    7159                       widget.s[0] = *iter2++;
    7160                   } else {
    7161                       widget.s[0] = *iter2++ >> 1;
    7162                   }
    7163               } else {
    7164                   widget.us[0] = *iter2++;
    7165               }
    7166               if (myswapBytes) {
    7167                   iter[0] = widget.ub[1];
    7168                   iter[1] = widget.ub[0];
    7169               } else {
    7170                   iter[0] = widget.ub[0];
    7171                   iter[1] = widget.ub[1];
    7172               }
    7173               break;
    7174             case GL_UNSIGNED_INT_8_8_8_8:
    7175                for (k = 0; k < 4; k++) {
    7176                   shoveComponents[k]= *iter2++ / 65535.0;
    7177                }
    7178                shove8888(shoveComponents,0,(void *)&widget.ui);
    7179                if (myswapBytes) {
    7180                    iter[3] = widget.ub[0];
    7181                    iter[2] = widget.ub[1];
    7182                    iter[1] = widget.ub[2];
    7183                    iter[0] = widget.ub[3];
    7184                } else {
    7185                    *(GLuint *)iter= widget.ui;
    7186                }
    7187                break;
    7188             case GL_UNSIGNED_INT_8_8_8_8_REV:
    7189                for (k = 0; k < 4; k++) {
    7190                   shoveComponents[k]= *iter2++ / 65535.0;
    7191                }
    7192                shove8888rev(shoveComponents,0,(void *)&widget.ui);
    7193                if (myswapBytes) {
    7194                    iter[3] = widget.ub[0];
    7195                    iter[2] = widget.ub[1];
    7196                    iter[1] = widget.ub[2];
    7197                    iter[0] = widget.ub[3];
    7198                } else {
    7199                    *(GLuint *)iter= widget.ui;
    7200                }
    7201                break;
    7202             case GL_UNSIGNED_INT_10_10_10_2:
    7203                for (k = 0; k < 4; k++) {
    7204                   shoveComponents[k]= *iter2++ / 65535.0;
    7205                }
    7206                shove1010102(shoveComponents,0,(void *)&widget.ui);
    7207                if (myswapBytes) {
    7208                    iter[3] = widget.ub[0];
    7209                    iter[2] = widget.ub[1];
    7210                    iter[1] = widget.ub[2];
    7211                    iter[0] = widget.ub[3];
    7212                } else {
    7213                    *(GLuint *)iter= widget.ui;
    7214                }
    7215                break;
    7216             case GL_UNSIGNED_INT_2_10_10_10_REV:
    7217                for (k = 0; k < 4; k++) {
    7218                   shoveComponents[k]= *iter2++ / 65535.0;
    7219                }
    7220                shove2101010rev(shoveComponents,0,(void *)&widget.ui);
    7221                if (myswapBytes) {
    7222                    iter[3] = widget.ub[0];
    7223                    iter[2] = widget.ub[1];
    7224                    iter[1] = widget.ub[2];
    7225                    iter[0] = widget.ub[3];
    7226                } else {
    7227                    *(GLuint *)iter= widget.ui;
    7228                }
    7229                break;
    7230             case GL_INT:
    7231             case GL_UNSIGNED_INT:
    7232             case GL_FLOAT:
    7233               if (type == GL_FLOAT) {
    7234                   if (indexFormat) {
    7235                       widget.f = *iter2++;
    7236                   } else {
    7237                       widget.f = *iter2++ / (float) 65535.0;
    7238                   }
    7239               } else if (type == GL_UNSIGNED_INT) {
    7240                   if (indexFormat) {
    7241                       widget.ui = *iter2++;
    7242                   } else {
    7243                       widget.ui = (unsigned int) *iter2++ * 65537;
    7244                   }
    7245               } else {
    7246                   if (indexFormat) {
    7247                       widget.i = *iter2++;
    7248                   } else {
    7249                       widget.i = ((unsigned int) *iter2++ * 65537)/2;
    7250                   }
    7251               }
    7252               if (myswapBytes) {
    7253                   iter[3] = widget.ub[0];
    7254                   iter[2] = widget.ub[1];
    7255                   iter[1] = widget.ub[2];
    7256                   iter[0] = widget.ub[3];
    7257               } else {
    7258                   iter[0] = widget.ub[0];
    7259                   iter[1] = widget.ub[1];
    7260                   iter[2] = widget.ub[2];
    7261                   iter[3] = widget.ub[3];
    7262               }
    7263               break;
    7264             default:
    7265                assert(0);
    7266             }
    7267 
    7268             iter+= elementSize;
    7269         }  /* for jj */
    7270 
    7271         rowStart+= rowSize;
     7048        iter = rowStart;
     7049
     7050        for (jj = 0; jj < elementsPerLine; jj++) {
     7051            Type_Widget widget;
     7052            float shoveComponents[4];
     7053
     7054            switch(type){
     7055            case GL_UNSIGNED_BYTE:
     7056              if (indexFormat) {
     7057                  *iter = *iter2++;
     7058              } else {
     7059                  *iter = *iter2++ >> 8;
     7060              }
     7061              break;
     7062            case GL_BYTE:
     7063              if (indexFormat) {
     7064                  *((GLbyte *) iter) = *iter2++;
     7065              } else {
     7066                  *((GLbyte *) iter) = *iter2++ >> 9;
     7067              }
     7068              break;
     7069            case GL_UNSIGNED_BYTE_3_3_2:
     7070              for (k = 0; k < 3; k++) {
     7071                shoveComponents[k]= *iter2++ / 65535.0;
     7072              }
     7073              shove332(shoveComponents,0,(void *)iter);
     7074              break;
     7075            case GL_UNSIGNED_BYTE_2_3_3_REV:
     7076              for (k = 0; k < 3; k++) {
     7077                shoveComponents[k]= *iter2++ / 65535.0;
     7078              }
     7079              shove233rev(shoveComponents,0,(void *)iter);
     7080              break;
     7081            case GL_UNSIGNED_SHORT_5_6_5:
     7082              for (k = 0; k < 3; k++) {
     7083                shoveComponents[k]= *iter2++ / 65535.0;
     7084              }
     7085              shove565(shoveComponents,0,(void *)&widget.us[0]);
     7086              if (myswapBytes) {
     7087                iter[0] = widget.ub[1];
     7088                iter[1] = widget.ub[0];
     7089              }
     7090              else {
     7091                *(GLushort *)iter = widget.us[0];
     7092              }
     7093              break;
     7094            case GL_UNSIGNED_SHORT_5_6_5_REV:
     7095              for (k = 0; k < 3; k++) {
     7096                shoveComponents[k]= *iter2++ / 65535.0;
     7097              }
     7098              shove565rev(shoveComponents,0,(void *)&widget.us[0]);
     7099              if (myswapBytes) {
     7100                iter[0] = widget.ub[1];
     7101                iter[1] = widget.ub[0];
     7102              }
     7103              else {
     7104                *(GLushort *)iter = widget.us[0];
     7105              }
     7106              break;
     7107            case GL_UNSIGNED_SHORT_4_4_4_4:
     7108              for (k = 0; k < 4; k++) {
     7109                shoveComponents[k]= *iter2++ / 65535.0;
     7110              }
     7111              shove4444(shoveComponents,0,(void *)&widget.us[0]);
     7112              if (myswapBytes) {
     7113                iter[0] = widget.ub[1];
     7114                iter[1] = widget.ub[0];
     7115              } else {
     7116                *(GLushort *)iter = widget.us[0];
     7117              }
     7118              break;
     7119            case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     7120              for (k = 0; k < 4; k++) {
     7121                shoveComponents[k]= *iter2++ / 65535.0;
     7122              }
     7123              shove4444rev(shoveComponents,0,(void *)&widget.us[0]);
     7124              if (myswapBytes) {
     7125                iter[0] = widget.ub[1];
     7126                iter[1] = widget.ub[0];
     7127              } else {
     7128                *(GLushort *)iter = widget.us[0];
     7129              }
     7130              break;
     7131            case GL_UNSIGNED_SHORT_5_5_5_1:
     7132              for (k = 0; k < 4; k++) {
     7133                shoveComponents[k]= *iter2++ / 65535.0;
     7134              }
     7135              shove5551(shoveComponents,0,(void *)&widget.us[0]);
     7136              if (myswapBytes) {
     7137                iter[0] = widget.ub[1];
     7138                iter[1] = widget.ub[0];
     7139              } else {
     7140                *(GLushort *)iter = widget.us[0];
     7141              }
     7142              break;
     7143            case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     7144              for (k = 0; k < 4; k++) {
     7145                shoveComponents[k]= *iter2++ / 65535.0;
     7146              }
     7147              shove1555rev(shoveComponents,0,(void *)&widget.us[0]);
     7148              if (myswapBytes) {
     7149                iter[0] = widget.ub[1];
     7150                iter[1] = widget.ub[0];
     7151              } else {
     7152                *(GLushort *)iter = widget.us[0];
     7153              }
     7154              break;
     7155            case GL_UNSIGNED_SHORT:
     7156            case GL_SHORT:
     7157              if (type == GL_SHORT) {
     7158                  if (indexFormat) {
     7159                      widget.s[0] = *iter2++;
     7160                  } else {
     7161                      widget.s[0] = *iter2++ >> 1;
     7162                  }
     7163              } else {
     7164                  widget.us[0] = *iter2++;
     7165              }
     7166              if (myswapBytes) {
     7167                  iter[0] = widget.ub[1];
     7168                  iter[1] = widget.ub[0];
     7169              } else {
     7170                  iter[0] = widget.ub[0];
     7171                  iter[1] = widget.ub[1];
     7172              }
     7173              break;
     7174            case GL_UNSIGNED_INT_8_8_8_8:
     7175               for (k = 0; k < 4; k++) {
     7176                  shoveComponents[k]= *iter2++ / 65535.0;
     7177               }
     7178               shove8888(shoveComponents,0,(void *)&widget.ui);
     7179               if (myswapBytes) {
     7180                   iter[3] = widget.ub[0];
     7181                   iter[2] = widget.ub[1];
     7182                   iter[1] = widget.ub[2];
     7183                   iter[0] = widget.ub[3];
     7184               } else {
     7185                   *(GLuint *)iter= widget.ui;
     7186               }
     7187               break;
     7188            case GL_UNSIGNED_INT_8_8_8_8_REV:
     7189               for (k = 0; k < 4; k++) {
     7190                  shoveComponents[k]= *iter2++ / 65535.0;
     7191               }
     7192               shove8888rev(shoveComponents,0,(void *)&widget.ui);
     7193               if (myswapBytes) {
     7194                   iter[3] = widget.ub[0];
     7195                   iter[2] = widget.ub[1];
     7196                   iter[1] = widget.ub[2];
     7197                   iter[0] = widget.ub[3];
     7198               } else {
     7199                   *(GLuint *)iter= widget.ui;
     7200               }
     7201               break;
     7202            case GL_UNSIGNED_INT_10_10_10_2:
     7203               for (k = 0; k < 4; k++) {
     7204                  shoveComponents[k]= *iter2++ / 65535.0;
     7205               }
     7206               shove1010102(shoveComponents,0,(void *)&widget.ui);
     7207               if (myswapBytes) {
     7208                   iter[3] = widget.ub[0];
     7209                   iter[2] = widget.ub[1];
     7210                   iter[1] = widget.ub[2];
     7211                   iter[0] = widget.ub[3];
     7212               } else {
     7213                   *(GLuint *)iter= widget.ui;
     7214               }
     7215               break;
     7216            case GL_UNSIGNED_INT_2_10_10_10_REV:
     7217               for (k = 0; k < 4; k++) {
     7218                  shoveComponents[k]= *iter2++ / 65535.0;
     7219               }
     7220               shove2101010rev(shoveComponents,0,(void *)&widget.ui);
     7221               if (myswapBytes) {
     7222                   iter[3] = widget.ub[0];
     7223                   iter[2] = widget.ub[1];
     7224                   iter[1] = widget.ub[2];
     7225                   iter[0] = widget.ub[3];
     7226               } else {
     7227                   *(GLuint *)iter= widget.ui;
     7228               }
     7229               break;
     7230            case GL_INT:
     7231            case GL_UNSIGNED_INT:
     7232            case GL_FLOAT:
     7233              if (type == GL_FLOAT) {
     7234                  if (indexFormat) {
     7235                      widget.f = *iter2++;
     7236                  } else {
     7237                      widget.f = *iter2++ / (float) 65535.0;
     7238                  }
     7239              } else if (type == GL_UNSIGNED_INT) {
     7240                  if (indexFormat) {
     7241                      widget.ui = *iter2++;
     7242                  } else {
     7243                      widget.ui = (unsigned int) *iter2++ * 65537;
     7244                  }
     7245              } else {
     7246                  if (indexFormat) {
     7247                      widget.i = *iter2++;
     7248                  } else {
     7249                      widget.i = ((unsigned int) *iter2++ * 65537)/2;
     7250                  }
     7251              }
     7252              if (myswapBytes) {
     7253                  iter[3] = widget.ub[0];
     7254                  iter[2] = widget.ub[1];
     7255                  iter[1] = widget.ub[2];
     7256                  iter[0] = widget.ub[3];
     7257              } else {
     7258                  iter[0] = widget.ub[0];
     7259                  iter[1] = widget.ub[1];
     7260                  iter[2] = widget.ub[2];
     7261                  iter[3] = widget.ub[3];
     7262              }
     7263              break;
     7264            default:
     7265               assert(0);
     7266            }
     7267
     7268            iter+= elementSize;
     7269        }  /* for jj */
     7270
     7271        rowStart+= rowSize;
    72727272      } /* for ii */
    72737273
     
    72817281   else {
    72827282      assert(iter2 == &oldImage[width*height*depth*
    7283                                 elements_per_group(format,NULL)]);
     7283                                elements_per_group(format,NULL)]);
    72847284   }
    72857285   assert( iter == &((GLubyte *)userImage)[rowSize*height*depth] );
     
    72877287
    72887288int gluScaleImage3D(GLenum format,
    7289                     GLint widthIn, GLint heightIn, GLint depthIn,
    7290                     GLenum typeIn, const void *dataIn,
    7291                     GLint widthOut, GLint heightOut, GLint depthOut,
    7292                     GLenum typeOut, void *dataOut)
     7289                    GLint widthIn, GLint heightIn, GLint depthIn,
     7290                    GLenum typeIn, const void *dataIn,
     7291                    GLint widthOut, GLint heightOut, GLint depthOut,
     7292                    GLenum typeOut, void *dataOut)
    72937293{
    72947294   int components;
     
    73307330   components = elements_per_group(format,NULL);
    73317331   scaleInternal3D(components,widthIn,heightIn,depthIn,beforeImage,
    7332                    widthOut,heightOut,depthOut,afterImage);
     7332                   widthOut,heightOut,depthOut,afterImage);
    73337333   emptyImage3D(&psm,widthOut,heightOut,depthOut,format,typeOut,
    7334                 is_index(format),afterImage, dataOut);
     7334                is_index(format),afterImage, dataOut);
    73357335   free((void *) beforeImage);
    73367336   free((void *) afterImage);
     
    73407340
    73417341static void closestFit3D(GLenum target, GLint width, GLint height, GLint depth,
    7342                         GLint internalFormat, GLenum format, GLenum type,
    7343                         GLint *newWidth, GLint *newHeight, GLint *newDepth)
     7342                        GLint internalFormat, GLenum format, GLenum type,
     7343                        GLint *newWidth, GLint *newHeight, GLint *newDepth)
    73447344{
    73457345   GLint widthPowerOf2= nearestPower(width);
    7346    GLint heightPowerOf2= nearestPower(height);         
     7346   GLint heightPowerOf2= nearestPower(height);
    73477347   GLint depthPowerOf2= nearestPower(depth);
    73487348   GLint proxyWidth;
     
    73517351      /* compute level 1 width & height & depth, clamping each at 1 */
    73527352      GLint widthAtLevelOne= (widthPowerOf2 > 1) ?
    7353                               widthPowerOf2 >> 1 :
    7354                               widthPowerOf2;
     7353                              widthPowerOf2 >> 1 :
     7354                              widthPowerOf2;
    73557355      GLint heightAtLevelOne= (heightPowerOf2 > 1) ?
    7356                                heightPowerOf2 >> 1 :
    7357                                heightPowerOf2;
     7356                               heightPowerOf2 >> 1 :
     7357                               heightPowerOf2;
    73587358      GLint depthAtLevelOne= (depthPowerOf2 > 1) ?
    7359                               depthPowerOf2 >> 1 :
    7360                               depthPowerOf2;
     7359                              depthPowerOf2 >> 1 :
     7360                              depthPowerOf2;
    73617361      GLenum proxyTarget;
    73627362      assert(widthAtLevelOne > 0);
     
    73667366      /* does width x height x depth at level 1 & all their mipmaps fit? */
    73677367      if (target == GL_TEXTURE_3D || target == GL_PROXY_TEXTURE_3D) {
    7368         proxyTarget = GL_PROXY_TEXTURE_3D;
    7369          glTexImage3D(proxyTarget, 1, /* must be non-zero */
    7370                       internalFormat,
    7371                       widthAtLevelOne,heightAtLevelOne,depthAtLevelOne,
    7372                       0,format,type,NULL);
     7368        proxyTarget = GL_PROXY_TEXTURE_3D;
     7369         glTexImage3DEXT(proxyTarget, 1,                /* must be non-zero*/
     7370                         internalFormat,
     7371                         widthAtLevelOne,heightAtLevelOne,depthAtLevelOne,
     7372                         0,format,type,NULL);
    73737373      }
    73747374      glGetTexLevelParameteriv(proxyTarget, 1,GL_TEXTURE_WIDTH,&proxyWidth);
    73757375      /* does it fit??? */
    73767376      if (proxyWidth == 0) { /* nope, so try again with these sizes */
    7377         if (widthPowerOf2 == 1 && heightPowerOf2 == 1 &&
    7378              depthPowerOf2 == 1) {
    7379             *newWidth= *newHeight= *newDepth= 1; /* must fit 1x1x1 texture */
    7380             return;
    7381         }
    7382         widthPowerOf2= widthAtLevelOne;
    7383         heightPowerOf2= heightAtLevelOne;
    7384         depthPowerOf2= depthAtLevelOne;
     7377        if (widthPowerOf2 == 1 && heightPowerOf2 == 1 &&
     7378             depthPowerOf2 == 1) {
     7379            *newWidth= *newHeight= *newDepth= 1; /* must fit 1x1x1 texture */
     7380            return;
     7381        }
     7382        widthPowerOf2= widthAtLevelOne;
     7383        heightPowerOf2= heightAtLevelOne;
     7384        depthPowerOf2= depthAtLevelOne;
    73857385      }
    73867386      /* else it does fit */
     
    73967396
    73977397static void halveImagePackedPixelSlice(int components,
    7398                                        void (*extractPackedPixel)
    7399                                        (int, const void *,GLfloat []),
    7400                                        void (*shovePackedPixel)
    7401                                        (const GLfloat [],int, void *),
    7402                                        GLint width, GLint height, GLint depth,
    7403                                        const void *dataIn, void *dataOut,
    7404                                        GLint pixelSizeInBytes,
    7405                                        GLint rowSizeInBytes,
    7406                                        GLint imageSizeInBytes,
    7407                                        GLint isSwap)
     7398                                       void (*extractPackedPixel)
     7399                                       (int, const void *,GLfloat []),
     7400                                       void (*shovePackedPixel)
     7401                                       (const GLfloat [],int, void *),
     7402                                       GLint width, GLint height, GLint depth,
     7403                                       const void *dataIn, void *dataOut,
     7404                                       GLint pixelSizeInBytes,
     7405                                       GLint rowSizeInBytes,
     7406                                       GLint imageSizeInBytes,
     7407                                       GLint isSwap)
    74087408{
    74097409   int ii, jj;
     
    74177417   assert((width == 1 || height == 1) && depth >= 2);
    74187418
    7419    if (width == height) {       /* a 1-pixel column viewed from top */
     7419   if (width == height) {       /* a 1-pixel column viewed from top */
    74207420      assert(width == 1 && height == 1);
    74217421      assert(depth >= 2);
    74227422
    74237423      for (ii= 0; ii< halfDepth; ii++) {
    7424         float totals[4];
    7425         float extractTotals[BOX2][4];
    7426         int cc;
    7427 
    7428         (*extractPackedPixel)(isSwap,(void *)src,&extractTotals[0][0]);
    7429         (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
    7430                                &extractTotals[1][0]);
    7431         for (cc = 0; cc < components; cc++) {
    7432             int kk;
    7433 
    7434             /* average 2 pixels since only a column */
    7435             totals[cc]= 0.0;
    7436             /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
    7437              * totals[RED]/= 2.0;
    7438              */
    7439             for (kk = 0; kk < BOX2; kk++) {
    7440               totals[cc]+= extractTotals[kk][cc];
    7441             }
    7442             totals[cc]/= (float)BOX2;
    7443         } /* for cc */
    7444        
    7445         (*shovePackedPixel)(totals,outIndex,dataOut);
    7446         outIndex++;
    7447         /* skip over to next group of 2 */
    7448         src+= imageSizeInBytes + imageSizeInBytes;
     7424        float totals[4];
     7425        float extractTotals[BOX2][4];
     7426        int cc;
     7427
     7428        (*extractPackedPixel)(isSwap,(void *)src,&extractTotals[0][0]);
     7429        (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
     7430                               &extractTotals[1][0]);
     7431        for (cc = 0; cc < components; cc++) {
     7432            int kk;
     7433
     7434            /* average 2 pixels since only a column */
     7435            totals[cc]= 0.0;
     7436            /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
     7437             * totals[RED]/= 2.0;
     7438             */
     7439            for (kk = 0; kk < BOX2; kk++) {
     7440              totals[cc]+= extractTotals[kk][cc];
     7441            }
     7442            totals[cc]/= (float)BOX2;
     7443        } /* for cc */
     7444
     7445        (*shovePackedPixel)(totals,outIndex,dataOut);
     7446        outIndex++;
     7447        /* skip over to next group of 2 */
     7448        src+= imageSizeInBytes + imageSizeInBytes;
    74497449      } /* for ii */
    74507450   }
    7451    else if (height == 1) {      /* horizontal slice viewed from top */
     7451   else if (height == 1) {      /* horizontal slice viewed from top */
    74527452      assert(width != 1);
    74537453
    74547454      for (ii= 0; ii< halfDepth; ii++) {
    7455         for (jj= 0; jj< halfWidth; jj++) {
    7456              float totals[4];
    7457              float extractTotals[BOX4][4];
    7458              int cc;
    7459 
    7460              (*extractPackedPixel)(isSwap,(void *)src,
    7461                                    &extractTotals[0][0]);
    7462              (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes),
    7463                                    &extractTotals[1][0]);
    7464              (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
    7465                                    &extractTotals[2][0]);
    7466              (*extractPackedPixel)(isSwap,
    7467                                    (void*)(src+imageSizeInBytes+pixelSizeInBytes),
    7468                                    &extractTotals[3][0]);
    7469              for (cc = 0; cc < components; cc++) {
    7470                 int kk;
    7471 
    7472                 /* grab 4 pixels to average */
    7473                 totals[cc]= 0.0;
    7474                 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    7475                 *              extractTotals[2][RED]+extractTotals[3][RED];
    7476                 * totals[RED]/= 4.0;
    7477                 */
    7478                 for (kk = 0; kk < BOX4; kk++) {
    7479                    totals[cc]+= extractTotals[kk][cc];
    7480                 }
    7481                 totals[cc]/= (float)BOX4;
    7482              }
    7483              (*shovePackedPixel)(totals,outIndex,dataOut);
    7484 
    7485              outIndex++;
    7486              /* skip over to next horizontal square of 4 */
    7487              src+= imageSizeInBytes + imageSizeInBytes;
    7488         }
     7455        for (jj= 0; jj< halfWidth; jj++) {
     7456             float totals[4];
     7457             float extractTotals[BOX4][4];
     7458             int cc;
     7459
     7460             (*extractPackedPixel)(isSwap,(void *)src,
     7461                                   &extractTotals[0][0]);
     7462             (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes),
     7463                                   &extractTotals[1][0]);
     7464             (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
     7465                                   &extractTotals[2][0]);
     7466             (*extractPackedPixel)(isSwap,
     7467                                   (void*)(src+imageSizeInBytes+pixelSizeInBytes),
     7468                                   &extractTotals[3][0]);
     7469             for (cc = 0; cc < components; cc++) {
     7470                int kk;
     7471
     7472                /* grab 4 pixels to average */
     7473                totals[cc]= 0.0;
     7474                /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     7475                *              extractTotals[2][RED]+extractTotals[3][RED];
     7476                * totals[RED]/= 4.0;
     7477                */
     7478                for (kk = 0; kk < BOX4; kk++) {
     7479                   totals[cc]+= extractTotals[kk][cc];
     7480                }
     7481                totals[cc]/= (float)BOX4;
     7482             }
     7483             (*shovePackedPixel)(totals,outIndex,dataOut);
     7484
     7485             outIndex++;
     7486             /* skip over to next horizontal square of 4 */
     7487             src+= imageSizeInBytes + imageSizeInBytes;
     7488        }
    74897489      }
    74907490
    74917491      /* assert() */
    74927492   }
    7493    else if (width == 1) {       /* vertical slice viewed from top */
     7493   else if (width == 1) {       /* vertical slice viewed from top */
    74947494      assert(height != 1);
    74957495
    74967496      for (ii= 0; ii< halfDepth; ii++) {
    7497         for (jj= 0; jj< halfHeight; jj++) {
    7498             float totals[4];
    7499             float extractTotals[BOX4][4];
    7500             int cc;
    7501 
    7502             (*extractPackedPixel)(isSwap,(void *)src,
    7503                                   &extractTotals[0][0]);
    7504             (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes),
    7505                                   &extractTotals[1][0]);
    7506             (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
    7507                                   &extractTotals[2][0]);
    7508             (*extractPackedPixel)(isSwap,
    7509                                   (void*)(src+imageSizeInBytes+rowSizeInBytes),
    7510                                   &extractTotals[3][0]);
    7511             for (cc = 0; cc < components; cc++) {
    7512                int kk;
    7513 
    7514                /* grab 4 pixels to average */
    7515                totals[cc]= 0.0;
    7516                /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    7517                 *              extractTotals[2][RED]+extractTotals[3][RED];
    7518                 * totals[RED]/= 4.0;
    7519                 */
    7520                for (kk = 0; kk < BOX4; kk++) {
    7521                   totals[cc]+= extractTotals[kk][cc];
    7522                }
    7523                totals[cc]/= (float)BOX4;
    7524             }
    7525             (*shovePackedPixel)(totals,outIndex,dataOut);
    7526 
    7527             outIndex++;
    7528 
    7529             /* skip over to next vertical square of 4 */
    7530             src+= imageSizeInBytes + imageSizeInBytes;
    7531         }
     7497        for (jj= 0; jj< halfHeight; jj++) {
     7498            float totals[4];
     7499            float extractTotals[BOX4][4];
     7500            int cc;
     7501
     7502            (*extractPackedPixel)(isSwap,(void *)src,
     7503                                  &extractTotals[0][0]);
     7504            (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes),
     7505                                  &extractTotals[1][0]);
     7506            (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
     7507                                  &extractTotals[2][0]);
     7508            (*extractPackedPixel)(isSwap,
     7509                                  (void*)(src+imageSizeInBytes+rowSizeInBytes),
     7510                                  &extractTotals[3][0]);
     7511            for (cc = 0; cc < components; cc++) {
     7512               int kk;
     7513
     7514               /* grab 4 pixels to average */
     7515               totals[cc]= 0.0;
     7516               /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     7517                *              extractTotals[2][RED]+extractTotals[3][RED];
     7518                * totals[RED]/= 4.0;
     7519                */
     7520               for (kk = 0; kk < BOX4; kk++) {
     7521                  totals[cc]+= extractTotals[kk][cc];
     7522               }
     7523               totals[cc]/= (float)BOX4;
     7524            }
     7525            (*shovePackedPixel)(totals,outIndex,dataOut);
     7526
     7527            outIndex++;
     7528
     7529            /* skip over to next vertical square of 4 */
     7530            src+= imageSizeInBytes + imageSizeInBytes;
     7531        }
    75327532      }
    75337533      /* assert() */
     
    75377537
    75387538static void halveImagePackedPixel3D(int components,
    7539                                     void (*extractPackedPixel)
    7540                                     (int, const void *,GLfloat []),
    7541                                     void (*shovePackedPixel)
    7542                                     (const GLfloat [],int, void *),
    7543                                     GLint width, GLint height, GLint depth,
    7544                                     const void *dataIn, void *dataOut,
    7545                                     GLint pixelSizeInBytes,
    7546                                     GLint rowSizeInBytes,
    7547                                     GLint imageSizeInBytes,
    7548                                     GLint isSwap)
     7539                                    void (*extractPackedPixel)
     7540                                    (int, const void *,GLfloat []),
     7541                                    void (*shovePackedPixel)
     7542                                    (const GLfloat [],int, void *),
     7543                                    GLint width, GLint height, GLint depth,
     7544                                    const void *dataIn, void *dataOut,
     7545                                    GLint pixelSizeInBytes,
     7546                                    GLint rowSizeInBytes,
     7547                                    GLint imageSizeInBytes,
     7548                                    GLint isSwap)
    75497549{
    75507550   if (depth == 1) {
     
    75527552
    75537553      halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel,
    7554                             width,height,dataIn,dataOut,pixelSizeInBytes,
    7555                             rowSizeInBytes,isSwap);
     7554                            width,height,dataIn,dataOut,pixelSizeInBytes,
     7555                            rowSizeInBytes,isSwap);
    75567556      return;
    75577557   }
     
    75617561
    75627562      halveImagePackedPixelSlice(components,
    7563                                 extractPackedPixel,shovePackedPixel,
    7564                                 width, height, depth, dataIn, dataOut,
    7565                                 pixelSizeInBytes, rowSizeInBytes,
    7566                                 imageSizeInBytes, isSwap);
     7563                                extractPackedPixel,shovePackedPixel,
     7564                                width, height, depth, dataIn, dataOut,
     7565                                pixelSizeInBytes, rowSizeInBytes,
     7566                                imageSizeInBytes, isSwap);
    75677567      return;
    75687568   }
     
    75787578
    75797579      for (dd= 0; dd < halfDepth; dd++) {
    7580         for (ii= 0; ii< halfHeight; ii++) {
    7581             for (jj= 0; jj< halfWidth; jj++) {
     7580        for (ii= 0; ii< halfHeight; ii++) {
     7581            for (jj= 0; jj< halfWidth; jj++) {
    75827582#define BOX8 8
    7583                float totals[4]; /* 4 is maximum components */
    7584                float extractTotals[BOX8][4]; /* 4 is maximum components */
    7585                int cc;
    7586 
    7587                (*extractPackedPixel)(isSwap,(void *)src,
    7588                                      &extractTotals[0][0]);
    7589                (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes),
    7590                                      &extractTotals[1][0]);
    7591                (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes),
    7592                                      &extractTotals[2][0]);
    7593                (*extractPackedPixel)(isSwap,
    7594                                      (void*)(src+rowSizeInBytes+pixelSizeInBytes),
    7595                                      &extractTotals[3][0]);
    7596 
    7597                (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
    7598                                      &extractTotals[4][0]);
    7599                (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes+imageSizeInBytes),
    7600                                      &extractTotals[5][0]);
    7601                (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes+imageSizeInBytes),
    7602                                      &extractTotals[6][0]);
    7603                (*extractPackedPixel)(isSwap,
    7604                                      (void*)(src+rowSizeInBytes+pixelSizeInBytes+imageSizeInBytes),
    7605                                      &extractTotals[7][0]);
    7606                for (cc = 0; cc < components; cc++) {
    7607                   int kk;
    7608 
    7609                   /* grab 8 pixels to average */
    7610                   totals[cc]= 0.0;
    7611                   /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    7612                    *              extractTotals[2][RED]+extractTotals[3][RED]+
    7613                    *              extractTotals[4][RED]+extractTotals[5][RED]+
    7614                    *              extractTotals[6][RED]+extractTotals[7][RED];
    7615                    * totals[RED]/= 8.0;
    7616                    */
    7617                   for (kk = 0; kk < BOX8; kk++) {
    7618                      totals[cc]+= extractTotals[kk][cc];
    7619                   }
    7620                   totals[cc]/= (float)BOX8;
    7621                }
    7622                (*shovePackedPixel)(totals,outIndex,dataOut);
    7623 
    7624                outIndex++;
    7625                /* skip over to next square of 4 */
    7626                src+= pixelSizeInBytes + pixelSizeInBytes;
    7627             }
    7628             /* skip past pad bytes, if any, to get to next row */
    7629             src+= padBytes;
    7630 
    7631             /* src is at beginning of a row here, but it's the second row of
    7632              * the square block of 4 pixels that we just worked on so we
    7633              * need to go one more row.
    7634              * i.e.,
    7635              *                   OO...
    7636              *           here -->OO...
    7637              *       but want -->OO...
    7638              *                   OO...
    7639              *                   ...
    7640              */
    7641             src+= rowSizeInBytes;
    7642         }
    7643 
    7644         src+= imageSizeInBytes;
     7583               float totals[4]; /* 4 is maximum components */
     7584               float extractTotals[BOX8][4]; /* 4 is maximum components */
     7585               int cc;
     7586
     7587               (*extractPackedPixel)(isSwap,(void *)src,
     7588                                     &extractTotals[0][0]);
     7589               (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes),
     7590                                     &extractTotals[1][0]);
     7591               (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes),
     7592                                     &extractTotals[2][0]);
     7593               (*extractPackedPixel)(isSwap,
     7594                                     (void*)(src+rowSizeInBytes+pixelSizeInBytes),
     7595                                     &extractTotals[3][0]);
     7596
     7597               (*extractPackedPixel)(isSwap,(void *)(src+imageSizeInBytes),
     7598                                     &extractTotals[4][0]);
     7599               (*extractPackedPixel)(isSwap,(void *)(src+pixelSizeInBytes+imageSizeInBytes),
     7600                                     &extractTotals[5][0]);
     7601               (*extractPackedPixel)(isSwap,(void *)(src+rowSizeInBytes+imageSizeInBytes),
     7602                                     &extractTotals[6][0]);
     7603               (*extractPackedPixel)(isSwap,
     7604                                     (void*)(src+rowSizeInBytes+pixelSizeInBytes+imageSizeInBytes),
     7605                                     &extractTotals[7][0]);
     7606               for (cc = 0; cc < components; cc++) {
     7607                  int kk;
     7608
     7609                  /* grab 8 pixels to average */
     7610                  totals[cc]= 0.0;
     7611                  /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     7612                   *              extractTotals[2][RED]+extractTotals[3][RED]+
     7613                   *              extractTotals[4][RED]+extractTotals[5][RED]+
     7614                   *              extractTotals[6][RED]+extractTotals[7][RED];
     7615                   * totals[RED]/= 8.0;
     7616                   */
     7617                  for (kk = 0; kk < BOX8; kk++) {
     7618                     totals[cc]+= extractTotals[kk][cc];
     7619                  }
     7620                  totals[cc]/= (float)BOX8;
     7621               }
     7622               (*shovePackedPixel)(totals,outIndex,dataOut);
     7623
     7624               outIndex++;
     7625               /* skip over to next square of 4 */
     7626               src+= pixelSizeInBytes + pixelSizeInBytes;
     7627            }
     7628            /* skip past pad bytes, if any, to get to next row */
     7629            src+= padBytes;
     7630
     7631            /* src is at beginning of a row here, but it's the second row of
     7632             * the square block of 4 pixels that we just worked on so we
     7633             * need to go one more row.
     7634             * i.e.,
     7635             *                   OO...
     7636             *           here -->OO...
     7637             *       but want -->OO...
     7638             *                   OO...
     7639             *                   ...
     7640             */
     7641            src+= rowSizeInBytes;
     7642        }
     7643
     7644        src+= imageSizeInBytes;
    76457645      } /* for dd */
    76467646
     
    76537653
    76547654static int gluBuild3DMipmapLevelsCore(GLenum target, GLint internalFormat,
    7655                                       GLsizei width,
    7656                                       GLsizei height,
    7657                                       GLsizei depth,
    7658                                       GLsizei widthPowerOf2,
    7659                                       GLsizei heightPowerOf2,
    7660                                       GLsizei depthPowerOf2,
    7661                                       GLenum format, GLenum type,
    7662                                       GLint userLevel,
    7663                                       GLint baseLevel,GLint maxLevel,
    7664                                       const void *data)
     7655                                      GLsizei width,
     7656                                      GLsizei height,
     7657                                      GLsizei depth,
     7658                                      GLsizei widthPowerOf2,
     7659                                      GLsizei heightPowerOf2,
     7660                                      GLsizei depthPowerOf2,
     7661                                      GLenum format, GLenum type,
     7662                                      GLint userLevel,
     7663                                      GLint baseLevel,GLint maxLevel,
     7664                                      const void *data)
    76657665{
    76667666   GLint newWidth, newHeight, newDepth;
     
    77277727
    77287728   usersImage = (GLubyte *)data + psm.unpack_skip_rows * rowSize +
    7729                                   psm.unpack_skip_pixels * groupSize +
    7730                                   /* 3dstuff */
    7731                                   psm.unpack_skip_images * imageSize;
     7729                                  psm.unpack_skip_pixels * groupSize +
     7730                                  /* 3dstuff */
     7731                                  psm.unpack_skip_images * imageSize;
    77327732
    77337733   glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
     
    77427742       /* Use usersImage for level userLevel */
    77437743       if (baseLevel <= level && level <= maxLevel) {
    7744           glTexImage3D(target, level, internalFormat, width,
    7745                        height, depth, 0, format, type,
    7746                        (void *) usersImage);
     7744          glTexImage3DEXT(target, level, internalFormat, width,
     7745                          height, depth, 0, format, type,
     7746                          (void *) usersImage);
    77477747       }
    77487748       if(levels == 0) { /* we're done. clean up and return */
    7749         glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    7750         glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    7751         glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    7752         glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    7753         glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    7754         glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
    7755         glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
    7756         return 0;
     7749        glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     7750        glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     7751        glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     7752        glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     7753        glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     7754        glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
     7755        glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
     7756        return 0;
    77577757       }
    77587758       {
    7759           int nextWidth= newWidth/2;
    7760           int nextHeight= newHeight/2;
    7761           int nextDepth= newDepth/2;
    7762 
    7763           /* clamp to 1 */
    7764           if (nextWidth < 1) nextWidth= 1;
    7765           if (nextHeight < 1) nextHeight= 1;
    7766           if (nextDepth < 1) nextDepth= 1;     
     7759          int nextWidth= newWidth/2;
     7760          int nextHeight= newHeight/2;
     7761          int nextDepth= newDepth/2;
     7762
     7763          /* clamp to 1 */
     7764          if (nextWidth < 1) nextWidth= 1;
     7765          if (nextHeight < 1) nextHeight= 1;
     7766          if (nextDepth < 1) nextDepth= 1;
    77677767       memReq = imageSize3D(nextWidth, nextHeight, nextDepth, format, type);
    77687768       }
    77697769       switch(type) {
    77707770       case GL_UNSIGNED_BYTE:
    7771         dstImage = (GLubyte *)malloc(memReq);
    7772         break;
     7771        dstImage = (GLubyte *)malloc(memReq);
     7772        break;
    77737773       case GL_BYTE:
    7774         dstImage = (GLbyte *)malloc(memReq);
    7775         break;
     7774        dstImage = (GLbyte *)malloc(memReq);
     7775        break;
    77767776       case GL_UNSIGNED_SHORT:
    7777         dstImage = (GLushort *)malloc(memReq);
    7778         break;
     7777        dstImage = (GLushort *)malloc(memReq);
     7778        break;
    77797779       case GL_SHORT:
    7780         dstImage = (GLshort *)malloc(memReq);
    7781         break;
     7780        dstImage = (GLshort *)malloc(memReq);
     7781        break;
    77827782       case GL_UNSIGNED_INT:
    7783         dstImage = (GLuint *)malloc(memReq);
    7784         break;
     7783        dstImage = (GLuint *)malloc(memReq);
     7784        break;
    77857785       case GL_INT:
    7786         dstImage = (GLint *)malloc(memReq);
    7787         break;
     7786        dstImage = (GLint *)malloc(memReq);
     7787        break;
    77887788       case GL_FLOAT:
    7789         dstImage = (GLfloat *)malloc(memReq);
    7790         break;
     7789        dstImage = (GLfloat *)malloc(memReq);
     7790        break;
    77917791       case GL_UNSIGNED_BYTE_3_3_2:
    77927792       case GL_UNSIGNED_BYTE_2_3_3_REV:
    7793         dstImage = (GLubyte *)malloc(memReq);
    7794         break;
     7793        dstImage = (GLubyte *)malloc(memReq);
     7794        break;
    77957795       case GL_UNSIGNED_SHORT_5_6_5:
    77967796       case GL_UNSIGNED_SHORT_5_6_5_REV:
     
    79327932         case GL_UNSIGNED_SHORT_5_6_5_REV:
    79337933           halveImagePackedPixel3D(3,extract565rev,shove565rev,
    7934                                    width,height,depth,usersImage,dstImage,
    7935                                    elementSize,rowSize,imageSize,myswapBytes);
    7936            break;
    7937         case GL_UNSIGNED_SHORT_4_4_4_4:
    7938            halveImagePackedPixel3D(4,extract4444,shove4444,
    7939                                    width,height,depth,usersImage,dstImage,
    7940                                    elementSize,rowSize,imageSize,myswapBytes);
    7941            break;
    7942         case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    7943            halveImagePackedPixel3D(4,extract4444rev,shove4444rev,
    7944                                    width,height,depth,usersImage,dstImage,
    7945                                    elementSize,rowSize,imageSize,myswapBytes);
    7946            break;
    7947         case GL_UNSIGNED_SHORT_5_5_5_1:
    7948            halveImagePackedPixel3D(4,extract5551,shove5551,
    7949                                    width,height,depth,usersImage,dstImage,
    7950                                    elementSize,rowSize,imageSize,myswapBytes);
    7951            break;
    7952         case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    7953            halveImagePackedPixel3D(4,extract1555rev,shove1555rev,
    7954                                    width,height,depth,usersImage,dstImage,
    7955                                    elementSize,rowSize,imageSize,myswapBytes);
    7956            break;
    7957         case GL_UNSIGNED_INT_8_8_8_8:
    7958            halveImagePackedPixel3D(4,extract8888,shove8888,
    7959                                    width,height,depth,usersImage,dstImage,
    7960                                    elementSize,rowSize,imageSize,myswapBytes);
    7961            break;
    7962         case GL_UNSIGNED_INT_8_8_8_8_REV:
    7963            halveImagePackedPixel3D(4,extract8888rev,shove8888rev,
    7964                                    width,height,depth,usersImage,dstImage,
    7965                                    elementSize,rowSize,imageSize,myswapBytes);
    7966            break;
    7967         case GL_UNSIGNED_INT_10_10_10_2:
    7968            halveImagePackedPixel3D(4,extract1010102,shove1010102,
    7969                                    width,height,depth,usersImage,dstImage,
    7970                                    elementSize,rowSize,imageSize,myswapBytes);
    7971            break;
    7972         case GL_UNSIGNED_INT_2_10_10_10_REV:
    7973            halveImagePackedPixel3D(4,extract2101010rev,shove2101010rev,
    7974                                    width,height,depth,usersImage,dstImage,
    7975                                    elementSize,rowSize,imageSize,myswapBytes);
    7976            break;
    7977         default:
    7978            assert(0);
    7979            break;
    7980         }
     7934                                   width,height,depth,usersImage,dstImage,
     7935                                   elementSize,rowSize,imageSize,myswapBytes);
     7936           break;
     7937        case GL_UNSIGNED_SHORT_4_4_4_4:
     7938           halveImagePackedPixel3D(4,extract4444,shove4444,
     7939                                   width,height,depth,usersImage,dstImage,
     7940                                   elementSize,rowSize,imageSize,myswapBytes);
     7941           break;
     7942        case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     7943           halveImagePackedPixel3D(4,extract4444rev,shove4444rev,
     7944                                   width,height,depth,usersImage,dstImage,
     7945                                   elementSize,rowSize,imageSize,myswapBytes);
     7946           break;
     7947        case GL_UNSIGNED_SHORT_5_5_5_1:
     7948           halveImagePackedPixel3D(4,extract5551,shove5551,
     7949                                   width,height,depth,usersImage,dstImage,
     7950                                   elementSize,rowSize,imageSize,myswapBytes);
     7951           break;
     7952        case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     7953           halveImagePackedPixel3D(4,extract1555rev,shove1555rev,
     7954                                   width,height,depth,usersImage,dstImage,
     7955                                   elementSize,rowSize,imageSize,myswapBytes);
     7956           break;
     7957        case GL_UNSIGNED_INT_8_8_8_8:
     7958           halveImagePackedPixel3D(4,extract8888,shove8888,
     7959                                   width,height,depth,usersImage,dstImage,
     7960                                   elementSize,rowSize,imageSize,myswapBytes);
     7961           break;
     7962        case GL_UNSIGNED_INT_8_8_8_8_REV:
     7963           halveImagePackedPixel3D(4,extract8888rev,shove8888rev,
     7964                                   width,height,depth,usersImage,dstImage,
     7965                                   elementSize,rowSize,imageSize,myswapBytes);
     7966           break;
     7967        case GL_UNSIGNED_INT_10_10_10_2:
     7968           halveImagePackedPixel3D(4,extract1010102,shove1010102,
     7969                                   width,height,depth,usersImage,dstImage,
     7970                                   elementSize,rowSize,imageSize,myswapBytes);
     7971           break;
     7972        case GL_UNSIGNED_INT_2_10_10_10_REV:
     7973           halveImagePackedPixel3D(4,extract2101010rev,shove2101010rev,
     7974                                   width,height,depth,usersImage,dstImage,
     7975                                   elementSize,rowSize,imageSize,myswapBytes);
     7976           break;
     7977        default:
     7978           assert(0);
     7979           break;
     7980        }
    79817981       newWidth = width/2;
    79827982       newHeight = height/2;
     
    79957995       switch(type) {
    79967996       case GL_UNSIGNED_BYTE:
    7997         dstImage = (GLubyte *)malloc(memReq);
    7998         break;
     7997        dstImage = (GLubyte *)malloc(memReq);
     7998        break;
    79997999       case GL_BYTE:
    8000         dstImage = (GLbyte *)malloc(memReq);
    8001         break;
     8000        dstImage = (GLbyte *)malloc(memReq);
     8001        break;
    80028002       case GL_UNSIGNED_SHORT:
    8003         dstImage = (GLushort *)malloc(memReq);
    8004         break;
     8003        dstImage = (GLushort *)malloc(memReq);
     8004        break;
    80058005       case GL_SHORT:
    8006         dstImage = (GLshort *)malloc(memReq);
    8007         break;
     8006        dstImage = (GLshort *)malloc(memReq);
     8007        break;
    80088008       case GL_UNSIGNED_INT:
    8009         dstImage = (GLuint *)malloc(memReq);
    8010         break;
     8009        dstImage = (GLuint *)malloc(memReq);
     8010        break;
    80118011       case GL_INT:
    8012         dstImage = (GLint *)malloc(memReq);
    8013         break;
     8012        dstImage = (GLint *)malloc(memReq);
     8013        break;
    80148014       case GL_FLOAT:
    8015         dstImage = (GLfloat *)malloc(memReq);
    8016         break;
     8015        dstImage = (GLfloat *)malloc(memReq);
     8016        break;
    80178017       case GL_UNSIGNED_BYTE_3_3_2:
    80188018       case GL_UNSIGNED_BYTE_2_3_3_REV:
    8019         dstImage = (GLubyte *)malloc(memReq);
    8020         break;
     8019        dstImage = (GLubyte *)malloc(memReq);
     8020        break;
    80218021       case GL_UNSIGNED_SHORT_5_6_5:
    80228022       case GL_UNSIGNED_SHORT_5_6_5_REV:
     
    80258025       case GL_UNSIGNED_SHORT_5_5_5_1:
    80268026       case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    8027         dstImage = (GLushort *)malloc(memReq);
    8028         break;
     8027        dstImage = (GLushort *)malloc(memReq);
     8028        break;
    80298029       case GL_UNSIGNED_INT_8_8_8_8:
    80308030       case GL_UNSIGNED_INT_8_8_8_8_REV:
    80318031       case GL_UNSIGNED_INT_10_10_10_2:
    80328032       case GL_UNSIGNED_INT_2_10_10_10_REV:
    8033         dstImage = (GLuint *)malloc(memReq);
    8034         break;
     8033        dstImage = (GLuint *)malloc(memReq);
     8034        break;
    80358035       default:
    8036         return GLU_INVALID_ENUM; /* assertion */
     8036        return GLU_INVALID_ENUM; /* assertion */
    80378037       }
    80388038       if (dstImage == NULL) {
    8039         glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    8040         glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    8041         glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    8042         glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    8043         glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    8044         glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
    8045         glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
    8046         return GLU_OUT_OF_MEMORY;
     8039        glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     8040        glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     8041        glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     8042        glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     8043        glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     8044        glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
     8045        glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
     8046        return GLU_OUT_OF_MEMORY;
    80478047       }
    80488048       /* level userLevel+1 is in srcImage; level userLevel already saved */
     
    80518051       memReq = imageSize3D(newWidth, newHeight, newDepth, format, type);
    80528052       switch(type) {
    8053            case GL_UNSIGNED_BYTE:
    8054                dstImage = (GLubyte *)malloc(memReq);
    8055                break;
    8056            case GL_BYTE:
    8057                dstImage = (GLbyte *)malloc(memReq);
    8058                break;
    8059            case GL_UNSIGNED_SHORT:
    8060                dstImage = (GLushort *)malloc(memReq);
    8061                break;
    8062            case GL_SHORT:
    8063                dstImage = (GLshort *)malloc(memReq);
    8064                break;
    8065            case GL_UNSIGNED_INT:
    8066                dstImage = (GLuint *)malloc(memReq);
    8067                break;
    8068            case GL_INT:
    8069                dstImage = (GLint *)malloc(memReq);
    8070                break;
    8071            case GL_FLOAT:
    8072                dstImage = (GLfloat *)malloc(memReq);
    8073                break;
    8074            case GL_UNSIGNED_BYTE_3_3_2:
    8075            case GL_UNSIGNED_BYTE_2_3_3_REV:
    8076                dstImage = (GLubyte *)malloc(memReq);
    8077                break;
    8078            case GL_UNSIGNED_SHORT_5_6_5:
    8079            case GL_UNSIGNED_SHORT_5_6_5_REV:
    8080            case GL_UNSIGNED_SHORT_4_4_4_4:
    8081            case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    8082            case GL_UNSIGNED_SHORT_5_5_5_1:
    8083            case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    8084                dstImage = (GLushort *)malloc(memReq);
    8085                break;
    8086            case GL_UNSIGNED_INT_8_8_8_8:
    8087            case GL_UNSIGNED_INT_8_8_8_8_REV:
    8088            case GL_UNSIGNED_INT_10_10_10_2:
    8089            case GL_UNSIGNED_INT_2_10_10_10_REV:
    8090                dstImage = (GLuint *)malloc(memReq);
    8091                break;
    8092            default:
    8093                return GLU_INVALID_ENUM; /* assertion */
     8053           case GL_UNSIGNED_BYTE:
     8054               dstImage = (GLubyte *)malloc(memReq);
     8055               break;
     8056           case GL_BYTE:
     8057               dstImage = (GLbyte *)malloc(memReq);
     8058               break;
     8059           case GL_UNSIGNED_SHORT:
     8060               dstImage = (GLushort *)malloc(memReq);
     8061               break;
     8062           case GL_SHORT:
     8063               dstImage = (GLshort *)malloc(memReq);
     8064               break;
     8065           case GL_UNSIGNED_INT:
     8066               dstImage = (GLuint *)malloc(memReq);
     8067               break;
     8068           case GL_INT:
     8069               dstImage = (GLint *)malloc(memReq);
     8070               break;
     8071           case GL_FLOAT:
     8072               dstImage = (GLfloat *)malloc(memReq);
     8073               break;
     8074           case GL_UNSIGNED_BYTE_3_3_2:
     8075           case GL_UNSIGNED_BYTE_2_3_3_REV:
     8076               dstImage = (GLubyte *)malloc(memReq);
     8077               break;
     8078           case GL_UNSIGNED_SHORT_5_6_5:
     8079           case GL_UNSIGNED_SHORT_5_6_5_REV:
     8080           case GL_UNSIGNED_SHORT_4_4_4_4:
     8081           case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     8082           case GL_UNSIGNED_SHORT_5_5_5_1:
     8083           case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     8084               dstImage = (GLushort *)malloc(memReq);
     8085               break;
     8086           case GL_UNSIGNED_INT_8_8_8_8:
     8087           case GL_UNSIGNED_INT_8_8_8_8_REV:
     8088           case GL_UNSIGNED_INT_10_10_10_2:
     8089           case GL_UNSIGNED_INT_2_10_10_10_REV:
     8090               dstImage = (GLuint *)malloc(memReq);
     8091               break;
     8092           default:
     8093               return GLU_INVALID_ENUM; /* assertion */
    80948094       }
    80958095
    80968096       if (dstImage == NULL) {
    8097            glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    8098            glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    8099            glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    8100            glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    8101            glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    8102            glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
    8103            glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
    8104            return GLU_OUT_OF_MEMORY;
     8097           glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     8098           glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     8099           glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     8100           glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     8101           glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     8102           glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
     8103           glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
     8104           return GLU_OUT_OF_MEMORY;
    81058105       }
    81068106       /*printf("Build3DMipmaps(): ScaleImage3D %d %d %d->%d %d %d\n",
     
    81088108
    81098109       gluScaleImage3D(format, width, height, depth, type, usersImage,
    8110                        newWidth, newHeight, newDepth, type, dstImage);
     8110                       newWidth, newHeight, newDepth, type, dstImage);
    81118111
    81128112       myswapBytes = 0;
     
    81178117
    81188118       if(levels != 0) { /* use as little memory as possible */
    8119         {
    8120             int nextWidth= newWidth/2;
    8121             int nextHeight= newHeight/2;
    8122             int nextDepth= newDepth/2;
    8123             if (nextWidth < 1) nextWidth= 1;
    8124             if (nextHeight < 1) nextHeight= 1; 
    8125             if (nextDepth < 1) nextDepth= 1;   
    8126 
    8127         memReq = imageSize3D(nextWidth, nextHeight, nextDepth, format, type);
    8128         }
    8129         switch(type) {
    8130         case GL_UNSIGNED_BYTE:
    8131            dstImage = (GLubyte *)malloc(memReq);
    8132            break;
    8133         case GL_BYTE:
    8134            dstImage = (GLbyte *)malloc(memReq);
    8135            break;
    8136         case GL_UNSIGNED_SHORT:
    8137            dstImage = (GLushort *)malloc(memReq);
    8138            break;
    8139         case GL_SHORT:
    8140            dstImage = (GLshort *)malloc(memReq);
    8141            break;
    8142         case GL_UNSIGNED_INT:
    8143            dstImage = (GLuint *)malloc(memReq);
    8144            break;
    8145         case GL_INT:
    8146            dstImage = (GLint *)malloc(memReq);
    8147            break;
    8148         case GL_FLOAT:
    8149            dstImage = (GLfloat *)malloc(memReq);
    8150            break;
    8151         case GL_UNSIGNED_BYTE_3_3_2:
    8152         case GL_UNSIGNED_BYTE_2_3_3_REV:
    8153            dstImage = (GLubyte *)malloc(memReq);
    8154            break;
    8155         case GL_UNSIGNED_SHORT_5_6_5:
    8156         case GL_UNSIGNED_SHORT_5_6_5_REV:
    8157         case GL_UNSIGNED_SHORT_4_4_4_4:
    8158         case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    8159         case GL_UNSIGNED_SHORT_5_5_5_1:
    8160         case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    8161            dstImage = (GLushort *)malloc(memReq);
    8162            break;
    8163         case GL_UNSIGNED_INT_8_8_8_8:
    8164         case GL_UNSIGNED_INT_8_8_8_8_REV:
    8165         case GL_UNSIGNED_INT_10_10_10_2:
    8166         case GL_UNSIGNED_INT_2_10_10_10_REV:
    8167            dstImage = (GLuint *)malloc(memReq);
    8168            break;
    8169         default:
    8170            return GLU_INVALID_ENUM; /* assertion */
    8171         }
    8172         if (dstImage == NULL) {
    8173            glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
    8174            glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
    8175            glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
    8176            glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
    8177            glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
    8178            glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
    8179            glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
    8180            return GLU_OUT_OF_MEMORY;
    8181         }
     8119        {
     8120            int nextWidth= newWidth/2;
     8121            int nextHeight= newHeight/2;
     8122            int nextDepth= newDepth/2;
     8123            if (nextWidth < 1) nextWidth= 1;
     8124            if (nextHeight < 1) nextHeight= 1;
     8125            if (nextDepth < 1) nextDepth= 1;
     8126
     8127        memReq = imageSize3D(nextWidth, nextHeight, nextDepth, format, type);
     8128        }
     8129        switch(type) {
     8130        case GL_UNSIGNED_BYTE:
     8131           dstImage = (GLubyte *)malloc(memReq);
     8132           break;
     8133        case GL_BYTE:
     8134           dstImage = (GLbyte *)malloc(memReq);
     8135           break;
     8136        case GL_UNSIGNED_SHORT:
     8137           dstImage = (GLushort *)malloc(memReq);
     8138           break;
     8139        case GL_SHORT:
     8140           dstImage = (GLshort *)malloc(memReq);
     8141           break;
     8142        case GL_UNSIGNED_INT:
     8143           dstImage = (GLuint *)malloc(memReq);
     8144           break;
     8145        case GL_INT:
     8146           dstImage = (GLint *)malloc(memReq);
     8147           break;
     8148        case GL_FLOAT:
     8149           dstImage = (GLfloat *)malloc(memReq);
     8150           break;
     8151        case GL_UNSIGNED_BYTE_3_3_2:
     8152        case GL_UNSIGNED_BYTE_2_3_3_REV:
     8153           dstImage = (GLubyte *)malloc(memReq);
     8154           break;
     8155        case GL_UNSIGNED_SHORT_5_6_5:
     8156        case GL_UNSIGNED_SHORT_5_6_5_REV:
     8157        case GL_UNSIGNED_SHORT_4_4_4_4:
     8158        case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     8159        case GL_UNSIGNED_SHORT_5_5_5_1:
     8160        case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     8161           dstImage = (GLushort *)malloc(memReq);
     8162           break;
     8163        case GL_UNSIGNED_INT_8_8_8_8:
     8164        case GL_UNSIGNED_INT_8_8_8_8_REV:
     8165        case GL_UNSIGNED_INT_10_10_10_2:
     8166        case GL_UNSIGNED_INT_2_10_10_10_REV:
     8167           dstImage = (GLuint *)malloc(memReq);
     8168           break;
     8169        default:
     8170           return GLU_INVALID_ENUM; /* assertion */
     8171        }
     8172        if (dstImage == NULL) {
     8173           glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment);
     8174           glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows);
     8175           glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
     8176           glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
     8177           glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
     8178           glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images);
     8179           glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height);
     8180           return GLU_OUT_OF_MEMORY;
     8181        }
    81828182       }
    81838183       /* level userLevel is in srcImage; nothing saved yet */
    8184        level = userLevel;       
     8184       level = userLevel;
    81858185   }
    81868186
    81878187   glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
    81888188   if (baseLevel <= level && level <= maxLevel) {
    8189      glTexImage3D(target, level, internalFormat, newWidth, newHeight, newDepth,
    8190                   0,format, type, (void *)srcImage);
     8189     glTexImage3DEXT(target, level, internalFormat, newWidth, newHeight, newDepth,
     8190                     0,format, type, (void *)srcImage);
    81918191   }
    81928192   level++; /* update current level for the loop */
     
    83038303               break;
    83048304           case GL_UNSIGNED_SHORT_5_6_5_REV:
    8305                halveImagePackedPixel3D(3,extract565rev,shove565rev,
    8306                                        newWidth,newHeight,newDepth,
    8307                                        srcImage,dstImage,elementSize,rowSize,
    8308                                        imageSize,myswapBytes);
    8309                break;
    8310            case GL_UNSIGNED_SHORT_4_4_4_4:
    8311                halveImagePackedPixel3D(4,extract4444,shove4444,
    8312                                        newWidth,newHeight,newDepth,
    8313                                        srcImage,dstImage,elementSize,rowSize,
    8314                                        imageSize,myswapBytes);
    8315                break;
    8316            case GL_UNSIGNED_SHORT_4_4_4_4_REV:
    8317                halveImagePackedPixel3D(4,extract4444rev,shove4444rev,
    8318                                        newWidth,newHeight,newDepth,
    8319                                        srcImage,dstImage,elementSize,rowSize,
    8320                                        imageSize,myswapBytes);
    8321                break;
    8322            case GL_UNSIGNED_SHORT_5_5_5_1:             
    8323                halveImagePackedPixel3D(4,extract5551,shove5551,
    8324                                        newWidth,newHeight,newDepth,
    8325                                        srcImage,dstImage,elementSize,rowSize,
    8326                                        imageSize,myswapBytes);
    8327                break;
    8328            case GL_UNSIGNED_SHORT_1_5_5_5_REV:         
    8329                halveImagePackedPixel3D(4,extract1555rev,shove1555rev,
    8330                                        newWidth,newHeight,newDepth,
    8331                                        srcImage,dstImage,elementSize,rowSize,
    8332                                        imageSize,myswapBytes);
    8333                break;
    8334            case GL_UNSIGNED_INT_8_8_8_8:
    8335                halveImagePackedPixel3D(4,extract8888,shove8888,
    8336                                        newWidth,newHeight,newDepth,
    8337                                        srcImage,dstImage,elementSize,rowSize,
    8338                                        imageSize,myswapBytes);
    8339                break;
    8340            case GL_UNSIGNED_INT_8_8_8_8_REV:
    8341                halveImagePackedPixel3D(4,extract8888rev,shove8888rev,
    8342                                        newWidth,newHeight,newDepth,
    8343                                        srcImage,dstImage,elementSize,rowSize,
    8344                                        imageSize,myswapBytes);
    8345                break;
    8346            case GL_UNSIGNED_INT_10_10_10_2:
    8347                halveImagePackedPixel3D(4,extract1010102,shove1010102,
    8348                                        newWidth,newHeight,newDepth,
    8349                                        srcImage,dstImage,elementSize,rowSize,
    8350                                        imageSize,myswapBytes);
    8351                break;
    8352            case GL_UNSIGNED_INT_2_10_10_10_REV:
    8353                halveImagePackedPixel3D(4,extract2101010rev,shove2101010rev,
    8354                                        newWidth,newHeight,newDepth,
    8355                                        srcImage,dstImage,elementSize,rowSize,
    8356                                        imageSize,myswapBytes);
    8357                break;
    8358            default:
    8359                assert(0);
    8360                break;
     8305               halveImagePackedPixel3D(3,extract565rev,shove565rev,
     8306                                       newWidth,newHeight,newDepth,
     8307                                       srcImage,dstImage,elementSize,rowSize,
     8308                                       imageSize,myswapBytes);
     8309               break;
     8310           case GL_UNSIGNED_SHORT_4_4_4_4:
     8311               halveImagePackedPixel3D(4,extract4444,shove4444,
     8312                                       newWidth,newHeight,newDepth,
     8313                                       srcImage,dstImage,elementSize,rowSize,
     8314                                       imageSize,myswapBytes);
     8315               break;
     8316           case GL_UNSIGNED_SHORT_4_4_4_4_REV:
     8317               halveImagePackedPixel3D(4,extract4444rev,shove4444rev,
     8318                                       newWidth,newHeight,newDepth,
     8319                                       srcImage,dstImage,elementSize,rowSize,
     8320                                       imageSize,myswapBytes);
     8321               break;
     8322           case GL_UNSIGNED_SHORT_5_5_5_1:
     8323               halveImagePackedPixel3D(4,extract5551,shove5551,
     8324                                       newWidth,newHeight,newDepth,
     8325                                       srcImage,dstImage,elementSize,rowSize,
     8326                                       imageSize,myswapBytes);
     8327               break;
     8328           case GL_UNSIGNED_SHORT_1_5_5_5_REV:
     8329               halveImagePackedPixel3D(4,extract1555rev,shove1555rev,
     8330                                       newWidth,newHeight,newDepth,
     8331                                       srcImage,dstImage,elementSize,rowSize,
     8332                                       imageSize,myswapBytes);
     8333               break;
     8334           case GL_UNSIGNED_INT_8_8_8_8:
     8335               halveImagePackedPixel3D(4,extract8888,shove8888,
     8336                                       newWidth,newHeight,newDepth,
     8337                                       srcImage,dstImage,elementSize,rowSize,
     8338                                       imageSize,myswapBytes);
     8339               break;
     8340           case GL_UNSIGNED_INT_8_8_8_8_REV:
     8341               halveImagePackedPixel3D(4,extract8888rev,shove8888rev,
     8342                                       newWidth,newHeight,newDepth,
     8343                                       srcImage,dstImage,elementSize,rowSize,
     8344                                       imageSize,myswapBytes);
     8345               break;
     8346           case GL_UNSIGNED_INT_10_10_10_2:
     8347               halveImagePackedPixel3D(4,extract1010102,shove1010102,
     8348                                       newWidth,newHeight,newDepth,
     8349                                       srcImage,dstImage,elementSize,rowSize,
     8350                                       imageSize,myswapBytes);
     8351               break;
     8352           case GL_UNSIGNED_INT_2_10_10_10_REV:
     8353               halveImagePackedPixel3D(4,extract2101010rev,shove2101010rev,
     8354                                       newWidth,newHeight,newDepth,
     8355                                       srcImage,dstImage,elementSize,rowSize,
     8356                                       imageSize,myswapBytes);
     8357               break;
     8358           default:
     8359               assert(0);
     8360               break;
    83618361       }
    83628362
     
    83678367       if (newDepth > 1) newDepth /= 2;
    83688368       {
    8369           /* call tex image with srcImage untouched since it's not padded */
    8370           if (baseLevel <= level && level <= maxLevel) {
    8371             glTexImage3D(target, level, internalFormat, newWidth, newHeight,
    8372                         newDepth,0, format, type, (void *) srcImage);
    8373           }
     8369          /* call tex image with srcImage untouched since it's not padded */
     8370          if (baseLevel <= level && level <= maxLevel) {
     8371            glTexImage3DEXT(target, level, internalFormat, newWidth, newHeight,
     8372                            newDepth,0, format, type, (void *) srcImage);
     8373          }
    83748374       }
    83758375   } /* for level */
     
    83918391GLint GLAPI
    83928392gluBuild3DMipmapLevels(GLenum target, GLint internalFormat,
    8393                              GLsizei width, GLsizei height, GLsizei depth,
    8394                              GLenum format, GLenum type,
    8395                              GLint userLevel, GLint baseLevel, GLint maxLevel,
    8396                              const void *data)
     8393                             GLsizei width, GLsizei height, GLsizei depth,
     8394                             GLenum format, GLenum type,
     8395                             GLint userLevel, GLint baseLevel, GLint maxLevel,
     8396                             const void *data)
    83978397{
    83988398   int level, levels;
     
    84208420
    84218421   return gluBuild3DMipmapLevelsCore(target, internalFormat,
    8422                                      width, height, depth,
    8423                                      width, height, depth,
    8424                                      format, type,
    8425                                      userLevel, baseLevel, maxLevel,
    8426                                      data);
     8422                                     width, height, depth,
     8423                                     width, height, depth,
     8424                                     format, type,
     8425                                     userLevel, baseLevel, maxLevel,
     8426                                     data);
    84278427} /* gluBuild3DMipmapLevels() */
    84288428
    84298429GLint GLAPI
    84308430gluBuild3DMipmaps(GLenum target, GLint internalFormat,
    8431                         GLsizei width, GLsizei height, GLsizei depth,
    8432                         GLenum format, GLenum type, const void *data)
     8431                        GLsizei width, GLsizei height, GLsizei depth,
     8432                        GLenum format, GLenum type, const void *data)
    84338433{
    84348434   GLint widthPowerOf2, heightPowerOf2, depthPowerOf2;
     
    84478447
    84488448   closestFit3D(target,width,height,depth,internalFormat,format,type,
    8449                 &widthPowerOf2,&heightPowerOf2,&depthPowerOf2);
     8449                &widthPowerOf2,&heightPowerOf2,&depthPowerOf2);
    84508450
    84518451   levels = computeLog(widthPowerOf2);
     
    84568456
    84578457   return gluBuild3DMipmapLevelsCore(target, internalFormat,
    8458                                      width, height, depth,
    8459                                      widthPowerOf2, heightPowerOf2,
    8460                                      depthPowerOf2,
    8461                                      format, type, 0, 0, levels,
    8462                                      data);
     8458                                     width, height, depth,
     8459                                     widthPowerOf2, heightPowerOf2,
     8460                                     depthPowerOf2,
     8461                                     format, type, 0, 0, levels,
     8462                                     data);
    84638463} /* gluBuild3DMipmaps() */
    84648464
    84658465static GLdouble extractUbyte(int isSwap, const void *ubyte)
    84668466{
    8467    isSwap= isSwap;              /* turn off warnings */
     8467   isSwap= isSwap;              /* turn off warnings */
    84688468
    84698469   assert(*((GLubyte *)ubyte) <= 255);
     
    84818481static GLdouble extractSbyte(int isSwap, const void *sbyte)
    84828482{
    8483    isSwap= isSwap;              /* turn off warnings */
     8483   isSwap= isSwap;              /* turn off warnings */
    84848484
    84858485   assert(*((GLbyte *)sbyte) <= 127);
     
    86098609
    86108610static void halveImageSlice(int components,
    8611                             GLdouble (*extract)(int, const void *),
    8612                             void (*shove)(GLdouble, int, void *),
    8613                             GLint width, GLint height, GLint depth,
    8614                             const void *dataIn, void *dataOut,
    8615                             GLint elementSizeInBytes,
    8616                             GLint groupSizeInBytes,
    8617                             GLint rowSizeInBytes,
    8618                             GLint imageSizeInBytes,
    8619                             GLint isSwap)
     8611                            GLdouble (*extract)(int, const void *),
     8612                            void (*shove)(GLdouble, int, void *),
     8613                            GLint width, GLint height, GLint depth,
     8614                            const void *dataIn, void *dataOut,
     8615                            GLint elementSizeInBytes,
     8616                            GLint groupSizeInBytes,
     8617                            GLint rowSizeInBytes,
     8618                            GLint imageSizeInBytes,
     8619                            GLint isSwap)
    86208620{
    86218621   int ii, jj;
     
    86298629   assert((width == 1 || height == 1) && depth >= 2);
    86308630
    8631    if (width == height) {       /* a 1-pixel column viewed from top */
     8631   if (width == height) {       /* a 1-pixel column viewed from top */
    86328632      /* printf("1-column\n");*/
    86338633      assert(width == 1 && height == 1);
     
    86358635
    86368636      for (ii= 0; ii< halfDepth; ii++) {
    8637         int cc;
    8638 
    8639         for (cc = 0; cc < components; cc++) {
    8640             double totals[4];
    8641             double extractTotals[BOX2][4];
    8642             int kk;
    8643 
    8644             extractTotals[0][cc]= (*extract)(isSwap,(void *)src);
    8645             extractTotals[1][cc]= (*extract)(isSwap,
    8646                                              (void *)(src+imageSizeInBytes));
    8647 
    8648             /* average 2 pixels since only a column */
    8649             totals[cc]= 0.0;
    8650             /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
    8651              * totals[RED]/= 2.0;
    8652              */
    8653             for (kk = 0; kk < BOX2; kk++) {
    8654               totals[cc]+= extractTotals[kk][cc];
    8655             }
    8656             totals[cc]/= (double)BOX2;
    8657 
    8658             (*shove)(totals[cc],outIndex,dataOut);
    8659             outIndex++;
    8660             src+= elementSizeInBytes;
    8661         } /* for cc */
    8662 
    8663         /* skip over to next group of 2 */
    8664         src+= rowSizeInBytes;
     8637        int cc;
     8638
     8639        for (cc = 0; cc < components; cc++) {
     8640            double totals[4];
     8641            double extractTotals[BOX2][4];
     8642            int kk;
     8643
     8644            extractTotals[0][cc]= (*extract)(isSwap,(void *)src);
     8645            extractTotals[1][cc]= (*extract)(isSwap,
     8646                                             (void *)(src+imageSizeInBytes));
     8647
     8648            /* average 2 pixels since only a column */
     8649            totals[cc]= 0.0;
     8650            /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
     8651             * totals[RED]/= 2.0;
     8652             */
     8653            for (kk = 0; kk < BOX2; kk++) {
     8654              totals[cc]+= extractTotals[kk][cc];
     8655            }
     8656            totals[cc]/= (double)BOX2;
     8657
     8658            (*shove)(totals[cc],outIndex,dataOut);
     8659            outIndex++;
     8660            src+= elementSizeInBytes;
     8661        } /* for cc */
     8662
     8663        /* skip over to next group of 2 */
     8664        src+= rowSizeInBytes;
    86658665      } /* for ii */
    86668666
     
    86688668      assert(outIndex == halfDepth * components);
    86698669   }
    8670    else if (height == 1) {      /* horizontal slice viewed from top */
     8670   else if (height == 1) {      /* horizontal slice viewed from top */
    86718671      /* printf("horizontal slice\n"); */
    86728672      assert(width != 1);
    86738673
    86748674      for (ii= 0; ii< halfDepth; ii++) {
    8675         for (jj= 0; jj< halfWidth; jj++) {
    8676             int cc;
    8677 
    8678             for (cc = 0; cc < components; cc++) {
    8679                int kk;
    8680                double totals[4];
    8681                double extractTotals[BOX4][4];
    8682 
    8683                extractTotals[0][cc]=(*extract)(isSwap,(void *)src);
    8684                extractTotals[1][cc]=(*extract)(isSwap,
    8685                                                (void *)(src+groupSizeInBytes));
    8686                extractTotals[2][cc]=(*extract)(isSwap,
    8687                                                (void *)(src+imageSizeInBytes));
    8688                extractTotals[3][cc]=(*extract)(isSwap,
    8689                                                (void*)(src+imageSizeInBytes+groupSizeInBytes));
    8690 
    8691                /* grab 4 pixels to average */
    8692                totals[cc]= 0.0;
    8693                /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    8694                 *              extractTotals[2][RED]+extractTotals[3][RED];
    8695                 * totals[RED]/= 4.0;
    8696                 */
    8697                for (kk = 0; kk < BOX4; kk++) {
    8698                   totals[cc]+= extractTotals[kk][cc];
    8699                }
    8700                totals[cc]/= (double)BOX4;
    8701 
    8702                (*shove)(totals[cc],outIndex,dataOut);
    8703                outIndex++;
    8704 
    8705                src+= elementSizeInBytes;
    8706             } /* for cc */
    8707 
    8708             /* skip over to next horizontal square of 4 */
    8709             src+= groupSizeInBytes;
    8710         } /* for jj */
    8711         src+= padBytes;
    8712 
    8713         src+= rowSizeInBytes;
     8675        for (jj= 0; jj< halfWidth; jj++) {
     8676            int cc;
     8677
     8678            for (cc = 0; cc < components; cc++) {
     8679               int kk;
     8680               double totals[4];
     8681               double extractTotals[BOX4][4];
     8682
     8683               extractTotals[0][cc]=(*extract)(isSwap,(void *)src);
     8684               extractTotals[1][cc]=(*extract)(isSwap,
     8685                                               (void *)(src+groupSizeInBytes));
     8686               extractTotals[2][cc]=(*extract)(isSwap,
     8687                                               (void *)(src+imageSizeInBytes));
     8688               extractTotals[3][cc]=(*extract)(isSwap,
     8689                                               (void*)(src+imageSizeInBytes+groupSizeInBytes));
     8690
     8691               /* grab 4 pixels to average */
     8692               totals[cc]= 0.0;
     8693               /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     8694                *              extractTotals[2][RED]+extractTotals[3][RED];
     8695                * totals[RED]/= 4.0;
     8696                */
     8697               for (kk = 0; kk < BOX4; kk++) {
     8698                  totals[cc]+= extractTotals[kk][cc];
     8699               }
     8700               totals[cc]/= (double)BOX4;
     8701
     8702               (*shove)(totals[cc],outIndex,dataOut);
     8703               outIndex++;
     8704
     8705               src+= elementSizeInBytes;
     8706            } /* for cc */
     8707
     8708            /* skip over to next horizontal square of 4 */
     8709            src+= groupSizeInBytes;
     8710        } /* for jj */
     8711        src+= padBytes;
     8712
     8713        src+= rowSizeInBytes;
    87148714      } /* for ii */
    87158715
     
    87178717      assert(outIndex == halfWidth * halfDepth * components);
    87188718   }
    8719    else if (width == 1) {       /* vertical slice viewed from top */
     8719   else if (width == 1) {       /* vertical slice viewed from top */
    87208720      /* printf("vertical slice\n"); */
    87218721      assert(height != 1);
    87228722
    87238723      for (ii= 0; ii< halfDepth; ii++) {
    8724         for (jj= 0; jj< halfHeight; jj++) {
    8725             int cc;
    8726 
    8727             for (cc = 0; cc < components; cc++) {
    8728                int kk;
    8729                double totals[4];
    8730                double extractTotals[BOX4][4];
    8731 
    8732                extractTotals[0][cc]=(*extract)(isSwap,(void *)src);
    8733                extractTotals[1][cc]=(*extract)(isSwap,
    8734                                                (void *)(src+rowSizeInBytes));
    8735                extractTotals[2][cc]=(*extract)(isSwap,
    8736                                                (void *)(src+imageSizeInBytes));
    8737                extractTotals[3][cc]=(*extract)(isSwap,
    8738                                                (void*)(src+imageSizeInBytes+rowSizeInBytes));
    8739 
    8740                /* grab 4 pixels to average */
    8741                totals[cc]= 0.0;
    8742                /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    8743                 *              extractTotals[2][RED]+extractTotals[3][RED];
    8744                 * totals[RED]/= 4.0;
    8745                 */
    8746                for (kk = 0; kk < BOX4; kk++) {
    8747                   totals[cc]+= extractTotals[kk][cc];
    8748                }
    8749                totals[cc]/= (double)BOX4;
    8750 
    8751                (*shove)(totals[cc],outIndex,dataOut);
    8752                outIndex++;
    8753 
    8754                src+= elementSizeInBytes;
    8755             } /* for cc */
    8756             src+= padBytes;
    8757 
    8758             /* skip over to next vertical square of 4 */
    8759             src+= rowSizeInBytes;
    8760         } /* for jj */
    8761 
    8762         src+= imageSizeInBytes;
     8724        for (jj= 0; jj< halfHeight; jj++) {
     8725            int cc;
     8726
     8727            for (cc = 0; cc < components; cc++) {
     8728               int kk;
     8729               double totals[4];
     8730               double extractTotals[BOX4][4];
     8731
     8732               extractTotals[0][cc]=(*extract)(isSwap,(void *)src);
     8733               extractTotals[1][cc]=(*extract)(isSwap,
     8734                                               (void *)(src+rowSizeInBytes));
     8735               extractTotals[2][cc]=(*extract)(isSwap,
     8736                                               (void *)(src+imageSizeInBytes));
     8737               extractTotals[3][cc]=(*extract)(isSwap,
     8738                                               (void*)(src+imageSizeInBytes+rowSizeInBytes));
     8739
     8740               /* grab 4 pixels to average */
     8741               totals[cc]= 0.0;
     8742               /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     8743                *              extractTotals[2][RED]+extractTotals[3][RED];
     8744                * totals[RED]/= 4.0;
     8745                */
     8746               for (kk = 0; kk < BOX4; kk++) {
     8747                  totals[cc]+= extractTotals[kk][cc];
     8748               }
     8749               totals[cc]/= (double)BOX4;
     8750
     8751               (*shove)(totals[cc],outIndex,dataOut);
     8752               outIndex++;
     8753
     8754               src+= elementSizeInBytes;
     8755            } /* for cc */
     8756            src+= padBytes;
     8757
     8758            /* skip over to next vertical square of 4 */
     8759            src+= rowSizeInBytes;
     8760        } /* for jj */
     8761
     8762        src+= imageSizeInBytes;
    87638763      } /* for ii */
    87648764
     
    87708770
    87718771static void halveImage3D(int components,
    8772                         GLdouble (*extract)(int, const void *),
    8773                         void (*shove)(GLdouble, int, void *),
    8774                         GLint width, GLint height, GLint depth,
    8775                         const void *dataIn, void *dataOut,
    8776                         GLint elementSizeInBytes,
    8777                         GLint groupSizeInBytes,
    8778                         GLint rowSizeInBytes,
    8779                         GLint imageSizeInBytes,
    8780                         GLint isSwap)
     8772                        GLdouble (*extract)(int, const void *),
     8773                        void (*shove)(GLdouble, int, void *),
     8774                        GLint width, GLint height, GLint depth,
     8775                        const void *dataIn, void *dataOut,
     8776                        GLint elementSizeInBytes,
     8777                        GLint groupSizeInBytes,
     8778                        GLint rowSizeInBytes,
     8779                        GLint imageSizeInBytes,
     8780                        GLint isSwap)
    87818781{
    87828782   assert(depth > 1);
     
    87878787
    87888788      halveImageSlice(components,extract,shove, width, height, depth,
    8789                       dataIn, dataOut, elementSizeInBytes, groupSizeInBytes,
    8790                       rowSizeInBytes, imageSizeInBytes, isSwap);
     8789                      dataIn, dataOut, elementSizeInBytes, groupSizeInBytes,
     8790                      rowSizeInBytes, imageSizeInBytes, isSwap);
    87918791      return;
    87928792   }
     
    88028802
    88038803      for (dd= 0; dd < halfDepth; dd++) {
    8804         for (ii= 0; ii< halfHeight; ii++) {
    8805             for (jj= 0; jj< halfWidth; jj++) {
    8806                int cc;
    8807 
    8808                for (cc= 0; cc < components; cc++) {
    8809                   int kk;
     8804        for (ii= 0; ii< halfHeight; ii++) {
     8805            for (jj= 0; jj< halfWidth; jj++) {
     8806               int cc;
     8807
     8808               for (cc= 0; cc < components; cc++) {
     8809                  int kk;
    88108810#define BOX8 8
    8811                   double totals[4];     /* 4 is maximum components */
    8812                   double extractTotals[BOX8][4]; /* 4 is maximum components */
    8813 
    8814                   extractTotals[0][cc]= (*extract)(isSwap,(void *)src);
    8815                   extractTotals[1][cc]= (*extract)(isSwap,
    8816                                                    (void *)(src+groupSizeInBytes));
    8817                   extractTotals[2][cc]= (*extract)(isSwap,
    8818                                                    (void *)(src+rowSizeInBytes));
    8819                   extractTotals[3][cc]= (*extract)(isSwap,
    8820                                                    (void*)(src+rowSizeInBytes+groupSizeInBytes));
    8821 
    8822                   extractTotals[4][cc]= (*extract)(isSwap,
    8823                                                    (void *)(src+imageSizeInBytes));
    8824 
    8825                   extractTotals[5][cc]= (*extract)(isSwap,
    8826                                                    (void *)(src+groupSizeInBytes+imageSizeInBytes));
    8827                   extractTotals[6][cc]= (*extract)(isSwap,
    8828                                                    (void *)(src+rowSizeInBytes+imageSizeInBytes));
    8829                   extractTotals[7][cc]= (*extract)(isSwap,
    8830                                                    (void*)(src+rowSizeInBytes+groupSizeInBytes+imageSizeInBytes));
    8831 
    8832                   totals[cc]= 0.0;
    8833 
    8834                   /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
    8835                    *              extractTotals[2][RED]+extractTotals[3][RED]+
    8836                    *              extractTotals[4][RED]+extractTotals[5][RED]+
    8837                    *              extractTotals[6][RED]+extractTotals[7][RED];
    8838                    * totals[RED]/= 8.0;
    8839                    */
    8840                   for (kk = 0; kk < BOX8; kk++) {
    8841                      totals[cc]+= extractTotals[kk][cc];
    8842                   }
    8843                   totals[cc]/= (double)BOX8;
    8844 
    8845                   (*shove)(totals[cc],outIndex,dataOut);
    8846 
    8847                   outIndex++;
    8848 
    8849                   src+= elementSizeInBytes; /* go to next component */
    8850                } /* for cc */
    8851 
    8852                /* skip over to next square of 4 */
    8853                src+= groupSizeInBytes;
    8854             } /* for jj */
    8855             /* skip past pad bytes, if any, to get to next row */
    8856             src+= padBytes;
    8857 
    8858             /* src is at beginning of a row here, but it's the second row of
    8859              * the square block of 4 pixels that we just worked on so we
    8860              * need to go one more row.
    8861              * i.e.,
    8862              *                   OO...
    8863              *           here -->OO...
    8864              *       but want -->OO...
    8865              *                   OO...
    8866              *                   ...
    8867              */
    8868             src+= rowSizeInBytes;
    8869         } /* for ii */
    8870 
    8871         src+= imageSizeInBytes;
     8811                  double totals[4];     /* 4 is maximum components */
     8812                  double extractTotals[BOX8][4]; /* 4 is maximum components */
     8813
     8814                  extractTotals[0][cc]= (*extract)(isSwap,(void *)src);
     8815                  extractTotals[1][cc]= (*extract)(isSwap,
     8816                                                   (void *)(src+groupSizeInBytes));
     8817                  extractTotals[2][cc]= (*extract)(isSwap,
     8818                                                   (void *)(src+rowSizeInBytes));
     8819                  extractTotals[3][cc]= (*extract)(isSwap,
     8820                                                   (void*)(src+rowSizeInBytes+groupSizeInBytes));
     8821
     8822                  extractTotals[4][cc]= (*extract)(isSwap,
     8823                                                   (void *)(src+imageSizeInBytes));
     8824
     8825                  extractTotals[5][cc]= (*extract)(isSwap,
     8826                                                   (void *)(src+groupSizeInBytes+imageSizeInBytes));
     8827                  extractTotals[6][cc]= (*extract)(isSwap,
     8828                                                   (void *)(src+rowSizeInBytes+imageSizeInBytes));
     8829                  extractTotals[7][cc]= (*extract)(isSwap,
     8830                                                   (void*)(src+rowSizeInBytes+groupSizeInBytes+imageSizeInBytes));
     8831
     8832                  totals[cc]= 0.0;
     8833
     8834                  /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
     8835                   *              extractTotals[2][RED]+extractTotals[3][RED]+
     8836                   *              extractTotals[4][RED]+extractTotals[5][RED]+
     8837                   *              extractTotals[6][RED]+extractTotals[7][RED];
     8838                   * totals[RED]/= 8.0;
     8839                   */
     8840                  for (kk = 0; kk < BOX8; kk++) {
     8841                     totals[cc]+= extractTotals[kk][cc];
     8842                  }
     8843                  totals[cc]/= (double)BOX8;
     8844
     8845                  (*shove)(totals[cc],outIndex,dataOut);
     8846
     8847                  outIndex++;
     8848
     8849                  src+= elementSizeInBytes; /* go to next component */
     8850               } /* for cc */
     8851
     8852               /* skip over to next square of 4 */
     8853               src+= groupSizeInBytes;
     8854            } /* for jj */
     8855            /* skip past pad bytes, if any, to get to next row */
     8856            src+= padBytes;
     8857
     8858            /* src is at beginning of a row here, but it's the second row of
     8859             * the square block of 4 pixels that we just worked on so we
     8860             * need to go one more row.
     8861             * i.e.,
     8862             *                   OO...
     8863             *           here -->OO...
     8864             *       but want -->OO...
     8865             *                   OO...
     8866             *                   ...
     8867             */
     8868            src+= rowSizeInBytes;
     8869        } /* for ii */
     8870
     8871        src+= imageSizeInBytes;
    88728872      } /* for dd */
    88738873
Note: See TracChangeset for help on using the changeset viewer.