aseprite/src/raster/palette.h

109 lines
2.6 KiB
C
Raw Normal View History

/* ASEPRITE
2012-01-06 03:52:11 +00:00
* Copyright (C) 2001-2012 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
2012-07-09 00:09:09 +00:00
#include "raster/frame_number.h"
2008-03-22 21:44:03 +00:00
#include "raster/gfxobj.h"
2012-07-09 00:09:09 +00:00
2008-03-22 21:44:03 +00:00
#include <allegro/color.h>
#include <vector>
2008-03-22 21:44:03 +00:00
class SortPalette
{
public:
enum Channel {
RGB_Red,
RGB_Green,
RGB_Blue,
HSV_Hue,
HSV_Saturation,
HSV_Value,
HSL_Lightness,
YUV_Luma,
};
SortPalette(Channel channel, bool ascending);
~SortPalette();
void addChain(SortPalette* chain);
2011-03-24 21:36:19 +00:00
bool operator()(uint32_t c1, uint32_t c2);
private:
Channel m_channel;
bool m_ascending;
SortPalette* m_chain;
};
class Palette : public GfxObj
2008-03-22 21:44:03 +00:00
{
public:
2012-03-21 22:22:11 +00:00
enum { MaxColors = 256 };
2012-07-09 00:09:09 +00:00
Palette(FrameNumber frame, int ncolors);
Palette(const Palette& palette);
~Palette();
static Palette* createGrayscale();
2008-03-22 21:44:03 +00:00
int size() const { return m_colors.size(); }
void resize(int ncolors);
2008-03-22 21:44:03 +00:00
int getModifications() const { return m_modifications; }
2010-04-20 01:43:41 +00:00
2012-07-09 00:09:09 +00:00
FrameNumber getFrame() const { return m_frame; }
void setFrame(FrameNumber frame);
2008-03-22 21:44:03 +00:00
2011-03-24 21:36:19 +00:00
uint32_t getEntry(int i) const {
ASSERT(i >= 0 && i < size());
return m_colors[i];
}
2008-03-22 21:44:03 +00:00
2011-03-24 21:36:19 +00:00
void setEntry(int i, uint32_t 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
// Returns true if the palette is completelly black.
bool isBlack() const;
void makeBlack();
void makeHorzRamp(int from, int to);
void makeVertRamp(int from, int to, int columns);
void makeRectRamp(int from, int to, int columns);
void sort(int from, int to, SortPalette* sort_palette, std::vector<int>& mapping);
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:
2012-07-09 00:09:09 +00:00
FrameNumber m_frame;
2011-03-24 21:36:19 +00:00
std::vector<uint32_t> m_colors;
int m_modifications;
};
2008-03-22 21:44:03 +00:00
2009-08-17 21:38:00 +00:00
#endif