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