gallium/util: pregenerate half float tables
[mesa.git] / src / gallium / auxiliary / util / u_format.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 above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 VMWARE 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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * Pixel format accessor functions.
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35 #include "u_format.h"
36 #include "u_format_s3tc.h"
37 #include "u_half.h"
38
39
40 void
41 util_format_read_4f(enum pipe_format format,
42 float *dst, unsigned dst_stride,
43 const void *src, unsigned src_stride,
44 unsigned x, unsigned y, unsigned w, unsigned h)
45 {
46 const struct util_format_description *format_desc;
47 const uint8_t *src_row;
48 float *dst_row;
49
50 format_desc = util_format_description(format);
51
52 assert(x % format_desc->block.width == 0);
53 assert(y % format_desc->block.height == 0);
54
55 src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
56 dst_row = dst;
57
58 format_desc->unpack_float(dst_row, dst_stride, src_row, src_stride, w, h);
59 }
60
61
62 void
63 util_format_write_4f(enum pipe_format format,
64 const float *src, unsigned src_stride,
65 void *dst, unsigned dst_stride,
66 unsigned x, unsigned y, unsigned w, unsigned h)
67 {
68 const struct util_format_description *format_desc;
69 uint8_t *dst_row;
70 const float *src_row;
71
72 format_desc = util_format_description(format);
73
74 assert(x % format_desc->block.width == 0);
75 assert(y % format_desc->block.height == 0);
76
77 dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
78 src_row = src;
79
80 format_desc->pack_float(dst_row, dst_stride, src_row, src_stride, w, h);
81 }
82
83
84 void
85 util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h)
86 {
87 const struct util_format_description *format_desc;
88 const uint8_t *src_row;
89 uint8_t *dst_row;
90
91 format_desc = util_format_description(format);
92
93 assert(x % format_desc->block.width == 0);
94 assert(y % format_desc->block.height == 0);
95
96 src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
97 dst_row = dst;
98
99 format_desc->unpack_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
100 }
101
102
103 void
104 util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_stride, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h)
105 {
106 const struct util_format_description *format_desc;
107 uint8_t *dst_row;
108 const uint8_t *src_row;
109
110 format_desc = util_format_description(format);
111
112 assert(x % format_desc->block.width == 0);
113 assert(y % format_desc->block.height == 0);
114
115 dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
116 src_row = src;
117
118 format_desc->pack_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
119 }
120
121 boolean util_format_inited;
122
123 void
124 util_format_do_init(void)
125 {
126 util_format_s3tc_init();
127 }