OpenVideo Documentation

   Main Page       Modules       Class Hierarchy       Alphabetical List       Compound List       File List       Compound Members       Related Pages   

PixelFormat.cxx

Go to the documentation of this file.
00001 /* ========================================================================
00002 * Copyright (C) 2005  Graz University of Technology
00003 *
00004 * This framework is free software; you can redistribute it and/or modify
00005 * it under the terms of the GNU General Public License as published by
00006 * the Free Software Foundation; either version 2 of the License, or
00007 * (at your option) any later version.
00008 *
00009 * This framework 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 framework; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 *
00018 * For further information please contact Denis Kalkofen under
00019 * <kalkofen@icg.tu-graz.ac.at> or write to Denis Kalkofen,
00020 * Graz University of Technology, Inffeldgasse 16a, A8010 Graz,
00021 * Austria.
00022 * ========================================================================
00023 * PROJECT: OpenVideo
00024 * ======================================================================== */
00031 /* ======================================================================= */
00032 
00033 
00034 #include <openvideo/PixelFormat.h>
00035 
00036 #ifdef OV_IS_WINDOWS
00037 #  include <windows.h>
00038 #endif
00039 
00040 #include <GL/gl.h>
00041 #include <map>
00042 
00043 
00044 #ifndef GL_BGR
00045 #  define GL_BGR 0x80E0
00046 #endif
00047 
00048 #ifndef GL_BGRA
00049 #  define GL_BGRA 0x80E1
00050 #endif
00051 
00052 
00053 namespace openvideo 
00054 {
00055 
00056 
00057 typedef std::map<std::string, PIXEL_FORMAT> StringFormatMap;
00058 typedef std::pair<std::string, PIXEL_FORMAT> StringFormatPair;
00059 
00060 
00061 const char* formatNames[] = {
00062         "R8G8B8",
00063         "B8G8R8",
00064         "R8G8B8X8",
00065         "B8G8R8X8",
00066         "R5G6B5",
00067         "L8",
00068         "UNKNOWN"
00069     };
00070 
00071 static StringFormatMap stringFormatMap;
00072 
00073 
00074 static void
00075 fillStringFormatMap()
00076 {
00077     stringFormatMap.clear();
00078 
00079     for(int i=0; i<FORMAT_UNKNOWN; i++)
00080         stringFormatMap.insert( StringFormatPair(formatNames[i], static_cast<PIXEL_FORMAT>(i)) );
00081 }
00082 
00083 
00084 PIXEL_FORMAT
00085 PixelFormat::StringToFormat(const std::string& formatName)
00086 {
00087     if(stringFormatMap.empty())
00088         fillStringFormatMap();
00089 
00090     StringFormatMap::iterator it = stringFormatMap.find(formatName);
00091 
00092     if(it == stringFormatMap.end())
00093         return FORMAT_UNKNOWN;
00094 
00095     return it->second;
00096 }
00097 
00098 
00099 std::string
00100 PixelFormat::FormatToString(PIXEL_FORMAT format)
00101 {
00102     if(format>=0 && format<FORMAT_UNKNOWN)
00103         return formatNames[format];
00104 
00105     return formatNames[FORMAT_UNKNOWN];
00106 }
00107 
00108 
00109 int
00110 PixelFormat::getBitsPerPixel(PIXEL_FORMAT format)
00111 {
00112     switch(format)
00113     {
00114     case FORMAT_R8G8B8X8:
00115     case FORMAT_B8G8R8X8:
00116         return 32;
00117 
00118     case FORMAT_R8G8B8:
00119     case FORMAT_B8G8R8:
00120         return 24;
00121 
00122     case FORMAT_R5G6B5:
00123         return 16;
00124 
00125     case FORMAT_L8:
00126         return 8;
00127 
00128     default:
00129         return 0;
00130     }
00131 }
00132 
00133 
00134 PIXEL_FORMAT
00135 PixelFormat::fromOGL(int format)
00136 {
00137     switch(format)
00138     {
00139     case GL_RGB:
00140         return FORMAT_R8G8B8;
00141     case GL_BGR:
00142         return FORMAT_B8G8R8;
00143     case GL_RGBA:
00144         return FORMAT_R8G8B8X8;
00145     case GL_BGRA:
00146         return FORMAT_B8G8R8X8;
00147     case GL_LUMINANCE:
00148         return FORMAT_L8;
00149     default:
00150         return FORMAT_UNKNOWN;
00151     }
00152 }
00153 
00154 
00155 bool
00156 PixelFormat::toOGL(PIXEL_FORMAT format, unsigned int& oglFormat, int& oglInternalFormat)
00157 {
00158     switch(format)
00159     {
00160     case FORMAT_R8G8B8:
00161         oglFormat=GL_RGB;
00162         oglInternalFormat=3;
00163         return true;
00164 
00165     case FORMAT_B8G8R8:
00166         oglFormat=GL_BGR_EXT;
00167         oglInternalFormat=3;
00168         return true;
00169 
00170     case FORMAT_R8G8B8X8:
00171         oglFormat=GL_RGBA;
00172         oglInternalFormat=4;
00173         return true;
00174 
00175     case FORMAT_B8G8R8X8:
00176         oglFormat=GL_BGRA_EXT;
00177         oglInternalFormat=4;
00178         return true;
00179 
00180     case FORMAT_L8:
00181         oglFormat=GL_LUMINANCE;
00182         oglInternalFormat=GL_LUMINANCE8;
00183         return true;
00184     }
00185 
00186     return false;
00187 }
00188 
00189 
00190 }  // namespace openvideo
 This page was generated at Wed May 31 13:04:16 2006 for OpenVideo by Doxygen.
 If you have any comments, please send a message to schmalstieg@icg.tu-graz.ac.at.
www.studierstube.org