1// Aseprite Render Library
2// Copyright (c) 2019 Igara Studio S.A
3// Copyright (c) 2017 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_ERROR_DIFFUSION_H_INCLUDED
9#define RENDER_ERROR_DIFFUSION_H_INCLUDED
10#pragma once
11
12#include "doc/image_ref.h"
13#include "render/ordered_dither.h"
14
15#include <vector>
16
17namespace render {
18
19 class ErrorDiffusionDither : public DitheringAlgorithmBase {
20 public:
21 ErrorDiffusionDither(int transparentIndex = -1);
22 int dimensions() const override { return 2; }
23 bool zigZag() const override { return true; }
24 void start(
25 const doc::Image* srcImage,
26 doc::Image* dstImage,
27 const double factor) override;
28 void finish() override;
29 doc::color_t ditherRgbToIndex2D(
30 const int x, const int y,
31 const doc::RgbMap* rgbmap,
32 const doc::Palette* palette) override;
33 private:
34 int m_transparentIndex;
35 const doc::Image* m_srcImage;
36 int m_width, m_lastY;
37 static const int kChannels = 4;
38 std::vector<int> m_err[kChannels];
39 int m_factor;
40 };
41
42} // namespace render
43
44#endif
45