Add dynamic filtering.
[Ale.git] / d2 / image_zero.h
blob520746994a9ae72e91f1d05a0017c7966d1bc36a
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__
28 #include "point.h"
29 #include "pixel.h"
30 #include "exposure/exposure.h"
32 class image_zero : public image_weighted_avg {
33 public:
35 pixel get_pixel(unsigned int y, unsigned int x) const {
36 return pixel::zero();
39 ale_real maxval() const {
40 return 0;
43 ale_real minval() const {
44 return 0;
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 {
60 pixel result[2];
62 get_bl(x, result);
64 return result[0];
67 pixel get_scaled_bl(point x, ale_pos f) const {
68 return pixel::zero();
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);
79 assert(is);
81 return is;
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());
93 assert(is);
95 return is;
99 * Scale by half. We use the following filter:
101 * 1/16 1/8 1/16
102 * 1/8 1/4 1/8
103 * 1/16 1/8 1/16
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 {
109 ale_pos f = 0.5;
111 image *result = new image_zero(
112 (int) floor(height() * f),
113 (int) floor(width() * f), depth());
115 assert(result);
117 return result;
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 {
149 ale_pos f = 0.5;
151 image *result = new image_zero(
152 (int) floor(height() * f),
153 (int) floor(width() * f), depth());
155 assert(result);
157 return result;
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;
167 _offset[0] -= top;
168 _offset[1] -= left;
172 * Clone
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
181 * real inputs.
183 ale_real avg_channel_clamped_magnitude(unsigned int k) const {
184 return 0;
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 {
196 return 0;
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 {
208 return 0;
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) {
216 return 1;
219 void accumulate(int i, int j, int f, pixel new_value, pixel new_weight) {
220 assert(0);
223 image *get_colors() {
224 return this;
227 image *get_weights() {
228 return this;
232 #endif