| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2001-2015 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/remap_colors.h" |
| 12 | |
| 13 | #include "doc/cel.h" |
| 14 | #include "doc/cels_range.h" |
| 15 | #include "doc/image.h" |
| 16 | #include "doc/remap.h" |
| 17 | #include "doc/sprite.h" |
| 18 | |
| 19 | namespace app { |
| 20 | namespace cmd { |
| 21 | |
| 22 | using namespace doc; |
| 23 | |
| 24 | RemapColors::RemapColors(Sprite* sprite, const Remap& remap) |
| 25 | : WithSprite(sprite) |
| 26 | , m_remap(remap) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | void RemapColors::onExecute() |
| 31 | { |
| 32 | Sprite* spr = sprite(); |
| 33 | if (spr->pixelFormat() == IMAGE_INDEXED) { |
| 34 | spr->remapImages(m_remap); |
| 35 | incrementVersions(spr); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void RemapColors::onUndo() |
| 40 | { |
| 41 | Sprite* spr = this->sprite(); |
| 42 | if (spr->pixelFormat() == IMAGE_INDEXED) { |
| 43 | spr->remapImages(m_remap.invert()); |
| 44 | incrementVersions(spr); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void RemapColors::incrementVersions(Sprite* spr) |
| 49 | { |
| 50 | for (const Cel* cel : spr->uniqueCels()) |
| 51 | cel->image()->incrementVersion(); |
| 52 | } |
| 53 | |
| 54 | } // namespace cmd |
| 55 | } // namespace app |
| 56 |