2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class to define a canvas designed to draw style modules
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2008-04-30 15:41:54 +00:00
|
|
|
#include <vector>
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "Canvas.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
#include "StrokeRenderer.h"
|
|
|
|
|
#include "StyleModule.h"
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "../image/GaussianFilter.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "../image/Image.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "../image/ImagePyramid.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
#include "../system/FreestyleConfig.h"
|
|
|
|
|
#include "../system/PseudoNoise.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "../system/TimeStamp.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "../view_map/SteerableViewMap.h"
|
|
|
|
|
|
2022-10-26 18:58:04 +02:00
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2013-01-03 23:27:20 +00:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// soc #include <qimage.h>
|
|
|
|
|
// soc #include <QString>
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf.hh"
|
|
|
|
|
#include "IMB_imbuf_types.hh"
|
2008-05-09 23:06:28 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
Canvas *Canvas::_pInstance = nullptr;
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
const char *Canvas::_MapsPath = nullptr;
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
Canvas::Canvas()
|
|
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
_SelectedFEdge = nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
_pInstance = this;
|
|
|
|
|
PseudoNoise::init(42);
|
2020-11-06 17:49:09 +01:00
|
|
|
_Renderer = nullptr;
|
|
|
|
|
_current_sm = nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
_steerableViewMap = new SteerableViewMap(NB_STEERABLE_VIEWMAP - 1);
|
|
|
|
|
_basic = false;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Canvas::Canvas(const Canvas &iBrother)
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
_SelectedFEdge = iBrother._SelectedFEdge;
|
|
|
|
|
_pInstance = this;
|
|
|
|
|
PseudoNoise::init(42);
|
|
|
|
|
_Renderer = iBrother._Renderer;
|
|
|
|
|
_current_sm = iBrother._current_sm;
|
|
|
|
|
_steerableViewMap = new SteerableViewMap(*(iBrother._steerableViewMap));
|
|
|
|
|
_basic = iBrother._basic;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Canvas::~Canvas()
|
|
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
_pInstance = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Clear();
|
|
|
|
|
if (_Renderer) {
|
|
|
|
|
delete _Renderer;
|
2020-11-06 17:49:09 +01:00
|
|
|
_Renderer = nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
// FIXME: think about an easy control for the maps memory management...
|
|
|
|
|
if (!_maps.empty()) {
|
|
|
|
|
for (mapsMap::iterator m = _maps.begin(), mend = _maps.end(); m != mend; ++m) {
|
|
|
|
|
delete ((*m).second);
|
|
|
|
|
}
|
|
|
|
|
_maps.clear();
|
|
|
|
|
}
|
2020-07-03 16:32:12 +02:00
|
|
|
delete _steerableViewMap;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
void Canvas::preDraw() {}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
void Canvas::Draw()
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_StyleModules.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
preDraw();
|
|
|
|
|
TimeStamp *timestamp = TimeStamp::instance();
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < _StyleModules.size(); ++i) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_sm = _StyleModules[i];
|
2008-09-25 18:02:15 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (i < _Layers.size() && _Layers[i]) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete _Layers[i];
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_Layers[i] = _StyleModules[i]->execute();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_Layers[i]) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
stroke_count += _Layers[i]->strokes_size();
|
2008-12-10 22:06:27 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
timestamp->increment();
|
|
|
|
|
}
|
|
|
|
|
postDraw();
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Canvas::postDraw()
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
update();
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Canvas::Clear()
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_Layers.empty()) {
|
|
|
|
|
for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
|
2024-01-02 18:12:54 +01:00
|
|
|
++sl)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*sl) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete (*sl);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
_Layers.clear();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_StyleModules.empty()) {
|
|
|
|
|
for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
|
|
|
|
|
s != send;
|
|
|
|
|
++s)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*s) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete (*s);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
_StyleModules.clear();
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_steerableViewMap) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_steerableViewMap->Reset();
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-10 22:06:27 +00:00
|
|
|
stroke_count = 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Canvas::Erase()
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_Layers.empty()) {
|
|
|
|
|
for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
|
2024-01-02 18:12:54 +01:00
|
|
|
++sl)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*sl) {
|
2012-12-28 20:21:05 +00:00
|
|
|
(*sl)->clear();
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_steerableViewMap) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_steerableViewMap->Reset();
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
update();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
stroke_count = 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void Canvas::PushBackStyleModule(StyleModule *iStyleModule)
|
|
|
|
|
{
|
2013-03-11 06:56:51 +00:00
|
|
|
StrokeLayer *layer = new StrokeLayer();
|
2012-12-28 20:21:05 +00:00
|
|
|
_StyleModules.push_back(iStyleModule);
|
|
|
|
|
_Layers.push_back(layer);
|
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
- in any render layer
- with as many style modules per layer
DETAILS:
Freestyle usage has not changed:
- all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
- each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
- it is fully compatible with compositor nodes
In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).
Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)
The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.
The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.
The current pipeline works as follows:
----------------------------------------------------------------------------------------------
for every scene that is being rendered
if Freestyle is enabled globally
Freestyle is initialized
camera and view settings are transferred from Blender to Freestyle
for every render layer
if: - layer is enabled
- layer enabled Freestyle
- the number of displayed style modules is non-zero
canvas is cleared
geometry is transferred from Blender to Freestyle
settings are fixed for current iteration
view map is calculated
strokes are computed in the canvas (based on view map and style modules)
strokes are rendered in separate Blender scene
scene is composited in current layer
----------------------------------------------------------------------------------------------
A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended
LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers
This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.
2009-04-07 18:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::InsertStyleModule(uint index, StyleModule *iStyleModule)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
2022-09-26 10:04:44 +10:00
|
|
|
uint size = _StyleModules.size();
|
2012-12-28 20:21:05 +00:00
|
|
|
StrokeLayer *layer = new StrokeLayer();
|
2022-10-07 22:52:53 +11:00
|
|
|
if (_StyleModules.empty() || (index == size)) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_StyleModules.push_back(iStyleModule);
|
|
|
|
|
_Layers.push_back(layer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
_StyleModules.insert(_StyleModules.begin() + index, iStyleModule);
|
2012-12-28 20:21:05 +00:00
|
|
|
_Layers.insert(_Layers.begin() + index, layer);
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::RemoveStyleModule(uint index)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
uint i = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_StyleModules.empty()) {
|
|
|
|
|
for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
|
|
|
|
|
s != send;
|
|
|
|
|
++s, ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == index) {
|
|
|
|
|
// remove shader
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*s) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete *s;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_StyleModules.erase(s);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_Layers.empty()) {
|
|
|
|
|
i = 0;
|
|
|
|
|
for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
|
|
|
|
|
++sl, ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == index) {
|
|
|
|
|
// remove layer
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*sl) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete *sl;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_Layers.erase(sl);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::SwapStyleModules(uint i1, uint i2)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
StyleModule *tmp;
|
|
|
|
|
tmp = _StyleModules[i1];
|
|
|
|
|
_StyleModules[i1] = _StyleModules[i2];
|
|
|
|
|
_StyleModules[i2] = tmp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
StrokeLayer *tmp2;
|
|
|
|
|
tmp2 = _Layers[i1];
|
|
|
|
|
_Layers[i1] = _Layers[i2];
|
|
|
|
|
_Layers[i2] = tmp2;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::ReplaceStyleModule(uint index, StyleModule *iStyleModule)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2022-09-26 10:04:44 +10:00
|
|
|
uint i = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
|
|
|
|
|
s != send;
|
|
|
|
|
++s, ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == index) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (*s) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete *s;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
*s = iStyleModule;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::setVisible(uint index, bool iVisible)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
|
|
|
|
_StyleModules[index]->setDisplayed(iVisible);
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::setModified(uint index, bool iMod)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
_StyleModules[index]->setModified(iMod);
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void Canvas::resetModified(bool iMod /* = false */)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
uint size = _StyleModules.size();
|
|
|
|
|
for (uint i = 0; i < size; ++i) {
|
2012-12-28 20:21:05 +00:00
|
|
|
setModified(i, iMod);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
void Canvas::causalStyleModules(vector<uint> &vec, uint index)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
uint size = _StyleModules.size();
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = index; i < size; ++i) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_StyleModules[i]->getCausal()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
vec.push_back(i);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Canvas::Render(const StrokeRenderer *iRenderer)
|
|
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < _StyleModules.size(); ++i) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_Layers[i]->Render(iRenderer);
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Canvas::RenderBasic(const StrokeRenderer *iRenderer)
|
|
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < _StyleModules.size(); ++i) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_Layers[i]->RenderBasic(iRenderer);
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
void Canvas::loadMap(const char *iFileName, const char *iMapName, uint iNbLevels, float iSigma)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
|
|
|
|
// check whether this map was already loaded:
|
|
|
|
|
if (!_maps.empty()) {
|
|
|
|
|
mapsMap::iterator m = _maps.find(iMapName);
|
|
|
|
|
if (m != _maps.end()) {
|
|
|
|
|
// lazy check for size changes
|
2013-03-11 06:56:51 +00:00
|
|
|
ImagePyramid *pyramid = (*m).second;
|
2012-12-28 20:21:05 +00:00
|
|
|
if ((pyramid->width() != width()) || (pyramid->height() != height())) {
|
|
|
|
|
delete pyramid;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
string filePath;
|
|
|
|
|
if (_MapsPath) {
|
|
|
|
|
filePath = _MapsPath;
|
|
|
|
|
filePath += iFileName;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
filePath = iFileName;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
#if 0 // soc
|
2012-12-28 20:21:05 +00:00
|
|
|
QImage *qimg;
|
|
|
|
|
QImage newMap(filePath.c_str());
|
|
|
|
|
if (newMap.isNull()) {
|
2013-01-03 23:27:20 +00:00
|
|
|
cerr << "Could not load image file " << filePath << endl;
|
2012-12-28 20:21:05 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
qimg = &newMap;
|
|
|
|
|
#endif
|
2012-09-23 18:50:56 +00:00
|
|
|
/* OCIO_TODO: support different input color space */
|
2020-11-06 17:49:09 +01:00
|
|
|
ImBuf *qimg = IMB_loadiffname(filePath.c_str(), 0, nullptr);
|
|
|
|
|
if (qimg == nullptr) {
|
2013-01-03 23:27:20 +00:00
|
|
|
cerr << "Could not load image file " << filePath << endl;
|
2012-12-28 20:21:05 +00:00
|
|
|
return;
|
2008-05-09 23:06:28 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
#if 0 // soc
|
|
|
|
|
// resize
|
|
|
|
|
QImage scaledImg;
|
|
|
|
|
if ((newMap.width() != width()) || (newMap.height() != height())) {
|
|
|
|
|
scaledImg = newMap.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
|
qimg = &scaledImg;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2008-05-09 23:06:28 +00:00
|
|
|
ImBuf *scaledImg;
|
2012-12-28 20:21:05 +00:00
|
|
|
if ((qimg->x != width()) || (qimg->y != height())) {
|
|
|
|
|
scaledImg = IMB_dupImBuf(qimg);
|
2024-08-19 16:50:05 +02:00
|
|
|
IMB_scale(scaledImg, width(), height(), IMBScaleFilter::Box, false);
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deal with color image
|
|
|
|
|
#if 0
|
|
|
|
|
if (newMap->depth() != 8) {
|
|
|
|
|
int w = newMap->width();
|
|
|
|
|
int h = newMap->height();
|
|
|
|
|
QImage *tmp = new QImage(w, h, 8);
|
2023-07-25 12:51:50 +10:00
|
|
|
for (uint y = 0; y < h; ++y) {
|
|
|
|
|
for (uint x = 0; x < w; ++x) {
|
2012-12-28 20:21:05 +00:00
|
|
|
int c = qGray(newMap->pixel(x, y));
|
|
|
|
|
tmp->setPixel(x, y, c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete newMap;
|
|
|
|
|
newMap = tmp;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
|
int w = qimg->x;
|
|
|
|
|
int h = qimg->y;
|
|
|
|
|
int rowbytes = w * 4;
|
|
|
|
|
GrayImage tmp(w, h);
|
2023-05-18 10:19:01 +02:00
|
|
|
uchar *pix;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (y = 0; y < h; ++y) {
|
|
|
|
|
for (x = 0; x < w; ++x) {
|
2023-05-18 10:19:01 +02:00
|
|
|
pix = qimg->byte_buffer.data + y * rowbytes + x * 4;
|
2012-12-28 20:21:05 +00:00
|
|
|
float c = (pix[0] * 11 + pix[1] * 16 + pix[2] * 5) / 32;
|
|
|
|
|
tmp.setPixel(x, y, c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
GrayImage blur(w, h);
|
|
|
|
|
GaussianFilter gf(4.0f);
|
2023-08-09 10:47:43 +10:00
|
|
|
// int bound = gf.getBound();
|
2012-12-28 20:21:05 +00:00
|
|
|
for (y = 0; y < h; ++y) {
|
|
|
|
|
for (x = 0; x < w; ++x) {
|
|
|
|
|
int c = gf.getSmoothedPixel<GrayImage>(&tmp, x, y);
|
|
|
|
|
blur.setPixel(x, y, c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
GaussianPyramid *pyramid = new GaussianPyramid(tmp, iNbLevels, iSigma);
|
|
|
|
|
int ow = pyramid->width(0);
|
|
|
|
|
int oh = pyramid->height(0);
|
2019-04-30 17:50:57 +10:00
|
|
|
string base(iMapName); // soc
|
2012-12-28 20:21:05 +00:00
|
|
|
for (int i = 0; i < pyramid->getNumberOfLevels(); ++i) {
|
|
|
|
|
// save each image:
|
|
|
|
|
#if 0
|
|
|
|
|
w = pyramid.width(i);
|
|
|
|
|
h = pyramid.height(i);
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// soc QImage qtmp(ow, oh, QImage::Format_RGB32);
|
2012-12-28 20:21:05 +00:00
|
|
|
ImBuf *qtmp = IMB_allocImBuf(ow, oh, 32, IB_rect);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// int k = (1 << i);
|
2012-12-28 20:21:05 +00:00
|
|
|
for (y = 0; y < oh; ++y) {
|
|
|
|
|
for (x = 0; x < ow; ++x) {
|
|
|
|
|
int c = pyramid->pixel(x, y, i); // 255 * pyramid->pixel(x, y, i);
|
2019-04-30 17:50:57 +10:00
|
|
|
// soc qtmp.setPixel(x, y, qRgb(c, c, c));
|
2023-05-18 10:19:01 +02:00
|
|
|
pix = qtmp->byte_buffer.data + y * rowbytes + x * 4;
|
2013-03-11 06:56:51 +00:00
|
|
|
pix[0] = pix[1] = pix[2] = c;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-30 17:50:57 +10:00
|
|
|
// soc qtmp.save(base + QString::number(i) + ".bmp", "BMP");
|
2023-05-03 14:13:27 +10:00
|
|
|
stringstream filepath;
|
|
|
|
|
filepath << base;
|
|
|
|
|
filepath << i << ".bmp";
|
2015-07-13 13:58:17 +02:00
|
|
|
qtmp->ftype = IMB_FTYPE_BMP;
|
2023-05-03 14:13:27 +10:00
|
|
|
IMB_saveiff(qtmp, const_cast<char *>(filepath.str().c_str()), 0);
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
QImage *qtmp = new QImage(w, h, 32);
|
|
|
|
|
for (y = 0; y < h; ++y) {
|
|
|
|
|
for (x = 0; x < w; ++x) {
|
2023-07-25 12:51:50 +10:00
|
|
|
int c = int(blur.pixel(x, y));
|
2012-12-28 20:21:05 +00:00
|
|
|
qtmp->setPixel(x, y, qRgb(c, c, c));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete newMap;
|
|
|
|
|
newMap = qtmp;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
_maps[iMapName] = pyramid;
|
2019-04-30 17:50:57 +10:00
|
|
|
// newMap->save("toto.bmp", "BMP");
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
float Canvas::readMapPixel(const char *iMapName, int level, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (_maps.empty()) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "readMapPixel warning: no map was loaded " << endl;
|
|
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
mapsMap::iterator m = _maps.find(iMapName);
|
|
|
|
|
if (m == _maps.end()) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "readMapPixel warning: no map was loaded with the name " << iMapName << endl;
|
|
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
ImagePyramid *pyramid = (*m).second;
|
2019-05-31 22:51:19 +10:00
|
|
|
if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
return pyramid->pixel(x, height() - 1 - y, level);
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|