Convert color_t type to Color class.

+ Add color_utils namespace and move useful routines for colors right there.
+ Add test_color.cpp.
This commit is contained in:
David Capello 2010-08-25 00:26:37 -03:00
parent 733ee5b705
commit 3f9e947ea9
62 changed files with 1451 additions and 1315 deletions

View File

@ -96,7 +96,7 @@ $(VACA_LIB): $(VACA_OBJS)
# Rules to build objects and the application # Rules to build objects and the application
VPATH = src \ VPATH = src \
src/ase \ src/app \
src/commands \ src/commands \
src/commands/fx \ src/commands/fx \
src/console \ src/console \

View File

@ -19,6 +19,8 @@ COMMON_SOURCES = \
src/ui_context.cpp \ src/ui_context.cpp \
src/undoable.cpp \ src/undoable.cpp \
src/xml_widgets.cpp \ src/xml_widgets.cpp \
src/app/color.cpp \
src/app/color_utils.cpp \
src/commands/cmd_about.cpp \ src/commands/cmd_about.cpp \
src/commands/cmd_advanced_mode.cpp \ src/commands/cmd_advanced_mode.cpp \
src/commands/cmd_background_from_layer.cpp \ src/commands/cmd_background_from_layer.cpp \
@ -93,7 +95,6 @@ COMMON_SOURCES = \
src/commands/fx/cmd_replace_color.cpp \ src/commands/fx/cmd_replace_color.cpp \
src/commands/fx/effectbg.cpp \ src/commands/fx/effectbg.cpp \
src/core/cfg.cpp \ src/core/cfg.cpp \
src/core/color.cpp \
src/core/config.cpp \ src/core/config.cpp \
src/core/core.cpp \ src/core/core.cpp \
src/core/drop_files.cpp \ src/core/drop_files.cpp \

View File

@ -146,7 +146,7 @@ $(VACA_LIB): $(VACA_OBJS)
# Rules to build objects and the application # Rules to build objects and the application
VPATH = src \ VPATH = src \
src/ase \ src/app \
src/commands \ src/commands \
src/commands/fx \ src/commands/fx \
src/console \ src/console \

View File

