<div dir="ltr">Any reason why you added 2 new functions, instead of just altering the ones we have and updating where they are used?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 18, 2014 at 1:23 AM, Iago Toral Quiroga <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We have _mesa_swap{2,4} but these do in-place byte-swapping only. The new<br>
functions receive an extra parameter so we can swap bytes on a source<br>
input array and store the results in a (possibly different) destination<br>
array.<br>
<br>
This is useful to implement byte-swapping in pixel uploads, since in this<br>
case we need to swap bytes on the src data which is owned by the<br>
application so we can't do an in-place byte swap.<br>
---<br>
 src/mesa/main/image.c | 25 +++++++++++++++++--------<br>
 src/mesa/main/image.h | 10 ++++++++--<br>
 2 files changed, 25 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c<br>
index 4ea5f04..9ad97c5 100644<br>
--- a/src/mesa/main/image.c<br>
+++ b/src/mesa/main/image.c<br>
@@ -41,36 +41,45 @@<br>
<br>
<br>
 /**<br>
- * Flip the order of the 2 bytes in each word in the given array.<br>
+ * Flip the order of the 2 bytes in each word in the given array (src) and<br>
+ * store the result in another array (dst). For in-place byte-swapping this<br>
+ * function can be called with the same array for src and dst.<br>
  *<br>
- * \param p array.<br>
+ * \param dst the array where byte-swapped data will be stored.<br>
+ * \param src the array with the source data we want to byte-swap.<br>
  * \param n number of words.<br>
  */<br>
 void<br>
-_mesa_swap2( GLushort *p, GLuint n )<br>
+_mesa_swap2_copy( GLushort *dst, GLushort *src, GLuint n )<br>
 {<br>
    GLuint i;<br>
    for (i = 0; i < n; i++) {<br>
-      p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00);<br>
+      dst[i] = (src[i] >> 8) | ((src[i] << 8) & 0xff00);<br>
    }<br>
 }<br>
<br>
<br>
<br>
 /*<br>
- * Flip the order of the 4 bytes in each word in the given array.<br>
+ * Flip the order of the 4 bytes in each word in the given array (src) and<br>
+ * store the result in another array (dst). For in-place byte-swapping this<br>
+ * function can be called with the same array for src and dst.<br>
+ *<br>
+ * \param dst the array where byte-swapped data will be stored.<br>
+ * \param src the array with the source data we want to byte-swap.<br>
+ * \param n number of words.<br>
  */<br>
 void<br>
-_mesa_swap4( GLuint *p, GLuint n )<br>
+_mesa_swap4_copy( GLuint *dst, GLuint *src, GLuint n )<br>
 {<br>
    GLuint i, a, b;<br>
    for (i = 0; i < n; i++) {<br>
-      b = p[i];<br>
+      b = src[i];<br>
       a =  (b >> 24)<br>
        | ((b >> 8) & 0xff00)<br>
        | ((b << 8) & 0xff0000)<br>
        | ((b << 24) & 0xff000000);<br>
-      p[i] = a;<br>
+      dst[i] = a;<br>
    }<br>
 }<br>
<br>
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h<br>
index abd84bf..79c6e68 100644<br>
--- a/src/mesa/main/image.h<br>
+++ b/src/mesa/main/image.h<br>
@@ -33,10 +33,16 @@ struct gl_context;<br>
 struct gl_pixelstore_attrib;<br>
<br>
 extern void<br>
-_mesa_swap2( GLushort *p, GLuint n );<br>
+_mesa_swap2_copy( GLushort *dst, GLushort *src, GLuint n );<br>
<br>
 extern void<br>
-_mesa_swap4( GLuint *p, GLuint n );<br>
+_mesa_swap4_copy( GLuint *dst, GLuint *src, GLuint n );<br>
+<br>
+static inline void<br>
+_mesa_swap2( GLushort *p, GLuint n ) { _mesa_swap2_copy(p, p, n); }<br>
+<br>
+static inline void<br>
+_mesa_swap4( GLuint *p, GLuint n ) { _mesa_swap4_copy(p, p, n); }<br>
<br>
 extern GLintptr<br>
 _mesa_image_offset( GLuint dimensions,<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>