d37baab8744aa913db2cfe1a3ed44490f2261713
[mesa.git] / src / util / format / u_format_zs.c
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
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.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 **************************************************************************/
27
28
29 #include "util/format/u_format_zs.h"
30 #include "util/u_math.h"
31
32
33 /*
34 * z32_unorm conversion functions
35 */
36
37 static inline uint16_t
38 z32_unorm_to_z16_unorm(uint32_t z)
39 {
40 /* z * 0xffff / 0xffffffff */
41 return z >> 16;
42 }
43
44 static inline uint32_t
45 z16_unorm_to_z32_unorm(uint16_t z)
46 {
47 /* z * 0xffffffff / 0xffff */
48 return ((uint32_t)z << 16) | z;
49 }
50
51 static inline uint32_t
52 z32_unorm_to_z24_unorm(uint32_t z)
53 {
54 /* z * 0xffffff / 0xffffffff */
55 return z >> 8;
56 }
57
58 static inline uint32_t
59 z24_unorm_to_z32_unorm(uint32_t z)
60 {
61 /* z * 0xffffffff / 0xffffff */
62 return (z << 8) | (z >> 16);
63 }
64
65
66 /*
67 * z32_float conversion functions
68 */
69
70 static inline uint16_t
71 z32_float_to_z16_unorm(float z)
72 {
73 const float scale = 0xffff;
74 return (uint16_t)(z * scale + 0.5f);
75 }
76
77 static inline float
78 z16_unorm_to_z32_float(uint16_t z)
79 {
80 const float scale = 1.0 / 0xffff;
81 return (float)(z * scale);
82 }
83
84 static inline uint32_t
85 z32_float_to_z24_unorm(float z)
86 {
87 const double scale = 0xffffff;
88 return (uint32_t)(z * scale) & 0xffffff;
89 }
90
91 static inline float
92 z24_unorm_to_z32_float(uint32_t z)
93 {
94 const double scale = 1.0 / 0xffffff;
95 return (float)(z * scale);
96 }
97
98 static inline uint32_t
99 z32_float_to_z32_unorm(float z)
100 {
101 const double scale = 0xffffffff;
102 return (uint32_t)(z * scale);
103 }
104
105 static inline float
106 z32_unorm_to_z32_float(uint32_t z)
107 {
108 const double scale = 1.0 / 0xffffffff;
109 return (float)(z * scale);
110 }
111
112
113 void
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)
117 {
118 unsigned y;
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);
123 }
124 }
125
126 void
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)
130 {
131 unsigned y;
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);
136 }
137 }
138
139 void
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)
143 {
144 unsigned x, y;
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);
151 }
152 src_row += src_stride/sizeof(*src_row);
153 dst_row += dst_stride/sizeof(*dst_row);
154 }
155 }
156
157 void
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)
161 {
162 unsigned x, y;
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) {
167 uint16_t value;
168 value = z32_float_to_z16_unorm(*src++);
169 *dst++ = util_le16_to_cpu(value);
170 }
171 dst_row += dst_stride/sizeof(*dst_row);
172 src_row += src_stride/sizeof(*src_row);
173 }
174 }
175
176 void
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)
180 {
181 unsigned x, y;
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);
188 }
189 src_row += src_stride/sizeof(*src_row);
190 dst_row += dst_stride/sizeof(*dst_row);
191 }
192 }
193
194 void
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)
198 {
199 unsigned x, y;
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) {
204 uint16_t value;
205 value = z32_unorm_to_z16_unorm(*src++);
206 *dst++ = util_le16_to_cpu(value);
207 }
208 dst_row += dst_stride/sizeof(*dst_row);
209 src_row += src_stride/sizeof(*src_row);
210 }
211 }
212
213 void
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)
217 {
218 unsigned x, y;
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);
225 }
226 src_row += src_stride/sizeof(*src_row);
227 dst_row += dst_stride/sizeof(*dst_row);
228 }
229 }
230
231 void
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)
235 {
236 unsigned x, y;
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) {
241 uint32_t value;
242 value = z32_float_to_z32_unorm(*src++);
243 *dst++ = util_le32_to_cpu(value);
244 }
245 dst_row += dst_stride/sizeof(*dst_row);
246 src_row += src_stride/sizeof(*src_row);
247 }
248 }
249
250 void
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)
254 {
255 unsigned y;
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);
260 }
261 }
262
263 void
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)
267 {
268 unsigned y;
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);
273 }
274 }
275
276 void
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)
280 {
281 unsigned y;
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);
286 }
287 }
288
289 void
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)
293 {
294 unsigned y;
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);
299 }
300 }
301
302 void
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)
306 {
307 unsigned x, y;
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++);
313 }
314 src_row += src_stride/sizeof(*src_row);
315 dst_row += dst_stride/sizeof(*dst_row);
316 }
317 }
318
319 void
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)
323 {
324 unsigned x, y;
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++);
330 }
331 dst_row += dst_stride/sizeof(*dst_row);
332 src_row += src_stride/sizeof(*src_row);
333 }
334 }
335
336 void
337 util_format_z24_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)
340 {
341 unsigned x, y;
342 for(y = 0; y < height; ++y) {
343 float *dst = dst_row;
344 const uint32_t *src = (const uint32_t *)src_row;
345 for(x = 0; x < width; ++x) {
346 uint32_t value = util_cpu_to_le32(*src++);
347 *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
348 }
349 src_row += src_stride/sizeof(*src_row);
350 dst_row += dst_stride/sizeof(*dst_row);
351 }
352 }
353
354 void
355 util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
356 const float *src_row, unsigned src_stride,
357 unsigned width, unsigned height)
358 {
359 unsigned x, y;
360 for(y = 0; y < height; ++y) {
361 const float *src = src_row;
362 uint32_t *dst = (uint32_t *)dst_row;
363 for(x = 0; x < width; ++x) {
364 uint32_t value = util_le32_to_cpu(*dst);
365 value &= 0xff000000;
366 value |= z32_float_to_z24_unorm(*src++);
367 *dst++ = util_cpu_to_le32(value);
368 }
369 dst_row += dst_stride/sizeof(*dst_row);
370 src_row += src_stride/sizeof(*src_row);
371 }
372 }
373
374 void
375 util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
376 const uint8_t *src_row, unsigned src_stride,
377 unsigned width, unsigned height)
378 {
379 unsigned x, y;
380 for(y = 0; y < height; ++y) {
381 uint32_t *dst = dst_row;
382 const uint32_t *src = (const uint32_t *)src_row;
383 for(x = 0; x < width; ++x) {
384 uint32_t value = util_cpu_to_le32(*src++);
385 *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
386 }
387 src_row += src_stride/sizeof(*src_row);
388 dst_row += dst_stride/sizeof(*dst_row);
389 }
390 }
391
392 void
393 util_format_z24_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
394 const uint32_t *src_row, unsigned src_stride,
395 unsigned width, unsigned height)
396 {
397 unsigned x, y;
398 for(y = 0; y < height; ++y) {
399 const uint32_t *src = src_row;
400 uint32_t *dst = (uint32_t *)dst_row;
401 for(x = 0; x < width; ++x) {
402 uint32_t value = util_le32_to_cpu(*dst);
403 value &= 0xff000000;
404 value |= z32_unorm_to_z24_unorm(*src++);
405 *dst++ = util_cpu_to_le32(value);
406 }
407 dst_row += dst_stride/sizeof(*dst_row);
408 src_row += src_stride/sizeof(*src_row);
409 }
410 }
411
412 void
413 util_format_z24_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
414 const uint8_t *src_row, unsigned src_stride,
415 unsigned width, unsigned height)
416 {
417 unsigned x, y;
418 for(y = 0; y < height; ++y) {
419 uint8_t *dst = dst_row;
420 const uint32_t *src = (const uint32_t *)src_row;
421 for(x = 0; x < width; ++x) {
422 uint32_t value = util_cpu_to_le32(*src++);
423 *dst++ = value >> 24;
424 }
425 src_row += src_stride/sizeof(*src_row);
426 dst_row += dst_stride/sizeof(*dst_row);
427 }
428 }
429
430 void
431 util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
432 const uint8_t *src_row, unsigned src_stride,
433 unsigned width, unsigned height)
434 {
435 unsigned x, y;
436 for(y = 0; y < height; ++y) {
437 const uint8_t *src = src_row;
438 uint32_t *dst = (uint32_t *)dst_row;
439 for(x = 0; x < width; ++x) {
440 uint32_t value = util_le32_to_cpu(*dst);
441 value &= 0x00ffffff;
442 value |= (uint32_t)*src++ << 24;
443 *dst++ = util_cpu_to_le32(value);
444 }
445 dst_row += dst_stride/sizeof(*dst_row);
446 src_row += src_stride/sizeof(*src_row);
447 }
448 }
449
450 void
451 util_format_z24_unorm_s8_uint_pack_separate(uint8_t *dst_row, unsigned dst_stride,
452 const uint32_t *z_src_row, unsigned z_src_stride,
453 const uint8_t *s_src_row, unsigned s_src_stride,
454 unsigned width, unsigned height)
455 {
456 unsigned x, y;
457 for (y = 0; y < height; ++y) {
458 const uint32_t *z_src = z_src_row;
459 const uint8_t *s_src = s_src_row;
460 uint32_t *dst = (uint32_t *)dst_row;
461 for (x = 0; x < width; ++x) {
462 *dst++ = (*z_src++ & 0x00ffffff) | ((uint32_t)*s_src++ << 24);
463 }
464 dst_row += dst_stride / sizeof(*dst_row);
465 z_src_row += z_src_stride / sizeof(*z_src_row);
466 s_src_row += s_src_stride / sizeof(*s_src_row);
467 }
468 }
469
470 void
471 util_format_s8_uint_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
472 const uint8_t *src_row, unsigned src_stride,
473 unsigned width, unsigned height)
474 {
475 unsigned x, y;
476 for(y = 0; y < height; ++y) {
477 float *dst = dst_row;
478 const uint32_t *src = (const uint32_t *)src_row;
479 for(x = 0; x < width; ++x) {
480 uint32_t value = util_cpu_to_le32(*src++);
481 *dst++ = z24_unorm_to_z32_float(value >> 8);
482 }
483 src_row += src_stride/sizeof(*src_row);
484 dst_row += dst_stride/sizeof(*dst_row);
485 }
486 }
487
488 void
489 util_format_s8_uint_z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
490 const float *src_row, unsigned src_stride,
491 unsigned width, unsigned height)
492 {
493 unsigned x, y;
494 for(y = 0; y < height; ++y) {
495 const float *src = src_row;
496 uint32_t *dst = (uint32_t *)dst_row;
497 for(x = 0; x < width; ++x) {
498 uint32_t value = util_le32_to_cpu(*dst);
499 value &= 0x000000ff;
500 value |= z32_float_to_z24_unorm(*src++) << 8;
501 *dst++ = util_cpu_to_le32(value);
502 }
503 dst_row += dst_stride/sizeof(*dst_row);
504 src_row += src_stride/sizeof(*src_row);
505 }
506 }
507
508 void
509 util_format_s8_uint_z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
510 const uint8_t *src_row, unsigned src_stride,
511 unsigned width, unsigned height)
512 {
513 unsigned x, y;
514 for(y = 0; y < height; ++y) {
515 uint32_t *dst = dst_row;
516 const uint32_t *src = (const uint32_t *)src_row;
517 for(x = 0; x < width; ++x) {
518 uint32_t value = util_cpu_to_le32(*src++);
519 *dst++ = z24_unorm_to_z32_unorm(value >> 8);
520 }
521 src_row += src_stride/sizeof(*src_row);
522 dst_row += dst_stride/sizeof(*dst_row);
523 }
524 }
525
526 void
527 util_format_s8_uint_z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
528 const uint32_t *src_row, unsigned src_stride,
529 unsigned width, unsigned height)
530 {
531 unsigned x, y;
532 for(y = 0; y < height; ++y) {
533 const uint32_t *src = src_row;
534 uint32_t *dst = (uint32_t *)dst_row;
535 for(x = 0; x < width; ++x) {
536 uint32_t value = util_le32_to_cpu(*dst);
537 value &= 0x000000ff;
538 value |= *src++ & 0xffffff00;
539 *dst++ = util_cpu_to_le32(value);
540 }
541 dst_row += dst_stride/sizeof(*dst_row);
542 src_row += src_stride/sizeof(*src_row);
543 }
544 }
545
546 void
547 util_format_s8_uint_z24_unorm_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
548 const uint8_t *src_row, unsigned src_stride,
549 unsigned width, unsigned height)
550 {
551 unsigned x, y;
552 for(y = 0; y < height; ++y) {
553 uint8_t *dst = dst_row;
554 const uint32_t *src = (const uint32_t *)src_row;
555 for(x = 0; x < width; ++x) {
556 uint32_t value = util_cpu_to_le32(*src++);
557 *dst++ = value & 0xff;
558 }
559 src_row += src_stride/sizeof(*src_row);
560 dst_row += dst_stride/sizeof(*dst_row);
561 }
562 }
563
564 void
565 util_format_s8_uint_z24_unorm_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
566 const uint8_t *src_row, unsigned src_stride,
567 unsigned width, unsigned height)
568 {
569 unsigned x, y;
570 for(y = 0; y < height; ++y) {
571 const uint8_t *src = src_row;
572 uint32_t *dst = (uint32_t *)dst_row;
573 for(x = 0; x < width; ++x) {
574 uint32_t value = util_le32_to_cpu(*dst);
575 value &= 0xffffff00;
576 value |= *src++;
577 *dst++ = util_cpu_to_le32(value);
578 }
579 dst_row += dst_stride/sizeof(*dst_row);
580 src_row += src_stride/sizeof(*src_row);
581 }
582 }
583
584 void
585 util_format_z24x8_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
586 const uint8_t *src_row, unsigned src_stride,
587 unsigned width, unsigned height)
588 {
589 unsigned x, y;
590 for(y = 0; y < height; ++y) {
591 float *dst = dst_row;
592 const uint32_t *src = (const uint32_t *)src_row;
593 for(x = 0; x < width; ++x) {
594 uint32_t value = util_cpu_to_le32(*src++);
595 *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
596 }
597 src_row += src_stride/sizeof(*src_row);
598 dst_row += dst_stride/sizeof(*dst_row);
599 }
600 }
601
602 void
603 util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
604 const float *src_row, unsigned src_stride,
605 unsigned width, unsigned height)
606 {
607 unsigned x, y;
608 for(y = 0; y < height; ++y) {
609 const float *src = src_row;
610 uint32_t *dst = (uint32_t *)dst_row;
611 for(x = 0; x < width; ++x) {
612 uint32_t value;
613 value = z32_float_to_z24_unorm(*src++);
614 *dst++ = util_le32_to_cpu(value);
615 }
616 dst_row += dst_stride/sizeof(*dst_row);
617 src_row += src_stride/sizeof(*src_row);
618 }
619 }
620
621 void
622 util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
623 const uint8_t *src_row, unsigned src_stride,
624 unsigned width, unsigned height)
625 {
626 unsigned x, y;
627 for(y = 0; y < height; ++y) {
628 uint32_t *dst = dst_row;
629 const uint32_t *src = (const uint32_t *)src_row;
630 for(x = 0; x < width; ++x) {
631 uint32_t value = util_cpu_to_le32(*src++);
632 *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
633 }
634 src_row += src_stride/sizeof(*src_row);
635 dst_row += dst_stride/sizeof(*dst_row);
636 }
637 }
638
639 void
640 util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
641 const uint32_t *src_row, unsigned src_stride,
642 unsigned width, unsigned height)
643 {
644 unsigned x, y;
645 for(y = 0; y < height; ++y) {
646 const uint32_t *src = src_row;
647 uint32_t *dst = (uint32_t *)dst_row;
648 for(x = 0; x < width; ++x) {
649 uint32_t value;
650 value = z32_unorm_to_z24_unorm(*src++);
651 *dst++ = util_cpu_to_le32(value);
652 }
653 dst_row += dst_stride/sizeof(*dst_row);
654 src_row += src_stride/sizeof(*src_row);
655 }
656 }
657
658 void
659 util_format_x8z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
660 const uint8_t *src_row, unsigned src_stride,
661 unsigned width, unsigned height)
662 {
663 unsigned x, y;
664 for(y = 0; y < height; ++y) {
665 float *dst = dst_row;
666 const uint32_t *src = (uint32_t *)src_row;
667 for(x = 0; x < width; ++x) {
668 uint32_t value = util_cpu_to_le32(*src++);
669 *dst++ = z24_unorm_to_z32_float(value >> 8);
670 }
671 src_row += src_stride/sizeof(*src_row);
672 dst_row += dst_stride/sizeof(*dst_row);
673 }
674 }
675
676 void
677 util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
678 const float *src_row, unsigned src_stride,
679 unsigned width, unsigned height)
680 {
681 unsigned x, y;
682 for(y = 0; y < height; ++y) {
683 const float *src = src_row;
684 uint32_t *dst = (uint32_t *)dst_row;
685 for(x = 0; x < width; ++x) {
686 uint32_t value;
687 value = z32_float_to_z24_unorm(*src++) << 8;
688 *dst++ = util_cpu_to_le32(value);
689 }
690 dst_row += dst_stride/sizeof(*dst_row);
691 src_row += src_stride/sizeof(*src_row);
692 }
693 }
694
695 void
696 util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
697 const uint8_t *src_row, unsigned src_stride,
698 unsigned width, unsigned height)
699 {
700 unsigned x, y;
701 for(y = 0; y < height; ++y) {
702 uint32_t *dst = dst_row;
703 const uint32_t *src = (const uint32_t *)src_row;
704 for(x = 0; x < width; ++x) {
705 uint32_t value = util_cpu_to_le32(*src++);
706 *dst++ = z24_unorm_to_z32_unorm(value >> 8);
707 }
708 src_row += src_stride/sizeof(*src_row);
709 dst_row += dst_stride/sizeof(*dst_row);
710 }
711 }
712
713 void
714 util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
715 const uint32_t *src_row, unsigned src_stride,
716 unsigned width, unsigned height)
717 {
718 unsigned x, y;
719 for(y = 0; y < height; ++y) {
720 const uint32_t *src = src_row;
721 uint32_t *dst = (uint32_t *)dst_row;
722 for(x = 0; x < width; ++x) {
723 uint32_t value;
724 value = z32_unorm_to_z24_unorm(*src++) << 8;
725 *dst++ = util_cpu_to_le32(value);
726 }
727 dst_row += dst_stride/sizeof(*dst_row);
728 src_row += src_stride/sizeof(*src_row);
729 }
730 }
731
732 void
733 util_format_z32_float_s8x24_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
734 const uint8_t *src_row, unsigned src_stride,
735 unsigned width, unsigned height)
736 {
737 unsigned x, y;
738 for(y = 0; y < height; ++y) {
739 float *dst = dst_row;
740 const float *src = (const float *)src_row;
741 for(x = 0; x < width; ++x) {
742 *dst = *src;
743 src += 2;
744 dst += 1;
745 }
746 src_row += src_stride/sizeof(*src_row);
747 dst_row += dst_stride/sizeof(*dst_row);
748 }
749 }
750
751 void
752 util_format_z32_float_s8x24_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
753 const float *src_row, unsigned src_stride,
754 unsigned width, unsigned height)
755 {
756 unsigned x, y;
757 for(y = 0; y < height; ++y) {
758 const float *src = src_row;
759 float *dst = (float *)dst_row;
760 for(x = 0; x < width; ++x) {
761 *dst = *src;
762 src += 1;
763 dst += 2;
764 }
765 dst_row += dst_stride/sizeof(*dst_row);
766 src_row += src_stride/sizeof(*src_row);
767 }
768 }
769
770 void
771 util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
772 const uint8_t *src_row, unsigned src_stride,
773 unsigned width, unsigned height)
774 {
775 unsigned x, y;
776 for(y = 0; y < height; ++y) {
777 uint32_t *dst = dst_row;
778 const float *src = (const float *)src_row;
779 for(x = 0; x < width; ++x) {
780 *dst = z32_float_to_z32_unorm(*src);
781 src += 2;
782 dst += 1;
783 }
784 src_row += src_stride/sizeof(*src_row);
785 dst_row += dst_stride/sizeof(*dst_row);
786 }
787 }
788
789 void
790 util_format_z32_float_s8x24_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
791 const uint32_t *src_row, unsigned src_stride,
792 unsigned width, unsigned height)
793 {
794 unsigned x, y;
795 for(y = 0; y < height; ++y) {
796 const uint32_t *src = src_row;
797 float *dst = (float *)dst_row;
798 for(x = 0; x < width; ++x) {
799 *dst++ = z32_unorm_to_z32_float(*src++);
800 }
801 dst_row += dst_stride/sizeof(*dst_row);
802 src_row += src_stride/sizeof(*src_row);
803 }
804 }
805
806 void
807 util_format_z32_float_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
808 const uint8_t *src_row, unsigned src_stride,
809 unsigned width, unsigned height)
810 {
811 unsigned x, y;
812 for(y = 0; y < height; ++y) {
813 uint8_t *dst = dst_row;
814 const uint8_t *src = src_row + 4;
815 for(x = 0; x < width; ++x) {
816 *dst = *src;
817 src += 8;
818 dst += 1;
819 }
820 src_row += src_stride/sizeof(*src_row);
821 dst_row += dst_stride/sizeof(*dst_row);
822 }
823 }
824
825 void
826 util_format_z32_float_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
827 const uint8_t *src_row, unsigned src_stride,
828 unsigned width, unsigned height)
829 {
830 unsigned x, y;
831 for(y = 0; y < height; ++y) {
832 const uint8_t *src = src_row;
833 uint32_t *dst = ((uint32_t *)dst_row) + 1;
834 for(x = 0; x < width; ++x) {
835 *dst = util_cpu_to_le32(*src);
836 src += 1;
837 dst += 2;
838 }
839 dst_row += dst_stride/sizeof(*dst_row);
840 src_row += src_stride/sizeof(*src_row);
841 }
842 }
843
844
845 void
846 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)
847 {
848 util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row, dst_stride,
849 src_row, src_stride,
850 width, height);
851 }
852
853 void
854 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)
855 {
856 util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row, dst_stride,
857 src_row, src_stride,
858 width, height);
859 }
860
861 void
862 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)
863 {
864 util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row, dst_stride,
865 src_row, src_stride,
866 width, height);
867 }
868
869 void
870 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)
871 {
872 util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row, dst_stride,
873 src_row, src_stride,
874 width, height);
875 }
876
877 void
878 util_format_x32_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
879 const uint8_t *src_row, unsigned src_stride,
880 unsigned width, unsigned height)
881 {
882 util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row, dst_stride,
883 src_row, src_stride,
884 width, height);
885
886 }
887
888 void
889 util_format_x32_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
890 const uint8_t *src_row, unsigned src_stride,
891 unsigned width, unsigned height)
892 {
893 util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row, dst_stride,
894 src_row, src_stride,
895 width, height);
896 }