@ -41,6 +41,8 @@ add_executable(aseprite WIN32
ui_context.cpp ui_context.cpp
undoable.cpp undoable.cpp
xml_widgets.cpp xml_widgets.cpp
app/color.cpp
app/color_utils.cpp
commands/cmd_about.cpp commands/cmd_about.cpp
commands/cmd_advanced_mode.cpp commands/cmd_advanced_mode.cpp
commands/cmd_background_from_layer.cpp commands/cmd_background_from_layer.cpp
@ -115,7 +117,6 @@ add_executable(aseprite WIN32
commands/fx/cmd_replace_color.cpp commands/fx/cmd_replace_color.cpp
commands/fx/effectbg.cpp commands/fx/effectbg.cpp
core/cfg.cpp core/cfg.cpp
core/color.cpp
core/config.cpp core/config.cpp
core/core.cpp core/core.cpp
core/drop_files.cpp core/drop_files.cpp

View File

@ -33,6 +33,7 @@
#include "Vaca/String.h" #include "Vaca/String.h"
#include "app.h" #include "app.h"
#include "app/color_utils.h"
#include "ase_exception.h" #include "ase_exception.h"
#include "check_args.h" #include "check_args.h"
#include "commands/commands.h" #include "commands/commands.h"
@ -450,16 +451,16 @@ void app_default_statusbar_message()
->setStatusText(250, "%s %s | %s", PACKAGE, VERSION, COPYRIGHT); ->setStatusText(250, "%s %s | %s", PACKAGE, VERSION, COPYRIGHT);
} }
int app_get_color_to_clear_layer(Layer *layer) int app_get_color_to_clear_layer(Layer* layer)
{ {
/* all transparent layers are cleared with the mask color */ /* all transparent layers are cleared with the mask color */
color_t color = color_mask(); Color color = Color::fromMask();
/* the `Background' is erased with the `Background Color' */ /* the `Background' is erased with the `Background Color' */
if (layer != NULL && layer->is_background()) if (layer != NULL && layer->is_background())
color = colorbar->getBgColor(); color = colorbar->getBgColor();
return get_color_for_layer(layer, color); return color_utils::color_for_layer(color, layer);
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

594
src/app/color.cpp Normal file
View File

@ -0,0 +1,594 @@
/* 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 <string>
#include <cstdlib>
#include <sstream>
#include <iomanip>
#include "Vaca/String.h"
#include "app/color.h"
#include "app/color_utils.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "modules/palettes.h"
#define MAKE_DATA(c1,c2,c3) ((c3) << 16) | ((c2) << 8) | (c1)
#define GET_DATA_C1(c) (((c) >> 0) & 0xff)
#define GET_DATA_C2(c) (((c) >> 8) & 0xff)
#define GET_DATA_C3(c) (((c) >> 16) & 0xff)
// static
Color Color::fromMask()
{
return Color(Color::MaskType, 0);
}
// static
Color Color::fromRgb(int r, int g, int b)
{
return Color(Color::RgbType, MAKE_DATA(r & 0xff, g & 0xff, b & 0xff));
}
// static
Color Color::fromHsv(int h, int s, int v)
{
return Color(Color::HsvType, MAKE_DATA(h & 0xff, s & 0xff, v & 0xff));
}
// static
Color Color::fromGray(int g)
{
return Color(Color::GrayType, g & 0xff);
}
// static
Color Color::fromIndex(int index)
{
return Color(Color::IndexType, index & 0xff);
}
// static
Color Color::fromImage(int imgtype, int c)
{
Color color = Color::fromMask();
switch (imgtype) {
case IMAGE_RGB:
if (_rgba_geta(c) > 0) {
color = Color::fromRgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c));
}
break;
case IMAGE_GRAYSCALE:
if (_graya_geta(c) > 0) {
color = Color::fromGray(_graya_getv(c));
}
break;
case IMAGE_INDEXED:
color = Color::fromIndex(c);
break;
}
return color;
}
// static
Color Color::fromImageGetPixel(Image *image, int x, int y)
{
if ((x >= 0) && (y >= 0) && (x < image->w) && (y < image->h))
return Color::fromImage(image->imgtype, image_getpixel(image, x, y));
else
return Color::fromMask();
}
// static
Color Color::fromString(const std::string& str)
{
Color color = Color::fromMask();
if (str != "mask") {
if (str.find("rgb{") == 0 ||
str.find("hsv{") == 0) {
int c = 0, table[3] = { 0, 0, 0 };
int i = 4, j;
while ((j = str.find_first_of(",}", i)) != std::string::npos) {
std::string element = str.substr(i, j - i);
if (c < 3)
table[c++] = std::strtol(element.c_str(), NULL, 10);
if (c >= 3)
break;
i = j+1;
}
if (str[0] == 'r')
color = Color::fromRgb(table[0], table[1], table[2]);
else
color = Color::fromHsv(table[0], table[1], table[2]);
}
else if (str.find("gray{") == 0) {
color = Color::fromGray(std::strtol(str.c_str()+5, NULL, 10));
}
else if (str.find("index{") == 0) {
color = Color::fromIndex(std::strtol(str.c_str()+6, NULL, 10));
}
}
return color;
}
std::string Color::toString() const
{
std::stringstream result;
int data;
switch (getType()) {
case Color::MaskType:
result << "mask";
break;
case Color::RgbType:
data = getRgbData();
result << "rgb{"
<< GET_DATA_C1(data) << ","
<< GET_DATA_C2(data) << ","
<< GET_DATA_C3(data) << "}";
break;
case Color::HsvType:
data = getHsvData();
result << "hsv{"
<< GET_DATA_C1(data) << ","
<< GET_DATA_C2(data) << ","
<< GET_DATA_C3(data) << "}";
break;
case Color::GrayType:
data = getGrayData();
result << "gray{" << data << "}";
break;
case Color::IndexType:
data = getIndexData();
result << "index{" << data << "}";
break;
}
return result.str();
}
std::string Color::toFormalString(int imgtype, bool long_format) const
{
std::stringstream result;
int data;
// Long format
if (long_format) {
switch (getType()) {
case Color::MaskType:
result << _("Mask");
break;
case Color::RgbType:
data = getRgbData();
if (imgtype == IMAGE_GRAYSCALE) {
result << "Gray "
<< _graya_getv(color_utils::color_for_image(*this, imgtype));
}
else {
result << "RGB "
<< GET_DATA_C1(data) << " "
<< GET_DATA_C2(data) << " "
<< GET_DATA_C3(data);
if (imgtype == IMAGE_INDEXED)
result << " Index "
<< color_utils::color_for_image(*this, imgtype);
}
break;
case Color::HsvType:
data = getHsvData();
if (imgtype == IMAGE_GRAYSCALE) {
result << "Gray " << GET_DATA_C3(data);
}
else {
result << "HSV "
<< GET_DATA_C1(data) << " "
<< GET_DATA_C2(data) << " "
<< GET_DATA_C3(data);
if (imgtype == IMAGE_INDEXED)
result << " Index " << color_utils::color_for_image(*this, imgtype);
}
break;
case Color::GrayType:
data = getGrayData();
result << "Gray " << data;
break;
case Color::IndexType:
data = getIndexData();
if (data >= 0 && data < (int)get_current_palette()->size()) {
ase_uint32 _c = get_current_palette()->getEntry(data);
result << "Index " << data
<< " (RGB "
<< (int)_rgba_getr(_c) << " "
<< (int)_rgba_getg(_c) << " "
<< (int)_rgba_getb(_c) << ")";
}
else {
result << "Index "
<< data
<< " (out of range)";
}
break;
default:
ASSERT(false);
break;
}
}
// Short format
else {
switch (getType()) {
case Color::MaskType:
result << "MASK";
break;
case Color::RgbType:
data = getRgbData();
if (imgtype == IMAGE_GRAYSCALE) {
result << "V " << _graya_getv(color_utils::color_for_image(*this, imgtype));
}
else {
result << "RGB " << std::hex << std::setfill('0')
<< std::setw(2) << GET_DATA_C1(data)
<< std::setw(2) << GET_DATA_C2(data)
<< std::setw(2) << GET_DATA_C3(data);
if (imgtype == IMAGE_INDEXED) {
result << " (" << std::dec
<< color_utils::color_for_image(*this, imgtype) << ")";
}
}
break;
case Color::HsvType:
data = getHsvData();
if (imgtype == IMAGE_GRAYSCALE) {
result << "V " << GET_DATA_C3(data);
}
else {
result << "HSV " << std::hex << std::setfill('0')
<< std::setw(2) << GET_DATA_C1(data)
<< std::setw(2) << GET_DATA_C2(data)
<< std::setw(2) << GET_DATA_C3(data);
if (imgtype == IMAGE_INDEXED) {
result << " (" << std::dec
<< color_utils::color_for_image(*this, imgtype) << ")";
}
}
break;
case Color::GrayType:
data = getGrayData();
result << "V " << data;
break;
case Color::IndexType:
data = getIndexData();
result << "I " << data;
break;
default:
ASSERT(false);
break;
}
}
return result.str();
}
// Returns false only if the color is a index and it is outside the
// valid range (outside the maximum number of colors in the current
// palette)
bool Color::isValid() const
{
switch (getType()) {
case Color::IndexType: {
int i = getIndexData();
return (i >= 0 && i < get_current_palette()->size());
}
}
return true;
}
int Color::getRed() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType:
return GET_DATA_C1(getRgbData());
case Color::HsvType: {
int c = getHsvData();
int h = GET_DATA_C1(c);
int s = GET_DATA_C2(c);
int v = GET_DATA_C3(c);
hsv_to_rgb_int(&h, &s, &v);
return h;
}
case Color::GrayType:
return getGrayData();
case Color::IndexType: {
int i = getIndexData();
ASSERT(i >= 0 && i < get_current_palette()->size());
return _rgba_getr(get_current_palette()->getEntry(i));
}
}
ASSERT(false);
return -1;
}
int Color::getGreen() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType:
return GET_DATA_C2(getRgbData());
case Color::HsvType: {
int c = getHsvData();
int h = GET_DATA_C1(c);
int s = GET_DATA_C2(c);
int v = GET_DATA_C3(c);
hsv_to_rgb_int(&h, &s, &v);
return s;
}
case Color::GrayType:
return getGrayData();
case Color::IndexType: {
int i = getIndexData();
ASSERT(i >= 0 && i < get_current_palette()->size());
return _rgba_getg(get_current_palette()->getEntry(i));
}
}
ASSERT(false);
return -1;
}
int Color::getBlue() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType:
return GET_DATA_C3(getRgbData());
case Color::HsvType: {
int c = getHsvData();
int h = GET_DATA_C1(c);
int s = GET_DATA_C2(c);
int v = GET_DATA_C3(c);
hsv_to_rgb_int(&h, &s, &v);
return v;
}
case Color::GrayType:
return getGrayData();
case Color::IndexType: {
int i = getIndexData();
ASSERT(i >= 0 && i < get_current_palette()->size());
return _rgba_getb(get_current_palette()->getEntry(i));
}
}
ASSERT(false);
return -1;
}
int Color::getHue() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType: {
int c = getRgbData();
int r = GET_DATA_C1(c);
int g = GET_DATA_C2(c);
int b = GET_DATA_C3(c);
rgb_to_hsv_int(&r, &g, &b);
return r;
}
case Color::HsvType:
return GET_DATA_C1(getHsvData());
case Color::GrayType:
return 0;
case Color::IndexType: {
int i = getIndexData();
ASSERT(i >= 0 && i < get_current_palette()->size());
ase_uint32 c = get_current_palette()->getEntry(i);
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return r;
}
}
ASSERT(false);
return -1;
}
int Color::getSaturation() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType: {
int c = getRgbData();
int r = GET_DATA_C1(c);
int g = GET_DATA_C2(c);
int b = GET_DATA_C3(c);
rgb_to_hsv_int(&r, &g, &b);
return g;
}
case Color::HsvType:
return GET_DATA_C2(getHsvData());
case Color::GrayType:
return 0;
case Color::IndexType: {
int i = getIndexData();
ASSERT(i >= 0 && i < get_current_palette()->size());
ase_uint32 c = get_current_palette()->getEntry(i);
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return g;
}
}
ASSERT(false);
return -1;
}
int Color::getValue() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType: {
int c = getRgbData();
int r = GET_DATA_C1(c);
int g = GET_DATA_C2(c);
int b = GET_DATA_C3(c);
rgb_to_hsv_int(&r, &g, &b);
return b;
}
case Color::HsvType:
return GET_DATA_C3(getHsvData());
case Color::GrayType:
return getGrayData();
case Color::IndexType: {
int i = getIndexData();
ASSERT(i >= 0 && i < get_current_palette()->size());
ase_uint32 c = get_current_palette()->getEntry(i);
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return b;
}
}
ASSERT(false);
return -1;
}
int Color::getIndex() const
{
switch (getType()) {
case Color::MaskType:
return 0;
case Color::RgbType:
PRINTF("Getting `index' from a RGB color\n"); // TODO
ASSERT(false);
break;
case Color::HsvType:
PRINTF("Getting `index' from a HSV color\n"); // TODO
ASSERT(false);
break;
case Color::GrayType:
return getGrayData();
case Color::IndexType:
return getIndexData();
}
ASSERT(false);
return -1;
}

104
src/app/color.h Normal file
View File

@ -0,0 +1,104 @@
/* 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 CORE_COLOR_H_INCLUDED
#define CORE_COLOR_H_INCLUDED
#include <string>
class Image;
class Layer;
class Color {
public:
enum Type {
MaskType,
RgbType,
HsvType,
GrayType,
IndexType,
};
// Default ctor is mask color
Color()
: m_value(fromMask().m_value) {
}
static Color fromMask();
static Color fromRgb(int r, int g, int b);
static Color fromHsv(int h, int s, int v);
static Color fromGray(int g);
static Color fromIndex(int index);
static Color fromImage(int imgtype, int pixel);
static Color fromImageGetPixel(Image* image, int x, int y);
static Color fromString(const std::string& str);
std::string toString() const;
std::string toFormalString(int imgtype, bool long_format) const;
bool operator==(const Color& other) const {
return m_value == other.m_value;
}
bool operator!=(const Color& other) const {
return m_value != other.m_value;
}
Type getType() const {
return static_cast<Type>(m_value >> 24);
}
bool isValid() const;
int getRed() const;
int getGreen() const;
int getBlue() const;
int getHue() const;
int getSaturation() const;
int getValue() const;
int getIndex() const;
private:
Color(Type type, uint32_t data)
: m_value((static_cast<int>(type) << 24) |
(data & 0xffffff)) {
ASSERT((data & 0xff000000) == 0);
}
uint32_t getRgbData() const {
return m_value & 0xffffff;
}
uint32_t getHsvData() const {
return m_value & 0xffffff;
}
uint8_t getGrayData() const {
return m_value & 0xff;
}
uint8_t getIndexData() const {
return m_value & 0xff;
}
uint32_t m_value;
};
#endif

257
src/app/color_utils.cpp Normal file
View File

@ -0,0 +1,257 @@
/* 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 <allegro.h>
#include "app/color_utils.h"
#include "app/color.h"
#include "modules/palettes.h"
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "raster/palette.h"
// Internal functions
namespace {
// Returns the same values of bitmap_mask_color() (this function *must*
// returns the same values).
int get_mask_for_bitmap(int depth)
{
switch (depth) {
case 8: return MASK_COLOR_8; break;
case 15: return MASK_COLOR_15; break;
case 16: return MASK_COLOR_16; break;
case 24: return MASK_COLOR_24; break;
case 32: return MASK_COLOR_32; break;
default:
return -1;
}
}
}
int color_utils::blackandwhite(int r, int g, int b)
{
return (r*30+g*59+b*11)/100 < 128 ?
makecol(0, 0, 0):
makecol(255, 255, 255);
}
int color_utils::blackandwhite_neg(int r, int g, int b)
{
return (r*30+g*59+b*11)/100 < 128 ?
makecol(255, 255, 255):
makecol(0, 0, 0);
}
int color_utils::color_for_allegro(const Color& color, int depth)
{
int c = -1;
switch (color.getType()) {
case Color::MaskType:
c = get_mask_for_bitmap(depth);
break;
case Color::RgbType:
c = makeacol_depth(depth,
color.getRed(),
color.getGreen(),
color.getBlue(), 255);
break;
case Color::HsvType: {
int h, s, v;
h = color.getHue();
s = color.getSaturation();
v = color.getValue();
hsv_to_rgb_int(&h, &s, &v);
c = makeacol_depth(depth, h, s, v, 255);
break;
}
case Color::GrayType:
c = color.getValue();
if (depth != 8)
c = makeacol_depth(depth, c, c, c, 255);
break;
case Color::IndexType:
c = color.getIndex();
if (depth != 8) {
ASSERT(c >= 0 && c < (int)get_current_palette()->size());
ase_uint32 _c = get_current_palette()->getEntry(c);
c = makeacol_depth(depth,
_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
}
break;
}
return c;
}
int color_utils::color_for_image(const Color& color, int imgtype)
{
int c = -1;
switch (color.getType()) {
case Color::MaskType:
switch (imgtype) {
case IMAGE_RGB:
c = _rgba(0, 0, 0, 0);
break;
case IMAGE_GRAYSCALE:
c = _graya(0, 0);
break;
case IMAGE_INDEXED:
c = 0;
break;
}
break;
case Color::RgbType: {
int r, g, b;
r = color.getRed();
g = color.getGreen();
b = color.getBlue();
switch (imgtype) {
case IMAGE_RGB: {
c = _rgba(r, g, b, 255);
break;
}
case IMAGE_GRAYSCALE: {
rgb_to_hsv_int(&r, &g, &b);
c = _graya(b, 255);
break;
}
case IMAGE_INDEXED:
c = get_current_palette()->findBestfit(r, g, b);
break;
}
break;
}
case Color::HsvType: {
int h, s, v;
h = color.getHue();
s = color.getSaturation();
v = color.getValue();
switch (imgtype) {
case IMAGE_RGB:
hsv_to_rgb_int(&h, &s, &v);
c = _rgba(h, s, v, 255);
break;
case IMAGE_GRAYSCALE: {
c = _graya(v, 255);
break;
}
case IMAGE_INDEXED:
hsv_to_rgb_int(&h, &s, &v);
c = get_current_palette()->findBestfit(h, s, v);
break;
}
break;
}
case Color::GrayType:
switch (imgtype) {
case IMAGE_RGB:
c = color.getValue();
c = _rgba(c, c, c, 255);
break;
case IMAGE_GRAYSCALE:
c = color.getValue();
break;
case IMAGE_INDEXED:
c = color.getValue();
c = get_current_palette()->findBestfit(c, c, c);
break;
}
break;
case Color::IndexType:
switch (imgtype) {
case IMAGE_RGB: {
ase_uint32 _c = get_current_palette()->getEntry(color.getIndex());
c = _rgba(_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
break;
}
case IMAGE_GRAYSCALE:
c = _graya(color.getIndex(), 255);
break;
case IMAGE_INDEXED:
c = MID(0, color.getIndex(), get_current_palette()->size()-1);
break;
}
break;
}
return c;
}
int color_utils::color_for_layer(const Color& color, Layer* layer)
{
int imgtype = layer->getSprite()->getImgType();
return fixup_color_for_layer(layer, color_for_image(color, imgtype));
}
int color_utils::fixup_color_for_layer(Layer *layer, int color)
{
if (layer->is_background())
return fixup_color_for_background(layer->getSprite()->getImgType(), color);
else
return color;
}
int color_utils::fixup_color_for_background(int imgtype, int color)
{
switch (imgtype) {
case IMAGE_RGB:
if (_rgba_geta(color) < 255) {
return _rgba(_rgba_getr(color),
_rgba_getg(color),
_rgba_getb(color), 255);
}
break;
case IMAGE_GRAYSCALE:
if (_graya_geta(color) < 255) {
return _graya(_graya_getv(color), 255);
}
break;
}
return color;
}

41
src/app/color_utils.h Normal file
View File

@ -0,0 +1,41 @@
/* 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 APP_COLOR_UTILS_H_INCLUDED
#define APP_COLOR_UTILS_H_INCLUDED
#include "app/color.h"
class Layer;
namespace color_utils {
int blackandwhite(int r, int g, int b);
int blackandwhite_neg(int r, int g, int b);
int color_for_allegro(const Color& color, int depth);
int color_for_image(const Color& color, int imgtype);
int color_for_layer(const Color& color, Layer* layer);
int fixup_color_for_layer(Layer* layer, int color);
int fixup_color_for_background(int imgtype, int color);
}
#endif

View File

@ -25,6 +25,7 @@
#include "sprite_wrappers.h" #include "sprite_wrappers.h"
#include "undoable.h" #include "undoable.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "app/color_utils.h"
class BackgroundFromLayerCommand : public Command class BackgroundFromLayerCommand : public Command
{ {
@ -62,9 +63,8 @@ void BackgroundFromLayerCommand::onExecute(Context* context)
// each frame of the layer to be converted as `Background' must be // each frame of the layer to be converted as `Background' must be
// cleared using the selected background color in the color-bar // cleared using the selected background color in the color-bar
int bgcolor = get_color_for_image(sprite->getImgType(), int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType());
context->getSettings()->getBgColor()); bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor);
bgcolor = fixup_color_for_background(sprite->getImgType(), bgcolor);
{ {
Undoable undoable(sprite, "Background from Layer"); Undoable undoable(sprite, "Background from Layer");

View File

@ -30,6 +30,7 @@
#include "sprite_wrappers.h" #include "sprite_wrappers.h"
#include "undoable.h" #include "undoable.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "app/color_utils.h"
class CanvasSizeCommand : public Command class CanvasSizeCommand : public Command
{ {
@ -108,9 +109,8 @@ void CanvasSizeCommand::onExecute(Context* context)
{ {
Undoable undoable(sprite, "Canvas Size"); Undoable undoable(sprite, "Canvas Size");
int bgcolor = get_color_for_image(sprite->getImgType(), int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType());
context->getSettings()->getBgColor()); bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor);
bgcolor = fixup_color_for_background(sprite->getImgType(), bgcolor);
undoable.crop_sprite(x1, y1, x2-x1, y2-y1, bgcolor); undoable.crop_sprite(x1, y1, x2-x1, y2-y1, bgcolor);
undoable.commit(); undoable.commit();

View File

@ -71,30 +71,30 @@ void ChangeColorCommand::onLoadParams(Params* params)
void ChangeColorCommand::onExecute(Context* context) void ChangeColorCommand::onExecute(Context* context)
{ {
ColorBar* colorbar = app_get_colorbar(); ColorBar* colorbar = app_get_colorbar();
color_t color = m_background ? colorbar->getBgColor(): Color color = m_background ? colorbar->getBgColor():
colorbar->getFgColor(); colorbar->getFgColor();
switch (m_change) { switch (m_change) {
case None: case None:
// do nothing // do nothing
break; break;
case IncrementIndex: case IncrementIndex:
if (color_type(color) == COLOR_TYPE_INDEX) { if (color.getType() == Color::IndexType) {
int index = color_get_index(color); int index = color.getIndex();
if (index < 255) // TODO use sprite palette limit if (index < 255) // TODO use sprite palette limit
color = color_index(index+1); color = Color::fromIndex(index+1);
} }
else else
color = color_index(0); color = Color::fromIndex(0);
break; break;
case DecrementIndex: case DecrementIndex:
if (color_type(color) == COLOR_TYPE_INDEX) { if (color.getType() == Color::IndexType) {
int index = color_get_index(color); int index = color.getIndex();
if (index > 0) if (index > 0)
color = color_index(index-1); color = Color::fromIndex(index-1);
} }
else else
color = color_index(0); color = Color::fromIndex(0);
break; break;
} }

View File

@ -30,6 +30,7 @@
#include "util/autocrop.h" #include "util/autocrop.h"
#include "util/misc.h" #include "util/misc.h"
#include "sprite_wrappers.h" #include "sprite_wrappers.h"
#include "app/color_utils.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// crop_sprite // crop_sprite
@ -66,8 +67,8 @@ void CropSpriteCommand::onExecute(Context* context)
CurrentSpriteWriter sprite(context); CurrentSpriteWriter sprite(context);
{ {
Undoable undoable(sprite, "Sprite Crop"); Undoable undoable(sprite, "Sprite Crop");
int bgcolor = get_color_for_image(sprite->getImgType(), int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType());
app_get_colorbar()->getBgColor());
undoable.crop_sprite(sprite->getMask()->x, undoable.crop_sprite(sprite->getMask()->x,
sprite->getMask()->y, sprite->getMask()->y,
sprite->getMask()->w, sprite->getMask()->w,
@ -110,8 +111,10 @@ void AutocropSpriteCommand::onExecute(Context* context)
{ {
CurrentSpriteWriter sprite(context); CurrentSpriteWriter sprite(context);
{ {
int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType());
Undoable undoable(sprite, "Sprite Autocrop"); Undoable undoable(sprite, "Sprite Autocrop");
undoable.autocrop_sprite(app_get_colorbar()->getBgColor()); undoable.autocrop_sprite(bgcolor);
undoable.commit(); undoable.commit();
} }
sprite->generateMaskBoundaries(); sprite->generateMaskBoundaries();

View File

@ -81,8 +81,8 @@ void EyedropperCommand::onExecute(Context* context)
editor->screen_to_editor(jmouse_x(0), jmouse_y(0), &x, &y); editor->screen_to_editor(jmouse_x(0), jmouse_y(0), &x, &y);
// get the color from the image // get the color from the image
color_t color = color_from_image(sprite->getImgType(), Color color = Color::fromImage(sprite->getImgType(),
sprite->getPixel(x, y)); sprite->getPixel(x, y));
// TODO replace the color in the "context", not directly from the color-bar // TODO replace the color in the "context", not directly from the color-bar

View File

@ -25,6 +25,7 @@
#include "undoable.h" #include "undoable.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "sprite_wrappers.h" #include "sprite_wrappers.h"
#include "app/color_utils.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// flatten_layers // flatten_layers
@ -56,8 +57,7 @@ bool FlattenLayersCommand::onEnabled(Context* context)
void FlattenLayersCommand::onExecute(Context* context) void FlattenLayersCommand::onExecute(Context* context)
{ {
CurrentSpriteWriter sprite(context); CurrentSpriteWriter sprite(context);
int bgcolor = get_color_for_image(sprite->getImgType(), int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType());
app_get_colorbar()->getBgColor());
{ {
Undoable undoable(sprite, "Flatten Layers"); Undoable undoable(sprite, "Flatten Layers");
undoable.flatten_layers(bgcolor); undoable.flatten_layers(bgcolor);

View File

@ -22,7 +22,7 @@
#include "commands/command.h" #include "commands/command.h"
#include "console.h" #include "console.h"
#include "core/color.h" #include "gfx/color.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/cel.h" #include "raster/cel.h"
#include "raster/image.h" #include "raster/image.h"

View File

@ -28,7 +28,7 @@
#include "console.h" #include "console.h"
#include "app.h" #include "app.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/image.h" #include "raster/image.h"
@ -37,6 +37,7 @@
#include "raster/undo.h" #include "raster/undo.h"
#include "util/misc.h" #include "util/misc.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "app/color_utils.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// new_file // new_file
@ -71,12 +72,11 @@ void NewFileCommand::onExecute(Context* context)
int imgtype, w, h, bg, ncolors; int imgtype, w, h, bg, ncolors;
char buf[1024]; char buf[1024];
Sprite *sprite; Sprite *sprite;
color_t color; Color bg_table[] = {
color_t bg_table[] = { Color::fromMask(),
color_mask(), Color::fromRgb(0, 0, 0),
color_rgb(0, 0, 0), Color::fromRgb(255, 255, 255),
color_rgb(255, 255, 255), Color::fromRgb(255, 0, 255),
color_rgb(255, 0, 255),
app_get_colorbar()->getBgColor() app_get_colorbar()->getBgColor()
}; };
@ -135,7 +135,7 @@ void NewFileCommand::onExecute(Context* context)
ncolors = MID(2, ncolors, 256); ncolors = MID(2, ncolors, 256);
// Select the color // Select the color
color = color_mask(); Color color = Color::fromMask();
if (bg >= 0 && bg <= 4) { if (bg >= 0 && bg <= 4) {
color = bg_table[bg]; color = bg_table[bg];
@ -162,11 +162,11 @@ void NewFileCommand::onExecute(Context* context)
// If the background color isn't transparent, we have to // If the background color isn't transparent, we have to
// convert the `Layer 1' in a `Background' // convert the `Layer 1' in a `Background'
if (color_type(color) != COLOR_TYPE_MASK) { if (color.getType() != Color::MaskType) {
ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image()); ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image());
static_cast<LayerImage*>(sprite->getCurrentLayer())->configure_as_background(); static_cast<LayerImage*>(sprite->getCurrentLayer())->configure_as_background();
image_clear(sprite->getCurrentImage(), get_color_for_image(imgtype, color)); image_clear(sprite->getCurrentImage(), color_utils::color_for_image(color, imgtype));
} }
// Show the sprite to the user // Show the sprite to the user

View File

@ -22,7 +22,7 @@
#include "commands/command.h" #include "commands/command.h"
#include "console.h" #include "console.h"
#include "core/color.h" #include "app/color.h"
#include "app.h" #include "app.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/cel.h" #include "raster/cel.h"

View File

@ -179,8 +179,8 @@ void OptionsCommand::onResetCheckedBg()
// Default values // Default values
m_checked_bg->setSelectedItem((int)RenderEngine::CHECKED_BG_16X16); m_checked_bg->setSelectedItem((int)RenderEngine::CHECKED_BG_16X16);
m_checked_bg_zoom->setSelected(true); m_checked_bg_zoom->setSelected(true);
m_checked_bg_color1->setColor(color_rgb(128, 128, 128)); m_checked_bg_color1->setColor(Color::fromRgb(128, 128, 128));
m_checked_bg_color2->setColor(color_rgb(192, 192, 192)); m_checked_bg_color2->setColor(Color::fromRgb(192, 192, 192));
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View File

@ -31,7 +31,7 @@
#include "commands/command.h" #include "commands/command.h"
#include "commands/params.h" #include "commands/params.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "dialogs/filesel.h" #include "dialogs/filesel.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "modules/editors.h" #include "modules/editors.h"
@ -123,7 +123,7 @@ static bool select_rgb_hook(JWidget widget, void *data);
static bool select_hsv_hook(JWidget widget, void *data); static bool select_hsv_hook(JWidget widget, void *data);
static bool expand_button_select_hook(JWidget widget, void *data); static bool expand_button_select_hook(JWidget widget, void *data);
static void modify_all_selected_entries_in_palette(int r, int g, int b); static void modify_all_selected_entries_in_palette(int r, int g, int b);
static void on_color_changed(color_t color); static void on_color_changed(const Color& color);
static void set_new_palette(Palette *palette); static void set_new_palette(Palette *palette);
@ -276,7 +276,7 @@ void PaletteEditorCommand::onExecute(Context* context)
// Show the specified target color // Show the specified target color
{ {
color_t color = Color color =
(m_background ? context->getSettings()->getBgColor(): (m_background ? context->getSettings()->getBgColor():
context->getSettings()->getFgColor()); context->getSettings()->getFgColor());
@ -732,11 +732,11 @@ static bool sliderRGB_change_hook(JWidget widget, void *data)
int r = jslider_get_value(R_slider); int r = jslider_get_value(R_slider);
int g = jslider_get_value(G_slider); int g = jslider_get_value(G_slider);
int b = jslider_get_value(B_slider); int b = jslider_get_value(B_slider);
color_t color = color_rgb(r, g, b); Color color = Color::fromRgb(r, g, b);
jslider_set_value(H_slider, color_get_hue(color)); jslider_set_value(H_slider, color.getHue());
jslider_set_value(V_slider, color_get_value(color)); jslider_set_value(V_slider, color.getValue());
jslider_set_value(S_slider, color_get_saturation(color)); jslider_set_value(S_slider, color.getSaturation());
modify_all_selected_entries_in_palette(r, g, b); modify_all_selected_entries_in_palette(r, g, b);
@ -752,12 +752,12 @@ static bool sliderHSV_change_hook(JWidget widget, void *data)
int h = jslider_get_value(H_slider); int h = jslider_get_value(H_slider);
int s = jslider_get_value(S_slider); int s = jslider_get_value(S_slider);
int v = jslider_get_value(V_slider); int v = jslider_get_value(V_slider);
color_t color = color_hsv(h, s, v); Color color = Color::fromHsv(h, s, v);
int r, g, b; int r, g, b;
jslider_set_value(R_slider, r = color_get_red(color)); jslider_set_value(R_slider, r = color.getRed());
jslider_set_value(G_slider, g = color_get_green(color)); jslider_set_value(G_slider, g = color.getGreen());
jslider_set_value(B_slider, b = color_get_blue(color)); jslider_set_value(B_slider, b = color.getBlue());
modify_all_selected_entries_in_palette(r, g, b); modify_all_selected_entries_in_palette(r, g, b);
@ -776,11 +776,11 @@ static bool entryRGB_change_hook(JWidget widget, void *data)
r = MID(0, r, 255); r = MID(0, r, 255);
g = MID(0, g, 255); g = MID(0, g, 255);
b = MID(0, b, 255); b = MID(0, b, 255);
color_t color = color_rgb(r, g, b); Color color = Color::fromRgb(r, g, b);
H_entry->setTextf("%d", color_get_hue(color)); H_entry->setTextf("%d", color.getHue());
V_entry->setTextf("%d", color_get_value(color)); V_entry->setTextf("%d", color.getValue());
S_entry->setTextf("%d", color_get_saturation(color)); S_entry->setTextf("%d", color.getSaturation());
modify_all_selected_entries_in_palette(r, g, b); modify_all_selected_entries_in_palette(r, g, b);
@ -796,12 +796,12 @@ static bool entryHSV_change_hook(JWidget widget, void *data)
int h = H_entry->getTextInt(); int h = H_entry->getTextInt();
int s = S_entry->getTextInt(); int s = S_entry->getTextInt();
int v = V_entry->getTextInt(); int v = V_entry->getTextInt();
color_t color = color_hsv(h, s, v); Color color = Color::fromHsv(h, s, v);
int r, g, b; int r, g, b;
R_entry->setTextf("%d", r = color_get_red(color)); R_entry->setTextf("%d", r = color.getRed());
G_entry->setTextf("%d", g = color_get_green(color)); G_entry->setTextf("%d", g = color.getGreen());
B_entry->setTextf("%d", b = color_get_blue(color)); B_entry->setTextf("%d", b = color.getBlue());
modify_all_selected_entries_in_palette(r, g, b); modify_all_selected_entries_in_palette(r, g, b);
@ -905,19 +905,19 @@ static void update_colorbar()
app_get_colorbar()->dirty(); app_get_colorbar()->dirty();
} }
static void update_sliders_from_color(color_t color) static void update_sliders_from_color(const Color& color)
{ {
jslider_set_value(R_slider, color_get_red(color)); jslider_set_value(R_slider, color.getRed());
jslider_set_value(G_slider, color_get_green(color)); jslider_set_value(G_slider, color.getGreen());
jslider_set_value(B_slider, color_get_blue(color)); jslider_set_value(B_slider, color.getBlue());
jslider_set_value(H_slider, color_get_hue(color)); jslider_set_value(H_slider, color.getHue());
jslider_set_value(S_slider, color_get_saturation(color)); jslider_set_value(S_slider, color.getSaturation());
jslider_set_value(V_slider, color_get_value(color)); jslider_set_value(V_slider, color.getValue());
} }
static bool palette_editor_change_hook(JWidget widget, void *data) static bool palette_editor_change_hook(JWidget widget, void *data)
{ {
color_t color = color_index(palette_editor->get2ndColor()); Color color = Color::fromIndex(palette_editor->get2ndColor());
// colorviewer_set_color(colorviewer, color); // colorviewer_set_color(colorviewer, color);
@ -1053,13 +1053,13 @@ static void modify_all_selected_entries_in_palette(int r, int g, int b)
palette->setEntry(c, _rgba(r, g, b, 255)); palette->setEntry(c, _rgba(r, g, b, 255));
} }
static void on_color_changed(color_t color) static void on_color_changed(const Color& color)
{ {
if (disable_colorbar_signals) if (disable_colorbar_signals)
return; return;
if (color_is_valid(color) && color_type(color) == COLOR_TYPE_INDEX) { if (color.isValid() && color.getType() == Color::IndexType) {
int index = color_get_index(color); int index = color.getIndex();
palette_editor->selectColor(index); palette_editor->selectColor(index);
update_sliders_from_color(color); // Update sliders update_sliders_from_color(color); // Update sliders

View File

@ -24,7 +24,7 @@
#include "Vaca/Bind.h" #include "Vaca/Bind.h"
#include "commands/command.h" #include "commands/command.h"
#include "core/color.h" #include "app/color.h"
#include "mem_utils.h" #include "mem_utils.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/image.h" #include "raster/image.h"

View File

@ -45,8 +45,8 @@ SwitchColorsCommand::SwitchColorsCommand()
void SwitchColorsCommand::onExecute(Context* context) void SwitchColorsCommand::onExecute(Context* context)
{ {
ColorBar* colorbar = app_get_colorbar(); ColorBar* colorbar = app_get_colorbar();
color_t fg = colorbar->getFgColor(); Color fg = colorbar->getFgColor();
color_t bg = colorbar->getBgColor(); Color bg = colorbar->getBgColor();
colorbar->setFgColor(bg); colorbar->setFgColor(bg);
colorbar->setBgColor(fg); colorbar->setBgColor(fg);

View File

@ -26,7 +26,7 @@
#include "console.h" #include "console.h"
#include "app.h" #include "app.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "effect/colcurve.h" #include "effect/colcurve.h"
#include "effect/effect.h" #include "effect/effect.h"

View File

@ -36,7 +36,7 @@
#include "commands/fx/effectbg.h" #include "commands/fx/effectbg.h"
#include "console.h" #include "console.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "effect/colcurve.h" #include "effect/colcurve.h"
#include "effect/convmatr.h" #include "effect/convmatr.h"

View File

@ -31,7 +31,7 @@
#include "commands/fx/effectbg.h" #include "commands/fx/effectbg.h"
#include "console.h" #include "console.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "effect/effect.h" #include "effect/effect.h"
#include "modules/gui.h" #include "modules/gui.h"

View File

@ -28,7 +28,7 @@
#include "console.h" #include "console.h"
#include "app.h" #include "app.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "effect/effect.h" #include "effect/effect.h"
#include "effect/replcol.h" #include "effect/replcol.h"
@ -41,6 +41,7 @@
#include "widgets/color_button.h" #include "widgets/color_button.h"
#include "widgets/preview.h" #include "widgets/preview.h"
#include "widgets/target.h" #include "widgets/target.h"
#include "app/color_utils.h"
static ColorButton* button_color1; static ColorButton* button_color1;
static ColorButton* button_color2; static ColorButton* button_color2;
@ -191,15 +192,14 @@ static void preview_change_hook(Widget* widget)
static void make_preview() static void make_preview()
{ {
Sprite* sprite = preview_get_effect(preview)->sprite; Sprite* sprite = preview_get_effect(preview)->sprite;
color_t from, to;
int tolerance; int tolerance;
from = get_config_color("ReplaceColor", "Color1", color_mask()); Color from = get_config_color("ReplaceColor", "Color1", Color::fromMask());
to = get_config_color("ReplaceColor", "Color2", color_mask()); Color to = get_config_color("ReplaceColor", "Color2", Color::fromMask());
tolerance = get_config_int("ReplaceColor", "Tolerance", 0); tolerance = get_config_int("ReplaceColor", "Tolerance", 0);
set_replace_colors(get_color_for_layer(sprite->getCurrentLayer(), from), set_replace_colors(color_utils::color_for_layer(from, sprite->getCurrentLayer()),
get_color_for_layer(sprite->getCurrentLayer(), to), color_utils::color_for_layer(to, sprite->getCurrentLayer()),
MID(0, tolerance, 255)); MID(0, tolerance, 255));
if (check_preview->isSelected()) if (check_preview->isSelected())

View File

@ -99,16 +99,12 @@ void set_config_rect(const char *section, const char *name, const Rect& rect)
set_config_string(section, name, buf); set_config_string(section, name, buf);
} }
color_t get_config_color(const char *section, const char *name, color_t value) Color get_config_color(const char *section, const char *name, const Color& value)
{ {
char buf[128]; return Color::fromString(get_config_string(section, name, value.toString().c_str()));
color_to_string(value, buf, sizeof(buf));
return string_to_color(get_config_string(section, name, buf));
} }
void set_config_color(const char *section, const char *name, color_t value) void set_config_color(const char *section, const char *name, const Color& value)
{ {
char buf[128]; set_config_string(section, name, value.toString().c_str());
color_to_string(value, buf, sizeof(buf));
set_config_string(section, name, buf);
} }

View File

@ -21,7 +21,7 @@
#include <allegro/config.h> #include <allegro/config.h>
#include "Vaca/Rect.h" #include "Vaca/Rect.h"
#include "core/color.h" #include "app/color.h"
using Vaca::Rect; using Vaca::Rect;
@ -38,7 +38,7 @@ void set_config_bool(const char *section, const char *name, bool value);
Rect get_config_rect(const char *section, const char *name, const Rect& rect); Rect get_config_rect(const char *section, const char *name, const Rect& rect);
void set_config_rect(const char *section, const char *name, const Rect& rect); void set_config_rect(const char *section, const char *name, const Rect& rect);
color_t get_config_color(const char *section, const char *name, color_t value); Color get_config_color(const char *section, const char *name, const Color& value);
void set_config_color(const char *section, const char *name, color_t value); void set_config_color(const char *section, const char *name, const Color& value);
#endif #endif

View File

@ -1,851 +0,0 @@
/* 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 <allegro.h>
#include "jinete/jbase.h"
#include "app.h"
#include "core/color.h"
#include "core/core.h"
#include "modules/gfx.h"
#include "modules/palettes.h"
#include "raster/blend.h"
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/palette.h"
#include "raster/sprite.h"
#include "widgets/color_bar.h"
/* #define GET_COLOR_TYPE(color) ((ase_uint32)((color).coltype)) */
/* #define GET_COLOR_DATA(color) ((ase_uint32)((color).imgcolor)) */
#define MAKE_COLOR(type,data) (((type) << 24) | (data))
#define GET_COLOR_TYPE(color) ((color) >> 24)
#define GET_COLOR_DATA(color) ((color) & 0xffffff)
#define GET_COLOR_DATA_RGB(color) (GET_COLOR_DATA(color) & 0xffffff)
#define GET_COLOR_DATA_HSV(color) (GET_COLOR_DATA(color) & 0xffffff)
#define GET_COLOR_DATA_GRAY(color) (GET_COLOR_DATA(color) & 0xff)
#define GET_COLOR_DATA_INDEX(color) (GET_COLOR_DATA(color) & 0xff)
#define MAKE_DATA(c1,c2,c3) (((c3) << 16) | ((c2) << 8) | (c1))
#define GET_DATA_C1(c) (((c) >> 0) & 0xff)
#define GET_DATA_C2(c) (((c) >> 8) & 0xff)
#define GET_DATA_C3(c) (((c) >> 16) & 0xff)
static int get_mask_for_bitmap(int depth);
char *color_to_string(color_t color, char *buf, int size)
{
int data;
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
uszprintf(buf, size, "mask");
break;
case COLOR_TYPE_RGB:
data = GET_COLOR_DATA_RGB(color);
uszprintf(buf, size, "rgb{%d,%d,%d}",
GET_DATA_C1(data),
GET_DATA_C2(data),
GET_DATA_C3(data));
break;
case COLOR_TYPE_HSV:
data = GET_COLOR_DATA_HSV(color);
uszprintf(buf, size, "hsv{%d,%d,%d}",
GET_DATA_C1(data),
GET_DATA_C2(data),
GET_DATA_C3(data));
break;
case COLOR_TYPE_GRAY:
data = GET_COLOR_DATA_GRAY(color);
uszprintf(buf, size, "gray{%d}", data);
break;
case COLOR_TYPE_INDEX:
data = GET_COLOR_DATA_INDEX(color);
uszprintf(buf, size, "index{%d}", data);
break;
}
return buf;
}
color_t string_to_color(const char *_str)
{
char *str = jstrdup(_str);
color_t color = color_mask();
char *tok;
if (ustrcmp(str, "mask") != 0) {
if (ustrncmp(str, "rgb{", 4) == 0) {
int c=0, table[3] = { 0, 0, 0 };
for (tok=ustrtok(str+4, ","); tok;
tok=ustrtok(NULL, ",")) {
if (c < 3)
table[c++] = ustrtol(tok, NULL, 10);
}
color = color_rgb(table[0], table[1], table[2]);
}
else if (ustrncmp(str, "hsv{", 4) == 0) {
int c=0, table[3] = { 0, 0, 0 };
for (tok=ustrtok(str+4, ","); tok;
tok=ustrtok(NULL, ",")) {
if (c < 3)
table[c++] = ustrtol(tok, NULL, 10);
}
color = color_hsv(table[0], table[1], table[2]);
}
else if (ustrncmp(str, "gray{", 5) == 0) {
color = color_gray(ustrtol(str+5, NULL, 10));
}
else if (ustrncmp(str, "index{", 6) == 0) {
color = color_index(ustrtol(str+6, NULL, 10));
}
}
jfree(str);
return color;
}
int color_type(color_t color)
{
return GET_COLOR_TYPE(color);
}
// Returns false only if the color is a index and it is outside the
// valid range (outside the maximum number of colors in the current
// palette)
bool color_is_valid(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
return (i >= 0 && i < get_current_palette()->size());
}
}
return true;
}
bool color_equals(color_t c1, color_t c2)
{
return
GET_COLOR_TYPE(c1) == GET_COLOR_TYPE(c2) &&
GET_COLOR_DATA(c1) == GET_COLOR_DATA(c2);
}
color_t color_mask()
{
return MAKE_COLOR(COLOR_TYPE_MASK, 0);
}
color_t color_rgb(int r, int g, int b)
{
return MAKE_COLOR(COLOR_TYPE_RGB,
MAKE_DATA(r & 0xff,
g & 0xff,
b & 0xff));
}
color_t color_hsv(int h, int s, int v)
{
return MAKE_COLOR(COLOR_TYPE_HSV,
MAKE_DATA(h & 0xff,
s & 0xff,
v & 0xff));
}
color_t color_gray(int g)
{
return MAKE_COLOR(COLOR_TYPE_GRAY, g & 0xff);
}
color_t color_index(int index)
{
return MAKE_COLOR(COLOR_TYPE_INDEX, index & 0xff);
}
int color_get_red(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB:
return GET_DATA_C1(GET_COLOR_DATA_RGB(color));
case COLOR_TYPE_HSV: {
int c = GET_COLOR_DATA_HSV(color);
int h = GET_DATA_C1(c);
int s = GET_DATA_C2(c);
int v = GET_DATA_C3(c);
hsv_to_rgb_int(&h, &s, &v);
return h;
}
case COLOR_TYPE_GRAY:
return GET_COLOR_DATA_GRAY(color);
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
ASSERT(i >= 0 && i < get_current_palette()->size());
return _rgba_getr(get_current_palette()->getEntry(i));
}
}
ASSERT(false);
return -1;
}
int color_get_green(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB:
return GET_DATA_C2(GET_COLOR_DATA_RGB(color));
case COLOR_TYPE_HSV: {
int c = GET_COLOR_DATA_HSV(color);
int h = GET_DATA_C1(c);
int s = GET_DATA_C2(c);
int v = GET_DATA_C3(c);
hsv_to_rgb_int(&h, &s, &v);
return s;
}
case COLOR_TYPE_GRAY:
return GET_COLOR_DATA_GRAY(color);
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
ASSERT(i >= 0 && i < get_current_palette()->size());
return _rgba_getg(get_current_palette()->getEntry(i));
}
}
ASSERT(false);
return -1;
}
int color_get_blue(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB:
return GET_DATA_C3(GET_COLOR_DATA_RGB(color));
case COLOR_TYPE_HSV: {
int c = GET_COLOR_DATA_HSV(color);
int h = GET_DATA_C1(c);
int s = GET_DATA_C2(c);
int v = GET_DATA_C3(c);
hsv_to_rgb_int(&h, &s, &v);
return v;
}
case COLOR_TYPE_GRAY:
return GET_COLOR_DATA_GRAY(color);
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
ASSERT(i >= 0 && i < get_current_palette()->size());
return _rgba_getb(get_current_palette()->getEntry(i));
}
}
ASSERT(false);
return -1;
}
int color_get_hue(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB: {
int c = GET_COLOR_DATA_RGB(color);
int r = GET_DATA_C1(c);
int g = GET_DATA_C2(c);
int b = GET_DATA_C3(c);
rgb_to_hsv_int(&r, &g, &b);
return r;
}
case COLOR_TYPE_HSV:
return GET_DATA_C1(GET_COLOR_DATA_HSV(color));
case COLOR_TYPE_GRAY:
return 0;
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
ASSERT(i >= 0 && i < get_current_palette()->size());
ase_uint32 c = get_current_palette()->getEntry(i);
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return r;
}
}
ASSERT(false);
return -1;
}
int color_get_saturation(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB: {
int c = GET_COLOR_DATA_RGB(color);
int r = GET_DATA_C1(c);
int g = GET_DATA_C2(c);
int b = GET_DATA_C3(c);
rgb_to_hsv_int(&r, &g, &b);
return g;
}
case COLOR_TYPE_HSV:
return GET_DATA_C2(GET_COLOR_DATA_HSV(color));
case COLOR_TYPE_GRAY:
return 0;
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
ASSERT(i >= 0 && i < get_current_palette()->size());
ase_uint32 c = get_current_palette()->getEntry(i);
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return g;
}
}
ASSERT(false);
return -1;
}
int color_get_value(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB: {
int c = GET_COLOR_DATA_RGB(color);
int r = GET_DATA_C1(c);
int g = GET_DATA_C2(c);
int b = GET_DATA_C3(c);
rgb_to_hsv_int(&r, &g, &b);
return b;
}
case COLOR_TYPE_HSV:
return GET_DATA_C3(GET_COLOR_DATA_HSV(color));
case COLOR_TYPE_GRAY:
return GET_COLOR_DATA_GRAY(color);
case COLOR_TYPE_INDEX: {
int i = GET_COLOR_DATA_INDEX(color);
ASSERT(i >= 0 && i < get_current_palette()->size());
ase_uint32 c = get_current_palette()->getEntry(i);
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return b;
}
}
ASSERT(false);
return -1;
}
int color_get_index(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return 0;
case COLOR_TYPE_RGB:
PRINTF("Getting `index' from a RGB color\n"); /* TODO */
ASSERT(false);
break;
case COLOR_TYPE_HSV:
PRINTF("Getting `index' from a HSV color\n"); /* TODO */
ASSERT(false);
break;
case COLOR_TYPE_GRAY:
return GET_COLOR_DATA_GRAY(color);
case COLOR_TYPE_INDEX:
return GET_COLOR_DATA_INDEX(color);
}
ASSERT(false);
return -1;
}
color_t color_from_image(int imgtype, int c)
{
color_t color = color_mask();
switch (imgtype) {
case IMAGE_RGB:
if (_rgba_geta(c) > 0) {
color = color_rgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c));
}
break;
case IMAGE_GRAYSCALE:
if (_graya_geta(c) > 0) {
color = color_gray(_graya_getv(c));
}
break;
case IMAGE_INDEXED:
color = color_index(c);
break;
}
return color;
}
int blackandwhite(int r, int g, int b)
{
return (r*30+g*59+b*11)/100 < 128 ?
makecol(0, 0, 0):
makecol(255, 255, 255);
}
int blackandwhite_neg(int r, int g, int b)
{
return (r*30+g*59+b*11)/100 < 128 ?
makecol(255, 255, 255):
makecol(0, 0, 0);
}
int get_color_for_allegro(int depth, color_t color)
{
int data;
int c = -1;
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
c = get_mask_for_bitmap(depth);
break;
case COLOR_TYPE_RGB:
data = GET_COLOR_DATA_RGB(color);
c = makeacol_depth(depth,
_rgba_getr(data),
_rgba_getg(data),
_rgba_getb(data), 255);
break;
case COLOR_TYPE_HSV: {
int h, s, v;
data = GET_COLOR_DATA_HSV(color);
h = GET_DATA_C1(data);
s = GET_DATA_C2(data);
v = GET_DATA_C3(data);
hsv_to_rgb_int(&h, &s, &v);
c = makeacol_depth(depth, h, s, v, 255);
break;
}
case COLOR_TYPE_GRAY:
c = GET_COLOR_DATA_GRAY(color);
if (depth != 8)
c = makeacol_depth(depth, c, c, c, 255);
break;
case COLOR_TYPE_INDEX:
c = GET_COLOR_DATA_INDEX(color);
if (depth != 8) {
ASSERT(c >= 0 && c < (int)get_current_palette()->size());
ase_uint32 _c = get_current_palette()->getEntry(c);
c = makeacol_depth(depth,
_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
}
break;
}
return c;
}
int get_color_for_image(int imgtype, color_t color)
{
int c = -1;
int data;
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
switch (imgtype) {
case IMAGE_RGB:
c = _rgba(0, 0, 0, 0);
break;
case IMAGE_GRAYSCALE:
c = _graya(0, 0);
break;
case IMAGE_INDEXED:
c = 0;
break;
}
break;
case COLOR_TYPE_RGB: {
int r, g, b;
data = GET_COLOR_DATA_RGB(color);
r = GET_DATA_C1(data);
g = GET_DATA_C2(data);
b = GET_DATA_C3(data);
switch (imgtype) {
case IMAGE_RGB: {
c = _rgba(r, g, b, 255);
break;
}
case IMAGE_GRAYSCALE: {
rgb_to_hsv_int(&r, &g, &b);
c = _graya(b, 255);
break;
}
case IMAGE_INDEXED:
c = get_current_palette()->findBestfit(r, g, b);
break;
}
break;
}
case COLOR_TYPE_HSV: {
int h, s, v;
data = GET_COLOR_DATA_HSV(color);
h = GET_DATA_C1(data);
s = GET_DATA_C2(data);
v = GET_DATA_C3(data);
switch (imgtype) {
case IMAGE_RGB:
hsv_to_rgb_int(&h, &s, &v);
c = _rgba(h, s, v, 255);
break;
case IMAGE_GRAYSCALE: {
c = _graya(v, 255);
break;
}
case IMAGE_INDEXED:
hsv_to_rgb_int(&h, &s, &v);
c = get_current_palette()->findBestfit(h, s, v);
break;
}
break;
}
case COLOR_TYPE_GRAY:
data = GET_COLOR_DATA_GRAY(color);
switch (imgtype) {
case IMAGE_RGB:
c = data;
c = _rgba(c, c, c, 255);
break;
case IMAGE_GRAYSCALE:
c = data;
break;
case IMAGE_INDEXED:
c = data;
c = get_current_palette()->findBestfit(c, c, c);
break;
}
break;
case COLOR_TYPE_INDEX:
data = GET_COLOR_DATA_INDEX(color);
switch (imgtype) {
case IMAGE_RGB: {
ase_uint32 _c = get_current_palette()->getEntry(data);
c = _rgba(_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
break;
}
case IMAGE_GRAYSCALE:
c = _graya(data & 0xff, 255);
break;
case IMAGE_INDEXED:
c = MID(0, (data & 0xff), get_current_palette()->size()-1);
break;
}
break;
}
return c;
}
int get_color_for_layer(Layer *layer, color_t color)
{
return
fixup_color_for_layer(layer,
get_color_for_image(layer->getSprite()->getImgType(),
color));
}
int fixup_color_for_layer(Layer *layer, int color)
{
if (layer->is_background())
return fixup_color_for_background(layer->getSprite()->getImgType(), color);
else
return color;
}
int fixup_color_for_background(int imgtype, int color)
{
switch (imgtype) {
case IMAGE_RGB:
if (_rgba_geta(color) < 255) {
return _rgba(_rgba_getr(color),
_rgba_getg(color),
_rgba_getb(color), 255);
}
break;
case IMAGE_GRAYSCALE:
if (_graya_geta(color) < 255) {
return _graya(_graya_getv(color), 255);
}
break;
}
return color;
}
color_t image_getpixel_color(Image *image, int x, int y)
{
if ((x >= 0) && (y >= 0) && (x < image->w) && (y < image->h))
return color_from_image(image->imgtype, image_getpixel(image, x, y));
else
return color_mask();
}
void color_to_formalstring(int imgtype, color_t color,
char *buf, int size, bool long_format)
{
int data;
// Long format
if (long_format) {
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
ustrncpy(buf, _("Mask"), size);
break;
case COLOR_TYPE_RGB:
data = GET_COLOR_DATA_RGB(color);
if (imgtype == IMAGE_GRAYSCALE) {
uszprintf(buf, size, "Gray %d",
_graya_getv(get_color_for_image(imgtype, color)));
}
else {
uszprintf(buf, size, "RGB %d %d %d",
GET_DATA_C1(data),
GET_DATA_C2(data),
GET_DATA_C3(data));
if (imgtype == IMAGE_INDEXED)
uszprintf(buf+ustrlen(buf), size, " %s %d",
_("Index"), get_color_for_image(imgtype, color));
}
break;
case COLOR_TYPE_HSV:
data = GET_COLOR_DATA_HSV(color);
if (imgtype == IMAGE_GRAYSCALE) {
uszprintf(buf, size, "Gray %d",
GET_DATA_C3(data));
}
else {
uszprintf(buf, size, "HSV %d %d %d",
GET_DATA_C1(data),
GET_DATA_C2(data),
GET_DATA_C3(data));
if (imgtype == IMAGE_INDEXED)
uszprintf(buf+ustrlen(buf), size, " Index %d",
get_color_for_image(imgtype, color));
}
break;
case COLOR_TYPE_GRAY:
data = GET_COLOR_DATA_GRAY(color);
uszprintf(buf, size, "Gray %d",
data);
break;
case COLOR_TYPE_INDEX:
data = GET_COLOR_DATA_INDEX(color);
if (data >= 0 && data < (int)get_current_palette()->size()) {
ase_uint32 _c = get_current_palette()->getEntry(data);
uszprintf(buf, size, "Index %d (RGB %d %d %d)",
data,
_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c));
}
else {
uszprintf(buf, size, "Index %d (out of range)", data);
}
break;
default:
ASSERT(false);
break;
}
}
// Short format
else {
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
uszprintf(buf, size, "MASK");
break;
case COLOR_TYPE_RGB:
data = GET_COLOR_DATA_RGB(color);
if (imgtype == IMAGE_GRAYSCALE) {
uszprintf(buf, size, "V %d",
_graya_getv(get_color_for_image(imgtype, color)));
}
else {
uszprintf(buf, size, "RGB %02x%02x%02x",
GET_DATA_C1(data),
GET_DATA_C2(data),
GET_DATA_C3(data));
if (imgtype == IMAGE_INDEXED)
uszprintf(buf+ustrlen(buf), size, "(%d)",
get_color_for_image(imgtype, color));
}
break;
case COLOR_TYPE_HSV:
data = GET_COLOR_DATA_HSV(color);
if (imgtype == IMAGE_GRAYSCALE) {
uszprintf(buf, size, "V %d",
GET_DATA_C3(data));
}
else {
uszprintf(buf, size, "HSV %02x%02x%02x",
GET_DATA_C1(data),
GET_DATA_C2(data),
GET_DATA_C3(data));
if (imgtype == IMAGE_INDEXED)
uszprintf(buf+ustrlen(buf), size, "(%d)",
get_color_for_image(imgtype, color));
}
break;
case COLOR_TYPE_GRAY:
data = GET_COLOR_DATA_GRAY(color);
uszprintf(buf, size, "V %d", data);
break;
case COLOR_TYPE_INDEX:
data = GET_COLOR_DATA_INDEX(color);
uszprintf(buf, size, "I %d", data);
break;
default:
ASSERT(false);
break;
}
}
}
/* returns the same values of bitmap_mask_color() (this function *must*
returns the same values) */
static int get_mask_for_bitmap(int depth)
{
switch (depth) {
case 8: return MASK_COLOR_8; break;
case 15: return MASK_COLOR_15; break;
case 16: return MASK_COLOR_16; break;
case 24: return MASK_COLOR_24; break;
case 32: return MASK_COLOR_32; break;
default:
return -1;
}
}

