1 | // Aseprite |
2 | // Copyright (C) 2001-2018 David Capello |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "app/cmd/flip_masked_cel.h" |
12 | |
13 | #include "app/cmd/copy_rect.h" |
14 | #include "app/doc.h" |
15 | #include "app/util/autocrop.h" |
16 | #include "doc/algorithm/flip_image.h" |
17 | #include "doc/cel.h" |
18 | #include "doc/image.h" |
19 | #include "doc/layer.h" |
20 | #include "doc/mask.h" |
21 | |
22 | namespace app { |
23 | namespace cmd { |
24 | |
25 | FlipMaskedCel::FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType) |
26 | { |
27 | Doc* doc = static_cast<Doc*>(cel->document()); |
28 | color_t bgcolor = doc->bgColor(cel->layer()); |
29 | Image* image = cel->image(); |
30 | Mask* mask = doc->mask(); |
31 | ASSERT(mask->bitmap()); |
32 | if (!mask->bitmap()) |
33 | return; |
34 | |
35 | ImageRef copy(Image::createCopy(image)); |
36 | int x = cel->x(); |
37 | int y = cel->y(); |
38 | mask->offsetOrigin(-x, -y); |
39 | doc::algorithm::flip_image_with_mask( |
40 | copy.get(), mask, flipType, bgcolor); |
41 | mask->offsetOrigin(x, y); |
42 | |
43 | int x1, y1, x2, y2; |
44 | if (get_shrink_rect2(&x1, &y1, &x2, &y2, image, copy.get())) { |
45 | add(new cmd::CopyRect(image, copy.get(), |
46 | gfx::Clip(x1, y1, x1, y1, x2-x1+1, y2-y1+1))); |
47 | } |
48 | } |
49 | |
50 | } // namespace cmd |
51 | } // namespace app |
52 | |