X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_readpix.c;h=b5ab06e4ba6e5ec3919c85b17f30ca8b791349a0;hb=8ef874f1a543c693cfef9c935bed05903800fbfe;hp=562d87184630206e3f98d24b19723149415ad46b;hpb=551b65f13754e6760e5c272ff86f8873c9c13e5c;p=mesa.git diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c index 562d8718463..b5ab06e4ba6 100644 --- a/src/mesa/swrast/s_readpix.c +++ b/src/mesa/swrast/s_readpix.c @@ -1,10 +1,8 @@ -/* $Id: s_readpix.c,v 1.16 2002/09/21 17:34:56 brianp Exp $ */ - /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 6.1 * - * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2004 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"), @@ -32,7 +30,7 @@ #include "feedback.h" #include "image.h" #include "macros.h" -#include "mem.h" +#include "imports.h" #include "pixel.h" #include "s_alphabuf.h" @@ -62,6 +60,17 @@ read_index_pixels( GLcontext *ctx, return; } + if (type != GL_BYTE && + type != GL_UNSIGNED_BYTE && + type != GL_SHORT && + type != GL_UNSIGNED_SHORT && + type != GL_INT && + type != GL_UNSIGNED_INT && + type != GL_FLOAT) { + _mesa_error( ctx, GL_INVALID_OPERATION, "glReadPixels(index type)"); + return; + } + _swrast_use_read_buffer(ctx); readWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; @@ -126,7 +135,7 @@ read_depth_pixels( GLcontext *ctx, GLushort *dst = (GLushort*) _mesa_image_address( packing, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 ); GLint i; - _mesa_read_depth_span(ctx, width, x, y, depth); + _swrast_read_depth_span(ctx, width, x, y, depth); for (i = 0; i < width; i++) dst[i] = depth[i]; } @@ -138,7 +147,7 @@ read_depth_pixels( GLcontext *ctx, for (j=0;jDriver.ReadRGBASpan)(ctx, readWidth, srcX, srcY, (GLchan (*)[4]) dest); if (ctx->DrawBuffer->UseSoftwareAlphaBuffers) { - _mesa_read_alpha_span(ctx, readWidth, srcX, srcY, + _swrast_read_alpha_span(ctx, readWidth, srcX, srcY, (GLchan (*)[4]) dest); } dest += rowLength * 4; @@ -373,14 +382,14 @@ read_rgba_pixels( GLcontext *ctx, GLfloat *dest, *src, *tmpImage, *convImage; GLint row; - tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); + tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); if (!tmpImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); return; } - convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); + convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); if (!convImage) { - FREE(tmpImage); + _mesa_free(tmpImage); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); return; } @@ -390,7 +399,7 @@ read_rgba_pixels( GLcontext *ctx, for (row = 0; row < height; row++, y++) { GLchan rgba[MAX_WIDTH][4]; if (ctx->Visual.rgbMode) { - _mesa_read_rgba_span(ctx, ctx->ReadBuffer, readWidth, x, y, rgba); + _swrast_read_rgba_span(ctx, ctx->ReadBuffer, readWidth, x, y, rgba); } else { GLuint index[MAX_WIDTH]; @@ -400,8 +409,8 @@ read_rgba_pixels( GLcontext *ctx, } _mesa_map_ci_to_rgba_chan(ctx, readWidth, index, rgba); } - _mesa_pack_rgba_span(ctx, readWidth, (const GLchan (*)[4]) rgba, - GL_RGBA, GL_FLOAT, dest, &_mesa_native_packing, + _mesa_pack_rgba_span_chan(ctx, readWidth, (const GLchan (*)[4]) rgba, + GL_RGBA, GL_FLOAT, dest, &ctx->DefaultPacking, transferOps & IMAGE_PRE_CONVOLUTION_BITS); dest += width * 4; } @@ -414,7 +423,7 @@ read_rgba_pixels( GLcontext *ctx, ASSERT(ctx->Pixel.Separable2DEnabled); _mesa_convolve_sep_image(ctx, &readWidth, &height, tmpImage, convImage); } - FREE(tmpImage); + _mesa_free(tmpImage); /* finish transfer ops and pack the resulting image */ src = convImage; @@ -422,7 +431,7 @@ read_rgba_pixels( GLcontext *ctx, GLvoid *dest; dest = _mesa_image_address(packing, pixels, readWidth, height, format, type, 0, row, 0); - _mesa_pack_float_rgba_span(ctx, readWidth, + _mesa_pack_rgba_span_float(ctx, readWidth, (const GLfloat (*)[4]) src, format, type, dest, packing, transferOps & IMAGE_POST_CONVOLUTION_BITS); @@ -436,7 +445,7 @@ read_rgba_pixels( GLcontext *ctx, GLchan rgba[MAX_WIDTH][4]; GLvoid *dst; if (ctx->Visual.rgbMode) { - _mesa_read_rgba_span(ctx, ctx->ReadBuffer, readWidth, x, y, rgba); + _swrast_read_rgba_span(ctx, ctx->ReadBuffer, readWidth, x, y, rgba); } else { GLuint index[MAX_WIDTH]; @@ -459,7 +468,7 @@ read_rgba_pixels( GLcontext *ctx, CHECKARRAY(rgbaf, return); /* mac 32k limitation */ _mesa_chan_to_float_span(ctx, readWidth, (CONST GLchan (*)[4]) rgba, rgbaf); - _mesa_pack_float_rgba_span(ctx, readWidth, + _mesa_pack_rgba_span_float(ctx, readWidth, (CONST GLfloat (*)[4]) rgbaf, format, type, dst, packing, ctx->_ImageTransferState); @@ -467,7 +476,7 @@ read_rgba_pixels( GLcontext *ctx, } else { /* GLubytes are fine */ - _mesa_pack_rgba_span(ctx, readWidth, (CONST GLchan (*)[4]) rgba, + _mesa_pack_rgba_span_chan(ctx, readWidth, (CONST GLchan (*)[4]) rgba, format, type, dst, packing, ctx->_ImageTransferState); } @@ -492,6 +501,14 @@ _swrast_ReadPixels( GLcontext *ctx, if (swrast->NewState) _swrast_validate_derived( ctx ); + pixels = _swrast_validate_pbo_access(pack, width, height, 1, + format, type, (GLvoid *) pixels); + + if (!pixels) { + _mesa_error( ctx, GL_INVALID_VALUE, "glReadPixels(pixels)" ); + return; + } + RENDER_START(swrast,ctx); switch (format) {