From 7d240c861f9e86330d6ec14933217b99f3bfba90 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 24 Mar 2010 19:15:23 -0300 Subject: [PATCH] Fixed bug 'preview cursor is not visible in indexed images when fg-color is 0' adding Image::mask_color field. --- src/raster/image.cpp | 18 +++++++++++++----- src/raster/image.h | 7 ++++--- src/raster/image_impl.h | 4 +++- src/raster/sprite.cpp | 2 +- src/util/render.cpp | 10 ++++++---- src/widgets/editor/cursor.cpp | 22 ++++++++++++++++++++-- 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/raster/image.cpp b/src/raster/image.cpp index 99761b798..b62c3af65 100644 --- a/src/raster/image.cpp +++ b/src/raster/image.cpp @@ -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; vh; v++) { - for (u=0; uw; 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; vh; v++) { + for (u=0; uw; 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); + } } } } diff --git a/src/raster/image.h b/src/raster/image.h index 75b0e4bc3..7101bc4e9 100644 --- a/src/raster/image.h +++ b/src/raster/image.h @@ -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); diff --git a/src/raster/image_impl.h b/src/raster/image_impl.h index e3351539e..6cef733cc 100644 --- a/src/raster/image_impl.h +++ b/src/raster/image_impl.h @@ -292,12 +292,14 @@ void ImageImpl::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*)src)->line_address(ysrc)+xsrc; dst_address = ((ImageImpl*)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 diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index 90fb5a3a3..e53019180 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -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); } } diff --git a/src/util/render.cpp b/src/util/render.cpp index c1728e169..a62a82f9d 100644 --- a/src/util/render.cpp +++ b/src/util/render.cpp @@ -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 { 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 blender(blend_mode); + BlenderHelper 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; diff --git a/src/widgets/editor/cursor.cpp b/src/widgets/editor/cursor.cpp index ffd879dfc..ebc6640de 100644 --- a/src/widgets/editor/cursor.cpp +++ b/src/widgets/editor/cursor.cpp @@ -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,