| 1 | // Aseprite Document Library |
| 2 | // Copyright (c) 2001-2016 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "doc/compressed_image.h" |
| 12 | |
| 13 | #include "doc/primitives.h" |
| 14 | #include "doc/primitives_fast.h" |
| 15 | |
| 16 | namespace doc { |
| 17 | |
| 18 | CompressedImage::CompressedImage(const Image* image, |
| 19 | const Image* maskBitmap, |
| 20 | bool diffColors) |
| 21 | : m_image(image) |
| 22 | { |
| 23 | color_t c1, c2, mask = image->maskColor(); |
| 24 | |
| 25 | for (int y=0; y<image->height(); ++y) { |
| 26 | Scanline scanline(y); |
| 27 | |
| 28 | for (int x=0; x<image->width(); ) { |
| 29 | if (maskBitmap && !get_pixel_fast<BitmapTraits>(maskBitmap, x, y)) { |
| 30 | ++x; |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | c1 = get_pixel(image, x, y); |
| 35 | |
| 36 | if (!maskBitmap && c1 == mask) { |
| 37 | ++x; |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | scanline.color = c1; |
| 42 | scanline.x = x; |
| 43 | |
| 44 | for (++x; x<image->width(); ++x) { |
| 45 | if (maskBitmap && !get_pixel_fast<BitmapTraits>(maskBitmap, x, y)) |
| 46 | break; |
| 47 | |
| 48 | c2 = get_pixel(image, x, y); |
| 49 | |
| 50 | if (diffColors && c1 != c2) |
| 51 | break; |
| 52 | |
| 53 | if (!diffColors && !maskBitmap && c2 == mask) |
| 54 | break; |
| 55 | } |
| 56 | |
| 57 | scanline.w = x - scanline.x; |
| 58 | if (scanline.w > 0) |
| 59 | m_scanlines.push_back(scanline); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | } // namespace doc |
| 65 | |