1 | // Aseprite Render Library |
2 | // Copyright (c) 2019-2022 Igara Studio S.A. |
3 | // Copyright (c) 2001-2018 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef RENDER_RENDER_H_INCLUDED |
9 | #define RENDER_RENDER_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "doc/doc.h" |
13 | #include "doc/anidir.h" |
14 | #include "doc/blend_mode.h" |
15 | #include "doc/color.h" |
16 | #include "doc/frame.h" |
17 | #include "doc/pixel_format.h" |
18 | #include "gfx/clip.h" |
19 | #include "gfx/point.h" |
20 | #include "gfx/size.h" |
21 | #include "render/bg_options.h" |
22 | #include "render/extra_type.h" |
23 | #include "render/onionskin_options.h" |
24 | #include "render/projection.h" |
25 | |
26 | namespace doc { |
27 | class Cel; |
28 | class Image; |
29 | class Layer; |
30 | class Palette; |
31 | class Sprite; |
32 | class Tileset; |
33 | } |
34 | |
35 | namespace render { |
36 | using namespace doc; |
37 | |
38 | typedef void (*CompositeImageFunc)( |
39 | Image* dst, |
40 | const Image* src, |
41 | const Palette* pal, |
42 | const gfx::ClipF& area, |
43 | const int opacity, |
44 | const BlendMode blendMode, |
45 | const double sx, |
46 | const double sy, |
47 | const bool newBlend); |
48 | |
49 | class Render { |
50 | enum Flags { |
51 | ShowRefLayers = 1, |
52 | }; |
53 | |
54 | public: |
55 | Render(); |
56 | |
57 | void setRefLayersVisiblity(const bool visible); |
58 | void setNonactiveLayersOpacity(const int opacity); |
59 | void setNewBlend(const bool newBlend); |
60 | void setProjection(const Projection& projection); |
61 | void setBgOptions(const BgOptions& bg); |
62 | void setSelectedLayer(const Layer* layer); |
63 | |
64 | // Sets the preview image. This preview image is an alternative |
65 | // image to be used for the given layer/frame. |
66 | void setPreviewImage(const Layer* layer, |
67 | const frame_t frame, |
68 | const Image* image, |
69 | const Tileset* tileset, |
70 | const gfx::Point& pos, |
71 | const BlendMode blendMode); |
72 | void removePreviewImage(); |
73 | |
74 | // Sets an extra cel/image to be drawn after the current |
75 | // layer/frame. |
76 | void ( |
77 | ExtraType type, |
78 | const Cel* cel, const Image* image, BlendMode blendMode, |
79 | const Layer* currentLayer, |
80 | frame_t currentFrame); |
81 | void (); |
82 | |
83 | void setOnionskin(const OnionskinOptions& options); |
84 | void disableOnionskin(); |
85 | |
86 | void renderSprite( |
87 | Image* dstImage, |
88 | const Sprite* sprite, |
89 | frame_t frame); |
90 | |
91 | void renderLayer( |
92 | Image* dstImage, |
93 | const Layer* layer, |
94 | frame_t frame); |
95 | |
96 | void renderLayer( |
97 | Image* dstImage, |
98 | const Layer* layer, |
99 | frame_t frame, |
100 | const gfx::Clip& area, |
101 | BlendMode blendMode = BlendMode::UNSPECIFIED); |
102 | |
103 | // Main function used to render the sprite. Draws the given sprite |
104 | // frame in a new image and return it. Note: zoomedRect must have |
105 | // the zoom applied (zoomedRect = zoom.apply(spriteRect)). |
106 | void renderSprite( |
107 | Image* dstImage, |
108 | const Sprite* sprite, |
109 | frame_t frame, |
110 | const gfx::ClipF& area); |
111 | |
112 | // Extra functions |
113 | void renderCheckeredBackground( |
114 | Image* image, |
115 | const gfx::Clip& area); |
116 | |
117 | void renderImage( |
118 | Image* dst_image, |
119 | const Image* src_image, |
120 | const Palette* pal, |
121 | const int x, |
122 | const int y, |
123 | const int opacity, |
124 | const BlendMode blendMode); |
125 | |
126 | void renderCel( |
127 | Image* dst_image, |
128 | const Cel* cel, |
129 | const Sprite* sprite, |
130 | const Image* cel_image, |
131 | const Layer* cel_layer, |
132 | const Palette* pal, |
133 | const gfx::RectF& celBounds, |
134 | const gfx::Clip& area, |
135 | const int opacity, |
136 | const BlendMode blendMode); |
137 | |
138 | private: |
139 | void renderSpriteLayers( |
140 | Image* dstImage, |
141 | const gfx::ClipF& area, |
142 | frame_t frame, |
143 | CompositeImageFunc compositeImage); |
144 | |
145 | void renderBackground( |
146 | Image* image, |
147 | const Layer* bgLayer, |
148 | const color_t bg_color, |
149 | const gfx::ClipF& area); |
150 | |
151 | bool isSolidBackground( |
152 | const Layer* bgLayer, |
153 | const color_t bg_color) const; |
154 | |
155 | void renderOnionskin( |
156 | Image* image, |
157 | const gfx::Clip& area, |
158 | const frame_t frame, |
159 | const CompositeImageFunc compositeImage); |
160 | |
161 | void renderLayer( |
162 | const Layer* layer, |
163 | Image* image, |
164 | const gfx::Clip& area, |
165 | const frame_t frame, |
166 | const CompositeImageFunc compositeImage, |
167 | const bool render_background, |
168 | const bool render_transparent, |
169 | const BlendMode blendMode, |
170 | bool isSelected); |
171 | |
172 | void renderCel( |
173 | Image* dst_image, |
174 | const Cel* cel, |
175 | const Image* cel_image, |
176 | const Layer* cel_layer, |
177 | const Palette* pal, |
178 | const gfx::RectF& celBounds, |
179 | const gfx::Clip& area, |
180 | const CompositeImageFunc compositeImage, |
181 | const int opacity, |
182 | const BlendMode blendMode); |
183 | |
184 | void renderImage( |
185 | Image* dst_image, |
186 | const Image* cel_image, |
187 | const Palette* pal, |
188 | const gfx::RectF& celBounds, |
189 | const gfx::Clip& area, |
190 | const CompositeImageFunc compositeImage, |
191 | const int opacity, |
192 | const BlendMode blendMode); |
193 | |
194 | CompositeImageFunc getImageComposition( |
195 | const PixelFormat dstFormat, |
196 | const PixelFormat srcFormat, |
197 | const Layer* layer); |
198 | |
199 | bool checkIfWeShouldUsePreview(const Cel* cel) const; |
200 | |
201 | int m_flags; |
202 | int m_nonactiveLayersOpacity; |
203 | const Sprite* m_sprite; |
204 | const Layer* m_currentLayer; |
205 | frame_t m_currentFrame; |
206 | Projection m_proj; |
207 | ExtraType ; |
208 | const Cel* ; |
209 | const Image* ; |
210 | BlendMode ; |
211 | bool m_newBlendMethod; |
212 | BgOptions m_bg; |
213 | int m_globalOpacity; |
214 | const Layer* m_selectedLayerForOpacity; |
215 | const Layer* m_selectedLayer; |
216 | frame_t m_selectedFrame; |
217 | const Image* m_previewImage; |
218 | const Tileset* m_previewTileset; |
219 | gfx::Point m_previewPos; |
220 | BlendMode m_previewBlendMode; |
221 | OnionskinOptions m_onionskin; |
222 | ImageBufferPtr m_tmpBuf; |
223 | }; |
224 | |
225 | void composite_image(Image* dst, |
226 | const Image* src, |
227 | const Palette* pal, |
228 | const int x, |
229 | const int y, |
230 | const int opacity, |
231 | const BlendMode blendMode); |
232 | |
233 | } // namespace render |
234 | |
235 | #endif |
236 | |