/*
* Mesa 3-D graphics library
- * Version: 7.5
*
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
* Copyright (C) 2009 VMware, Inc. All Rights Reserved.
* 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.
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 "image.h"
#include "imports.h"
#include "macros.h"
-#include "mfeatures.h"
#include "mtypes.h"
/**
- * Flip the order of the 2 bytes in each word in the given array.
+ * Flip the order of the 2 bytes in each word in the given array (src) and
+ * store the result in another array (dst). For in-place byte-swapping this
+ * function can be called with the same array for src and dst.
*
- * \param p array.
+ * \param dst the array where byte-swapped data will be stored.
+ * \param src the array with the source data we want to byte-swap.
* \param n number of words.
*/
-void
-_mesa_swap2( GLushort *p, GLuint n )
+static void
+swap2_copy( GLushort *dst, GLushort *src, GLuint n )
{
GLuint i;
for (i = 0; i < n; i++) {
- p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00);
+ dst[i] = (src[i] >> 8) | ((src[i] << 8) & 0xff00);
}
}
-
+void
+_mesa_swap2(GLushort *p, GLuint n)
+{
+ swap2_copy(p, p, n);
+}
/*
- * Flip the order of the 4 bytes in each word in the given array.
+ * Flip the order of the 4 bytes in each word in the given array (src) and
+ * store the result in another array (dst). For in-place byte-swapping this
+ * function can be called with the same array for src and dst.
+ *
+ * \param dst the array where byte-swapped data will be stored.
+ * \param src the array with the source data we want to byte-swap.
+ * \param n number of words.
*/
-void
-_mesa_swap4( GLuint *p, GLuint n )
+static void
+swap4_copy( GLuint *dst, GLuint *src, GLuint n )
{
GLuint i, a, b;
for (i = 0; i < n; i++) {
- b = p[i];
+ b = src[i];
a = (b >> 24)
| ((b >> 8) & 0xff00)
| ((b << 8) & 0xff0000)
| ((b << 24) & 0xff000000);
- p[i] = a;
+ dst[i] = a;
}
}
-
-/**
- * Do error checking of format/type combinations for glReadPixels,
- * glDrawPixels and glTex[Sub]Image. Note that depending on the format
- * and type values, we may either generate GL_INVALID_OPERATION or
- * GL_INVALID_ENUM.
- *
- * \param format pixel format.
- * \param type pixel type.
- *
- * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
- */
-GLenum
-_mesa_error_check_format_and_type(const struct gl_context *ctx,
- GLenum format, GLenum type)
+void
+_mesa_swap4(GLuint *p, GLuint n)
{
- /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
- switch (type) {
- case GL_BITMAP:
- if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) {
- return GL_INVALID_ENUM;
- }
- break;
-
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- if (format == GL_RGB) {
- break; /* OK */
- }
- if (format == GL_RGB_INTEGER_EXT &&
- ctx->Extensions.ARB_texture_rgb10_a2ui) {
- break; /* OK */
- }
- return GL_INVALID_OPERATION;
-
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- if (format == GL_RGBA ||
- format == GL_BGRA ||
- format == GL_ABGR_EXT) {
- break; /* OK */
- }
- if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) &&
- ctx->Extensions.ARB_texture_rgb10_a2ui) {
- break; /* OK */
- }
- return GL_INVALID_OPERATION;
-
- case GL_UNSIGNED_INT_24_8:
- if (!ctx->Extensions.EXT_packed_depth_stencil) {
- return GL_INVALID_ENUM;
- }
- if (format != GL_DEPTH_STENCIL) {
- return GL_INVALID_OPERATION;
- }
- return GL_NO_ERROR;
-
- case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
- if (!ctx->Extensions.ARB_depth_buffer_float) {
- return GL_INVALID_ENUM;
- }
- if (format != GL_DEPTH_STENCIL) {
- return GL_INVALID_OPERATION;
- }
- return GL_NO_ERROR;
-
- case GL_UNSIGNED_INT_10F_11F_11F_REV:
- if (!ctx->Extensions.EXT_packed_float) {
- return GL_INVALID_ENUM;
- }
- if (format != GL_RGB) {
- return GL_INVALID_OPERATION;
- }
- return GL_NO_ERROR;
-
- default:
- ; /* fall-through */
- }
-
- /* now, for each format, check the type for compatibility */
- switch (format) {
- case GL_COLOR_INDEX:
- case GL_STENCIL_INDEX:
- switch (type) {
- case GL_BITMAP:
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_NO_ERROR;
- case GL_HALF_FLOAT:
- return ctx->Extensions.ARB_half_float_pixel
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
-#if 0 /* not legal! see table 3.6 of the 1.5 spec */
- case GL_INTENSITY:
-#endif
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_DEPTH_COMPONENT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_NO_ERROR;
- case GL_HALF_FLOAT:
- return ctx->Extensions.ARB_half_float_pixel
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_RG:
- if (!ctx->Extensions.ARB_texture_rg)
- return GL_INVALID_ENUM;
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_NO_ERROR;
- case GL_HALF_FLOAT:
- return ctx->Extensions.ARB_half_float_pixel
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_RGB:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- return GL_NO_ERROR;
- case GL_HALF_FLOAT:
- return ctx->Extensions.ARB_half_float_pixel
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- case GL_UNSIGNED_INT_5_9_9_9_REV:
- return ctx->Extensions.EXT_texture_shared_exponent
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- case GL_UNSIGNED_INT_10F_11F_11F_REV:
- return ctx->Extensions.EXT_packed_float
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_BGR:
- switch (type) {
- /* NOTE: no packed types are supported with BGR. That's
- * intentional, according to the GL spec.
- */
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_NO_ERROR;
- case GL_HALF_FLOAT:
- return ctx->Extensions.ARB_half_float_pixel
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return GL_NO_ERROR;
- case GL_HALF_FLOAT:
- return ctx->Extensions.ARB_half_float_pixel
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_YCBCR_MESA:
- if (!ctx->Extensions.MESA_ycbcr_texture)
- return GL_INVALID_ENUM;
- if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
- type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
- return GL_NO_ERROR;
- else
- return GL_INVALID_OPERATION;
-
- case GL_DEPTH_STENCIL_EXT:
- if (ctx->Extensions.EXT_packed_depth_stencil &&
- type == GL_UNSIGNED_INT_24_8)
- return GL_NO_ERROR;
- else if (ctx->Extensions.ARB_depth_buffer_float &&
- type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
- return GL_NO_ERROR;
- else
- return GL_INVALID_ENUM;
-
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- if (!ctx->Extensions.ATI_envmap_bumpmap)
- return GL_INVALID_ENUM;
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_NO_ERROR;
- default:
- return GL_INVALID_ENUM;
- }
-
- /* integer-valued formats */
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- case GL_RG_INTEGER:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- return (ctx->VersionMajor >= 3 ||
- ctx->Extensions.EXT_texture_integer)
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_RGB_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- return (ctx->VersionMajor >= 3 ||
- ctx->Extensions.EXT_texture_integer)
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- return ctx->Extensions.ARB_texture_rgb10_a2ui
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_BGR_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- /* NOTE: no packed formats w/ BGR format */
- return (ctx->VersionMajor >= 3 ||
- ctx->Extensions.EXT_texture_integer)
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_RGBA_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- return (ctx->VersionMajor >= 3 ||
- ctx->Extensions.EXT_texture_integer)
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return ctx->Extensions.ARB_texture_rgb10_a2ui
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- return ctx->Extensions.EXT_texture_integer
- ? GL_NO_ERROR : GL_INVALID_ENUM;
- default:
- return GL_INVALID_ENUM;
- }
-
- default:
- return GL_INVALID_ENUM;
- }
- return GL_NO_ERROR;
+ swap4_copy(p, p, n);
}
-
/**
* Return the byte offset of a specific pixel in an image (1D, 2D or 3D).
*
GLint skipimages; /* for 3-D volume images */
GLintptr offset;
- ASSERT(dimensions >= 1 && dimensions <= 3);
+ assert(dimensions >= 1 && dimensions <= 3);
alignment = packing->Alignment;
if (packing->RowLength > 0) {
if (type == GL_BITMAP) {
/* BITMAP data */
- GLint bytes_per_row;
- GLint bytes_per_image;
+ GLintptr bytes_per_row;
+ GLintptr bytes_per_image;
/* components per pixel for color or stencil index: */
const GLint comp_per_pixel = 1;
assert(format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX);
bytes_per_row = alignment
- * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
+ * DIV_ROUND_UP( comp_per_pixel*pixels_per_row, 8*alignment );
bytes_per_image = bytes_per_row * rows_per_image;
}
else {
/* Non-BITMAP data */
- GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
- GLint topOfImage;
+ GLintptr bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
+ GLintptr topOfImage;
bytes_per_pixel = _mesa_bytes_per_pixel( format, type );
if (remainder > 0)
bytes_per_row += (alignment - remainder);
- ASSERT(bytes_per_row % alignment == 0);
+ assert(bytes_per_row % alignment == 0);
bytes_per_image = bytes_per_row * rows_per_image;
{
GLint bytesPerRow, remainder;
- ASSERT(packing);
+ assert(packing);
if (type == GL_BITMAP) {
if (packing->RowLength == 0) {
{
GLint bytesPerRow, bytesPerImage, remainder;
- ASSERT(packing);
+ assert(packing);
if (type == GL_BITMAP) {
if (packing->RowLength == 0) {
const GLint srcStride = _mesa_image_row_stride(unpack, width,
GL_COLOR_INDEX, GL_BITMAP);
GLint row, col;
-
-#define SET_PIXEL(COL, ROW) \
- destBuffer[(ROW) * destStride + (COL)] = onValue;
+ GLubyte *dstRow = destBuffer;
for (row = 0; row < height; row++) {
const GLubyte *src = srcRow;
for (col = 0; col < width; col++) {
if (*src & mask) {
- SET_PIXEL(col, row);
+ dstRow[col] = onValue;
}
if (mask == 128U) {
for (col = 0; col < width; col++) {
if (*src & mask) {
- SET_PIXEL(col, row);
+ dstRow[col] = onValue;
}
if (mask == 1U) {
}
srcRow += srcStride;
+ dstRow += destStride;
} /* row */
-
-#undef SET_PIXEL
}
if (!tempBuffer)
return;
- ASSERT(srcType != dstType);
+ assert(srcType != dstType);
switch (srcType) {
case GL_UNSIGNED_BYTE:
const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
GLuint i;
- ASSERT(dstType == GL_FLOAT);
+ assert(dstType == GL_FLOAT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
dst4[i][RCOMP] = UBYTE_TO_FLOAT(src1[i][RCOMP]);
const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
GLuint i;
- ASSERT(dstType == GL_FLOAT);
+ assert(dstType == GL_FLOAT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
dst4[i][RCOMP] = USHORT_TO_FLOAT(src2[i][RCOMP]);
const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
GLuint i;
- ASSERT(dstType == GL_UNSIGNED_SHORT);
+ assert(dstType == GL_UNSIGNED_SHORT);
for (i = 0; i < count; i++) {
if (!mask || mask[i]) {
UNCLAMPED_FLOAT_TO_USHORT(dst2[i][RCOMP], src4[i][RCOMP]);
unpack->RowLength = *width;
}
- ASSERT(ctx->Pixel.ZoomX == 1.0F);
- ASSERT(ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F);
+ assert(ctx->Pixel.ZoomX == 1.0F);
+ assert(ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F);
/* left clipping */
if (*destX < buffer->_Xmin) {
* so that the image region is entirely within the window bounds.
* Note: this is different from _mesa_clip_drawpixels() in that the
* scissor box is ignored, and we use the bounds of the current readbuffer
- * surface.
+ * surface or the attached image.
*
* \return GL_TRUE if region to read is in bounds
* GL_FALSE if region is completely out of bounds (nothing to read)
struct gl_pixelstore_attrib *pack)
{
const struct gl_framebuffer *buffer = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = buffer->_ColorReadBuffer;
+ GLsizei clip_width;
+ GLsizei clip_height;
+
+ if (rb) {
+ clip_width = rb->Width;
+ clip_height = rb->Height;
+ } else {
+ clip_width = buffer->Width;
+ clip_height = buffer->Height;
+ }
+
if (pack->RowLength == 0) {
pack->RowLength = *width;
*srcX = 0;
}
/* right clipping */
- if (*srcX + *width > (GLsizei) buffer->Width)
- *width -= (*srcX + *width - buffer->Width);
+ if (*srcX + *width > clip_width)
+ *width -= (*srcX + *width - clip_width);
if (*width <= 0)
return GL_FALSE;
*srcY = 0;
}
/* top clipping */
- if (*srcY + *height > (GLsizei) buffer->Height)
- *height -= (*srcY + *height - buffer->Height);
+ if (*srcY + *height > clip_height)
+ *height -= (*srcY + *height - clip_height);
if (*height <= 0)
return GL_FALSE;
if (*dstX1 > maxValue) {
/* X1 outside right edge */
- ASSERT(*dstX0 < maxValue); /* X0 should be inside right edge */
+ assert(*dstX0 < maxValue); /* X0 should be inside right edge */
t = (GLfloat) (maxValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
/* chop off [t, 1] part */
- ASSERT(t >= 0.0 && t <= 1.0);
+ assert(t >= 0.0 && t <= 1.0);
*dstX1 = maxValue;
bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
*srcX1 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
}
else if (*dstX0 > maxValue) {
/* X0 outside right edge */
- ASSERT(*dstX1 < maxValue); /* X1 should be inside right edge */
+ assert(*dstX1 < maxValue); /* X1 should be inside right edge */
t = (GLfloat) (maxValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
/* chop off [t, 1] part */
- ASSERT(t >= 0.0 && t <= 1.0);
+ assert(t >= 0.0 && t <= 1.0);
*dstX0 = maxValue;
bias = (*srcX0 < *srcX1) ? -0.5F : 0.5F;
*srcX0 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
if (*dstX0 < minValue) {
/* X0 outside left edge */
- ASSERT(*dstX1 > minValue); /* X1 should be inside left edge */
+ assert(*dstX1 > minValue); /* X1 should be inside left edge */
t = (GLfloat) (minValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
/* chop off [0, t] part */
- ASSERT(t >= 0.0 && t <= 1.0);
+ assert(t >= 0.0 && t <= 1.0);
*dstX0 = minValue;
- bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F; /* flipped??? */
+ bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
*srcX0 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
}
else if (*dstX1 < minValue) {
/* X1 outside left edge */
- ASSERT(*dstX0 > minValue); /* X0 should be inside left edge */
+ assert(*dstX0 > minValue); /* X0 should be inside left edge */
t = (GLfloat) (minValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
/* chop off [0, t] part */
- ASSERT(t >= 0.0 && t <= 1.0);
+ assert(t >= 0.0 && t <= 1.0);
*dstX1 = minValue;
- bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
+ bias = (*srcX0 < *srcX1) ? -0.5F : 0.5F;
*srcX1 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
}
}
*/
GLboolean
_mesa_clip_blit(struct gl_context *ctx,
+ const struct gl_framebuffer *readFb,
+ const struct gl_framebuffer *drawFb,
GLint *srcX0, GLint *srcY0, GLint *srcX1, GLint *srcY1,
GLint *dstX0, GLint *dstY0, GLint *dstX1, GLint *dstY1)
{
const GLint srcXmin = 0;
- const GLint srcXmax = ctx->ReadBuffer->Width;
+ const GLint srcXmax = readFb->Width;
const GLint srcYmin = 0;
- const GLint srcYmax = ctx->ReadBuffer->Height;
+ const GLint srcYmax = readFb->Height;
/* these include scissor bounds */
- const GLint dstXmin = ctx->DrawBuffer->_Xmin;
- const GLint dstXmax = ctx->DrawBuffer->_Xmax;
- const GLint dstYmin = ctx->DrawBuffer->_Ymin;
- const GLint dstYmax = ctx->DrawBuffer->_Ymax;
+ const GLint dstXmin = drawFb->_Xmin;
+ const GLint dstXmax = drawFb->_Xmax;
+ const GLint dstYmin = drawFb->_Ymin;
+ const GLint dstYmax = drawFb->_Ymax;
/*
printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
*srcY0, *srcY1, *dstY0, *dstY1);
*/
- ASSERT(*dstX0 >= dstXmin);
- ASSERT(*dstX0 <= dstXmax);
- ASSERT(*dstX1 >= dstXmin);
- ASSERT(*dstX1 <= dstXmax);
+ assert(*dstX0 >= dstXmin);
+ assert(*dstX0 <= dstXmax);
+ assert(*dstX1 >= dstXmin);
+ assert(*dstX1 <= dstXmax);
- ASSERT(*dstY0 >= dstYmin);
- ASSERT(*dstY0 <= dstYmax);
- ASSERT(*dstY1 >= dstYmin);
- ASSERT(*dstY1 <= dstYmax);
+ assert(*dstY0 >= dstYmin);
+ assert(*dstY0 <= dstYmax);
+ assert(*dstY1 >= dstYmin);
+ assert(*dstY1 <= dstYmax);
- ASSERT(*srcX0 >= srcXmin);
- ASSERT(*srcX0 <= srcXmax);
- ASSERT(*srcX1 >= srcXmin);
- ASSERT(*srcX1 <= srcXmax);
+ assert(*srcX0 >= srcXmin);
+ assert(*srcX0 <= srcXmax);
+ assert(*srcX1 >= srcXmin);
+ assert(*srcX1 <= srcXmax);
- ASSERT(*srcY0 >= srcYmin);
- ASSERT(*srcY0 <= srcYmax);
- ASSERT(*srcY1 >= srcYmin);
- ASSERT(*srcY1 <= srcYmax);
+ assert(*srcY0 >= srcYmin);
+ assert(*srcY0 <= srcYmax);
+ assert(*srcY1 >= srcYmin);
+ assert(*srcY1 <= srcYmax);
return GL_TRUE;
}
+
+/**
+ * Swap the bytes in a 2D image.
+ *
+ * using the packing information this swaps the bytes
+ * according to the format and type of data being input.
+ * It takes into a/c various packing parameters like
+ * Alignment and RowLength.
+ */
+void
+_mesa_swap_bytes_2d_image(GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *packing,
+ GLsizei width, GLsizei height,
+ GLvoid *dst, const GLvoid *src)
+{
+ GLint swapSize = _mesa_sizeof_packed_type(type);
+
+ assert(packing->SwapBytes);
+
+ if (swapSize == 2 || swapSize == 4) {
+ int swapsPerPixel = _mesa_bytes_per_pixel(format, type) / swapSize;
+ int stride = _mesa_image_row_stride(packing, width, format, type);
+ int row;
+ uint8_t *dstrow;
+ const uint8_t *srcrow;
+ assert(swapsPerPixel > 0);
+ assert(_mesa_bytes_per_pixel(format, type) % swapSize == 0);
+ dstrow = dst;
+ srcrow = src;
+ for (row = 0; row < height; row++) {
+ if (swapSize == 2)
+ swap2_copy((GLushort *)dstrow, (GLushort *)srcrow, width * swapsPerPixel);
+ else if (swapSize == 4)
+ swap4_copy((GLuint *)dstrow, (GLuint *)srcrow, width * swapsPerPixel);
+ dstrow += stride;
+ srcrow += stride;
+ }
+ }
+}