00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef SPU_COLORPACK_H
00031 #define SPU_COLORPACK_H
00032
00033
00034 #include <spu_intrinsics.h>
00035
00036
00037 static INLINE unsigned int
00038 spu_pack_R8G8B8A8(vector float rgba)
00039 {
00040 vector unsigned int out = spu_convtu(rgba, 32);
00041
00042 out = spu_shuffle(out, out, ((vector unsigned char) {
00043 0, 4, 8, 12, 0, 0, 0, 0,
00044 0, 0, 0, 0, 0, 0, 0, 0 }) );
00045
00046 return spu_extract(out, 0);
00047 }
00048
00049
00050 static INLINE unsigned int
00051 spu_pack_A8R8G8B8(vector float rgba)
00052 {
00053 vector unsigned int out = spu_convtu(rgba, 32);
00054 out = spu_shuffle(out, out, ((vector unsigned char) {
00055 12, 0, 4, 8, 0, 0, 0, 0,
00056 0, 0, 0, 0, 0, 0, 0, 0}) );
00057 return spu_extract(out, 0);
00058 }
00059
00060
00061 static INLINE unsigned int
00062 spu_pack_B8G8R8A8(vector float rgba)
00063 {
00064 vector unsigned int out = spu_convtu(rgba, 32);
00065 out = spu_shuffle(out, out, ((vector unsigned char) {
00066 8, 4, 0, 12, 0, 0, 0, 0,
00067 0, 0, 0, 0, 0, 0, 0, 0}) );
00068 return spu_extract(out, 0);
00069 }
00070
00071
00072 static INLINE unsigned int
00073 spu_pack_color_shuffle(vector float rgba, vector unsigned char shuffle)
00074 {
00075 vector unsigned int out = spu_convtu(rgba, 32);
00076 out = spu_shuffle(out, out, shuffle);
00077 return spu_extract(out, 0);
00078 }
00079
00080
00081 static INLINE vector float
00082 spu_unpack_B8G8R8A8(uint color)
00083 {
00084 vector unsigned int color_u4 = spu_splats(color);
00085 color_u4 = spu_shuffle(color_u4, color_u4,
00086 ((vector unsigned char) {
00087 10, 10, 10, 10,
00088 5, 5, 5, 5,
00089 0, 0, 0, 0,
00090 15, 15, 15, 15}) );
00091 return spu_convtf(color_u4, 32);
00092 }
00093
00094
00095 static INLINE vector float
00096 spu_unpack_A8R8G8B8(uint color)
00097 {
00098 vector unsigned int color_u4 = spu_splats(color);
00099 color_u4 = spu_shuffle(color_u4, color_u4,
00100 ((vector unsigned char) {
00101 5, 5, 5, 5,
00102 10, 10, 10, 10,
00103 15, 15, 15, 15,
00104 0, 0, 0, 0}) );
00105
00106 return spu_convtf(color_u4, 32);
00107 }
00108
00109
00110 #endif