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.
34 #include "pipe/p_defines.h"
35 #include "pipe/p_inlines.h"
37 #include "util/u_math.h"
38 #include "util/u_memory.h"
39 #include "util/u_rect.h"
40 #include "util/u_tile.h"
44 * Move raw block of pixels from transfer object to user memory.
47 pipe_get_tile_raw(struct pipe_transfer
*pt
,
48 uint x
, uint y
, uint w
, uint h
,
49 void *dst
, int dst_stride
)
51 struct pipe_screen
*screen
= pt
->texture
->screen
;
55 dst_stride
= pf_get_nblocksx(&pt
->block
, w
) * pt
->block
.size
;
57 if (pipe_clip_tile(x
, y
, &w
, &h
, pt
))
60 src
= screen
->transfer_map(screen
, pt
);
65 pipe_copy_rect(dst
, &pt
->block
, dst_stride
, 0, 0, w
, h
, src
, pt
->stride
, x
, y
);
67 screen
->transfer_unmap(screen
, pt
);
72 * Move raw block of pixels from user memory to transfer object.
75 pipe_put_tile_raw(struct pipe_transfer
*pt
,
76 uint x
, uint y
, uint w
, uint h
,
77 const void *src
, int src_stride
)
79 struct pipe_screen
*screen
= pt
->texture
->screen
;
83 src_stride
= pf_get_nblocksx(&pt
->block
, w
) * pt
->block
.size
;
85 if (pipe_clip_tile(x
, y
, &w
, &h
, pt
))
88 dst
= screen
->transfer_map(screen
, pt
);
93 pipe_copy_rect(dst
, &pt
->block
, pt
->stride
, x
, y
, w
, h
, src
, src_stride
, 0, 0);
95 screen
->transfer_unmap(screen
, pt
);
101 /** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
102 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
104 #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
105 us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
109 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
112 a8r8g8b8_get_tile_rgba(const unsigned *src
,
113 unsigned w
, unsigned h
,
119 for (i
= 0; i
< h
; i
++) {
121 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
122 const unsigned pixel
= *src
++;
123 pRow
[0] = ubyte_to_float((pixel
>> 16) & 0xff);
124 pRow
[1] = ubyte_to_float((pixel
>> 8) & 0xff);
125 pRow
[2] = ubyte_to_float((pixel
>> 0) & 0xff);
126 pRow
[3] = ubyte_to_float((pixel
>> 24) & 0xff);
134 a8r8g8b8_put_tile_rgba(unsigned *dst
,
135 unsigned w
, unsigned h
,
141 for (i
= 0; i
< h
; i
++) {
142 const float *pRow
= p
;
143 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
145 r
= float_to_ubyte(pRow
[0]);
146 g
= float_to_ubyte(pRow
[1]);
147 b
= float_to_ubyte(pRow
[2]);
148 a
= float_to_ubyte(pRow
[3]);
149 *dst
++ = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
156 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
159 x8r8g8b8_get_tile_rgba(const unsigned *src
,
160 unsigned w
, unsigned h
,
166 for (i
= 0; i
< h
; i
++) {
168 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
169 const unsigned pixel
= *src
++;
170 pRow
[0] = ubyte_to_float((pixel
>> 16) & 0xff);
171 pRow
[1] = ubyte_to_float((pixel
>> 8) & 0xff);
172 pRow
[2] = ubyte_to_float((pixel
>> 0) & 0xff);
173 pRow
[3] = ubyte_to_float(0xff);
181 x8r8g8b8_put_tile_rgba(unsigned *dst
,
182 unsigned w
, unsigned h
,
188 for (i
= 0; i
< h
; i
++) {
189 const float *pRow
= p
;
190 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
192 r
= float_to_ubyte(pRow
[0]);
193 g
= float_to_ubyte(pRow
[1]);
194 b
= float_to_ubyte(pRow
[2]);
195 *dst
++ = (0xff << 24) | (r
<< 16) | (g
<< 8) | b
;
202 /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/
205 b8g8r8a8_get_tile_rgba(const unsigned *src
,
206 unsigned w
, unsigned h
,
212 for (i
= 0; i
< h
; i
++) {
214 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
215 const unsigned pixel
= *src
++;
216 pRow
[0] = ubyte_to_float((pixel
>> 8) & 0xff);
217 pRow
[1] = ubyte_to_float((pixel
>> 16) & 0xff);
218 pRow
[2] = ubyte_to_float((pixel
>> 24) & 0xff);
219 pRow
[3] = ubyte_to_float((pixel
>> 0) & 0xff);
227 b8g8r8a8_put_tile_rgba(unsigned *dst
,
228 unsigned w
, unsigned h
,
234 for (i
= 0; i
< h
; i
++) {
235 const float *pRow
= p
;
236 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
238 r
= float_to_ubyte(pRow
[0]);
239 g
= float_to_ubyte(pRow
[1]);
240 b
= float_to_ubyte(pRow
[2]);
241 a
= float_to_ubyte(pRow
[3]);
242 *dst
++ = (b
<< 24) | (g
<< 16) | (r
<< 8) | a
;
249 /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/
252 a1r5g5b5_get_tile_rgba(const ushort
*src
,
253 unsigned w
, unsigned h
,
259 for (i
= 0; i
< h
; i
++) {
261 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
262 const ushort pixel
= *src
++;
263 pRow
[0] = ((pixel
>> 10) & 0x1f) * (1.0f
/ 31.0f
);
264 pRow
[1] = ((pixel
>> 5) & 0x1f) * (1.0f
/ 31.0f
);
265 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
266 pRow
[3] = ((pixel
>> 15) ) * 1.0f
;
274 a1r5g5b5_put_tile_rgba(ushort
*dst
,
275 unsigned w
, unsigned h
,
281 for (i
= 0; i
< h
; i
++) {
282 const float *pRow
= p
;
283 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
285 r
= float_to_ubyte(pRow
[0]);
286 g
= float_to_ubyte(pRow
[1]);
287 b
= float_to_ubyte(pRow
[2]);
288 a
= float_to_ubyte(pRow
[3]);
289 r
= r
>> 3; /* 5 bits */
290 g
= g
>> 3; /* 5 bits */
291 b
= b
>> 3; /* 5 bits */
292 a
= a
>> 7; /* 1 bit */
293 *dst
++ = (a
<< 15) | (r
<< 10) | (g
<< 5) | b
;
300 /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/
303 a4r4g4b4_get_tile_rgba(const ushort
*src
,
304 unsigned w
, unsigned h
,
310 for (i
= 0; i
< h
; i
++) {
312 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
313 const ushort pixel
= *src
++;
314 pRow
[0] = ((pixel
>> 8) & 0xf) * (1.0f
/ 15.0f
);
315 pRow
[1] = ((pixel
>> 4) & 0xf) * (1.0f
/ 15.0f
);
316 pRow
[2] = ((pixel
) & 0xf) * (1.0f
/ 15.0f
);
317 pRow
[3] = ((pixel
>> 12) ) * (1.0f
/ 15.0f
);
325 a4r4g4b4_put_tile_rgba(ushort
*dst
,
326 unsigned w
, unsigned h
,
332 for (i
= 0; i
< h
; i
++) {
333 const float *pRow
= p
;
334 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
336 r
= float_to_ubyte(pRow
[0]);
337 g
= float_to_ubyte(pRow
[1]);
338 b
= float_to_ubyte(pRow
[2]);
339 a
= float_to_ubyte(pRow
[3]);
344 *dst
++ = (a
<< 12) | (r
<< 16) | (g
<< 4) | b
;
351 /*** PIPE_FORMAT_R5G6B5_UNORM ***/
354 r5g6b5_get_tile_rgba(const ushort
*src
,
355 unsigned w
, unsigned h
,
361 for (i
= 0; i
< h
; i
++) {
363 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
364 const ushort pixel
= *src
++;
365 pRow
[0] = ((pixel
>> 11) & 0x1f) * (1.0f
/ 31.0f
);
366 pRow
[1] = ((pixel
>> 5) & 0x3f) * (1.0f
/ 63.0f
);
367 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
376 r5g6b5_put_tile_rgba(ushort
*dst
,
377 unsigned w
, unsigned h
,
383 for (i
= 0; i
< h
; i
++) {
384 const float *pRow
= p
;
385 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
386 uint r
= (uint
) (CLAMP(pRow
[0], 0.0, 1.0) * 31.0);
387 uint g
= (uint
) (CLAMP(pRow
[1], 0.0, 1.0) * 63.0);
388 uint b
= (uint
) (CLAMP(pRow
[2], 0.0, 1.0) * 31.0);
389 *dst
++ = (r
<< 11) | (g
<< 5) | (b
);
397 /*** PIPE_FORMAT_Z16_UNORM ***/
400 * Return each Z value as four floats in [0,1].
403 z16_get_tile_rgba(const ushort
*src
,
404 unsigned w
, unsigned h
,
408 const float scale
= 1.0f
/ 65535.0f
;
411 for (i
= 0; i
< h
; i
++) {
413 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
417 pRow
[3] = *src
++ * scale
;
426 /*** PIPE_FORMAT_L8_UNORM ***/
429 l8_get_tile_rgba(const ubyte
*src
,
430 unsigned w
, unsigned h
,
436 for (i
= 0; i
< h
; i
++) {
438 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
441 pRow
[2] = ubyte_to_float(*src
);
450 l8_put_tile_rgba(ubyte
*dst
,
451 unsigned w
, unsigned h
,
457 for (i
= 0; i
< h
; i
++) {
458 const float *pRow
= p
;
459 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
461 r
= float_to_ubyte(pRow
[0]);
470 /*** PIPE_FORMAT_A8_UNORM ***/
473 a8_get_tile_rgba(const ubyte
*src
,
474 unsigned w
, unsigned h
,
480 for (i
= 0; i
< h
; i
++) {
482 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
486 pRow
[3] = ubyte_to_float(*src
);
494 a8_put_tile_rgba(ubyte
*dst
,
495 unsigned w
, unsigned h
,
501 for (i
= 0; i
< h
; i
++) {
502 const float *pRow
= p
;
503 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
505 a
= float_to_ubyte(pRow
[3]);
514 /*** PIPE_FORMAT_R16_SNORM ***/
517 r16_get_tile_rgba(const short *src
,
518 unsigned w
, unsigned h
,
524 for (i
= 0; i
< h
; i
++) {
526 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
527 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
538 r16_put_tile_rgba(short *dst
,
539 unsigned w
, unsigned h
,
545 for (i
= 0; i
< h
; i
++) {
546 const float *pRow
= p
;
547 for (j
= 0; j
< w
; j
++, dst
++, pRow
+= 4) {
548 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
555 /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/
558 r16g16b16a16_get_tile_rgba(const short *src
,
559 unsigned w
, unsigned h
,
565 for (i
= 0; i
< h
; i
++) {
567 for (j
= 0; j
< w
; j
++, src
+= 4, pRow
+= 4) {
568 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
569 pRow
[1] = SHORT_TO_FLOAT(src
[1]);
570 pRow
[2] = SHORT_TO_FLOAT(src
[2]);
571 pRow
[3] = SHORT_TO_FLOAT(src
[3]);
579 r16g16b16a16_put_tile_rgba(short *dst
,
580 unsigned w
, unsigned h
,
586 for (i
= 0; i
< h
; i
++) {
587 const float *pRow
= p
;
588 for (j
= 0; j
< w
; j
++, dst
+= 4, pRow
+= 4) {
589 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
590 UNCLAMPED_FLOAT_TO_SHORT(dst
[1], pRow
[1]);
591 UNCLAMPED_FLOAT_TO_SHORT(dst
[2], pRow
[2]);
592 UNCLAMPED_FLOAT_TO_SHORT(dst
[3], pRow
[3]);
600 /*** PIPE_FORMAT_I8_UNORM ***/
603 i8_get_tile_rgba(const ubyte
*src
,
604 unsigned w
, unsigned h
,
610 for (i
= 0; i
< h
; i
++) {
612 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
616 pRow
[3] = ubyte_to_float(*src
);
624 i8_put_tile_rgba(ubyte
*dst
,
625 unsigned w
, unsigned h
,
631 for (i
= 0; i
< h
; i
++) {
632 const float *pRow
= p
;
633 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
635 r
= float_to_ubyte(pRow
[0]);
643 /*** PIPE_FORMAT_A8L8_UNORM ***/
646 a8l8_get_tile_rgba(const ushort
*src
,
647 unsigned w
, unsigned h
,
653 for (i
= 0; i
< h
; i
++) {
655 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
659 pRow
[2] = ubyte_to_float(p
& 0xff);
660 pRow
[3] = ubyte_to_float(p
>> 8);
668 a8l8_put_tile_rgba(ushort
*dst
,
669 unsigned w
, unsigned h
,
675 for (i
= 0; i
< h
; i
++) {
676 const float *pRow
= p
;
677 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
679 r
= float_to_ubyte(pRow
[0]);
680 a
= float_to_ubyte(pRow
[3]);
681 *dst
++ = (a
<< 8) | r
;
690 /*** PIPE_FORMAT_Z32_UNORM ***/
693 * Return each Z value as four floats in [0,1].
696 z32_get_tile_rgba(const unsigned *src
,
697 unsigned w
, unsigned h
,
701 const double scale
= 1.0 / (double) 0xffffffff;
704 for (i
= 0; i
< h
; i
++) {
706 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
710 pRow
[3] = (float) (*src
++ * scale
);
717 /*** PIPE_FORMAT_S8Z24_UNORM ***/
720 * Return Z component as four float in [0,1]. Stencil part ignored.
723 s8z24_get_tile_rgba(const unsigned *src
,
724 unsigned w
, unsigned h
,
728 const double scale
= 1.0 / ((1 << 24) - 1);
731 for (i
= 0; i
< h
; i
++) {
733 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
737 pRow
[3] = (float) (scale
* (*src
++ & 0xffffff));
744 /*** PIPE_FORMAT_Z24S8_UNORM ***/
747 * Return Z component as four float in [0,1]. Stencil part ignored.
750 z24s8_get_tile_rgba(const unsigned *src
,
751 unsigned w
, unsigned h
,
755 const double scale
= 1.0 / ((1 << 24) - 1);
758 for (i
= 0; i
< h
; i
++) {
760 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
764 pRow
[3] = (float) (scale
* (*src
++ >> 8));
771 /*** PIPE_FORMAT_Z32_FLOAT ***/
774 * Return each Z value as four floats in [0,1].
777 z32f_get_tile_rgba(const float *src
,
778 unsigned w
, unsigned h
,
784 for (i
= 0; i
< h
; i
++) {
786 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
797 /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/
800 * Convert YCbCr (or YCrCb) to RGBA.
803 ycbcr_get_tile_rgba(const ushort
*src
,
804 unsigned w
, unsigned h
,
809 const float scale
= 1.0f
/ 255.0f
;
812 for (i
= 0; i
< h
; i
++) {
814 /* do two texels at a time */
815 for (j
= 0; j
< (w
& ~1); j
+= 2, src
+= 2) {
816 const ushort t0
= src
[0];
817 const ushort t1
= src
[1];
818 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
819 const ubyte y1
= (t1
>> 8) & 0xff; /* luminance */
824 cb
= t1
& 0xff; /* chroma U */
825 cr
= t0
& 0xff; /* chroma V */
828 cb
= t0
& 0xff; /* chroma U */
829 cr
= t1
& 0xff; /* chroma V */
832 /* even pixel: y0,cr,cb */
833 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
834 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
835 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
842 /* odd pixel: use y1,cr,cb */
843 r
= 1.164f
* (y1
-16) + 1.596f
* (cr
-128);
844 g
= 1.164f
* (y1
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
845 b
= 1.164f
* (y1
-16) + 2.018f
* (cb
-128);
853 /* do the last texel */
855 const ushort t0
= src
[0];
856 const ushort t1
= src
[1];
857 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
862 cb
= t1
& 0xff; /* chroma U */
863 cr
= t0
& 0xff; /* chroma V */
866 cb
= t0
& 0xff; /* chroma U */
867 cr
= t1
& 0xff; /* chroma V */
870 /* even pixel: y0,cr,cb */
871 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
872 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
873 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
886 fake_get_tile_rgba(const ushort
*src
,
887 unsigned w
, unsigned h
,
893 for (i
= 0; i
< h
; i
++) {
895 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
899 pRow
[3] = (i
^ j
) & 1 ? 1.0f
: 0.0f
;
907 pipe_tile_raw_to_rgba(enum pipe_format format
,
910 float *dst
, unsigned dst_stride
)
913 case PIPE_FORMAT_A8R8G8B8_UNORM
:
914 a8r8g8b8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
916 case PIPE_FORMAT_X8R8G8B8_UNORM
:
917 x8r8g8b8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
919 case PIPE_FORMAT_B8G8R8A8_UNORM
:
920 b8g8r8a8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
922 case PIPE_FORMAT_A1R5G5B5_UNORM
:
923 a1r5g5b5_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
925 case PIPE_FORMAT_A4R4G4B4_UNORM
:
926 a4r4g4b4_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
928 case PIPE_FORMAT_R5G6B5_UNORM
:
929 r5g6b5_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
931 case PIPE_FORMAT_L8_UNORM
:
932 l8_get_tile_rgba((ubyte
*) src
, w
, h
, dst
, dst_stride
);
934 case PIPE_FORMAT_A8_UNORM
:
935 a8_get_tile_rgba((ubyte
*) src
, w
, h
, dst
, dst_stride
);
937 case PIPE_FORMAT_I8_UNORM
:
938 i8_get_tile_rgba((ubyte
*) src
, w
, h
, dst
, dst_stride
);
940 case PIPE_FORMAT_A8L8_UNORM
:
941 a8l8_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
943 case PIPE_FORMAT_R16_SNORM
:
944 r16_get_tile_rgba((short *) src
, w
, h
, dst
, dst_stride
);
946 case PIPE_FORMAT_R16G16B16A16_SNORM
:
947 r16g16b16a16_get_tile_rgba((short *) src
, w
, h
, dst
, dst_stride
);
949 case PIPE_FORMAT_Z16_UNORM
:
950 z16_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
);
952 case PIPE_FORMAT_Z32_UNORM
:
953 z32_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
955 case PIPE_FORMAT_S8Z24_UNORM
:
956 case PIPE_FORMAT_X8Z24_UNORM
:
957 s8z24_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
959 case PIPE_FORMAT_Z24S8_UNORM
:
960 case PIPE_FORMAT_Z24X8_UNORM
:
961 z24s8_get_tile_rgba((unsigned *) src
, w
, h
, dst
, dst_stride
);
963 case PIPE_FORMAT_Z32_FLOAT
:
964 z32f_get_tile_rgba((float *) src
, w
, h
, dst
, dst_stride
);
966 case PIPE_FORMAT_YCBCR
:
967 ycbcr_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
, FALSE
);
969 case PIPE_FORMAT_YCBCR_REV
:
970 ycbcr_get_tile_rgba((ushort
*) src
, w
, h
, dst
, dst_stride
, TRUE
);
973 debug_printf("%s: unsupported format %s\n", __FUNCTION__
, pf_name(format
));
974 fake_get_tile_rgba(src
, w
, h
, dst
, dst_stride
);
980 pipe_get_tile_rgba(struct pipe_transfer
*pt
,
981 uint x
, uint y
, uint w
, uint h
,
984 unsigned dst_stride
= w
* 4;
987 if (pipe_clip_tile(x
, y
, &w
, &h
, pt
))
990 packed
= MALLOC(pf_get_nblocks(&pt
->block
, w
, h
) * pt
->block
.size
);
995 if(pt
->format
== PIPE_FORMAT_YCBCR
|| pt
->format
== PIPE_FORMAT_YCBCR_REV
)
996 assert((x
& 1) == 0);
998 pipe_get_tile_raw(pt
, x
, y
, w
, h
, packed
, 0);
1000 pipe_tile_raw_to_rgba(pt
->format
, packed
, w
, h
, p
, dst_stride
);
1007 pipe_put_tile_rgba(struct pipe_transfer
*pt
,
1008 uint x
, uint y
, uint w
, uint h
,
1011 unsigned src_stride
= w
* 4;
1014 if (pipe_clip_tile(x
, y
, &w
, &h
, pt
))
1017 packed
= MALLOC(pf_get_nblocks(&pt
->block
, w
, h
) * pt
->block
.size
);
1022 switch (pt
->format
) {
1023 case PIPE_FORMAT_A8R8G8B8_UNORM
:
1024 a8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
1026 case PIPE_FORMAT_X8R8G8B8_UNORM
:
1027 x8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
1029 case PIPE_FORMAT_B8G8R8A8_UNORM
:
1030 b8g8r8a8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
1032 case PIPE_FORMAT_A1R5G5B5_UNORM
:
1033 a1r5g5b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1035 case PIPE_FORMAT_R5G6B5_UNORM
:
1036 r5g6b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1038 case PIPE_FORMAT_R8G8B8A8_UNORM
:
1041 case PIPE_FORMAT_A4R4G4B4_UNORM
:
1042 a4r4g4b4_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1044 case PIPE_FORMAT_L8_UNORM
:
1045 l8_put_tile_rgba((ubyte
*) packed
, w
, h
, p
, src_stride
);
1047 case PIPE_FORMAT_A8_UNORM
:
1048 a8_put_tile_rgba((ubyte
*) packed
, w
, h
, p
, src_stride
);
1050 case PIPE_FORMAT_I8_UNORM
:
1051 i8_put_tile_rgba((ubyte
*) packed
, w
, h
, p
, src_stride
);
1053 case PIPE_FORMAT_A8L8_UNORM
:
1054 a8l8_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
1056 case PIPE_FORMAT_R16_SNORM
:
1057 r16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
1059 case PIPE_FORMAT_R16G16B16A16_SNORM
:
1060 r16g16b16a16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
1062 case PIPE_FORMAT_Z16_UNORM
:
1063 /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
1065 case PIPE_FORMAT_Z32_UNORM
:
1066 /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
1068 case PIPE_FORMAT_S8Z24_UNORM
:
1069 case PIPE_FORMAT_X8Z24_UNORM
:
1070 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
1072 case PIPE_FORMAT_Z24S8_UNORM
:
1073 case PIPE_FORMAT_Z24X8_UNORM
:
1074 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
1077 debug_printf("%s: unsupported format %s\n", __FUNCTION__
, pf_name(pt
->format
));
1080 pipe_put_tile_raw(pt
, x
, y
, w
, h
, packed
, 0);
1087 * Get a block of Z values, converted to 32-bit range.
1090 pipe_get_tile_z(struct pipe_transfer
*pt
,
1091 uint x
, uint y
, uint w
, uint h
,
1094 struct pipe_screen
*screen
= pt
->texture
->screen
;
1095 const uint dstStride
= w
;
1100 if (pipe_clip_tile(x
, y
, &w
, &h
, pt
))
1103 map
= (ubyte
*)screen
->transfer_map(screen
, pt
);
1109 switch (pt
->format
) {
1110 case PIPE_FORMAT_Z32_UNORM
:
1113 = (const uint
*)(map
+ y
* pt
->stride
+ x
*4);
1114 for (i
= 0; i
< h
; i
++) {
1115 memcpy(pDest
, ptrc
, 4 * w
);
1117 ptrc
+= pt
->stride
/4;
1121 case PIPE_FORMAT_S8Z24_UNORM
:
1122 case PIPE_FORMAT_X8Z24_UNORM
:
1125 = (const uint
*)(map
+ y
* pt
->stride
+ x
*4);
1126 for (i
= 0; i
< h
; i
++) {
1127 for (j
= 0; j
< w
; j
++) {
1128 /* convert 24-bit Z to 32-bit Z */
1129 pDest
[j
] = (ptrc
[j
] << 8) | (ptrc
[j
] & 0xff);
1132 ptrc
+= pt
->stride
/4;
1136 case PIPE_FORMAT_Z16_UNORM
:
1139 = (const ushort
*)(map
+ y
* pt
->stride
+ x
*2);
1140 for (i
= 0; i
< h
; i
++) {
1141 for (j
= 0; j
< w
; j
++) {
1142 /* convert 16-bit Z to 32-bit Z */
1143 pDest
[j
] = (ptrc
[j
] << 16) | ptrc
[j
];
1146 ptrc
+= pt
->stride
/2;
1154 screen
->transfer_unmap(screen
, pt
);
1159 pipe_put_tile_z(struct pipe_transfer
*pt
,
1160 uint x
, uint y
, uint w
, uint h
,
1163 struct pipe_screen
*screen
= pt
->texture
->screen
;
1164 const uint srcStride
= w
;
1165 const uint
*ptrc
= zSrc
;
1169 if (pipe_clip_tile(x
, y
, &w
, &h
, pt
))
1172 map
= (ubyte
*)screen
->transfer_map(screen
, pt
);
1178 switch (pt
->format
) {
1179 case PIPE_FORMAT_Z32_UNORM
:
1181 uint
*pDest
= (uint
*) (map
+ y
* pt
->stride
+ x
*4);
1182 for (i
= 0; i
< h
; i
++) {
1183 memcpy(pDest
, ptrc
, 4 * w
);
1184 pDest
+= pt
->stride
/4;
1189 case PIPE_FORMAT_S8Z24_UNORM
:
1190 case PIPE_FORMAT_X8Z24_UNORM
:
1192 uint
*pDest
= (uint
*) (map
+ y
* pt
->stride
+ x
*4);
1193 for (i
= 0; i
< h
; i
++) {
1194 for (j
= 0; j
< w
; j
++) {
1195 /* convert 32-bit Z to 24-bit Z (0 stencil) */
1196 pDest
[j
] = ptrc
[j
] >> 8;
1198 pDest
+= pt
->stride
/4;
1203 case PIPE_FORMAT_Z24S8_UNORM
:
1204 case PIPE_FORMAT_Z24X8_UNORM
:
1206 uint
*pDest
= (uint
*) (map
+ y
* pt
->stride
+ x
*4);
1207 for (i
= 0; i
< h
; i
++) {
1208 for (j
= 0; j
< w
; j
++) {
1209 /* convert 32-bit Z to 24-bit Z (0 stencil) */
1210 pDest
[j
] = ptrc
[j
] << 8;
1212 pDest
+= pt
->stride
/4;
1217 case PIPE_FORMAT_Z16_UNORM
:
1219 ushort
*pDest
= (ushort
*) (map
+ y
* pt
->stride
+ x
*2);
1220 for (i
= 0; i
< h
; i
++) {
1221 for (j
= 0; j
< w
; j
++) {
1222 /* convert 32-bit Z to 16-bit Z */
1223 pDest
[j
] = ptrc
[j
] >> 16;
1225 pDest
+= pt
->stride
/2;
1234 screen
->transfer_unmap(screen
, pt
);