-/* $Id: drawpix.c,v 1.7 1999/11/18 15:44:37 brianp Exp $ */
+/* $Id: drawpix.c,v 1.8 1999/11/22 22:21:38 brianp Exp $ */
/*
* Mesa 3-D graphics library
+/*
+ * Given the dest position, size and skipPixels and skipRows values
+ * for a glDrawPixels command, perform clipping of the image bounds
+ * so the result lies withing the context's buffer bounds.
+ * Return: GL_TRUE if image is ready for drawing
+ * GL_FALSE if image was completely clipped away (draw nothing)
+ */
+GLboolean
+_mesa_clip_pixelrect(const GLcontext *ctx,
+ GLint *destX, GLint *destY,
+ GLsizei *width, GLsizei *height,
+ GLint *skipPixels, GLint *skipRows)
+{
+ /* left clipping */
+ if (*destX < ctx->Buffer->Xmin) {
+ *skipPixels += (ctx->Buffer->Xmin - *destX);
+ *width -= (ctx->Buffer->Xmin - *destX);
+ *destX = ctx->Buffer->Xmin;
+ }
+ /* right clipping */
+ if (*destX + *width > ctx->Buffer->Xmax)
+ *width -= (*destX + *width - ctx->Buffer->Xmax - 1);
+
+ if (*width <= 0)
+ return GL_FALSE;
+
+ /* bottom clipping */
+ if (*destY < ctx->Buffer->Ymin) {
+ *skipRows += (ctx->Buffer->Ymin - *destY);
+ *height -= (ctx->Buffer->Ymin - *destY);
+ *destY = ctx->Buffer->Ymin;
+ }
+ /* top clipping */
+ if (*destY + *height > ctx->Buffer->Ymax)
+ *height -= (*destY + *height - ctx->Buffer->Ymax - 1);
+
+ if (*height <= 0)
+ return GL_TRUE;
+
+ return GL_TRUE;
+}
+
+
+
/*
* Try to do a fast and simple RGB(a) glDrawPixels.
* Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
-/* $Id: drawpix.h,v 1.2 1999/11/11 01:22:26 brianp Exp $ */
+/* $Id: drawpix.h,v 1.3 1999/11/22 22:21:38 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "types.h"
+extern GLboolean
+_mesa_clip_pixelrect(const GLcontext *ctx,
+ GLint *destX, GLint *destY,
+ GLsizei *width, GLsizei *height,
+ GLint *skipPixels, GLint *skipRows);
+
+
extern void
_mesa_DrawPixels( GLsizei width, GLsizei height,
GLenum format, GLenum type, const GLvoid *pixels );