View File

@ -1,74 +0,0 @@
/* 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 CORE_COLOR_H_INCLUDED
#define CORE_COLOR_H_INCLUDED
#include "jinete/jbase.h"
struct BITMAP;
class Image;
class Layer;
enum {
COLOR_TYPE_MASK,
COLOR_TYPE_RGB,
COLOR_TYPE_HSV,
COLOR_TYPE_GRAY,
COLOR_TYPE_INDEX,
};
typedef uint32_t color_t;
char *color_to_string(color_t color, char *buf, int size);
color_t string_to_color(const char *str);
int color_type(color_t color);
bool color_is_valid(color_t color);
bool color_equals(color_t c1, color_t c2);
color_t color_mask();
color_t color_rgb(int r, int g, int b);
color_t color_hsv(int h, int s, int v);
color_t color_gray(int g);
color_t color_index(int index);
int color_get_red(color_t color);
int color_get_green(color_t color);
int color_get_blue(color_t color);
int color_get_hue(color_t color);
int color_get_saturation(color_t color);
int color_get_value(color_t color);
int color_get_index(color_t color);
color_t color_from_image(int imgtype, int c);
int blackandwhite(int r, int g, int b);
int blackandwhite_neg(int r, int g, int b);
int get_color_for_allegro(int depth, color_t color);
int get_color_for_image(int imgtype, color_t color);
int get_color_for_layer(Layer* layer, color_t color);
int fixup_color_for_layer(Layer* layer, int color);
int fixup_color_for_background(int imgtype, int color);
color_t image_getpixel_color(Image* image, int x, int y);
void color_to_formalstring(int imgtype, color_t color, char *buf,
int size, bool long_format);
#endif

View File

@ -25,7 +25,7 @@
#include "app.h" #include "app.h"
#include "console.h" #include "console.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "dialogs/filesel.h" #include "dialogs/filesel.h"
#include "modules/gui.h" #include "modules/gui.h"
@ -97,7 +97,7 @@ void dialogs_draw_text(Sprite* sprite)
window->open_window_fg(); window->open_window_fg();
if (window->get_killer() == button_ok) { if (window->get_killer() == button_ok) {
color_t color_with_type = colorbutton_get_color(color_but); Color color_with_type = colorbutton_get_color(color_but);
const char *text = jwidget_get_text(entry_text); const char *text = jwidget_get_text(entry_text);
const char *size_str = jwidget_get_text(entry_size); const char *size_str = jwidget_get_text(entry_size);
const char *font_str = get_config_string("DrawText", "Font", const char *font_str = get_config_string("DrawText", "Font",
@ -123,8 +123,7 @@ void dialogs_draw_text(Sprite* sprite)
ji_font_set_size(f, size); ji_font_set_size(f, size);
/* setup color */ /* setup color */
color = get_color_for_image(sprite->imgtype, color = color_utils::color_for_image(color_with_type, sprite->imgtype);
color_with_type);
/* update configuration */ /* update configuration */
set_config_color("DrawText", "Color", color_with_type); set_config_color("DrawText", "Color", color_with_type);

