bugs: suggest image_rw return either d2::image or ale_image, according to request.
[Ale.git] / d2 / spixel.h
blob3119fa3f1670d8dd1394252662f76bd57112a897
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 __spixel_h__
22 #define __spixel_h__
25 * Structure to describe a pixel to be used in storage.
28 class spixel {
29 private:
30 ale_sreal x[3];
32 public:
33 spixel() {
34 x[0] = 0;
35 x[1] = 0;
36 x[2] = 0;
39 spixel(pixel p) {
40 x[0] = p[0];
41 x[1] = p[1];
42 x[2] = p[2];
45 spixel(ale_sreal x0, ale_sreal x1, ale_sreal x2) {
46 x[0] = x0;
47 x[1] = x1;
48 x[2] = x2;
51 operator pixel() const {
52 pixel result;
54 result[0] = x[0];
55 result[1] = x[1];
56 result[2] = x[2];
58 return result;
61 const ale_sreal &operator[](unsigned int i) const {
62 #if 0
64 * This may be expensive.
66 assert (i < 3);
67 #endif
69 return x[i];
72 ale_sreal &operator[](unsigned int i) {
73 #if 0
75 * This may be expensive.
77 assert (i < 3);
78 #endif
80 return x[i];
83 ale_sreal min_norm() const {
84 ale_sreal m = x[0];
85 if (x[1] < m)
86 m = x[1];
87 if (x[2] < m)
88 m = x[2];
90 return m;
93 spixel operator+=(pixel p) {
94 return spixel(x[0] += p[0], x[1] += p[1], x[2] += p[2]);
97 spixel operator*=(pixel p) {
98 return spixel(x[0] *= p[0], x[1] *= p[1], x[2] *= p[2]);
101 spixel operator*=(ale_real d) {
102 return spixel(x[0] *= d, x[1] *= d, x[2] *= d);
105 spixel operator/=(pixel p) {
106 return spixel(x[0] /= p[0], x[1] /= p[1], x[2] /= p[2]);
109 spixel operator/=(ale_real d) {
110 return spixel(x[0] /= d, x[1] /= d, x[2] /= d);
114 #endif