diff options
author | Brian Paul <brianp@vmware.com> | 2009-09-01 17:11:35 -0600 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-09-01 17:39:32 -0600 |
commit | 278e76832fc26678592368b7b89bfddc137e0e93 (patch) | |
tree | 4c6a157fabb9189a2283a1c264c2f62670b71d11 /src | |
parent | 921bbfc94278d6897d44d1b6ae230315e2ab6e8c (diff) |
mesa: new _mesa_expand_bitmap() function
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/image.c | 85 | ||||
-rw-r--r-- | src/mesa/main/image.h | 7 |
2 files changed, 92 insertions, 0 deletions
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 */ /*@{*/ |