mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 13:21:34 +00:00
[lua] Add support to use ColorCurve/ConvolutionMatrix commands from scripts
This commit is contained in:
parent
ccef22f187
commit
4c4c20ace6
@ -293,10 +293,6 @@ if(ENABLE_UI)
|
||||
commands/cmd_undo_history.cpp
|
||||
commands/cmd_unlink_cel.cpp
|
||||
commands/cmd_zoom.cpp
|
||||
commands/filters/cmd_color_curve.cpp
|
||||
commands/filters/cmd_convolution_matrix.cpp
|
||||
commands/filters/color_curve_editor.cpp
|
||||
commands/filters/convolution_matrix_stock.cpp
|
||||
commands/filters/filter_preview.cpp
|
||||
commands/filters/filter_target_buttons.cpp
|
||||
commands/filters/filter_window.cpp
|
||||
@ -516,11 +512,15 @@ add_library(app-lib
|
||||
commands/command.cpp
|
||||
commands/commands.cpp
|
||||
commands/filters/cmd_brightness_contrast.cpp
|
||||
commands/filters/cmd_color_curve.cpp
|
||||
commands/filters/cmd_convolution_matrix.cpp
|
||||
commands/filters/cmd_despeckle.cpp
|
||||
commands/filters/cmd_hue_saturation.cpp
|
||||
commands/filters/cmd_invert_color.cpp
|
||||
commands/filters/cmd_outline.cpp
|
||||
commands/filters/cmd_replace_color.cpp
|
||||
commands/filters/color_curve_editor.cpp
|
||||
commands/filters/convolution_matrix_stock.cpp
|
||||
commands/filters/filter_manager_impl.cpp
|
||||
commands/filters/filter_worker.cpp
|
||||
commands/move_thing.cpp
|
||||
|
@ -11,6 +11,8 @@ FOR_EACH_COMMAND(BrightnessContrast)
|
||||
FOR_EACH_COMMAND(CanvasSize)
|
||||
FOR_EACH_COMMAND(CelOpacity)
|
||||
FOR_EACH_COMMAND(ChangePixelFormat)
|
||||
FOR_EACH_COMMAND(ColorCurve)
|
||||
FOR_EACH_COMMAND(ConvolutionMatrix)
|
||||
FOR_EACH_COMMAND(CropSprite)
|
||||
FOR_EACH_COMMAND(Despeckle)
|
||||
FOR_EACH_COMMAND(ExportSpriteSheet)
|
||||
@ -48,10 +50,8 @@ FOR_EACH_COMMAND(ClearCel)
|
||||
FOR_EACH_COMMAND(ClearRecentFiles)
|
||||
FOR_EACH_COMMAND(CloseAllFiles)
|
||||
FOR_EACH_COMMAND(CloseFile)
|
||||
FOR_EACH_COMMAND(ColorCurve)
|
||||
FOR_EACH_COMMAND(ColorQuantization)
|
||||
FOR_EACH_COMMAND(ContiguousFill)
|
||||
FOR_EACH_COMMAND(ConvolutionMatrix)
|
||||
FOR_EACH_COMMAND(Copy)
|
||||
FOR_EACH_COMMAND(CopyCel)
|
||||
FOR_EACH_COMMAND(CopyMerged)
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -13,12 +14,10 @@
|
||||
#include "app/commands/filters/color_curve_editor.h"
|
||||
#include "app/commands/filters/filter_manager_impl.h"
|
||||
#include "app/commands/filters/filter_window.h"
|
||||
#include "app/commands/filters/filter_worker.h"
|
||||
#include "app/commands/new_params.h"
|
||||
#include "app/context.h"
|
||||
#include "app/ini_file.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/ui/color_button.h"
|
||||
#include "base/bind.h"
|
||||
#include "doc/mask.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "filters/color_curve.h"
|
||||
#include "filters/color_curve_filter.h"
|
||||
@ -28,7 +27,13 @@ namespace app {
|
||||
|
||||
using namespace filters;
|
||||
|
||||
static std::unique_ptr<ColorCurve> the_curve;
|
||||
struct ColorCurveParams : public NewParams {
|
||||
Param<bool> ui { this, true, "ui" };
|
||||
Param<filters::Target> channels { this, 0, "channels" };
|
||||
Param<filters::ColorCurve> curve { this, filters::ColorCurve(), "curve" };
|
||||
};
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
|
||||
class ColorCurveWindow : public FilterWindow {
|
||||
public:
|
||||
@ -37,8 +42,7 @@ public:
|
||||
WithChannelsSelector,
|
||||
WithoutTiledCheckBox)
|
||||
, m_filter(filter)
|
||||
, m_editor(filter.getCurve(), gfx::Rect(0, 0, 256, 256))
|
||||
{
|
||||
, m_editor(filter.getCurve(), gfx::Rect(0, 0, 256, 256)) {
|
||||
m_view.attachToView(&m_editor);
|
||||
m_view.setExpansive(true);
|
||||
m_view.setMinSize(gfx::Size(128, 64));
|
||||
@ -50,8 +54,7 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
void onCurveChange()
|
||||
{
|
||||
void onCurveChange() {
|
||||
// The color curve in the filter is the same refereced by the
|
||||
// editor. But anyway, we have to re-set the same curve in the
|
||||
// filter to regenerate the map used internally by the filter
|
||||
@ -67,7 +70,9 @@ private:
|
||||
ColorCurveEditor m_editor;
|
||||
};
|
||||
|
||||
class ColorCurveCommand : public Command {
|
||||
#endif // ENABLE_UI
|
||||
|
||||
class ColorCurveCommand : public CommandWithNewParams<ColorCurveParams> {
|
||||
public:
|
||||
ColorCurveCommand();
|
||||
|
||||
@ -77,7 +82,7 @@ protected:
|
||||
};
|
||||
|
||||
ColorCurveCommand::ColorCurveCommand()
|
||||
: Command(CommandId::ColorCurve(), CmdRecordableFlag)
|
||||
: CommandWithNewParams<ColorCurveParams>(CommandId::ColorCurve(), CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
@ -89,28 +94,50 @@ bool ColorCurveCommand::onEnabled(Context* context)
|
||||
|
||||
void ColorCurveCommand::onExecute(Context* context)
|
||||
{
|
||||
// Default curve
|
||||
if (!the_curve) {
|
||||
// TODO load the curve?
|
||||
|
||||
the_curve.reset(new ColorCurve(ColorCurve::Linear));
|
||||
the_curve->addPoint(gfx::Point(0, 0));
|
||||
the_curve->addPoint(gfx::Point(255, 255));
|
||||
}
|
||||
|
||||
const bool ui = (params().ui() && context->isUIAvailable());
|
||||
ColorCurveFilter filter;
|
||||
filter.setCurve(the_curve.get());
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
// Default curve
|
||||
if (ui) {
|
||||
static std::unique_ptr<ColorCurve> the_curve;
|
||||
if (!the_curve) {
|
||||
// TODO load the curve?
|
||||
the_curve.reset(new ColorCurve(ColorCurve::Linear));
|
||||
the_curve->addDefaultPoints();
|
||||
}
|
||||
filter.setCurve(*the_curve.get());
|
||||
}
|
||||
#endif
|
||||
|
||||
FilterManagerImpl filterMgr(context, &filter);
|
||||
filterMgr.setTarget(TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL |
|
||||
TARGET_GRAY_CHANNEL |
|
||||
TARGET_ALPHA_CHANNEL);
|
||||
|
||||
ColorCurveWindow window(filter, filterMgr);
|
||||
if (window.doModal()) {
|
||||
// TODO save the curve?
|
||||
filters::Target channels =
|
||||
TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL |
|
||||
TARGET_GRAY_CHANNEL;
|
||||
if (params().channels.isSet()) channels = params().channels();
|
||||
filterMgr.setTarget(channels);
|
||||
|
||||
if (params().curve.isSet()) filter.setCurve(params().curve());
|
||||
else if (!ui) {
|
||||
ColorCurve curve;
|
||||
curve.addDefaultPoints();
|
||||
filter.setCurve(curve);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
if (ui) {
|
||||
ColorCurveWindow window(filter, filterMgr);
|
||||
if (window.doModal()) {
|
||||
// TODO save the curve?
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif // ENABLE_UI
|
||||
{
|
||||
start_filter_worker(&filterMgr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -14,6 +15,8 @@
|
||||
#include "app/commands/filters/convolution_matrix_stock.h"
|
||||
#include "app/commands/filters/filter_manager_impl.h"
|
||||
#include "app/commands/filters/filter_window.h"
|
||||
#include "app/commands/filters/filter_worker.h"
|
||||
#include "app/commands/new_params.h"
|
||||
#include "app/context.h"
|
||||
#include "app/doc.h"
|
||||
#include "app/find_widget.h"
|
||||
@ -35,12 +38,22 @@
|
||||
#include "ui/window.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace filters;
|
||||
using namespace ui;
|
||||
|
||||
struct ConvolutionMatrixParams : public NewParams {
|
||||
Param<bool> ui { this, true, "ui" };
|
||||
Param<filters::Target> channels { this, 0, "channels" };
|
||||
Param<filters::TiledMode> tiledMode { this, filters::TiledMode::NONE, "tiledMode" };
|
||||
Param<std::string> fromResource { this, std::string(), "fromResource" };
|
||||
};
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
|
||||
static const char* ConfigSection = "ConvolutionMatrix";
|
||||
|
||||
class ConvolutionMatrixWindow : public FilterWindow {
|
||||
@ -87,7 +100,7 @@ private:
|
||||
|
||||
for (ConvolutionMatrixStock::iterator it = m_stock.begin(), end = m_stock.end();
|
||||
it != end; ++it) {
|
||||
base::SharedPtr<ConvolutionMatrix> matrix = *it;
|
||||
std::shared_ptr<ConvolutionMatrix> matrix = *it;
|
||||
ListItem* listitem = new ListItem(matrix->getName());
|
||||
m_stockListBox->addChild(listitem);
|
||||
}
|
||||
@ -119,7 +132,7 @@ private:
|
||||
void onMatrixChange()
|
||||
{
|
||||
Widget* selected = m_stockListBox->getSelectedChild();
|
||||
base::SharedPtr<ConvolutionMatrix> matrix = m_stock.getByName(selected->text().c_str());
|
||||
std::shared_ptr<ConvolutionMatrix> matrix = m_stock.getByName(selected->text().c_str());
|
||||
Target newTarget = matrix->getDefaultTarget();
|
||||
|
||||
m_filter.setMatrix(matrix);
|
||||
@ -137,7 +150,9 @@ private:
|
||||
Button* m_reloadButton;
|
||||
};
|
||||
|
||||
class ConvolutionMatrixCommand : public Command {
|
||||
#endif // ENABLE_UI
|
||||
|
||||
class ConvolutionMatrixCommand : public CommandWithNewParams<ConvolutionMatrixParams> {
|
||||
public:
|
||||
ConvolutionMatrixCommand();
|
||||
|
||||
@ -147,7 +162,7 @@ protected:
|
||||
};
|
||||
|
||||
ConvolutionMatrixCommand::ConvolutionMatrixCommand()
|
||||
: Command(CommandId::ConvolutionMatrix(), CmdRecordableFlag)
|
||||
: CommandWithNewParams<ConvolutionMatrixParams>(CommandId::ConvolutionMatrix(), CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
@ -159,28 +174,43 @@ bool ConvolutionMatrixCommand::onEnabled(Context* context)
|
||||
|
||||
void ConvolutionMatrixCommand::onExecute(Context* context)
|
||||
{
|
||||
// Load stock
|
||||
ConvolutionMatrixStock m_stock;
|
||||
#ifdef ENABLE_UI
|
||||
const bool ui = (params().ui() && context->isUIAvailable());
|
||||
#endif
|
||||
|
||||
// Get last used (selected) matrix
|
||||
base::SharedPtr<ConvolutionMatrix> matrix =
|
||||
m_stock.getByName(get_config_string(ConfigSection, "Selected", ""));
|
||||
static ConvolutionMatrixStock stock; // Load stock
|
||||
ConvolutionMatrixFilter filter; // Create the filter and setup initial settings
|
||||
|
||||
// Create the filter and setup initial settings
|
||||
DocumentPreferences& docPref = Preferences::instance()
|
||||
.document(context->activeDocument());
|
||||
std::shared_ptr<ConvolutionMatrix> matrix;
|
||||
#ifdef ENABLE_UI
|
||||
if (ui) {
|
||||
// Get last used (selected) matrix
|
||||
matrix = stock.getByName(get_config_string(ConfigSection, "Selected", ""));
|
||||
|
||||
ConvolutionMatrixFilter filter;
|
||||
filter.setTiledMode(docPref.tiled.mode());
|
||||
if (matrix)
|
||||
filter.setMatrix(matrix);
|
||||
DocumentPreferences& docPref = Preferences::instance()
|
||||
.document(context->activeDocument());
|
||||
filter.setTiledMode(docPref.tiled.mode());
|
||||
}
|
||||
#endif // ENABLE_UI
|
||||
|
||||
if (params().tiledMode.isSet()) filter.setTiledMode(params().tiledMode());
|
||||
if (params().fromResource.isSet()) matrix = stock.getByName(params().fromResource().c_str());
|
||||
if (matrix) filter.setMatrix(matrix);
|
||||
|
||||
FilterManagerImpl filterMgr(context, &filter);
|
||||
|
||||
ConvolutionMatrixWindow window(filter, filterMgr, m_stock);
|
||||
if (window.doModal()) {
|
||||
if (filter.getMatrix())
|
||||
set_config_string(ConfigSection, "Selected", filter.getMatrix()->getName());
|
||||
#ifdef ENABLE_UI
|
||||
if (ui) {
|
||||
ConvolutionMatrixWindow window(filter, filterMgr, stock);
|
||||
if (window.doModal()) {
|
||||
if (filter.getMatrix())
|
||||
set_config_string(ConfigSection, "Selected", filter.getMatrix()->getName());
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif // ENABLE_UI
|
||||
{
|
||||
start_filter_worker(&filterMgr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -42,7 +43,7 @@ enum {
|
||||
STATUS_SCALING,
|
||||
};
|
||||
|
||||
ColorCurveEditor::ColorCurveEditor(ColorCurve* curve, const gfx::Rect& viewBounds)
|
||||
ColorCurveEditor::ColorCurveEditor(const ColorCurve& curve, const gfx::Rect& viewBounds)
|
||||
: Widget(kGenericWidget)
|
||||
, m_curve(curve)
|
||||
, m_viewBounds(viewBounds)
|
||||
@ -74,9 +75,8 @@ bool ColorCurveEditor::onProcessMessage(Message* msg)
|
||||
}
|
||||
|
||||
case kKeyDel: {
|
||||
gfx::Point* point = getClosestPoint(screenToView(get_mouse_position()));
|
||||
if (point)
|
||||
removePoint(point);
|
||||
if (gfx::Point* point = getClosestPoint(screenToView(get_mouse_position())))
|
||||
removePoint(*point);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ void ColorCurveEditor::onPaint(ui::PaintEvent& ev)
|
||||
|
||||
// Get curve values
|
||||
std::vector<int> values(m_viewBounds.w);
|
||||
m_curve->getValues(m_viewBounds.x, m_viewBounds.x+m_viewBounds.w-1, values);
|
||||
m_curve.getValues(m_viewBounds.x, m_viewBounds.x+m_viewBounds.w-1, values);
|
||||
|
||||
// Draw curve
|
||||
for (c = client.x; c < client.x+client.w; ++c) {
|
||||
@ -217,7 +217,7 @@ void ColorCurveEditor::onPaint(ui::PaintEvent& ev)
|
||||
}
|
||||
|
||||
// Draw nodes
|
||||
for (const gfx::Point& point : *m_curve) {
|
||||
for (const gfx::Point& point : m_curve) {
|
||||
pt = viewToClient(point);
|
||||
|
||||
gfx::Rect box(0, 0, 5*guiscale(), 5*guiscale());
|
||||
@ -241,7 +241,7 @@ gfx::Point* ColorCurveEditor::getClosestPoint(const gfx::Point& viewPt)
|
||||
gfx::Point* point_found = NULL;
|
||||
double dist_min = 0;
|
||||
|
||||
for (gfx::Point& point : *m_curve) {
|
||||
for (gfx::Point& point : m_curve) {
|
||||
int dx = point.x - viewPt.x;
|
||||
int dy = point.y - viewPt.y;
|
||||
double dist = std::sqrt(static_cast<double>(dx*dx + dy*dy));
|
||||
@ -274,7 +274,7 @@ bool ColorCurveEditor::editNodeManually(gfx::Point& viewPt)
|
||||
return true;
|
||||
}
|
||||
else if (window.closer() == window.deleteButton()) {
|
||||
removePoint(&viewPt);
|
||||
removePoint(viewPt);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@ -307,16 +307,16 @@ gfx::Point ColorCurveEditor::clientToView(const gfx::Point& clientPt)
|
||||
void ColorCurveEditor::addPoint(const gfx::Point& viewPoint)
|
||||
{
|
||||
// TODO Undo history
|
||||
m_curve->addPoint(viewPoint);
|
||||
m_curve.addPoint(viewPoint);
|
||||
|
||||
invalidate();
|
||||
CurveEditorChange();
|
||||
}
|
||||
|
||||
void ColorCurveEditor::removePoint(gfx::Point* viewPoint)
|
||||
void ColorCurveEditor::removePoint(const gfx::Point& viewPoint)
|
||||
{
|
||||
// TODO Undo history
|
||||
m_curve->removePoint(*viewPoint);
|
||||
m_curve.removePoint(viewPoint);
|
||||
|
||||
m_hotPoint = nullptr;
|
||||
m_editPoint = nullptr;
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -8,22 +9,19 @@
|
||||
#define APP_COMMANDS_FILTERS_COLOR_CURVE_EDITOR_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "filters/color_curve.h"
|
||||
#include "gfx/point.h"
|
||||
#include "obs/signal.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
namespace filters {
|
||||
class ColorCurve;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
using namespace filters;
|
||||
|
||||
class ColorCurveEditor : public ui::Widget {
|
||||
public:
|
||||
ColorCurveEditor(ColorCurve* curve, const gfx::Rect& viewBounds);
|
||||
ColorCurveEditor(const ColorCurve& curve, const gfx::Rect& viewBounds);
|
||||
|
||||
ColorCurve* getCurve() const { return m_curve; }
|
||||
const ColorCurve& getCurve() const { return m_curve; }
|
||||
|
||||
obs::signal<void()> CurveEditorChange;
|
||||
|
||||
@ -39,9 +37,9 @@ namespace app {
|
||||
gfx::Point screenToView(const gfx::Point& screenPt);
|
||||
gfx::Point clientToView(const gfx::Point& clientPt);
|
||||
void addPoint(const gfx::Point& viewPoint);
|
||||
void removePoint(gfx::Point* viewPoint);
|
||||
void removePoint(const gfx::Point& viewPoint);
|
||||
|
||||
ColorCurve* m_curve;
|
||||
ColorCurve m_curve;
|
||||
int m_status;
|
||||
gfx::Rect m_viewBounds;
|
||||
gfx::Point* m_hotPoint;
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -30,13 +31,13 @@ ConvolutionMatrixStock::~ConvolutionMatrixStock()
|
||||
cleanStock();
|
||||
}
|
||||
|
||||
base::SharedPtr<ConvolutionMatrix> ConvolutionMatrixStock::getByName(const char* name)
|
||||
std::shared_ptr<ConvolutionMatrix> ConvolutionMatrixStock::getByName(const char* name)
|
||||
{
|
||||
for (const_iterator it = begin(), end = this->end(); it != end; ++it) {
|
||||
if (std::strcmp((*it)->getName(), name) == 0)
|
||||
return *it;
|
||||
}
|
||||
return base::SharedPtr<ConvolutionMatrix>(0);
|
||||
return std::shared_ptr<ConvolutionMatrix>(0);
|
||||
}
|
||||
|
||||
void ConvolutionMatrixStock::reloadStock()
|
||||
@ -56,7 +57,7 @@ void ConvolutionMatrixStock::reloadStock()
|
||||
"convmatr.def", NULL };
|
||||
char *s, buf[256], leavings[4096];
|
||||
int i, x, y, w, h, div, bias;
|
||||
base::SharedPtr<ConvolutionMatrix> matrix;
|
||||
std::shared_ptr<ConvolutionMatrix> matrix;
|
||||
std::string name;
|
||||
|
||||
cleanStock();
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -10,7 +11,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/shared_ptr.h"
|
||||
#include <memory>
|
||||
|
||||
namespace filters {
|
||||
class ConvolutionMatrix;
|
||||
@ -22,8 +23,8 @@ namespace app {
|
||||
// A container of all convolution matrices in the convmatr.def file.
|
||||
class ConvolutionMatrixStock {
|
||||
public:
|
||||
typedef std::vector<base::SharedPtr<ConvolutionMatrix> >::iterator iterator;
|
||||
typedef std::vector<base::SharedPtr<ConvolutionMatrix> >::const_iterator const_iterator;
|
||||
typedef std::vector<std::shared_ptr<ConvolutionMatrix> >::iterator iterator;
|
||||
typedef std::vector<std::shared_ptr<ConvolutionMatrix> >::const_iterator const_iterator;
|
||||
|
||||
ConvolutionMatrixStock();
|
||||
virtual ~ConvolutionMatrixStock();
|
||||
@ -33,13 +34,13 @@ namespace app {
|
||||
const_iterator begin() const { return m_matrices.begin(); }
|
||||
const_iterator end() const { return m_matrices.end(); }
|
||||
|
||||
base::SharedPtr<ConvolutionMatrix> getByName(const char* name);
|
||||
std::shared_ptr<ConvolutionMatrix> getByName(const char* name);
|
||||
|
||||
void reloadStock();
|
||||
void cleanStock();
|
||||
|
||||
private:
|
||||
std::vector<base::SharedPtr<ConvolutionMatrix> > m_matrices;
|
||||
std::vector<std::shared_ptr<ConvolutionMatrix> > m_matrices;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -14,8 +14,10 @@
|
||||
#include "app/doc_exporter.h"
|
||||
#include "app/sprite_sheet_type.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/split_string.h"
|
||||
#include "base/string.h"
|
||||
#include "doc/color_mode.h"
|
||||
#include "filters/color_curve.h"
|
||||
#include "filters/hue_saturation_filter.h"
|
||||
#include "filters/outline_filter.h"
|
||||
#include "filters/tiled_mode.h"
|
||||
@ -150,6 +152,21 @@ void Param<filters::HueSaturationFilter::Mode>::fromString(const std::string& va
|
||||
setValue(filters::HueSaturationFilter::Mode::HSL);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Param<filters::ColorCurve>::fromString(const std::string& value)
|
||||
{
|
||||
filters::ColorCurve curve;
|
||||
std::vector<std::string> parts;
|
||||
base::split_string(value, parts, ",");
|
||||
for (int i=0; i+1<int(parts.size()); i+=2) {
|
||||
curve.addPoint(
|
||||
gfx::Point(
|
||||
base::convert_to<int>(parts[i]),
|
||||
base::convert_to<int>(parts[i+1])));
|
||||
}
|
||||
setValue(curve);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Convert values from Lua
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -252,6 +269,23 @@ void Param<filters::HueSaturationFilter::Mode>::fromLua(lua_State* L, int index)
|
||||
setValue((filters::HueSaturationFilter::Mode)lua_tointeger(L, index));
|
||||
}
|
||||
|
||||
template<>
|
||||
void Param<filters::ColorCurve>::fromLua(lua_State* L, int index)
|
||||
{
|
||||
if (lua_type(L, index) == LUA_TSTRING)
|
||||
fromString(lua_tostring(L, index));
|
||||
else if (lua_type(L, index) == LUA_TTABLE) {
|
||||
filters::ColorCurve curve;
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2) != 0) {
|
||||
gfx::Point pt = script::convert_args_into_point(L, -1);
|
||||
curve.addPoint(pt);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
setValue(curve);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandWithNewParamsBase::loadParamsFromLuaTable(lua_State* L, int index)
|
||||
{
|
||||
onResetValues();
|
||||
|
@ -37,11 +37,18 @@ gfx::Point Point_new(lua_State* L, int index)
|
||||
}
|
||||
else {
|
||||
lua_pop(L, 1);
|
||||
|
||||
// TODO Investigate this further: why we cannot use two
|
||||
// lua_geti() calls and then lua_pop(L, 2) when we are iterating
|
||||
// points in a table defined like {{0,0},{32,32}}
|
||||
|
||||
lua_geti(L, index, 1);
|
||||
pt.x = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_geti(L, index, 2);
|
||||
pt.x = lua_tointeger(L, -2);
|
||||
pt.y = lua_tointeger(L, -1);
|
||||
lua_pop(L, 2);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -19,6 +20,12 @@ ColorCurve::ColorCurve(Type type)
|
||||
{
|
||||
}
|
||||
|
||||
void ColorCurve::addDefaultPoints()
|
||||
{
|
||||
addPoint(gfx::Point(0, 0));
|
||||
addPoint(gfx::Point(255, 255));
|
||||
}
|
||||
|
||||
void ColorCurve::addPoint(const gfx::Point& point)
|
||||
{
|
||||
for (iterator it = begin(), end = this->end(); it != end; ++it) {
|
||||
@ -27,7 +34,6 @@ void ColorCurve::addPoint(const gfx::Point& point)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_points.push_back(point);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -26,7 +27,9 @@ namespace filters {
|
||||
typedef Points::iterator iterator;
|
||||
typedef Points::const_iterator const_iterator;
|
||||
|
||||
ColorCurve(Type type);
|
||||
ColorCurve(Type type = Linear);
|
||||
|
||||
void addDefaultPoints();
|
||||
|
||||
iterator begin() { return m_points.begin(); }
|
||||
iterator end() { return m_points.end(); }
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -26,19 +27,20 @@ namespace filters {
|
||||
using namespace doc;
|
||||
|
||||
ColorCurveFilter::ColorCurveFilter()
|
||||
: m_curve(NULL)
|
||||
, m_cmap(256)
|
||||
: m_cmap(256)
|
||||
{
|
||||
}
|
||||
|
||||
void ColorCurveFilter::setCurve(ColorCurve* curve)
|
||||
void ColorCurveFilter::setCurve(const ColorCurve& curve)
|
||||
{
|
||||
ASSERT(curve != NULL);
|
||||
|
||||
m_curve = curve;
|
||||
generateMap();
|
||||
}
|
||||
|
||||
void ColorCurveFilter::generateMap()
|
||||
{
|
||||
// Generate the color convertion map
|
||||
m_curve->getValues(0, 255, m_cmap);
|
||||
m_curve.getValues(0, 255, m_cmap);
|
||||
for (int c=0; c<256; c++)
|
||||
m_cmap[c] = MID(0, m_cmap[c], 255);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -11,18 +12,16 @@
|
||||
#include <vector>
|
||||
|
||||
#include "filters/filter.h"
|
||||
#include "filters/color_curve.h"
|
||||
|
||||
namespace filters {
|
||||
|
||||
class ColorCurve;
|
||||
|
||||
class ColorCurveFilter : public Filter
|
||||
{
|
||||
class ColorCurveFilter : public Filter {
|
||||
public:
|
||||
ColorCurveFilter();
|
||||
|
||||
void setCurve(ColorCurve* curve);
|
||||
ColorCurve* getCurve() const { return m_curve; }
|
||||
void setCurve(const ColorCurve& curve);
|
||||
const ColorCurve& getCurve() const { return m_curve; }
|
||||
|
||||
// Filter implementation
|
||||
const char* getName();
|
||||
@ -31,7 +30,9 @@ namespace filters {
|
||||
void applyToIndexed(FilterManager* filterMgr);
|
||||
|
||||
private:
|
||||
ColorCurve* m_curve;
|
||||
void generateMap();
|
||||
|
||||
ColorCurve m_curve;
|
||||
std::vector<int> m_cmap;
|
||||
};
|
||||
|
||||
|
@ -116,7 +116,7 @@ ConvolutionMatrixFilter::ConvolutionMatrixFilter()
|
||||
{
|
||||
}
|
||||
|
||||
void ConvolutionMatrixFilter::setMatrix(const base::SharedPtr<ConvolutionMatrix>& matrix)
|
||||
void ConvolutionMatrixFilter::setMatrix(const std::shared_ptr<ConvolutionMatrix>& matrix)
|
||||
{
|
||||
m_matrix = matrix;
|
||||
}
|
||||
|
@ -9,10 +9,11 @@
|
||||
#define FILTERS_CONVOLUTION_MATRIX_FILTER_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/shared_ptr.h"
|
||||
#include "filters/filter.h"
|
||||
#include "filters/tiled_mode.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace filters {
|
||||
|
||||
class ConvolutionMatrix;
|
||||
@ -21,10 +22,10 @@ namespace filters {
|
||||
public:
|
||||
ConvolutionMatrixFilter();
|
||||
|
||||
void setMatrix(const base::SharedPtr<ConvolutionMatrix>& matrix);
|
||||
void setMatrix(const std::shared_ptr<ConvolutionMatrix>& matrix);
|
||||
void setTiledMode(TiledMode tiledMode);
|
||||
|
||||
base::SharedPtr<ConvolutionMatrix> getMatrix() { return m_matrix; }
|
||||
std::shared_ptr<ConvolutionMatrix> getMatrix() { return m_matrix; }
|
||||
TiledMode getTiledMode() const { return m_tiledMode; }
|
||||
|
||||
// Filter implementation
|
||||
@ -34,7 +35,7 @@ namespace filters {
|
||||
void applyToIndexed(FilterManager* filterMgr);
|
||||
|
||||
private:
|
||||
base::SharedPtr<ConvolutionMatrix> m_matrix;
|
||||
std::shared_ptr<ConvolutionMatrix> m_matrix;
|
||||
TiledMode m_tiledMode;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user