From 278e76832fc26678592368b7b89bfddc137e0e93 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 1 Sep 2009 17:11:35 -0600 Subject: mesa: new _mesa_expand_bitmap() function --- src/mesa/main/image.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/mesa/main/image.h | 7 +++++ 2 files changed, 92 insertions(+) (limited to 'src') diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index 006a55116b..baecbab0a3 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -1259,6 +1259,91 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, } +/** + * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel. + * This is typically used to convert a bitmap into a GLubyte/pixel texture. + * "On" bits will set texels to \p onValue. + * "Off" bits will not modify texels. + * \param width src bitmap width in pixels + * \param height src bitmap height in pixels + * \param unpack bitmap unpacking state + * \param bitmap the src bitmap data + * \param destBuffer start of dest buffer + * \param destStride row stride in dest buffer + * \param onValue if bit is 1, set destBuffer pixel to this value + */ +void +_mesa_expand_bitmap(GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap, + GLubyte *destBuffer, GLint destStride, + GLubyte onValue) +{ + const GLubyte *srcRow = (const GLubyte *) + _mesa_image_address2d(unpack, bitmap, width, height, + GL_COLOR_INDEX, GL_BITMAP, 0, 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; + + for (row = 0; row < height; row++) { + const GLubyte *src = srcRow; + + if (unpack->LsbFirst) { + /* Lsb first */ + GLubyte mask = 1U << (unpack->SkipPixels & 0x7); + for (col = 0; col < width; col++) { + + if (*src & mask) { + SET_PIXEL(col, row); + } + + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + + /* get ready for next row */ + if (mask != 1) + src++; + } + else { + /* Msb first */ + GLubyte mask = 128U >> (unpack->SkipPixels & 0x7); + for (col = 0; col < width; col++) { + + if (*src & mask) { + SET_PIXEL(col, row); + } + + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + + /* get ready for next row */ + if (mask != 128) + src++; + } + + srcRow += srcStride; + } /* row */ + +#undef SET_PIXEL +} + + /**********************************************************************/ /***** Pixel processing functions ******/ /**********************************************************************/ diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h index a082f37457..72717d6787 100644 --- a/src/mesa/main/image.h +++ b/src/mesa/main/image.h @@ -134,6 +134,13 @@ extern void _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, GLubyte *dest, const struct gl_pixelstore_attrib *packing ); +extern void +_mesa_expand_bitmap(GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap, + GLubyte *destBuffer, GLint destStride, + GLubyte onValue); + /** \name Pixel processing functions */ /*@{*/ -- cgit v1.2.3