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 2 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[](int i
) const {
61 ale_real
&operator[](int i
) {
68 pixel
operator+(pixel p
) const {
69 return pixel(p
[0] + x
[0], p
[1] + x
[1], p
[2] + x
[2]);
72 pixel
operator-(pixel p
) const {
73 return pixel(x
[0] - p
[0], x
[1] - p
[1], x
[2] - p
[2]);
76 pixel
operator-() const {
77 return pixel(-x
[0], -x
[1], -x
[2]);
80 pixel
operator/(pixel p
) const {
81 return pixel(x
[0] / p
[0], x
[1] / p
[1], x
[2] / p
[2]);
84 pixel
operator/(ale_real d
) const {
85 return pixel(x
[0] / d
, x
[1] / d
, x
[2] / d
);
88 pixel
operator*(pixel p
) const {
89 return pixel(x
[0] * p
[0], x
[1] * p
[1], x
[2] * p
[2]);
92 pixel
mult(ale_real d
) const {
93 return pixel(x
[0] * d
, x
[1] * d
, x
[2] * d
);
96 pixel
operator+=(pixel p
) {
97 return pixel(x
[0] += p
[0], x
[1] += p
[1], x
[2] += p
[2]);
100 pixel
operator*=(pixel p
) {
101 return pixel(x
[0] *= p
[0], x
[1] *= p
[1], x
[2] *= p
[2]);
104 pixel
operator*=(ale_real d
) {
105 return pixel(x
[0] *= d
, x
[1] *= d
, x
[2] *= d
);
108 pixel
operator/=(pixel p
) {
109 return pixel(x
[0] /= p
[0], x
[1] /= p
[1], x
[2] /= p
[2]);
112 pixel
operator/=(ale_real d
) {
113 return pixel(x
[0] /= d
, x
[1] /= d
, x
[2] /= d
);
116 pixel
clamp() const {
119 for (int i
= 0; i
< 3; i
++)
132 return pixel(fabs(x
[0]), fabs(x
[1]), fabs(x
[2]));
136 return x
[0] * x
[0] + x
[1] * x
[1] + x
[2] * x
[2];
140 return sqrt(normsq());
144 return x
[0] + x
[1] + x
[2];
147 ale_real
maxabs_norm() {
148 ale_real m
= fabs(x
[0]);
157 ale_real
minabs_norm() {
158 ale_real m
= fabs(x
[0]);
167 ale_real
min_norm() {
177 ale_real
max_norm() {
187 static pixel
zero() {
188 return pixel(0, 0, 0);
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
) {