1 // Aseprite
2 // Copyright (C) 2001-2016 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/extra_cel.h"
12
13 #include "doc/sprite.h"
14
15 namespace app {
16
ExtraCel()17 ExtraCel::ExtraCel()
18 : m_type(render::ExtraType::NONE)
19 , m_blendMode(doc::BlendMode::NORMAL)
20 {
21 }
22
create(doc::Sprite * sprite,const gfx::Rect & bounds,doc::frame_t frame,int opacity)23 void ExtraCel::create(doc::Sprite* sprite,
24 const gfx::Rect& bounds,
25 doc::frame_t frame,
26 int opacity)
27 {
28 ASSERT(sprite);
29
30 if (!m_image ||
31 m_image->pixelFormat() != sprite->pixelFormat() ||
32 m_image->width() != bounds.w ||
33 m_image->height() != bounds.h) {
34 if (!m_imageBuffer)
35 m_imageBuffer.reset(new doc::ImageBuffer(1));
36 doc::Image* newImage = doc::Image::create(sprite->pixelFormat(),
37 bounds.w, bounds.h,
38 m_imageBuffer);
39 m_image.reset(newImage);
40 }
41
42 if (!m_cel) {
43 // Ignored fields for this cel (frame, and image index)
44 m_cel.reset(new doc::Cel(doc::frame_t(0), doc::ImageRef(nullptr)));
45 }
46
47 m_cel->setBounds(bounds);
48 m_cel->setOpacity(opacity);
49 m_cel->setFrame(frame);
50 }
51
52 } // namespace app
53