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