summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2000-03-13 18:31:51 +0000
committerBrian Paul <[email protected]>2000-03-13 18:31:51 +0000
commit7c652d77220610ecc19aaefa20876216b035e961 (patch)
tree81703d849e0fb821102f121f757714ed07a41770 /src/mesa/main
parent3cb112129998e8a4ae8499b47a7c5325ef08bc64 (diff)
fixed polygon stipple packing/unpacking
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/image.c153
-rw-r--r--src/mesa/main/image.h20
-rw-r--r--src/mesa/main/polygon.c13
3 files changed, 140 insertions, 46 deletions
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index a1a0fe20eec..6c7e66dd64b 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1,4 +1,4 @@
-/* $Id: image.c,v 1.18 2000/03/03 17:47:39 brianp Exp $ */
+/* $Id: image.c,v 1.19 2000/03/13 18:31:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -493,22 +493,25 @@ GLvoid *gl_pixel_addr_in_image( const struct gl_pixelstore_attrib *packing,
* Unpack a 32x32 pixel polygon stipple from user memory using the
* current pixel unpack settings.
*/
-void gl_unpack_polygon_stipple( const GLcontext *ctx,
- const GLubyte *pattern, GLuint dest[32] )
+void
+_mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32],
+ const struct gl_pixelstore_attrib *unpacking )
{
- GLint i;
- for (i = 0; i < 32; i++) {
- GLubyte *src = (GLubyte *) gl_pixel_addr_in_image( &ctx->Unpack, pattern,
- 32, 32, GL_COLOR_INDEX, GL_BITMAP, 0, i, 0 );
- dest[i] = (src[0] << 24)
- | (src[1] << 16)
- | (src[2] << 8)
- | (src[3] );
- }
-
- /* Bit flipping within each byte */
- if (ctx->Unpack.LsbFirst) {
- gl_flip_bytes( (GLubyte *) dest, 32 * 4 );
+ GLubyte *ptrn = _mesa_unpack_bitmap( 32, 32, pattern, unpacking );
+ if (ptrn) {
+ /* Convert pattern from GLubytes to GLuints and handle big/little
+ * endian differences
+ */
+ GLubyte *p = ptrn;
+ GLint i;
+ for (i = 0; i < 32; i++) {
+ dest[i] = (p[0] << 24)
+ | (p[1] << 16)
+ | (p[2] << 8)
+ | (p[3] );
+ p += 4;
+ }
+ FREE(ptrn);
}
}
@@ -518,24 +521,23 @@ void gl_unpack_polygon_stipple( const GLcontext *ctx,
* Pack polygon stipple into user memory given current pixel packing
* settings.
*/
-void gl_pack_polygon_stipple( const GLcontext *ctx,
- const GLuint pattern[32],
- GLubyte *dest )
+void
+_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest,
+ const struct gl_pixelstore_attrib *packing )
{
+ /* Convert pattern from GLuints to GLubytes to handle big/little
+ * endian differences.
+ */
+ GLubyte ptrn[32*4];
GLint i;
for (i = 0; i < 32; i++) {
- GLubyte *dst = (GLubyte *) gl_pixel_addr_in_image( &ctx->Pack, dest,
- 32, 32, GL_COLOR_INDEX, GL_BITMAP, 0, i, 0 );
- dst[0] = (pattern[i] >> 24) & 0xff;
- dst[1] = (pattern[i] >> 16) & 0xff;
- dst[2] = (pattern[i] >> 8) & 0xff;
- dst[3] = (pattern[i] ) & 0xff;
-
- /* Bit flipping within each byte */
- if (ctx->Pack.LsbFirst) {
- gl_flip_bytes( (GLubyte *) dst, 4 );
- }
+ ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff);
+ ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff);
+ ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff);
+ ptrn[i * 4 + 3] = (GLubyte) ((pattern[i] ) & 0xff);
}
+
+ _mesa_pack_bitmap(32, 32, ptrn, dest, packing);
}
@@ -2827,3 +2829,94 @@ _mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels,
return buffer;
}
+
+
+/*
+ * Pack bitmap data.
+ */
+void
+_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
+ GLubyte *dest, const struct gl_pixelstore_attrib *packing )
+{
+ GLint row, width_in_bytes;
+ const GLubyte *src;
+
+ if (!source)
+ return;
+
+ width_in_bytes = CEILING( width, 8 );
+ src = source;
+ for (row = 0; row < height; row++) {
+ GLubyte *dst = gl_pixel_addr_in_image( packing, dest, width, height,
+ GL_COLOR_INDEX, GL_BITMAP,
+ 0, row, 0 );
+ if (!dst)
+ return;
+
+ if (packing->SkipPixels == 0) {
+ MEMCPY( dst, src, width_in_bytes );
+ if (packing->LsbFirst) {
+ gl_flip_bytes( dst, width_in_bytes );
+ }
+ }
+ else {
+ /* handling SkipPixels is a bit tricky (no pun intended!) */
+ GLint i;
+ if (packing->LsbFirst) {
+ GLubyte srcMask = 1 << (packing->SkipPixels & 0x7);
+ GLubyte dstMask = 128;
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 128) {
+ srcMask = 1;
+ s++;
+ }
+ else {
+ srcMask = srcMask << 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ else {
+ GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7);
+ GLubyte dstMask = 128;
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 1) {
+ srcMask = 128;
+ s++;
+ }
+ else {
+ srcMask = srcMask >> 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ }
+ src += width_in_bytes;
+ }
+}
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index 03651cc14a1..252363c8da2 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -1,10 +1,10 @@
-/* $Id: image.h,v 1.3 1999/11/11 01:22:27 brianp Exp $ */
+/* $Id: image.h,v 1.4 2000/03/13 18:31:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.1
+ * Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 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"),
@@ -62,15 +62,13 @@ gl_pixel_addr_in_image( const struct gl_pixelstore_attrib *packing,
extern void
-gl_unpack_polygon_stipple( const GLcontext *ctx,
- const GLubyte *pattern,
- GLuint dest[32] );
+_mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32],
+ const struct gl_pixelstore_attrib *unpacking );
extern void
-gl_pack_polygon_stipple( const GLcontext *ctx,
- const GLuint pattern[32],
- GLubyte *dest );
+_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest,
+ const struct gl_pixelstore_attrib *packing );
extern void
@@ -123,5 +121,9 @@ extern GLvoid *
_mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels,
const struct gl_pixelstore_attrib *packing );
+extern void
+_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
+ GLubyte *dest, const struct gl_pixelstore_attrib *packing );
+
#endif
diff --git a/src/mesa/main/polygon.c b/src/mesa/main/polygon.c
index b461ac2998f..5fb07b41209 100644
--- a/src/mesa/main/polygon.c
+++ b/src/mesa/main/polygon.c
@@ -1,10 +1,10 @@
-/* $Id: polygon.c,v 1.9 2000/03/03 17:47:39 brianp Exp $ */
+/* $Id: polygon.c,v 1.10 2000/03/13 18:31:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 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"),
@@ -136,23 +136,22 @@ _mesa_PolygonMode( GLenum face, GLenum mode )
* NOTE: stipple pattern has already been unpacked.
*/
void
-_mesa_PolygonStipple( const GLubyte *mask )
+_mesa_PolygonStipple( const GLubyte *pattern )
{
GET_CURRENT_CONTEXT(ctx);
- GLuint *pattern = (GLuint *) mask; /* XXX verify */
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonStipple");
if (MESA_VERBOSE&VERBOSE_API)
fprintf(stderr, "glPolygonStipple\n");
- MEMCPY( ctx->PolygonStipple, pattern, 32 * 4 );
+ _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
if (ctx->Polygon.StippleFlag) {
ctx->NewState |= NEW_RASTER_OPS;
}
if (ctx->Driver.PolygonStipple)
- ctx->Driver.PolygonStipple( ctx, mask );
+ ctx->Driver.PolygonStipple( ctx, (const GLubyte *) ctx->PolygonStipple );
}
@@ -166,7 +165,7 @@ _mesa_GetPolygonStipple( GLubyte *dest )
if (MESA_VERBOSE&VERBOSE_API)
fprintf(stderr, "glGetPolygonStipple\n");
- gl_pack_polygon_stipple( ctx, ctx->PolygonStipple, dest );
+ _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
}