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 * zero_image.h: Image that is zero everywhere.
25 #ifndef __image_zero_h__
26 #define __image_zero_h__
30 #include "exposure/exposure.h"
32 class image_zero
: public image_weighted_avg
{
35 pixel
get_pixel(unsigned int y
, unsigned int x
) const {
39 ale_real
maxval() const {
43 ale_real
minval() const {
48 * Get a color value at a given position using bilinear interpolation between the
49 * four nearest pixels. Result values:
51 * result[0] == pixel value
52 * result[1] == pixel confidence
54 void get_bl(point x
, pixel result
[2]) const {
55 result
[0] = pixel::zero();
56 result
[1] = pixel::zero();
59 pixel
get_bl(point x
) const {
67 pixel
get_scaled_bl(point x
, ale_pos f
) const {
73 * Make a new image suitable for receiving scaled values.
75 virtual image
*scale_generator(int height
, int width
, int depth
, char *name
) const {
77 image
*is
= new image_zero(height
, width
, depth
, name
);
85 * Return an image scaled by some factor >= 1.0
87 image
*scale(ale_pos f
, char *name
) const {
89 image
*is
= new image_zero(
90 (int) floor(height() * f
),
91 (int) floor(width() * f
), depth());
99 * Scale by half. We use the following filter:
105 * At the edges, these values are normalized so that the sum of
106 * contributing pixels is 1.
108 image
*scale_by_half(char *name
) const {
111 image
*result
= new image_zero(
112 (int) floor(height() * f
),
113 (int) floor(width() * f
), depth());
121 * Scale an image definition array by 1/2.
123 * ALE considers an image definition array as a special kind of image
124 * weight array (typedefs of which should appear below the definition
125 * of this class). ALE uses nonzero pixel values to mean 'defined' and
126 * zero values to mean 'undefined'. Through this interpretation, the
127 * image weight array implementation that ALE uses allows image weight
128 * arrays to also serve as image definition arrays.
130 * Whereas scaling of image weight arrays is not generally obvious in
131 * either purpose or method, ALE requires that image definition arrays
132 * be scalable, and the method we implement here is a fairly obvious
133 * one. In particular, if any source pixel contributing to the value of
134 * a scaled target pixel has an undefined value, then the scaled target
135 * pixel is undefined (zero). Otherwise, it is defined (non-zero).
137 * Since there are many possible ways of implementing this function, we
138 * choose an easy way and simply multiply the numerical values of the
139 * source pixels to obtain the value of the scaled target pixel.
141 * XXX: we consider all pixels within a 9-pixel square to contribute.
142 * There are other approaches. For example, edge pixels could be
143 * considered to have six contributing pixels and corner pixels four
144 * contributing pixels. To use this convention, change the ': 0' text
145 * in the code below to ': 1'.
148 image
*defined_scale_by_half(char *name
) const {
151 image
*result
= new image_zero(
152 (int) floor(height() * f
),
153 (int) floor(width() * f
), depth());
161 * Extend the image area to the top, bottom, left, and right,
162 * initializing the new image areas with black pixels.
164 virtual void extend(int top
, int bottom
, int left
, int right
) {
165 _dimy
+= top
+ bottom
;
166 _dimx
+= left
+ right
;
174 image
*clone(char *name
) const {
175 return new image_zero(_dimy
, _dimx
, _depth
, name
);
179 * Calculate the average (mean) clamped magnitude of a channel across
180 * all pixels in an image. The magnitude is clamped to the range of
183 ale_real
avg_channel_clamped_magnitude(unsigned int k
) const {
187 pixel
avg_channel_clamped_magnitude() const {
188 return pixel::zero();
192 * Calculate the average (mean) magnitude of a channel across all
193 * pixels in an image.
195 ale_real
avg_channel_magnitude(unsigned int k
) const {
199 pixel
avg_channel_magnitude() const {
200 return pixel::zero();
204 * Calculate the average (mean) magnitude of a pixel (where magnitude
205 * is defined as the mean of the channel values).
207 ale_real
avg_pixel_magnitude() const {
211 image_zero(unsigned int dimy
, unsigned int dimx
, unsigned int depth
,
212 char *name
= "anonymous") : image_weighted_avg(dimy
, dimx
, depth
, name
) {
215 int accumulate_norender(int i
, int j
) {
219 void accumulate(int i
, int j
, int f
, pixel new_value
, pixel new_weight
) {
223 image
*get_colors() {
227 image
*get_weights() {