util: Expose rgba unpack/fetch functions as external functions as well.
[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_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)
340 {
341 unreachable("z16_s8 packing/unpacking is not implemented.");
342 }
343
344 void
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)
348 {
349 unreachable("z16_s8 packing/unpacking is not implemented.");
350 }
351
352 void
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)
356 {
357 unreachable("z16_s8 packing/unpacking is not implemented.");
358 }
359
360 void
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)
364 {
365 unreachable("z16_s8 packing/unpacking is not implemented.");
366 }
367
368 void
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)
372 {
373 unreachable("z16_s8 packing/unpacking is not implemented.");
374 }
375
376 void
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)
380 {
381 unreachable("z16_s8 packing/unpacking is not implemented.");
382 }
383
384 void
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)
388 {
389 unsigned x, y;
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);
396 }
397 src_row += src_stride/sizeof(*src_row);
398 dst_row += dst_stride/sizeof(*dst_row);
399 }
400 }
401
402 void
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)
406 {
407 unsigned x, y;
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);
413 value &= 0xff000000;
414 value |= z32_float_to_z24_unorm(*src++);
415 *dst++ = util_cpu_to_le32(value);
416 }
417 dst_row += dst_stride/sizeof(*dst_row);
418 src_row += src_stride/sizeof(*src_row);
419 }
420 }
421
422
423 void
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)
427 {
428 unsigned x, y;
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);
435 }
436 src_row += src_stride/sizeof(*src_row);
437 dst_row += dst_stride/sizeof(*dst_row);
438 }
439 }
440
441 void
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)
445 {
446 unsigned x, y;
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);
452 value &= 0xff000000;
453 value |= *src & 0xffffff;
454 src++;
455 *dst++ = util_cpu_to_le32(value);
456 }
457 dst_row += dst_stride/sizeof(*dst_row);
458 src_row += src_stride/sizeof(*src_row);
459 }
460 }
461
462 void
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)
466 {
467 unsigned x, y;
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);
474 }
475 src_row += src_stride/sizeof(*src_row);
476 dst_row += dst_stride/sizeof(*dst_row);
477 }
478 }
479
480 void
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)
484 {
485 unsigned x, y;
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);
491 value &= 0xff000000;
492 value |= z32_unorm_to_z24_unorm(*src++);
493 *dst++ = util_cpu_to_le32(value);
494 }
495 dst_row += dst_stride/sizeof(*dst_row);
496 src_row += src_stride/sizeof(*src_row);
497 }
498 }
499
500 void
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)
504 {
505 unsigned x, y;
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;
512 }
513 src_row += src_stride/sizeof(*src_row);
514 dst_row += dst_stride/sizeof(*dst_row);
515 }
516 }
517
518 void
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)
522 {
523 unsigned x, y;
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);
529 value &= 0x00ffffff;
530 value |= (uint32_t)*src++ << 24;
531 *dst++ = util_cpu_to_le32(value);
532 }
533 dst_row += dst_stride/sizeof(*dst_row);
534 src_row += src_stride/sizeof(*src_row);
535 }
536 }
537
538 void
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)
543 {
544 unsigned x, y;
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);
551 }
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);
555 }
556 }
557
558 void
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)
562 {
563 unsigned x, y;
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);
570 }
571 src_row += src_stride/sizeof(*src_row);
572 dst_row += dst_stride/sizeof(*dst_row);
573 }
574 }
575
576 void
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)
580 {
581 unsigned x, y;
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);
587 value &= 0x000000ff;
588 value |= z32_float_to_z24_unorm(*src++) << 8;
589 *dst++ = util_cpu_to_le32(value);
590 }
591 dst_row += dst_stride/sizeof(*dst_row);
592 src_row += src_stride/sizeof(*src_row);
593 }
594 }
595
596 void
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)
600 {
601 unsigned x, y;
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);
608 }
609 src_row += src_stride/sizeof(*src_row);
610 dst_row += dst_stride/sizeof(*dst_row);
611 }
612 }
613
614 void
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)
618 {
619 unsigned x, y;
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);
625 value &= 0x000000ff;
626 value |= *src++ & 0xffffff00;
627 *dst++ = util_cpu_to_le32(value);
628 }
629 dst_row += dst_stride/sizeof(*dst_row);
630 src_row += src_stride/sizeof(*src_row);
631 }
632 }
633
634 void
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)
638 {
639 unsigned x, y;
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;
646 }
647 src_row += src_stride/sizeof(*src_row);
648 dst_row += dst_stride/sizeof(*dst_row);
649 }
650 }
651
652 void
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)
656 {
657 unsigned x, y;
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);
663 value &= 0xffffff00;
664 value |= *src++;
665 *dst++ = util_cpu_to_le32(value);
666 }
667 dst_row += dst_stride/sizeof(*dst_row);
668 src_row += src_stride/sizeof(*src_row);
669 }
670 }
671
672 void
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)
676 {
677 unsigned x, y;
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);
684 }
685 src_row += src_stride/sizeof(*src_row);
686 dst_row += dst_stride/sizeof(*dst_row);
687 }
688 }
689
690 void
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)
694 {
695 unsigned x, y;
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) {
700 uint32_t value;
701 value = z32_float_to_z24_unorm(*src++);
702 *dst++ = util_le32_to_cpu(value);
703 }
704 dst_row += dst_stride/sizeof(*dst_row);
705 src_row += src_stride/sizeof(*src_row);
706 }
707 }
708
709 void
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)
713 {
714 unsigned x, y;
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);
721 }
722 src_row += src_stride/sizeof(*src_row);
723 dst_row += dst_stride/sizeof(*dst_row);
724 }
725 }
726
727 void
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)
731 {
732 unsigned x, y;
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) {
737 uint32_t value;
738 value = z32_unorm_to_z24_unorm(*src++);
739 *dst++ = util_cpu_to_le32(value);
740 }
741 dst_row += dst_stride/sizeof(*dst_row);
742 src_row += src_stride/sizeof(*src_row);
743 }
744 }
745
746 void
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)
750 {
751 unsigned x, y;
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);
758 }
759 src_row += src_stride/sizeof(*src_row);
760 dst_row += dst_stride/sizeof(*dst_row);
761 }
762 }
763
764 void
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)
768 {
769 unsigned x, y;
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) {
774 uint32_t value;
775 value = z32_float_to_z24_unorm(*src++) << 8;
776 *dst++ = util_cpu_to_le32(value);
777 }
778 dst_row += dst_stride/sizeof(*dst_row);
779 src_row += src_stride/sizeof(*src_row);
780 }
781 }
782
783 void
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)
787 {
788 unsigned x, y;
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);
795 }
796 src_row += src_stride/sizeof(*src_row);
797 dst_row += dst_stride/sizeof(*dst_row);
798 }
799 }
800
801 void
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)
805 {
806 unsigned x, y;
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) {
811 uint32_t value;
812 value = z32_unorm_to_z24_unorm(*src++) << 8;
813 *dst++ = util_cpu_to_le32(value);
814 }
815 dst_row += dst_stride/sizeof(*dst_row);
816 src_row += src_stride/sizeof(*src_row);
817 }
818 }
819
820 void
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)
824 {
825 unsigned x, y;
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) {
830 *dst = *src;
831 src += 2;
832 dst += 1;
833 }
834 src_row += src_stride/sizeof(*src_row);
835 dst_row += dst_stride/sizeof(*dst_row);
836 }
837 }
838
839 void
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)
843 {
844 unsigned x, y;
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) {
849 *dst = *src;
850 src += 1;
851 dst += 2;
852 }
853 dst_row += dst_stride/sizeof(*dst_row);
854 src_row += src_stride/sizeof(*src_row);
855 }
856 }
857
858 void
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)
862 {
863 unsigned x, y;
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);
869 src += 2;
870 dst += 1;
871 }
872 src_row += src_stride/sizeof(*src_row);
873 dst_row += dst_stride/sizeof(*dst_row);
874 }
875 }
876
877 void
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)
881 {
882 unsigned x, y;
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++);
888 }
889 dst_row += dst_stride/sizeof(*dst_row);
890 src_row += src_stride/sizeof(*src_row);
891 }
892 }
893
894 void
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)
898 {
899 unsigned x, y;
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) {
904 *dst = *src;
905 src += 8;
906 dst += 1;
907 }
908 src_row += src_stride/sizeof(*src_row);
909 dst_row += dst_stride/sizeof(*dst_row);
910 }
911 }
912
913 void
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)
917 {
918 unsigned x, y;
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);
924 src += 1;
925 dst += 2;
926 }
927 dst_row += dst_stride/sizeof(*dst_row);
928 src_row += src_stride/sizeof(*src_row);
929 }
930 }
931
932
933 void
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)
935 {
936 util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row, dst_stride,
937 src_row, src_stride,
938 width, height);
939 }
940
941 void
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)
943 {
944 util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row, dst_stride,
945 src_row, src_stride,
946 width, height);
947 }
948
949 void
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)
951 {
952 util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row, dst_stride,
953 src_row, src_stride,
954 width, height);
955 }
956
957 void
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)
959 {
960 util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row, dst_stride,
961 src_row, src_stride,
962 width, height);
963 }
964
965 void
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)
969 {
970 util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row, dst_stride,
971 src_row, src_stride,
972 width, height);
973
974 }
975
976 void
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)
980 {
981 util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row, dst_stride,
982 src_row, src_stride,
983 width, height);
984 }