1// Aseprite
2// Copyright (C) 2019-2020 Igara Studio S.A.
3// Copyright (C) 2001-2017 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_CMD_SET_PIXEL_FORMAT_H_INCLUDED
9#define APP_CMD_SET_PIXEL_FORMAT_H_INCLUDED
10#pragma once
11
12#include "app/cmd/with_sprite.h"
13#include "app/cmd_sequence.h"
14#include "doc/color.h"
15#include "doc/frame.h"
16#include "doc/image_ref.h"
17#include "doc/pixel_format.h"
18#include "doc/rgbmap_algorithm.h"
19
20namespace doc {
21 class Sprite;
22}
23
24namespace render {
25 class Dithering;
26 class TaskDelegate;
27}
28
29namespace app {
30namespace cmd {
31
32 class SetPixelFormat : public Cmd
33 , public WithSprite {
34 public:
35 SetPixelFormat(doc::Sprite* sprite,
36 const doc::PixelFormat newFormat,
37 const render::Dithering& dithering,
38 const doc::RgbMapAlgorithm mapAlgorithm,
39 doc::rgba_to_graya_func toGray,
40 render::TaskDelegate* delegate);
41
42 protected:
43 void onExecute() override;
44 void onUndo() override;
45 void onRedo() override;
46 size_t onMemSize() const override {
47 return sizeof(*this) + m_seq.memSize();
48 }
49
50 private:
51 void setFormat(doc::PixelFormat format);
52 void convertImage(doc::Sprite* sprite,
53 const render::Dithering& dithering,
54 const doc::ImageRef& oldImage,
55 const doc::frame_t frame,
56 const bool isBackground,
57 const doc::RgbMapAlgorithm mapAlgorithm,
58 doc::rgba_to_graya_func toGray,
59 render::TaskDelegate* delegate);
60
61 doc::PixelFormat m_oldFormat;
62 doc::PixelFormat m_newFormat;
63 CmdSequence m_seq;
64 };
65
66} // namespace cmd
67} // namespace app
68
69#endif
70