From 66940ad2d7145d30cf0381a9a2835efaa0d1ee3f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 29 Jan 2012 19:47:37 -0700 Subject: mesa: added _mesa_pack_ubyte_rgba_rect() Reviewed-by: Eric Anholt --- src/mesa/main/format_pack.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/mesa/main/format_pack.c') diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c index 85b2c691c54..ea1d95ee9e9 100644 --- a/src/mesa/main/format_pack.c +++ b/src/mesa/main/format_pack.c @@ -2049,6 +2049,48 @@ _mesa_pack_ubyte_rgba_row(gl_format format, GLuint n, } +/** + * Pack a 2D image of ubyte RGBA pixels in the given format. + * \param srcRowStride source image row stride in bytes + * \param dstRowStride destination image row stride in bytes + */ +void +_mesa_pack_ubyte_rgba_rect(gl_format format, GLuint width, GLuint height, + const GLubyte *src, GLint srcRowStride, + void *dst, GLint dstRowStride) +{ + pack_ubyte_rgba_row_func packrow = get_pack_ubyte_rgba_row_function(format); + GLubyte *dstUB = (GLubyte *) dst; + GLuint i; + + if (packrow) { + if (srcRowStride == width * 4 * sizeof(GLubyte) && + dstRowStride == _mesa_format_row_stride(format, width)) { + /* do whole image at once */ + packrow(width * height, (const GLubyte (*)[4]) src, dst); + } + else { + /* row by row */ + for (i = 0; i < height; i++) { + packrow(width, (const GLubyte (*)[4]) src, dstUB); + src += srcRowStride; + dstUB += dstRowStride; + } + } + } + else { + /* slower fallback */ + for (i = 0; i < height; i++) { + _mesa_pack_ubyte_rgba_row(format, width, + (const GLubyte (*)[4]) src, dstUB); + src += srcRowStride; + dstUB += dstRowStride; + } + } +} + + + /** ** Pack float Z pixels **/ -- cgit v1.2.3