⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mipmap.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	for (j = 0; j < widthout; j++) {	    x = convx * (j+0.5);	    if (widthin > widthout) {		highx = x + halfconvx;		lowx = x - halfconvx;	    } else {		highx = x + 0.5;		lowx = x - 0.5;	    }	    /*	    ** Ok, now apply box filter to box that goes from (lowx, lowy)	    ** to (highx, highy) on input data into this pixel on output	    ** data.	    */	    totals[0] = totals[1] = totals[2] = totals[3] = 0.0;	    area = 0.0;	    y = lowy;	    yint = floor(y);	    while (y < highy) {		yindex = (yint + heightin) % heightin;		if (highy < yint+1) {		    ypercent = highy - y;		} else {		    ypercent = yint+1 - y;		}		x = lowx;		xint = floor(x);		while (x < highx) {		    xindex = (xint + widthin) % widthin;		    if (highx < xint+1) {			xpercent = highx - x;		    } else {			xpercent = xint+1 - x;		    }		    percent = xpercent * ypercent;		    area += percent;		    temp = (xindex + (yindex * widthin)) * components;		    for (k = 0; k < components; k++) {			totals[k] += datain[temp + k] * percent;		    }		    xint++;		    x = xint;		}		yint++;		y = yint;	    }	    temp = (j + (i * widthout)) * components;	    for (k = 0; k < components; k++) {		/* totals[] should be rounded in the case of enlarging an RGB		 * ramp when the type is 332 or 4444		 */		dataout[temp + k] = (totals[k]+0.5)/area;	    }	}    }}static void scale_internal_ubyte(GLint components, GLint widthin,			   GLint heightin, const GLubyte *datain,			   GLint widthout, GLint heightout,			   GLubyte *dataout, GLint element_size,			   GLint ysize, GLint group_size){    float convx;    float convy;    float percent;    /* Max components in a format is 4, so... */    float totals[4];    float area;    int i,j,k,xindex;    const char *temp, *temp0;    const char *temp_index;    int outindex;    int lowx_int, highx_int, lowy_int, highy_int;    float x_percent, y_percent;    float lowx_float, highx_float, lowy_float, highy_float;    float convy_float, convx_float;    int convy_int, convx_int;    int l, m;    const char *left, *right;    if (widthin == widthout*2 && heightin == heightout*2) {	halveImage_ubyte(components, widthin, heightin,	(const GLubyte *)datain, (GLubyte *)dataout,	element_size, ysize, group_size);	return;    }    convy = (float) heightin/heightout;    convx = (float) widthin/widthout;    convy_int = floor(convy);    convy_float = convy - convy_int;    convx_int = floor(convx);    convx_float = convx - convx_int;    area = convx * convy;    lowy_int = 0;    lowy_float = 0;    highy_int = convy_int;    highy_float = convy_float;    for (i = 0; i < heightout; i++) {        /* Clamp here to be sure we don't read beyond input buffer. */        if (highy_int >= heightin)            highy_int = heightin - 1;	lowx_int = 0;	lowx_float = 0;	highx_int = convx_int;	highx_float = convx_float;	for (j = 0; j < widthout; j++) {	    /*	    ** Ok, now apply box filter to box that goes from (lowx, lowy)	    ** to (highx, highy) on input data into this pixel on output	    ** data.	    */	    totals[0] = totals[1] = totals[2] = totals[3] = 0.0;	    /* calculate the value for pixels in the 1st row */	    xindex = lowx_int*group_size;	    if((highy_int>lowy_int) && (highx_int>lowx_int)) {		y_percent = 1-lowy_float;		temp = (const char *)datain + xindex + lowy_int * ysize;		percent = y_percent * (1-lowx_float);		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}		left = temp;		for(l = lowx_int+1; l < highx_int; l++) {		    temp += group_size;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * y_percent;		    }		}		temp += group_size;		right = temp;		percent = y_percent * highx_float;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}		/* calculate the value for pixels in the last row */		y_percent = highy_float;		percent = y_percent * (1-lowx_float);		temp = (const char *)datain + xindex + highy_int * ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}		for(l = lowx_int+1; l < highx_int; l++) {		    temp += group_size;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * y_percent;		    }		}		temp += group_size;		percent = y_percent * highx_float;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}		/* calculate the value for pixels in the 1st and last column */		for(m = lowy_int+1; m < highy_int; m++) {		    left += ysize;		    right += ysize;		    for (k = 0; k < components;			 k++, left += element_size, right += element_size) {			totals[k] += (GLubyte)(*(left))*(1-lowx_float)				+(GLubyte)(*(right))*highx_float;		    }		}	    } else if (highy_int > lowy_int) {		x_percent = highx_float - lowx_float;		percent = (1-lowy_float)*x_percent;		temp = (const char *)datain + xindex + lowy_int*ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}		for(m = lowy_int+1; m < highy_int; m++) {		    temp += ysize;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * x_percent;		    }		}		percent = x_percent * highy_float;		temp += ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}	    } else if (highx_int > lowx_int) {		y_percent = highy_float - lowy_float;		percent = (1-lowx_float)*y_percent;		temp = (const char *)datain + xindex + lowy_int*ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}		for (l = lowx_int+1; l < highx_int; l++) {		    temp += group_size;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * y_percent;		    }		}		temp += group_size;		percent = y_percent * highx_float;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}	    } else {		percent = (highy_float-lowy_float)*(highx_float-lowx_float);		temp = (const char *)datain + xindex + lowy_int * ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index)) * percent;		}	    }	    /* this is for the pixels in the body */	    temp0 = (const char *)datain + xindex + group_size +		 (lowy_int+1)*ysize;	    for (m = lowy_int+1; m < highy_int; m++) {		temp = temp0;		for(l = lowx_int+1; l < highx_int; l++) {		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLubyte)(*(temp_index));		    }		    temp += group_size;		}		temp0 += ysize;	    }	    outindex = (j + (i * widthout)) * components;	    for (k = 0; k < components; k++) {		dataout[outindex + k] = totals[k]/area;		/*printf("totals[%d] = %f\n", k, totals[k]);*/	    }	    lowx_int = highx_int;	    lowx_float = highx_float;	    highx_int += convx_int;	    highx_float += convx_float;	    if(highx_float > 1) {		highx_float -= 1.0;		highx_int++;	    }	}	lowy_int = highy_int;	lowy_float = highy_float;	highy_int += convy_int;	highy_float += convy_float;	if(highy_float > 1) {	    highy_float -= 1.0;	    highy_int++;	}    }}static void scale_internal_byte(GLint components, GLint widthin,			   GLint heightin, const GLbyte *datain,			   GLint widthout, GLint heightout,			   GLbyte *dataout, GLint element_size,			   GLint ysize, GLint group_size){    float convx;    float convy;    float percent;    /* Max components in a format is 4, so... */    float totals[4];    float area;    int i,j,k,xindex;    const char *temp, *temp0;    const char *temp_index;    int outindex;    int lowx_int, highx_int, lowy_int, highy_int;    float x_percent, y_percent;    float lowx_float, highx_float, lowy_float, highy_float;    float convy_float, convx_float;    int convy_int, convx_int;    int l, m;    const char *left, *right;    if (widthin == widthout*2 && heightin == heightout*2) {	halveImage_byte(components, widthin, heightin,	(const GLbyte *)datain, (GLbyte *)dataout,	element_size, ysize, group_size);	return;    }    convy = (float) heightin/heightout;    convx = (float) widthin/widthout;    convy_int = floor(convy);    convy_float = convy - convy_int;    convx_int = floor(convx);    convx_float = convx - convx_int;    area = convx * convy;    lowy_int = 0;    lowy_float = 0;    highy_int = convy_int;    highy_float = convy_float;    for (i = 0; i < heightout; i++) {        /* Clamp here to be sure we don't read beyond input buffer. */        if (highy_int >= heightin)            highy_int = heightin - 1;	lowx_int = 0;	lowx_float = 0;	highx_int = convx_int;	highx_float = convx_float;	for (j = 0; j < widthout; j++) {	    /*	    ** Ok, now apply box filter to box that goes from (lowx, lowy)	    ** to (highx, highy) on input data into this pixel on output	    ** data.	    */	    totals[0] = totals[1] = totals[2] = totals[3] = 0.0;	    /* calculate the value for pixels in the 1st row */	    xindex = lowx_int*group_size;	    if((highy_int>lowy_int) && (highx_int>lowx_int)) {		y_percent = 1-lowy_float;		temp = (const char *)datain + xindex + lowy_int * ysize;		percent = y_percent * (1-lowx_float);		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}		left = temp;		for(l = lowx_int+1; l < highx_int; l++) {		    temp += group_size;		    for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * y_percent;		    }		}		temp += group_size;		right = temp;		percent = y_percent * highx_float;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}		/* calculate the value for pixels in the last row */	        		y_percent = highy_float;		percent = y_percent * (1-lowx_float);		temp = (const char *)datain + xindex + highy_int * ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}		for(l = lowx_int+1; l < highx_int; l++) {		    temp += group_size;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * y_percent;		    }		}		temp += group_size;		percent = y_percent * highx_float;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}		/* calculate the value for pixels in the 1st and last column */		for(m = lowy_int+1; m < highy_int; m++) {		    left += ysize;		    right += ysize;		    for (k = 0; k < components;			 k++, left += element_size, right += element_size) {			totals[k] += (GLbyte)(*(left))*(1-lowx_float)				+(GLbyte)(*(right))*highx_float;		    }		}	    } else if (highy_int > lowy_int) {		x_percent = highx_float - lowx_float;		percent = (1-lowy_float)*x_percent;		temp = (const char *)datain + xindex + lowy_int*ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}		for(m = lowy_int+1; m < highy_int; m++) {		    temp += ysize;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * x_percent;		    }		}		percent = x_percent * highy_float;		temp += ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}	    } else if (highx_int > lowx_int) {		y_percent = highy_float - lowy_float;		percent = (1-lowx_float)*y_percent;		temp = (const char *)datain + xindex + lowy_int*ysize;		for (k = 0, temp_index = temp; k < components;		     k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * percent;		}		for (l = lowx_int+1; l < highx_int; l++) {		    temp += group_size;		    for (k = 0, temp_index = temp; k < components;			 k++, temp_index += element_size) {			totals[k] += (GLbyte)(*(temp_index)) * y_percent;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -