| 1 | // Aseprite |
| 2 | // Copyright (C) 2020 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2016 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include "config.h" |
| 10 | #endif |
| 11 | |
| 12 | #include "app/extra_cel.h" |
| 13 | |
| 14 | #include "doc/sprite.h" |
| 15 | |
| 16 | namespace app { |
| 17 | |
| 18 | ExtraCel::() |
| 19 | : m_type(render::ExtraType::NONE) |
| 20 | , m_blendMode(doc::BlendMode::NORMAL) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | void ExtraCel::(const TilemapMode tilemapMode, |
| 25 | doc::Sprite* sprite, |
| 26 | const gfx::Rect& bounds, |
| 27 | const gfx::Size& imageSize, |
| 28 | const doc::frame_t frame, |
| 29 | const int opacity) |
| 30 | { |
| 31 | ASSERT(sprite); |
| 32 | |
| 33 | doc::PixelFormat pixelFormat; |
| 34 | if (tilemapMode == TilemapMode::Tiles) |
| 35 | pixelFormat = doc::IMAGE_TILEMAP; |
| 36 | else |
| 37 | pixelFormat = sprite->pixelFormat(); |
| 38 | |
| 39 | if (!m_image || |
| 40 | m_image->pixelFormat() != pixelFormat || |
| 41 | m_image->width() != imageSize.w || |
| 42 | m_image->height() != imageSize.h) { |
| 43 | if (!m_imageBuffer) |
| 44 | m_imageBuffer.reset(new doc::ImageBuffer(1)); |
| 45 | doc::Image* newImage = doc::Image::create(pixelFormat, |
| 46 | imageSize.w, imageSize.h, |
| 47 | m_imageBuffer); |
| 48 | m_image.reset(newImage); |
| 49 | } |
| 50 | |
| 51 | if (!m_cel) { |
| 52 | // Ignored fields for this cel (frame, and image index) |
| 53 | m_cel.reset(new doc::Cel(doc::frame_t(0), doc::ImageRef(nullptr))); |
| 54 | } |
| 55 | |
| 56 | m_cel->setBounds(bounds); |
| 57 | m_cel->setOpacity(opacity); |
| 58 | m_cel->setFrame(frame); |
| 59 | } |
| 60 | |
| 61 | void ExtraCel::() |
| 62 | { |
| 63 | m_type = render::ExtraType::NONE; |
| 64 | m_image.reset(); |
| 65 | m_cel.reset(); |
| 66 | } |
| 67 | |
| 68 | } // namespace app |
| 69 | |