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
21 #ifndef __pixel_accum_h__
22 #define __pixel_accum_h__
27 * Structure to accumulate values over many pixels.
41 pixel_accum(ale_accum x0
, ale_accum x1
, ale_accum x2
) {
47 pixel_accum(pixel p
) {
63 // Due to automatic typecasts and automatic int <==> ale_accum *
64 // conversions, this can cause some really weird bugs.
66 // pixel_accum(ale_accum *_x) {
72 const ale_accum
&operator[](int i
) const {
79 ale_accum
&operator[](int i
) {
86 pixel_accum
operator+(pixel_accum p
) const {
87 return pixel_accum(p
[0] + x
[0], p
[1] + x
[1], p
[2] + x
[2]);
90 pixel_accum
operator-(pixel_accum p
) const {
91 return pixel_accum(x
[0] - p
[0], x
[1] - p
[1], x
[2] - p
[2]);
94 pixel_accum
operator/(pixel_accum p
) const {
95 return pixel_accum(x
[0] / p
[0], x
[1] / p
[1], x
[2] / p
[2]);
98 pixel_accum
operator/(ale_accum d
) const {
99 return pixel_accum(x
[0] / d
, x
[1] / d
, x
[2] / d
);
102 pixel_accum
operator*(pixel_accum p
) const {
103 return pixel_accum(x
[0] * p
[0], x
[1] * p
[1], x
[2] * p
[2]);
106 pixel_accum
operator*(ale_accum d
) const {
107 return pixel_accum(x
[0] * d
, x
[1] * d
, x
[2] * d
);
110 pixel_accum
operator+=(pixel_accum p
) {
111 return pixel_accum(x
[0] += p
[0], x
[1] += p
[1], x
[2] += p
[2]);
114 pixel_accum
operator*=(pixel_accum p
) {
115 return pixel_accum(x
[0] *= p
[0], x
[1] *= p
[1], x
[2] *= p
[2]);
118 pixel_accum
operator*=(ale_accum d
) {
119 return pixel_accum(x
[0] *= d
, x
[1] *= d
, x
[2] *= d
);
122 pixel_accum
operator/=(pixel_accum p
) {
123 return pixel_accum(x
[0] /= p
[0], x
[1] /= p
[1], x
[2] /= p
[2]);
126 pixel_accum
operator/=(ale_accum d
) {
127 return pixel_accum(x
[0] /= d
, x
[1] /= d
, x
[2] /= d
);
131 inline pixel_accum
operator*(float d
, const pixel_accum
&p
) {
135 inline pixel_accum
operator*(double d
, const pixel_accum
&p
) {
139 inline std::ostream
&operator<<(std::ostream
&o
, const pixel_accum
&p
) {
140 o
<< "[" << (double) p
[0] << " " << (double) p
[1] << " " << (double) p
[2] << "]";
144 inline pixel_accum
ppow(pixel_accum p
, float d
) {
146 pow((ale_accum
) p
[0], d
),
147 pow((ale_accum
) p
[1], d
),
148 pow((ale_accum
) p
[2], d
));
151 inline pixel_accum
ppow(pixel_accum p
, double d
) {
153 pow((ale_accum
) p
[0], d
),
154 pow((ale_accum
) p
[1], d
),
155 pow((ale_accum
) p
[2], d
));