diff --git a/src/app/tools/point_shapes.h b/src/app/tools/point_shapes.h index 9350da16a..c0ad700eb 100644 --- a/src/app/tools/point_shapes.h +++ b/src/app/tools/point_shapes.h @@ -39,7 +39,7 @@ public: void preparePointShape(ToolLoop* loop) override { m_brush = loop->getBrush(); - m_compressedImage.reset(new CompressedImage(m_brush->image())); + m_compressedImage.reset(new CompressedImage(m_brush->image(), false)); m_firstPoint = true; } diff --git a/src/doc/compressed_image.cpp b/src/doc/compressed_image.cpp index dd8194e19..b94988ee5 100644 --- a/src/doc/compressed_image.cpp +++ b/src/doc/compressed_image.cpp @@ -14,27 +14,33 @@ namespace doc { -CompressedImage::CompressedImage(const Image* image) +CompressedImage::CompressedImage(const Image* image, bool diffColors) : m_image(image) { - color_t mask = image->maskColor(); + color_t c1, c2, mask = image->maskColor(); for (int y=0; yheight(); ++y) { Scanline scanline(y); - for (int x=0; xwidth(); ++x) { - scanline.color = get_pixel(image, x, y); - - if (scanline.color != mask) { + for (int x=0; xwidth(); ) { + c1 = get_pixel(image, x, y); + if (c1 != mask) { + scanline.color = c1; scanline.x = x; - for (; xwidth(); ++x) - if (!get_pixel(image, x, y)) + for (++x; xwidth(); ++x) { + c2 = get_pixel(image, x, y); + + if ((diffColors && c1 != c2) || + (!diffColors && c2 == mask)) break; + } scanline.w = x - scanline.x; m_scanlines.push_back(scanline); } + else + ++x; } } } diff --git a/src/doc/compressed_image.h b/src/doc/compressed_image.h index 46b550665..b9fff4518 100644 --- a/src/doc/compressed_image.h +++ b/src/doc/compressed_image.h @@ -26,7 +26,11 @@ namespace doc { typedef std::vector Scanlines; typedef Scanlines::const_iterator const_iterator; - CompressedImage(const Image* image); + // If diffColors is true, it generates one Scanline instance for + // each different color. If it's false, it generates a scanline + // for each row of consecutive pixels different than the mask + // color. + CompressedImage(const Image* image, bool diffColors); const_iterator begin() const { return m_scanlines.begin(); } const_iterator end() const { return m_scanlines.end(); }