doc/web: Place examples section more visibly.
[Ale.git] / d2 / pixel_accum.h
blobed7f9d36913f6e6164fb894316c3c237603ae36f
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__
24 #include "pixel.h"
27 * Structure to accumulate values over many pixels.
30 class pixel_accum {
31 private:
32 ale_accum x[3];
34 public:
35 pixel_accum() {
36 x[0] = 0;
37 x[1] = 0;
38 x[2] = 0;
41 pixel_accum(ale_accum x0, ale_accum x1, ale_accum x2) {
42 x[0] = x0;
43 x[1] = x1;
44 x[2] = x2;
47 pixel_accum(pixel p) {
48 x[0] = p[0];
49 x[1] = p[1];
50 x[2] = p[2];
53 operator pixel() {
54 pixel result;
56 result[0] = x[0];
57 result[1] = x[1];
58 result[2] = x[2];
60 return result;
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) {
67 // x[0] = _x[0];
68 // x[1] = _x[1];
69 // x[2] = _x[2];
70 // }
72 const ale_accum &operator[](int i) const {
73 assert (i >= 0);
74 assert (i < 3);
76 return x[i];
79 ale_accum &operator[](int i) {
80 assert (i >= 0);
81 assert (i < 3);
83 return x[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) {
132 return p * d;
135 inline pixel_accum operator*(double d, const pixel_accum &p) {
136 return p * d;
139 inline std::ostream &operator<<(std::ostream &o, const pixel_accum &p) {
140 o << "[" << (double) p[0] << " " << (double) p[1] << " " << (double) p[2] << "]";
141 return o;
144 inline pixel_accum ppow(pixel_accum p, float d) {
145 return pixel_accum(
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) {
152 return pixel_accum(
153 pow((ale_accum) p[0], d),
154 pow((ale_accum) p[1], d),
155 pow((ale_accum) p[2], d));
158 #endif