<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 9, 2014 at 4:07 AM, Iago Toral Quiroga <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For glReadPixels with a Luminance destination format we compute luminance<br>
values from RGBA as L=R+G+B. This, however, requires ad-hoc implementation,<br>
since pack/unpack functions or _mesa_swizzle_and_convert won't do this<br>
(and thus, neither will _mesa_format_convert). This patch adds helpers<br>
to do this computation so they can be used to support conversion to luminance<br>
formats.<br>
<br>
The current implementation of glReadPixels does this computation as part<br>
of the span functions in pack.c (see _mesa_pack_rgba_span_float), that do<br>
this together with other things like type conversion, etc. We do not want<br>
to use these functions but use _mesa_format_convert instead (later patches<br>
will remove the color span functions), so we need to extract this functionality<br>
as helpers.<br>
---<br>
src/mesa/main/pack.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
src/mesa/main/pack.h | 9 ++++++++<br>
2 files changed, 72 insertions(+)<br>
<br>
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c<br>
index de6ab27..fa4046c 100644<br>
--- a/src/mesa/main/pack.c<br>
+++ b/src/mesa/main/pack.c<br>
@@ -4334,4 +4334,67 @@ _mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat)<br>
}<br>
}<br>
<br>
+void<br>
+_mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],<br>
+ GLvoid *dstAddr, GLenum dst_format,<br>
+ GLbitfield transferOps)<br>
+{<br>
+ int i;<br>
+ GLfloat *dst = (GLfloat *) dstAddr;<br>
+<br>
+ switch (dst_format) {<br>
+ case GL_LUMINANCE:<br>
+ if (transferOps & IMAGE_CLAMP_BIT) {<br>
+ for (i = 0; i < n; i++) {<br>
+ GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];<br>
+ dst[i] = CLAMP(sum, 0.0F, 1.0F);<br>
+ }<br>
+ } else {<br>
+ for (i = 0; i < n; i++) {<br>
+ dst[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];<br>
+ }<br>
+ }<br>
+ return;<br>
+ case GL_LUMINANCE_ALPHA:<br>
+ if (transferOps & IMAGE_CLAMP_BIT) {<br>
+ for (i = 0; i < n; i++) {<br>
+ GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];<br>
+ dst[2*i] = CLAMP(sum, 0.0F, 1.0F);<br>
+ dst[2*i+1] = rgba[i][ACOMP];<br>
+ }<br>
+ } else {<br>
+ for (i = 0; i < n; i++) {<br>
+ dst[2*i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];<br>
+ dst[2*i+1] = rgba[i][ACOMP];<br>
+ }<br>
+ }<br>
+ return;<br>
+ default:<br>
+ assert(!"Unsupported format");<br>
+ }<br>
+}<br>
+<br>
+void<br>
+_mesa_pack_luminance_from_rgba_integer(GLuint n, GLuint rgba[][4],<br>
+ GLvoid *dstAddr, GLenum dst_format)<br>
+{<br>
+ int i;<br>
+ GLuint *dst = (GLuint *) dstAddr;<br>
+<br>
+ switch (dst_format) {<br>
+ case GL_LUMINANCE:<br>
+ for (i = 0; i < n; i++) {<br>
+ dst[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];<br></blockquote><div><br></div><div>I know this is getting old, but don't we need to do some clamping here? If we do, then we have to handle signed vs. unsigned seperately. Yeah, that's annoying.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ }<br>
+ return;<br>
+ case GL_LUMINANCE_ALPHA:<br>
+ for (i = 0; i < n; i++) {<br>
+ dst[2*i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];<br>
+ dst[2*i+1] = rgba[i][ACOMP];<br>
+ }<br>
+ return;<br>
+ default:<br>
+ assert(!"Unsupported format");<br>
+ }<br>
+}<br>
<br>
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h<br>
index 2173b65..2783f23 100644<br>
--- a/src/mesa/main/pack.h<br>
+++ b/src/mesa/main/pack.h<br>
@@ -155,4 +155,13 @@ _mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], GLenum baseFormat);<br>
extern void<br>
_mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat);<br>
<br>
+extern void<br>
+_mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],<br>
+ GLvoid *dstAddr, GLenum dst_format,<br>
+ GLbitfield transferOps);<br>
+<br>
+extern void<br>
+_mesa_pack_luminance_from_rgba_integer(GLuint n, GLuint rgba[][4],<br>
+ GLvoid *dstAddr, GLenum dst_format);<br>
+<br>
#endif<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></div></div>