iPalette.h
Go to the documentation of this file.
00001 /*
00002 imagen - Simple object-oriented imaging library
00003 Copyright (C) 2011-2012 Mark D. Procarione
00004 
00005 imagen is free software: you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation, either
00008 version 3 of the License, or (at your option) any later version.
00009 
00010 imagen is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __IPALETTE_H__
00017 #define __IPALETTE_H__
00018 
00019 #include "imagen.h"
00020 #include "iColor.h"
00021 
00022 namespace imagen
00023 {
00025     class iPalette
00026     {
00027         public:
00029             iPalette();
00030 
00032             iPalette( const iPalette &pal );
00033 
00035 
00037             iPalette( iPalFormat tp, int num = 10 );
00038 
00040 
00041             iPalette( const Iubyte *d, iPalFormat fmt, int num );
00042 
00044 
00046             ~iPalette();
00047 
00049             void clear();
00050 
00052             bool isNull() const;
00053 
00055 
00058             void setData( const Iubyte *d, iPalFormat fmt, int num );
00059 
00061             const Iubyte *getData() const { return data; }
00062 
00064             int length() const { return len; }
00065 
00067             int getBpp() const { return bpp; }
00068 
00070             int depth() const { return bpp << 3; }
00071 
00073             int dataSize() const { return len*bpp; }
00074 
00076             iPalFormat getFormat() const { return format; }
00077 
00079             void addEntry( iColor entry );
00080 
00082 
00083             void delEntry();
00084 
00086             iColor getEntry( int index );
00087 
00089 
00092             void setAllocSize( int size ) { prealloclen = size; }
00093 
00095 
00098             void resize( int size );
00099 
00101             void swapRGB();
00102 
00104 
00107             void convertFormat( iPalFormat fmt, int alpha = 255 );
00108 
00109             iPalette &operator=( const iPalette &pal );
00110 
00111         private:
00112             void init();
00113 
00115             void reallocate( int num );
00116 
00117         private:
00118             Iubyte *data;       
00119             iPalFormat format;  
00120             int bpp;            
00121 
00122             int prealloclen;    
00123             int len;            
00124             int alloc;          
00125     };
00126 }
00127 
00128 #endif // __IPALETTE_H__
00129