View File

@ -29,7 +29,7 @@
#include "app.h" #include "app.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "modules/gui.h" #include "modules/gui.h"
@ -40,6 +40,7 @@
#include "util/misc.h" #include "util/misc.h"
#include "widgets/color_bar.h" #include "widgets/color_bar.h"
#include "widgets/color_button.h" #include "widgets/color_button.h"
#include "app/color_utils.h"
static ColorButton* button_color; static ColorButton* button_color;
static CheckBox* check_preview; static CheckBox* check_preview;
@ -192,7 +193,7 @@ static Mask *gen_mask(const Sprite* sprite)
const Image* image = sprite->getCurrentImage(&xpos, &ypos, NULL); const Image* image = sprite->getCurrentImage(&xpos, &ypos, NULL);
color = get_color_for_image(sprite->getImgType(), button_color->getColor()); color = color_utils::color_for_image(button_color->getColor(), sprite->getImgType());
fuzziness = jslider_get_value(slider_fuzziness); fuzziness = jslider_get_value(slider_fuzziness);
Mask* mask = mask_new(); Mask* mask = mask_new();

View File

@ -18,7 +18,7 @@
#include "config.h" #include "config.h"
#include "core/color.h" #include "app/color.h"
#include "effect/effect.h" #include "effect/effect.h"
#include "raster/image.h" #include "raster/image.h"

View File

@ -20,7 +20,7 @@
#define MODULES_EDITORS_H_INCLUDED #define MODULES_EDITORS_H_INCLUDED
#include "jinete/jbase.h" #include "jinete/jbase.h"
#include "core/color.h" #include "app/color.h"
class Editor; class Editor;

View File

