From 9a95a40e926044368663e387f4a662335cb6d155 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 20 Apr 2010 23:32:44 -0300 Subject: [PATCH] Added RgbMap class (this class will replace rgb_map Allegro usage). --- makefile.lst | 1 + src/raster/gfxobj.h | 1 + src/raster/raster.h | 1 + src/raster/rgbmap.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++ src/raster/rgbmap.h | 43 ++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 src/raster/rgbmap.cpp create mode 100644 src/raster/rgbmap.h diff --git a/makefile.lst b/makefile.lst index ac3fd3512..54476fa2b 100644 --- a/makefile.lst +++ b/makefile.lst @@ -179,6 +179,7 @@ COMMON_SOURCES = \ src/raster/palette.cpp \ src/raster/path.cpp \ src/raster/quant.cpp \ + src/raster/rgbmap.cpp \ src/raster/rotate.cpp \ src/raster/sprite.cpp \ src/raster/stock.cpp \ diff --git a/src/raster/gfxobj.h b/src/raster/gfxobj.h index 39ad81ddb..8c058f3bd 100644 --- a/src/raster/gfxobj.h +++ b/src/raster/gfxobj.h @@ -33,6 +33,7 @@ enum { GFXOBJ_SPRITE, GFXOBJ_STOCK, GFXOBJ_UNDO, + GFXOBJ_RGBMAP, }; typedef unsigned int gfxobj_id; diff --git a/src/raster/raster.h b/src/raster/raster.h index 33b284234..73b48a1c5 100644 --- a/src/raster/raster.h +++ b/src/raster/raster.h @@ -31,6 +31,7 @@ #include "raster/path.h" #include "raster/pen.h" #include "raster/quant.h" +#include "raster/rgbmap.h" #include "raster/rotate.h" #include "raster/sprite.h" #include "raster/stock.h" diff --git a/src/raster/rgbmap.cpp b/src/raster/rgbmap.cpp new file mode 100644 index 000000000..3fac48775 --- /dev/null +++ b/src/raster/rgbmap.cpp @@ -0,0 +1,94 @@ +/* ASE - Allegro Sprite Editor + * Copyright (C) 2001-2010 David Capello + * + * 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 + */ + +#include "config.h" + +#include +#include + +#include "raster/palette.h" +#include "raster/rgbmap.h" + +class RgbMapImpl +{ +public: + RgbMapImpl() { + m_allegMap = new RGB_MAP; + m_palette_id = 0; + m_modifications = 0; + } + + ~RgbMapImpl() { + delete m_allegMap; + } + + bool match(const Palette* palette) const { + return (m_palette_id == palette->id && + m_modifications == palette->getModifications()); + } + + void regenerate(const Palette* palette) { + m_palette_id = palette->id; + m_modifications = palette->getModifications(); + + PALETTE allegPal; + palette->toAllegro(allegPal); + create_rgb_table(m_allegMap, allegPal, NULL); + } + + int mapColor(int r, int g, int b) const { + assert(r >= 0 && r < 256); + assert(g >= 0 && g < 256); + assert(b >= 0 && b < 256); + return m_allegMap->data[r>>3][g>>3][b>>3]; + } + +private: + RGB_MAP* m_allegMap; + gfxobj_id m_palette_id; + size_t m_modifications; +}; + +////////////////////////////////////////////////////////////////////// +// RgbMap + +RgbMap::RgbMap() + : GfxObj(GFXOBJ_RGBMAP) +{ + m_impl = new RgbMapImpl; +} + +RgbMap::~RgbMap() +{ + delete m_impl; +} + +bool RgbMap::match(const Palette* palette) const +{ + return m_impl->match(palette); +} + +void RgbMap::regenerate(const Palette* palette) +{ + m_impl->regenerate(palette); +} + +int RgbMap::mapColor(int r, int g, int b) const +{ + return m_impl->mapColor(r, g, b); +} diff --git a/src/raster/rgbmap.h b/src/raster/rgbmap.h new file mode 100644 index 000000000..370f0ea40 --- /dev/null +++ b/src/raster/rgbmap.h @@ -0,0 +1,43 @@ +/* ASE - Allegro Sprite Editor + * Copyright (C) 2001-2010 David Capello + * + * 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 + */ + +#ifndef RASTER_RGBMAP_H_INCLUDED +#define RASTER_RGBMAP_H_INCLUDED + +#include "Vaca/NonCopyable.h" +#include "raster/gfxobj.h" + +class Palette; + +class RgbMap : public GfxObj + , Vaca::NonCopyable +{ +public: + RgbMap(); + virtual ~RgbMap(); + + bool match(const Palette* palette) const; + void regenerate(const Palette* palette); + + int mapColor(int r, int g, int b) const; + +private: + class RgbMapImpl* m_impl; +}; + +#endif