📄 s_drawpix.c
字号:
/* * Mesa 3-D graphics library * Version: 6.5 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#include "glheader.h"#include "bufferobj.h"#include "context.h"#include "convolve.h"#include "image.h"#include "macros.h"#include "imports.h"#include "pixel.h"#include "state.h"#include "s_context.h"#include "s_drawpix.h"#include "s_span.h"#include "s_stencil.h"#include "s_zoom.h"/* * Try to do a fast and simple RGB(a) glDrawPixels. * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead */static GLbooleanfast_draw_pixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels){ const GLint imgX = x, imgY = y; struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][0]; SWcontext *swrast = SWRAST_CONTEXT(ctx); struct sw_span span; INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_RGBA); if (swrast->_RasterMask & MULTI_DRAW_BIT) return GL_FALSE; if (ctx->Depth.Test) _swrast_span_default_z(ctx, &span); if (swrast->_FogEnabled) _swrast_span_default_fog(ctx, &span); if (ctx->Texture._EnabledCoordUnits) _swrast_span_default_texcoords(ctx, &span); if ((swrast->_RasterMask & ~CLIP_BIT) == 0 && ctx->Texture._EnabledCoordUnits == 0 && unpack->Alignment == 1 /* XXX may not really need this */ && !unpack->SwapBytes && !unpack->LsbFirst) { /* XXX there's a lot of clipping code here that should be replaced * by a call to _mesa_clip_drawpixels(). */ GLint destX = x; GLint destY = y; GLint drawWidth = width; /* actual width drawn */ GLint drawHeight = height; /* actual height drawn */ GLint skipPixels = unpack->SkipPixels; GLint skipRows = unpack->SkipRows; GLint rowLength; if (unpack->RowLength > 0) rowLength = unpack->RowLength; else rowLength = width; /* If we're not using pixel zoom then do all clipping calculations * now. Otherwise, we'll let the _swrast_write_zoomed_*_span() functions * handle the clipping. */ if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* horizontal clipping */ if (destX < ctx->DrawBuffer->_Xmin) { skipPixels += (ctx->DrawBuffer->_Xmin - destX); drawWidth -= (ctx->DrawBuffer->_Xmin - destX); destX = ctx->DrawBuffer->_Xmin; } if (destX + drawWidth > ctx->DrawBuffer->_Xmax) drawWidth -= (destX + drawWidth - ctx->DrawBuffer->_Xmax); if (drawWidth <= 0) return GL_TRUE; /* vertical clipping */ if (destY < ctx->DrawBuffer->_Ymin) { skipRows += (ctx->DrawBuffer->_Ymin - destY); drawHeight -= (ctx->DrawBuffer->_Ymin - destY); destY = ctx->DrawBuffer->_Ymin; } if (destY + drawHeight > ctx->DrawBuffer->_Ymax) drawHeight -= (destY + drawHeight - ctx->DrawBuffer->_Ymax); if (drawHeight <= 0) return GL_TRUE; } else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down image */ /* horizontal clipping */ if (destX < ctx->DrawBuffer->_Xmin) { skipPixels += (ctx->DrawBuffer->_Xmin - destX); drawWidth -= (ctx->DrawBuffer->_Xmin - destX); destX = ctx->DrawBuffer->_Xmin; } if (destX + drawWidth > ctx->DrawBuffer->_Xmax) drawWidth -= (destX + drawWidth - ctx->DrawBuffer->_Xmax); if (drawWidth <= 0) return GL_TRUE; /* vertical clipping */ if (destY > ctx->DrawBuffer->_Ymax) { skipRows += (destY - ctx->DrawBuffer->_Ymax); drawHeight -= (destY - ctx->DrawBuffer->_Ymax); destY = ctx->DrawBuffer->_Ymax; } if (destY - drawHeight < ctx->DrawBuffer->_Ymin) drawHeight -= (ctx->DrawBuffer->_Ymin - (destY - drawHeight)); if (drawHeight <= 0) return GL_TRUE; } else { if (drawWidth > MAX_WIDTH) return GL_FALSE; /* fall back to general case path */ } /* * Ready to draw! * The window region at (destX, destY) of size (drawWidth, drawHeight) * will be written to. * We'll take pixel data from buffer pointed to by "pixels" but we'll * skip "skipRows" rows and skip "skipPixels" pixels/row. */ if (format == GL_RGBA && type == CHAN_TYPE && ctx->_ImageTransferState==0) { if (ctx->Visual.rgbMode) { GLchan *src = (GLchan *) pixels + (skipRows * rowLength + skipPixels) * 4; if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; for (row=0; row<drawHeight; row++) { rb->PutRow(ctx, rb, drawWidth, destX, destY, src, NULL); src += rowLength * 4; destY++; } } else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down */ GLint row; for (row=0; row<drawHeight; row++) { destY--; rb->PutRow(ctx, rb, drawWidth, destX, destY, src, NULL); src += rowLength * 4; } } else { /* with zooming */ GLint row; for (row=0; row<drawHeight; row++) { span.x = destX; span.y = destY + row; span.end = drawWidth; _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, (CONST GLchan (*)[4]) src); src += rowLength * 4; } } } return GL_TRUE; } else if (format == GL_RGB && type == CHAN_TYPE && ctx->_ImageTransferState == 0) { if (ctx->Visual.rgbMode) { GLchan *src = (GLchan *) pixels + (skipRows * rowLength + skipPixels) * 3; if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { GLint row; for (row=0; row<drawHeight; row++) { rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, src, NULL); src += rowLength * 3; destY++; } } else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down */ GLint row; for (row=0; row<drawHeight; row++) { destY--; rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, src, NULL); src += rowLength * 3; } } else { /* with zooming */ GLint row; for (row=0; row<drawHeight; row++) { span.x = destX; span.y = destY; span.end = drawWidth; _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, (CONST GLchan (*)[3]) src); src += rowLength * 3; destY++; } } } return GL_TRUE; } else if (format == GL_LUMINANCE && type == CHAN_TYPE && ctx->_ImageTransferState==0) { if (ctx->Visual.rgbMode) { GLchan *src = (GLchan *) pixels + (skipRows * rowLength + skipPixels); if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; ASSERT(drawWidth <= MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; for (i=0;i<drawWidth;i++) { span.array->rgb[i][0] = src[i]; span.array->rgb[i][1] = src[i]; span.array->rgb[i][2] = src[i]; } rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, span.array->rgb, NULL); src += rowLength; destY++; } } else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down */ GLint row; ASSERT(drawWidth <= MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; for (i=0;i<drawWidth;i++) { span.array->rgb[i][0] = src[i]; span.array->rgb[i][1] = src[i]; span.array->rgb[i][2] = src[i]; } destY--; rb->PutRow(ctx, rb, drawWidth, destX, destY, span.array->rgb, NULL); src += rowLength; } } else { /* with zooming */ GLint row; ASSERT(drawWidth <= MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; for (i=0;i<drawWidth;i++) { span.array->rgb[i][0] = src[i]; span.array->rgb[i][1] = src[i]; span.array->rgb[i][2] = src[i]; } span.x = destX; span.y = destY; span.end = drawWidth; _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, (CONST GLchan (*)[3]) span.array->rgb); src += rowLength; destY++; } } } return GL_TRUE; } else if (format == GL_LUMINANCE_ALPHA && type == CHAN_TYPE && ctx->_ImageTransferState == 0) { if (ctx->Visual.rgbMode) { GLchan *src = (GLchan *) pixels + (skipRows * rowLength + skipPixels)*2; if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; ASSERT(drawWidth <= MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; GLchan *ptr = src; for (i=0;i<drawWidth;i++) { span.array->rgba[i][0] = *ptr; span.array->rgba[i][1] = *ptr; span.array->rgba[i][2] = *ptr++; span.array->rgba[i][3] = *ptr++; } rb->PutRow(ctx, rb, drawWidth, destX, destY, span.array->rgba, NULL); src += rowLength*2; destY++; } } else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down */ GLint row; ASSERT(drawWidth <= MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; GLchan *ptr = src; for (i=0;i<drawWidth;i++) { span.array->rgba[i][0] = *ptr; span.array->rgba[i][1] = *ptr; span.array->rgba[i][2] = *ptr++; span.array->rgba[i][3] = *ptr++; } destY--; rb->PutRow(ctx, rb, drawWidth, destX, destY, span.array->rgba, NULL); src += rowLength*2; } } else { /* with zooming */ GLint row; ASSERT(drawWidth <= MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLchan *ptr = src; GLint i; for (i=0;i<drawWidth;i++) { span.array->rgba[i][0] = *ptr; span.array->rgba[i][1] = *ptr; span.array->rgba[i][2] = *ptr++; span.array->rgba[i][3] = *ptr++; } span.x = destX; span.y = destY; span.end = drawWidth; _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, (CONST GLchan (*)[4]) span.array->rgba); src += rowLength*2; destY++; } } } return GL_TRUE; } else if (format==GL_COLOR_INDEX && type==GL_UNSIGNED_BYTE) { GLubyte *src = (GLubyte *) pixels + skipRows * rowLength + skipPixels; if (ctx->Visual.rgbMode) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -