Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/pixmap/format.cc

Go to the documentation of this file.
00001 /*
00002  * lib/pixmap/format.cc
00003  * 
00004  * Image format description class (channels, bits). 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #include "format.h"
00018 
00019 
00021 static const PixmapFormat::FMT commons[PixmapFormat::_LASTID]=
00022 {
00024     {  PixmapFormat::Gray, {1}  },
00026     {  PixmapFormat::Gray, {8}  },
00028     {  PixmapFormat::Gray, {16}  },
00030     {  PixmapFormat::GrayA, {8,8}  },
00032     {  PixmapFormat::GrayA, {16,16}  },
00034     {  PixmapFormat::RGB, {8,8,8}  },
00036     {  PixmapFormat::RGB, {16,16,16}  },
00038     {  PixmapFormat::RGBA, {8,8,8,8}  },
00040     {  PixmapFormat::RGBA, {16,16,16,16}  },
00042     {  PixmapFormat::RGB, {5,5,5}  },
00044     {  PixmapFormat::RGB, {5,6,5}  },
00046     {  PixmapFormat::RGBFT, 
00047         { PixmapFormat::FloatBits,PixmapFormat::FloatBits,
00048           PixmapFormat::FloatBits,PixmapFormat::FloatBits, 
00049           PixmapFormat::FloatBits }  },
00050 };
00051 
00053 const short int PixmapFormat::_nchannels[_LASTF]=
00054 {
00055     0,   
00056     1,   
00057     2,   
00058     3,   
00059     4,   
00060     5,   // /<RGBFT
00061 };
00062 
00063 
00064 signed char PixmapFormat::SameBitsForAll() const
00065 {
00066     short int nchan=nchannels();
00067     if(!nchan)  return(0);
00068     signed char b=bits(0);
00069     for(short int i=1; i<nchan; i++)
00070         if(b!=bits(i))  return(0);
00071     return(b);
00072 }
00073 
00074 
00075 void PixmapFormat::_set(CommonID cid)
00076 {
00077     Assert(cid>=0 && cid<_LASTID);
00078     f=commons[cid];
00079 }
00080 
00081 
00082 void PixmapFormat::_set(Format fmt,const signed char *bits)
00083 {
00084     Assert(fmt>=0 && fmt<_LASTF);
00085     f.format=fmt;
00086     for(int i=0,e=_nchannels[fmt]; i<e; i++)
00087     {  f.bits[i]=bits[i];  }
00088 }
00089 
00090 
00091 bool PixmapFormat::operator==(const PixmapFormat &pf) const
00092 {
00093     if(f.format!=pf.f.format)  return(0);
00094     short int e=nchannels();
00095     if(e!=pf.nchannels())  return(0);
00096     for(short int i=0; i<e; i++)
00097         if(bits(i)!=pf.bits(i))  return(0);
00098     return(1);
00099 }

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5