aseprite/src/raster/palette.h

72 lines
1.9 KiB
C
Raw Normal View History

2008-03-22 21:44:03 +00:00
/* ASE - Allegro Sprite Editor
2010-02-01 21:25:40 +00:00
* Copyright (C) 2001-2010 David Capello
2008-03-22 21:44:03 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2009-08-17 21:38:00 +00:00
#ifndef RASTER_PALETTE_H_INCLUDED
#define RASTER_PALETTE_H_INCLUDED
2008-03-22 21:44:03 +00:00
#include "raster/gfxobj.h"
#include <allegro/color.h>
#include <vector>
#include <cassert>
2008-03-22 21:44:03 +00:00
class Palette : public GfxObj
2008-03-22 21:44:03 +00:00
{
public:
Palette(int frame, size_t ncolors);
Palette(const Palette& palette);
~Palette();
static Palette* createGrayscale();
2008-03-22 21:44:03 +00:00
size_t size() const { return m_colors.size(); }
void resize(size_t ncolors);
2008-03-22 21:44:03 +00:00
int getFrame() const { return m_frame; }
void setFrame(int frame);
2008-03-22 21:44:03 +00:00
ase_uint32 getEntry(size_t i) const {
assert(i >= 0 && i < size());
return m_colors[i];
}
2008-03-22 21:44:03 +00:00
void setEntry(size_t i, ase_uint32 color);
2008-03-22 21:44:03 +00:00
void copyColorsTo(Palette* dst) const;
2008-03-22 21:44:03 +00:00
int countDiff(const Palette* other, int* from, int* to) const;
2008-03-22 21:44:03 +00:00
void makeBlack();
void makeHorzRamp(int from, int to);
void makeVertRamp(int from, int to, int columns);
void makeRectRamp(int from, int to, int columns);
2008-03-22 21:44:03 +00:00
void toAllegro(RGB* rgb) const;
void fromAllegro(const RGB* rgb);
2008-03-22 21:44:03 +00:00
static Palette* load(const char *filename);
bool save(const char *filename) const;
int findBestfit(int r, int g, int b) const;
private:
int m_frame;
std::vector<ase_uint32> m_colors;
};
2008-03-22 21:44:03 +00:00
2009-08-17 21:38:00 +00:00
#endif