@ -40,6 +40,7 @@
#include "raster/image.h" #include "raster/image.h"
#include "raster/palette.h" #include "raster/palette.h"
#include "widgets/editor.h" #include "widgets/editor.h"
#include "app/color_utils.h"
using Vaca::Rect; using Vaca::Rect;
using Vaca::Point; using Vaca::Point;
@ -423,21 +424,21 @@ void draw_emptyset_symbol(BITMAP* bmp, const Rect& rc, int color)
center.x+size/2, center.y-size/2, color); center.x+size/2, center.y-size/2, color);
} }
void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color) void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color)
{ {
int type = color_type(color); Color::Type type = color.getType();
BITMAP* graph; BITMAP* graph;
if (type == COLOR_TYPE_MASK) { if (type == Color::MaskType) {
rectgrid(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, rc.w/4, rc.h/2); rectgrid(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, rc.w/4, rc.h/2);
return; return;
} }
else if (type == COLOR_TYPE_INDEX) { else if (type == Color::IndexType) {
int index = color_get_index(color); int index = color.getIndex();
if (index >= 0 && index < get_current_palette()->size()) { if (index >= 0 && index < get_current_palette()->size()) {
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
get_color_for_allegro(bitmap_color_depth(bmp), color)); color_utils::color_for_allegro(color, bitmap_color_depth(bmp)));
} }
else { else {
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, makecol(0, 0, 0)); rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, makecol(0, 0, 0));
@ -450,7 +451,8 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color)
case IMAGE_INDEXED: case IMAGE_INDEXED:
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
get_color_for_allegro(imgtype, color_index(get_color_for_image(imgtype, color)))); color_utils::color_for_allegro(Color::fromIndex(color_utils::color_for_image(color, imgtype)),
bitmap_color_depth(bmp)));
break; break;
case IMAGE_RGB: case IMAGE_RGB:
@ -459,11 +461,12 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color)
return; return;
{ {
int rgb_bitmap_color = get_color_for_image(imgtype, color); int rgb_bitmap_color = color_utils::color_for_image(color, imgtype);
color_t color2 = color_rgb(_rgba_getr(rgb_bitmap_color), Color color2 = Color::fromRgb(_rgba_getr(rgb_bitmap_color),
_rgba_getg(rgb_bitmap_color), _rgba_getg(rgb_bitmap_color),
_rgba_getb(rgb_bitmap_color)); _rgba_getb(rgb_bitmap_color));
rectfill(graph, 0, 0, rc.w-1, rc.h-1, get_color_for_allegro(32, color2)); rectfill(graph, 0, 0, rc.w-1, rc.h-1,
color_utils::color_for_allegro(color2, 32));
} }
blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h); blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h);
@ -477,9 +480,10 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color)
return; return;
{ {
int gray_bitmap_color = get_color_for_image(imgtype, color); int gray_bitmap_color = color_utils::color_for_image(color, imgtype);
color_t color2 = color_gray(_graya_getv(gray_bitmap_color)); Color color2 = Color::fromGray(_graya_getv(gray_bitmap_color));
rectfill(graph, 0, 0, rc.w-1, rc.h-1, get_color_for_allegro(32, color2)); rectfill(graph, 0, 0, rc.w-1, rc.h-1,
color_utils::color_for_allegro(color2, 32));
} }
blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h); blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h);
@ -493,7 +497,7 @@ void draw_color_button(BITMAP* bmp,
const Rect& rc, const Rect& rc,
bool outer_nw, bool outer_n, bool outer_ne, bool outer_e, bool outer_nw, bool outer_n, bool outer_ne, bool outer_e,
bool outer_se, bool outer_s, bool outer_sw, bool outer_w, bool outer_se, bool outer_s, bool outer_sw, bool outer_w,
int imgtype, color_t color, bool hot, bool drag) int imgtype, const Color& color, bool hot, bool drag)
{ {
SkinneableTheme* theme = (SkinneableTheme*)ji_get_theme(); SkinneableTheme* theme = (SkinneableTheme*)ji_get_theme();
int scale = jguiscale(); int scale = jguiscale();

View File

@ -19,7 +19,7 @@
#ifndef MODULES_GFX_H_INCLUDED #ifndef MODULES_GFX_H_INCLUDED
#define MODULES_GFX_H_INCLUDED #define MODULES_GFX_H_INCLUDED
#include "core/color.h" #include "app/color.h"
#include "jinete/jbase.h" #include "jinete/jbase.h"
namespace Vaca { class Rect; } namespace Vaca { class Rect; }
@ -94,12 +94,12 @@ void rectdotted(BITMAP* bmp, int x1, int y1, int x2, int y2, int fg, int bg);
void rectgrid(BITMAP* bmp, int x1, int y1, int x2, int y2, int w, int h); void rectgrid(BITMAP* bmp, int x1, int y1, int x2, int y2, int w, int h);
void draw_emptyset_symbol(BITMAP* bmp, const Rect& rc, int color); void draw_emptyset_symbol(BITMAP* bmp, const Rect& rc, int color);
void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color); void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color);
void draw_color_button(BITMAP* bmp, void draw_color_button(BITMAP* bmp,
const Rect& rc, const Rect& rc,
bool outer_nw, bool outer_n, bool outer_ne, bool outer_e, bool outer_nw, bool outer_n, bool outer_ne, bool outer_e,
bool outer_se, bool outer_s, bool outer_sw, bool outer_w, bool outer_se, bool outer_s, bool outer_sw, bool outer_w,
int imgtype, color_t color, int imgtype, const Color& color,
bool hot, bool drag); bool hot, bool drag);
void draw_progress_bar(BITMAP* bmp, void draw_progress_bar(BITMAP* bmp,
int x1, int y1, int x2, int y2, int x1, int y1, int x2, int y2,

View File

@ -20,7 +20,7 @@
#define SETTINGS_SETTINGS_H_INCLUDED #define SETTINGS_SETTINGS_H_INCLUDED
#include "Vaca/Rect.h" #include "Vaca/Rect.h"
#include "core/color.h" #include "app/color.h"
#include "tiled_mode.h" #include "tiled_mode.h"
#include "pen_type.h" #include "pen_type.h"
@ -38,13 +38,13 @@ public:
// General settings // General settings
virtual color_t getFgColor() = 0; virtual Color getFgColor() = 0;
virtual color_t getBgColor() = 0; virtual Color getBgColor() = 0;
virtual Tool* getCurrentTool() = 0; virtual Tool* getCurrentTool() = 0;
virtual TiledMode getTiledMode() = 0; virtual TiledMode getTiledMode() = 0;
virtual void setFgColor(color_t color) = 0; virtual void setFgColor(const Color& color) = 0;
virtual void setBgColor(color_t color) = 0; virtual void setBgColor(const Color& color) = 0;
virtual void setCurrentTool(Tool* tool) = 0; virtual void setCurrentTool(Tool* tool) = 0;
virtual void setTiledMode(TiledMode mode) = 0; virtual void setTiledMode(TiledMode mode) = 0;
@ -53,20 +53,20 @@ public:
virtual bool getSnapToGrid() = 0; virtual bool getSnapToGrid() = 0;
virtual bool getGridVisible() = 0; virtual bool getGridVisible() = 0;
virtual Rect getGridBounds() = 0; virtual Rect getGridBounds() = 0;
virtual color_t getGridColor() = 0; virtual Color getGridColor() = 0;
virtual void setSnapToGrid(bool state) = 0; virtual void setSnapToGrid(bool state) = 0;
virtual void setGridVisible(bool state) = 0; virtual void setGridVisible(bool state) = 0;
virtual void setGridBounds(Rect rect) = 0; virtual void setGridBounds(Rect rect) = 0;
virtual void setGridColor(color_t color) = 0; virtual void setGridColor(const Color& color) = 0;
// Pixel grid // Pixel grid
virtual bool getPixelGridVisible() = 0; virtual bool getPixelGridVisible() = 0;
virtual color_t getPixelGridColor() = 0; virtual Color getPixelGridColor() = 0;
virtual void setPixelGridVisible(bool state) = 0; virtual void setPixelGridVisible(bool state) = 0;
virtual void setPixelGridColor(color_t color) = 0; virtual void setPixelGridColor(const Color& color) = 0;
// Onionskin settings // Onionskin settings

View File

@ -33,23 +33,21 @@
// UISettingsImpl // UISettingsImpl
UISettingsImpl::UISettingsImpl() UISettingsImpl::UISettingsImpl()
: m_gridBounds(0, 0, 16, 16) : m_currentTool(NULL)
, m_tiledMode((TiledMode)get_config_int("Tools", "Tiled", (int)TILED_NONE))
, m_use_onionskin(get_config_bool("Onionskin", "Enabled", false))
, m_prev_frames_onionskin(get_config_int("Onionskin", "PrevFrames", 1))
, m_next_frames_onionskin(get_config_int("Onionskin", "NextFrames", 0))
, m_onionskin_opacity_base(get_config_int("Onionskin", "OpacityBase", 128))
, m_onionskin_opacity_step(get_config_int("Onionskin", "OpacityStep", 32))
, m_snapToGrid(get_config_bool("Grid", "SnapTo", false))
, m_gridVisible(get_config_bool("Grid", "Visible", false))
, m_gridBounds(get_config_rect("Grid", "Bounds", Rect(0, 0, 16, 16)))
, m_gridColor(get_config_color("Grid", "Color", Color::fromRgb(0, 0, 255)))
, m_pixelGridColor(get_config_color("PixelGrid", "Color", Color::fromRgb(200, 200, 200)))
, m_pixelGridVisible(get_config_bool("PixelGrid", "Visible", false))
{ {
m_currentTool = NULL; m_tiledMode = (TiledMode)MID(0, (int)m_tiledMode, (int)TILED_BOTH);
m_tiledMode = (TiledMode)get_config_int("Tools", "Tiled", (int)TILED_NONE);
m_tiledMode = (TiledMode)MID(0, (int)m_tiledMode, (int)TILED_BOTH);
m_snapToGrid = get_config_bool("Grid", "SnapTo", false);
m_gridVisible = get_config_bool("Grid", "Visible", false);
m_gridColor = get_config_color("Grid", "Color", color_rgb(0, 0, 255));
m_gridBounds = get_config_rect("Grid", "Bounds", m_gridBounds);
m_pixelGridVisible = get_config_bool("PixelGrid", "Visible", false);
m_pixelGridColor = get_config_color("PixelGrid", "Color", color_rgb(200, 200, 200));
m_use_onionskin = get_config_bool("Onionskin", "Enabled", false);
m_prev_frames_onionskin = get_config_int("Onionskin", "PrevFrames", 1);
m_next_frames_onionskin = get_config_int("Onionskin", "NextFrames", 0);
m_onionskin_opacity_base = get_config_int("Onionskin", "OpacityBase", 128);
m_onionskin_opacity_step = get_config_int("Onionskin", "OpacityStep", 32);
} }
UISettingsImpl::~UISettingsImpl() UISettingsImpl::~UISettingsImpl()
@ -77,12 +75,12 @@ UISettingsImpl::~UISettingsImpl()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// General settings // General settings
color_t UISettingsImpl::getFgColor() Color UISettingsImpl::getFgColor()
{ {
return app_get_colorbar()->getFgColor(); return app_get_colorbar()->getFgColor();
} }
color_t UISettingsImpl::getBgColor() Color UISettingsImpl::getBgColor()
{ {
return app_get_colorbar()->getBgColor(); return app_get_colorbar()->getBgColor();
} }
@ -100,12 +98,12 @@ TiledMode UISettingsImpl::getTiledMode()
return m_tiledMode; return m_tiledMode;
} }
void UISettingsImpl::setFgColor(color_t color) void UISettingsImpl::setFgColor(const Color& color)
{ {
app_get_colorbar()->setFgColor(color); app_get_colorbar()->setFgColor(color);
} }
void UISettingsImpl::setBgColor(color_t color) void UISettingsImpl::setBgColor(const Color& color)
{ {
app_get_colorbar()->setFgColor(color); app_get_colorbar()->setFgColor(color);
} }
@ -147,7 +145,7 @@ Rect UISettingsImpl::getGridBounds()
return m_gridBounds; return m_gridBounds;
} }
color_t UISettingsImpl::getGridColor() Color UISettingsImpl::getGridColor()
{ {
return m_gridColor; return m_gridColor;
} }
@ -167,7 +165,7 @@ void UISettingsImpl::setGridBounds(Rect rect)
m_gridBounds = rect; m_gridBounds = rect;
} }
void UISettingsImpl::setGridColor(color_t color) void UISettingsImpl::setGridColor(const Color& color)
{ {
m_gridColor = color; m_gridColor = color;
} }
@ -180,7 +178,7 @@ bool UISettingsImpl::getPixelGridVisible()
return m_pixelGridVisible; return m_pixelGridVisible;
} }
color_t UISettingsImpl::getPixelGridColor() Color UISettingsImpl::getPixelGridColor()
{ {
return m_pixelGridColor; return m_pixelGridColor;
} }
@ -190,7 +188,7 @@ void UISettingsImpl::setPixelGridVisible(bool state)
m_pixelGridVisible = state; m_pixelGridVisible = state;
} }
void UISettingsImpl::setPixelGridColor(color_t color) void UISettingsImpl::setPixelGridColor(const Color& color)
{ {
m_pixelGridColor = color; m_pixelGridColor = color;
} }

View File

@ -31,13 +31,13 @@ public:
// General settings // General settings
color_t getFgColor(); Color getFgColor();
color_t getBgColor(); Color getBgColor();
Tool* getCurrentTool(); Tool* getCurrentTool();
TiledMode getTiledMode(); TiledMode getTiledMode();
void setFgColor(color_t color); void setFgColor(const Color& color);
void setBgColor(color_t color); void setBgColor(const Color& color);
void setCurrentTool(Tool* tool); void setCurrentTool(Tool* tool);
void setTiledMode(TiledMode mode); void setTiledMode(TiledMode mode);
@ -46,20 +46,20 @@ public:
bool getSnapToGrid(); bool getSnapToGrid();
bool getGridVisible(); bool getGridVisible();
Rect getGridBounds(); Rect getGridBounds();
color_t getGridColor(); Color getGridColor();
void setSnapToGrid(bool state); void setSnapToGrid(bool state);
void setGridVisible(bool state); void setGridVisible(bool state);
void setGridBounds(Rect rect); void setGridBounds(Rect rect);
void setGridColor(color_t color); void setGridColor(const Color& color);
// Pixel grid // Pixel grid
bool getPixelGridVisible(); bool getPixelGridVisible();
color_t getPixelGridColor(); Color getPixelGridColor();
void setPixelGridVisible(bool state); void setPixelGridVisible(bool state);
void setPixelGridColor(color_t color); void setPixelGridColor(const Color& color);
// Onionskin settings // Onionskin settings
@ -80,8 +80,8 @@ public:
IToolSettings* getToolSettings(Tool* tool); IToolSettings* getToolSettings(Tool* tool);
private: private:
TiledMode m_tiledMode;
Tool* m_currentTool; Tool* m_currentTool;
TiledMode m_tiledMode;
bool m_use_onionskin; bool m_use_onionskin;
int m_prev_frames_onionskin; int m_prev_frames_onionskin;
int m_next_frames_onionskin; int m_next_frames_onionskin;
@ -90,9 +90,9 @@ private:
bool m_snapToGrid; bool m_snapToGrid;
bool m_gridVisible; bool m_gridVisible;
Rect m_gridBounds; Rect m_gridBounds;
color_t m_gridColor; Color m_gridColor;
bool m_pixelGridVisible; bool m_pixelGridVisible;
color_t m_pixelGridColor; Color m_pixelGridColor;
std::map<std::string, IToolSettings*> m_toolSettings; std::map<std::string, IToolSettings*> m_toolSettings;
}; };

View File

@ -20,7 +20,7 @@
#define TESTS_TEST_H_INCLUDED #define TESTS_TEST_H_INCLUDED
#ifdef NDEBUG #ifdef NDEBUG
#error You should compile the tests with the NDEBUG flag activated #error You must compile tests with the NDEBUG flag disabled
#endif #endif
#include <stdio.h> #include <stdio.h>

41
src/tests/test_color.cpp Normal file
View File

@ -0,0 +1,41 @@
/* 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 "tests/test.h"
#include "app/color.h"
int main(int argc, char *argv[])
{
test_init();
ASSERT(Color::fromRgb(32, 16, 255).getRed() == 32);
ASSERT(Color::fromRgb(32, 16, 255).getGreen() == 16);
ASSERT(Color::fromRgb(32, 16, 255).getBlue() == 255);
ASSERT(Color::fromString("rgb{0,0,0}") == Color::fromRgb(0, 0, 0));
ASSERT(Color::fromString("rgb{32,16,255}") == Color::fromRgb(32, 16, 255));
ASSERT(Color::fromString("hsv{32,64,99}") == Color::fromHsv(32, 64, 99));
ASSERT("rgb{0,0,0}" == Color::fromRgb(0, 0, 0).toString());
ASSERT("rgb{32,16,255}" == Color::fromRgb(32, 16, 255).toString());
ASSERT("hsv{32,64,99}" == Color::fromHsv(32, 64, 99).toString());
return test_exit();
}
END_OF_MAIN();

View File

@ -17,6 +17,7 @@
*/ */
#include "app.h" // TODO avoid to include this file #include "app.h" // TODO avoid to include this file
#include "app/color_utils.h"
#include "raster/undo.h" #include "raster/undo.h"
#include "tools/ink_processing.h" #include "tools/ink_processing.h"
@ -49,10 +50,10 @@ public:
case WithFg: case WithFg:
case WithBg: case WithBg:
{ {
int color = get_color_for_layer(loop->getLayer(), int color = color_utils::color_for_layer(m_type == WithFg ?
m_type == WithFg ? loop->getContext()->getSettings()->getFgColor():
loop->getContext()->getSettings()->getFgColor(): loop->getContext()->getSettings()->getBgColor(),
loop->getContext()->getSettings()->getBgColor()); loop->getLayer());
loop->setPrimaryColor(color); loop->setPrimaryColor(color);
loop->setSecondaryColor(color); loop->setSecondaryColor(color);
} }
@ -163,19 +164,19 @@ public:
case ReplaceFgWithBg: case ReplaceFgWithBg:
m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getImgType(), 2)]; m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getImgType(), 2)];
loop->setPrimaryColor(get_color_for_layer(loop->getLayer(), loop->setPrimaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getFgColor(),
loop->getContext()->getSettings()->getFgColor())); loop->getLayer()));
loop->setSecondaryColor(get_color_for_layer(loop->getLayer(), loop->setSecondaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getBgColor(),
loop->getContext()->getSettings()->getBgColor())); loop->getLayer()));
break; break;
case ReplaceBgWithFg: case ReplaceBgWithFg:
m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getImgType(), 2)]; m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getImgType(), 2)];
loop->setPrimaryColor(get_color_for_layer(loop->getLayer(), loop->setPrimaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getBgColor(),
loop->getContext()->getSettings()->getBgColor())); loop->getLayer()));
loop->setSecondaryColor(get_color_for_layer(loop->getLayer(), loop->setSecondaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getFgColor(),
loop->getContext()->getSettings()->getFgColor())); loop->getLayer()));
break; break;
} }
} }

View File

@ -23,7 +23,7 @@
#include "sprite_wrappers.h" #include "sprite_wrappers.h"
#include "console.h" #include "console.h"
#include "app.h" #include "app.h"
#include "core/color.h" #include "app/color.h"
#include "core/core.h" #include "core/core.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/blend.h" #include "raster/blend.h"

View File

@ -28,7 +28,7 @@
#include "app.h" #include "app.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "modules/palettes.h" #include "modules/palettes.h"

View File

@ -19,7 +19,7 @@
#ifndef UTIL_MISC_H_INCLUDED #ifndef UTIL_MISC_H_INCLUDED
#define UTIL_MISC_H_INCLUDED #define UTIL_MISC_H_INCLUDED
#include "core/color.h" #include "app/color.h"
#include "widgets/editor.h" /* for movement modes */ #include "widgets/editor.h" /* for movement modes */
class Frame; class Frame;

View File

