util: Merge util_format_write_4* functions.
[mesa.git] / src / util / format / u_format.c
index 2d657cb6bb3b9a524640ec9c80f9a7be4437ba11..12af0ed65625c8460d2adb36288135bed957bdaa 100644 (file)
@@ -348,14 +348,13 @@ util_format_read_4f(enum pipe_format format,
 
 
 void
-util_format_write_4f(enum pipe_format format,
-                     const float *src, unsigned src_stride,
+util_format_write_4(enum pipe_format format,
+                     const void *src, unsigned src_stride,
                      void *dst, unsigned dst_stride,
                      unsigned x, unsigned y, unsigned w, unsigned h)
 {
    const struct util_format_description *format_desc;
    uint8_t *dst_row;
-   const float *src_row;
 
    format_desc = util_format_description(format);
 
@@ -363,9 +362,13 @@ util_format_write_4f(enum pipe_format format,
    assert(y % format_desc->block.height == 0);
 
    dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
-   src_row = src;
 
-   format_desc->pack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h);
+   if (util_format_is_pure_uint(format))
+      format_desc->pack_rgba_uint(dst_row, dst_stride, src, src_stride, w, h);
+   else if (util_format_is_pure_sint(format))
+      format_desc->pack_rgba_sint(dst_row, dst_stride, src, src_stride, w, h);
+   else
+      format_desc->pack_rgba_float(dst_row, dst_stride, src, src_stride, w, h);
 }
 
 
@@ -427,27 +430,6 @@ util_format_read_4ui(enum pipe_format format,
    format_desc->unpack_rgba_uint(dst_row, dst_stride, src_row, src_stride, w, h);
 }
 
-void
-util_format_write_4ui(enum pipe_format format,
-                      const unsigned int *src, unsigned src_stride,
-                      void *dst, unsigned dst_stride,
-                      unsigned x, unsigned y, unsigned w, unsigned h)
-{
-   const struct util_format_description *format_desc;
-   uint8_t *dst_row;
-   const uint32_t *src_row;
-
-   format_desc = util_format_description(format);
-
-   assert(x % format_desc->block.width == 0);
-   assert(y % format_desc->block.height == 0);
-
-   dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
-   src_row = src;
-
-   format_desc->pack_rgba_uint(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
 void
 util_format_read_4i(enum pipe_format format,
                     int *dst, unsigned dst_stride,
@@ -469,27 +451,6 @@ util_format_read_4i(enum pipe_format format,
    format_desc->unpack_rgba_sint(dst_row, dst_stride, src_row, src_stride, w, h);
 }
 
-void
-util_format_write_4i(enum pipe_format format,
-                      const int *src, unsigned src_stride,
-                      void *dst, unsigned dst_stride,
-                      unsigned x, unsigned y, unsigned w, unsigned h)
-{
-   const struct util_format_description *format_desc;
-   uint8_t *dst_row;
-   const int32_t *src_row;
-
-   format_desc = util_format_description(format);
-
-   assert(x % format_desc->block.width == 0);
-   assert(y % format_desc->block.height == 0);
-
-   dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
-   src_row = src;
-
-   format_desc->pack_rgba_sint(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
 /**
  * Check if we can safely memcopy from the source format to the dest format.
  * This basically covers the cases of a "used" channel copied to a typeless