📄 mipmap.c
字号:
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++) { *dest= (*(const GLubyte*)src + *(const GLubyte*)(src+ysize)) / 2; 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_ubyte() */static void halveImage_byte(GLint components, GLuint width, GLuint height, const GLbyte *datain, GLbyte *dataout, GLint element_size, GLint ysize, GLint group_size){ int i, j, k; int newwidth, newheight; int padBytes; GLbyte *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_byte(components,width,height,datain,dataout, element_size,ysize,group_size); return; } newwidth = width / 2; newheight = height / 2; padBytes = ysize - (width*group_size); s = dataout; t = (const char *)datain; /* Piece o' cake! */ for (i = 0; i < newheight; i++) { for (j = 0; j < newwidth; j++) { for (k = 0; k < components; k++) { s[0] = (*(const GLbyte*)t + *(const GLbyte*)(t+group_size) + *(const GLbyte*)(t+ysize) + *(const GLbyte*)(t+ysize+group_size) + 2) / 4; s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; }}static void halve1Dimage_byte(GLint components, GLuint width, GLuint height, const GLbyte *dataIn, GLbyte *dataOut, GLint element_size,GLint ysize, GLint group_size){ GLint halfWidth= width / 2; GLint halfHeight= height / 2; const char *src= (const char *) dataIn; GLbyte *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++) { *dest= (*(const GLbyte*)src + *(const GLbyte*)(src+group_size)) / 2; 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++) { *dest= (*(const GLbyte*)src + *(const GLbyte*)(src+ysize)) / 2; 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_byte() */static void halveImage_ushort(GLint components, GLuint width, GLuint height, const GLushort *datain, GLushort *dataout, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ int i, j, k; int newwidth, newheight; int padBytes; GLushort *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_ushort(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 GLushort*)t + *(const GLushort*)(t+group_size) + *(const GLushort*)(t+ysize) + *(const GLushort*)(t+ysize+group_size) + 2) / 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++) { s[0] = (__GLU_SWAP_2_BYTES(t) + __GLU_SWAP_2_BYTES(t+group_size) + __GLU_SWAP_2_BYTES(t+ysize) + __GLU_SWAP_2_BYTES(t+ysize+group_size)+ 2)/4; s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; }}static void halve1Dimage_ushort(GLint components, GLuint width, GLuint height, const GLushort *dataIn, GLushort *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; GLushort *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 GLushort ushort[BOX2]; if (myswap_bytes) { ushort[0]= __GLU_SWAP_2_BYTES(src); ushort[1]= __GLU_SWAP_2_BYTES(src+group_size); } else { ushort[0]= *(const GLushort*)src; ushort[1]= *(const GLushort*)(src+group_size); } *dest= (ushort[0] + ushort[1]) / 2; 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 GLushort ushort[BOX2]; if (myswap_bytes) { ushort[0]= __GLU_SWAP_2_BYTES(src); ushort[1]= __GLU_SWAP_2_BYTES(src+ysize); } else { ushort[0]= *(const GLushort*)src; ushort[1]= *(const GLushort*)(src+ysize); } *dest= (ushort[0] + ushort[1]) / 2; 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_ushort() */static void halveImage_short(GLint components, GLuint width, GLuint height, const GLshort *datain, GLshort *dataout, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ int i, j, k; int newwidth, newheight; int padBytes; GLshort *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_short(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 GLshort*)t + *(const GLshort*)(t+group_size) + *(const GLshort*)(t+ysize) + *(const GLshort*)(t+ysize+group_size) + 2) / 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++) { GLushort b; GLint buf; b = __GLU_SWAP_2_BYTES(t); buf = *(const GLshort*)&b; b = __GLU_SWAP_2_BYTES(t+group_size); buf += *(const GLshort*)&b; b = __GLU_SWAP_2_BYTES(t+ysize); buf += *(const GLshort*)&b; b = __GLU_SWAP_2_BYTES(t+ysize+group_size); buf += *(const GLshort*)&b; s[0] = (GLshort)((buf+2)/4); s++; t += element_size; } t += group_size; } t += padBytes; t += ysize; }}static void halve1Dimage_short(GLint components, GLuint width, GLuint height, const GLshort *dataIn, GLshort *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; GLshort *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 GLshort sshort[BOX2]; if (myswap_bytes) { sshort[0]= __GLU_SWAP_2_BYTES(src); sshort[1]= __GLU_SWAP_2_BYTES(src+group_size); } else { sshort[0]= *(const GLshort*)src; sshort[1]= *(const GLshort*)(src+group_size); } *dest= (sshort[0] + sshort[1]) / 2; 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 GLshort sshort[BOX2]; if (myswap_bytes) { sshort[0]= __GLU_SWAP_2_BYTES(src); sshort[1]= __GLU_SWAP_2_BYTES(src+ysize); } else { sshort[0]= *(const GLshort*)src; sshort[1]= *(const GLshort*)(src+ysize); } *dest= (sshort[0] + sshort[1]) / 2; 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_short() */static void halveImage_uint(GLint components, GLuint width, GLuint height, const GLuint *datain, GLuint *dataout, GLint element_size, GLint ysize, GLint group_size, GLint myswap_bytes){ int i, j, k; int newwidth, newheight; int padBytes; GLuint *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_uint(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! */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -