1 // Copyright 2002, 2003, 2004 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@ugcs.caltech.edu>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * image_weighted_simple.h: Image representing a weighted average of inputs.
23 * Covers simple cases that require space constant with frame count.
26 #ifndef __image_weighted_simple_h__
27 #define __image_weighted_simple_h__
29 #include "image_weighted_avg.h"
30 #include "render/invariant.h"
32 class image_weighted_simple
: public image_weighted_avg
{
35 image_ale_real
*colors
;
36 image_ale_real
*weights
;
39 image_weighted_simple (unsigned int dimy
, unsigned int dimx
, unsigned int
40 depth
, invariant
*inv
, char *name
= "anonymous")
41 : image_weighted_avg(dimy
, dimx
, depth
, name
) {
42 colors
= new image_ale_real(dimy
, dimx
, depth
);
43 weights
= new image_ale_real(dimy
, dimx
, depth
);
47 virtual ~image_weighted_simple() {
53 * Extend the image area to the top, bottom, left, and right,
54 * initializing the new image areas with black pixels. Negative values
57 void extend(int top
, int bottom
, int left
, int right
) {
58 colors
->extend(top
, bottom
, left
, right
);
59 weights
->extend(top
, bottom
, left
, right
);
61 _dimx
= colors
->width();
62 _dimy
= colors
->height();
63 _offset
= colors
->offset();
67 * Pre-transformation check for whether an area should be skipped.
68 * Takes image weights as an argument.
70 int accumulate_norender(int i
, int j
) {
74 if (inv
->is_first() && weights
->get_pixel(i
, j
)[0] != 0)
77 * Weight limit satisfied
80 && weights
->get_pixel(i
, j
)[0] > inv
->get_param()
81 && weights
->get_pixel(i
, j
)[1] > inv
->get_param()
82 && weights
->get_pixel(i
, j
)[2] > inv
->get_param())
91 void accumulate(int i
, int j
, int f
, pixel new_value
, pixel new_weight
) {
94 * Perform operations separately for each channel
96 for (unsigned int k
= 0; k
< 3; k
++) {
99 * Cases independent of the old pixel value and weight
100 * for which the update can be ignored.
104 && new_weight
[k
] < render::get_wt())
108 * Cases independent of the old pixel value and weight for which
109 * previous pixel values can be ignored.
112 if (inv
->is_last() && new_weight
[k
] >= render::get_wt()) {
113 colors
->chan(i
, j
, k
) = new_value
[k
] * new_weight
[k
];
114 weights
->chan(i
, j
, k
) = new_weight
[k
];
119 * Obtain the old pixel weight.
122 ale_real old_weight
= weights
->chan(i
, j
, k
);
125 * Cases independent of the old pixel value for which the
126 * update can be ignored.
129 if (old_weight
>= render::get_wt()
134 && old_weight
>= inv
->get_param())
138 * Cases independent of the old pixel value for which previous
139 * pixel values can be ignored.
143 || (old_weight
< render::get_wt()
144 && !inv
->is_avgx())) {
145 weights
->chan(i
, j
, k
) = new_weight
[k
];
146 colors
->chan(i
, j
, k
) = new_value
[k
] * new_weight
[k
];
151 * Obtain the old pixel value
154 ale_real old_value
= colors
->chan(i
, j
, k
) / weights
->chan(i
, j
, k
);
157 * Cases in which the old pixel value can be ignored
161 && new_value
[k
] > old_value
)
163 && new_value
[k
] < old_value
)) {
164 weights
->chan(i
, j
, k
) = new_weight
[k
];
165 colors
-> chan(i
, j
, k
) = new_value
[k
] * new_weight
[k
];
170 * Cases in which the new pixel value can be ignored
174 && old_value
> new_value
[k
])
176 && old_value
< new_value
[k
])) {
181 * Update weight and color values.
184 weights
->chan(i
, j
, k
) += new_weight
[k
];
185 colors
->chan(i
, j
, k
) += new_weight
[k
] * new_value
[k
];
190 pixel
get_pixel(unsigned int y
, unsigned int x
) const {
191 return colors
->get_pixel(y
, x
) / weights
->get_pixel(y
, x
);
194 image
*get_weights() {
198 image
*get_colors() {