2014-12-28 22:06:11 +08:00
|
|
|
// Aseprite Rener Library
|
2019-08-13 03:42:51 +08:00
|
|
|
// Copyright (c) 2019 Igara Studio S.A.
|
|
|
|
// 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"
|
|
|
|
#include "render/color_histogram.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace doc {
|
|
|
|
class Image;
|
|
|
|
class Palette;
|
|
|
|
class RgbMap;
|
|
|
|
class Sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2017-05-16 03:25:09 +08:00
|
|
|
void feedWithImage(doc::Image* image, bool withAlpha);
|
|
|
|
void feedWithRgbaColor(doc::color_t color);
|
2017-05-18 02:25:40 +08:00
|
|
|
void calculate(doc::Palette* palette, int maskIndex);
|
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,
|
|
|
|
const bool newBlend);
|
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(
|
2017-05-16 03:25:09 +08:00
|
|
|
const doc::Image* src,
|
|
|
|
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,
|
2017-05-18 02:25:40 +08:00
|
|
|
TaskDelegate* delegate = nullptr);
|
2014-12-28 22:06:11 +08:00
|
|
|
|
|
|
|
} // namespace render
|
|
|
|
|
|
|
|
#endif
|