1 // Copyright 2002 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
25 * Structure to describe a pixel
39 pixel(ale_real x0
, ale_real x1
, ale_real x2
) {
45 // Due to automatic typecasts and automatic int <==> ale_real *
46 // conversions, this can cause some really weird bugs.
48 // pixel(ale_real *_x) {
54 const ale_real
&operator[](unsigned int i
) const {
59 ale_real
&operator[](unsigned int i
) {
64 pixel
operator+(pixel p
) const {
65 return pixel(p
[0] + x
[0], p
[1] + x
[1], p
[2] + x
[2]);
68 pixel
operator-(pixel p
) const {
69 return pixel(x
[0] - p
[0], x
[1] - p
[1], x
[2] - p
[2]);
72 pixel
operator-() const {
73 return pixel(-x
[0], -x
[1], -x
[2]);
76 pixel
operator/(pixel p
) const {
77 return pixel(x
[0] / p
[0], x
[1] / p
[1], x
[2] / p
[2]);
80 pixel
operator/(ale_real d
) const {
81 return pixel(x
[0] / d
, x
[1] / d
, x
[2] / d
);
84 pixel
operator*(pixel p
) const {
85 return pixel(x
[0] * p
[0], x
[1] * p
[1], x
[2] * p
[2]);
88 pixel
mult(ale_real d
) const {
89 return pixel(x
[0] * d
, x
[1] * d
, x
[2] * d
);
92 pixel
operator+=(pixel p
) {
93 return pixel(x
[0] += p
[0], x
[1] += p
[1], x
[2] += p
[2]);
96 pixel
operator*=(pixel p
) {
97 return pixel(x
[0] *= p
[0], x
[1] *= p
[1], x
[2] *= p
[2]);
100 pixel
operator*=(ale_real d
) {
101 return pixel(x
[0] *= d
, x
[1] *= d
, x
[2] *= d
);
104 pixel
operator/=(pixel p
) {
105 return pixel(x
[0] /= p
[0], x
[1] /= p
[1], x
[2] /= p
[2]);
108 pixel
operator/=(ale_real d
) {
109 return pixel(x
[0] /= d
, x
[1] /= d
, x
[2] /= d
);
112 pixel
clamp() const {
115 for (int i
= 0; i
< 3; i
++)
128 return pixel(fabs(x
[0]), fabs(x
[1]), fabs(x
[2]));
132 return x
[0] * x
[0] + x
[1] * x
[1] + x
[2] * x
[2];
136 return sqrt(normsq());
140 return x
[0] + x
[1] + x
[2];
143 ale_real
maxabs_norm() {
144 ale_real m
= fabs(x
[0]);
153 ale_real
minabs_norm() {
154 ale_real m
= fabs(x
[0]);
163 ale_real
min_norm() {
173 ale_real
max_norm() {
183 static pixel
zero() {
184 return pixel(0, 0, 0);
188 return pixel(1, 1, 1);
191 int operator==(const pixel
&p
) {
197 int operator!=(const pixel
&p
) {
198 return !operator==(p
);
202 return ::finite(x
[0]) && ::finite(x
[1]) && ::finite(x
[2]);
205 static pixel
undefined() {
207 return pixel(zero
/ zero
, zero
/ zero
, zero
/ zero
);
212 inline pixel
operator*(const pixel
&p
, float d
) {
215 inline pixel
operator*(const pixel
&p
, double d
) {
218 inline pixel
operator*(double d
, const pixel
&p
) {
221 inline pixel
operator*(float d
, const pixel
&p
) {
225 inline std::ostream
&operator<<(std::ostream
&o
, const pixel
&p
) {
226 o
<< "[" << p
[0] << " " << p
[1] << " " << p
[2] << "]";
230 inline pixel
ppow(pixel p
, double d
) {
232 pow((double) p
[0], d
),
233 pow((double) p
[1], d
),
234 pow((double) p
[2], d
));
237 inline pixel
ppow(pixel p
, float d
) {
239 pow((double) p
[0], d
),
240 pow((double) p
[1], d
),
241 pow((double) p
[2], d
));
244 inline pixel
pexp(pixel p
) {