// // File: image.cc // // (C) 2000-2006 Helmut Cantzler // // Licensed under the terms of the Lesser General Public License. // #include "image.h" Image::Image() { image = NULL; image_data = NULL; image_height = image_width = 0; } Image::~Image() { delete image; delete image_data; } int Image::read(const char *filename) { delete image; image = new QImage(filename); if (image->isNull()) { delete image; image = NULL; return 1; } image_height = image->width(); image_width = image->height(); return 0; } void Image::scale(int height, int width) { if (image == NULL) return; // scale image QImage scaled_image = image->scale(width, height); delete image; image = new QImage(scaled_image); image_height=height; image_width=width; } int Image::height(void) const { return image_height; } int Image::width(void) const { return image_width; } const unsigned char* Image::data(void) { QRgb pixel; int y, x; if (image == NULL) return NULL; // Create the texture data structures delete image_data; image_data = new Array3D(image_width, image_height, 3); // copy in data structure for (y=0; y < image_height; y++) for (x=0; x < image_width; x++) { pixel = image->pixel( x, image_width-y-1 ); image_data->set(x, y, 0, qRed(pixel) ); image_data->set(x, y, 1, qGreen(pixel) ); image_data->set(x, y, 2, qBlue(pixel) ); } return image_data->get_data(); }