1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 #ifndef SPU_COLORPACK_H
31 #define SPU_COLORPACK_H
34 #include <spu_intrinsics.h>
37 static INLINE
unsigned int
38 spu_pack_R8G8B8A8(vector
float rgba
)
40 vector
unsigned int out
= spu_convtu(rgba
, 32);
42 out
= spu_shuffle(out
, out
, ((vector
unsigned char) {
43 0, 4, 8, 12, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0 }) );
46 return spu_extract(out
, 0);
50 static INLINE
unsigned int
51 spu_pack_A8R8G8B8(vector
float rgba
)
53 vector
unsigned int out
= spu_convtu(rgba
, 32);
54 out
= spu_shuffle(out
, out
, ((vector
unsigned char) {
55 12, 0, 4, 8, 0, 0, 0, 0,
56 0, 0, 0, 0, 0, 0, 0, 0}) );
57 return spu_extract(out
, 0);
61 static INLINE
unsigned int
62 spu_pack_B8G8R8A8(vector
float rgba
)
64 vector
unsigned int out
= spu_convtu(rgba
, 32);
65 out
= spu_shuffle(out
, out
, ((vector
unsigned char) {
66 8, 4, 0, 12, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0}) );
68 return spu_extract(out
, 0);
72 static INLINE
unsigned int
73 spu_pack_color_shuffle(vector
float rgba
, vector
unsigned char shuffle
)
75 vector
unsigned int out
= spu_convtu(rgba
, 32);
76 out
= spu_shuffle(out
, out
, shuffle
);
77 return spu_extract(out
, 0);
81 static INLINE vector
float
82 spu_unpack_color(uint color
)
84 vector
unsigned int color_u4
= spu_splats(color
);
85 color_u4
= spu_shuffle(color_u4
, color_u4
,
86 ((vector
unsigned char) {
91 return spu_convtf(color_u4
, 32);
95 static INLINE vector
float
96 spu_unpack_A8R8G8B8(uint color
)
98 vector
unsigned int color_u4
= spu_splats(color
);
99 color_u4
= spu_shuffle(color_u4
, color_u4
,
100 ((vector
unsigned char) {
106 return spu_convtf(color_u4
, 32);
110 #endif /* SPU_COLORPACK_H */