// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // An rgb image. Includes code to read the image from the // screen, and save/read the image from a PPM file on disk. // // Author: Alejo Hausner (ahausner@truehaus.net) 2008. #include "Image.h" #include #include #include #include #include extern FILE *dbgfp; Image::Image() { // cout << "Image constr." << endl; buf = NULL; height = width = 0; } ///////////////////////////////////////////////// // // Destructor. Release the image array. // Image::~Image() { if (height > 0) { for (int row=0; row=0; row-- ) { src = buf[row]; dst = scanLine; for (col=0; col height-1) row = height-1; if (col < 0) col = 0; if (col > width-1) col = width-1; byte* p = buf[row] + 4*col; Colour c; int r = *p++; int g = *p++; int b = *p; // fprintf(dbgfp,"(row col)=(%d %d) rgb=(%d %d %d)\n",row,col,r,g,b); c.set(r,g,b); return c; } void Image::ensureSpace(int newWidth, int newHeight) { if (height != newHeight || width != newWidth) { int y; if (buf != NULL) { for (y=0; y dy ? dy/2.0 : dx/2.0; } void Image::drawScreen(int width, int height) { int row,col=0; double x,y; for (row=0; rowwidth/2; col--) { pr = *right; pl = *left; *right++ = pl; *left++ = pr; pr = *right; pl = *left; *right++ = pl; *left++ = pr; pr = *right; pl = *left; *right++ = pl; *left++ = pr; pr = *right; pl = *left; *right++ = pl; *left++ = pr; right -= 8; } } }