forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathordered_dither.h
93 lines (76 loc) · 2.99 KB
/
ordered_dither.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Aseprite Render Library
// Copyright (c) 2019 Igara Studio S.A.
// Copyright (c) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef RENDER_ORDERED_DITHER_H_INCLUDED
#define RENDER_ORDERED_DITHER_H_INCLUDED
#pragma once
#include "doc/color.h"
#include "doc/image_impl.h"
#include "doc/palette.h"
#include "doc/rgbmap.h"
#include "gfx/point.h"
#include "gfx/size.h"
#include "render/task_delegate.h"
namespace render {
class Dithering;
class DitheringMatrix;
class DitheringAlgorithmBase {
public:
virtual ~DitheringAlgorithmBase() {}
virtual int dimensions() const { return 1; }
virtual bool zigZag() const { return false; }
virtual void start(const doc::Image* srcImage, doc::Image* dstImage, const double factor) {}
virtual void finish() {}
virtual doc::color_t ditherRgbPixelToIndex(const DitheringMatrix& matrix,
const doc::color_t color,
const int x,
const int y,
const doc::RgbMap* rgbmap,
const doc::Palette* palette)
{
return 0;
}
virtual doc::color_t ditherRgbToIndex2D(const int x,
const int y,
const doc::RgbMap* rgbmap,
const doc::Palette* palette)
{
return 0;
}
};
class OrderedDither : public DitheringAlgorithmBase {
public:
OrderedDither(int transparentIndex = -1);
doc::color_t ditherRgbPixelToIndex(const DitheringMatrix& matrix,
const doc::color_t color,
const int x,
const int y,
const doc::RgbMap* rgbmap,
const doc::Palette* palette) override;
private:
int m_transparentIndex;
};
class OrderedDither2 : public DitheringAlgorithmBase {
public:
OrderedDither2(int transparentIndex = -1);
doc::color_t ditherRgbPixelToIndex(const DitheringMatrix& matrix,
const doc::color_t color,
const int x,
const int y,
const doc::RgbMap* rgbmap,
const doc::Palette* palette) override;
private:
int m_transparentIndex;
};
void dither_rgb_image_to_indexed(DitheringAlgorithmBase& algorithm,
const Dithering& dithering,
const doc::Image* srcImage,
doc::Image* dstImage,
const doc::RgbMap* rgbmap,
const doc::Palette* palette,
TaskDelegate* delegate = nullptr);
} // namespace render
#endif