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>
|
2010-03-28 15:15:32 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-06-15 01:53:30 +00:00
|
|
|
class SortPalette
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Channel {
|
|
|
|
RGB_Red,
|
|
|
|
RGB_Green,
|
|
|
|
RGB_Blue,
|
|
|
|
HSV_Hue,
|
|
|
|
HSV_Saturation,
|
|
|
|
HSV_Value,
|
|
|
|
};
|
|
|
|
|
|
|
|
SortPalette(Channel channel, bool ascending);
|
|
|
|
~SortPalette();
|
|
|
|
|
|
|
|
void addChain(SortPalette* chain);
|
|
|
|
|
|
|
|
bool operator()(ase_uint32 c1, ase_uint32 c2);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Channel m_channel;
|
|
|
|
bool m_ascending;
|
|
|
|
SortPalette* m_chain;
|
|
|
|
};
|
|
|
|
|
2008-10-01 01:27:51 +00:00
|
|
|
class Palette : public GfxObj
|
2008-03-22 21:44:03 +00:00
|
|
|
{
|
2008-10-01 01:27:51 +00:00
|
|
|
public:
|
2010-03-28 15:15:32 +00:00
|
|
|
Palette(int frame, size_t ncolors);
|
2008-10-01 01:27:51 +00:00
|
|
|
Palette(const Palette& palette);
|
2010-03-28 15:15:32 +00:00
|
|
|
~Palette();
|
|
|
|
|
|
|
|
static Palette* createGrayscale();
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +00:00
|
|
|
size_t size() const { return m_colors.size(); }
|
|
|
|
void resize(size_t ncolors);
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-04-20 01:43:41 +00:00
|
|
|
size_t getModifications() const { return m_modifications; }
|
|
|
|
|
2010-03-28 15:15:32 +00:00
|
|
|
int getFrame() const { return m_frame; }
|
|
|
|
void setFrame(int frame);
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +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
|
|
|
|
2010-03-28 15:15:32 +00:00
|
|
|
void setEntry(size_t i, ase_uint32 color);
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +00:00
|
|
|
void copyColorsTo(Palette* dst) const;
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +00:00
|
|
|
int countDiff(const Palette* other, int* from, int* to) const;
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +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);
|
2010-06-15 01:53:30 +00:00
|
|
|
void sort(int from, int to, SortPalette* sort_palette);
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +00:00
|
|
|
void toAllegro(RGB* rgb) const;
|
|
|
|
void fromAllegro(const RGB* rgb);
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2010-03-28 15:15:32 +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;
|
2010-04-20 01:43:41 +00:00
|
|
|
size_t m_modifications;
|
2010-03-28 15:15:32 +00:00
|
|
|
};
|
2008-03-22 21:44:03 +00:00
|
|
|
|
2009-08-17 21:38:00 +00:00
|
|
|
#endif
|