From e63dea61fd2f3ffedfd488c8b8d4caf7db83fdbf Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 9 Dec 2015 11:00:57 -0300 Subject: [PATCH] Include opacity and blend mode for each layer in JSON output --- src/app/document_exporter.cpp | 7 ++++++- src/doc/CMakeLists.txt | 1 + src/doc/blend_mode.cpp | 38 +++++++++++++++++++++++++++++++++++ src/doc/blend_mode.h | 4 ++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/doc/blend_mode.cpp diff --git a/src/app/document_exporter.cpp b/src/app/document_exporter.cpp index d1544befb..2c4ee610f 100644 --- a/src/app/document_exporter.cpp +++ b/src/app/document_exporter.cpp @@ -729,7 +729,12 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os, firstLayer = false; else os << ","; - os << "\n { \"name\": \"" << escape_for_json(layer->name()) << "\" }"; + os << "\n { \"name\": \"" << escape_for_json(layer->name()) << "\""; + if (LayerImage* layerImg = dynamic_cast(layer)) { + os << ", \"opacity\": " << layerImg->opacity() + << ", \"blendMode\": \"" << blend_mode_to_string(layerImg->blendMode()) << "\""; + } + os << " }"; } } os << "\n ]"; diff --git a/src/doc/CMakeLists.txt b/src/doc/CMakeLists.txt index 0d3bf8e2c..44e46cb87 100644 --- a/src/doc/CMakeLists.txt +++ b/src/doc/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(doc-lib algorithm/shrink_bounds.cpp anidir.cpp blend_funcs.cpp + blend_mode.cpp brush.cpp cel.cpp cel_data.cpp diff --git a/src/doc/blend_mode.cpp b/src/doc/blend_mode.cpp new file mode 100644 index 000000000..c35f73596 --- /dev/null +++ b/src/doc/blend_mode.cpp @@ -0,0 +1,38 @@ +// Aseprite Document Library +// Copyright (c) 2001-2015 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "doc/blend_mode.h" + +namespace doc { + +std::string blend_mode_to_string(BlendMode blendMode) +{ + switch (blendMode) { + case BlendMode::NORMAL: return "normal"; + case BlendMode::MULTIPLY: return "multiply"; + case BlendMode::SCREEN: return "screen"; + case BlendMode::OVERLAY: return "overlay"; + case BlendMode::DARKEN: return "darken"; + case BlendMode::LIGHTEN: return "lighten"; + case BlendMode::COLOR_DODGE: return "color_dodge"; + case BlendMode::COLOR_BURN: return "color_burn"; + case BlendMode::HARD_LIGHT: return "hard_light"; + case BlendMode::SOFT_LIGHT: return "soft_light"; + case BlendMode::DIFFERENCE: return "difference"; + case BlendMode::EXCLUSION: return "exclusion"; + case BlendMode::HSL_HUE: return "hsl_hue"; + case BlendMode::HSL_SATURATION: return "hsl_saturation"; + case BlendMode::HSL_COLOR: return "hsl_color"; + case BlendMode::HSL_LUMINOSITY: return "hsl_luminosity"; + default: return "unknown"; + } +} + +} // namespace doc diff --git a/src/doc/blend_mode.h b/src/doc/blend_mode.h index 497bb0c58..f26e04c56 100644 --- a/src/doc/blend_mode.h +++ b/src/doc/blend_mode.h @@ -8,6 +8,8 @@ #define DOC_BLEND_MODE_H_INCLUDED #pragma once +#include + namespace doc { enum class BlendMode { @@ -38,6 +40,8 @@ namespace doc { HSL_LUMINOSITY = 15 }; + std::string blend_mode_to_string(BlendMode blendMode); + } // namespace doc #endif