Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_WrapOperation.cc « operations « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 336e1b72520e18fa280787b8fe0134c21bad1f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * 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 2011, Blender Foundation.
 */

#include <cmath>

#include "COM_WrapOperation.h"

namespace blender::compositor {

WrapOperation::WrapOperation(DataType datatype) : ReadBufferOperation(datatype)
{
  wrapping_type_ = CMP_NODE_WRAP_NONE;
}

inline float WrapOperation::get_wrapped_original_xpos(float x)
{
  if (this->get_width() == 0) {
    return 0;
  }
  while (x < 0) {
    x += this->get_width();
  }
  return fmodf(x, this->get_width());
}

inline float WrapOperation::get_wrapped_original_ypos(float y)
{
  if (this->get_height() == 0) {
    return 0;
  }
  while (y < 0) {
    y += this->get_height();
  }
  return fmodf(y, this->get_height());
}

void WrapOperation::execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler)
{
  float nx, ny;
  nx = x;
  ny = y;
  MemoryBufferExtend extend_x = MemoryBufferExtend::Clip, extend_y = MemoryBufferExtend::Clip;
  switch (wrapping_type_) {
    case CMP_NODE_WRAP_NONE:
      /* Intentionally empty, original_xpos and original_ypos have been set before. */
      break;
    case CMP_NODE_WRAP_X:
      /* Wrap only on the x-axis. */
      nx = this->get_wrapped_original_xpos(x);
      extend_x = MemoryBufferExtend::Repeat;
      break;
    case CMP_NODE_WRAP_Y:
      /* Wrap only on the y-axis. */
      ny = this->get_wrapped_original_ypos(y);
      extend_y = MemoryBufferExtend::Repeat;
      break;
    case CMP_NODE_WRAP_XY:
      /* Wrap on both. */
      nx = this->get_wrapped_original_xpos(x);
      ny = this->get_wrapped_original_ypos(y);
      extend_x = MemoryBufferExtend::Repeat;
      extend_y = MemoryBufferExtend::Repeat;
      break;
  }

  execute_pixel_extend(output, nx, ny, sampler, extend_x, extend_y);
}

bool WrapOperation::determine_depending_area_of_interest(rcti *input,
                                                         ReadBufferOperation *read_operation,
                                                         rcti *output)
{
  rcti new_input;
  new_input.xmin = input->xmin;
  new_input.xmax = input->xmax;
  new_input.ymin = input->ymin;
  new_input.ymax = input->ymax;

  if (ELEM(wrapping_type_, CMP_NODE_WRAP_X, CMP_NODE_WRAP_XY)) {
    /* Wrap only on the x-axis if tile is wrapping. */
    new_input.xmin = get_wrapped_original_xpos(input->xmin);
    new_input.xmax = roundf(get_wrapped_original_xpos(input->xmax));
    if (new_input.xmin >= new_input.xmax) {
      new_input.xmin = 0;
      new_input.xmax = this->get_width();
    }
  }
  if (ELEM(wrapping_type_, CMP_NODE_WRAP_Y, CMP_NODE_WRAP_XY)) {
    /* Wrap only on the y-axis if tile is wrapping. */
    new_input.ymin = get_wrapped_original_ypos(input->ymin);
    new_input.ymax = roundf(get_wrapped_original_ypos(input->ymax));
    if (new_input.ymin >= new_input.ymax) {
      new_input.ymin = 0;
      new_input.ymax = this->get_height();
    }
  }

  return ReadBufferOperation::determine_depending_area_of_interest(
      &new_input, read_operation, output);
}

void WrapOperation::set_wrapping(int wrapping_type)
{
  wrapping_type_ = wrapping_type;
}

}  // namespace blender::compositor