Some image change

This commit is contained in:
Sonaion
2019-11-26 17:26:43 +01:00
parent b4d8738e71
commit bccca91111
29 changed files with 340 additions and 4099 deletions

View File

@@ -0,0 +1,71 @@
#include"Image/IntelliImage.h"
#include<QSize>
#include<QPainter>
IntelliImage::IntelliImage(int weight, int height)
:imageData(QSize(weight, height), QImage::Format_RGB32){
}
IntelliImage::~IntelliImage(){
}
bool IntelliImage::loadImage(const QString &fileName){
// Holds the image
QImage loadedImage;
// If the image wasn't loaded leave this function
if (!loadedImage.load(fileName))
return false;
QSize newSize = loadedImage.size().expandedTo(imageData.size());
resizeImage(&loadedImage, newSize);
imageData = loadedImage;
return true;
}
void IntelliImage::resizeImage(QImage *image, const QSize &newSize){
// Check if we need to redraw the image
if (image->size() == newSize)
return;
// Create a new image to display and fill it with white
QImage newImage(newSize, QImage::Format_RGB32);
newImage.fill(qRgb(255, 255, 255));
// Draw the image
QPainter painter(&newImage);
painter.drawImage(QPoint(0, 0), *image);
*image = newImage;
}
void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
// Used to draw on the widget
QPainter painter(&imageData);
// Set the current settings for the pen
painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
// Draw a line from the last registered point to the current
painter.drawPoint(p1);
// Call to update the rectangular space where we drew
//update(QRect(p1, p2));
}
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
// Used to draw on the widget
QPainter painter(&imageData);
// Set the current settings for the pen
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
// Draw a line from the last registered point to the current
painter.drawLine(p1, p2);
}
void IntelliImage::floodFill(const QColor& color){
imageData.fill(color);
}

View File

@@ -0,0 +1,38 @@
#ifndef INTELLIIMAGE_H
#define INTELLIIMAGE_H
#include<QImage>
#include<QPoint>
#include<QColor>
#include<QSize>
#include<vector>
enum class ImageType{
Raster_Image,
Shaped_Image
};
class IntelliImage{
protected:
void resizeImage(QImage *image, const QSize &newSize);
QImage imageData;
public:
IntelliImage(int weight, int height);
virtual ~IntelliImage() = 0;
//start on top left
virtual void drawPixel(const QPoint &p1, const QColor& color);
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
virtual void floodFill(const QColor& color);
//returns the filtered output
virtual QImage getDisplayable(const QSize& displaySize)=0;
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
virtual bool loadImage(const QString &fileName);
};
#endif

View File

@@ -0,0 +1,25 @@
#include"Image/IntelliRasterImage.h"
#include<QPainter>
#include<QRect>
#include<QDebug>
IntelliRasterimage::IntelliRasterimage(int weight, int height)
:IntelliImage(weight, height){
}
IntelliRasterimage::~IntelliRasterimage(){
}
QImage IntelliRasterimage::getDisplayable(const QSize& displaySize){
QImage copy = imageData;
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
}
void IntelliRasterimage::setPolygon(const std::vector<QPoint>& polygonData){
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
return;
}

View File

@@ -0,0 +1,18 @@
#ifndef INTELLIRASTER_H
#define INTELLIRASTER_H
#include"Image/IntelliImage.h"
class IntelliRasterimage : public IntelliImage{
public:
IntelliRasterimage(int weight, int height);
virtual ~IntelliRasterimage() override;
//returns the filtered output
virtual QImage getDisplayable(const QSize& displaySize) override;
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
};
#endif

View File

@@ -0,0 +1,48 @@
#include"Image/IntelliShapedImage.h"
#include"IntelliHelper/IntelliHelper.h"
#include<QPainter>
#include<QRect>
#include<QDebug>
IntelliShapedImage::IntelliShapedImage(int weight, int height)
:IntelliImage(weight, height){
}
IntelliShapedImage::~IntelliShapedImage(){
}
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){
QImage copy = imageData;
QPoint extrem(copy.width()+1, 0);
QPoint startPoint(0,0);
//traverse through y direction
for(int y = 0; y<copy.height(); y++){
extrem.setY(y);
startPoint.setY(y);
//traverse through x dircetion
for(int x=0; x<copy.width(); x++){
startPoint.setX(x);
//traverse all edges
int cutNumber = 0;
for(size_t i=0; i<polygonData.size()-1; i++){
QPoint& start = polygonData[i];
QPoint& end = polygonData[i+1];
cutNumber += IntelliHelper::hasIntersection(startPoint, extrem, start, end);
}
//check if zhe cutNumber is Even -> not in Polygon
if(!(cutNumber&1)){
QColor tmpColor(copy.color(y*copy.width()+x));
tmpColor.setAlpha(0);
copy.setPixelColor(startPoint,tmpColor);
}
}
}
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
}
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
this->polygonData=polygonData;
return;
}

View File

@@ -0,0 +1,20 @@
#ifndef INTELLISHAPE_H
#define INTELLISHAPE_H
#include"Image/IntelliImage.h"
class IntelliShapedImage : public IntelliImage{
protected:
std::vector<QPoint> polygonData;
public:
IntelliShapedImage(int weight, int height);
virtual ~IntelliShapedImage() override;
//returns the filtered output
virtual QImage getDisplayable(const QSize& displaySize) override;
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
};
#endif