Mesa (master): util: allocate larger tmp_row in util_format_translate

Keith Whitwell keithw at kemper.freedesktop.org
Mon Jun 7 08:35:43 PDT 2010


Module: Mesa
Branch: master
Commit: ac7c8f7dd3649507f6a5dc4d5222124dd954cbfd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ac7c8f7dd3649507f6a5dc4d5222124dd954cbfd

Author: Keith Whitwell <keithw at vmware.com>
Date:   Sun May 30 13:26:36 2010 +0100

util: allocate larger tmp_row in util_format_translate

The tmp_row storage allocation took into account the format's y block
size by allocating y_step rows of data.  However, the x block size was
not being taken into account when deciding how wide those rows need to
be.

Now make sure that tmp_row is at least x_step by y_step in size.

---

 src/gallium/auxiliary/util/u_format.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index c50c807..3168a1f 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -189,7 +189,7 @@ util_format_translate(enum pipe_format dst_format,
    const struct util_format_description *src_format_desc;
    uint8_t *dst_row;
    const uint8_t *src_row;
-   unsigned y_step;
+   unsigned x_step, y_step;
    unsigned dst_step;
    unsigned src_step;
 
@@ -221,6 +221,7 @@ util_format_translate(enum pipe_format dst_format,
     */
 
    y_step = MAX2(dst_format_desc->block.height, src_format_desc->block.height);
+   x_step = MAX2(dst_format_desc->block.width, src_format_desc->block.width);
    assert(y_step % dst_format_desc->block.height == 0);
    assert(y_step % src_format_desc->block.height == 0);
 
@@ -237,7 +238,7 @@ util_format_translate(enum pipe_format dst_format,
       unsigned tmp_stride;
       uint8_t *tmp_row;
 
-      tmp_stride = width * 4 * sizeof *tmp_row;
+      tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
       tmp_row = MALLOC(y_step * tmp_stride);
       if (!tmp_row)
          return;
@@ -262,7 +263,7 @@ util_format_translate(enum pipe_format dst_format,
       unsigned tmp_stride;
       float *tmp_row;
 
-      tmp_stride = width * 4 * sizeof *tmp_row;
+      tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
       tmp_row = MALLOC(y_step * tmp_stride);
       if (!tmp_row)
          return;



More information about the mesa-commit mailing list