Guest User

ColorIndexMap.h

a guest
Dec 7th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "ByteMap.h"
  4. #include "ColorPalette256.h"
  5.  
  6. class ColorIndexMap : public ByteMap, public Mipmapable<ColorIndexMap>
  7. {
  8. public:
  9.     ColorIndexMap::ColorIndexMap(int width, int height) : ByteMap(width, height) {
  10.     }
  11.  
  12.     ColorIndexMap::ColorIndexMap(int width, int height, ColorPalette256 & palette) : ByteMap(width, height) {
  13.         setColorPalette(palette);
  14.     }
  15.  
  16.     ColorIndexMap::~ColorIndexMap(void) {
  17.     }
  18.  
  19.     void setColorPalette(ColorPalette256 & palette) {
  20.         for (int i = 0; i < 256; i++) {
  21.             mapPalette.setPaletteColor(i, palette.getPaletteColor(i));
  22.         }
  23.     }
  24.  
  25.     ColorPalette256* getColorPalette() {
  26.         return &mapPalette;
  27.     }
  28.  
  29.     Color getColorAt(int x, int y) {
  30.         return mapPalette.getPaletteColor(getByte(x, y));
  31.     }
  32.    
  33.     ColorIndexMap* makeMipMap(void) {
  34.         int width = getWidth() / 2;
  35.         int height = getHeight() / 2;
  36.         ColorIndexMap* mipMap = new ColorIndexMap(width, height);
  37.         for (int x = 0; x < width; x++) {
  38.             for (int y = 0; y < height; y++) {
  39.                 mipMap->setByte(x, y, getByte(2 * x, 2 * y));
  40.             }
  41.         }
  42.         return mipMap;
  43.     }
  44.  
  45. private:
  46.     ColorPalette256 mapPalette;
  47. };
Advertisement
Add Comment
Please, Sign In to add comment