2014-12-28 14:06:11 +00:00
|
|
|
// Aseprite Render Library
|
2023-05-06 01:11:19 +00:00
|
|
|
// Copyright (c) 2019-2023 Igara Studio S.A.
|
2018-06-20 02:25:31 +00:00
|
|
|
// Copyright (c) 2001-2018 David Capello
|
2014-12-28 14:06:11 +00:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifndef RENDER_RENDER_H_INCLUDED
|
|
|
|
#define RENDER_RENDER_H_INCLUDED
|
|
|
|
#pragma once
|
|
|
|
|
2015-05-27 20:42:41 +00:00
|
|
|
#include "doc/anidir.h"
|
2015-06-14 00:29:16 +00:00
|
|
|
#include "doc/blend_mode.h"
|
2014-12-28 14:06:11 +00:00
|
|
|
#include "doc/color.h"
|
2023-07-17 18:02:15 +00:00
|
|
|
#include "doc/doc.h"
|
2014-12-28 23:39:11 +00:00
|
|
|
#include "doc/frame.h"
|
2014-12-28 14:06:11 +00:00
|
|
|
#include "doc/pixel_format.h"
|
2023-07-17 22:37:27 +00:00
|
|
|
#include "doc/tile.h"
|
2016-10-11 02:42:47 +00:00
|
|
|
#include "gfx/clip.h"
|
2016-07-01 21:49:58 +00:00
|
|
|
#include "gfx/point.h"
|
2014-12-28 14:06:11 +00:00
|
|
|
#include "gfx/size.h"
|
2022-08-18 01:40:25 +00:00
|
|
|
#include "render/bg_options.h"
|
2015-04-26 18:59:28 +00:00
|
|
|
#include "render/extra_type.h"
|
2018-06-20 02:25:31 +00:00
|
|
|
#include "render/onionskin_options.h"
|
2016-05-23 22:22:02 +00:00
|
|
|
#include "render/projection.h"
|
2014-12-28 14:06:11 +00:00
|
|
|
|
|
|
|
namespace doc {
|
|
|
|
class Cel;
|
|
|
|
class Image;
|
|
|
|
class Layer;
|
|
|
|
class Palette;
|
2023-04-10 20:44:22 +00:00
|
|
|
class RenderPlan;
|
2014-12-28 14:06:11 +00:00
|
|
|
class Sprite;
|
2020-11-04 19:54:12 +00:00
|
|
|
class Tileset;
|
2014-12-28 14:06:11 +00:00
|
|
|
} // namespace doc
|
|
|
|
|
|
|
|
namespace render {
|
|
|
|
using namespace doc;
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-07-01 21:49:58 +00:00
|
|
|
typedef void (*CompositeImageFunc)(Image* dst,
|
2015-06-14 00:29:16 +00:00
|
|
|
const Image* src,
|
2014-12-28 14:06:11 +00:00
|
|
|
const Palette* pal,
|
2015-04-26 18:59:28 +00:00
|
|
|
const gfx::ClipF& area,
|
2016-06-30 15:26:41 +00:00
|
|
|
const int opacity,
|
|
|
|
const BlendMode blendMode,
|
2019-04-11 17:29:20 +00:00
|
|
|
const double sx,
|
2019-02-25 21:02:58 +00:00
|
|
|
const double sy,
|
2016-06-30 15:26:41 +00:00
|
|
|
const bool newBlend,
|
2023-05-06 01:11:19 +00:00
|
|
|
const tile_flags tileFlags);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2023-07-17 22:37:27 +00:00
|
|
|
class Render {
|
|
|
|
enum Flags {
|
2014-12-28 14:06:11 +00:00
|
|
|
ShowRefLayers = 1,
|
|
|
|
};
|
|
|
|
|
2024-12-16 17:52:19 +00:00
|
|
|
public:
|
2014-12-28 14:06:11 +00:00
|
|
|
Render();
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-06-29 13:01:14 +00:00
|
|
|
void setRefLayersVisiblity(const bool visible);
|
|
|
|
void setNonactiveLayersOpacity(const int opacity);
|
2019-02-25 21:02:58 +00:00
|
|
|
void setNewBlend(const bool newBlend);
|
2024-06-03 22:00:04 +00:00
|
|
|
void setComposeGroups(bool composeGroup);
|
2016-05-23 22:22:02 +00:00
|
|
|
void setProjection(const Projection& projection);
|
2022-08-18 01:40:25 +00:00
|
|
|
void setBgOptions(const BgOptions& bg);
|
2016-12-01 18:20:35 +00:00
|
|
|
void setSelectedLayer(const Layer* layer);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
// Sets the preview image. This preview image is an alternative
|
|
|
|
// image to be used for the given layer/frame.
|
2016-07-01 21:49:58 +00:00
|
|
|
void setPreviewImage(const Layer* layer,
|
|
|
|
const frame_t frame,
|
2016-06-29 13:01:14 +00:00
|
|
|
const Image* image,
|
2020-11-04 19:54:12 +00:00
|
|
|
const Tileset* tileset,
|
2016-07-01 21:49:58 +00:00
|
|
|
const gfx::Point& pos,
|
2016-06-29 13:01:14 +00:00
|
|
|
const BlendMode blendMode);
|
2014-12-28 14:06:11 +00:00
|
|
|
void removePreviewImage();
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
// Sets an extra cel/image to be drawn after the current
|
|
|
|
// layer/frame.
|
|
|
|
void setExtraImage(ExtraType type,
|
2015-06-14 00:29:16 +00:00
|
|
|
const Cel* cel,
|
2016-07-01 21:49:58 +00:00
|
|
|
const Image* image,
|
2015-06-14 00:29:16 +00:00
|
|
|
BlendMode blendMode,
|
2014-12-28 14:06:11 +00:00
|
|
|
const Layer* currentLayer,
|
2014-12-28 23:39:11 +00:00
|
|
|
frame_t currentFrame);
|
2014-12-28 14:06:11 +00:00
|
|
|
void removeExtraImage();
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2015-05-27 17:49:01 +00:00
|
|
|
void setOnionskin(const OnionskinOptions& options);
|
2014-12-28 14:06:11 +00:00
|
|
|
void disableOnionskin();
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
void renderSprite(Image* dstImage, const Sprite* sprite, frame_t frame);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-12-01 18:20:35 +00:00
|
|
|
void renderLayer(Image* dstImage, const Layer* layer, frame_t frame);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
void renderLayer(Image* dstImage,
|
|
|
|
const Layer* layer,
|
2014-12-28 23:39:11 +00:00
|
|
|
frame_t frame,
|
2019-04-11 17:29:20 +00:00
|
|
|
const gfx::Clip& area,
|
2016-05-23 22:22:02 +00:00
|
|
|
BlendMode blendMode = BlendMode::UNSPECIFIED);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
// Main function used to render the sprite. Draws the given sprite
|
|
|
|
// frame in a new image and return it. Note: zoomedRect must have
|
|
|
|
// the zoom applied (zoomedRect = zoom.apply(spriteRect)).
|
|
|
|
void renderSprite(Image* dstImage, const Sprite* sprite, frame_t frame, const gfx::ClipF& area);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
// Extra functions
|
2022-08-18 01:19:07 +00:00
|
|
|
void renderCheckeredBackground(Image* image, const gfx::Clip& area);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-05-23 22:22:02 +00:00
|
|
|
void renderImage(Image* dst_image,
|
2016-06-30 15:26:41 +00:00
|
|
|
const Image* src_image,
|
|
|
|
const Palette* pal,
|
2016-06-29 13:01:14 +00:00
|
|
|
const int x,
|
2016-06-30 15:26:41 +00:00
|
|
|
const int y,
|
|
|
|
const int opacity,
|
2016-07-01 21:49:58 +00:00
|
|
|
const BlendMode blendMode);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-06-30 15:26:41 +00:00
|
|
|
void renderCel(Image* dst_image,
|
2020-11-04 19:54:12 +00:00
|
|
|
const Cel* cel,
|
2014-12-28 14:06:11 +00:00
|
|
|
const Sprite* sprite,
|
2019-04-11 17:29:20 +00:00
|
|
|
const Image* cel_image,
|
|
|
|
const Layer* cel_layer,
|
2016-06-30 15:26:41 +00:00
|
|
|
const Palette* pal,
|
2019-04-11 17:29:20 +00:00
|
|
|
const gfx::RectF& celBounds,
|
|
|
|
const gfx::Clip& area,
|
2016-06-30 15:26:41 +00:00
|
|
|
const int opacity,
|
2016-07-01 21:49:58 +00:00
|
|
|
const BlendMode blendMode);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-25 21:02:58 +00:00
|
|
|
void renderSpriteLayers(Image* dstImage,
|
|
|
|
const gfx::ClipF& area,
|
|
|
|
frame_t frame,
|
|
|
|
CompositeImageFunc compositeImage);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2019-03-09 18:00:09 +00:00
|
|
|
void renderBackground(Image* image,
|
|
|
|
const Layer* bgLayer,
|
|
|
|
const color_t bg_color,
|
2019-02-25 21:02:58 +00:00
|
|
|
const gfx::ClipF& area);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2019-03-09 18:00:09 +00:00
|
|
|
bool isSolidBackground(const Layer* bgLayer, const color_t bg_color) const;
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2015-07-31 18:55:06 +00:00
|
|
|
void renderOnionskin(Image* image,
|
2019-04-11 17:29:20 +00:00
|
|
|
const gfx::Clip& area,
|
2016-06-30 15:26:41 +00:00
|
|
|
const frame_t frame,
|
|
|
|
const CompositeImageFunc compositeImage);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2023-04-10 20:44:22 +00:00
|
|
|
void renderPlan(doc::RenderPlan& plan,
|
2019-02-25 21:02:58 +00:00
|
|
|
Image* image,
|
2019-04-11 17:29:20 +00:00
|
|
|
const gfx::Clip& area,
|
2016-06-30 15:26:41 +00:00
|
|
|
const frame_t frame,
|
|
|
|
const CompositeImageFunc compositeImage,
|
|
|
|
const bool render_background,
|
|
|
|
const bool render_transparent,
|
|
|
|
const BlendMode blendMode);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
void renderCel(Image* dst_image,
|
2020-11-04 19:54:12 +00:00
|
|
|
const Cel* cel,
|
2014-12-28 14:06:11 +00:00
|
|
|
const Image* cel_image,
|
2019-03-29 18:57:10 +00:00
|
|
|
const Layer* cel_layer,
|
2014-12-28 14:06:11 +00:00
|
|
|
const Palette* pal,
|
2016-10-11 02:42:47 +00:00
|
|
|
const gfx::RectF& celBounds,
|
2015-07-31 18:55:06 +00:00
|
|
|
const gfx::Clip& area,
|
2016-06-30 15:26:41 +00:00
|
|
|
const CompositeImageFunc compositeImage,
|
|
|
|
const int opacity,
|
|
|
|
const BlendMode blendMode);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2014-12-28 14:06:11 +00:00
|
|
|
void renderImage(Image* dst_image,
|
|
|
|
const Image* cel_image,
|
|
|
|
const Palette* pal,
|
2016-10-11 02:42:47 +00:00
|
|
|
const gfx::RectF& celBounds,
|
2014-12-28 14:06:11 +00:00
|
|
|
const gfx::Clip& area,
|
2016-06-30 15:26:41 +00:00
|
|
|
CompositeImageFunc compositeImage,
|
|
|
|
const int opacity,
|
2015-06-14 00:29:16 +00:00
|
|
|
const BlendMode blendMode,
|
2023-07-17 22:37:27 +00:00
|
|
|
const tile_flags tileFlags = notile);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-10-11 19:43:37 +00:00
|
|
|
CompositeImageFunc getImageComposition(const PixelFormat dstFormat,
|
|
|
|
const PixelFormat srcFormat,
|
2023-07-17 22:37:27 +00:00
|
|
|
const Layer* layer,
|
|
|
|
const tile_flags tileFlags = notile);
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2020-11-04 19:54:12 +00:00
|
|
|
bool checkIfWeShouldUsePreview(const Cel* cel) const;
|
2024-12-16 17:52:19 +00:00
|
|
|
|
2016-10-26 18:16:22 +00:00
|
|
|
int m_flags;
|
2016-12-01 18:20:35 +00:00
|
|
|
int m_nonactiveLayersOpacity;
|
2014-12-28 14:06:11 +00:00
|
|
|
const Sprite* m_sprite;
|
|
|
|
const Layer* m_currentLayer;
|
2014-12-28 23:39:11 +00:00
|
|
|
frame_t m_currentFrame;
|
2016-05-23 22:22:02 +00:00
|
|
|
Projection m_proj;
|
2015-04-26 18:59:28 +00:00
|
|
|
ExtraType m_extraType;
|
2014-12-28 14:06:11 +00:00
|
|
|
const Cel* m_extraCel;
|
|
|
|
const Image* m_extraImage;
|
2015-06-14 00:29:16 +00:00
|
|
|
BlendMode m_extraBlendMode;
|
2019-02-25 21:02:58 +00:00
|
|
|
bool m_newBlendMethod;
|
2022-08-18 01:40:25 +00:00
|
|
|
BgOptions m_bg;
|
2014-12-28 14:06:11 +00:00
|
|
|
int m_globalOpacity;
|
2016-12-07 20:05:31 +00:00
|
|
|
const Layer* m_selectedLayerForOpacity;
|
|
|
|
const Layer* m_selectedLayer;
|
2014-12-28 23:39:11 +00:00
|
|
|
frame_t m_selectedFrame;
|
2016-07-01 21:49:58 +00:00
|
|
|
const Image* m_previewImage;
|
2020-11-04 19:54:12 +00:00
|
|
|
const Tileset* m_previewTileset;
|
2016-07-01 21:49:58 +00:00
|
|
|
gfx::Point m_previewPos;
|
2016-05-02 21:42:02 +00:00
|
|
|
BlendMode m_previewBlendMode;
|
2015-05-27 17:49:01 +00:00
|
|
|
OnionskinOptions m_onionskin;
|
2019-02-25 21:02:58 +00:00
|
|
|
ImageBufferPtr m_tmpBuf;
|
2024-06-03 22:00:04 +00:00
|
|
|
bool m_composeGroups = false;
|
2024-12-16 17:52:19 +00:00
|
|
|
};
|
|
|
|
|
2016-06-29 13:01:14 +00:00
|
|
|
void composite_image(Image* dst,
|
|
|
|
const Image* src,
|
2016-05-02 21:42:02 +00:00
|
|
|
const Palette* pal,
|
2016-06-29 13:01:14 +00:00
|
|
|
const int x,
|
|
|
|
const int y,
|
2016-06-30 15:26:41 +00:00
|
|
|
const int opacity,
|
2016-06-29 13:01:14 +00:00
|
|
|
const BlendMode blendMode);
|
2014-12-28 14:06:11 +00:00
|
|
|
|
|
|
|
} // namespace render
|
|
|
|
|
|
|
|
#endif
|