1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 **************************************************************************/
29 #include "util/format/u_format_zs.h"
30 #include "util/u_math.h"
34 * z32_unorm conversion functions
37 static inline uint16_t
38 z32_unorm_to_z16_unorm(uint32_t z
)
40 /* z * 0xffff / 0xffffffff */
44 static inline uint32_t
45 z16_unorm_to_z32_unorm(uint16_t z
)
47 /* z * 0xffffffff / 0xffff */
48 return ((uint32_t)z
<< 16) | z
;
51 static inline uint32_t
52 z32_unorm_to_z24_unorm(uint32_t z
)
54 /* z * 0xffffff / 0xffffffff */
58 static inline uint32_t
59 z24_unorm_to_z32_unorm(uint32_t z
)
61 /* z * 0xffffffff / 0xffffff */
62 return (z
<< 8) | (z
>> 16);
67 * z32_float conversion functions
70 static inline uint16_t
71 z32_float_to_z16_unorm(float z
)
73 const float scale
= 0xffff;
74 return (uint16_t)(z
* scale
+ 0.5f
);
78 z16_unorm_to_z32_float(uint16_t z
)
80 const float scale
= 1.0 / 0xffff;
81 return (float)(z
* scale
);
84 static inline uint32_t
85 z32_float_to_z24_unorm(float z
)
87 const double scale
= 0xffffff;
88 return (uint32_t)(z
* scale
) & 0xffffff;
92 z24_unorm_to_z32_float(uint32_t z
)
94 const double scale
= 1.0 / 0xffffff;
95 return (float)(z
* scale
);
98 static inline uint32_t
99 z32_float_to_z32_unorm(float z
)
101 const double scale
= 0xffffffff;
102 return (uint32_t)(z
* scale
);
106 z32_unorm_to_z32_float(uint32_t z
)
108 const double scale
= 1.0 / 0xffffffff;
109 return (float)(z
* scale
);
114 util_format_s8_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
115 const uint8_t *src_row
, unsigned src_stride
,
116 unsigned width
, unsigned height
)
119 for(y
= 0; y
< height
; ++y
) {
120 memcpy(dst_row
, src_row
, width
);
121 src_row
+= src_stride
/sizeof(*src_row
);
122 dst_row
+= dst_stride
/sizeof(*dst_row
);
127 util_format_s8_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
128 const uint8_t *src_row
, unsigned src_stride
,
129 unsigned width
, unsigned height
)
132 for(y
= 0; y
< height
; ++y
) {
133 memcpy(dst_row
, src_row
, width
);
134 src_row
+= src_stride
/sizeof(*src_row
);
135 dst_row
+= dst_stride
/sizeof(*dst_row
);
140 util_format_z16_unorm_unpack_z_float(float *dst_row
, unsigned dst_stride
,
141 const uint8_t *src_row
, unsigned src_stride
,
142 unsigned width
, unsigned height
)
145 for(y
= 0; y
< height
; ++y
) {
146 float *dst
= dst_row
;
147 const uint16_t *src
= (const uint16_t *)src_row
;
148 for(x
= 0; x
< width
; ++x
) {
149 uint16_t value
= util_cpu_to_le16(*src
++);
150 *dst
++ = z16_unorm_to_z32_float(value
);
152 src_row
+= src_stride
/sizeof(*src_row
);
153 dst_row
+= dst_stride
/sizeof(*dst_row
);
158 util_format_z16_unorm_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
159 const float *src_row
, unsigned src_stride
,
160 unsigned width
, unsigned height
)
163 for(y
= 0; y
< height
; ++y
) {
164 const float *src
= src_row
;
165 uint16_t *dst
= (uint16_t *)dst_row
;
166 for(x
= 0; x
< width
; ++x
) {
168 value
= z32_float_to_z16_unorm(*src
++);
169 *dst
++ = util_le16_to_cpu(value
);
171 dst_row
+= dst_stride
/sizeof(*dst_row
);
172 src_row
+= src_stride
/sizeof(*src_row
);
177 util_format_z16_unorm_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
178 const uint8_t *src_row
, unsigned src_stride
,
179 unsigned width
, unsigned height
)
182 for(y
= 0; y
< height
; ++y
) {
183 uint32_t *dst
= dst_row
;
184 const uint16_t *src
= (const uint16_t *)src_row
;
185 for(x
= 0; x
< width
; ++x
) {
186 uint16_t value
= util_cpu_to_le16(*src
++);
187 *dst
++ = z16_unorm_to_z32_unorm(value
);
189 src_row
+= src_stride
/sizeof(*src_row
);
190 dst_row
+= dst_stride
/sizeof(*dst_row
);
195 util_format_z16_unorm_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
196 const uint32_t *src_row
, unsigned src_stride
,
197 unsigned width
, unsigned height
)
200 for(y
= 0; y
< height
; ++y
) {
201 const uint32_t *src
= src_row
;
202 uint16_t *dst
= (uint16_t *)dst_row
;
203 for(x
= 0; x
< width
; ++x
) {
205 value
= z32_unorm_to_z16_unorm(*src
++);
206 *dst
++ = util_le16_to_cpu(value
);
208 dst_row
+= dst_stride
/sizeof(*dst_row
);
209 src_row
+= src_stride
/sizeof(*src_row
);
214 util_format_z32_unorm_unpack_z_float(float *dst_row
, unsigned dst_stride
,
215 const uint8_t *src_row
, unsigned src_stride
,
216 unsigned width
, unsigned height
)
219 for(y
= 0; y
< height
; ++y
) {
220 float *dst
= dst_row
;
221 const uint32_t *src
= (const uint32_t *)src_row
;
222 for(x
= 0; x
< width
; ++x
) {
223 uint32_t value
= util_cpu_to_le32(*src
++);
224 *dst
++ = z32_unorm_to_z32_float(value
);
226 src_row
+= src_stride
/sizeof(*src_row
);
227 dst_row
+= dst_stride
/sizeof(*dst_row
);
232 util_format_z32_unorm_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
233 const float *src_row
, unsigned src_stride
,
234 unsigned width
, unsigned height
)
237 for(y
= 0; y
< height
; ++y
) {
238 const float *src
= src_row
;
239 uint32_t *dst
= (uint32_t *)dst_row
;
240 for(x
= 0; x
< width
; ++x
) {
242 value
= z32_float_to_z32_unorm(*src
++);
243 *dst
++ = util_le32_to_cpu(value
);
245 dst_row
+= dst_stride
/sizeof(*dst_row
);
246 src_row
+= src_stride
/sizeof(*src_row
);
251 util_format_z32_unorm_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
252 const uint8_t *src_row
, unsigned src_stride
,
253 unsigned width
, unsigned height
)
256 for(y
= 0; y
< height
; ++y
) {
257 memcpy(dst_row
, src_row
, width
* 4);
258 src_row
+= src_stride
/sizeof(*src_row
);
259 dst_row
+= dst_stride
/sizeof(*dst_row
);
264 util_format_z32_unorm_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
265 const uint32_t *src_row
, unsigned src_stride
,
266 unsigned width
, unsigned height
)
269 for(y
= 0; y
< height
; ++y
) {
270 memcpy(dst_row
, src_row
, width
* 4);
271 src_row
+= src_stride
/sizeof(*src_row
);
272 dst_row
+= dst_stride
/sizeof(*dst_row
);
277 util_format_z32_float_unpack_z_float(float *dst_row
, unsigned dst_stride
,
278 const uint8_t *src_row
, unsigned src_stride
,
279 unsigned width
, unsigned height
)
282 for(y
= 0; y
< height
; ++y
) {
283 memcpy(dst_row
, src_row
, width
* 4);
284 src_row
+= src_stride
/sizeof(*src_row
);
285 dst_row
+= dst_stride
/sizeof(*dst_row
);
290 util_format_z32_float_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
291 const float *src_row
, unsigned src_stride
,
292 unsigned width
, unsigned height
)
295 for(y
= 0; y
< height
; ++y
) {
296 memcpy(dst_row
, src_row
, width
* 4);
297 src_row
+= src_stride
/sizeof(*src_row
);
298 dst_row
+= dst_stride
/sizeof(*dst_row
);
303 util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
304 const uint8_t *src_row
, unsigned src_stride
,
305 unsigned width
, unsigned height
)
308 for(y
= 0; y
< height
; ++y
) {
309 uint32_t *dst
= dst_row
;
310 const float *src
= (const float *)src_row
;
311 for(x
= 0; x
< width
; ++x
) {
312 *dst
++ = z32_float_to_z32_unorm(*src
++);
314 src_row
+= src_stride
/sizeof(*src_row
);
315 dst_row
+= dst_stride
/sizeof(*dst_row
);
320 util_format_z32_float_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
321 const uint32_t *src_row
, unsigned src_stride
,
322 unsigned width
, unsigned height
)
325 for(y
= 0; y
< height
; ++y
) {
326 const uint32_t *src
= src_row
;
327 float *dst
= (float *)dst_row
;
328 for(x
= 0; x
< width
; ++x
) {
329 *dst
++ = z32_unorm_to_z32_float(*src
++);
331 dst_row
+= dst_stride
/sizeof(*dst_row
);
332 src_row
+= src_stride
/sizeof(*src_row
);
337 util_format_z16_unorm_s8_uint_unpack_z_float(float *dst_row
, unsigned dst_stride
,
338 const uint8_t *src_row
, unsigned src_stride
,
339 unsigned width
, unsigned height
)
341 unreachable("z16_s8 packing/unpacking is not implemented.");
345 util_format_z16_unorm_s8_uint_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
346 const float *src_row
, unsigned src_stride
,
347 unsigned width
, unsigned height
)
349 unreachable("z16_s8 packing/unpacking is not implemented.");
353 util_format_z16_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
354 const uint8_t *src_row
, unsigned src_stride
,
355 unsigned width
, unsigned height
)
357 unreachable("z16_s8 packing/unpacking is not implemented.");
361 util_format_z16_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
362 const uint32_t *src_row
, unsigned src_stride
,
363 unsigned width
, unsigned height
)
365 unreachable("z16_s8 packing/unpacking is not implemented.");
369 util_format_z16_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
370 const uint8_t *src_row
, unsigned src_stride
,
371 unsigned width
, unsigned height
)
373 unreachable("z16_s8 packing/unpacking is not implemented.");
377 util_format_z16_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
378 const uint8_t *src_row
, unsigned src_stride
,
379 unsigned width
, unsigned height
)
381 unreachable("z16_s8 packing/unpacking is not implemented.");
385 util_format_z24_unorm_s8_uint_unpack_z_float(float *dst_row
, unsigned dst_stride
,
386 const uint8_t *src_row
, unsigned src_stride
,
387 unsigned width
, unsigned height
)
390 for(y
= 0; y
< height
; ++y
) {
391 float *dst
= dst_row
;
392 const uint32_t *src
= (const uint32_t *)src_row
;
393 for(x
= 0; x
< width
; ++x
) {
394 uint32_t value
= util_cpu_to_le32(*src
++);
395 *dst
++ = z24_unorm_to_z32_float(value
& 0xffffff);
397 src_row
+= src_stride
/sizeof(*src_row
);
398 dst_row
+= dst_stride
/sizeof(*dst_row
);
403 util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
404 const float *src_row
, unsigned src_stride
,
405 unsigned width
, unsigned height
)
408 for(y
= 0; y
< height
; ++y
) {
409 const float *src
= src_row
;
410 uint32_t *dst
= (uint32_t *)dst_row
;
411 for(x
= 0; x
< width
; ++x
) {
412 uint32_t value
= util_le32_to_cpu(*dst
);
414 value
|= z32_float_to_z24_unorm(*src
++);
415 *dst
++ = util_cpu_to_le32(value
);
417 dst_row
+= dst_stride
/sizeof(*dst_row
);
418 src_row
+= src_stride
/sizeof(*src_row
);
424 util_format_z24_unorm_s8_uint_unpack_z24(uint8_t *dst_row
, unsigned dst_stride
,
425 const uint8_t *src_row
, unsigned src_stride
,
426 unsigned width
, unsigned height
)
429 for(y
= 0; y
< height
; ++y
) {
430 uint32_t *dst
= (uint32_t *)dst_row
;
431 const uint32_t *src
= (const uint32_t *)src_row
;
432 for(x
= 0; x
< width
; ++x
) {
433 uint32_t value
= util_cpu_to_le32(*src
++);
434 *dst
++ = (value
& 0xffffff);
436 src_row
+= src_stride
/sizeof(*src_row
);
437 dst_row
+= dst_stride
/sizeof(*dst_row
);
442 util_format_z24_unorm_s8_uint_pack_z24(uint8_t *dst_row
, unsigned dst_stride
,
443 const uint8_t *src_row
, unsigned src_stride
,
444 unsigned width
, unsigned height
)
447 for(y
= 0; y
< height
; ++y
) {
448 const uint32_t *src
= (const uint32_t *)src_row
;
449 uint32_t *dst
= (uint32_t *)dst_row
;
450 for(x
= 0; x
< width
; ++x
) {
451 uint32_t value
= util_le32_to_cpu(*dst
);
453 value
|= *src
& 0xffffff;
455 *dst
++ = util_cpu_to_le32(value
);
457 dst_row
+= dst_stride
/sizeof(*dst_row
);
458 src_row
+= src_stride
/sizeof(*src_row
);
463 util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
464 const uint8_t *src_row
, unsigned src_stride
,
465 unsigned width
, unsigned height
)
468 for(y
= 0; y
< height
; ++y
) {
469 uint32_t *dst
= dst_row
;
470 const uint32_t *src
= (const uint32_t *)src_row
;
471 for(x
= 0; x
< width
; ++x
) {
472 uint32_t value
= util_cpu_to_le32(*src
++);
473 *dst
++ = z24_unorm_to_z32_unorm(value
& 0xffffff);
475 src_row
+= src_stride
/sizeof(*src_row
);
476 dst_row
+= dst_stride
/sizeof(*dst_row
);
481 util_format_z24_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
482 const uint32_t *src_row
, unsigned src_stride
,
483 unsigned width
, unsigned height
)
486 for(y
= 0; y
< height
; ++y
) {
487 const uint32_t *src
= src_row
;
488 uint32_t *dst
= (uint32_t *)dst_row
;
489 for(x
= 0; x
< width
; ++x
) {
490 uint32_t value
= util_le32_to_cpu(*dst
);
492 value
|= z32_unorm_to_z24_unorm(*src
++);
493 *dst
++ = util_cpu_to_le32(value
);
495 dst_row
+= dst_stride
/sizeof(*dst_row
);
496 src_row
+= src_stride
/sizeof(*src_row
);
501 util_format_z24_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
502 const uint8_t *src_row
, unsigned src_stride
,
503 unsigned width
, unsigned height
)
506 for(y
= 0; y
< height
; ++y
) {
507 uint8_t *dst
= dst_row
;
508 const uint32_t *src
= (const uint32_t *)src_row
;
509 for(x
= 0; x
< width
; ++x
) {
510 uint32_t value
= util_cpu_to_le32(*src
++);
511 *dst
++ = value
>> 24;
513 src_row
+= src_stride
/sizeof(*src_row
);
514 dst_row
+= dst_stride
/sizeof(*dst_row
);
519 util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
520 const uint8_t *src_row
, unsigned src_stride
,
521 unsigned width
, unsigned height
)
524 for(y
= 0; y
< height
; ++y
) {
525 const uint8_t *src
= src_row
;
526 uint32_t *dst
= (uint32_t *)dst_row
;
527 for(x
= 0; x
< width
; ++x
) {
528 uint32_t value
= util_le32_to_cpu(*dst
);
530 value
|= (uint32_t)*src
++ << 24;
531 *dst
++ = util_cpu_to_le32(value
);
533 dst_row
+= dst_stride
/sizeof(*dst_row
);
534 src_row
+= src_stride
/sizeof(*src_row
);
539 util_format_z24_unorm_s8_uint_pack_separate(uint8_t *dst_row
, unsigned dst_stride
,
540 const uint32_t *z_src_row
, unsigned z_src_stride
,
541 const uint8_t *s_src_row
, unsigned s_src_stride
,
542 unsigned width
, unsigned height
)
545 for (y
= 0; y
< height
; ++y
) {
546 const uint32_t *z_src
= z_src_row
;
547 const uint8_t *s_src
= s_src_row
;
548 uint32_t *dst
= (uint32_t *)dst_row
;
549 for (x
= 0; x
< width
; ++x
) {
550 *dst
++ = (*z_src
++ & 0x00ffffff) | ((uint32_t)*s_src
++ << 24);
552 dst_row
+= dst_stride
/ sizeof(*dst_row
);
553 z_src_row
+= z_src_stride
/ sizeof(*z_src_row
);
554 s_src_row
+= s_src_stride
/ sizeof(*s_src_row
);
559 util_format_s8_uint_z24_unorm_unpack_z_float(float *dst_row
, unsigned dst_stride
,
560 const uint8_t *src_row
, unsigned src_stride
,
561 unsigned width
, unsigned height
)
564 for(y
= 0; y
< height
; ++y
) {
565 float *dst
= dst_row
;
566 const uint32_t *src
= (const uint32_t *)src_row
;
567 for(x
= 0; x
< width
; ++x
) {
568 uint32_t value
= util_cpu_to_le32(*src
++);
569 *dst
++ = z24_unorm_to_z32_float(value
>> 8);
571 src_row
+= src_stride
/sizeof(*src_row
);
572 dst_row
+= dst_stride
/sizeof(*dst_row
);
577 util_format_s8_uint_z24_unorm_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
578 const float *src_row
, unsigned src_stride
,
579 unsigned width
, unsigned height
)
582 for(y
= 0; y
< height
; ++y
) {
583 const float *src
= src_row
;
584 uint32_t *dst
= (uint32_t *)dst_row
;
585 for(x
= 0; x
< width
; ++x
) {
586 uint32_t value
= util_le32_to_cpu(*dst
);
588 value
|= z32_float_to_z24_unorm(*src
++) << 8;
589 *dst
++ = util_cpu_to_le32(value
);
591 dst_row
+= dst_stride
/sizeof(*dst_row
);
592 src_row
+= src_stride
/sizeof(*src_row
);
597 util_format_s8_uint_z24_unorm_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
598 const uint8_t *src_row
, unsigned src_stride
,
599 unsigned width
, unsigned height
)
602 for(y
= 0; y
< height
; ++y
) {
603 uint32_t *dst
= dst_row
;
604 const uint32_t *src
= (const uint32_t *)src_row
;
605 for(x
= 0; x
< width
; ++x
) {
606 uint32_t value
= util_cpu_to_le32(*src
++);
607 *dst
++ = z24_unorm_to_z32_unorm(value
>> 8);
609 src_row
+= src_stride
/sizeof(*src_row
);
610 dst_row
+= dst_stride
/sizeof(*dst_row
);
615 util_format_s8_uint_z24_unorm_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
616 const uint32_t *src_row
, unsigned src_stride
,
617 unsigned width
, unsigned height
)
620 for(y
= 0; y
< height
; ++y
) {
621 const uint32_t *src
= src_row
;
622 uint32_t *dst
= (uint32_t *)dst_row
;
623 for(x
= 0; x
< width
; ++x
) {
624 uint32_t value
= util_le32_to_cpu(*dst
);
626 value
|= *src
++ & 0xffffff00;
627 *dst
++ = util_cpu_to_le32(value
);
629 dst_row
+= dst_stride
/sizeof(*dst_row
);
630 src_row
+= src_stride
/sizeof(*src_row
);
635 util_format_s8_uint_z24_unorm_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
636 const uint8_t *src_row
, unsigned src_stride
,
637 unsigned width
, unsigned height
)
640 for(y
= 0; y
< height
; ++y
) {
641 uint8_t *dst
= dst_row
;
642 const uint32_t *src
= (const uint32_t *)src_row
;
643 for(x
= 0; x
< width
; ++x
) {
644 uint32_t value
= util_cpu_to_le32(*src
++);
645 *dst
++ = value
& 0xff;
647 src_row
+= src_stride
/sizeof(*src_row
);
648 dst_row
+= dst_stride
/sizeof(*dst_row
);
653 util_format_s8_uint_z24_unorm_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
654 const uint8_t *src_row
, unsigned src_stride
,
655 unsigned width
, unsigned height
)
658 for(y
= 0; y
< height
; ++y
) {
659 const uint8_t *src
= src_row
;
660 uint32_t *dst
= (uint32_t *)dst_row
;
661 for(x
= 0; x
< width
; ++x
) {
662 uint32_t value
= util_le32_to_cpu(*dst
);
665 *dst
++ = util_cpu_to_le32(value
);
667 dst_row
+= dst_stride
/sizeof(*dst_row
);
668 src_row
+= src_stride
/sizeof(*src_row
);
673 util_format_z24x8_unorm_unpack_z_float(float *dst_row
, unsigned dst_stride
,
674 const uint8_t *src_row
, unsigned src_stride
,
675 unsigned width
, unsigned height
)
678 for(y
= 0; y
< height
; ++y
) {
679 float *dst
= dst_row
;
680 const uint32_t *src
= (const uint32_t *)src_row
;
681 for(x
= 0; x
< width
; ++x
) {
682 uint32_t value
= util_cpu_to_le32(*src
++);
683 *dst
++ = z24_unorm_to_z32_float(value
& 0xffffff);
685 src_row
+= src_stride
/sizeof(*src_row
);
686 dst_row
+= dst_stride
/sizeof(*dst_row
);
691 util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
692 const float *src_row
, unsigned src_stride
,
693 unsigned width
, unsigned height
)
696 for(y
= 0; y
< height
; ++y
) {
697 const float *src
= src_row
;
698 uint32_t *dst
= (uint32_t *)dst_row
;
699 for(x
= 0; x
< width
; ++x
) {
701 value
= z32_float_to_z24_unorm(*src
++);
702 *dst
++ = util_le32_to_cpu(value
);
704 dst_row
+= dst_stride
/sizeof(*dst_row
);
705 src_row
+= src_stride
/sizeof(*src_row
);
710 util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
711 const uint8_t *src_row
, unsigned src_stride
,
712 unsigned width
, unsigned height
)
715 for(y
= 0; y
< height
; ++y
) {
716 uint32_t *dst
= dst_row
;
717 const uint32_t *src
= (const uint32_t *)src_row
;
718 for(x
= 0; x
< width
; ++x
) {
719 uint32_t value
= util_cpu_to_le32(*src
++);
720 *dst
++ = z24_unorm_to_z32_unorm(value
& 0xffffff);
722 src_row
+= src_stride
/sizeof(*src_row
);
723 dst_row
+= dst_stride
/sizeof(*dst_row
);
728 util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
729 const uint32_t *src_row
, unsigned src_stride
,
730 unsigned width
, unsigned height
)
733 for(y
= 0; y
< height
; ++y
) {
734 const uint32_t *src
= src_row
;
735 uint32_t *dst
= (uint32_t *)dst_row
;
736 for(x
= 0; x
< width
; ++x
) {
738 value
= z32_unorm_to_z24_unorm(*src
++);
739 *dst
++ = util_cpu_to_le32(value
);
741 dst_row
+= dst_stride
/sizeof(*dst_row
);
742 src_row
+= src_stride
/sizeof(*src_row
);
747 util_format_x8z24_unorm_unpack_z_float(float *dst_row
, unsigned dst_stride
,
748 const uint8_t *src_row
, unsigned src_stride
,
749 unsigned width
, unsigned height
)
752 for(y
= 0; y
< height
; ++y
) {
753 float *dst
= dst_row
;
754 const uint32_t *src
= (uint32_t *)src_row
;
755 for(x
= 0; x
< width
; ++x
) {
756 uint32_t value
= util_cpu_to_le32(*src
++);
757 *dst
++ = z24_unorm_to_z32_float(value
>> 8);
759 src_row
+= src_stride
/sizeof(*src_row
);
760 dst_row
+= dst_stride
/sizeof(*dst_row
);
765 util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
766 const float *src_row
, unsigned src_stride
,
767 unsigned width
, unsigned height
)
770 for(y
= 0; y
< height
; ++y
) {
771 const float *src
= src_row
;
772 uint32_t *dst
= (uint32_t *)dst_row
;
773 for(x
= 0; x
< width
; ++x
) {
775 value
= z32_float_to_z24_unorm(*src
++) << 8;
776 *dst
++ = util_cpu_to_le32(value
);
778 dst_row
+= dst_stride
/sizeof(*dst_row
);
779 src_row
+= src_stride
/sizeof(*src_row
);
784 util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
785 const uint8_t *src_row
, unsigned src_stride
,
786 unsigned width
, unsigned height
)
789 for(y
= 0; y
< height
; ++y
) {
790 uint32_t *dst
= dst_row
;
791 const uint32_t *src
= (const uint32_t *)src_row
;
792 for(x
= 0; x
< width
; ++x
) {
793 uint32_t value
= util_cpu_to_le32(*src
++);
794 *dst
++ = z24_unorm_to_z32_unorm(value
>> 8);
796 src_row
+= src_stride
/sizeof(*src_row
);
797 dst_row
+= dst_stride
/sizeof(*dst_row
);
802 util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
803 const uint32_t *src_row
, unsigned src_stride
,
804 unsigned width
, unsigned height
)
807 for(y
= 0; y
< height
; ++y
) {
808 const uint32_t *src
= src_row
;
809 uint32_t *dst
= (uint32_t *)dst_row
;
810 for(x
= 0; x
< width
; ++x
) {
812 value
= z32_unorm_to_z24_unorm(*src
++) << 8;
813 *dst
++ = util_cpu_to_le32(value
);
815 dst_row
+= dst_stride
/sizeof(*dst_row
);
816 src_row
+= src_stride
/sizeof(*src_row
);
821 util_format_z32_float_s8x24_uint_unpack_z_float(float *dst_row
, unsigned dst_stride
,
822 const uint8_t *src_row
, unsigned src_stride
,
823 unsigned width
, unsigned height
)
826 for(y
= 0; y
< height
; ++y
) {
827 float *dst
= dst_row
;
828 const float *src
= (const float *)src_row
;
829 for(x
= 0; x
< width
; ++x
) {
834 src_row
+= src_stride
/sizeof(*src_row
);
835 dst_row
+= dst_stride
/sizeof(*dst_row
);
840 util_format_z32_float_s8x24_uint_pack_z_float(uint8_t *dst_row
, unsigned dst_stride
,
841 const float *src_row
, unsigned src_stride
,
842 unsigned width
, unsigned height
)
845 for(y
= 0; y
< height
; ++y
) {
846 const float *src
= src_row
;
847 float *dst
= (float *)dst_row
;
848 for(x
= 0; x
< width
; ++x
) {
853 dst_row
+= dst_stride
/sizeof(*dst_row
);
854 src_row
+= src_stride
/sizeof(*src_row
);
859 util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *dst_row
, unsigned dst_stride
,
860 const uint8_t *src_row
, unsigned src_stride
,
861 unsigned width
, unsigned height
)
864 for(y
= 0; y
< height
; ++y
) {
865 uint32_t *dst
= dst_row
;
866 const float *src
= (const float *)src_row
;
867 for(x
= 0; x
< width
; ++x
) {
868 *dst
= z32_float_to_z32_unorm(*src
);
872 src_row
+= src_stride
/sizeof(*src_row
);
873 dst_row
+= dst_stride
/sizeof(*dst_row
);
878 util_format_z32_float_s8x24_uint_pack_z_32unorm(uint8_t *dst_row
, unsigned dst_stride
,
879 const uint32_t *src_row
, unsigned src_stride
,
880 unsigned width
, unsigned height
)
883 for(y
= 0; y
< height
; ++y
) {
884 const uint32_t *src
= src_row
;
885 float *dst
= (float *)dst_row
;
886 for(x
= 0; x
< width
; ++x
) {
887 *dst
++ = z32_unorm_to_z32_float(*src
++);
889 dst_row
+= dst_stride
/sizeof(*dst_row
);
890 src_row
+= src_stride
/sizeof(*src_row
);
895 util_format_z32_float_s8x24_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
896 const uint8_t *src_row
, unsigned src_stride
,
897 unsigned width
, unsigned height
)
900 for(y
= 0; y
< height
; ++y
) {
901 uint8_t *dst
= dst_row
;
902 const uint8_t *src
= src_row
+ 4;
903 for(x
= 0; x
< width
; ++x
) {
908 src_row
+= src_stride
/sizeof(*src_row
);
909 dst_row
+= dst_stride
/sizeof(*dst_row
);
914 util_format_z32_float_s8x24_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
915 const uint8_t *src_row
, unsigned src_stride
,
916 unsigned width
, unsigned height
)
919 for(y
= 0; y
< height
; ++y
) {
920 const uint8_t *src
= src_row
;
921 uint32_t *dst
= ((uint32_t *)dst_row
) + 1;
922 for(x
= 0; x
< width
; ++x
) {
923 *dst
= util_cpu_to_le32(*src
);
927 dst_row
+= dst_stride
/sizeof(*dst_row
);
928 src_row
+= src_stride
/sizeof(*src_row
);
934 util_format_x24s8_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
936 util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row
, dst_stride
,
942 util_format_x24s8_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
944 util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row
, dst_stride
,
950 util_format_s8x24_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
952 util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row
, dst_stride
,
958 util_format_s8x24_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
960 util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row
, dst_stride
,
966 util_format_x32_s8x24_uint_unpack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
967 const uint8_t *src_row
, unsigned src_stride
,
968 unsigned width
, unsigned height
)
970 util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row
, dst_stride
,
977 util_format_x32_s8x24_uint_pack_s_8uint(uint8_t *dst_row
, unsigned dst_stride
,
978 const uint8_t *src_row
, unsigned src_stride
,
979 unsigned width
, unsigned height
)
981 util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row
, dst_stride
,