2015-06-23 07:58:33 +08:00
|
|
|
// Aseprite Render Library
|
2019-04-02 08:44:06 +08:00
|
|
|
// Copyright (c) 2019 Igara Studio S.A.
|
2017-05-17 04:18:55 +08:00
|
|
|
// Copyright (c) 2001-2017 David Capello
|
2015-06-23 07:58:33 +08:00
|
|
|
//
|
|
|
|
// 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"
|
2024-12-19 20:36:27 +08:00
|
|
|
#include "doc/image.h"
|
2015-06-23 07:58:33 +08:00
|
|
|
#include "doc/palette.h"
|
|
|
|
#include "doc/rgbmap.h"
|
2019-04-02 08:44:06 +08:00
|
|
|
#include "gfx/point.h"
|
|
|
|
#include "gfx/size.h"
|
2017-05-18 02:25:40 +08:00
|
|
|
#include "render/task_delegate.h"
|
2015-06-23 07:58:33 +08:00
|
|
|
|
|
|
|
namespace render {
|
|
|
|
|
2019-04-04 06:32:24 +08:00
|
|
|
class Dithering;
|
|
|
|
class DitheringMatrix;
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2017-05-20 02:49:31 +08:00
|
|
|
class DitheringAlgorithmBase {
|
|
|
|
public:
|
|
|
|
virtual ~DitheringAlgorithmBase() {}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2019-04-02 08:44:06 +08:00
|
|
|
virtual int dimensions() const { return 1; }
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2019-04-02 08:44:06 +08:00
|
|
|
virtual void start(const doc::Image* srcImage, doc::Image* dstImage, const double factor) {}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2019-04-02 08:44:06 +08:00
|
|
|
virtual void finish() {}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2017-05-20 02:49:31 +08:00
|
|
|
virtual doc::color_t ditherRgbPixelToIndex(const DitheringMatrix& matrix,
|
|
|
|
const doc::color_t color,
|
2019-04-02 08:44:06 +08:00
|
|
|
const int x,
|
|
|
|
const int y,
|
|
|
|
const doc::RgbMap* rgbmap,
|
|
|
|
const doc::Palette* palette)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2019-04-02 08:44:06 +08:00
|
|
|
virtual doc::color_t ditherRgbToIndex2D(const int x,
|
|
|
|
const int y,
|
2017-05-20 02:49:31 +08:00
|
|
|
const doc::RgbMap* rgbmap,
|
2025-06-13 23:53:42 +08:00
|
|
|
const doc::Palette* palette,
|
|
|
|
const int direction)
|
2019-04-02 08:44:06 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-20 02:49:31 +08:00
|
|
|
};
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2017-05-20 02:49:31 +08:00
|
|
|
class OrderedDither : public DitheringAlgorithmBase {
|
2015-06-23 07:58:33 +08:00
|
|
|
public:
|
2017-06-02 04:14:15 +08:00
|
|
|
OrderedDither(int transparentIndex = -1);
|
2015-06-23 07:58:33 +08:00
|
|
|
doc::color_t ditherRgbPixelToIndex(const DitheringMatrix& matrix,
|
2017-05-20 02:49:31 +08:00
|
|
|
const doc::color_t color,
|
|
|
|
const int x,
|
|
|
|
const int y,
|
2015-06-23 07:58:33 +08:00
|
|
|
const doc::RgbMap* rgbmap,
|
2017-06-02 04:14:15 +08:00
|
|
|
const doc::Palette* palette) override;
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2017-05-18 00:32:34 +08:00
|
|
|
private:
|
|
|
|
int m_transparentIndex;
|
|
|
|
};
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2017-05-20 02:49:31 +08:00
|
|
|
class OrderedDither2 : public DitheringAlgorithmBase {
|
2017-05-18 00:32:34 +08:00
|
|
|
public:
|
2017-06-02 04:14:15 +08:00
|
|
|
OrderedDither2(int transparentIndex = -1);
|
2017-05-18 00:32:34 +08:00
|
|
|
doc::color_t ditherRgbPixelToIndex(const DitheringMatrix& matrix,
|
2017-05-20 02:49:31 +08:00
|
|
|
const doc::color_t color,
|
|
|
|
const int x,
|
|
|
|
const int y,
|
2017-05-18 00:32:34 +08:00
|
|
|
const doc::RgbMap* rgbmap,
|
2017-06-02 04:14:15 +08:00
|
|
|
const doc::Palette* palette) override;
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2015-06-23 07:58:33 +08:00
|
|
|
private:
|
|
|
|
int m_transparentIndex;
|
|
|
|
};
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2017-05-20 02:49:31 +08:00
|
|
|
void dither_rgb_image_to_indexed(DitheringAlgorithmBase& algorithm,
|
2019-04-04 06:32:24 +08:00
|
|
|
const Dithering& dithering,
|
2017-05-20 02:49:31 +08:00
|
|
|
const doc::Image* srcImage,
|
|
|
|
doc::Image* dstImage,
|
|
|
|
const doc::RgbMap* rgbmap,
|
|
|
|
const doc::Palette* palette,
|
|
|
|
TaskDelegate* delegate = nullptr);
|
2017-05-18 00:32:34 +08:00
|
|
|
|
2015-06-23 07:58:33 +08:00
|
|
|
} // namespace render
|
|
|
|
|
|
|
|
#endif
|