This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/compositor/intern/COM_MetaData.cpp
Jeroen Bakker 87ace46827 Cryptomatte: Manifest Parsing.
This patch adds manifest parsing to Cryptomatte. Normally when loading
cryptomatte layer from an OpenEXR file the manifest contains data to
convert a hash to its original name of the object/material. In the
future we want to use this to support lookup of cryptomatte
hashes and show it to the user.

Currently this logic isn't available to users (for now), but is required
by D3959 where a new cryptomatte workflow is implemented.
2021-02-26 14:13:15 +01:00

72 lines
2.6 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2021, Blender Foundation.
*/
#include "COM_MetaData.h"
#include "BKE_cryptomatte.hh"
#include "BKE_image.h"
#include "RE_pipeline.h"
#include <string_view>
void MetaData::add(const blender::StringRef key, const blender::StringRef value)
{
entries_.add(key, value);
}
void MetaData::addCryptomatteEntry(const blender::StringRef layer_name,
const blender::StringRefNull key,
const blender::StringRef value)
{
add(blender::bke::cryptomatte::BKE_cryptomatte_meta_data_key(layer_name, key), value);
}
/* Replace the hash neutral cryptomatte keys with hashed versions.
*
* When a conversion happens it will also add the cryptomatte name key with the given
* `layer_name`.*/
void MetaData::replaceHashNeutralCryptomatteKeys(const blender::StringRef layer_name)
{
std::string cryptomatte_hash = entries_.pop_default(META_DATA_KEY_CRYPTOMATTE_HASH, "");
std::string cryptomatte_conversion = entries_.pop_default(META_DATA_KEY_CRYPTOMATTE_CONVERSION,
"");
std::string cryptomatte_manifest = entries_.pop_default(META_DATA_KEY_CRYPTOMATTE_MANIFEST, "");
if (cryptomatte_hash.length() || cryptomatte_conversion.length() ||
cryptomatte_manifest.length()) {
addCryptomatteEntry(layer_name, "name", layer_name);
}
if (cryptomatte_hash.length()) {
addCryptomatteEntry(layer_name, "hash", cryptomatte_hash);
}
if (cryptomatte_conversion.length()) {
addCryptomatteEntry(layer_name, "conversion", cryptomatte_conversion);
}
if (cryptomatte_manifest.length()) {
addCryptomatteEntry(layer_name, "manifest", cryptomatte_manifest);
}
}
void MetaData::addToRenderResult(RenderResult *render_result) const
{
for (blender::Map<std::string, std::string>::Item entry : entries_.items()) {
BKE_render_result_stamp_data(render_result, entry.key.c_str(), entry.value.c_str());
}
}