Manips.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2005 The Pentagram Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef MANIPS_H_INCLUDED
00020 #define MANIPS_H_INCLUDED
00021 
00022 #include "RenderSurface.h"
00023 #include "Texture.h"
00024 
00025 template<class uintX> class Manip_Nat2Nat
00026 {
00027 public:
00028         static bool are_same() { return true; }
00029         static uintX copy (uintX src) { return src; }
00030         static void split(uintX src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00031                 UNPACK_RGBA8(src, r, g, b, a);
00032         }
00033         static uintX merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00034                 return PACK_RGBA8(r, g, b, a);
00035         }
00036         static uint16 to16bit(uintX src) { 
00037                 uint8 r,g,b;
00038                 UNPACK_RGB(src,r,g,b);
00039                 return (r>>3)|((g&0xFC)<<3)|((b&0xF8)<<8);
00040         }
00041 };
00042 
00043 class Manip_Nat2Nat_16
00044 {
00045 public:
00046         static bool are_same() { return true; }
00047         static uint16 copy (uint16 src) { return src; }
00048         static void split(uint16 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00049                 UNPACK_RGBA8(src, r, g, b, a);
00050         }
00051         static uint16 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00052                 return PACK_RGBA8(r, g, b, a);
00053         }
00054         static uint16 to16bit(uint16 src) { 
00055                 return src;
00056         }
00057 };
00058 
00059 class Manip_Nat2Nat_32
00060 {
00061 public:
00062         static bool are_same() { return true; }
00063         static uint32 copy (uint32 src) { return src; }
00064         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00065                 UNPACK_RGBA8(src, r, g, b, a);
00066         }
00067         static uint32 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00068                 return PACK_RGBA8(r, g, b, a);
00069         }
00070         static uint16 to16bit(uint32 src) { 
00071                 uint8 r,g,b;
00072                 UNPACK_RGB8(src,r,g,b);
00073                 return (r>>3)|((g&0xFC)<<3)|((b&0xF8)<<8);
00074         }
00075 };
00076 
00077 template<class uintX> class Manip_Sta2Nat
00078 {
00079 public:
00080         static bool are_same() { return false; }
00081         static uintX copy (uint32 src) { 
00082                 return static_cast<uintX>(PACK_RGBA8( TEX32_R(src), TEX32_G(src), TEX32_B(src), TEX32_A(src) ));
00083         }
00084         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00085                 r = TEX32_R(src);
00086                 g = TEX32_G(src);
00087                 b = TEX32_B(src);
00088                 a = TEX32_A(src);
00089         }
00090         static uintX merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00091                 return PACK_RGBA8(r, g, b, a);
00092         }
00093         static uint16 to16bit(uint32 src) { 
00094                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00095         }
00096 };
00097 
00098 class Manip_Sta2Nat_16
00099 {
00100 public:
00101         static bool are_same() { return false; }
00102         static uint16 copy (uint32 src) { 
00103                 return PACK_RGBA8( TEX32_R(src), TEX32_G(src), TEX32_B(src), TEX32_A(src) );
00104         }
00105         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00106                 r = TEX32_R(src);
00107                 g = TEX32_G(src);
00108                 b = TEX32_B(src);
00109                 a = TEX32_A(src);
00110         }
00111         static uint16 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00112                 return PACK_RGBA8(r, g, b, a);
00113         }
00114         static uint16 to16bit(uint32 src) { 
00115                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00116         }
00117 };
00118 
00119 class Manip_Sta2Nat_32
00120 {
00121 public:
00122         static bool are_same() { return false; }
00123         static uint32 copy (uint32 src) { 
00124                 return PACK_RGBA8( TEX32_R(src), TEX32_G(src), TEX32_B(src), TEX32_A(src) );
00125         }
00126         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00127                 r = TEX32_R(src);
00128                 g = TEX32_G(src);
00129                 b = TEX32_B(src);
00130                 a = TEX32_A(src);
00131         }
00132         static uint32 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00133                 return PACK_RGBA8(r, g, b, a);
00134         }
00135         static uint16 to16bit(uint32 src) { 
00136                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00137         }
00138 };
00139 
00140 // Assumption, ABGR (but doesn't matter)
00141 class Manip_32_A888
00142 {
00143 public:
00144         static bool are_same() { return true; }
00145         static uint32 copy (uint32 src) { return src; }
00146         static void split(uint32 src, uint8 &c0, uint8 &c1, uint8 &c2, uint8 &a) {
00147                 c0 = src; c1 = src>>8; c2 = src>>16; a = src>>24;
00148         }
00149         static uint32 merge(uint8 c0, uint8 c1, uint8 c2, uint8 a) {
00150                 return c0|(c1<<8)|(c2<<16)|(a<<24);
00151         }
00152         static uint16 to16bit(uint32 src) { 
00153                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00154         }
00155 };
00156 
00157 // Assumption, RGBA (but doesn't matter)
00158 class Manip_32_888A
00159 {
00160 public:
00161         static bool are_same() { return true; }
00162         static uint32 copy (uint32 src) { return src; }
00163         static void split(uint32 src, uint8 &c0, uint8 &c1, uint8 &c2, uint8 &a) {
00164                 a = src; c2 = src>>8; c1 = src>>16; c0 = src>>24;
00165         }
00166         static uint32 merge(uint8 c0, uint8 c1, uint8 c2, uint8 a) {
00167                 return a|(c2<<8)|(c1<<16)|(c0<<24);
00168         }
00169         static uint16 to16bit(uint32 src) { 
00170                 return (src>>27)|((src>>13)&0x7E0)|((src<<8)&0xF800);
00171         }
00172 };
00173 
00174 //
00175 // Gamma Corrected Manips
00176 //
00177 
00178 
00179 class Manip_Nat2Nat_16_GC
00180 {
00181 public:
00182         static bool are_same() { return true; }
00183         static uint16 copy (uint16 src) { return src; }
00184         static void split(uint16 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00185                 UNPACK_RGBA8(src, r, g, b, a);
00186                 r = RenderSurface::Gamma22toGamma10[r];
00187                 g = RenderSurface::Gamma22toGamma10[g];
00188                 b = RenderSurface::Gamma22toGamma10[b];
00189         }
00190         static uint16 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00191                 return PACK_RGBA8(RenderSurface::Gamma10toGamma22[r], RenderSurface::Gamma10toGamma22[g], RenderSurface::Gamma10toGamma22[b], a);
00192         }
00193         static uint16 to16bit(uint16 src) { 
00194                 return src;
00195         }
00196 };
00197 
00198 class Manip_Nat2Nat_32_GC
00199 {
00200 public:
00201         static bool are_same() { return true; }
00202         static uint32 copy (uint32 src) { return src; }
00203         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00204                 UNPACK_RGBA8(src, r, g, b, a);
00205                 r = RenderSurface::Gamma22toGamma10[r];
00206                 g = RenderSurface::Gamma22toGamma10[g];
00207                 b = RenderSurface::Gamma22toGamma10[b];
00208         }
00209         static uint32 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00210                 return PACK_RGBA8(RenderSurface::Gamma10toGamma22[r], RenderSurface::Gamma10toGamma22[g], RenderSurface::Gamma10toGamma22[b], a);
00211         }
00212         static uint16 to16bit(uint32 src) { 
00213                 uint8 r,g,b;
00214                 UNPACK_RGB8(src,r,g,b);
00215                 return (r>>3)|((g&0xFC)<<3)|((b&0xF8)<<8);
00216         }
00217 };
00218 
00219 class Manip_Sta2Nat_16_GC
00220 {
00221 public:
00222         static bool are_same() { return false; }
00223         static uint16 copy (uint32 src) { 
00224                 return PACK_RGBA8( TEX32_R(src), TEX32_G(src), TEX32_B(src), TEX32_A(src) );
00225         }
00226         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00227                 r = RenderSurface::Gamma22toGamma10[TEX32_R(src)];
00228                 g = RenderSurface::Gamma22toGamma10[TEX32_G(src)];
00229                 b = RenderSurface::Gamma22toGamma10[TEX32_B(src)];
00230                 a = TEX32_A(src);
00231         }
00232         static uint16 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00233                 return PACK_RGBA8(RenderSurface::Gamma10toGamma22[r], RenderSurface::Gamma10toGamma22[g], RenderSurface::Gamma10toGamma22[b], a);
00234         }
00235         static uint16 to16bit(uint32 src) { 
00236                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00237         }
00238 };
00239 
00240 class Manip_Sta2Nat_32_GC
00241 {
00242 public:
00243         static bool are_same() { return false; }
00244         static uint32 copy (uint32 src) { 
00245                 return PACK_RGBA8( TEX32_R(src), TEX32_G(src), TEX32_B(src), TEX32_A(src) );
00246         }
00247         static void split(uint32 src, uint8 &r, uint8 &g, uint8 &b, uint8 &a) {
00248                 r = RenderSurface::Gamma22toGamma10[TEX32_R(src)];
00249                 g = RenderSurface::Gamma22toGamma10[TEX32_G(src)];
00250                 b = RenderSurface::Gamma22toGamma10[TEX32_B(src)];
00251                 a = TEX32_A(src);
00252         }
00253         static uint32 merge(uint8 r, uint8 g, uint8 b, uint8 a) {
00254                 return PACK_RGBA8(RenderSurface::Gamma10toGamma22[r], RenderSurface::Gamma10toGamma22[g], RenderSurface::Gamma10toGamma22[b], a);
00255         }
00256         static uint16 to16bit(uint32 src) { 
00257                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00258         }
00259 };
00260 
00261 // Assumption, ABGR (but doesn't matter)
00262 class Manip_32_A888_GC
00263 {
00264 public:
00265         static bool are_same() { return true; }
00266         static uint32 copy (uint32 src) { return src; }
00267         static void split(uint32 src, uint8 &c0, uint8 &c1, uint8 &c2, uint8 &a) {
00268                 c0 = RenderSurface::Gamma22toGamma10[(src)&0xFF]; 
00269                 c1 = RenderSurface::Gamma22toGamma10[(src>>8)&0xFF];
00270                 c2 = RenderSurface::Gamma22toGamma10[(src>>16)&0xFF];
00271                 a = src>>24;
00272         }
00273         static uint32 merge(uint8 c0, uint8 c1, uint8 c2, uint8 a) {
00274                 return RenderSurface::Gamma10toGamma22[c0]|(RenderSurface::Gamma10toGamma22[c1]<<8)|(RenderSurface::Gamma10toGamma22[c2]<<16)|(a<<24);
00275         }
00276         static uint16 to16bit(uint32 src) { 
00277                 return (src>>3)|((src>>5)&0x7E0)|((src>>8)&0xF800);
00278         }
00279 };
00280 
00281 // Assumption, RGBA (but doesn't matter)
00282 class Manip_32_888A_GC
00283 {
00284 public:
00285         static bool are_same() { return true; }
00286         static uint32 copy (uint32 src) { return src; }
00287         static void split(uint32 src, uint8 &c0, uint8 &c1, uint8 &c2, uint8 &a) {
00288                 a = src; 
00289                 c2 = RenderSurface::Gamma22toGamma10[(src>>8)&0xFF]; 
00290                 c1 = RenderSurface::Gamma22toGamma10[(src>>16)&0xFF]; 
00291                 c0 = RenderSurface::Gamma22toGamma10[(src>>24)&0xFF];
00292         }
00293         static uint32 merge(uint8 c0, uint8 c1, uint8 c2, uint8 a) {
00294                 return a|(RenderSurface::Gamma10toGamma22[c2]<<8)|(RenderSurface::Gamma10toGamma22[c1]<<16)|(RenderSurface::Gamma10toGamma22[c0]<<24);
00295         }
00296         static uint16 to16bit(uint32 src) { 
00297                 return (src>>27)|((src>>13)&0x7E0)|((src<<8)&0xF800);
00298         }
00299 };
00300 
00301 
00302 #endif //MANIPS_H_INCLUDED

Generated on Fri Jul 27 22:27:25 2007 for pentagram by  doxygen 1.4.7