use QImage instead of QPixmap for image nodes
This commit is contained in:
@@ -30,10 +30,10 @@ void ImageCreateNode::compute()
|
||||
unsigned int height = defaultPortData<UnsignedIntegerData>(PortType::In, 2)->value();
|
||||
glm::vec4 color = defaultPortData<ColorData>(PortType::In, 3)->value();
|
||||
|
||||
QPixmap pixmap = QPixmap(QSize(width, height));
|
||||
pixmap.fill(QColor::fromRgbF(color.r, color.b, color.g, color.a));
|
||||
QImage image = QImage(QSize(width, height), QImage::Format_RGBA8888);
|
||||
image.fill(QColor::fromRgbF(color.r, color.b, color.g, color.a));
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(pixmap);
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(image);
|
||||
Q_EMIT dataUpdated(1);
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
|
||||
66
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageFillNode.cpp
Normal file
66
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageFillNode.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageFillNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageFillNode::ImageFillNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageFillNode");
|
||||
setCaption("Image Fill");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<ColorData>(PortType::In, "Color", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
}
|
||||
|
||||
void ImageFillNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
glm::vec4 color = defaultPortData<ColorData>(PortType::In, 2)->value();
|
||||
image.fill(QColor::fromRgbF(color.r, color.g, color.b, color.a));
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(image);
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
NodeValidationState ImageFillNode::validate()
|
||||
{
|
||||
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
QJsonObject ImageFillNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
defaultWidgetToJson(PortType::In, 2, json_obj, "color");
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void ImageFillNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
|
||||
defaultWidgetFromJson(PortType::In, 2, json_obj, "color");
|
||||
}
|
||||
|
||||
36
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageFillNode.hpp
Normal file
36
src/noggit/Red/NodeEditor/Nodes/Data/Image/ImageFillNode.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGEFILLNODE_HPP
|
||||
#define NOGGIT_IMAGEFILLNODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageFillNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageFillNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGEFILLNODE_HPP
|
||||
@@ -0,0 +1,73 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageGetPixelNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageGetPixelNode::ImageGetPixelNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageGetPixelNode");
|
||||
setCaption("Image Get Pixel");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<Vector2DData>(PortType::In, "PixelXY<Vector2D>", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ColorData>(PortType::Out, "Color", true);
|
||||
}
|
||||
|
||||
void ImageGetPixelNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
glm::vec2 pixel_xy = defaultPortData<Vector2DData>(PortType::In, 2)->value();
|
||||
|
||||
if (pixel_xy.x >= image.width() || pixel_xy.y >= image.height() || pixel_xy.y < 0 || pixel_xy.x < 0)
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: pixel coordinates are out of range.");
|
||||
return;
|
||||
}
|
||||
|
||||
QColor color = image.pixelColor(pixel_xy.x, pixel_xy.y);
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ColorData>(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF()));
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
NodeValidationState ImageGetPixelNode::validate()
|
||||
{
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
QJsonObject ImageGetPixelNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
defaultWidgetToJson(PortType::In, 2, json_obj, "pixel_xy");
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void ImageGetPixelNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
|
||||
defaultWidgetFromJson(PortType::In, 2, json_obj, "pixel_xy");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGEGETPIXELNODE_HPP
|
||||
#define NOGGIT_IMAGEGETPIXELNODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageGetPixelNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageGetPixelNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGEGETPIXELNODE_HPP
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
#include <QImage>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageInfoNode::ImageInfoNode()
|
||||
@@ -20,17 +22,18 @@ ImageInfoNode::ImageInfoNode()
|
||||
addPort<BooleanData>(PortType::Out, "HasAlpha<Boolean>", true);
|
||||
addPort<BooleanData>(PortType::Out, "IsNull<Boolean>", true);
|
||||
addPort<IntegerData>(PortType::Out, "Depth<Integer>", true);
|
||||
addPort<BooleanData>(PortType::Out, "IsGrayscale<Integer>", true);
|
||||
}
|
||||
|
||||
void ImageInfoNode::compute()
|
||||
{
|
||||
QPixmap image = static_cast<ImageData*>(_in_ports[0].in_value.lock().get())->value();
|
||||
QImage image = static_cast<ImageData*>(_in_ports[0].in_value.lock().get())->value();
|
||||
|
||||
auto size = image.size();
|
||||
_out_ports[0].out_value = std::make_shared<Vector2DData>(glm::vec2(size.width(), size.height()));
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<BooleanData>(image.hasAlpha());
|
||||
_out_ports[1].out_value = std::make_shared<BooleanData>(image.hasAlphaChannel());
|
||||
Q_EMIT dataUpdated(1);
|
||||
|
||||
_out_ports[2].out_value = std::make_shared<BooleanData>(image.isNull());
|
||||
@@ -39,6 +42,9 @@ void ImageInfoNode::compute()
|
||||
_out_ports[3].out_value = std::make_shared<IntegerData>(image.depth());
|
||||
Q_EMIT dataUpdated(3);
|
||||
|
||||
_out_ports[4].out_value = std::make_shared<BooleanData>(image.isGrayscale());
|
||||
Q_EMIT dataUpdated(4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageInvertNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
InvertImageNode::InvertImageNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageInvertNode");
|
||||
setCaption("Image Invert");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
}
|
||||
|
||||
void InvertImageNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
|
||||
image.invertPixels();
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(image);
|
||||
Q_EMIT dataUpdated(1);
|
||||
|
||||
}
|
||||
|
||||
NodeValidationState InvertImageNode::validate()
|
||||
{
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_INVERTIMAGENODE_HPP
|
||||
#define NOGGIT_INVERTIMAGENODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class InvertImageNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InvertImageNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_INVERTIMAGENODE_HPP
|
||||
@@ -0,0 +1,70 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageMirrorNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
MirrorImageNode::MirrorImageNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageMirrorNode");
|
||||
setCaption("Image Mirror");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<BooleanData>(PortType::In, "U<Boolean>", true);
|
||||
addPortDefault<BooleanData>(PortType::In, "V<Boolean>", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
}
|
||||
|
||||
void MirrorImageNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
|
||||
QImage new_img = image.mirrored(defaultPortData<BooleanData>(PortType::In, 2)->value(),
|
||||
defaultPortData<BooleanData>(PortType::In, 3)->value());
|
||||
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(new_img);
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
NodeValidationState MirrorImageNode::validate()
|
||||
{
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
QJsonObject MirrorImageNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
defaultWidgetToJson(PortType::In, 2, json_obj, "mirror_u");
|
||||
defaultWidgetToJson(PortType::In, 3, json_obj, "mirror_v");
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void MirrorImageNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
|
||||
defaultWidgetFromJson(PortType::In, 2, json_obj, "mirror_u");
|
||||
defaultWidgetFromJson(PortType::In, 3, json_obj, "mirror_v");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_MIRRORIMAGENODE_HPP
|
||||
#define NOGGIT_MIRRORIMAGENODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class MirrorImageNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MirrorImageNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_MIRRORIMAGENODE_HPP
|
||||
@@ -0,0 +1,77 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageResizeNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageResizeNode::ImageResizeNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageResizeNode");
|
||||
setCaption("Image Resize");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
_mode = new QComboBox(&_embedded_widget);
|
||||
_mode->addItems({"Fast", "Smooth"});
|
||||
addWidgetTop(_mode);
|
||||
|
||||
_aspect_ratio_mode = new QComboBox(&_embedded_widget);
|
||||
_aspect_ratio_mode->addItems({"Ignore", "Keep", "Keep by expanding"});
|
||||
addWidgetTop(_aspect_ratio_mode);
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<Vector2DData>(PortType::In, "Size<Vector2D>", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ImageResizeNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
glm::vec2 size = defaultPortData<Vector2DData>(PortType::In, 2)->value();
|
||||
QImage new_img = image.scaled(size.x, size.y,
|
||||
static_cast<Qt::AspectRatioMode>(_aspect_ratio_mode->currentIndex()),
|
||||
static_cast<Qt::TransformationMode>(_mode->currentIndex()));
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(new_img);
|
||||
Q_EMIT dataUpdated(1);
|
||||
|
||||
}
|
||||
|
||||
NodeValidationState ImageResizeNode::validate()
|
||||
{
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
QJsonObject ImageResizeNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
defaultWidgetToJson(PortType::In, 2, json_obj, "size");
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void ImageResizeNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
defaultWidgetFromJson(PortType::In, 2, json_obj, "size");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGERESIZENODE_HPP
|
||||
#define NOGGIT_IMAGERESIZENODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageResizeNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageResizeNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
private:
|
||||
QComboBox* _aspect_ratio_mode;
|
||||
QComboBox* _mode;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGERESIZENODE_HPP
|
||||
@@ -26,7 +26,7 @@ ImageSaveNode::ImageSaveNode()
|
||||
|
||||
void ImageSaveNode::compute()
|
||||
{
|
||||
QPixmap image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
auto path_ptr = static_cast<StringData*>(_in_ports[2].in_value.lock().get());
|
||||
QString path = path_ptr ? path_ptr->value().c_str() : static_cast<QLineEdit*>(_in_ports[2].default_widget)->text();
|
||||
|
||||
@@ -36,7 +36,7 @@ void ImageSaveNode::compute()
|
||||
path_folder.mkpath(".");
|
||||
}
|
||||
|
||||
if (path.isEmpty() || !image.toImage().save(path, "PNG"))
|
||||
if (path.isEmpty() || !image.save(path, "PNG"))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: saving image failed.");
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageSetPixelNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageSetPixelNode::ImageSetPixelNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageSetPixelNode");
|
||||
setCaption("Image Set Pixel");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<Vector2DData>(PortType::In, "PixelXY<Vector2D>", true);
|
||||
addPortDefault<ColorData>(PortType::In, "Color", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
}
|
||||
|
||||
void ImageSetPixelNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
glm::vec2 pixel_xy = defaultPortData<Vector2DData>(PortType::In, 2)->value();
|
||||
glm::vec4 color = defaultPortData<ColorData>(PortType::In, 3)->value();
|
||||
|
||||
if (pixel_xy.x >= image.width() || pixel_xy.y >= image.height() || pixel_xy.y < 0 || pixel_xy.x < 0)
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: pixel coordinates are out of range.");
|
||||
return;
|
||||
}
|
||||
|
||||
image.setPixelColor(pixel_xy.x, pixel_xy.y, QColor::fromRgbF(color.r, color.g, color.b, color.a));
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(image);
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
NodeValidationState ImageSetPixelNode::validate()
|
||||
{
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
QJsonObject ImageSetPixelNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
defaultWidgetToJson(PortType::In, 2, json_obj, "pixel_xy");
|
||||
defaultWidgetToJson(PortType::In, 3, json_obj, "color");
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void ImageSetPixelNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
|
||||
defaultWidgetFromJson(PortType::In, 2, json_obj, "pixel_xy");
|
||||
defaultWidgetFromJson(PortType::In, 3, json_obj, "color");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGESETPIXELNODE_HPP
|
||||
#define NOGGIT_IMAGESETPIXELNODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageSetPixelNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageSetPixelNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGESETPIXELNODE_HPP
|
||||
@@ -0,0 +1,61 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageToGrayscaleNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageToGrayscaleNode::ImageToGrayscaleNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageToGrayscaleNode");
|
||||
setCaption("Image to Grayscale");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<ColorData>(PortType::In, "Color", true);
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ImageData>(PortType::Out, "Image", true);
|
||||
}
|
||||
|
||||
void ImageToGrayscaleNode::compute()
|
||||
{
|
||||
QImage image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value();
|
||||
|
||||
for (int ii = 0; ii < image.height(); ii++)
|
||||
{
|
||||
uchar* scan = image.scanLine(ii);
|
||||
int depth = 4;
|
||||
for (int jj = 0; jj < image.width(); jj++)
|
||||
{
|
||||
|
||||
QRgb* rgbpixel = reinterpret_cast<QRgb*>(scan + jj*depth);
|
||||
int gray = qGray(*rgbpixel);
|
||||
*rgbpixel = QColor(gray, gray, gray).rgba();
|
||||
}
|
||||
}
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(image);
|
||||
Q_EMIT dataUpdated(1);
|
||||
|
||||
}
|
||||
|
||||
NodeValidationState ImageToGrayscaleNode::validate()
|
||||
{
|
||||
if (!static_cast<ImageData*>(_in_ports[1].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate image input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGETOGRAYSCALENODE_HPP
|
||||
#define NOGGIT_IMAGETOGRAYSCALENODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageToGrayscaleNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageToGrayscaleNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGETOGRAYSCALENODE_HPP
|
||||
@@ -60,7 +60,7 @@ void LoadImageNode::compute()
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(QPixmap::fromImage(image));
|
||||
_out_ports[1].out_value = std::make_shared<ImageData>(image);
|
||||
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QColor>
|
||||
#include <QPixmap>
|
||||
#include <QImage>
|
||||
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeData;
|
||||
@@ -478,7 +478,7 @@ DECLARE_NODE_DATA_TYPE(list, List, std::vector<std::shared_ptr<NodeData>>*, NoDe
|
||||
|
||||
// Custom types
|
||||
DECLARE_NODE_DATA_TYPE(color, Color, glm::vec4, DefaultColorWidget);
|
||||
DECLARE_NODE_DATA_TYPE(image, Image, QPixmap, NoDefaultWidget);
|
||||
DECLARE_NODE_DATA_TYPE(image, Image, QImage, NoDefaultWidget);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user