1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * RGBA/float tile get/put functions.
30 * Usable both by drivers and state trackers.
31 * Surfaces should already be in a mapped state.
35 #include "pipe/p_defines.h"
36 #include "pipe/p_inlines.h"
38 #include "util/u_math.h"
39 #include "util/u_memory.h"
40 #include "util/u_rect.h"
41 #include "util/u_tile.h"
45 * Move raw block of pixels from surface to user memory.
46 * This should be usable by any hw driver that has mappable surfaces.
49 pipe_get_tile_raw(struct pipe_surface
*ps
,
50 uint x
, uint y
, uint w
, uint h
,
51 void *dst
, int dst_stride
)
56 dst_stride
= pf_get_nblocksx(&ps
->block
, w
) * ps
->block
.size
;
58 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
61 src
= pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_READ
);
66 pipe_copy_rect(dst
, &ps
->block
, dst_stride
, 0, 0, w
, h
, src
, ps
->stride
, x
, y
);
68 pipe_surface_unmap(ps
);
73 * Move raw block of pixels from user memory to surface.
74 * This should be usable by any hw driver that has mappable surfaces.
77 pipe_put_tile_raw(struct pipe_surface
*ps
,
78 uint x
, uint y
, uint w
, uint h
,
79 const void *src
, int src_stride
)
84 src_stride
= pf_get_nblocksx(&ps
->block
, w
) * ps
->block
.size
;
86 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
89 dst
= pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
94 pipe_copy_rect(dst
, &ps
->block
, ps
->stride
, x
, y
, w
, h
, src
, src_stride
, 0, 0);
96 pipe_surface_unmap(ps
);
102 /** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
103 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
105 #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
106 us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
110 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
113 a8r8g8b8_get_tile_rgba(const unsigned *src
,
114 unsigned w
, unsigned h
,
120 for (i
= 0; i
< h
; i
++) {
122 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
123 const unsigned pixel
= *src
++;
124 pRow
[0] = ubyte_to_float((pixel
>> 16) & 0xff);
125 pRow
[1] = ubyte_to_float((pixel
>> 8) & 0xff);
126 pRow
[2] = ubyte_to_float((pixel
>> 0) & 0xff);
127 pRow
[3] = ubyte_to_float((pixel
>> 24) & 0xff);
135 a8r8g8b8_put_tile_rgba(unsigned *dst
,
136 unsigned w
, unsigned h
,
142 for (i
= 0; i
< h
; i
++) {
143 const float *pRow
= p
;
144 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
146 r
= float_to_ubyte(pRow
[0]);
147 g
= float_to_ubyte(pRow
[1]);
148 b
= float_to_ubyte(pRow
[2]);
149 a
= float_to_ubyte(pRow
[3]);
150 *dst
++ = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
157 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
160 x8r8g8b8_get_tile_rgba(const unsigned *src
,
161 unsigned w
, unsigned h
,
167 for (i
= 0; i
< h
; i
++) {
169 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
170 const unsigned pixel
= *src
++;
171 pRow
[0] = ubyte_to_float((pixel
>> 16) & 0xff);
172 pRow
[1] = ubyte_to_float((pixel
>> 8) & 0xff);
173 pRow
[2] = ubyte_to_float((pixel
>> 0) & 0xff);
174 pRow
[3] = ubyte_to_float(0xff);
182 x8r8g8b8_put_tile_rgba(unsigned *dst
,
183 unsigned w
, unsigned h
,
189 for (i
= 0; i
< h
; i
++) {
190 const float *pRow
= p
;
191 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
193 r
= float_to_ubyte(pRow
[0]);
194 g
= float_to_ubyte(pRow
[1]);
195 b
= float_to_ubyte(pRow
[2]);
196 *dst
++ = (0xff << 24) | (r
<< 16) | (g
<< 8) | b
;
203 /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/
206 b8g8r8a8_get_tile_rgba(const unsigned *src
,
207 unsigned w
, unsigned h
,
213 for (i
= 0; i
< h
; i
++) {
215 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
216 const unsigned pixel
= *src
++;
217 pRow
[0] = ubyte_to_float((pixel
>> 8) & 0xff);
218 pRow
[1] = ubyte_to_float((pixel
>> 16) & 0xff);
219 pRow
[2] = ubyte_to_float((pixel
>> 24) & 0xff);
220 pRow
[3] = ubyte_to_float((pixel
>> 0) & 0xff);
228 b8g8r8a8_put_tile_rgba(unsigned *dst
,
229 unsigned w
, unsigned h
,
235 for (i
= 0; i
< h
; i
++) {
236 const float *pRow
= p
;
237 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
239 r
= float_to_ubyte(pRow
[0]);
240 g
= float_to_ubyte(pRow
[1]);
241 b
= float_to_ubyte(pRow
[2]);
242 a
= float_to_ubyte(pRow
[3]);
243 *dst
++ = (b
<< 24) | (g
<< 16) | (r
<< 8) | a
;
250 /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/
253 a1r5g5b5_get_tile_rgba(const ushort
*src
,
254 unsigned w
, unsigned h
,
260 for (i
= 0; i
< h
; i
++) {
262 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
263 const ushort pixel
= *src
++;
264 pRow
[0] = ((pixel
>> 10) & 0x1f) * (1.0f
/ 31.0f
);
265 pRow
[1] = ((pixel
>> 5) & 0x1f) * (1.0f
/ 31.0f
);
266 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
267 pRow
[3] = ((pixel
>> 15) ) * 1.0f
;
275 a1r5g5b5_put_tile_rgba(ushort
*dst
,
276 unsigned w
, unsigned h
,
282 for (i
= 0; i
< h
; i
++) {
283 const float *pRow
= p
;
284 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
286 r
= float_to_ubyte(pRow
[0]);
287 g
= float_to_ubyte(pRow
[1]);
288 b
= float_to_ubyte(pRow
[2]);
289 a
= float_to_ubyte(pRow
[3]);
290 r
= r
>> 3; /* 5 bits */
291 g
= g
>> 3; /* 5 bits */
292 b
= b
>> 3; /* 5 bits */
293 a
= a
>> 7; /* 1 bit */
294 *dst
++ = (a
<< 15) | (r
<< 10) | (g
<< 5) | b
;
301 /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/
304 a4r4g4b4_get_tile_rgba(const ushort
*src
,
305 unsigned w
, unsigned h
,
311 for (i
= 0; i
< h
; i
++) {
313 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
314 const ushort pixel
= *src
++;
315 pRow
[0] = ((pixel
>> 8) & 0xf) * (1.0f
/ 15.0f
);
316 pRow
[1] = ((pixel
>> 4) & 0xf) * (1.0f
/ 15.0f
);
317 pRow
[2] = ((pixel
) & 0xf) * (1.0f
/ 15.0f
);
318 pRow
[3] = ((pixel
>> 12) ) * (1.0f
/ 15.0f
);
326 a4r4g4b4_put_tile_rgba(ushort
*dst
,
327 unsigned w
, unsigned h
,
333 for (i
= 0; i
< h
; i
++) {
334 const float *pRow
= p
;
335 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
337 r
= float_to_ubyte(pRow
[0]);
338 g
= float_to_ubyte(pRow
[1]);
339 b
= float_to_ubyte(pRow
[2]);
340 a
= float_to_ubyte(pRow
[3]);
345 *dst
++ = (a
<< 12) | (r
<< 16) | (g
<< 4) | b
;
352 /*** PIPE_FORMAT_R5G6B5_UNORM ***/
355 r5g6b5_get_tile_rgba(const ushort
*src
,
356 unsigned w
, unsigned h
,
362 for (i
= 0; i
< h
; i
++) {
364 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
365 const ushort pixel
= *src
++;
366 pRow
[0] = ((pixel
>> 11) & 0x1f) * (1.0f
/ 31.0f
);
367 pRow
[1] = ((pixel
>> 5) & 0x3f) * (1.0f
/ 63.0f
);
368 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
377 r5g6b5_put_tile_rgba(ushort
*dst
,
378 unsigned w
, unsigned h
,
384 for (i
= 0; i
< h
; i
++) {
385 const float *pRow
= p
;
386 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
387 uint r
= (uint
) (CLAMP(pRow
[0], 0.0, 1.0) * 31.0);
388 uint g
= (uint
) (CLAMP(pRow
[1], 0.0, 1.0) * 63.0);
389 uint b
= (uint
) (CLAMP(pRow
[2], 0.0, 1.0) * 31.0);
390 *dst
++ = (r
<< 11) | (g
<< 5) | (b
);
398 /*** PIPE_FORMAT_Z16_UNORM ***/
401 * Return each Z value as four floats in [0,1].
404 z16_get_tile_rgba(const ushort
*src
,
405 unsigned w
, unsigned h
,
409 const float scale
= 1.0f
/ 65535.0f
;
412 for (i
= 0; i
< h
; i
++) {
414 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
418 pRow
[3] = *src
++ * scale
;
427 /*** PIPE_FORMAT_L8_UNORM ***/
430 l8_get_tile_rgba(const ubyte
*src
,
431 unsigned w
, unsigned h
,
437 for (i
= 0; i
< h
; i
++) {
439 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
442 pRow
[2] = ubyte_to_float(*src
);
451 l8_put_tile_rgba(ubyte
*dst
,
452 unsigned w
, unsigned h
,
458 for (i
= 0; i
< h
; i
++) {
459 const float *pRow
= p
;
460 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
462 r
= float_to_ubyte(pRow
[0]);
471 /*** PIPE_FORMAT_A8_UNORM ***/
474 a8_get_tile_rgba(const ubyte
*src
,
475 unsigned w
, unsigned h
,
481 for (i
= 0; i
< h
; i
++) {
483 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
487 pRow
[3] = ubyte_to_float(*src
);
495 a8_put_tile_rgba(ubyte
*dst
,
496 unsigned w
, unsigned h
,
502 for (i
= 0; i
< h
; i
++) {
503 const float *pRow
= p
;
504 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
506 a
= float_to_ubyte(pRow
[3]);
515 /*** PIPE_FORMAT_R16_SNORM ***/
518 r16_get_tile_rgba(const short *src
,
519 unsigned w
, unsigned h
,
525 for (i
= 0; i
< h
; i
++) {
527 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
528 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
539 r16_put_tile_rgba(short *dst
,
540 unsigned w
, unsigned h
,
546 for (i
= 0; i
< h
; i
++) {
547 const float *pRow
= p
;
548 for (j
= 0; j
< w
; j
++, dst
++, pRow
+= 4) {
549 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
556 /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/
559 r16g16b16a16_get_tile_rgba(const short *src
,
560 unsigned w
, unsigned h
,
566 for (i
= 0; i
< h
; i
++) {
568 for (j
= 0; j
< w
; j
++, src
+= 4, pRow
+= 4) {
569 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
570 pRow
[1] = SHORT_TO_FLOAT(src
[1]);
571 pRow
[2] = SHORT_TO_FLOAT(src
[2]);
572 pRow
[3] = SHORT_TO_FLOAT(src
[3]);
580 r16g16b16a16_put_tile_rgba(short *dst
,
581 unsigned w
, unsigned h
,
587 for (i
= 0; i
< h
; i
++) {
588 const float *pRow
= p
;
589 for (j
= 0; j
< w
; j
++, dst
+= 4, pRow
+= 4) {
590 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
591 UNCLAMPED_FLOAT_TO_SHORT(dst
[1], pRow
[1]);
592 UNCLAMPED_FLOAT_TO_SHORT(dst
[2], pRow
[2]);
593 UNCLAMPED_FLOAT_TO_SHORT(dst
[3], pRow
[3]);
601 /*** PIPE_FORMAT_I8_UNORM ***/
604 i8_get_tile_rgba(const ubyte
*src
,
605 unsigned w
, unsigned h
,
611 for (i
= 0; i
< h
; i
++) {
613 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
617 pRow
[3] = ubyte_to_float(*src
);
625 i8_put_tile_rgba(ubyte
*dst
,
626 unsigned w
, unsigned h
,
632 for (i
= 0; i
< h
; i
++) {
633 const float *pRow
= p
;
634 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
636 r
= float_to_ubyte(pRow
[0]);
644 /*** PIPE_FORMAT_A8L8_UNORM ***/
647 a8l8_get_tile_rgba(const ushort
*src
,
648 unsigned w
, unsigned h
,
654 for (i
= 0; i
< h
; i
++) {
656 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
660 pRow
[2] = ubyte_to_float(p
& 0xff);
661 pRow
[3] = ubyte_to_float(p
>> 8);
669 a8l8_put_tile_rgba(ushort
*dst
,
670 unsigned w
, unsigned h
,
676 for (i
= 0; i
< h
; i
++) {
677 const float *pRow
= p
;
678 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
680 r
= float_to_ubyte(pRow
[0]);
681 a
= float_to_ubyte(pRow
[3]);
682 *dst
++ = (a
<< 8) | r
;
691 /*** PIPE_FORMAT_Z32_UNORM ***/
694 * Return each Z value as four floats in [0,1].
697 z32_get_tile_rgba(const unsigned *src
,
698 unsigned w
, unsigned h
,
702 const double scale
= 1.0 / (double) 0xffffffff;
705 for (i
= 0; i
< h
; i
++) {
707 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
711 pRow
[3] = (float) (*src
++ * scale
);
718 /*** PIPE_FORMAT_S8Z24_UNORM ***/
721 * Return Z component as four float in [0,1]. Stencil part ignored.
724 s8z24_get_tile_rgba(const unsigned *src
,
725 unsigned w
, unsigned h
,
729 const double scale
= 1.0 / ((1 << 24) - 1);
732 for (i
= 0; i
< h
; i
++) {
734 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
738 pRow
[3] = (float) (scale
* (*src
++ & 0xffffff));
745 /*** PIPE_FORMAT_Z24S8_UNORM ***/
748 * Return Z component as four float in [0,1]. Stencil part ignored.
751 z24s8_get_tile_rgba(const unsigned *src
,
752 unsigned w
, unsigned h
,
756 const double scale
= 1.0 / ((1 << 24) - 1);
759 for (i
= 0; i
< h
; i
++) {
761 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
765 pRow
[3] = (float) (scale
* (*src
++ >> 8));
772 /*** PIPE_FORMAT_Z32_FLOAT ***/
775 * Return each Z value as four floats in [0,1].
778 z32f_get_tile_rgba(const float *src
,
779 unsigned w
, unsigned h
,
785 for (i
= 0; i
< h
; i
++) {
787 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
798 /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/
801 * Convert YCbCr (or YCrCb) to RGBA.
804 ycbcr_get_tile_rgba(const ushort
*src
,
805 unsigned w
, unsigned h
,
810 const float scale
= 1.0f
/ 255.0f
;
813 for (i
= 0; i
< h
; i
++) {
815 /* do two texels at a time */
816 for (j
= 0; j
< (w
& ~1); j
+= 2, src
+= 2) {
817 const ushort t0
= src
[0];
818 const ushort t1
= src
[1];
819 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
820 const ubyte y1
= (t1
>> 8) & 0xff; /* luminance */
825 cb
= t1
& 0xff; /* chroma U */
826 cr
= t0
& 0xff; /* chroma V */
829 cb
= t0
& 0xff; /* chroma U */
830 cr
= t1
& 0xff; /* chroma V */
833 /* even pixel: y0,cr,cb */
834 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
835 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
836 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
843 /* odd pixel: use y1,cr,cb */
844 r
= 1.164f
* (y1
-16) + 1.596f
* (cr
-128);
845 g
= 1.164f
* (y1
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
846 b
= 1.164f
* (y1
-16) + 2.018f
* (cb
-128);
854 /* do the last texel */
856 const ushort t0
= src
[0];
857 const ushort t1
= src
[1];
858 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
863 cb
= t1
& 0xff; /* chroma U */
864 cr
= t0
& 0xff; /* chroma V */
867 cb
= t0
& 0xff; /* chroma U */
868 cr
= t1
& 0xff; /* chroma V */
871 /* even pixel: y0,cr,cb */
872 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
873 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
874 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
887 pipe_tile_raw_to_rgba(enum pipe_format format
,
890 float *dst
, unsigned dst_stride
)
893 case PIPE_FORMAT_A8R8G8B8_UNORM
:
894 a8r8g8b8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
896 case PIPE_FORMAT_X8R8G8B8_UNORM
:
897 x8r8g8b8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
899 case PIPE_FORMAT_B8G8R8A8_UNORM
:
900 b8g8r8a8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
902 case PIPE_FORMAT_A1R5G5B5_UNORM
:
903 a1r5g5b5_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
905 case PIPE_FORMAT_A4R4G4B4_UNORM
:
906 a4r4g4b4_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
908 case PIPE_FORMAT_R5G6B5_UNORM
:
909 r5g6b5_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
911 case PIPE_FORMAT_L8_UNORM
:
912 l8_get_tile_rgba((ubyte
*) src
, w
, h
, dst
, dst_stride
);
914 case PIPE_FORMAT_A8_UNORM
:
915 a8_get_tile_rgba((ubyte
*) src
, w
, h
, dst
, dst_stride
);
917 case PIPE_FORMAT_I8_UNORM
:
918 i8_get_tile_rgba((ubyte
*) src
, w
, h
, dst
, dst_stride
);
920 case PIPE_FORMAT_A8L8_UNORM
:
921 a8l8_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
923 case PIPE_FORMAT_R16_SNORM
:
924 r16_get_tile_rgba((short *) src
, w
, h
, dst
, dst_stride
);
926 case PIPE_FORMAT_R16G16B16A16_SNORM
:
927 r16g16b16a16_get_tile_rgba((short *) src
, w
, h
, dst
, dst_stride
);
929 case PIPE_FORMAT_Z16_UNORM
:
930 z16_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
932 case PIPE_FORMAT_Z32_UNORM
:
933 z32_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
935 case PIPE_FORMAT_S8Z24_UNORM
:
936 case PIPE_FORMAT_X8Z24_UNORM
:
937 s8z24_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
939 case PIPE_FORMAT_Z24S8_UNORM
:
940 z24s8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
942 case PIPE_FORMAT_Z32_FLOAT
:
943 z32f_get_tile_rgba((float *) src
, w
, h
, dst
, dst_stride
);
945 case PIPE_FORMAT_YCBCR
:
946 ycbcr_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
, FALSE
);
948 case PIPE_FORMAT_YCBCR_REV
:
949 ycbcr_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
, TRUE
);
958 pipe_get_tile_rgba(struct pipe_surface
*ps
,
959 uint x
, uint y
, uint w
, uint h
,
962 unsigned dst_stride
= w
* 4;
965 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
968 packed
= MALLOC(pf_get_nblocks(&ps
->block
, w
, h
) * ps
->block
.size
);
973 if(ps
->format
== PIPE_FORMAT_YCBCR
|| ps
->format
== PIPE_FORMAT_YCBCR_REV
)
974 assert((x
& 1) == 0);
976 pipe_get_tile_raw(ps
, x
, y
, w
, h
, packed
, 0);
978 pipe_tile_raw_to_rgba(ps
->format
, packed
, w
, h
, p
, dst_stride
);
985 pipe_put_tile_rgba(struct pipe_surface
*ps
,
986 uint x
, uint y
, uint w
, uint h
,
989 unsigned src_stride
= w
* 4;
992 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
995 packed
= MALLOC(pf_get_nblocks(&ps
->block
, w
, h
) * ps
->block
.size
);
1000 switch (ps
->format
) {
1001 case PIPE_FORMAT_A8R8G8B8_UNORM
:
1002 a8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
1004 case PIPE_FORMAT_X8R8G8B8_UNORM
:
1005 x8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
1007 case PIPE_FORMAT_B8G8R8A8_UNORM
:
1008 b8g8r8a8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
1010 case PIPE_FORMAT_A1R5G5B5_UNORM
:
1011 a1r5g5b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1013 case PIPE_FORMAT_R5G6B5_UNORM
:
1014 r5g6b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1016 case PIPE_FORMAT_R8G8B8A8_UNORM
:
1019 case PIPE_FORMAT_A4R4G4B4_UNORM
:
1020 a4r4g4b4_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1022 case PIPE_FORMAT_L8_UNORM
:
1023 l8_put_tile_rgba((ubyte
*) packed
, w
, h
, p
, src_stride
);
1025 case PIPE_FORMAT_A8_UNORM
:
1026 a8_put_tile_rgba((ubyte
*) packed
, w
, h
, p
, src_stride
);
1028 case PIPE_FORMAT_I8_UNORM
:
1029 i8_put_tile_rgba((ubyte
*) packed
, w
, h
, p
, src_stride
);
1031 case PIPE_FORMAT_A8L8_UNORM
:
1032 a8l8_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1034 case PIPE_FORMAT_R16_SNORM
:
1035 r16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
1037 case PIPE_FORMAT_R16G16B16A16_SNORM
:
1038 r16g16b16a16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
1040 case PIPE_FORMAT_Z16_UNORM
:
1041 /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
1043 case PIPE_FORMAT_Z32_UNORM
:
1044 /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
1046 case PIPE_FORMAT_S8Z24_UNORM
:
1047 case PIPE_FORMAT_X8Z24_UNORM
:
1048 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
1050 case PIPE_FORMAT_Z24S8_UNORM
:
1051 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
1057 pipe_put_tile_raw(ps
, x
, y
, w
, h
, packed
, 0);
1064 * Get a block of Z values, converted to 32-bit range.
1067 pipe_get_tile_z(struct pipe_surface
*ps
,
1068 uint x
, uint y
, uint w
, uint h
,
1071 const uint dstStride
= w
;
1076 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
1079 map
= (ubyte
*)pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_READ
);
1085 switch (ps
->format
) {
1086 case PIPE_FORMAT_Z32_UNORM
:
1089 = (const uint
*)(map
+ y
* ps
->stride
+ x
*4);
1090 for (i
= 0; i
< h
; i
++) {
1091 memcpy(pDest
, pSrc
, 4 * w
);
1093 pSrc
+= ps
->stride
/4;
1097 case PIPE_FORMAT_S8Z24_UNORM
:
1098 case PIPE_FORMAT_X8Z24_UNORM
:
1101 = (const uint
*)(map
+ y
* ps
->stride
+ x
*4);
1102 for (i
= 0; i
< h
; i
++) {
1103 for (j
= 0; j
< w
; j
++) {
1104 /* convert 24-bit Z to 32-bit Z */
1105 pDest
[j
] = (pSrc
[j
] << 8) | (pSrc
[j
] & 0xff);
1108 pSrc
+= ps
->stride
/4;
1112 case PIPE_FORMAT_Z16_UNORM
:
1115 = (const ushort
*)(map
+ y
* ps
->stride
+ x
*2);
1116 for (i
= 0; i
< h
; i
++) {
1117 for (j
= 0; j
< w
; j
++) {
1118 /* convert 16-bit Z to 32-bit Z */
1119 pDest
[j
] = (pSrc
[j
] << 16) | pSrc
[j
];
1122 pSrc
+= ps
->stride
/2;
1130 pipe_surface_unmap(ps
);
1135 pipe_put_tile_z(struct pipe_surface
*ps
,
1136 uint x
, uint y
, uint w
, uint h
,
1139 const uint srcStride
= w
;
1140 const uint
*pSrc
= zSrc
;
1144 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
1147 map
= (ubyte
*)pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
1153 switch (ps
->format
) {
1154 case PIPE_FORMAT_Z32_UNORM
:
1156 uint
*pDest
= (uint
*) (map
+ y
* ps
->stride
+ x
*4);
1157 for (i
= 0; i
< h
; i
++) {
1158 memcpy(pDest
, pSrc
, 4 * w
);
1159 pDest
+= ps
->stride
/4;
1164 case PIPE_FORMAT_S8Z24_UNORM
:
1165 case PIPE_FORMAT_X8Z24_UNORM
:
1167 uint
*pDest
= (uint
*) (map
+ y
* ps
->stride
+ x
*4);
1168 for (i
= 0; i
< h
; i
++) {
1169 for (j
= 0; j
< w
; j
++) {
1170 /* convert 32-bit Z to 24-bit Z (0 stencil) */
1171 pDest
[j
] = pSrc
[j
] >> 8;
1173 pDest
+= ps
->stride
/4;
1178 case PIPE_FORMAT_Z16_UNORM
:
1180 ushort
*pDest
= (ushort
*) (map
+ y
* ps
->stride
+ x
*2);
1181 for (i
= 0; i
< h
; i
++) {
1182 for (j
= 0; j
< w
; j
++) {
1183 /* convert 32-bit Z to 16-bit Z */
1184 pDest
[j
] = pSrc
[j
] >> 16;
1186 pDest
+= ps
->stride
/2;
1195 pipe_surface_unmap(ps
);