Changeset 3579 for trunk/src/opengl/glu/util
- Timestamp:
- May 20, 2000, 3:48:23 PM (25 years ago)
- 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:12jeroen Exp $ */1 /* $Id: mipmap.c,v 1.2 2000-05-20 13:47:55 jeroen Exp $ */ 2 2 /* 3 3 ** License Applicability. Except to the extent portions of this file are … … 33 33 ** compliant with the OpenGL(R) version 1.2.1 Specification. 34 34 ** 35 ** $Date: 2000-0 2-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:12jeroen 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 $ 37 37 */ 38 38 … … 3968 3968 halveImage_ushort(cmpts, width, height, 3969 3969 (GLushort *)usersImage, (GLushort *)dstImage, 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 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; 3998 3998 case GL_UNSIGNED_BYTE_2_3_3_REV: 3999 4000 4001 4002 4003 3999 assert(format == GL_RGB); 4000 halveImagePackedPixel(3,extract233rev,shove233rev, 4001 width,height,usersImage,dstImage, 4002 element_size,rowsize,myswap_bytes); 4003 break; 4004 4004 case GL_UNSIGNED_SHORT_5_6_5: 4005 4006 4007 4008 4005 halveImagePackedPixel(3,extract565,shove565, 4006 width,height,usersImage,dstImage, 4007 element_size,rowsize,myswap_bytes); 4008 break; 4009 4009 case GL_UNSIGNED_SHORT_5_6_5_REV: 4010 4011 4012 4013 4010 halveImagePackedPixel(3,extract565rev,shove565rev, 4011 width,height,usersImage,dstImage, 4012 element_size,rowsize,myswap_bytes); 4013 break; 4014 4014 case GL_UNSIGNED_SHORT_4_4_4_4: 4015 4016 4017 4018 4015 halveImagePackedPixel(4,extract4444,shove4444, 4016 width,height,usersImage,dstImage, 4017 element_size,rowsize,myswap_bytes); 4018 break; 4019 4019 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 4020 4021 4022 4023 4020 halveImagePackedPixel(4,extract4444rev,shove4444rev, 4021 width,height,usersImage,dstImage, 4022 element_size,rowsize,myswap_bytes); 4023 break; 4024 4024 case GL_UNSIGNED_SHORT_5_5_5_1: 4025 4026 4027 4028 4025 halveImagePackedPixel(4,extract5551,shove5551, 4026 width,height,usersImage,dstImage, 4027 element_size,rowsize,myswap_bytes); 4028 break; 4029 4029 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 4030 4031 4032 4033 4030 halveImagePackedPixel(4,extract1555rev,shove1555rev, 4031 width,height,usersImage,dstImage, 4032 element_size,rowsize,myswap_bytes); 4033 break; 4034 4034 case GL_UNSIGNED_INT_8_8_8_8: 4035 4036 4037 4038 4035 halveImagePackedPixel(4,extract8888,shove8888, 4036 width,height,usersImage,dstImage, 4037 element_size,rowsize,myswap_bytes); 4038 break; 4039 4039 case GL_UNSIGNED_INT_8_8_8_8_REV: 4040 4041 4042 4043 4040 halveImagePackedPixel(4,extract8888rev,shove8888rev, 4041 width,height,usersImage,dstImage, 4042 element_size,rowsize,myswap_bytes); 4043 break; 4044 4044 case GL_UNSIGNED_INT_10_10_10_2: 4045 4046 4047 4048 4045 halveImagePackedPixel(4,extract1010102,shove1010102, 4046 width,height,usersImage,dstImage, 4047 element_size,rowsize,myswap_bytes); 4048 break; 4049 4049 case GL_UNSIGNED_INT_2_10_10_10_REV: 4050 4051 4052 4053 4050 halveImagePackedPixel(4,extract2101010rev,shove2101010rev, 4051 width,height,usersImage,dstImage, 4052 element_size,rowsize,myswap_bytes); 4053 break; 4054 4054 default: 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 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; 4091 4091 case GL_UNSIGNED_BYTE_3_3_2: 4092 4092 case GL_UNSIGNED_BYTE_2_3_3_REV: 4093 4094 4093 dstImage = (GLubyte *)malloc(memreq); 4094 break; 4095 4095 case GL_UNSIGNED_SHORT_5_6_5: 4096 4096 case GL_UNSIGNED_SHORT_5_6_5_REV: … … 4099 4099 case GL_UNSIGNED_SHORT_5_5_5_1: 4100 4100 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 4101 4102 4101 dstImage = (GLushort *)malloc(memreq); 4102 break; 4103 4103 case GL_UNSIGNED_INT_8_8_8_8: 4104 4104 case GL_UNSIGNED_INT_8_8_8_8_REV: 4105 4105 case GL_UNSIGNED_INT_10_10_10_2: 4106 4106 case GL_UNSIGNED_INT_2_10_10_10_REV: 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 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; 4122 4122 } else { /* user's image is *not* nice power-of-2 sized square */ 4123 4124 4123 memreq = image_size(newwidth, newheight, format, type); 4124 switch(type) { 4125 4125 case GL_UNSIGNED_BYTE: 4126 4126 dstImage = (GLubyte *)malloc(memreq); … … 4147 4147 case GL_UNSIGNED_BYTE_2_3_3_REV: 4148 4148 dstImage = (GLubyte *)malloc(memreq); 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 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; 4164 4164 default: 4165 4165 return GLU_INVALID_ENUM; 4166 4166 } 4167 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 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; 4220 4220 case GL_UNSIGNED_BYTE_3_3_2: 4221 4222 4223 4224 4225 4221 scaleInternalPackedPixel(3,extract332,shove332, 4222 width, height,(const void *)usersImage, 4223 newwidth,newheight,(void *)dstImage, 4224 element_size,rowsize,myswap_bytes); 4225 break; 4226 4226 case GL_UNSIGNED_BYTE_2_3_3_REV: 4227 4228 4229 4230 4231 4227 scaleInternalPackedPixel(3,extract233rev,shove233rev, 4228 width, height,(const void *)usersImage, 4229 newwidth,newheight,(void *)dstImage, 4230 element_size,rowsize,myswap_bytes); 4231 break; 4232 4232 case GL_UNSIGNED_SHORT_5_6_5: 4233 4234 4235 4236 4237 4233 scaleInternalPackedPixel(3,extract565,shove565, 4234 width, height,(const void *)usersImage, 4235 newwidth,newheight,(void *)dstImage, 4236 element_size,rowsize,myswap_bytes); 4237 break; 4238 4238 case GL_UNSIGNED_SHORT_5_6_5_REV: 4239 4240 4241 4242 4243 4239 scaleInternalPackedPixel(3,extract565rev,shove565rev, 4240 width, height,(const void *)usersImage, 4241 newwidth,newheight,(void *)dstImage, 4242 element_size,rowsize,myswap_bytes); 4243 break; 4244 4244 case GL_UNSIGNED_SHORT_4_4_4_4: 4245 4246 4247 4248 4249 4245 scaleInternalPackedPixel(4,extract4444,shove4444, 4246 width, height,(const void *)usersImage, 4247 newwidth,newheight,(void *)dstImage, 4248 element_size,rowsize,myswap_bytes); 4249 break; 4250 4250 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 4251 4252 4253 4254 4255 4251 scaleInternalPackedPixel(4,extract4444rev,shove4444rev, 4252 width, height,(const void *)usersImage, 4253 newwidth,newheight,(void *)dstImage, 4254 element_size,rowsize,myswap_bytes); 4255 break; 4256 4256 case GL_UNSIGNED_SHORT_5_5_5_1: 4257 4258 4259 4260 4261 4257 scaleInternalPackedPixel(4,extract5551,shove5551, 4258 width, height,(const void *)usersImage, 4259 newwidth,newheight,(void *)dstImage, 4260 element_size,rowsize,myswap_bytes); 4261 break; 4262 4262 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 4263 4264 4265 4266 4267 4263 scaleInternalPackedPixel(4,extract1555rev,shove1555rev, 4264 width, height,(const void *)usersImage, 4265 newwidth,newheight,(void *)dstImage, 4266 element_size,rowsize,myswap_bytes); 4267 break; 4268 4268 case GL_UNSIGNED_INT_8_8_8_8: 4269 4270 4271 4272 4273 4269 scaleInternalPackedPixel(4,extract8888,shove8888, 4270 width, height,(const void *)usersImage, 4271 newwidth,newheight,(void *)dstImage, 4272 element_size,rowsize,myswap_bytes); 4273 break; 4274 4274 case GL_UNSIGNED_INT_8_8_8_8_REV: 4275 4276 4277 4278 4279 4275 scaleInternalPackedPixel(4,extract8888rev,shove8888rev, 4276 width, height,(const void *)usersImage, 4277 newwidth,newheight,(void *)dstImage, 4278 element_size,rowsize,myswap_bytes); 4279 break; 4280 4280 case GL_UNSIGNED_INT_10_10_10_2: 4281 4282 4283 4284 4285 4281 scaleInternalPackedPixel(4,extract1010102,shove1010102, 4282 width, height,(const void *)usersImage, 4283 newwidth,newheight,(void *)dstImage, 4284 element_size,rowsize,myswap_bytes); 4285 break; 4286 4286 case GL_UNSIGNED_INT_2_10_10_10_REV: 4287 4288 4289 4290 4291 4287 scaleInternalPackedPixel(4,extract2101010rev,shove2101010rev, 4288 width, height,(const void *)usersImage, 4289 newwidth,newheight,(void *)dstImage, 4290 element_size,rowsize,myswap_bytes); 4291 break; 4292 4292 default: 4293 4294 4295 4296 4297 4298 4299 4300 4301 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 */ 4302 4302 { 4303 4304 4305 4306 if (nextHeight < 1) nextHeight= 1; 4307 4308 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); 4309 4309 } 4310 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 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; 4333 4333 case GL_UNSIGNED_BYTE_3_3_2: 4334 4334 case GL_UNSIGNED_BYTE_2_3_3_REV: 4335 4336 4335 dstImage = (GLubyte *)malloc(memreq); 4336 break; 4337 4337 case GL_UNSIGNED_SHORT_5_6_5: 4338 4338 case GL_UNSIGNED_SHORT_5_6_5_REV: 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 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; 4365 4365 } 4366 4366 … … 4368 4368 if (baseLevel <= level && level <= maxLevel) { 4369 4369 glTexImage2D(target, level, internalFormat, newwidth, newheight, 0, 4370 4370 format, type, (void *)srcImage); 4371 4371 } 4372 4372 4373 4373 level++; /* update current level for the loop */ 4374 4374 for (; level <= levels; level++) { 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 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; 4411 4411 case GL_UNSIGNED_BYTE_3_3_2: 4412 4413 4414 4415 4416 4412 halveImagePackedPixel(3,extract332,shove332, 4413 newwidth,newheight, 4414 srcImage,dstImage,element_size,rowsize, 4415 myswap_bytes); 4416 break; 4417 4417 case GL_UNSIGNED_BYTE_2_3_3_REV: 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 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; 4435 4435 case GL_UNSIGNED_SHORT_4_4_4_4: 4436 4437 4438 4439 4440 4436 halveImagePackedPixel(4,extract4444,shove4444, 4437 newwidth,newheight, 4438 srcImage,dstImage,element_size,rowsize, 4439 myswap_bytes); 4440 break; 4441 4441 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 4442 4443 4444 4445 4446 4447 case GL_UNSIGNED_SHORT_5_5_5_1: 4448 4449 4450 4451 4452 4453 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 4454 4455 4456 4457 4458 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; 4459 4459 case GL_UNSIGNED_INT_8_8_8_8: 4460 4461 4462 4463 4464 4460 halveImagePackedPixel(4,extract8888,shove8888, 4461 newwidth,newheight, 4462 srcImage,dstImage,element_size,rowsize, 4463 myswap_bytes); 4464 break; 4465 4465 case GL_UNSIGNED_INT_8_8_8_8_REV: 4466 4467 4468 4469 4470 4466 halveImagePackedPixel(4,extract8888rev,shove8888rev, 4467 newwidth,newheight, 4468 srcImage,dstImage,element_size,rowsize, 4469 myswap_bytes); 4470 break; 4471 4471 case GL_UNSIGNED_INT_10_10_10_2: 4472 4473 4474 4475 4476 4472 halveImagePackedPixel(4,extract1010102,shove1010102, 4473 newwidth,newheight, 4474 srcImage,dstImage,element_size,rowsize, 4475 myswap_bytes); 4476 break; 4477 4477 case GL_UNSIGNED_INT_2_10_10_10_REV: 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 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; 4492 4492 { 4493 4493 /* compute amount to pad per row, if any */ … … 4495 4495 4496 4496 /* should row be padded? */ 4497 if (rowPad == 0) { 4498 4499 4500 4501 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 } 4503 4503 } 4504 else { 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 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! */ 4541 4541 } /* else */ 4542 4542 } … … 4557 4557 GLint GLAPI 4558 4558 gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, 4559 4560 4561 4562 4559 GLsizei width, GLsizei height, 4560 GLenum format, GLenum type, 4561 GLint userLevel, GLint baseLevel, GLint maxLevel, 4562 const void *data) 4563 4563 { 4564 4564 int level, levels; … … 4580 4580 4581 4581 return gluBuild2DMipmapLevelsCore(target, internalFormat, 4582 4583 4584 4585 4586 4582 width, height, 4583 width, height, 4584 format, type, 4585 userLevel, baseLevel, maxLevel, 4586 data); 4587 4587 } /* gluBuild2DMipmapLevels() */ 4588 4588 4589 4589 GLint GLAPI 4590 4590 gluBuild2DMipmaps(GLenum target, GLint internalFormat, 4591 4592 4593 4591 GLsizei width, GLsizei height, 4592 GLenum format, GLenum type, 4593 const void *data) 4594 4594 { 4595 4595 GLint widthPowerOf2, heightPowerOf2; … … 4604 4604 4605 4605 closestFit(target,width,height,internalFormat,format,type, 4606 4606 &widthPowerOf2,&heightPowerOf2); 4607 4607 4608 4608 levels = computeLog(widthPowerOf2); … … 4611 4611 4612 4612 return gluBuild2DMipmapLevelsCore(target,internalFormat, 4613 4614 4615 4616 4613 width, height, 4614 widthPowerOf2,heightPowerOf2, 4615 format,type, 4616 0,0,levels,data); 4617 4617 } /* gluBuild2DMipmaps() */ 4618 4618 4619 4619 /* 4620 4620 ** This routine is for the limited case in which 4621 ** 4622 ** 4621 ** type == GL_UNSIGNED_BYTE && format != index && 4622 ** unpack_alignment = 1 && unpack_swap_bytes == false 4623 4623 ** 4624 4624 ** so all of the work data can be kept as ubytes instead of shorts. 4625 4625 */ 4626 4626 int fastBuild2DMipmaps(const PixelStorageModes *psm, 4627 4628 4629 4627 GLenum target, GLint components, GLint width, 4628 GLint height, GLenum format, 4629 GLenum type, const void *data) 4630 4630 { 4631 4631 GLint newwidth, newheight; … … 4649 4649 #else 4650 4650 closestFit(target,width,height,components,format,type, 4651 4651 &newwidth,&newheight); 4652 4652 #endif 4653 4653 levels = computeLog(newwidth); … … 4663 4663 */ 4664 4664 if (psm->unpack_skip_rows == 0 && psm->unpack_skip_pixels == 0) { 4665 4666 4667 4665 newImage = (GLubyte *)data; 4666 newImage_width = width; 4667 newImage_height = height; 4668 4668 } else { 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 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 } 4708 4708 } 4709 4709 … … 4716 4716 4717 4717 for (level = 0; level <= levels; level++) { 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 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 } 4737 4737 /* 4738 4739 4738 scale_internal_ubyte(cmpts, newImage_width, newImage_height, 4739 newImage, newwidth, newheight, otherImage); 4740 4740 */ 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 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; 4754 4754 } 4755 4755 glPixelStorei(GL_UNPACK_ALIGNMENT, psm->unpack_alignment); … … 4760 4760 4761 4761 if (newImage != (GLubyte *)data) { 4762 4762 free((GLbyte *) newImage); 4763 4763 } 4764 4764 if (otherImage && otherImage != (GLubyte *)data) { 4765 4765 free((GLbyte *) otherImage); 4766 4766 } 4767 4767 return 0; … … 4779 4779 /* If the type is packedpixels then answer is 1 (ignore format) */ 4780 4780 if (type == GL_UNSIGNED_BYTE_3_3_2 || 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 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) { 4792 4792 return 1; 4793 4793 } … … 4797 4797 case GL_RGB: 4798 4798 case GL_BGR: 4799 4799 return 3; 4800 4800 case GL_LUMINANCE_ALPHA: 4801 4801 return 2; 4802 4802 case GL_RGBA: 4803 4803 case GL_BGRA: 4804 4804 return 4; 4805 4805 default: 4806 4806 return 1; 4807 4807 } 4808 4808 } … … 4815 4815 switch(type) { 4816 4816 case GL_BITMAP: 4817 4817 return 1.0 / 8.0; 4818 4818 case GL_UNSIGNED_SHORT: 4819 4819 return(sizeof(GLushort)); 4820 4820 case GL_SHORT: 4821 4821 return(sizeof(GLshort)); 4822 4822 case GL_UNSIGNED_BYTE: 4823 4823 return(sizeof(GLubyte)); 4824 4824 case GL_BYTE: 4825 4825 return(sizeof(GLbyte)); 4826 4826 case GL_INT: 4827 4827 return(sizeof(GLint)); 4828 4828 case GL_UNSIGNED_INT: 4829 4829 return(sizeof(GLuint)); 4830 4830 case GL_FLOAT: 4831 4831 return(sizeof(GLfloat)); 4832 4832 case GL_UNSIGNED_BYTE_3_3_2: 4833 case GL_UNSIGNED_BYTE_2_3_3_REV: 4834 4833 case GL_UNSIGNED_BYTE_2_3_3_REV: 4834 return(sizeof(GLubyte)); 4835 4835 case GL_UNSIGNED_SHORT_5_6_5: 4836 4836 case GL_UNSIGNED_SHORT_5_6_5_REV: … … 4839 4839 case GL_UNSIGNED_SHORT_5_5_5_1: 4840 4840 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 4841 4841 return(sizeof(GLushort)); 4842 4842 case GL_UNSIGNED_INT_8_8_8_8: 4843 4843 case GL_UNSIGNED_INT_8_8_8_8_REV: 4844 4844 case GL_UNSIGNED_INT_10_10_10_2: 4845 4845 case GL_UNSIGNED_INT_2_10_10_10_REV: 4846 4846 return(sizeof(GLuint)); 4847 4847 default: 4848 4848 return 4; 4849 4849 } 4850 4850 } … … 4868 4868 components = elements_per_group(format,type); 4869 4869 if (type == GL_BITMAP) { 4870 4870 bytes_per_row = (width + 7) / 8; 4871 4871 } else { 4872 4872 bytes_per_row = bytes_per_element(type) * width; 4873 4873 } 4874 4874 return bytes_per_row * height * components; … … 4880 4880 */ 4881 4881 static void fill_image(const PixelStorageModes *psm, 4882 4883 4884 4882 GLint width, GLint height, GLenum format, 4883 GLenum type, GLboolean index_format, 4884 const void *userdata, GLushort *newimage) 4885 4885 { 4886 4886 GLint components; … … 4900 4900 components = elements_per_group(format,type); 4901 4901 if (psm->unpack_row_length > 0) { 4902 4902 groups_per_line = psm->unpack_row_length; 4903 4903 } else { 4904 4904 groups_per_line = width; 4905 4905 } 4906 4906 4907 4907 /* All formats except GL_BITMAP fall out trivially */ 4908 4908 if (type == GL_BITMAP) { 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 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 } 4949 4949 } else { 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 case GL_UNSIGNED_SHORT_5_6_5: 4999 5000 5001 5002 5003 5004 case GL_UNSIGNED_SHORT_5_6_5_REV: 5005 5006 5007 5008 5009 5010 case GL_UNSIGNED_SHORT_4_4_4_4: 5011 5012 5013 5014 5015 5016 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 5017 5018 5019 5020 5021 5022 case GL_UNSIGNED_SHORT_5_5_5_1: 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 case GL_UNSIGNED_INT_8_8_8_8: 5055 5056 5057 5058 5059 5060 case GL_UNSIGNED_INT_8_8_8_8_REV: 5061 5062 5063 5064 5065 5066 case GL_UNSIGNED_INT_10_10_10_2: 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 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; 5116 5116 #if 1 5117 5118 5119 5120 iter= start; 5117 /* want 'iter' pointing at start, not within, row for assertion 5118 * purposes 5119 */ 5120 iter= start; 5121 5121 #endif 5122 5122 } /* for i */ 5123 5123 5124 5124 /* iterators should be one byte past end */ 5125 5125 if (!isTypePackedPixel(type)) { 5126 5126 assert(iter2 == &newimage[width*height*components]); 5127 5127 } 5128 5128 else { 5129 5130 5129 assert(iter2 == &newimage[width*height* 5130 elements_per_group(format,NULL)]); 5131 5131 } 5132 5132 assert( iter == &((GLubyte *)userdata)[rowsize*height] ); … … 5140 5140 */ 5141 5141 static void empty_image(const PixelStorageModes *psm, 5142 5143 5144 5142 GLint width, GLint height, GLenum format, 5143 GLenum type, GLboolean index_format, 5144 const GLushort *oldimage, void *userdata) 5145 5145 { 5146 5146 GLint components; … … 5160 5160 components = elements_per_group(format,type); 5161 5161 if (psm->pack_row_length > 0) { 5162 5162 groups_per_line = psm->pack_row_length; 5163 5163 } else { 5164 5164 groups_per_line = width; 5165 5165 } 5166 5166 5167 5167 /* All formats except GL_BITMAP fall out trivially */ 5168 5168 if (type == GL_BITMAP) { 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 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 } 5218 5218 } else { 5219 5219 float shoveComponents[4]; 5220 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 case GL_UNSIGNED_SHORT_5_6_5: 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 case GL_UNSIGNED_SHORT_5_6_5_REV: 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 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; 5293 5293 case GL_UNSIGNED_SHORT_4_4_4_4: 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 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; 5305 5305 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 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; 5455 5455 #if 1 5456 5457 5458 5459 iter= start; 5456 /* want 'iter' pointing at start, not within, row for assertion 5457 * purposes 5458 */ 5459 iter= start; 5460 5460 #endif 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 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] ); 5472 5472 } /* else */ 5473 5473 } /* empty_image() */ … … 5478 5478 */ 5479 5479 static void extract332(int isSwap, 5480 5480 const void *packedPixel, GLfloat extractComponents[]) 5481 5481 { 5482 5482 GLubyte ubyte= *(GLubyte *)packedPixel; 5483 5483 5484 isSwap= isSwap; 5484 isSwap= isSwap; /* turn off warnings */ 5485 5485 5486 5486 /* 11100000 == 0xe0 */ … … 5490 5490 extractComponents[0]= (float)((ubyte & 0xe0) >> 5) / 7.0; 5491 5491 extractComponents[1]= (float)((ubyte & 0x1c) >> 2) / 7.0; /* 7 = 2^3-1 */ 5492 extractComponents[2]= (float)((ubyte & 0x03) ) / 3.0; 5492 extractComponents[2]= (float)((ubyte & 0x03) ) / 3.0; /* 3 = 2^2-1 */ 5493 5493 } /* extract332() */ 5494 5494 5495 5495 static void shove332(const GLfloat shoveComponents[], 5496 int index, void *packedPixel) 5496 int index, void *packedPixel) 5497 5497 { 5498 5498 /* 11100000 == 0xe0 */ … … 5514 5514 5515 5515 static void extract233rev(int isSwap, 5516 5516 const void *packedPixel, GLfloat extractComponents[]) 5517 5517 { 5518 5518 GLubyte ubyte= *(GLubyte *)packedPixel; 5519 5519 5520 isSwap= isSwap; 5520 isSwap= isSwap; /* turn off warnings */ 5521 5521 5522 5522 /* 0000,0111 == 0x07 */ … … 5530 5530 5531 5531 static void shove233rev(const GLfloat shoveComponents[], 5532 int index, void *packedPixel) 5532 int index, void *packedPixel) 5533 5533 { 5534 5534 /* 0000,0111 == 0x07 */ … … 5550 5550 5551 5551 static void extract565(int isSwap, 5552 5552 const void *packedPixel, GLfloat extractComponents[]) 5553 5553 { 5554 5554 GLushort ushort= *(GLushort *)packedPixel; … … 5571 5571 5572 5572 static void shove565(const GLfloat shoveComponents[], 5573 5573 int index,void *packedPixel) 5574 5574 { 5575 5575 /* 11111000,00000000 == 0xf800 */ … … 5591 5591 5592 5592 static void extract565rev(int isSwap, 5593 5593 const void *packedPixel, GLfloat extractComponents[]) 5594 5594 { 5595 5595 GLushort ushort= *(GLushort *)packedPixel; … … 5612 5612 5613 5613 static void shove565rev(const GLfloat shoveComponents[], 5614 5614 int index,void *packedPixel) 5615 5615 { 5616 5616 /* 00000000,00011111 == 0x001f */ … … 5632 5632 5633 5633 static void extract4444(int isSwap,const void *packedPixel, 5634 5634 GLfloat extractComponents[]) 5635 5635 { 5636 5636 GLushort ushort; … … 5655 5655 5656 5656 static void shove4444(const GLfloat shoveComponents[], 5657 5657 int index,void *packedPixel) 5658 5658 { 5659 5659 assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); … … 5674 5674 5675 5675 static void extract4444rev(int isSwap,const void *packedPixel, 5676 5676 GLfloat extractComponents[]) 5677 5677 { 5678 5678 GLushort ushort; … … 5698 5698 5699 5699 static void shove4444rev(const GLfloat shoveComponents[], 5700 5700 int index,void *packedPixel) 5701 5701 { 5702 5702 /* 00000000,00001111 == 0x000f */ … … 5722 5722 5723 5723 static void extract5551(int isSwap,const void *packedPixel, 5724 5724 GLfloat extractComponents[]) 5725 5725 { 5726 5726 GLushort ushort; … … 5745 5745 5746 5746 static void shove5551(const GLfloat shoveComponents[], 5747 5747 int index,void *packedPixel) 5748 5748 { 5749 5749 /* 11111000,00000000 == 0xf800 */ … … 5769 5769 5770 5770 static void extract1555rev(int isSwap,const void *packedPixel, 5771 5771 GLfloat extractComponents[]) 5772 5772 { 5773 5773 GLushort ushort; … … 5793 5793 5794 5794 static void shove1555rev(const GLfloat shoveComponents[], 5795 5795 int index,void *packedPixel) 5796 5796 { 5797 5797 /* 00000000,00011111 == 0x001F */ … … 5817 5817 5818 5818 static void extract8888(int isSwap, 5819 5819 const void *packedPixel, GLfloat extractComponents[]) 5820 5820 { 5821 5821 GLuint uint; … … 5841 5841 5842 5842 static void shove8888(const GLfloat shoveComponents[], 5843 5843 int index,void *packedPixel) 5844 5844 { 5845 5845 /* 11111111,00000000,00000000,00000000 == 0xff000000 */ … … 5865 5865 5866 5866 static void extract8888rev(int isSwap, 5867 5867 const void *packedPixel,GLfloat extractComponents[]) 5868 5868 { 5869 5869 GLuint uint; … … 5889 5889 5890 5890 static void shove8888rev(const GLfloat shoveComponents[], 5891 5891 int index,void *packedPixel) 5892 5892 { 5893 5893 /* 00000000,00000000,00000000,11111111 == 0x000000ff */ … … 5913 5913 5914 5914 static void extract1010102(int isSwap, 5915 5915 const void *packedPixel,GLfloat extractComponents[]) 5916 5916 { 5917 5917 GLuint uint; … … 5937 5937 5938 5938 static void shove1010102(const GLfloat shoveComponents[], 5939 5939 int index,void *packedPixel) 5940 5940 { 5941 5941 /* 11111111,11000000,00000000,00000000 == 0xffc00000 */ … … 5961 5961 5962 5962 static void extract2101010rev(int isSwap, 5963 5964 5963 const void *packedPixel, 5964 GLfloat extractComponents[]) 5965 5965 { 5966 5966 GLuint uint; … … 5987 5987 5988 5988 static void shove2101010rev(const GLfloat shoveComponents[], 5989 5989 int index,void *packedPixel) 5990 5990 { 5991 5991 /* 00000000,00000000,00000011,11111111 == 0x000003FF */ … … 6011 6011 6012 6012 static void scaleInternalPackedPixel(int components, 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 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) 6023 6023 { 6024 6024 float x, convx; … … 6046 6046 6047 6047 if (widthIn == widthOut*2 && heightIn == heightOut*2) { 6048 6049 6050 6051 6048 halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel, 6049 widthIn, heightIn, dataIn, dataOut, 6050 pixelSizeInBytes,rowSizeInBytes,isSwap); 6051 return; 6052 6052 } 6053 6053 convy = (float) heightIn/heightOut; … … 6066 6066 6067 6067 for (i = 0; i < heightOut; i++) { 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 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); 6088 6088 #if 0 6089 6090 6091 6092 6093 6094 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 } 6097 6097 #else 6098 6099 6100 6101 6098 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6099 for (k = 0; k < components; k++) { 6100 totals[k]+= extractTotals[k] * percent; 6101 } 6102 6102 #endif 6103 6104 6105 6103 left = temp; 6104 for(l = lowx_int+1; l < highx_int; l++) { 6105 temp += pixelSizeInBytes; 6106 6106 #if 0 6107 6108 6107 for (k = 0, temp_index = temp; k < components; 6108 k++, temp_index += element_size) { 6109 6109 if (myswap_bytes) { 6110 6110 totals[k] += … … 6113 6113 totals[k] += *(GLushort*)temp_index * y_percent; 6114 6114 } 6115 6115 } 6116 6116 #else 6117 6118 6119 6120 6117 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6118 for (k = 0; k < components; k++) { 6119 totals[k]+= extractTotals[k] * y_percent; 6120 } 6121 6121 #endif 6122 6123 6124 6125 6122 } 6123 temp += pixelSizeInBytes; 6124 right = temp; 6125 percent = y_percent * highx_float; 6126 6126 #if 0 6127 6127 for (k = 0, temp_index = temp; k < components; 6128 6128 k++, temp_index += element_size) { 6129 6129 if (myswap_bytes) { 6130 6130 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6134 6134 } 6135 6135 #else 6136 6137 6138 6139 6136 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6137 for (k = 0; k < components; k++) { 6138 totals[k]+= extractTotals[k] * percent; 6139 } 6140 6140 #endif 6141 6141 6142 6143 6144 6145 6146 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; 6147 6147 #if 0 6148 6148 for (k = 0, temp_index = temp; k < components; 6149 6149 k++, temp_index += element_size) { 6150 6150 if (myswap_bytes) { 6151 6151 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6155 6155 } 6156 6156 #else 6157 6158 6159 6160 6157 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6158 for (k = 0; k < components; k++) { 6159 totals[k]+= extractTotals[k] * percent; 6160 } 6161 6161 #endif 6162 6162 for(l = lowx_int+1; l < highx_int; l++) { 6163 6163 temp += pixelSizeInBytes; 6164 6164 #if 0 6165 6165 for (k = 0, temp_index = temp; k < components; 6166 6166 k++, temp_index += element_size) { 6167 6167 if (myswap_bytes) { 6168 6168 totals[k] += … … 6173 6173 } 6174 6174 #else 6175 6176 6177 6178 6175 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6176 for (k = 0; k < components; k++) { 6177 totals[k]+= extractTotals[k] * y_percent; 6178 } 6179 6179 #endif 6180 6180 6181 6181 } 6182 6182 temp += pixelSizeInBytes; 6183 6183 percent = y_percent * highx_float; 6184 6184 #if 0 6185 6185 for (k = 0, temp_index = temp; k < components; 6186 6186 k++, temp_index += element_size) { 6187 6187 if (myswap_bytes) { 6188 6188 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6192 6192 } 6193 6193 #else 6194 6195 6196 6197 6194 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6195 for (k = 0; k < components; k++) { 6196 totals[k]+= extractTotals[k] * percent; 6197 } 6198 6198 #endif 6199 6199 6200 6201 6202 6203 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; 6204 6204 #if 0 6205 6205 for (k = 0; k < components; 6206 6206 k++, left += element_size, right += element_size) { 6207 6207 if (myswap_bytes) { 6208 6208 totals[k] += 6209 6210 6209 __GLU_SWAP_2_BYTES(left) * (1-lowx_float) + 6210 __GLU_SWAP_2_BYTES(right) * highx_float; 6211 6211 } else { 6212 6212 totals[k] += *(GLushort*)left * (1-lowx_float) 6213 6213 + *(GLushort*)right * highx_float; 6214 6214 } 6215 6215 } 6216 6216 #else 6217 6218 6219 6220 6221 6222 6223 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 } 6225 6225 #endif 6226 6227 6228 6229 6230 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; 6231 6231 #if 0 6232 6232 for (k = 0, temp_index = temp; k < components; 6233 6233 k++, temp_index += element_size) { 6234 6234 if (myswap_bytes) { 6235 6235 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6237 6237 totals[k] += *(GLushort*)temp_index * percent; 6238 6238 } 6239 6239 } 6240 6240 #else 6241 6242 6243 6244 6241 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6242 for (k = 0; k < components; k++) { 6243 totals[k]+= extractTotals[k] * percent; 6244 } 6245 6245 #endif 6246 6247 6246 for(m = lowy_int+1; m < highy_int; m++) { 6247 temp += rowSizeInBytes; 6248 6248 #if 0 6249 6249 for (k = 0, temp_index = temp; k < components; 6250 6250 k++, temp_index += element_size) { 6251 6251 if (myswap_bytes) { 6252 6252 totals[k] += 6253 6253 __GLU_SWAP_2_BYTES(temp_index) * x_percent; 6254 6254 } else { 6255 6255 totals[k] += *(GLushort*)temp_index * x_percent; 6256 6256 } 6257 6257 } 6258 6258 #else 6259 6260 6261 6262 6259 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6260 for (k = 0; k < components; k++) { 6261 totals[k]+= extractTotals[k] * x_percent; 6262 } 6263 6263 #endif 6264 6265 6266 6264 } 6265 percent = x_percent * highy_float; 6266 temp += rowSizeInBytes; 6267 6267 #if 0 6268 6268 for (k = 0, temp_index = temp; k < components; 6269 6269 k++, temp_index += element_size) { 6270 6270 if (myswap_bytes) { 6271 6271 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6275 6275 } 6276 6276 #else 6277 6278 6279 6280 6277 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6278 for (k = 0; k < components; k++) { 6279 totals[k]+= extractTotals[k] * percent; 6280 } 6281 6281 #endif 6282 6283 6284 6285 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; 6286 6286 #if 0 6287 6287 for (k = 0, temp_index = temp; k < components; 6288 6288 k++, temp_index += element_size) { 6289 6289 if (myswap_bytes) { 6290 6290 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6294 6294 } 6295 6295 #else 6296 6297 6298 6299 6296 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6297 for (k = 0; k < components; k++) { 6298 totals[k]+= extractTotals[k] * percent; 6299 } 6300 6300 #endif 6301 6301 for (l = lowx_int+1; l < highx_int; l++) { 6302 6302 temp += pixelSizeInBytes; 6303 6303 #if 0 6304 6304 for (k = 0, temp_index = temp; k < components; 6305 6305 k++, temp_index += element_size) { 6306 6306 if (myswap_bytes) { 6307 6307 totals[k] += 6308 6308 __GLU_SWAP_2_BYTES(temp_index) * y_percent; 6309 6309 } else { 6310 6310 totals[k] += *(GLushort*)temp_index * y_percent; 6311 6311 } 6312 6312 } 6313 6313 #else 6314 6315 6316 6317 6314 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6315 for (k = 0; k < components; k++) { 6316 totals[k]+= extractTotals[k] * y_percent; 6317 } 6318 6318 #endif 6319 6320 6321 6319 } 6320 temp += pixelSizeInBytes; 6321 percent = y_percent * highx_float; 6322 6322 #if 0 6323 6323 for (k = 0, temp_index = temp; k < components; 6324 6324 k++, temp_index += element_size) { 6325 6325 if (myswap_bytes) { 6326 6326 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6328 6328 totals[k] += *(GLushort*)temp_index * percent; 6329 6329 } 6330 6330 } 6331 6331 #else 6332 6333 6334 6335 6332 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6333 for (k = 0; k < components; k++) { 6334 totals[k]+= extractTotals[k] * percent; 6335 } 6336 6336 #endif 6337 6338 6339 6337 } else { 6338 percent = (highy_float-lowy_float)*(highx_float-lowx_float); 6339 temp = (char *)dataIn + xindex + lowy_int * rowSizeInBytes; 6340 6340 #if 0 6341 6341 for (k = 0, temp_index = temp; k < components; 6342 6342 k++, temp_index += element_size) { 6343 6343 if (myswap_bytes) { 6344 6344 totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; … … 6348 6348 } 6349 6349 #else 6350 6351 6352 6353 6350 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6351 for (k = 0; k < components; k++) { 6352 totals[k]+= extractTotals[k] * percent; 6353 } 6354 6354 #endif 6355 6356 6357 6358 6359 6360 6361 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++) { 6362 6362 #if 0 6363 6363 for (k = 0, temp_index = temp; k < components; 6364 6364 k++, temp_index += element_size) { 6365 6365 if (myswap_bytes) { 6366 6366 totals[k] += __GLU_SWAP_2_BYTES(temp_index); … … 6370 6370 } 6371 6371 #else 6372 6373 6374 6375 6372 (*extractPackedPixel)(isSwap,(void *)temp,extractTotals); 6373 for (k = 0; k < components; k++) { 6374 totals[k]+= extractTotals[k]; 6375 } 6376 6376 #endif 6377 6377 temp += pixelSizeInBytes; 6378 6378 } 6379 6380 6381 6382 6379 temp0 += rowSizeInBytes; 6380 } 6381 6382 outindex = (j + (i * widthOut)); /* * (components == 1) */ 6383 6383 #if 0 6384 6385 6386 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 } 6388 6388 #else 6389 6390 6391 6392 6389 for (k = 0; k < components; k++) { 6390 shoveTotals[k]= totals[k]/area; 6391 } 6392 (*shovePackedPixel)(shoveTotals,outindex,(void *)dataOut); 6393 6393 #endif 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 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 } 6411 6411 } 6412 6412 … … 6418 6418 */ 6419 6419 static void halveImagePackedPixel(int components, 6420 6421 6422 6423 6424 6425 6426 6427 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) 6428 6428 { 6429 6429 /* handle case where there is only 1 column/row */ … … 6431 6431 assert(!(width == 1 && height == 1)); /* can't be 1x1 */ 6432 6432 halve1DimagePackedPixel(components,extractPackedPixel,shovePackedPixel, 6433 6434 6433 width,height,dataIn,dataOut,pixelSizeInBytes, 6434 rowSizeInBytes,isSwap); 6435 6435 return; 6436 6436 } … … 6446 6446 6447 6447 for (ii= 0; ii< halfHeight; ii++) { 6448 6448 for (jj= 0; jj< halfWidth; jj++) { 6449 6449 #define BOX4 4 6450 float totals[4];/* 4 is maximum components */6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 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; 6497 6497 } 6498 6498 … … 6504 6504 6505 6505 static void halve1DimagePackedPixel(int components, 6506 6507 6508 6509 6510 6511 6512 6513 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) 6514 6514 { 6515 6515 int halfWidth= width / 2; … … 6519 6519 6520 6520 assert(width == 1 || height == 1); /* must be 1D */ 6521 assert(width != height); 6522 6523 if (height == 1) { 6521 assert(width != height); /* can't be square */ 6522 6523 if (height == 1) { /* 1 row */ 6524 6524 int outIndex= 0; 6525 6525 6526 assert(width != 1); 6526 assert(width != 1); /* widthxheight can't be 1x1 */ 6527 6527 halfHeight= 1; 6528 6528 … … 6531 6531 for (jj= 0; jj< halfWidth; jj++) { 6532 6532 #define BOX2 2 6533 float totals[4];/* 4 is maximum components */6534 6535 6536 6537 6538 6539 6540 6541 &extractTotals[1][0]); 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 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; 6560 6560 } 6561 6561 6562 6562 { 6563 6564 src+= padBytes;/* for assertion only */6563 int padBytes= rowSizeInBytes - (width*pixelSizeInBytes); 6564 src+= padBytes; /* for assertion only */ 6565 6565 } 6566 6566 assert(src == &((char *)dataIn)[rowSizeInBytes]); … … 6570 6570 int outIndex= 0; 6571 6571 6572 assert(height != 1); 6572 assert(height != 1); /* widthxheight can't be 1x1 */ 6573 6573 halfWidth= 1; 6574 6574 /* one vertical column with possible pad bytes per row */ … … 6577 6577 for (jj= 0; jj< halfHeight; jj++) { 6578 6578 #define BOX2 2 6579 float totals[4];/* 4 is maximum components */6580 6581 6582 6583 6584 6585 6586 6587 &extractTotals[1][0]); 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 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 */ 6605 6605 } 6606 6606 … … 6613 6613 6614 6614 static GLint imageSize3D(GLint width, GLint height, GLint depth, 6615 6615 GLenum format, GLenum type) 6616 6616 { 6617 6617 int components= elements_per_group(format,type); … … 6625 6625 6626 6626 static void fillImage3D(const PixelStorageModes *psm, 6627 6628 6629 6627 GLint width, GLint height, GLint depth, GLenum format, 6628 GLenum type, GLboolean indexFormat, 6629 const void *userImage, GLushort *newImage) 6630 6630 { 6631 6631 int myswapBytes; … … 6683 6683 6684 6684 for (hh= 0; hh < height; hh++) { 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 case GL_UNSIGNED_SHORT_5_6_5: 6720 6721 6722 6723 6724 6725 case GL_UNSIGNED_SHORT_5_6_5_REV: 6726 6727 6728 6729 6730 6731 case GL_UNSIGNED_SHORT_4_4_4_4: 6732 6733 6734 6735 6736 6737 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 6738 6739 6740 6741 6742 6743 case GL_UNSIGNED_SHORT_5_5_5_1: 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 case GL_UNSIGNED_INT_8_8_8_8: 6776 6777 6778 6779 6780 6781 case GL_UNSIGNED_INT_8_8_8_8_REV: 6782 6783 6784 6785 6786 6787 case GL_UNSIGNED_INT_10_10_10_2: 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 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; 6833 6833 default: 6834 6835 6836 6837 6838 6839 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 */ 6842 6842 } /* for hh */ 6843 6843 … … 6851 6851 else { 6852 6852 assert(iter2 == &newImage[width*height*depth* 6853 6853 elements_per_group(format,NULL)]); 6854 6854 } 6855 6855 assert( iter == &((GLubyte *)userImage)[rowSize*height*depth] ); … … 6857 6857 6858 6858 static void scaleInternal3D(GLint components, 6859 6860 6861 6862 6859 GLint widthIn, GLint heightIn, GLint depthIn, 6860 const GLushort *dataIn, 6861 GLint widthOut, GLint heightOut, GLint depthOut, 6862 GLushort *dataOut) 6863 6863 { 6864 6864 float x, lowx, highx, convx, halfconvx; … … 6882 6882 z = convz * (d+0.5); 6883 6883 if (depthIn > depthOut) { 6884 6885 6884 highz = z + halfconvz; 6885 lowz = z - halfconvz; 6886 6886 } else { 6887 6888 6887 highz = z + 0.5; 6888 lowz = z - 0.5; 6889 6889 } 6890 6890 for (i = 0; i < heightOut; i++) { 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 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 */ 6983 6983 } /* for i */ 6984 6984 } /* for d */ … … 6986 6986 6987 6987 static void emptyImage3D(const PixelStorageModes *psm, 6988 6989 6990 6988 GLint width, GLint height, GLint depth, 6989 GLenum format, GLenum type, GLboolean indexFormat, 6990 const GLushort *oldImage, void *userImage) 6991 6991 { 6992 6992 int myswapBytes; … … 7046 7046 7047 7047 for (ii= 0; ii< height; ii++) { 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 case GL_UNSIGNED_SHORT_5_6_5: 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 case GL_UNSIGNED_SHORT_5_6_5_REV: 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 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; 7272 7272 } /* for ii */ 7273 7273 … … 7281 7281 else { 7282 7282 assert(iter2 == &oldImage[width*height*depth* 7283 7283 elements_per_group(format,NULL)]); 7284 7284 } 7285 7285 assert( iter == &((GLubyte *)userImage)[rowSize*height*depth] ); … … 7287 7287 7288 7288 int gluScaleImage3D(GLenum format, 7289 7290 7291 7292 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) 7293 7293 { 7294 7294 int components; … … 7330 7330 components = elements_per_group(format,NULL); 7331 7331 scaleInternal3D(components,widthIn,heightIn,depthIn,beforeImage, 7332 7332 widthOut,heightOut,depthOut,afterImage); 7333 7333 emptyImage3D(&psm,widthOut,heightOut,depthOut,format,typeOut, 7334 7334 is_index(format),afterImage, dataOut); 7335 7335 free((void *) beforeImage); 7336 7336 free((void *) afterImage); … … 7340 7340 7341 7341 static void closestFit3D(GLenum target, GLint width, GLint height, GLint depth, 7342 7343 7342 GLint internalFormat, GLenum format, GLenum type, 7343 GLint *newWidth, GLint *newHeight, GLint *newDepth) 7344 7344 { 7345 7345 GLint widthPowerOf2= nearestPower(width); 7346 GLint heightPowerOf2= nearestPower(height); 7346 GLint heightPowerOf2= nearestPower(height); 7347 7347 GLint depthPowerOf2= nearestPower(depth); 7348 7348 GLint proxyWidth; … … 7351 7351 /* compute level 1 width & height & depth, clamping each at 1 */ 7352 7352 GLint widthAtLevelOne= (widthPowerOf2 > 1) ? 7353 7354 7353 widthPowerOf2 >> 1 : 7354 widthPowerOf2; 7355 7355 GLint heightAtLevelOne= (heightPowerOf2 > 1) ? 7356 7357 7356 heightPowerOf2 >> 1 : 7357 heightPowerOf2; 7358 7358 GLint depthAtLevelOne= (depthPowerOf2 > 1) ? 7359 7360 7359 depthPowerOf2 >> 1 : 7360 depthPowerOf2; 7361 7361 GLenum proxyTarget; 7362 7362 assert(widthAtLevelOne > 0); … … 7366 7366 /* does width x height x depth at level 1 & all their mipmaps fit? */ 7367 7367 if (target == GL_TEXTURE_3D || target == GL_PROXY_TEXTURE_3D) { 7368 7369 glTexImage3D(proxyTarget, 1, /* must be non-zero*/7370 7371 7372 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); 7373 7373 } 7374 7374 glGetTexLevelParameteriv(proxyTarget, 1,GL_TEXTURE_WIDTH,&proxyWidth); 7375 7375 /* does it fit??? */ 7376 7376 if (proxyWidth == 0) { /* nope, so try again with these sizes */ 7377 7378 7379 7380 7381 7382 7383 7384 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; 7385 7385 } 7386 7386 /* else it does fit */ … … 7396 7396 7397 7397 static void halveImagePackedPixelSlice(int components, 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 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) 7408 7408 { 7409 7409 int ii, jj; … … 7417 7417 assert((width == 1 || height == 1) && depth >= 2); 7418 7418 7419 if (width == height) { 7419 if (width == height) { /* a 1-pixel column viewed from top */ 7420 7420 assert(width == 1 && height == 1); 7421 7421 assert(depth >= 2); 7422 7422 7423 7423 for (ii= 0; ii< halfDepth; ii++) { 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 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; 7449 7449 } /* for ii */ 7450 7450 } 7451 else if (height == 1) { 7451 else if (height == 1) { /* horizontal slice viewed from top */ 7452 7452 assert(width != 1); 7453 7453 7454 7454 for (ii= 0; ii< halfDepth; ii++) { 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 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 } 7489 7489 } 7490 7490 7491 7491 /* assert() */ 7492 7492 } 7493 else if (width == 1) { 7493 else if (width == 1) { /* vertical slice viewed from top */ 7494 7494 assert(height != 1); 7495 7495 7496 7496 for (ii= 0; ii< halfDepth; ii++) { 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 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 } 7532 7532 } 7533 7533 /* assert() */ … … 7537 7537 7538 7538 static void halveImagePackedPixel3D(int components, 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 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) 7549 7549 { 7550 7550 if (depth == 1) { … … 7552 7552 7553 7553 halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel, 7554 7555 7554 width,height,dataIn,dataOut,pixelSizeInBytes, 7555 rowSizeInBytes,isSwap); 7556 7556 return; 7557 7557 } … … 7561 7561 7562 7562 halveImagePackedPixelSlice(components, 7563 7564 7565 7566 7563 extractPackedPixel,shovePackedPixel, 7564 width, height, depth, dataIn, dataOut, 7565 pixelSizeInBytes, rowSizeInBytes, 7566 imageSizeInBytes, isSwap); 7567 7567 return; 7568 7568 } … … 7578 7578 7579 7579 for (dd= 0; dd < halfDepth; dd++) { 7580 7581 7580 for (ii= 0; ii< halfHeight; ii++) { 7581 for (jj= 0; jj< halfWidth; jj++) { 7582 7582 #define BOX8 8 7583 float totals[4];/* 4 is maximum components */7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 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; 7645 7645 } /* for dd */ 7646 7646 … … 7653 7653 7654 7654 static int gluBuild3DMipmapLevelsCore(GLenum target, GLint internalFormat, 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 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) 7665 7665 { 7666 7666 GLint newWidth, newHeight, newDepth; … … 7727 7727 7728 7728 usersImage = (GLubyte *)data + psm.unpack_skip_rows * rowSize + 7729 7730 7731 7729 psm.unpack_skip_pixels * groupSize + 7730 /* 3dstuff */ 7731 psm.unpack_skip_images * imageSize; 7732 7732 7733 7733 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); … … 7742 7742 /* Use usersImage for level userLevel */ 7743 7743 if (baseLevel <= level && level <= maxLevel) { 7744 glTexImage3D (target, level, internalFormat, width,7745 7746 7744 glTexImage3DEXT(target, level, internalFormat, width, 7745 height, depth, 0, format, type, 7746 (void *) usersImage); 7747 7747 } 7748 7748 if(levels == 0) { /* we're done. clean up and return */ 7749 7750 7751 7752 7753 7754 7755 7756 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; 7757 7757 } 7758 7758 { 7759 7760 7761 7762 7763 7764 7765 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; 7767 7767 memReq = imageSize3D(nextWidth, nextHeight, nextDepth, format, type); 7768 7768 } 7769 7769 switch(type) { 7770 7770 case GL_UNSIGNED_BYTE: 7771 7772 7771 dstImage = (GLubyte *)malloc(memReq); 7772 break; 7773 7773 case GL_BYTE: 7774 7775 7774 dstImage = (GLbyte *)malloc(memReq); 7775 break; 7776 7776 case GL_UNSIGNED_SHORT: 7777 7778 7777 dstImage = (GLushort *)malloc(memReq); 7778 break; 7779 7779 case GL_SHORT: 7780 7781 7780 dstImage = (GLshort *)malloc(memReq); 7781 break; 7782 7782 case GL_UNSIGNED_INT: 7783 7784 7783 dstImage = (GLuint *)malloc(memReq); 7784 break; 7785 7785 case GL_INT: 7786 7787 7786 dstImage = (GLint *)malloc(memReq); 7787 break; 7788 7788 case GL_FLOAT: 7789 7790 7789 dstImage = (GLfloat *)malloc(memReq); 7790 break; 7791 7791 case GL_UNSIGNED_BYTE_3_3_2: 7792 7792 case GL_UNSIGNED_BYTE_2_3_3_REV: 7793 7794 7793 dstImage = (GLubyte *)malloc(memReq); 7794 break; 7795 7795 case GL_UNSIGNED_SHORT_5_6_5: 7796 7796 case GL_UNSIGNED_SHORT_5_6_5_REV: … … 7932 7932 case GL_UNSIGNED_SHORT_5_6_5_REV: 7933 7933 halveImagePackedPixel3D(3,extract565rev,shove565rev, 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 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 } 7981 7981 newWidth = width/2; 7982 7982 newHeight = height/2; … … 7995 7995 switch(type) { 7996 7996 case GL_UNSIGNED_BYTE: 7997 7998 7997 dstImage = (GLubyte *)malloc(memReq); 7998 break; 7999 7999 case GL_BYTE: 8000 8001 8000 dstImage = (GLbyte *)malloc(memReq); 8001 break; 8002 8002 case GL_UNSIGNED_SHORT: 8003 8004 8003 dstImage = (GLushort *)malloc(memReq); 8004 break; 8005 8005 case GL_SHORT: 8006 8007 8006 dstImage = (GLshort *)malloc(memReq); 8007 break; 8008 8008 case GL_UNSIGNED_INT: 8009 8010 8009 dstImage = (GLuint *)malloc(memReq); 8010 break; 8011 8011 case GL_INT: 8012 8013 8012 dstImage = (GLint *)malloc(memReq); 8013 break; 8014 8014 case GL_FLOAT: 8015 8016 8015 dstImage = (GLfloat *)malloc(memReq); 8016 break; 8017 8017 case GL_UNSIGNED_BYTE_3_3_2: 8018 8018 case GL_UNSIGNED_BYTE_2_3_3_REV: 8019 8020 8019 dstImage = (GLubyte *)malloc(memReq); 8020 break; 8021 8021 case GL_UNSIGNED_SHORT_5_6_5: 8022 8022 case GL_UNSIGNED_SHORT_5_6_5_REV: … … 8025 8025 case GL_UNSIGNED_SHORT_5_5_5_1: 8026 8026 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 8027 8028 8027 dstImage = (GLushort *)malloc(memReq); 8028 break; 8029 8029 case GL_UNSIGNED_INT_8_8_8_8: 8030 8030 case GL_UNSIGNED_INT_8_8_8_8_REV: 8031 8031 case GL_UNSIGNED_INT_10_10_10_2: 8032 8032 case GL_UNSIGNED_INT_2_10_10_10_REV: 8033 8034 8033 dstImage = (GLuint *)malloc(memReq); 8034 break; 8035 8035 default: 8036 8036 return GLU_INVALID_ENUM; /* assertion */ 8037 8037 } 8038 8038 if (dstImage == NULL) { 8039 8040 8041 8042 8043 8044 8045 8046 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; 8047 8047 } 8048 8048 /* level userLevel+1 is in srcImage; level userLevel already saved */ … … 8051 8051 memReq = imageSize3D(newWidth, newHeight, newDepth, format, type); 8052 8052 switch(type) { 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 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 */ 8094 8094 } 8095 8095 8096 8096 if (dstImage == NULL) { 8097 8098 8099 8100 8101 8102 8103 8104 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; 8105 8105 } 8106 8106 /*printf("Build3DMipmaps(): ScaleImage3D %d %d %d->%d %d %d\n", … … 8108 8108 8109 8109 gluScaleImage3D(format, width, height, depth, type, usersImage, 8110 8110 newWidth, newHeight, newDepth, type, dstImage); 8111 8111 8112 8112 myswapBytes = 0; … … 8117 8117 8118 8118 if(levels != 0) { /* use as little memory as possible */ 8119 8120 8121 8122 8123 8124 if (nextHeight < 1) nextHeight= 1; 8125 if (nextDepth < 1) nextDepth= 1; 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 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 } 8182 8182 } 8183 8183 /* level userLevel is in srcImage; nothing saved yet */ 8184 level = userLevel; 8184 level = userLevel; 8185 8185 } 8186 8186 8187 8187 glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); 8188 8188 if (baseLevel <= level && level <= maxLevel) { 8189 glTexImage3D (target, level, internalFormat, newWidth, newHeight, newDepth,8190 8189 glTexImage3DEXT(target, level, internalFormat, newWidth, newHeight, newDepth, 8190 0,format, type, (void *)srcImage); 8191 8191 } 8192 8192 level++; /* update current level for the loop */ … … 8303 8303 break; 8304 8304 case GL_UNSIGNED_SHORT_5_6_5_REV: 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 case GL_UNSIGNED_SHORT_5_5_5_1: 8323 8324 8325 8326 8327 8328 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 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; 8361 8361 } 8362 8362 … … 8367 8367 if (newDepth > 1) newDepth /= 2; 8368 8368 { 8369 8370 8371 glTexImage3D(target, level, internalFormat, newWidth, newHeight,8372 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 } 8374 8374 } 8375 8375 } /* for level */ … … 8391 8391 GLint GLAPI 8392 8392 gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, 8393 8394 8395 8396 8393 GLsizei width, GLsizei height, GLsizei depth, 8394 GLenum format, GLenum type, 8395 GLint userLevel, GLint baseLevel, GLint maxLevel, 8396 const void *data) 8397 8397 { 8398 8398 int level, levels; … … 8420 8420 8421 8421 return gluBuild3DMipmapLevelsCore(target, internalFormat, 8422 8423 8424 8425 8426 8422 width, height, depth, 8423 width, height, depth, 8424 format, type, 8425 userLevel, baseLevel, maxLevel, 8426 data); 8427 8427 } /* gluBuild3DMipmapLevels() */ 8428 8428 8429 8429 GLint GLAPI 8430 8430 gluBuild3DMipmaps(GLenum target, GLint internalFormat, 8431 8432 8431 GLsizei width, GLsizei height, GLsizei depth, 8432 GLenum format, GLenum type, const void *data) 8433 8433 { 8434 8434 GLint widthPowerOf2, heightPowerOf2, depthPowerOf2; … … 8447 8447 8448 8448 closestFit3D(target,width,height,depth,internalFormat,format,type, 8449 8449 &widthPowerOf2,&heightPowerOf2,&depthPowerOf2); 8450 8450 8451 8451 levels = computeLog(widthPowerOf2); … … 8456 8456 8457 8457 return gluBuild3DMipmapLevelsCore(target, internalFormat, 8458 8459 8460 8461 8462 8458 width, height, depth, 8459 widthPowerOf2, heightPowerOf2, 8460 depthPowerOf2, 8461 format, type, 0, 0, levels, 8462 data); 8463 8463 } /* gluBuild3DMipmaps() */ 8464 8464 8465 8465 static GLdouble extractUbyte(int isSwap, const void *ubyte) 8466 8466 { 8467 isSwap= isSwap; 8467 isSwap= isSwap; /* turn off warnings */ 8468 8468 8469 8469 assert(*((GLubyte *)ubyte) <= 255); … … 8481 8481 static GLdouble extractSbyte(int isSwap, const void *sbyte) 8482 8482 { 8483 isSwap= isSwap; 8483 isSwap= isSwap; /* turn off warnings */ 8484 8484 8485 8485 assert(*((GLbyte *)sbyte) <= 127); … … 8609 8609 8610 8610 static void halveImageSlice(int components, 8611 8612 8613 8614 8615 8616 8617 8618 8619 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) 8620 8620 { 8621 8621 int ii, jj; … … 8629 8629 assert((width == 1 || height == 1) && depth >= 2); 8630 8630 8631 if (width == height) { 8631 if (width == height) { /* a 1-pixel column viewed from top */ 8632 8632 /* printf("1-column\n");*/ 8633 8633 assert(width == 1 && height == 1); … … 8635 8635 8636 8636 for (ii= 0; ii< halfDepth; ii++) { 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 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; 8665 8665 } /* for ii */ 8666 8666 … … 8668 8668 assert(outIndex == halfDepth * components); 8669 8669 } 8670 else if (height == 1) { 8670 else if (height == 1) { /* horizontal slice viewed from top */ 8671 8671 /* printf("horizontal slice\n"); */ 8672 8672 assert(width != 1); 8673 8673 8674 8674 for (ii= 0; ii< halfDepth; ii++) { 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 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; 8714 8714 } /* for ii */ 8715 8715 … … 8717 8717 assert(outIndex == halfWidth * halfDepth * components); 8718 8718 } 8719 else if (width == 1) { 8719 else if (width == 1) { /* vertical slice viewed from top */ 8720 8720 /* printf("vertical slice\n"); */ 8721 8721 assert(height != 1); 8722 8722 8723 8723 for (ii= 0; ii< halfDepth; ii++) { 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 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; 8763 8763 } /* for ii */ 8764 8764 … … 8770 8770 8771 8771 static void halveImage3D(int components, 8772 8773 8774 8775 8776 8777 8778 8779 8780 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) 8781 8781 { 8782 8782 assert(depth > 1); … … 8787 8787 8788 8788 halveImageSlice(components,extract,shove, width, height, depth, 8789 8790 8789 dataIn, dataOut, elementSizeInBytes, groupSizeInBytes, 8790 rowSizeInBytes, imageSizeInBytes, isSwap); 8791 8791 return; 8792 8792 } … … 8802 8802 8803 8803 for (dd= 0; dd < halfDepth; dd++) { 8804 8805 8806 8807 8808 8809 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; 8810 8810 #define BOX8 8 8811 double totals[4];/* 4 is maximum components */8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 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; 8872 8872 } /* for dd */ 8873 8873
Note:
See TracChangeset
for help on using the changeset viewer.