spu_colorpack.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 /* SPU_COLORPACK_H */

Generated on Tue Sep 29 06:25:16 2009 for Gallium3D by  doxygen 1.5.4