📄 s_zoom.c
字号:
const GLfloat (*rgba)[4] = (const GLfloat (*)[4]) src; GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; ASSERT(j >= 0); ASSERT(j < span->end); COPY_4V(zoomed.array->attribs[FRAG_ATTRIB_COL0][i], rgba[j]); } } } else if (format == GL_RGB) { if (zoomed.array->ChanType == GL_UNSIGNED_BYTE) { const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) src; GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; ASSERT(j >= 0); ASSERT(j < (GLint) span->end); zoomed.array->rgba8[i][0] = rgb[j][0]; zoomed.array->rgba8[i][1] = rgb[j][1]; zoomed.array->rgba8[i][2] = rgb[j][2]; zoomed.array->rgba8[i][3] = 0xff; } } else if (zoomed.array->ChanType == GL_UNSIGNED_SHORT) { const GLushort (*rgb)[3] = (const GLushort (*)[3]) src; GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; ASSERT(j >= 0); ASSERT(j < (GLint) span->end); zoomed.array->rgba16[i][0] = rgb[j][0]; zoomed.array->rgba16[i][1] = rgb[j][1]; zoomed.array->rgba16[i][2] = rgb[j][2]; zoomed.array->rgba16[i][3] = 0xffff; } } else { const GLfloat (*rgb)[3] = (const GLfloat (*)[3]) src; GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; ASSERT(j >= 0); ASSERT(j < span->end); zoomed.array->attribs[FRAG_ATTRIB_COL0][i][0] = rgb[j][0]; zoomed.array->attribs[FRAG_ATTRIB_COL0][i][1] = rgb[j][1]; zoomed.array->attribs[FRAG_ATTRIB_COL0][i][2] = rgb[j][2]; zoomed.array->attribs[FRAG_ATTRIB_COL0][i][3] = 1.0F; } } } else if (format == GL_COLOR_INDEX) { const GLuint *indexes = (const GLuint *) src; GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; ASSERT(j >= 0); ASSERT(j < (GLint) span->end); zoomed.array->index[i] = indexes[j]; } } else if (format == GL_DEPTH_COMPONENT) { const GLuint *zValues = (const GLuint *) src; GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; ASSERT(j >= 0); ASSERT(j < (GLint) span->end); zoomed.array->z[i] = zValues[j]; } /* Now, fall into either the RGB or COLOR_INDEX path below */ format = ctx->Visual.rgbMode ? GL_RGBA : GL_COLOR_INDEX; } /* write the span in rows [r0, r1) */ if (format == GL_RGBA || format == GL_RGB) { /* Writing the span may modify the colors, so make a backup now if we're * going to call _swrast_write_zoomed_span() more than once. * Also, clipping may change the span end value, so store it as well. */ const GLint end = zoomed.end; /* save */ GLuint rgbaSave[MAX_WIDTH][4]; const GLint pixelSize = (zoomed.array->ChanType == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) : ((zoomed.array->ChanType == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort) : 4 * sizeof(GLfloat)); if (y1 - y0 > 1) { MEMCPY(rgbaSave, zoomed.array->rgba, zoomed.end * pixelSize); } for (zoomed.y = y0; zoomed.y < y1; zoomed.y++) { _swrast_write_rgba_span(ctx, &zoomed); zoomed.end = end; /* restore */ if (y1 - y0 > 1) { /* restore the colors */ MEMCPY(zoomed.array->rgba, rgbaSave, zoomed.end * pixelSize); } } } else if (format == GL_COLOR_INDEX) { /* use specular color array for temp storage */ GLuint *indexSave = (GLuint *) zoomed.array->attribs[FRAG_ATTRIB_FOGC]; const GLint end = zoomed.end; /* save */ if (y1 - y0 > 1) { MEMCPY(indexSave, zoomed.array->index, zoomed.end * sizeof(GLuint)); } for (zoomed.y = y0; zoomed.y < y1; zoomed.y++) { _swrast_write_index_span(ctx, &zoomed); zoomed.end = end; /* restore */ if (y1 - y0 > 1) { /* restore the colors */ MEMCPY(zoomed.array->index, indexSave, zoomed.end * sizeof(GLuint)); } } }}void_swrast_write_zoomed_rgba_span(GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span, const GLvoid *rgba){ zoom_span(ctx, imgX, imgY, span, rgba, GL_RGBA);}void_swrast_write_zoomed_rgb_span(GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span, const GLvoid *rgb){ zoom_span(ctx, imgX, imgY, span, rgb, GL_RGB);}void_swrast_write_zoomed_index_span(GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span){ zoom_span(ctx, imgX, imgY, span, (const GLvoid *) span->array->index, GL_COLOR_INDEX);}void_swrast_write_zoomed_depth_span(GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span){ zoom_span(ctx, imgX, imgY, span, (const GLvoid *) span->array->z, GL_DEPTH_COMPONENT);}/** * Zoom/write stencil values. * No per-fragment operations are applied. */void_swrast_write_zoomed_stencil_span(GLcontext *ctx, GLint imgX, GLint imgY, GLint width, GLint spanX, GLint spanY, const GLstencil stencil[]){ GLstencil zoomedVals[MAX_WIDTH]; GLint x0, x1, y0, y1, y; GLint i, zoomedWidth; if (!compute_zoomed_bounds(ctx, imgX, imgY, spanX, spanY, width, &x0, &x1, &y0, &y1)) { return; /* totally clipped */ } zoomedWidth = x1 - x0; ASSERT(zoomedWidth > 0); ASSERT(zoomedWidth <= MAX_WIDTH); /* zoom the span horizontally */ for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX; ASSERT(j >= 0); ASSERT(j < width); zoomedVals[i] = stencil[j]; } /* write the zoomed spans */ for (y = y0; y < y1; y++) { _swrast_write_stencil_span(ctx, zoomedWidth, x0, y, zoomedVals); }}/** * Zoom/write z values (16 or 32-bit). * No per-fragment operations are applied. */void_swrast_write_zoomed_z_span(GLcontext *ctx, GLint imgX, GLint imgY, GLint width, GLint spanX, GLint spanY, const GLvoid *z){ struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer; GLushort zoomedVals16[MAX_WIDTH]; GLuint zoomedVals32[MAX_WIDTH]; GLint x0, x1, y0, y1, y; GLint i, zoomedWidth; if (!compute_zoomed_bounds(ctx, imgX, imgY, spanX, spanY, width, &x0, &x1, &y0, &y1)) { return; /* totally clipped */ } zoomedWidth = x1 - x0; ASSERT(zoomedWidth > 0); ASSERT(zoomedWidth <= MAX_WIDTH); /* zoom the span horizontally */ if (rb->DataType == GL_UNSIGNED_SHORT) { for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX; ASSERT(j >= 0); ASSERT(j < width); zoomedVals16[i] = ((GLushort *) z)[j]; } z = zoomedVals16; } else { ASSERT(rb->DataType == GL_UNSIGNED_INT); for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX; ASSERT(j >= 0); ASSERT(j < width); zoomedVals32[i] = ((GLuint *) z)[j]; } z = zoomedVals32; } /* write the zoomed spans */ for (y = y0; y < y1; y++) { rb->PutRow(ctx, rb, zoomedWidth, x0, y, z, NULL); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -