📄 mipmap.c
字号:
if (!myswap_bytes) for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { /* need to cast to double to hold large unsigned ints */ s[0] = ((double)*(const GLuint*)t + (double)*(const GLuint*)(t+group_size) + (double)*(const GLuint*)(t+ysize) + (double)*(const GLuint*)(t+ysize+group_size))/4 + 0.5; s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; } else for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { /* need to cast to double to hold large unsigned ints */ GLdouble buf; buf = (GLdouble)__GLU_SWAP_4_BYTES(t) + (GLdouble)__GLU_SWAP_4_BYTES(t+group_size) + (GLdouble)__GLU_SWAP_4_BYTES(t+ysize) + (GLdouble)__GLU_SWAP_4_BYTES(t+ysize+group_size); s[0] = (GLuint)(buf/4 + 0.5); s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; }}/* */static void halve1Dimage_uint(GLint components, GLuint width, GLuint height, const GLuint *dataIn, GLuint *dataOut, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ GLint halfWidth= width / 2; GLint halfHeight= height / 2; const char *src= (const char *) dataIn; GLuint *dest= dataOut; int jj; assert(width == 1 || height == 1); /* must be 1D */ assert(width != height); /* can't be square */ if (height == 1) { /* 1 row */ assert(width != 1); /* widthxheight can't be 1x1 */ halfHeight= 1; for (jj= 0; jj< halfWidth; jj++) { int kk; for (kk= 0; kk< components; kk++) {#define BOX2 2 GLuint uint[BOX2]; if (myswap_bytes) { uint[0]= __GLU_SWAP_4_BYTES(src); uint[1]= __GLU_SWAP_4_BYTES(src+group_size); } else { uint[0]= *(const GLuint*)src; uint[1]= *(const GLuint*)(src+group_size); } *dest= ((double)uint[0]+(double)uint[1])/2.0; src+= element_size; dest++; } src+= group_size; /* skip to next 2 */ } { int padBytes= ysize - (width*group_size); src+= padBytes; /* for assertion only */ } } else if (width == 1) { /* 1 column */ int padBytes= ysize - (width * group_size); assert(height != 1); /* widthxheight can't be 1x1 */ halfWidth= 1; /* one vertical column with possible pad bytes per row */ /* average two at a time */ for (jj= 0; jj< halfHeight; jj++) { int kk; for (kk= 0; kk< components; kk++) {#define BOX2 2 GLuint uint[BOX2]; if (myswap_bytes) { uint[0]= __GLU_SWAP_4_BYTES(src); uint[1]= __GLU_SWAP_4_BYTES(src+ysize); } else { uint[0]= *(const GLuint*)src; uint[1]= *(const GLuint*)(src+ysize); } *dest= ((double)uint[0]+(double)uint[1])/2.0; src+= element_size; dest++; } src+= padBytes; /* add pad bytes, if any, to get to end to row */ src+= ysize; } assert(src == &((const char *)dataIn)[ysize*height]); } assert((char *)dest == &((char *)dataOut) [components * element_size * halfWidth * halfHeight]);} /* halve1Dimage_uint() */static void halveImage_int(GLint components, GLuint width, GLuint height, const GLint *datain, GLint *dataout, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ int i, j, k; int newwidth, newheight; int padBytes; GLint *s; const char *t; /* handle case where there is only 1 column/row */ if (width == 1 || height == 1) { assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ halve1Dimage_int(components,width,height,datain,dataout, element_size,ysize,group_size, myswap_bytes); return; } newwidth = width / 2; newheight = height / 2; padBytes = ysize - (width*group_size); s = dataout; t = (const char *)datain; /* Piece o' cake! */ if (!myswap_bytes) for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { s[0] = ((float)*(const GLint*)t + (float)*(const GLint*)(t+group_size) + (float)*(const GLint*)(t+ysize) + (float)*(const GLint*)(t+ysize+group_size))/4 + 0.5; s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; } else for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { GLuint b; GLfloat buf; b = __GLU_SWAP_4_BYTES(t); buf = *(GLint*)&b; b = __GLU_SWAP_4_BYTES(t+group_size); buf += *(GLint*)&b; b = __GLU_SWAP_4_BYTES(t+ysize); buf += *(GLint*)&b; b = __GLU_SWAP_4_BYTES(t+ysize+group_size); buf += *(GLint*)&b; s[0] = (GLint)(buf/4 + 0.5); s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; }}/* */static void halve1Dimage_int(GLint components, GLuint width, GLuint height, const GLint *dataIn, GLint *dataOut, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ GLint halfWidth= width / 2; GLint halfHeight= height / 2; const char *src= (const char *) dataIn; GLint *dest= dataOut; int jj; assert(width == 1 || height == 1); /* must be 1D */ assert(width != height); /* can't be square */ if (height == 1) { /* 1 row */ assert(width != 1); /* widthxheight can't be 1x1 */ halfHeight= 1; for (jj= 0; jj< halfWidth; jj++) { int kk; for (kk= 0; kk< components; kk++) {#define BOX2 2 GLuint uint[BOX2]; if (myswap_bytes) { uint[0]= __GLU_SWAP_4_BYTES(src); uint[1]= __GLU_SWAP_4_BYTES(src+group_size); } else { uint[0]= *(const GLuint*)src; uint[1]= *(const GLuint*)(src+group_size); } *dest= ((float)uint[0]+(float)uint[1])/2.0; src+= element_size; dest++; } src+= group_size; /* skip to next 2 */ } { int padBytes= ysize - (width*group_size); src+= padBytes; /* for assertion only */ } } else if (width == 1) { /* 1 column */ int padBytes= ysize - (width * group_size); assert(height != 1); /* widthxheight can't be 1x1 */ halfWidth= 1; /* one vertical column with possible pad bytes per row */ /* average two at a time */ for (jj= 0; jj< halfHeight; jj++) { int kk; for (kk= 0; kk< components; kk++) {#define BOX2 2 GLuint uint[BOX2]; if (myswap_bytes) { uint[0]= __GLU_SWAP_4_BYTES(src); uint[1]= __GLU_SWAP_4_BYTES(src+ysize); } else { uint[0]= *(const GLuint*)src; uint[1]= *(const GLuint*)(src+ysize); } *dest= ((float)uint[0]+(float)uint[1])/2.0; src+= element_size; dest++; } src+= padBytes; /* add pad bytes, if any, to get to end to row */ src+= ysize; } assert(src == &((const char *)dataIn)[ysize*height]); } assert((char *)dest == &((char *)dataOut) [components * element_size * halfWidth * halfHeight]);} /* halve1Dimage_int() */static void halveImage_float(GLint components, GLuint width, GLuint height, const GLfloat *datain, GLfloat *dataout, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ int i, j, k; int newwidth, newheight; int padBytes; GLfloat *s; const char *t; /* handle case where there is only 1 column/row */ if (width == 1 || height == 1) { assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ halve1Dimage_float(components,width,height,datain,dataout, element_size,ysize,group_size, myswap_bytes); return; } newwidth = width / 2; newheight = height / 2; padBytes = ysize - (width*group_size); s = dataout; t = (const char *)datain; /* Piece o' cake! */ if (!myswap_bytes) for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { s[0] = (*(const GLfloat*)t + *(const GLfloat*)(t+group_size) + *(const GLfloat*)(t+ysize) + *(const GLfloat*)(t+ysize+group_size)) / 4; s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; } else for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { union { GLuint b; GLfloat f; } swapbuf; swapbuf.b = __GLU_SWAP_4_BYTES(t); s[0] = swapbuf.f; swapbuf.b = __GLU_SWAP_4_BYTES(t+group_size); s[0] += swapbuf.f; swapbuf.b = __GLU_SWAP_4_BYTES(t+ysize); s[0] += swapbuf.f; swapbuf.b = __GLU_SWAP_4_BYTES(t+ysize+group_size); s[0] += swapbuf.f; s[0] /= 4; s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; }}/* */static void halve1Dimage_float(GLint components, GLuint width, GLuint height, const GLfloat *dataIn, GLfloat *dataOut, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ GLint halfWidth= width / 2; GLint halfHeight= height / 2; const char *src= (const char *) dataIn; GLfloat *dest= dataOut; int jj; assert(width == 1 || height == 1); /* must be 1D */ assert(width != height); /* can't be square */ if (height == 1) { /* 1 row */ assert(width != 1); /* widthxheight can't be 1x1 */ halfHeight= 1; for (jj= 0; jj< halfWidth; jj++) { int kk; for (kk= 0; kk< components; kk++) {#define BOX2 2 GLfloat sfloat[BOX2]; if (myswap_bytes) { sfloat[0]= __GLU_SWAP_4_BYTES(src); sfloat[1]= __GLU_SWAP_4_BYTES(src+group_size); } else { sfloat[0]= *(const GLfloat*)src; sfloat[1]= *(const GLfloat*)(src+group_size); } *dest= (sfloat[0] + sfloat[1]) / 2.0; src+= element_size; dest++; } src+= group_size; /* skip to next 2 */ } { int padBytes= ysize - (width*group_size); src+= padBytes; /* for assertion only */ } } else if (width == 1) { /* 1 column */ int padBytes= ysize - (width * group_size); assert(height != 1); /* widthxheight can't be 1x1 */ halfWidth= 1; /* one vertical column with possible pad bytes per row */ /* average two at a time */ for (jj= 0; jj< halfHeight; jj++) { int kk; for (kk= 0; kk< components; kk++) {#define BOX2 2 GLfloat sfloat[BOX2]; if (myswap_bytes) { sfloat[0]= __GLU_SWAP_4_BYTES(src); sfloat[1]= __GLU_SWAP_4_BYTES(src+ysize); } else { sfloat[0]= *(const GLfloat*)src; sfloat[1]= *(const GLfloat*)(src+ysize); } *dest= (sfloat[0] + sfloat[1]) / 2.0; src+= element_size; dest++; } src+= padBytes; /* add pad bytes, if any, to get to end to row */ src+= ysize; /* skip to odd row */ } } assert(src == &((const char *)dataIn)[ysize*height]); assert((char *)dest == &((char *)dataOut) [components * element_size * halfWidth * halfHeight]);} /* halve1Dimage_float() */static void scale_internal(GLint components, GLint widthin, GLint heightin, const GLushort *datain, GLint widthout, GLint heightout, GLushort *dataout){ float x, lowx, highx, convx, halfconvx; float y, lowy, highy, convy, halfconvy; float xpercent,ypercent; float percent; /* Max components in a format is 4, so... */ float totals[4]; float area; int i,j,k,yint,xint,xindex,yindex; int temp; if (widthin == widthout*2 && heightin == heightout*2) { halveImage(components, widthin, heightin, datain, dataout); return; } convy = (float) heightin/heightout; convx = (float) widthin/widthout; halfconvx = convx/2; halfconvy = convy/2; for (i = 0; i < heightout; i++) { y = convy * (i+0.5); if (heightin > heightout) { highy = y + halfconvy; lowy = y - halfconvy; } else { highy = y + 0.5; lowy = y - 0.5;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -