// // File: texture_image.cc // // (C) 2000-2006 Helmut Cantzler // // Licensed under the terms of the Lesser General Public License. // #include #include #include #include "texture_image.h" TextureImage::TextureImage(QWidget *parent) : QWidget(parent) { fn = fn_short = QString::null; homo_nr=0; resize(0,0); } const unsigned int* TextureImage::getHomoPoints(void) { if (homo_nr != 4) return NULL; unsigned int *points = new unsigned int[8]; points[0] = homo_points[0].x; points[1] = homo_points[0].y; points[2] = homo_points[1].x; points[3] = homo_points[1].y; points[4] = homo_points[2].x; points[5] = homo_points[2].y; points[6] = homo_points[3].x; points[7] = homo_points[3].y; return points; } const char* TextureImage::getFileName(void) const { return fn_short.latin1(); } void TextureImage::paintEvent(QPaintEvent *e) { if ( !pix.isNull() ) { QPainter painter(this); painter.setClipRect(e->rect()); painter.drawPixmap(0, 0, pix); } } void TextureImage::drawPoint(Point p, unsigned int color) { img.setPixel(p.x, p.y, color); img.setPixel(p.x+1, p.y, color); img.setPixel(p.x-1, p.y, color); img.setPixel(p.x, p.y+1, color); img.setPixel(p.x, p.y-1, color); img.setPixel(p.x+2, p.y, 0x000000); img.setPixel(p.x-2, p.y, 0x000000); img.setPixel(p.x, p.y+2, 0x000000); img.setPixel(p.x, p.y-2, 0x000000); img.setPixel(p.x+1, p.y+1, 0x000000); img.setPixel(p.x+1, p.y-1, 0x000000); img.setPixel(p.x-1, p.y+1, 0x000000); img.setPixel(p.x-1, p.y-1, 0x000000); pix.convertFromImage(img); repaint(); } void TextureImage::mousePressEvent(QMouseEvent *e) { Point p; int point_colors[4] = { 0xFF00FF, 0x00FF00, 0xFFFF00, 0xFFFFFF }; p.x = e->x(); p.y = e->y(); if (e->button() == Qt::LeftButton && homo_nr < 4) if ( p.x >= 5 && p.x < pix.width()-5 && p.y >= 5 && p.y < pix.height()-5 ) { homo_points[homo_nr] = p; drawPoint(p, point_colors[homo_nr]); homo_nr++; } e->accept(); } void TextureImage::clearImage(void) { if ( !fn.isEmpty() ) { homo_nr=0; img.load(fn); if (img.depth() <= 8) img = img.convertDepth(32); pix.convertFromImage(img); resize(pix.size()); repaint(); } } void TextureImage::loadImage(void) { QStringList list = QImage::inputFormatList(); QString formats = "Images ("; for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) formats += " *." + (*it).lower(); formats += ")"; fn = QFileDialog::getOpenFileName(QString::null, formats, this); if ( fn.contains('/') ) fn_short = fn.section('/', -1); else if ( fn.contains('\\') ) fn_short = fn.section('\\', -1); else fn_short = fn; clearImage(); }