Readapt the comments for Image
[cassata.biscotto.git] / src / Image.h
blob60b6e480f20fe83365968ef159a8260751458710
1 /* Copyright ® 2008 Fulvio Satta
3 * If you want contact me, send an email to Yota_VGA@users.sf.net
5 * This file is part of Biscotto
7 * Biscotto is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Biscotto is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef IMAGE_H
23 #define IMAGE_H
24 #include <memory> //For auto_ptr
25 #include <boost/smart_ptr.hpp> //For scoped_array
26 #include <string>
27 #include <ImfOutputFile.h>
29 /* Read and write in an image */
30 //TODO: Image reading
31 class Image
33 public:
34 /* A pixel */
35 struct RGBA
37 float r, g, b, a;
39 inline RGBA() : r(0), g(0), b(0), a(0) {}
41 inline RGBA(float red, float green, float blue, float alpha) :
42 r(red), g(green), b(blue), a(alpha) {}
44 inline RGBA &operator+=(const RGBA &ob)
46 r += ob.r;
47 g += ob.g;
48 b += ob.b;
49 a += ob.a;
51 return *this;
54 inline RGBA operator/(double ob) const
56 RGBA rgba(r, g, b, a);
58 rgba.r /= ob;
59 rgba.g /= ob;
60 rgba.b /= ob;
61 rgba.a /= ob;
63 return rgba;
67 protected:
68 /* Pointers used in the class. Automatic remotion */
69 boost::scoped_array<RGBA> data;
70 std::auto_ptr<Imf::OutputFile> file;
72 /* Size of the image */
73 unsigned int m_w, m_h;
75 public:
76 /* Actions for the class (only image creation for now) */
77 enum Action {Create};
79 /* Accept file name, the size of the image and the action */
80 Image(const std::string &filename, unsigned int w, unsigned int h,
81 enum Action action);
83 /* Write the next n lines, from top to bottom */
84 void writeLines(unsigned int n);
86 /* Like writeLines(1) */
87 void writeLine();
89 /* Get the pointer of a pixel column.
90 * It is possible access to the RGBA structure with image[x][y] */
91 inline RGBA *operator[](unsigned int x)
93 return &data[x * m_h];
96 /* Like the previous, but for consts */
97 inline const RGBA *operator[](unsigned int x) const
99 return &data[x * m_h];
102 /* Sizes of the image */
103 inline unsigned int w() const
105 return m_w;
108 inline unsigned int h() const
110 return m_h;
114 #endif