Move doc::DitheringMethod -> render::DitheringAlgorithm

This commit is contained in:
David Capello 2017-05-15 16:25:09 -03:00
parent e4a4f44127
commit 23272895c4
16 changed files with 97 additions and 85 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -31,7 +31,8 @@ namespace cmd {
using namespace doc;
SetPixelFormat::SetPixelFormat(Sprite* sprite,
PixelFormat newFormat, DitheringMethod dithering)
const PixelFormat newFormat,
const render::DitheringAlgorithm dithering)
: WithSprite(sprite)
, m_oldFormat(sprite->pixelFormat())
, m_newFormat(newFormat)

View File

@ -8,10 +8,10 @@
#define APP_CMD_SET_PIXEL_FORMAT_H_INCLUDED
#pragma once
#include "app/cmd_sequence.h"
#include "app/cmd/with_sprite.h"
#include "app/cmd_sequence.h"
#include "doc/pixel_format.h"
#include "doc/dithering_method.h"
#include "render/dithering_algorithm.h"
namespace doc {
class Sprite;
@ -19,14 +19,13 @@ namespace doc {
namespace app {
namespace cmd {
using namespace doc;
class SetPixelFormat : public Cmd
, public WithSprite {
public:
SetPixelFormat(Sprite* sprite,
PixelFormat newFormat,
DitheringMethod dithering);
SetPixelFormat(doc::Sprite* sprite,
const doc::PixelFormat newFormat,
const render::DitheringAlgorithm dithering);
protected:
void onExecute() override;
@ -39,9 +38,9 @@ namespace cmd {
private:
void setFormat(PixelFormat format);
PixelFormat m_oldFormat;
PixelFormat m_newFormat;
DitheringMethod m_dithering;
doc::PixelFormat m_oldFormat;
doc::PixelFormat m_newFormat;
render::DitheringAlgorithm m_dithering;
CmdSequence m_seq;
};

View File

@ -16,15 +16,16 @@
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/transaction.h"
#include "doc/dithering_method.h"
#include "doc/image.h"
#include "doc/sprite.h"
#include "render/dithering_algorithm.h"
namespace app {
class ChangePixelFormatCommand : public Command {
PixelFormat m_format;
DitheringMethod m_dithering;
doc::PixelFormat m_format;
render::DitheringAlgorithm m_dithering;
public:
ChangePixelFormatCommand();
Command* clone() const override { return new ChangePixelFormatCommand(*this); }
@ -42,7 +43,7 @@ ChangePixelFormatCommand::ChangePixelFormatCommand()
CmdUIOnlyFlag)
{
m_format = IMAGE_RGB;
m_dithering = DitheringMethod::NONE;
m_dithering = render::DitheringAlgorithm::None;
}
void ChangePixelFormatCommand::onLoadParams(const Params& params)
@ -54,9 +55,9 @@ void ChangePixelFormatCommand::onLoadParams(const Params& params)
std::string dithering = params.get("dithering");
if (dithering == "ordered")
m_dithering = DitheringMethod::ORDERED;
m_dithering = render::DitheringAlgorithm::Ordered;
else
m_dithering = DitheringMethod::NONE;
m_dithering = render::DitheringAlgorithm::None;
}
bool ChangePixelFormatCommand::onEnabled(Context* context)
@ -67,7 +68,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context)
if (sprite != NULL &&
sprite->pixelFormat() == IMAGE_INDEXED &&
m_format == IMAGE_INDEXED &&
m_dithering == DitheringMethod::ORDERED)
m_dithering == render::DitheringAlgorithm::Ordered)
return false;
return sprite != NULL;
@ -81,7 +82,7 @@ bool ChangePixelFormatCommand::onChecked(Context* context)
if (sprite != NULL &&
sprite->pixelFormat() == IMAGE_INDEXED &&
m_format == IMAGE_INDEXED &&
m_dithering == DitheringMethod::ORDERED)
m_dithering == render::DitheringAlgorithm::Ordered)
return false;
return

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -270,7 +270,7 @@ void NewLayerCommand::onExecute(Context* context)
pasteImage.get(),
nullptr,
sprite->pixelFormat(),
DitheringMethod::NONE,
render::DitheringAlgorithm::None,
sprite->rgbMap(dstFrame),
pasteSpr->palette(fr),
(pasteSpr->backgroundLayer() ? true: false),

View File

@ -184,7 +184,8 @@ void PasteTextCommand::onExecute(Context* ctx)
image.reset(
render::convert_pixel_format(
image.get(), NULL, sprite->pixelFormat(),
DitheringMethod::NONE, rgbmap, sprite->palette(editor->frame()),
render::DitheringAlgorithm::None, rgbmap,
sprite->palette(editor->frame()),
false, 0));
}

View File

@ -181,7 +181,9 @@ void DocumentApi::trimSprite(Sprite* sprite)
cropSprite(sprite, bounds);
}
void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, DitheringMethod dithering)
void DocumentApi::setPixelFormat(Sprite* sprite,
const PixelFormat newFormat,
const render::DitheringAlgorithm dithering)
{
if (sprite->pixelFormat() == newFormat)
return;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -10,11 +10,11 @@
#include "doc/algorithm/flip_type.h"
#include "doc/color.h"
#include "doc/dithering_method.h"
#include "doc/frame.h"
#include "doc/image_ref.h"
#include "doc/pixel_format.h"
#include "gfx/rect.h"
#include "render/dithering_algorithm.h"
namespace doc {
class Cel;
@ -46,7 +46,9 @@ namespace app {
void setSpriteTransparentColor(Sprite* sprite, color_t maskColor);
void cropSprite(Sprite* sprite, const gfx::Rect& bounds);
void trimSprite(Sprite* sprite);
void setPixelFormat(Sprite* sprite, PixelFormat newFormat, DitheringMethod dithering);
void setPixelFormat(Sprite* sprite,
const PixelFormat newFormat,
const render::DitheringAlgorithm dithering);
// Frames API
void addFrame(Sprite* sprite, frame_t newFrame);

View File

@ -26,7 +26,6 @@
#include "base/unique_ptr.h"
#include "doc/algorithm/shrink_bounds.h"
#include "doc/cel.h"
#include "doc/dithering_method.h"
#include "doc/frame_tag.h"
#include "doc/image.h"
#include "doc/layer.h"
@ -38,6 +37,7 @@
#include "doc/sprite.h"
#include "gfx/packing_rects.h"
#include "gfx/size.h"
#include "render/dithering_algorithm.h"
#include "render/render.h"
#include <cstdio>
@ -707,7 +707,8 @@ void DocumentExporter::renderTexture(const Samples& samples, Image* textureImage
cmd::SetPixelFormat(
sample.sprite(),
textureImage->pixelFormat(),
DitheringMethod::NONE).execute(UIContext::instance());
render::DitheringAlgorithm::None)
.execute(UIContext::instance());
}
renderSample(sample, textureImage,

View File

@ -695,7 +695,8 @@ private:
Image* oldImage = cel->image();
ImageRef newImage(
render::convert_pixel_format
(oldImage, NULL, IMAGE_RGB, DitheringMethod::NONE,
(oldImage, NULL, IMAGE_RGB,
render::DitheringAlgorithm::None,
nullptr,
m_sprite->palette(cel->frame()),
m_opaque,
@ -706,7 +707,8 @@ private:
m_currentImage.reset(
render::convert_pixel_format
(m_currentImage.get(), NULL, IMAGE_RGB, DitheringMethod::NONE,
(m_currentImage.get(), NULL, IMAGE_RGB,
render::DitheringAlgorithm::None,
nullptr,
m_sprite->palette(m_frameNum),
m_opaque,
@ -714,7 +716,8 @@ private:
m_previousImage.reset(
render::convert_pixel_format
(m_previousImage.get(), NULL, IMAGE_RGB, DitheringMethod::NONE,
(m_previousImage.get(), NULL, IMAGE_RGB,
render::DitheringAlgorithm::None,
nullptr,
m_sprite->palette(MAX(0, m_frameNum-1)),
m_opaque,

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -9,7 +9,7 @@
#pragma once
#include "app/file/format_options.h"
#include "doc/dithering_method.h"
#include "render/dithering_algorithm.h"
namespace app {

View File

@ -332,7 +332,8 @@ void paste()
src_image.reset(
render::convert_pixel_format(
clipboard_image.get(), NULL, dstSpr->pixelFormat(),
DitheringMethod::NONE, dst_rgbmap, clipboard_palette.get(),
render::DitheringAlgorithm::None,
dst_rgbmap, clipboard_palette.get(),
false,
0));
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -52,7 +52,7 @@ Cel* create_cel_copy(const Cel* srcCel,
celImage,
tmpImage.get(),
IMAGE_RGB,
DitheringMethod::NONE,
render::DitheringAlgorithm::None,
srcCel->sprite()->rgbMap(srcCel->frame()),
srcCel->sprite()->palette(srcCel->frame()),
srcCel->layer()->isBackground(),
@ -62,7 +62,7 @@ Cel* create_cel_copy(const Cel* srcCel,
tmpImage.get(),
dstCel->image(),
IMAGE_INDEXED,
DitheringMethod::NONE,
render::DitheringAlgorithm::None,
dstSprite->rgbMap(dstFrame),
dstSprite->palette(dstFrame),
srcCel->layer()->isBackground(),

View File

@ -1,21 +0,0 @@
// Aseprite Document Library
// Copyright (c) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_DITHERING_METHOD_H_INCLUDED
#define DOC_DITHERING_METHOD_H_INCLUDED
#pragma once
namespace doc {
// Dithering methods
enum class DitheringMethod {
NONE,
ORDERED,
};
} // namespace doc
#endif

View File

@ -0,0 +1,22 @@
// Aseprite Render Library
// 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_DITHERING_METHOD_H_INCLUDED
#define RENDER_DITHERING_METHOD_H_INCLUDED
#pragma once
namespace render {
// Dithering algorithms
enum class DitheringAlgorithm {
None,
OldOrdered,
Ordered,
};
} // namespace render
#endif

View File

@ -36,9 +36,9 @@ using namespace gfx;
Palette* create_palette_from_sprite(
const Sprite* sprite,
frame_t fromFrame,
frame_t toFrame,
bool withAlpha,
const frame_t fromFrame,
const frame_t toFrame,
const bool withAlpha,
Palette* palette,
PaletteOptimizerDelegate* delegate)
{
@ -81,7 +81,7 @@ Image* convert_pixel_format(
const Image* image,
Image* new_image,
PixelFormat pixelFormat,
DitheringMethod ditheringMethod,
DitheringAlgorithm ditheringAlgorithm,
const RgbMap* rgbmap,
const Palette* palette,
bool is_background,
@ -94,7 +94,7 @@ Image* convert_pixel_format(
// RGB -> Indexed with ordered dithering
if (image->pixelFormat() == IMAGE_RGB &&
pixelFormat == IMAGE_INDEXED &&
ditheringMethod == DitheringMethod::ORDERED) {
ditheringAlgorithm == DitheringAlgorithm::Ordered) {
BayerMatrix<8> matrix;
OrderedDither dither;
dither.ditherRgbImageToIndexed(matrix, image, new_image, 0, 0, rgbmap, palette);

View File

@ -1,5 +1,5 @@
// Aseprite Rener Library
// Copyright (c) 2001-2015 David Capello
// Copyright (c) 2001-2015, 2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -8,11 +8,10 @@
#define RENDER_QUANTIZATION_H_INCLUDED
#pragma once
#include "doc/dithering_method.h"
#include "doc/frame.h"
#include "doc/pixel_format.h"
#include "render/color_histogram.h"
#include "render/dithering_algorithm.h"
#include <vector>
@ -24,7 +23,6 @@ namespace doc {
}
namespace render {
using namespace doc;
class PaletteOptimizerDelegate {
public:
@ -35,34 +33,36 @@ namespace render {
class PaletteOptimizer {
public:
void feedWithImage(Image* image, bool withAlpha);
void feedWithRgbaColor(color_t color);
void calculate(Palette* palette, int maskIndex, PaletteOptimizerDelegate* delegate);
void feedWithImage(doc::Image* image, bool withAlpha);
void feedWithRgbaColor(doc::color_t color);
void calculate(doc::Palette* palette,
int maskIndex,
render::PaletteOptimizerDelegate* delegate);
private:
ColorHistogram<5, 6, 5, 5> m_histogram;
render::ColorHistogram<5, 6, 5, 5> m_histogram;
};
// Creates a new palette suitable to quantize the given RGB sprite to Indexed color.
Palette* create_palette_from_sprite(
const Sprite* sprite,
frame_t fromFrame,
frame_t toFrame,
bool withAlpha,
Palette* newPalette, // Can be NULL to create a new palette
PaletteOptimizerDelegate* delegate);
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
render::PaletteOptimizerDelegate* delegate);
// 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 Image* src,
Image* dst, // Can be NULL to create a new image
PixelFormat pixelFormat,
DitheringMethod ditheringMethod,
const RgbMap* rgbmap,
const Palette* palette,
const doc::Image* src,
doc::Image* dst, // Can be NULL to create a new image
doc::PixelFormat pixelFormat,
render::DitheringAlgorithm ditheringAlgorithm,
const doc::RgbMap* rgbmap,
const doc::Palette* palette,
bool is_background,
color_t new_mask_color);
doc::color_t new_mask_color);
} // namespace render