/* -*- 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 "magellan/contentfilled.h" #include #include "magellan/options.h" ContentFilled::ContentFilled( int _minx, int _miny, int _maxx, int _maxy, bool _smooth ) : minx(_minx), miny(_miny), maxx(_maxx), maxy(_maxy), smooth(_smooth) { init(); } ContentFilled::ContentFilled( int _maxx, int _maxy, bool _smooth ) : minx(0), miny(0), maxx(_maxx), maxy(_maxy), smooth(_smooth) { init(); } ContentFilled::ContentFilled() : minx(0), miny(0), maxx(0), maxy(0), smooth(false) { init(); } void ContentFilled::init() { xconv = (maxx-minx)/(2*M_PI); yconv = (maxy-miny)/M_PI; } void ContentFilled::plot( Output* bitmap, XfView* viewport, XfMap* projection, XfOrbit* orbit, XfSphere* sphere ) { ivec2 bm_pos; dvec2 map_pos; dvec3 shifted_pos; dvec3 globe_pos; dvec2 latlong; ivec3 colour; ivec3 c00; ivec3 c10; ivec3 c01; ivec3 c11; for(bm_pos[1] = viewport->bottom(); bm_pos[1] < viewport->top(); bm_pos[1]++) { for(bm_pos[0] = viewport->left(); bm_pos[0] < viewport->right(); bm_pos[0]++) { if(!viewport->g(map_pos, bm_pos)) continue; if(projection->g(shifted_pos, map_pos) && orbit->g(globe_pos, shifted_pos) && sphere->g(latlong, globe_pos)) { dvec2 pixelpos; pixelpos[0] = (latlong[0]+M_PI)*xconv; pixelpos[1] = (latlong[1]+M_PI_2)*yconv; if(smooth) { getpixel(c00, pixelpos); pixelpos[0]++; getpixel(c10, pixelpos); pixelpos[1]++; getpixel(c11, pixelpos); pixelpos[0]--; getpixel(c01, pixelpos); blend(colour, c00, c10, c11, c01, pixelpos[0] - int(pixelpos[0]), pixelpos[1] - int(pixelpos[1])); } else { getpixel(colour, pixelpos); } } else { colour[0] = colour[1] = colour[2] = 0; continue; } bitmap->setpixel(bm_pos, colour); } } } void ContentFilled::blend(ivec3& output, const ivec3& c00, const ivec3& c10, const ivec3& c11, const ivec3& c01, double dx, double dy) const { for(int i=0; i<3; i++) { double t0 = c00[i] + (c10[i] - c00[i]) * dx; double t1 = c01[i] + (c11[i] - c01[i]) * dx; output[i] = int(t0 + (t1 - t0) * dy); } }