Readapt the comments for Image
[cassata.biscotto.git] / src / Image.cpp
blob4bc94793ed983c8751c8dd5890b059033f007542
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 #include "Image.h"
23 #include <ImfChannelList.h>
24 #include <cstring> //For memset
26 using namespace Imf;
27 using namespace boost;
28 using namespace std;
30 Image::Image(const string &filename, unsigned int w, unsigned int h,
31 enum Action action) : data(new RGBA[w * h]), m_w(w), m_h(h)
33 /* Make an header */
34 Header header(w, h);
35 /* Channel inserting */
36 header.channels().insert("R", Channel(FLOAT));
37 header.channels().insert("G", Channel(FLOAT));
38 header.channels().insert("B", Channel(FLOAT));
39 header.channels().insert("A", Channel(FLOAT));
41 /* Make the file */
42 file = auto_ptr<OutputFile>(new OutputFile(filename.c_str(),
43 header));
45 /* Make a framebuffer */
46 FrameBuffer framebuffer;
48 /* Assign the color corrispondent slices at the framebuffer */
49 framebuffer.insert("R", Slice(FLOAT, (char *)&data[0].r,
50 sizeof(struct RGBA) * h, sizeof(struct RGBA)));
51 framebuffer.insert("G", Slice(FLOAT, (char *)&data[0].g,
52 sizeof(struct RGBA) * h, sizeof(struct RGBA)));
53 framebuffer.insert("B", Slice(FLOAT, (char *)&data[0].b,
54 sizeof(struct RGBA) * h, sizeof(struct RGBA)));
55 framebuffer.insert("A", Slice(FLOAT, (char *)&data[0].a,
56 sizeof(struct RGBA) * h, sizeof(struct RGBA)));
58 /* Clear the image data (black and transparent) */
59 memset(data.get(), 0, sizeof(RGBA) * w * h);
61 /* Join the framebuffer with the file */
62 file->setFrameBuffer(framebuffer);
65 void Image::writeLines(unsigned int n)
67 file->writePixels(n);
70 void Image::writeLine()
72 writeLines(1);