mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-16 22:18:30 +00:00
Optimize CompressedImage to get only bitmap information
When we create a CompressedImage from a Brush image, we want to know what pixels are != the mask color, just to generate the PointShape (we don't care the specific color of the scaneline/each pixel, that information is used in the "ink processing" step).
This commit is contained in:
parent
57156bddb7
commit
c5e79bb940
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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; y<image->height(); ++y) {
|
||||
Scanline scanline(y);
|
||||
|
||||
for (int x=0; x<image->width(); ++x) {
|
||||
scanline.color = get_pixel(image, x, y);
|
||||
|
||||
if (scanline.color != mask) {
|
||||
for (int x=0; x<image->width(); ) {
|
||||
c1 = get_pixel(image, x, y);
|
||||
if (c1 != mask) {
|
||||
scanline.color = c1;
|
||||
scanline.x = x;
|
||||
|
||||
for (; x<image->width(); ++x)
|
||||
if (!get_pixel(image, x, y))
|
||||
for (++x; x<image->width(); ++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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,11 @@ namespace doc {
|
||||
typedef std::vector<Scanline> 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(); }
|
||||
|
Loading…
Reference in New Issue
Block a user