/* -*- C++ -*- * Copyright ©2008 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "output_canvas.h" extern "C" PluginInfo* getmodules(int i) { if(i==0) { PluginInfo_Output* pi = new PluginInfo_Output(); pi->name = "Output to Canvas"; pi->author = "Hugo Mills"; pi->copyright = " ©2008 Hugo Mills"; pi->version = 0x00900; pi->parser = Output_Canvas::parser; return pi; } else return NULL; } Output* Output_Canvas::parser( ConfigLexer* lex, const std::string& type, const std::string& subtype ) { return NULL; // For internal use only -- cannot be used externally } Output_Canvas::Output_Canvas(int wid, int hgt) : Output(wid, hgt), canvas(NULL) { canvas = new unsigned char[wid*hgt*3]; } Output_Canvas::~Output_Canvas() { delete[] canvas; } void Output_Canvas::setpixel(const ivec2& pos, int r, int g, int b) { if(pos[0] < 0 || pos[0] >= xmax || pos[1] < 0 || pos[1] >= ymax) return; int offset = (pos[0] + pos[1] * xmax) * 3; canvas[offset] = r; canvas[offset+1] = g; canvas[offset+2] = b; } void Output_Canvas::getpixel(ivec3& rgb, const ivec2& pos) const { if(pos[0] < 0 || pos[0] >= xmax || pos[1] < 0 || pos[1] >= ymax) { rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; return; } int offset = (pos[0] + pos[1] * xmax) * 3; rgb[0] = canvas[offset]; rgb[1] = canvas[offset+1]; rgb[2] = canvas[offset+2]; }