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 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 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.
26 **************************************************************************/
30 * Pixel format accessor functions.
32 * @author Jose Fonseca <jfonseca@vmware.com>
39 util_format_read_4f(enum pipe_format format
,
40 float *dst
, unsigned dst_stride
,
41 const void *src
, unsigned src_stride
,
42 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
44 const struct util_format_description
*format_desc
;
45 const uint8_t *src_row
;
48 format_desc
= util_format_description(format
);
50 assert(x
% format_desc
->block
.width
== 0);
51 assert(y
% format_desc
->block
.height
== 0);
53 src_row
= (const uint8_t *)src
+ y
*src_stride
+ x
*(format_desc
->block
.bits
/8);
56 format_desc
->unpack_float(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
61 util_format_write_4f(enum pipe_format format
,
62 const float *src
, unsigned src_stride
,
63 void *dst
, unsigned dst_stride
,
64 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
66 const struct util_format_description
*format_desc
;
70 format_desc
= util_format_description(format
);
72 assert(x
% format_desc
->block
.width
== 0);
73 assert(y
% format_desc
->block
.height
== 0);
75 dst_row
= (uint8_t *)dst
+ y
*dst_stride
+ x
*(format_desc
->block
.bits
/8);
78 format_desc
->pack_float(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
83 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
)
85 const struct util_format_description
*format_desc
;
86 const uint8_t *src_row
;
89 format_desc
= util_format_description(format
);
91 assert(x
% format_desc
->block
.width
== 0);
92 assert(y
% format_desc
->block
.height
== 0);
94 src_row
= (const uint8_t *)src
+ y
*src_stride
+ x
*(format_desc
->block
.bits
/8);
97 format_desc
->unpack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
102 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
)
104 const struct util_format_description
*format_desc
;
106 const uint8_t *src_row
;
108 format_desc
= util_format_description(format
);
110 assert(x
% format_desc
->block
.width
== 0);
111 assert(y
% format_desc
->block
.height
== 0);
113 dst_row
= (uint8_t *)dst
+ y
*dst_stride
+ x
*(format_desc
->block
.bits
/8);
116 format_desc
->pack_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);