2025-06-12 22:25:20 +08:00
|
|
|
// Aseprite Render Library
|
2021-05-10 07:53:09 +08:00
|
|
|
// Copyright (c) 2019-2021 Igara Studio S.A.
|
2019-08-13 03:42:51 +08:00
|
|
|
// Copyright (c) 2001-2017 David Capello
|
2014-12-28 22:06:11 +08:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifndef RENDER_QUANTIZATION_H_INCLUDED
|
|
|
|
#define RENDER_QUANTIZATION_H_INCLUDED
|
|
|
|
#pragma once
|
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
#include "doc/frame.h"
|
2014-12-28 22:06:11 +08:00
|
|
|
#include "doc/pixel_format.h"
|
2020-04-15 07:01:25 +08:00
|
|
|
#include "doc/rgbmap_algorithm.h"
|
2014-12-28 22:06:11 +08:00
|
|
|
#include "render/color_histogram.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace doc {
|
|
|
|
class Image;
|
|
|
|
class Palette;
|
|
|
|
class RgbMap;
|
|
|
|
class Sprite;
|
|
|
|
} // namespace doc
|
|
|
|
|
|
|
|
namespace render {
|
2019-04-04 06:32:24 +08:00
|
|
|
class Dithering;
|
2017-05-18 02:25:40 +08:00
|
|
|
class TaskDelegate;
|
2015-07-23 05:26:25 +08:00
|
|
|
|
2015-07-02 22:18:43 +08:00
|
|
|
class PaletteOptimizer {
|
|
|
|
public:
|
2020-03-27 03:19:48 +08:00
|
|
|
void feedWithImage(const doc::Image* image, const bool withAlpha);
|
|
|
|
void feedWithImage(const doc::Image* image, const gfx::Rect& bounds, const bool withAlpha);
|
2017-05-16 03:25:09 +08:00
|
|
|
void feedWithRgbaColor(doc::color_t color);
|
2017-05-18 02:25:40 +08:00
|
|
|
void calculate(doc::Palette* palette, int maskIndex);
|
2020-03-26 01:32:43 +08:00
|
|
|
bool isHighPrecision() { return m_histogram.isHighPrecision(); }
|
|
|
|
int highPrecisionSize() { return m_histogram.highPrecisionSize(); }
|
2014-12-28 22:06:11 +08:00
|
|
|
|
|
|
|
private:
|
2017-05-16 03:25:09 +08:00
|
|
|
render::ColorHistogram<5, 6, 5, 5> m_histogram;
|
2019-08-13 03:42:51 +08:00
|
|
|
bool m_withAlpha = false;
|
2014-12-28 22:06:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Creates a new palette suitable to quantize the given RGB sprite to Indexed color.
|
2017-05-16 03:25:09 +08:00
|
|
|
doc::Palette* create_palette_from_sprite(const doc::Sprite* sprite,
|
|
|
|
const doc::frame_t fromFrame,
|
|
|
|
const doc::frame_t toFrame,
|
|
|
|
const bool withAlpha,
|
|
|
|
doc::Palette* newPalette, // Can be NULL to create a new
|
|
|
|
// palette
|
2019-02-26 05:02:58 +08:00
|
|
|
TaskDelegate* delegate,
|
2020-04-15 07:01:25 +08:00
|
|
|
const bool newBlend,
|
2021-05-10 07:53:09 +08:00
|
|
|
RgbMapAlgorithm mapAlgo,
|
2020-03-26 01:32:43 +08:00
|
|
|
const bool calculateWithTransparent = true);
|
2014-12-28 22:06:11 +08:00
|
|
|
|
|
|
|
// Changes the image pixel format. The dithering method is used only
|
|
|
|
// when you want to convert from RGB to Indexed.
|
|
|
|
Image* convert_pixel_format(const doc::Image* src,
|
2017-05-16 03:25:09 +08:00
|
|
|
doc::Image* dst, // Can be NULL to create a new image
|
|
|
|
doc::PixelFormat pixelFormat,
|
2019-04-04 06:32:24 +08:00
|
|
|
const render::Dithering& dithering,
|
2017-05-16 03:25:09 +08:00
|
|
|
const doc::RgbMap* rgbmap,
|
|
|
|
const doc::Palette* palette,
|
2015-07-14 20:44:31 +08:00
|
|
|
bool is_background,
|
2017-05-17 04:18:55 +08:00
|
|
|
doc::color_t new_mask_color,
|
2020-04-20 21:18:12 +08:00
|
|
|
doc::rgba_to_graya_func toGray = nullptr,
|
2017-05-18 02:25:40 +08:00
|
|
|
TaskDelegate* delegate = nullptr);
|
2014-12-28 22:06:11 +08:00
|
|
|
|
|
|
|
} // namespace render
|
|
|
|
|
|
|
|
#endif
|