projects
/
mesa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Committing in .
[mesa.git]
/
src
/
mesa
/
swrast
/
s_readpix.c
diff --git
a/src/mesa/swrast/s_readpix.c
b/src/mesa/swrast/s_readpix.c
index a24c44bebed8e070d7af02377cb14e391ca48e03..b5ab06e4ba6e5ec3919c85b17f30ca8b791349a0 100644
(file)
--- a/
src/mesa/swrast/s_readpix.c
+++ b/
src/mesa/swrast/s_readpix.c
@@
-1,10
+1,8
@@
-/* $Id: s_readpix.c,v 1.10 2001/03/12 00:48:42 gareth Exp $ */
-
/*
* Mesa 3-D graphics library
/*
* Mesa 3-D graphics library
- * Version:
3.5
+ * Version:
6.1
*
*
- * Copyright (C) 1999-200
1
Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-200
4
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"),
*
* 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 "feedback.h"
#include "image.h"
#include "macros.h"
-#include "
mem
.h"
+#include "
imports
.h"
#include "pixel.h"
#include "s_alphabuf.h"
#include "pixel.h"
#include "s_alphabuf.h"
@@
-53,6
+51,7
@@
read_index_pixels( GLcontext *ctx,
GLenum type, GLvoid *pixels,
const struct gl_pixelstore_attrib *packing )
{
GLenum type, GLvoid *pixels,
const struct gl_pixelstore_attrib *packing )
{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLint i, readWidth;
/* error checking */
GLint i, readWidth;
/* error checking */
@@
-61,9
+60,18
@@
read_index_pixels( GLcontext *ctx,
return;
}
return;
}
- ASSERT(ctx->Driver.SetReadBuffer);
- (*ctx->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer);
+ 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;
readWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width;
@@
-72,7
+80,7
@@
read_index_pixels( GLcontext *ctx,
GLuint index[MAX_WIDTH];
GLvoid *dest;
GLuint index[MAX_WIDTH];
GLvoid *dest;
- (*
ctx
->Driver.ReadCI32Span)(ctx, readWidth, x, y + i, index);
+ (*
swrast
->Driver.ReadCI32Span)(ctx, readWidth, x, y + i, index);
dest = _mesa_image_address(packing, pixels, width, height,
GL_COLOR_INDEX, type, 0, i, 0);
dest = _mesa_image_address(packing, pixels, width, height,
GL_COLOR_INDEX, type, 0, i, 0);
@@
-81,8
+89,7
@@
read_index_pixels( GLcontext *ctx,
&ctx->Pack, ctx->_ImageTransferState);
}
&ctx->Pack, ctx->_ImageTransferState);
}
- (*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer);
+ _swrast_use_draw_buffer(ctx);
}
}
@@
-128,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;
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];
}
for (i = 0; i < width; i++)
dst[i] = depth[i];
}
@@
-140,7
+147,7
@@
read_depth_pixels( GLcontext *ctx,
for (j=0;j<height;j++,y++) {
GLdepth *dst = (GLdepth *) _mesa_image_address( packing, pixels,
width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 );
for (j=0;j<height;j++,y++) {
GLdepth *dst = (GLdepth *) _mesa_image_address( packing, pixels,
width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 );
- _
mesa
_read_depth_span(ctx, width, x, y, dst);
+ _
swrast
_read_depth_span(ctx, width, x, y, dst);
}
}
else {
}
}
else {
@@
-150,7
+157,7
@@
read_depth_pixels( GLcontext *ctx,
GLfloat depth[MAX_WIDTH];
GLvoid *dest;
GLfloat depth[MAX_WIDTH];
GLvoid *dest;
- _
mesa
_read_depth_span_float(ctx, readWidth, x, y, depth);
+ _
swrast
_read_depth_span_float(ctx, readWidth, x, y, depth);
dest = _mesa_image_address(packing, pixels, width, height,
GL_DEPTH_COMPONENT, type, 0, j, 0);
dest = _mesa_image_address(packing, pixels, width, height,
GL_DEPTH_COMPONENT, type, 0, j, 0);
@@
-197,7
+204,7
@@
read_stencil_pixels( GLcontext *ctx,
GLvoid *dest;
GLstencil stencil[MAX_WIDTH];
GLvoid *dest;
GLstencil stencil[MAX_WIDTH];
- _
mesa
_read_stencil_span(ctx, readWidth, x, y, stencil);
+ _
swrast
_read_stencil_span(ctx, readWidth, x, y, stencil);
dest = _mesa_image_address(packing, pixels, width, height,
GL_STENCIL_INDEX, type, 0, j, 0);
dest = _mesa_image_address(packing, pixels, width, height,
GL_STENCIL_INDEX, type, 0, j, 0);
@@
-221,6
+228,7
@@
read_fast_rgba_pixels( GLcontext *ctx,
GLvoid *pixels,
const struct gl_pixelstore_attrib *packing )
{
GLvoid *pixels,
const struct gl_pixelstore_attrib *packing )
{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
/* can't do scale, bias, mapping, etc */
if (ctx->_ImageTransferState)
return GL_FALSE;
/* can't do scale, bias, mapping, etc */
if (ctx->_ImageTransferState)
return GL_FALSE;
@@
-244,24
+252,24
@@
read_fast_rgba_pixels( GLcontext *ctx,
rowLength = width;
/* horizontal clipping */
rowLength = width;
/* horizontal clipping */
- if (srcX <
ctx->ReadBuffer->_Xmin
) {
- skipPixels
+= (ctx->ReadBuffer->_Xmin - srcX)
;
- readWidth
-= (ctx->ReadBuffer->_Xmin - srcX)
;
- srcX =
ctx->ReadBuffer->_Xmin
;
+ if (srcX <
0
) {
+ skipPixels
-= srcX
;
+ readWidth
+= srcX
;
+ srcX =
0
;
}
}
- if (srcX + readWidth >
ctx->ReadBuffer->_Xmax
)
- readWidth -= (srcX + readWidth -
ctx->ReadBuffer->_Xmax
);
+ if (srcX + readWidth >
(GLint) ctx->ReadBuffer->Width
)
+ readWidth -= (srcX + readWidth -
(GLint) ctx->ReadBuffer->Width
);
if (readWidth <= 0)
return GL_TRUE;
/* vertical clipping */
if (readWidth <= 0)
return GL_TRUE;
/* vertical clipping */
- if (srcY <
ctx->ReadBuffer->_Ymin
) {
- skipRows
+= (ctx->ReadBuffer->_Ymin - srcY)
;
- readHeight
-= (ctx->ReadBuffer->_Ymin - srcY)
;
- srcY =
ctx->ReadBuffer->_Ymin
;
+ if (srcY <
0
) {
+ skipRows
-= srcY
;
+ readHeight
+= srcY
;
+ srcY =
0
;
}
}
- if (srcY + readHeight >
ctx->ReadBuffer->_Ymax
)
- readHeight -= (srcY + readHeight -
ctx->ReadBuffer->_Ymax
);
+ if (srcY + readHeight >
(GLint) ctx->ReadBuffer->Height
)
+ readHeight -= (srcY + readHeight -
(GLint) ctx->ReadBuffer->Height
);
if (readHeight <= 0)
return GL_TRUE;
if (readHeight <= 0)
return GL_TRUE;
@@
-280,13
+288,20
@@
read_fast_rgba_pixels( GLcontext *ctx,
if (0) {
#endif
GLchan *dest = (GLchan *) pixels
if (0) {
#endif
GLchan *dest = (GLchan *) pixels
-
+ (skipRows * rowLength + skipPixels) * 4;
+ + (skipRows * rowLength + skipPixels) * 4;
GLint row;
GLint row;
+
+ if (packing->Invert) {
+ /* start at top and go down */
+ dest += (readHeight - 1) * rowLength * 4;
+ rowLength = -rowLength;
+ }
+
for (row=0; row<readHeight; row++) {
for (row=0; row<readHeight; row++) {
- (*
ctx
->Driver.ReadRGBASpan)(ctx, readWidth, srcX, srcY,
+ (*
swrast
->Driver.ReadRGBASpan)(ctx, readWidth, srcX, srcY,
(GLchan (*)[4]) dest);
if (ctx->DrawBuffer->UseSoftwareAlphaBuffers) {
(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;
(GLchan (*)[4]) dest);
}
dest += rowLength * 4;
@@
-313,15
+328,16
@@
read_rgba_pixels( GLcontext *ctx,
GLenum format, GLenum type, GLvoid *pixels,
const struct gl_pixelstore_attrib *packing )
{
GLenum format, GLenum type, GLvoid *pixels,
const struct gl_pixelstore_attrib *packing )
{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLint readWidth;
GLint readWidth;
-
(*ctx->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer
);
+
_swrast_use_read_buffer(ctx
);
/* Try optimized path first */
if (read_fast_rgba_pixels( ctx, x, y, width, height,
format, type, pixels, packing )) {
/* Try optimized path first */
if (read_fast_rgba_pixels( ctx, x, y, width, height,
format, type, pixels, packing )) {
-
(*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer
);
+
_swrast_use_draw_buffer(ctx
);
return; /* done! */
}
return; /* done! */
}
@@
-366,14
+382,14
@@
read_rgba_pixels( GLcontext *ctx,
GLfloat *dest, *src, *tmpImage, *convImage;
GLint row;
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;
}
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) {
if (!convImage) {
-
FREE
(tmpImage);
+
_mesa_free
(tmpImage);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
return;
}
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
return;
}
@@
-383,18
+399,18
@@
read_rgba_pixels( GLcontext *ctx,
for (row = 0; row < height; row++, y++) {
GLchan rgba[MAX_WIDTH][4];
if (ctx->Visual.rgbMode) {
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];
}
else {
GLuint index[MAX_WIDTH];
- (*
ctx
->Driver.ReadCI32Span)(ctx, readWidth, x, y, index);
+ (*
swrast
->Driver.ReadCI32Span)(ctx, readWidth, x, y, index);
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset !=0 ) {
_mesa_map_ci(ctx, readWidth, index);
}
_mesa_map_ci_to_rgba_chan(ctx, readWidth, index, rgba);
}
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset !=0 ) {
_mesa_map_ci(ctx, readWidth, index);
}
_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_p
acking,
+ _mesa_pack_rgba_span
_chan
(ctx, readWidth, (const GLchan (*)[4]) rgba,
+ GL_RGBA, GL_FLOAT, dest, &
ctx->DefaultP
acking,
transferOps & IMAGE_PRE_CONVOLUTION_BITS);
dest += width * 4;
}
transferOps & IMAGE_PRE_CONVOLUTION_BITS);
dest += width * 4;
}
@@
-407,7
+423,7
@@
read_rgba_pixels( GLcontext *ctx,
ASSERT(ctx->Pixel.Separable2DEnabled);
_mesa_convolve_sep_image(ctx, &readWidth, &height, tmpImage, convImage);
}
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;
/* finish transfer ops and pack the resulting image */
src = convImage;
@@
-415,7
+431,7
@@
read_rgba_pixels( GLcontext *ctx,
GLvoid *dest;
dest = _mesa_image_address(packing, pixels, readWidth, height,
format, type, 0, row, 0);
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);
(const GLfloat (*)[4]) src,
format, type, dest, packing,
transferOps & IMAGE_POST_CONVOLUTION_BITS);
@@
-429,11
+445,11
@@
read_rgba_pixels( GLcontext *ctx,
GLchan rgba[MAX_WIDTH][4];
GLvoid *dst;
if (ctx->Visual.rgbMode) {
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];
}
else {
GLuint index[MAX_WIDTH];
- (*
ctx
->Driver.ReadCI32Span)(ctx, readWidth, x, y, index);
+ (*
swrast
->Driver.ReadCI32Span)(ctx, readWidth, x, y, index);
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) {
_mesa_map_ci(ctx, readWidth, index);
}
if (ctx->Pixel.IndexShift != 0 || ctx->Pixel.IndexOffset != 0) {
_mesa_map_ci(ctx, readWidth, index);
}
@@
-448,24
+464,26
@@
read_rgba_pixels( GLcontext *ctx,
* there. This fixes conformance failures with 16-bit color
* buffers, for example.
*/
* there. This fixes conformance failures with 16-bit color
* buffers, for example.
*/
- GLfloat rgbaf[MAX_WIDTH][4];
+ DEFMARRAY(GLfloat, rgbaf, MAX_WIDTH, 4); /* mac 32k limitation */
+ CHECKARRAY(rgbaf, return); /* mac 32k limitation */
_mesa_chan_to_float_span(ctx, readWidth,
(CONST GLchan (*)[4]) rgba, rgbaf);
_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);
(CONST GLfloat (*)[4]) rgbaf,
format, type, dst, packing,
ctx->_ImageTransferState);
+ UNDEFARRAY(rgbaf); /* mac 32k limitation */
}
else {
/* GLubytes are fine */
}
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);
}
}
}
format, type, dst, packing,
ctx->_ImageTransferState);
}
}
}
-
(*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer
);
+
_swrast_use_draw_buffer(ctx
);
}
}
@@
-477,11
+495,22
@@
_swrast_ReadPixels( GLcontext *ctx,
const struct gl_pixelstore_attrib *pack,
GLvoid *pixels )
{
const struct gl_pixelstore_attrib *pack,
GLvoid *pixels )
{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
(void) pack;
(void) pack;
- if (
SWRAST_CONTEXT(ctx)
->NewState)
+ if (
swrast
->NewState)
_swrast_validate_derived( ctx );
_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) {
case GL_COLOR_INDEX:
read_index_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack);
switch (format) {
case GL_COLOR_INDEX:
read_index_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack);
@@
-509,4
+538,6
@@
_swrast_ReadPixels( GLcontext *ctx,
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
}
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
}
+
+ RENDER_FINISH(swrast,ctx);
}
}