@ -26,6 +26,7 @@
#include "util/render.h" #include "util/render.h"
#include "settings/settings.h" #include "settings/settings.h"
#include "ui_context.h" #include "ui_context.h"
#include "app/color_utils.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Zoomed merge // Zoomed merge
@ -279,61 +280,70 @@ done_with_blit:;
static RenderEngine::CheckedBgType checked_bg_type; static RenderEngine::CheckedBgType checked_bg_type;
static bool checked_bg_zoom; static bool checked_bg_zoom;
static color_t checked_bg_color1; static Color checked_bg_color1;
static color_t checked_bg_color2; static Color checked_bg_color2;
static int global_opacity = 255; static int global_opacity = 255;
static Layer *selected_layer = NULL; static Layer *selected_layer = NULL;
static Image *rastering_image = NULL; static Image *rastering_image = NULL;
// static
void RenderEngine::loadConfig() void RenderEngine::loadConfig()
{ {
checked_bg_type = (CheckedBgType)get_config_int("Options", "CheckedBgType", checked_bg_type = (CheckedBgType)get_config_int("Options", "CheckedBgType",
(int)RenderEngine::CHECKED_BG_16X16); (int)RenderEngine::CHECKED_BG_16X16);
checked_bg_zoom = get_config_bool("Options", "CheckedBgZoom", true); checked_bg_zoom = get_config_bool("Options", "CheckedBgZoom", true);
checked_bg_color1 = get_config_color("Options", "CheckedBgColor1", color_rgb(128, 128, 128)); checked_bg_color1 = get_config_color("Options", "CheckedBgColor1", Color::fromRgb(128, 128, 128));
checked_bg_color2 = get_config_color("Options", "CheckedBgColor2", color_rgb(192, 192, 192)); checked_bg_color2 = get_config_color("Options", "CheckedBgColor2", Color::fromRgb(192, 192, 192));
} }
// static
RenderEngine::CheckedBgType RenderEngine::getCheckedBgType() RenderEngine::CheckedBgType RenderEngine::getCheckedBgType()
{ {
return checked_bg_type; return checked_bg_type;
} }
// static
void RenderEngine::setCheckedBgType(CheckedBgType type) void RenderEngine::setCheckedBgType(CheckedBgType type)
{ {
checked_bg_type = type; checked_bg_type = type;
set_config_int("Options", "CheckedBgType", (int)type); set_config_int("Options", "CheckedBgType", (int)type);
} }
// static
bool RenderEngine::getCheckedBgZoom() bool RenderEngine::getCheckedBgZoom()
{ {
return checked_bg_zoom; return checked_bg_zoom;
} }
// static
void RenderEngine::setCheckedBgZoom(bool state) void RenderEngine::setCheckedBgZoom(bool state)
{ {
checked_bg_zoom = state; checked_bg_zoom = state;
set_config_int("Options", "CheckedBgZoom", state); set_config_int("Options", "CheckedBgZoom", state);
} }
color_t RenderEngine::getCheckedBgColor1() // static
Color RenderEngine::getCheckedBgColor1()
{ {
return checked_bg_color1; return checked_bg_color1;
} }
void RenderEngine::setCheckedBgColor1(color_t color) // static
void RenderEngine::setCheckedBgColor1(const Color& color)
{ {
checked_bg_color1 = color; checked_bg_color1 = color;
set_config_color("Options", "CheckedBgColor1", color); set_config_color("Options", "CheckedBgColor1", color);
} }
color_t RenderEngine::getCheckedBgColor2() // static
Color RenderEngine::getCheckedBgColor2()
{ {
return checked_bg_color2; return checked_bg_color2;
} }
void RenderEngine::setCheckedBgColor2(color_t color) // static
void RenderEngine::setCheckedBgColor2(const Color& color)
{ {
checked_bg_color2 = color; checked_bg_color2 = color;
set_config_color("Options", "CheckedBgColor2", color); set_config_color("Options", "CheckedBgColor2", color);
@ -341,6 +351,7 @@ void RenderEngine::setCheckedBgColor2(color_t color)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// static
void RenderEngine::setPreviewImage(Layer *layer, Image *image) void RenderEngine::setPreviewImage(Layer *layer, Image *image)
{ {
selected_layer = layer; selected_layer = layer;
@ -354,6 +365,7 @@ void RenderEngine::setPreviewImage(Layer *layer, Image *image)
Positions source_x, source_y, width and height must have the Positions source_x, source_y, width and height must have the
zoom applied (sorce_x<<zoom, source_y<<zoom, width<<zoom, etc.) zoom applied (sorce_x<<zoom, source_y<<zoom, width<<zoom, etc.)
*/ */
// static
Image* RenderEngine::renderSprite(const Sprite* sprite, Image* RenderEngine::renderSprite(const Sprite* sprite,
int source_x, int source_y, int source_x, int source_y,
int width, int height, int width, int height,
@ -440,6 +452,7 @@ Image* RenderEngine::renderSprite(const Sprite* sprite,
return image; return image;
} }
// static
void RenderEngine::renderCheckedBackground(Image* image, void RenderEngine::renderCheckedBackground(Image* image,
int source_x, int source_y, int source_x, int source_y,
int zoom) int zoom)
@ -447,8 +460,8 @@ void RenderEngine::renderCheckedBackground(Image* image,
int x, y, u, v; int x, y, u, v;
int tile_w = 16; int tile_w = 16;
int tile_h = 16; int tile_h = 16;
int c1 = get_color_for_image(image->imgtype, checked_bg_color1); int c1 = color_utils::color_for_image(checked_bg_color1, image->imgtype);
int c2 = get_color_for_image(image->imgtype, checked_bg_color2); int c2 = color_utils::color_for_image(checked_bg_color2, image->imgtype);
switch (checked_bg_type) { switch (checked_bg_type) {
@ -504,6 +517,7 @@ void RenderEngine::renderCheckedBackground(Image* image,
} }
} }
// static
void RenderEngine::renderImage(Image* rgb_image, Image* src_image, const Palette* pal, void RenderEngine::renderImage(Image* rgb_image, Image* src_image, const Palette* pal,
int x, int y, int zoom) int x, int y, int zoom)
{ {
@ -532,6 +546,7 @@ void RenderEngine::renderImage(Image* rgb_image, Image* src_image, const Palette
(*zoomed_func)(rgb_image, src_image, pal, x, y, 255, BLEND_MODE_NORMAL, zoom); (*zoomed_func)(rgb_image, src_image, pal, x, y, 255, BLEND_MODE_NORMAL, zoom);
} }
// static
void RenderEngine::renderLayer(const Sprite *sprite, void RenderEngine::renderLayer(const Sprite *sprite,
const Layer *layer, const Layer *layer,
Image *image, Image *image,

View File

@ -19,7 +19,7 @@
#ifndef UTIL_RENDER_H_INCLUDED #ifndef UTIL_RENDER_H_INCLUDED
#define UTIL_RENDER_H_INCLUDED #define UTIL_RENDER_H_INCLUDED
#include "core/color.h" #include "app/color.h"
class Image; class Image;
class Layer; class Layer;
@ -43,10 +43,10 @@ public:
static void setCheckedBgType(CheckedBgType type); static void setCheckedBgType(CheckedBgType type);
static bool getCheckedBgZoom(); static bool getCheckedBgZoom();
static void setCheckedBgZoom(bool state); static void setCheckedBgZoom(bool state);
static color_t getCheckedBgColor1(); static Color getCheckedBgColor1();
static void setCheckedBgColor1(color_t color); static void setCheckedBgColor1(const Color& color);
static color_t getCheckedBgColor2(); static Color getCheckedBgColor2();
static void setCheckedBgColor2(color_t color); static void setCheckedBgColor2(const Color& color);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Preview image // Preview image

View File

@ -29,7 +29,7 @@
#include "commands/params.h" #include "commands/params.h"
#include "app.h" #include "app.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "modules/gfx.h" #include "modules/gfx.h"
#include "modules/gui.h" #include "modules/gui.h"
@ -71,13 +71,13 @@ int colorbar_type()
ColorBar::ColorBar(int align) ColorBar::ColorBar(int align)
: Widget(colorbar_type()) : Widget(colorbar_type())
, m_fgcolor(Color::fromIndex(15))
, m_bgcolor(Color::fromIndex(0))
{ {
m_entrySize = 16; m_entrySize = 16;
m_firstIndex = 0; m_firstIndex = 0;
m_columns = 2; m_columns = 2;
m_colorsPerColumn = 12; m_colorsPerColumn = 12;
m_fgcolor = color_index(15);
m_bgcolor = color_index(0);
m_hot = HOTCOLOR_NONE; m_hot = HOTCOLOR_NONE;
m_hot_editing = HOTCOLOR_NONE; m_hot_editing = HOTCOLOR_NONE;
m_hot_drag = HOTCOLOR_NONE; m_hot_drag = HOTCOLOR_NONE;
@ -111,7 +111,7 @@ ColorBar::~ColorBar()
set_config_int("ColorBar", "EntrySize", m_entrySize); set_config_int("ColorBar", "EntrySize", m_entrySize);
} }
void ColorBar::setFgColor(color_t color) void ColorBar::setFgColor(const Color& color)
{ {
m_fgcolor = color; m_fgcolor = color;
dirty(); dirty();
@ -120,7 +120,7 @@ void ColorBar::setFgColor(color_t color)
FgColorChange(m_fgcolor); FgColorChange(m_fgcolor);
} }
void ColorBar::setBgColor(color_t color) void ColorBar::setBgColor(const Color& color)
{ {
m_bgcolor = color; m_bgcolor = color;
dirty(); dirty();
@ -129,7 +129,7 @@ void ColorBar::setBgColor(color_t color)
BgColorChange(m_bgcolor); BgColorChange(m_bgcolor);
} }
color_t ColorBar::getColorByPosition(int x, int y) Color ColorBar::getColorByPosition(int x, int y)
{ {
for (int i=0; i<getEntriesCount(); ++i) { for (int i=0; i<getEntriesCount(); ++i) {
if (getEntryBounds(i).contains(Point(x, y))) if (getEntryBounds(i).contains(Point(x, y)))
@ -144,7 +144,7 @@ color_t ColorBar::getColorByPosition(int x, int y)
if (getBgBounds().contains(Point(x, y))) if (getBgBounds().contains(Point(x, y)))
return m_bgcolor; return m_bgcolor;
return color_mask(); return Color::fromMask();
} }
bool ColorBar::onProcessMessage(JMessage msg) bool ColorBar::onProcessMessage(JMessage msg)
@ -198,7 +198,7 @@ bool ColorBar::onProcessMessage(JMessage msg)
int col = (i / m_colorsPerColumn); int col = (i / m_colorsPerColumn);
int row = (i % m_colorsPerColumn); int row = (i % m_colorsPerColumn);
color_t color = color_index(m_firstIndex + i); Color color = Color::fromIndex(m_firstIndex + i);
draw_color_button(doublebuffer, entryBounds, draw_color_button(doublebuffer, entryBounds,
row == 0 && col == 0, // nw row == 0 && col == 0, // nw
@ -216,14 +216,14 @@ bool ColorBar::onProcessMessage(JMessage msg)
(m_hot_drag == i && (m_hot_drag == i &&
m_hot_drag != m_hot_drop)); m_hot_drag != m_hot_drop));
if (color_equals(m_bgcolor, color)) { if (m_bgcolor == color) {
theme->draw_bounds_nw(doublebuffer, theme->draw_bounds_nw(doublebuffer,
entryBounds.x, entryBounds.y, entryBounds.x, entryBounds.y,
entryBounds.x+entryBounds.w-1, entryBounds.x+entryBounds.w-1,
entryBounds.y+entryBounds.h-1 - (row == m_colorsPerColumn-1 ? jguiscale(): 0), entryBounds.y+entryBounds.h-1 - (row == m_colorsPerColumn-1 ? jguiscale(): 0),
PART_COLORBAR_BORDER_BG_NW, -1); PART_COLORBAR_BORDER_BG_NW, -1);
} }
if (color_equals(m_fgcolor, color)) { if (m_fgcolor == color) {
theme->draw_bounds_nw(doublebuffer, theme->draw_bounds_nw(doublebuffer,
entryBounds.x, entryBounds.y, entryBounds.x, entryBounds.y,
entryBounds.x+entryBounds.w-1, entryBounds.x+entryBounds.w-1,
@ -317,7 +317,7 @@ bool ColorBar::onProcessMessage(JMessage msg)
// Open the new hot-color to be edited // Open the new hot-color to be edited
if ((m_hot != HOTCOLOR_NONE) && if ((m_hot != HOTCOLOR_NONE) &&
(m_hot_drag == m_hot_drop)) { (m_hot_drag == m_hot_drop)) {
color_t color = getHotColor(m_hot); Color color = getHotColor(m_hot);
updateStatusBar(color, 0); updateStatusBar(color, 0);
} }
@ -403,17 +403,17 @@ bool ColorBar::onProcessMessage(JMessage msg)
/* drag and drop a color */ /* drag and drop a color */
if (m_hot_drag != m_hot_drop) { if (m_hot_drag != m_hot_drop) {
if (m_hot_drop != HOTCOLOR_NONE) { if (m_hot_drop != HOTCOLOR_NONE) {
color_t color = getHotColor(m_hot_drag); Color color = getHotColor(m_hot_drag);
setHotColor(m_hot_drop, color); setHotColor(m_hot_drop, color);
} }
dirty(); dirty();
} }
/* pick the color */ /* pick the color */
else if (m_hot != HOTCOLOR_NONE) { else if (m_hot != HOTCOLOR_NONE) {
color_t color = getHotColor(m_hot); Color color = getHotColor(m_hot);
// Check if the color is invalid (e.g. index out of range) // Check if the color is invalid (e.g. index out of range)
if (color_is_valid(color)) { if (color.isValid()) {
switch (m_hot) { switch (m_hot) {
@ -429,7 +429,7 @@ bool ColorBar::onProcessMessage(JMessage msg)
} }
default: { default: {
color_t color = getHotColor(m_hot); Color color = getHotColor(m_hot);
if (msg->mouse.left) { if (msg->mouse.left) {
this->setFgColor(color); this->setFgColor(color);
@ -467,10 +467,10 @@ bool ColorBar::onProcessMessage(JMessage msg)
return Widget::onProcessMessage(msg); return Widget::onProcessMessage(msg);
} }
color_t ColorBar::getHotColor(hotcolor_t hot) Color ColorBar::getHotColor(hotcolor_t hot)
{ {
switch (hot) { switch (hot) {
case HOTCOLOR_NONE: return color_mask(); case HOTCOLOR_NONE: return Color::fromMask();
case HOTCOLOR_FGCOLOR: return m_fgcolor; case HOTCOLOR_FGCOLOR: return m_fgcolor;
case HOTCOLOR_BGCOLOR: return m_bgcolor; case HOTCOLOR_BGCOLOR: return m_bgcolor;
default: default:
@ -479,7 +479,7 @@ color_t ColorBar::getHotColor(hotcolor_t hot)
} }
} }
void ColorBar::setHotColor(hotcolor_t hot, color_t color) void ColorBar::setHotColor(hotcolor_t hot, const Color& color)
{ {
switch (hot) { switch (hot) {
case HOTCOLOR_NONE: case HOTCOLOR_NONE:
@ -497,22 +497,21 @@ void ColorBar::setHotColor(hotcolor_t hot, color_t color)
m_color[hot] = color; m_color[hot] = color;
if (hot == 0 || hot == m_ncolor-1) { if (hot == 0 || hot == m_ncolor-1) {
int imgtype = app_get_current_image_type();
color_t c1 = m_color[0]; color_t c1 = m_color[0];
color_t c2 = m_color[m_ncolor-1]; color_t c2 = m_color[m_ncolor-1];
int r1 = color_get_red(imgtype, c1); int r1 = c1.getRed();
int g1 = color_get_green(imgtype, c1); int g1 = c1.getGreen();
int b1 = color_get_blue(imgtype, c1); int b1 = c1.getBlue();
int r2 = color_get_red(imgtype, c2); int r2 = c2.getRed();
int g2 = color_get_green(imgtype, c2); int g2 = c2.getGreen();
int b2 = color_get_blue(imgtype, c2); int b2 = c2.getBlue();
int c, r, g, b; int c, r, g, b;
for (c=1; c<m_ncolor-1; ++c) { for (c=1; c<m_ncolor-1; ++c) {
r = r1 + (r2-r1) * c / m_ncolor; r = r1 + (r2-r1) * c / m_ncolor;
g = g1 + (g2-g1) * c / m_ncolor; g = g1 + (g2-g1) * c / m_ncolor;
b = b1 + (b2-b1) * c / m_ncolor; b = b1 + (b2-b1) * c / m_ncolor;
m_color[c] = color_rgb(r, g, b); m_color[c] = Color::fromRgb(r, g, b);
} }
} }
#endif #endif
@ -565,9 +564,9 @@ Rect ColorBar::getBgBounds() const
rc.w, BGBUTTON_SIZE); rc.w, BGBUTTON_SIZE);
} }
void ColorBar::updateStatusBar(color_t color, int msecs) void ColorBar::updateStatusBar(const Color& color, int msecs)
{ {
if (color_is_valid(color)) { if (color.isValid()) {
app_get_statusbar() app_get_statusbar()
->showColor(msecs, "", color, 255); ->showColor(msecs, "", color, 255);
} }

View File

@ -22,7 +22,7 @@
#include "Vaca/Signal.h" #include "Vaca/Signal.h"
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "core/color.h" #include "app/color.h"
class ColorBar : public Widget class ColorBar : public Widget
{ {
@ -36,38 +36,43 @@ public:
ColorBar(int align); ColorBar(int align);
~ColorBar(); ~ColorBar();
color_t getFgColor() const { return m_fgcolor; } Color getFgColor() const { return m_fgcolor; }
color_t getBgColor() const { return m_bgcolor; } Color getBgColor() const { return m_bgcolor; }
void setFgColor(color_t color); void setFgColor(const Color& color);
void setBgColor(color_t color); void setBgColor(const Color& color);
color_t getColorByPosition(int x, int y); Color getColorByPosition(int x, int y);
// Signals // Signals
Vaca::Signal1<void, color_t> FgColorChange; Vaca::Signal1<void, const Color&> FgColorChange;
Vaca::Signal1<void, color_t> BgColorChange; Vaca::Signal1<void, const Color&> BgColorChange;
protected: protected:
bool onProcessMessage(JMessage msg); bool onProcessMessage(JMessage msg);
private: private:
int getEntriesCount() const { return m_columns*m_colorsPerColumn; } int getEntriesCount() const {
color_t getEntryColor(int i) const { return color_index(i+m_firstIndex); } return m_columns*m_colorsPerColumn;
}
color_t getHotColor(hotcolor_t hot); Color getEntryColor(int i) const {
void setHotColor(hotcolor_t hot, color_t color); return Color::fromIndex(i+m_firstIndex);
}
Color getHotColor(hotcolor_t hot);
void setHotColor(hotcolor_t hot, const Color& color);
Rect getColumnBounds(int column) const; Rect getColumnBounds(int column) const;
Rect getEntryBounds(int index) const; Rect getEntryBounds(int index) const;
Rect getFgBounds() const; Rect getFgBounds() const;
Rect getBgBounds() const; Rect getBgBounds() const;
void updateStatusBar(color_t color, int msecs); void updateStatusBar(const Color& color, int msecs);
int m_firstIndex; int m_firstIndex;
int m_columns; int m_columns;
int m_colorsPerColumn; int m_colorsPerColumn;
int m_entrySize; int m_entrySize;
color_t m_fgcolor; Color m_fgcolor;
color_t m_bgcolor; Color m_bgcolor;
hotcolor_t m_hot; hotcolor_t m_hot;
hotcolor_t m_hot_editing; hotcolor_t m_hot_editing;

View File

@ -23,7 +23,8 @@
#include "jinete/jinete.h" #include "jinete/jinete.h"
#include "Vaca/PreferredSizeEvent.h" #include "Vaca/PreferredSizeEvent.h"
#include "core/color.h" #include "app/color_utils.h"
#include "app/color.h"
#include "modules/gfx.h" #include "modules/gfx.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/sprite.h" #include "raster/sprite.h"
@ -42,13 +43,12 @@ static int colorbutton_type()
return type; return type;
} }
ColorButton::ColorButton(color_t color, int imgtype) ColorButton::ColorButton(const Color& color, int imgtype)
: ButtonBase("", colorbutton_type(), JI_BUTTON, JI_BUTTON) : ButtonBase("", colorbutton_type(), JI_BUTTON, JI_BUTTON)
, m_color(color)
, m_imgtype(imgtype)
, m_tooltip_window(NULL)
{ {
m_color = color;
m_imgtype = imgtype;
m_tooltip_window = NULL;
jwidget_focusrest(this, true); jwidget_focusrest(this, true);
} }
@ -58,17 +58,17 @@ ColorButton::~ColorButton()
delete m_tooltip_window; // widget, frame delete m_tooltip_window; // widget, frame
} }
int ColorButton::getImgType() int ColorButton::getImgType() const
{ {
return m_imgtype; return m_imgtype;
} }
color_t ColorButton::getColor() Color ColorButton::getColor() const
{ {
return m_color; return m_color;
} }
void ColorButton::setColor(color_t color) void ColorButton::setColor(const Color& color)
{ {
m_color = color; m_color = color;
dirty(); dirty();
@ -103,7 +103,7 @@ bool ColorButton::onProcessMessage(JMessage msg)
JWidget picked = jwidget_pick(ji_get_default_manager(), JWidget picked = jwidget_pick(ji_get_default_manager(),
msg->mouse.x, msg->mouse.x,
msg->mouse.y); msg->mouse.y);
color_t color = this->m_color; Color color = this->m_color;
if (picked && picked != this) { if (picked && picked != this) {
// Pick a color from another color-button // Pick a color from another color-button
@ -125,13 +125,13 @@ bool ColorButton::onProcessMessage(JMessage msg)
y = msg->mouse.y; y = msg->mouse.y;
editor->screen_to_editor(x, y, &x, &y); editor->screen_to_editor(x, y, &x, &y);
imgcolor = sprite->getPixel(x, y); imgcolor = sprite->getPixel(x, y);
color = color_from_image(sprite->getImgType(), imgcolor); color = Color::fromImage(sprite->getImgType(), imgcolor);
} }
} }
} }
/* does the color change? */ // Did the color change?
if (!color_equals(color, this->m_color)) { if (color != this->m_color) {
this->setColor(color); this->setColor(color);
jwidget_emit_signal(this, SIGNAL_COLORBUTTON_CHANGE); jwidget_emit_signal(this, SIGNAL_COLORBUTTON_CHANGE);
} }
@ -165,19 +165,18 @@ void ColorButton::onPreferredSize(PreferredSizeEvent& ev)
void ColorButton::draw() void ColorButton::draw()
{ {
struct jrect box, text, icon; struct jrect box, text, icon;
char buf[256];
jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0);
jdraw_rectfill(this->rc, ji_color_face()); jdraw_rectfill(this->rc, ji_color_face());
color_t color; Color color;
// When the button is pushed, show the negative // When the button is pushed, show the negative
if (this->isSelected()) { if (this->isSelected()) {
color = color_rgb(255-color_get_red(this->m_color), color = Color::fromRgb(255-m_color.getRed(),
255-color_get_green(this->m_color), 255-m_color.getGreen(),
255-color_get_blue(this->m_color)); 255-m_color.getBlue());
} }
// When the button is not pressed, show the real color // When the button is not pressed, show the real color
else else
@ -193,15 +192,15 @@ void ColorButton::draw()
this->hasMouseOver(), false); this->hasMouseOver(), false);
// Draw text // Draw text
color_to_formalstring(this->m_imgtype, std::string str =
this->m_color, buf, sizeof(buf), false); this->m_color.toFormalString(this->m_imgtype, false);
this->setTextQuiet(buf); this->setTextQuiet(str.c_str());
jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0);
int textcolor = blackandwhite_neg(color_get_red(color), int textcolor = color_utils::blackandwhite_neg(color.getRed(),
color_get_green(color), color.getGreen(),
color_get_blue(color)); color.getBlue());
jdraw_text(ji_screen, this->getFont(), this->getText(), text.x1, text.y1, jdraw_text(ji_screen, this->getFont(), this->getText(), text.x1, text.y1,
textcolor, -1, false, jguiscale()); textcolor, -1, false, jguiscale());
} }
@ -263,7 +262,7 @@ static bool tooltip_window_msg_proc(JWidget widget, JMessage msg)
case JM_SIGNAL: case JM_SIGNAL:
if (msg->signal.num == SIGNAL_COLORSELECTOR_COLOR_CHANGED) { if (msg->signal.num == SIGNAL_COLORSELECTOR_COLOR_CHANGED) {
ColorButton* colorbutton_widget = (ColorButton*)widget->user_data[0]; ColorButton* colorbutton_widget = (ColorButton*)widget->user_data[0];
color_t color = colorselector_get_color(widget); Color color = colorselector_get_color(widget);
colorbutton_widget->setColor(color); colorbutton_widget->setColor(color);
jwidget_emit_signal(colorbutton_widget, SIGNAL_COLORBUTTON_CHANGE); jwidget_emit_signal(colorbutton_widget, SIGNAL_COLORBUTTON_CHANGE);

View File

@ -19,7 +19,7 @@
#ifndef WIDGETS_COLOR_BUTTON_H_INCLUDED #ifndef WIDGETS_COLOR_BUTTON_H_INCLUDED
#define WIDGETS_COLOR_BUTTON_H_INCLUDED #define WIDGETS_COLOR_BUTTON_H_INCLUDED
#include "core/color.h" #include "app/color.h"
#include "jinete/jbutton.h" #include "jinete/jbutton.h"
class Frame; class Frame;
@ -30,13 +30,13 @@ class Frame;
class ColorButton : public ButtonBase class ColorButton : public ButtonBase
{ {
public: public:
ColorButton(color_t color, int imgtype); ColorButton(const Color& color, int imgtype);
~ColorButton(); ~ColorButton();
int getImgType(); int getImgType() const;
color_t getColor(); Color getColor() const;
void setColor(color_t color); void setColor(const Color& color);
protected: protected:
// Events // Events
@ -48,7 +48,7 @@ private:
void openSelectorDialog(); void openSelectorDialog();
void closeSelectorDialog(); void closeSelectorDialog();
color_t m_color; Color m_color;
int m_imgtype; int m_imgtype;
Frame* m_tooltip_window; Frame* m_tooltip_window;
}; };

View File

@ -25,7 +25,7 @@
#include "Vaca/Bind.h" #include "Vaca/Bind.h"
#include "app.h" #include "app.h"
#include "core/color.h" #include "app/color.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "modules/gfx.h" #include "modules/gfx.h"
#include "modules/palettes.h" #include "modules/palettes.h"
@ -41,17 +41,16 @@ enum {
MODEL_MASK MODEL_MASK
}; };
typedef struct Model struct Model
{ {
const char *text; const char *text;
int model; int model;
int color_type;
Widget* (*create)(); Widget* (*create)();
} Model; };
struct ColorSelector struct ColorSelector
{ {
color_t color; Color color;
Model* selected_model; Model* selected_model;
std::vector<Widget*> model_buttons; std::vector<Widget*> model_buttons;
}; };
@ -64,7 +63,7 @@ static Widget* create_mask_container();
static int colorselector_type(); static int colorselector_type();
static ColorSelector* colorselector_data(JWidget widget); static ColorSelector* colorselector_data(JWidget widget);
static bool colorselector_msg_proc(JWidget widget, JMessage msg); static bool colorselector_msg_proc(JWidget widget, JMessage msg);
static void colorselector_set_color2(JWidget widget, color_t color, static void colorselector_set_color2(JWidget widget, const Color& color,
bool update_index_entry, bool update_index_entry,
bool select_index_entry, bool select_index_entry,
Model* exclude_this_model); Model* exclude_this_model);
@ -76,11 +75,11 @@ static bool slider_change_hook(JWidget widget, void* data);
static bool paledit_change_hook(JWidget widget, void* data); static bool paledit_change_hook(JWidget widget, void* data);
static Model models[] = { static Model models[] = {
{ "RGB", MODEL_RGB, COLOR_TYPE_RGB, create_rgb_container }, { "RGB", MODEL_RGB, create_rgb_container },
{ "HSV", MODEL_HSV, COLOR_TYPE_RGB, create_hsv_container }, { "HSV", MODEL_HSV, create_hsv_container },
{ "Gray", MODEL_GRAY, COLOR_TYPE_GRAY, create_gray_container }, { "Gray", MODEL_GRAY, create_gray_container },
{ "Mask", MODEL_MASK, COLOR_TYPE_MASK, create_mask_container }, { "Mask", MODEL_MASK, create_mask_container },
{ NULL, 0, 0, NULL } { NULL, 0, NULL }
}; };
Frame* colorselector_new() Frame* colorselector_new()
@ -100,7 +99,7 @@ Frame* colorselector_new()
grid2->setName("grid2"); grid2->setName("grid2");
/* color selector */ /* color selector */
colorselector->color = color_mask(); colorselector->color = Color::fromMask();
colorselector->selected_model = &models[0]; colorselector->selected_model = &models[0];
/* palette */ /* palette */
@ -146,12 +145,12 @@ Frame* colorselector_new()
return window; return window;
} }
void colorselector_set_color(JWidget widget, color_t color) void colorselector_set_color(JWidget widget, const Color& color)
{ {
colorselector_set_color2(widget, color, true, true, NULL); colorselector_set_color2(widget, color, true, true, NULL);
} }
color_t colorselector_get_color(JWidget widget) Color colorselector_get_color(JWidget widget)
{ {
ColorSelector* colorselector = colorselector_data(widget); ColorSelector* colorselector = colorselector_data(widget);
@ -279,7 +278,7 @@ static bool colorselector_msg_proc(JWidget widget, JMessage msg)
return false; return false;
} }
static void colorselector_set_color2(JWidget widget, color_t color, static void colorselector_set_color2(JWidget widget, const Color& color,
bool update_index_entry, bool update_index_entry,
bool select_index_entry, bool select_index_entry,
Model* exclude_this_model) Model* exclude_this_model)
@ -297,36 +296,36 @@ static void colorselector_set_color2(JWidget widget, color_t color,
colorselector->color = color; colorselector->color = color;
if (exclude_this_model != models+MODEL_RGB) { if (exclude_this_model != models+MODEL_RGB) {
jslider_set_value(rgb_rslider, color_get_red(color)); jslider_set_value(rgb_rslider, color.getRed());
jslider_set_value(rgb_gslider, color_get_green(color)); jslider_set_value(rgb_gslider, color.getGreen());
jslider_set_value(rgb_bslider, color_get_blue(color)); jslider_set_value(rgb_bslider, color.getBlue());
} }
if (exclude_this_model != models+MODEL_HSV) { if (exclude_this_model != models+MODEL_HSV) {
jslider_set_value(hsv_hslider, color_get_hue(color)); jslider_set_value(hsv_hslider, color.getHue());
jslider_set_value(hsv_sslider, color_get_saturation(color)); jslider_set_value(hsv_sslider, color.getSaturation());
jslider_set_value(hsv_vslider, color_get_value(color)); jslider_set_value(hsv_vslider, color.getValue());
} }
if (exclude_this_model != models+MODEL_GRAY) { if (exclude_this_model != models+MODEL_GRAY) {
jslider_set_value(gray_vslider, color_get_value(color)); jslider_set_value(gray_vslider, color.getValue());
} }
switch (color_type(color)) { switch (color.getType()) {
case COLOR_TYPE_MASK: case Color::MaskType:
m = models+MODEL_MASK; m = models+MODEL_MASK;
break; break;
case COLOR_TYPE_RGB: case Color::RgbType:
m = models+MODEL_RGB; m = models+MODEL_RGB;
break; break;
case COLOR_TYPE_INDEX: case Color::IndexType:
if (m != models+MODEL_RGB && if (m != models+MODEL_RGB &&
m != models+MODEL_HSV) { m != models+MODEL_HSV) {
m = models+MODEL_RGB; m = models+MODEL_RGB;
} }
break; break;
case COLOR_TYPE_HSV: case Color::HsvType:
m = models+MODEL_HSV; m = models+MODEL_HSV;
break; break;
case COLOR_TYPE_GRAY: case Color::GrayType:
m = models+MODEL_GRAY; m = models+MODEL_GRAY;
break; break;
default: default:
@ -341,17 +340,17 @@ static void colorselector_set_color2(JWidget widget, color_t color,
select_model_hook(dynamic_cast<Frame*>(widget->getRoot()), m); select_model_hook(dynamic_cast<Frame*>(widget->getRoot()), m);
if (update_index_entry) { if (update_index_entry) {
switch (color_type(color)) { switch (color.getType()) {
case COLOR_TYPE_INDEX: case Color::IndexType:
colorselector_set_paledit_index(widget, color_get_index(color), select_index_entry); colorselector_set_paledit_index(widget, color.getIndex(), select_index_entry);
break; break;
case COLOR_TYPE_MASK: case Color::MaskType:
colorselector_set_paledit_index(widget, 0, true); colorselector_set_paledit_index(widget, 0, true);
break; break;
default: { default: {
int r = color_get_red (color); int r = color.getRed();
int g = color_get_green(color); int g = color.getGreen();
int b = color_get_blue (color); int b = color.getBlue();
int i = get_current_palette()->findBestfit(r, g, b); int i = get_current_palette()->findBestfit(r, g, b);
if (i >= 0 && i < 256) if (i >= 0 && i < 256)
colorselector_set_paledit_index(widget, i, true); colorselector_set_paledit_index(widget, i, true);
@ -416,7 +415,7 @@ static bool select_model_hook(Frame* frame, Model* selected_model)
if (something_change) { if (something_change) {
// Select the mask color // Select the mask color
if (selected_model->model == MODEL_MASK) { if (selected_model->model == MODEL_MASK) {
colorselector_set_color2(frame, color_mask(), false, false, NULL); colorselector_set_color2(frame, Color::fromMask(), false, false, NULL);
jwidget_emit_signal(frame, SIGNAL_COLORSELECTOR_COLOR_CHANGED); jwidget_emit_signal(frame, SIGNAL_COLORSELECTOR_COLOR_CHANGED);
} }
@ -431,7 +430,7 @@ static bool slider_change_hook(JWidget widget, void* data)
Frame* window = static_cast<Frame*>(widget->getRoot()); Frame* window = static_cast<Frame*>(widget->getRoot());
ColorSelector* colorselector = colorselector_data(window); ColorSelector* colorselector = colorselector_data(window);
Model* m = colorselector->selected_model; Model* m = colorselector->selected_model;
color_t color = colorselector->color; Color color = colorselector->color;
int i, r, g, b; int i, r, g, b;
switch (m->model) { switch (m->model) {
@ -442,7 +441,7 @@ static bool slider_change_hook(JWidget widget, void* data)
int r = jslider_get_value(rslider); int r = jslider_get_value(rslider);
int g = jslider_get_value(gslider); int g = jslider_get_value(gslider);
int b = jslider_get_value(bslider); int b = jslider_get_value(bslider);
color = color_rgb(r, g, b); color = Color::fromRgb(r, g, b);
break; break;
} }
case MODEL_HSV: { case MODEL_HSV: {
@ -452,20 +451,20 @@ static bool slider_change_hook(JWidget widget, void* data)
int h = jslider_get_value(hslider); int h = jslider_get_value(hslider);
int s = jslider_get_value(sslider); int s = jslider_get_value(sslider);
int v = jslider_get_value(vslider); int v = jslider_get_value(vslider);
color = color_hsv(h, s, v); color = Color::fromHsv(h, s, v);
break; break;
} }
case MODEL_GRAY: { case MODEL_GRAY: {
JWidget vslider = jwidget_find_name(window, "gray_v"); JWidget vslider = jwidget_find_name(window, "gray_v");
int v = jslider_get_value(vslider); int v = jslider_get_value(vslider);
color = color_gray(v); color = Color::fromGray(v);
break; break;
} }
} }
r = color_get_red (color); r = color.getRed();
g = color_get_green(color); g = color.getGreen();
b = color_get_blue (color); b = color.getBlue();
// Search for the closest color to the RGB values // Search for the closest color to the RGB values
i = get_current_palette()->findBestfit(r, g, b); i = get_current_palette()->findBestfit(r, g, b);
@ -482,13 +481,13 @@ static bool paledit_change_hook(Widget* widget, void* data)
Frame* window = static_cast<Frame*>(widget->getRoot()); Frame* window = static_cast<Frame*>(widget->getRoot());
PalEdit* paledit = static_cast<PalEdit*>(widget); PalEdit* paledit = static_cast<PalEdit*>(widget);
bool array[256]; bool array[256];
color_t color = colorselector_get_color(window); Color color = colorselector_get_color(window);
int i; int i;
paledit->getSelectedEntries(array); paledit->getSelectedEntries(array);
for (i=0; i<256; ++i) for (i=0; i<256; ++i)
if (array[i]) { if (array[i]) {
color = color_index(i); color = Color::fromIndex(i);
break; break;
} }

View File

@ -21,7 +21,7 @@
#include "jinete/jbase.h" #include "jinete/jbase.h"
#include "core/color.h" #include "app/color.h"
class Frame; class Frame;
@ -30,9 +30,9 @@ class Frame;
Frame* colorselector_new(); Frame* colorselector_new();
void colorselector_set_color(JWidget widget, color_t color); void colorselector_set_color(Widget* widget, const Color& color);
color_t colorselector_get_color(JWidget widget); Color colorselector_get_color(Widget* widget);
JWidget colorselector_get_paledit(JWidget widget); Widget* colorselector_get_paledit(Widget* widget);
#endif #endif

View File

@ -35,14 +35,14 @@
typedef struct ColorViewer typedef struct ColorViewer
{ {
color_t color; Color color;
int imgtype; int imgtype;
} ColorViewer; } ColorViewer;
static ColorViewer *colorviewer_data(JWidget widget); static ColorViewer *colorviewer_data(JWidget widget);
static bool colorviewer_msg_proc(JWidget widget, JMessage msg); static bool colorviewer_msg_proc(JWidget widget, JMessage msg);
JWidget colorviewer_new(color_t color, int imgtype) JWidget colorviewer_new(const Color& color, int imgtype)
{ {
Widget* widget = new Widget(colorviewer_type()); Widget* widget = new Widget(colorviewer_type());
ColorViewer *colorviewer = jnew(ColorViewer, 1); ColorViewer *colorviewer = jnew(ColorViewer, 1);
@ -74,14 +74,14 @@ int colorviewer_get_imgtype(JWidget widget)
return colorviewer->imgtype; return colorviewer->imgtype;
} }
color_t colorviewer_get_color(JWidget widget) Color colorviewer_get_color(JWidget widget)
{ {
ColorViewer *colorviewer = colorviewer_data(widget); ColorViewer *colorviewer = colorviewer_data(widget);
return colorviewer->color; return colorviewer->color;
} }
void colorviewer_set_color(JWidget widget, color_t color) void colorviewer_set_color(JWidget widget, const Color& color)
{ {
ColorViewer *colorviewer = colorviewer_data(widget); ColorViewer *colorviewer = colorviewer_data(widget);
@ -117,7 +117,6 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg)
case JM_DRAW: { case JM_DRAW: {
struct jrect box, text, icon; struct jrect box, text, icon;
JRect rect = jwidget_get_rect(widget); JRect rect = jwidget_get_rect(widget);
char buf[256];
jdraw_rectedge(rect, jdraw_rectedge(rect,
makecol(128, 128, 128), makecol(128, 128, 128),
@ -134,11 +133,11 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg)
colorviewer->imgtype, colorviewer->imgtype,
colorviewer->color); colorviewer->color);
/* draw text */ // Draw text
color_to_formalstring(colorviewer->imgtype, std::string str =
colorviewer->color, buf, sizeof(buf), false); colorviewer->color.toFormalString(colorviewer->imgtype, false);
widget->setTextQuiet(buf); widget->setTextQuiet(str.c_str());
jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0);
jdraw_rectfill(&text, makecol(0, 0, 0)); jdraw_rectfill(&text, makecol(0, 0, 0));

View File

@ -21,17 +21,17 @@
#include "jinete/jbase.h" #include "jinete/jbase.h"
#include "core/color.h" #include "app/color.h"
// TODO use some JI_SIGNAL_USER // TODO use some JI_SIGNAL_USER
#define SIGNAL_COLORVIEWER_SELECT 0x10002 #define SIGNAL_COLORVIEWER_SELECT 0x10002
JWidget colorviewer_new(color_t color, int imgtype); JWidget colorviewer_new(const Color& color, int imgtype);
int colorviewer_type(); int colorviewer_type();
int colorviewer_get_imgtype(JWidget colorviewer); int colorviewer_get_imgtype(JWidget colorviewer);
color_t colorviewer_get_color(JWidget colorviewer); Color colorviewer_get_color(JWidget colorviewer);
void colorviewer_set_color(JWidget colorviewer, color_t color); void colorviewer_set_color(JWidget colorviewer, const Color& color);
#endif #endif

View File

@ -21,7 +21,7 @@
#include "jinete/jbase.h" #include "jinete/jbase.h"
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "core/color.h" #include "app/color.h"
#include "Vaca/Signal.h" #include "Vaca/Signal.h"
#define MIN_ZOOM 0 #define MIN_ZOOM 0
@ -141,7 +141,7 @@ public:
void editor_draw_mask_safe(); void editor_draw_mask_safe();
void flashCurrentLayer(); void flashCurrentLayer();
void setMaskColorForPixelsMovement(color_t color); void setMaskColorForPixelsMovement(const Color& color);
void screen_to_editor(int xin, int yin, int *xout, int *yout); void screen_to_editor(int xin, int yin, int *xout, int *yout);
void editor_to_screen(int xin, int yin, int *xout, int *yout); void editor_to_screen(int xin, int yin, int *xout, int *yout);
@ -157,8 +157,8 @@ public:
static int get_raw_cursor_color(); static int get_raw_cursor_color();
static bool is_cursor_mask(); static bool is_cursor_mask();
static color_t get_cursor_color(); static Color get_cursor_color();
static void set_cursor_color(color_t color); static void set_cursor_color(const Color& color);
static void editor_cursor_init(); static void editor_cursor_init();
static void editor_cursor_exit(); static void editor_cursor_exit();
@ -197,7 +197,7 @@ protected:
void onCurrentToolChange(); void onCurrentToolChange();
private: private:
void drawGrid(const Rect& gridBounds, color_t color); void drawGrid(const Rect& gridBounds, const Color& color);
void addDecorator(Decorator* decorator); void addDecorator(Decorator* decorator);
void deleteDecorators(); void deleteDecorators();

View File

@ -28,8 +28,9 @@
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "app.h" #include "app.h"
#include "app/color_utils.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "raster/image.h" #include "raster/image.h"
#include "raster/layer.h" #include "raster/layer.h"
@ -97,19 +98,18 @@ static int get_pen_color(Sprite *sprite);
// CURSOR COLOR // CURSOR COLOR
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
static color_t cursor_color; static Color cursor_color;
static int _cursor_color; static int _cursor_color;
static bool _cursor_mask; static bool _cursor_mask;
static void update_cursor_color() static void update_cursor_color()
{ {
if (ji_screen) if (ji_screen)
_cursor_color = get_color_for_allegro(bitmap_color_depth(ji_screen), _cursor_color = color_utils::color_for_allegro(cursor_color, bitmap_color_depth(ji_screen));
cursor_color);
else else
_cursor_color = 0; _cursor_color = 0;
_cursor_mask = (color_type(cursor_color) == COLOR_TYPE_MASK); _cursor_mask = (cursor_color.getType() == Color::MaskType);
} }
int Editor::get_raw_cursor_color() int Editor::get_raw_cursor_color()
@ -122,12 +122,12 @@ bool Editor::is_cursor_mask()
return _cursor_mask; return _cursor_mask;
} }
color_t Editor::get_cursor_color() Color Editor::get_cursor_color()
{ {
return cursor_color; return cursor_color;
} }
void Editor::set_cursor_color(color_t color) void Editor::set_cursor_color(const Color& color)
{ {
cursor_color = color; cursor_color = color;
update_cursor_color(); update_cursor_color();
@ -197,7 +197,7 @@ static Pen* editor_get_current_pen()
void Editor::editor_cursor_init() void Editor::editor_cursor_init()
{ {
/* cursor color */ /* cursor color */
set_cursor_color(get_config_color("Tools", "CursorColor", color_mask())); set_cursor_color(get_config_color("Tools", "CursorColor", Color::fromMask()));
App::instance()->PaletteChange.connect(&on_palette_change_update_cursor_color); App::instance()->PaletteChange.connect(&on_palette_change_update_cursor_color);
App::instance()->PenSizeBeforeChange.connect(&on_pen_size_before_change); App::instance()->PenSizeBeforeChange.connect(&on_pen_size_before_change);
@ -258,7 +258,7 @@ void Editor::editor_draw_cursor(int x, int y, bool refresh)
else if (// Use cursor bounds for inks that are effects (eraser, blur, etc.) else if (// Use cursor bounds for inks that are effects (eraser, blur, etc.)
current_tool->getInk(0)->isEffect() || current_tool->getInk(0)->isEffect() ||
// or when the FG color is mask and we are not in the background layer // or when the FG color is mask and we are not in the background layer
(color_type(UIContext::instance()->getSettings()->getFgColor()) == COLOR_TYPE_MASK && (UIContext::instance()->getSettings()->getFgColor().getType() == Color::MaskType &&
(m_sprite->getCurrentLayer() != NULL && (m_sprite->getCurrentLayer() != NULL &&
!m_sprite->getCurrentLayer()->is_background()))) { !m_sprite->getCurrentLayer()->is_background()))) {
cursor_type = CURSOR_BOUNDS; cursor_type = CURSOR_BOUNDS;
@ -643,7 +643,7 @@ static void drawpixel(BITMAP *bmp, int x, int y, int color)
g = getg(c); g = getg(c);
b = getb(c); b = getb(c);
putpixel(bmp, x, y, blackandwhite_neg(r, g, b)); putpixel(bmp, x, y, color_utils::blackandwhite_neg(r, g, b));
} }
else { else {
putpixel(bmp, x, y, color); putpixel(bmp, x, y, color);
@ -670,15 +670,15 @@ static int point_inside_region(int x, int y, JRegion region)
static int get_pen_color(Sprite *sprite) static int get_pen_color(Sprite *sprite)
{ {
color_t c = UIContext::instance()->getSettings()->getFgColor(); Color c = UIContext::instance()->getSettings()->getFgColor();
ASSERT(sprite != NULL); ASSERT(sprite != NULL);
// Avoid using invalid colors // Avoid using invalid colors
if (!color_is_valid(c)) if (!c.isValid())
return 0; return 0;
if (sprite->getCurrentLayer() != NULL) if (sprite->getCurrentLayer() != NULL)
return get_color_for_layer(sprite->getCurrentLayer(), c); return color_utils::color_for_layer(c, sprite->getCurrentLayer());
else else
return get_color_for_image(sprite->getImgType(), c); return color_utils::color_for_image(c, sprite->getImgType());
} }

View File

@ -29,8 +29,9 @@
#include "commands/commands.h" #include "commands/commands.h"
#include "commands/params.h" #include "commands/params.h"
#include "app.h" #include "app.h"
#include "app/color_utils.h"
#include "core/cfg.h" #include "core/cfg.h"
#include "core/color.h" #include "app/color.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "modules/gfx.h" #include "modules/gfx.h"
#include "modules/gui.h" #include "modules/gui.h"
@ -485,13 +486,13 @@ void Editor::editor_draw_mask_safe()
} }
} }
void Editor::drawGrid(const Rect& gridBounds, color_t color) void Editor::drawGrid(const Rect& gridBounds, const Color& color)
{ {
Rect grid(gridBounds); Rect grid(gridBounds);
if (grid.w < 1 || grid.h < 1) if (grid.w < 1 || grid.h < 1)
return; return;
int grid_color = get_color_for_allegro(bitmap_color_depth(ji_screen), color); int grid_color = color_utils::color_for_allegro(color, bitmap_color_depth(ji_screen));
JWidget view = jwidget_get_view(this); JWidget view = jwidget_get_view(this);
JRect vp = jview_get_viewport_position(view); JRect vp = jview_get_viewport_position(view);
int scroll_x, scroll_y; int scroll_x, scroll_y;
@ -558,9 +559,9 @@ void Editor::flashCurrentLayer()
v-y >= 0 && v-y < src_image->h) { v-y >= 0 && v-y < src_image->h) {
ase_uint32 color = image_getpixel(src_image, u-x, v-y); ase_uint32 color = image_getpixel(src_image, u-x, v-y);
if (color != src_image->mask_color) { if (color != src_image->mask_color) {
color_t ccc = color_rgb(255, 255, 255); Color ccc = Color::fromRgb(255, 255, 255);
image_putpixel(flash_image, u, v, image_putpixel(flash_image, u, v,
get_color_for_image(flash_image->imgtype, ccc)); color_utils::color_for_image(ccc, flash_image->imgtype));
} }
} }
} }
@ -577,13 +578,13 @@ void Editor::flashCurrentLayer()
} }
} }
void Editor::setMaskColorForPixelsMovement(color_t color) void Editor::setMaskColorForPixelsMovement(const Color& color)
{ {
ASSERT(m_sprite != NULL); ASSERT(m_sprite != NULL);
ASSERT(m_pixelsMovement != NULL); ASSERT(m_pixelsMovement != NULL);
int imgtype = m_sprite->getImgType(); int imgtype = m_sprite->getImgType();
m_pixelsMovement->setMaskColor(get_color_for_image(imgtype, color)); m_pixelsMovement->setMaskColor(color_utils::color_for_image(color, imgtype));
} }
void Editor::deleteDecorators() void Editor::deleteDecorators()
@ -743,7 +744,7 @@ void Editor::editor_update_statusbar_for_standby()
current_tool->getInk(0)->isEyedropper()) { current_tool->getInk(0)->isEyedropper()) {
int imgtype = m_sprite->getImgType(); int imgtype = m_sprite->getImgType();
ase_uint32 pixel = m_sprite->getPixel(x, y); ase_uint32 pixel = m_sprite->getPixel(x, y);
color_t color = color_from_image(imgtype, pixel); Color color = Color::fromImage(imgtype, pixel);
int alpha = 255; int alpha = 255;
switch (imgtype) { switch (imgtype) {
@ -1425,22 +1426,22 @@ bool Editor::onProcessMessage(JMessage msg)
case WHEEL_FG: case WHEEL_FG:
if (m_state == EDITOR_STATE_STANDBY) { if (m_state == EDITOR_STATE_STANDBY) {
int newIndex = 0; int newIndex = 0;
if (color_type(app_get_colorbar()->getFgColor()) == COLOR_TYPE_INDEX) { if (app_get_colorbar()->getFgColor().getType() == Color::IndexType) {
newIndex = color_get_index(app_get_colorbar()->getFgColor()) + dz; newIndex = app_get_colorbar()->getFgColor().getIndex() + dz;
newIndex = MID(0, newIndex, 255); newIndex = MID(0, newIndex, 255);
} }
app_get_colorbar()->setFgColor(color_index(newIndex)); app_get_colorbar()->setFgColor(Color::fromIndex(newIndex));
} }
break; break;
case WHEEL_BG: case WHEEL_BG:
if (m_state == EDITOR_STATE_STANDBY) { if (m_state == EDITOR_STATE_STANDBY) {
int newIndex = 0; int newIndex = 0;
if (color_type(app_get_colorbar()->getBgColor()) == COLOR_TYPE_INDEX) { if (app_get_colorbar()->getBgColor().getType() == Color::IndexType) {
newIndex = color_get_index(app_get_colorbar()->getBgColor()) + dz; newIndex = app_get_colorbar()->getBgColor().getIndex() + dz;
newIndex = MID(0, newIndex, 255); newIndex = MID(0, newIndex, 255);
} }
app_get_colorbar()->setBgColor(color_index(newIndex)); app_get_colorbar()->setBgColor(Color::fromIndex(newIndex));
} }
break; break;
@ -1798,7 +1799,7 @@ class ToolLoopImpl : public IToolLoop
public: public:
ToolLoopImpl(Editor* editor, Context* context, Tool* tool, Sprite* sprite, Layer* layer, ToolLoopImpl(Editor* editor, Context* context, Tool* tool, Sprite* sprite, Layer* layer,
int button, color_t primary_color, color_t secondary_color) int button, const Color& primary_color, const Color& secondary_color)
{ {
m_editor = editor; m_editor = editor;
m_context = context; m_context = context;
@ -1810,8 +1811,8 @@ public:
m_cel_created = false; m_cel_created = false;
m_canceled = false; m_canceled = false;
m_button = button; m_button = button;
m_primary_color = get_color_for_layer(layer, primary_color); m_primary_color = color_utils::color_for_layer(primary_color, layer);
m_secondary_color = get_color_for_layer(layer, secondary_color); m_secondary_color = color_utils::color_for_layer(secondary_color, layer);
// Settings // Settings
ISettings* settings = m_context->getSettings(); ISettings* settings = m_context->getSettings();
@ -2118,10 +2119,10 @@ IToolLoop* Editor::createToolLoopImpl(Context* context, JMessage msg)
// Get fg/bg colors // Get fg/bg colors
ColorBar* colorbar = app_get_colorbar(); ColorBar* colorbar = app_get_colorbar();
color_t fg = colorbar->getFgColor(); Color fg = colorbar->getFgColor();
color_t bg = colorbar->getBgColor(); Color bg = colorbar->getBgColor();
if (!color_is_valid(fg) || !color_is_valid(bg)) { if (!fg.isValid() || !bg.isValid()) {
jalert(PACKAGE jalert(PACKAGE
"<<The current selected foreground and/or background color" "<<The current selected foreground and/or background color"
"<<is out of range. Select valid colors in the color-bar." "<<is out of range. Select valid colors in the color-bar."

View File

@ -26,7 +26,7 @@
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "app.h" #include "app.h"
#include "core/color.h" #include "app/color.h"
#include "modules/editors.h" #include "modules/editors.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "raster/image.h" #include "raster/image.h"

View File

@ -30,7 +30,7 @@
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "jinete/jtheme.h" #include "jinete/jtheme.h"
#include "core/color.h" #include "app/color.h"
#include "modules/gui.h" #include "modules/gui.h"
#include "modules/palettes.h" #include "modules/palettes.h"
#include "raster/blend.h" #include "raster/blend.h"

View File

@ -73,6 +73,7 @@ static int statusbar_type()
StatusBar::StatusBar() StatusBar::StatusBar()
: Widget(statusbar_type()) : Widget(statusbar_type())
, m_color(Color::fromMask())
{ {
#define BUTTON_NEW(name, text, action) \ #define BUTTON_NEW(name, text, action) \
{ \ { \
@ -144,7 +145,7 @@ StatusBar::StatusBar()
m_movePixelsBox = jbox_new(JI_HORIZONTAL); m_movePixelsBox = jbox_new(JI_HORIZONTAL);
m_transparentLabel = new Label("Transparent Color:"); m_transparentLabel = new Label("Transparent Color:");
m_transparentColor = new ColorButton(color_mask(), IMAGE_RGB); m_transparentColor = new ColorButton(Color::fromMask(), IMAGE_RGB);
jwidget_add_child(m_movePixelsBox, filler); jwidget_add_child(m_movePixelsBox, filler);
jwidget_add_child(m_movePixelsBox, m_transparentLabel); jwidget_add_child(m_movePixelsBox, m_transparentLabel);
@ -247,7 +248,7 @@ void StatusBar::showTip(int msecs, const char *format, ...)
this->dirty(); this->dirty();
} }
void StatusBar::showColor(int msecs, const char* text, color_t color, int alpha) void StatusBar::showColor(int msecs, const char* text, const Color& color, int alpha)
{ {
if (setStatusText(msecs, text)) { if (setStatusText(msecs, text)) {
m_state = SHOW_COLOR; m_state = SHOW_COLOR;
@ -296,7 +297,7 @@ void StatusBar::hideMovePixelsOptions()
} }
} }
color_t StatusBar::getTransparentColor() Color StatusBar::getTransparentColor()
{ {
return m_transparentColor->getColor(); return m_transparentColor->getColor();
} }
@ -435,17 +436,18 @@ bool StatusBar::onProcessMessage(JMessage msg)
x += (32+4)*jguiscale(); x += (32+4)*jguiscale();
// Draw color description // Draw color description
char buf[512]; // TODO warning buffer overflow std::string str = m_color.toFormalString(app_get_current_image_type(), true);
color_to_formalstring(app_get_current_image_type(), if (m_alpha < 255) {
m_color, buf, sizeof(buf), true); char buf[512];
if (m_alpha < 255) usprintf(buf, ", Alpha %d", m_alpha);
usprintf(buf+ustrlen(buf), ", Alpha %d", m_alpha); str += buf;
}
textout_ex(doublebuffer, this->getFont(), buf, textout_ex(doublebuffer, this->getFont(), str.c_str(),
x, (rc->y1+rc->y2)/2-text_height(this->getFont())/2, x, (rc->y1+rc->y2)/2-text_height(this->getFont())/2,
text_color, -1); text_color, -1);
x += ji_font_text_len(this->getFont(), buf) + 4*jguiscale(); x += ji_font_text_len(this->getFont(), str.c_str()) + 4*jguiscale();
} }
// Show tool // Show tool

View File

@ -22,7 +22,7 @@
#include "jinete/jbase.h" #include "jinete/jbase.h"
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "core/color.h" #include "app/color.h"
class Frame; class Frame;
class StatusBar; class StatusBar;
@ -56,13 +56,13 @@ public:
bool setStatusText(int msecs, const char *format, ...); bool setStatusText(int msecs, const char *format, ...);
void showTip(int msecs, const char *format, ...); void showTip(int msecs, const char *format, ...);
void showColor(int msecs, const char* text, color_t color, int alpha); void showColor(int msecs, const char* text, const Color& color, int alpha);
void showTool(int msecs, Tool* tool); void showTool(int msecs, Tool* tool);
void showMovePixelsOptions(); void showMovePixelsOptions();
void hideMovePixelsOptions(); void hideMovePixelsOptions();
color_t getTransparentColor(); Color getTransparentColor();
// Methods to add and remove progress bars // Methods to add and remove progress bars
Progress* addProgress(); Progress* addProgress();
@ -84,7 +84,7 @@ private:
Tool* m_tool; Tool* m_tool;
// Showing a color // Showing a color
color_t m_color; Color m_color;
int m_alpha; int m_alpha;
// Progress bar // Progress bar