Fixed bug 'preview cursor is not visible in indexed images when fg-color is 0' adding Image::mask_color field.

This commit is contained in:
David Capello 2010-03-24 19:15:23 -03:00
parent 975049bdea
commit 7d240c861f
6 changed files with 47 additions and 16 deletions

View File

@ -40,6 +40,7 @@ Image::Image(int imgtype, int w, int h)
this->h = h;
this->dat = NULL;
this->line = NULL;
this->mask_color = 0;
}
Image::~Image()
@ -98,7 +99,7 @@ void image_putpixel(Image* image, int x, int y, int color)
image->putpixel(x, y, color);
}
void image_putpen(Image* image, Pen* pen, int x, int y, int color)
void image_putpen(Image* image, Pen* pen, int x, int y, int fg_color, int bg_color)
{
Image* pen_image = pen->get_image();
int u, v, size = pen->get_size();
@ -106,10 +107,17 @@ void image_putpen(Image* image, Pen* pen, int x, int y, int color)
x -= size/2;
y -= size/2;
for (v=0; v<pen_image->h; v++) {
for (u=0; u<pen_image->w; u++) {
if (image_getpixel(pen_image, u, v))
image_putpixel(image, x+u, y+v, color);
if (fg_color == bg_color) {
image_rectfill(image, x, y, x+pen_image->w-1, y+pen_image->h-1, bg_color);
}
else {
for (v=0; v<pen_image->h; v++) {
for (u=0; u<pen_image->w; u++) {
if (image_getpixel(pen_image, u, v))
image_putpixel(image, x+u, y+v, fg_color);
else
image_putpixel(image, x+u, y+v, bg_color);
}
}
}
}

View File

@ -46,8 +46,9 @@ class Image : public GfxObj
public:
int imgtype;
int w, h;
ase_uint8* dat; /* pixmap data */
ase_uint8** line; /* start of each scanline */
ase_uint8* dat; // pixmap data
ase_uint8** line; // start of each scanline
ase_uint32 mask_color; // skipped color in merge process
Image(int imgtype, int w, int h);
virtual ~Image();
@ -70,7 +71,7 @@ int image_depth(Image* image);
int image_getpixel(const Image* image, int x, int y);
void image_putpixel(Image* image, int x, int y, int color);
void image_putpen(Image* image, Pen* pen, int x, int y, int color);
void image_putpen(Image* image, Pen* pen, int x, int y, int fg_color, int bg_color);
void image_clear(Image* image, int color);

View File

@ -292,12 +292,14 @@ void ImageImpl<IndexedTraits>::merge(const Image* src, int x, int y, int opacity
}
// with mask
else {
register int mask_color = src->mask_color;
for (ydst=ybeg; ydst<=yend; ydst++, ysrc++) {
src_address = ((ImageImpl<IndexedTraits>*)src)->line_address(ysrc)+xsrc;
dst_address = ((ImageImpl<IndexedTraits>*)dst)->line_address(ydst)+xbeg;
for (xdst=xbeg; xdst<=xend; xdst++) {
if (*src_address) {
if (*src_address != mask_color) {
if (color_map)
*dst_address = color_map->data[*src_address][*dst_address];
else

View File

@ -397,7 +397,7 @@ void Sprite::prepare_extra()
m_extras->h != h) {
delete m_extras; // image
m_extras = image_new(imgtype, w, h);
image_clear(m_extras, 0);
image_clear(m_extras, m_extras->mask_color = 0);
}
}

View File

@ -40,7 +40,7 @@ class BlenderHelper
{
BLEND_COLOR m_blend_color;
public:
BlenderHelper(int blend_mode)
BlenderHelper(int blend_mode, Image* src)
{
m_blend_color = Traits::get_blender(blend_mode);
}
@ -58,10 +58,12 @@ template<>
class BlenderHelper<IndexedTraits>
{
int m_blend_mode;
int m_mask_color;
public:
BlenderHelper(int blend_mode)
BlenderHelper(int blend_mode, Image* src)
{
m_blend_mode = blend_mode;
m_mask_color = src->mask_color;
}
inline void operator()(IndexedTraits::address_t& scanline_address,
@ -73,7 +75,7 @@ public:
*scanline_address = *src_address;
}
else {
if (*src_address) {
if (*src_address != m_mask_color) {
if (color_map)
*scanline_address = color_map->data[*src_address][*dst_address];
else
@ -90,7 +92,7 @@ static void merge_zoomed_image(Image *dst, Image *src,
int x, int y, int opacity,
int blend_mode, int zoom)
{
BlenderHelper<Traits> blender(blend_mode);
BlenderHelper<Traits> blender(blend_mode, src);
typename Traits::address_t src_address;
typename Traits::address_t dst_address, dst_address_end;
typename Traits::address_t scanline, scanline_address;

View File

@ -270,12 +270,28 @@ void Editor::editor_draw_cursor(int x, int y, bool refresh)
->getToolSettings(current_tool);
int pen_color = app_get_fg_color(m_sprite);
int new_mask_color;
Pen* pen = editor_get_current_pen();
// Set the opacity for the 'extra' layer used to show the cursor preview
m_sprite->set_extras_opacity(tool_settings->getOpacity());
// Create the 'extra' image/layer
m_sprite->prepare_extra();
image_putpen(m_sprite->get_extras(), pen, x, y, pen_color);
// In 'indexed' images, if the current color is 0, we have to use
// a different mask color (different from 0) to draw the extra layer
if (m_sprite->imgtype == IMAGE_INDEXED && pen_color == 0) {
new_mask_color = 1;
}
else {
new_mask_color = 0;
}
Image* extras = m_sprite->get_extras();
if (extras->mask_color != new_mask_color)
image_clear(extras, extras->mask_color = new_mask_color);
image_putpen(extras, pen, x, y, pen_color, extras->mask_color);
if (refresh) {
editors_draw_sprite(m_sprite,
@ -390,7 +406,9 @@ void Editor::editor_clean_cursor(bool refresh)
Pen* pen = editor_get_current_pen();
m_sprite->prepare_extra();
image_putpen(m_sprite->get_extras(), pen, x, y, 0);
image_putpen(m_sprite->get_extras(), pen, x, y,
m_sprite->get_extras()->mask_color,
m_sprite->get_extras()->mask_color);
if (refresh) {
editors_draw_sprite(m_sprite,