Image structure

This commit is contained in:
Sonaion
2019-11-28 16:34:26 +01:00
parent bccca91111
commit a23e4bdd9c
13 changed files with 129 additions and 97 deletions

View File

@@ -3,8 +3,8 @@
#include<QPainter>
IntelliImage::IntelliImage(int weight, int height)
:imageData(QSize(weight, height), QImage::Format_RGB32){
:imageData(QSize(weight, height), QImage::Format_ARGB32){
imageData.fill(QColor(255,255,255,255));
}
IntelliImage::~IntelliImage(){
@@ -19,9 +19,8 @@ bool IntelliImage::loadImage(const QString &fileName){
if (!loadedImage.load(fileName))
return false;
QSize newSize = loadedImage.size().expandedTo(imageData.size());
resizeImage(&loadedImage, newSize);
imageData = loadedImage;
loadedImage =loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
imageData= loadedImage.convertToFormat(QImage::Format_ARGB32);
return true;
}
@@ -31,7 +30,7 @@ void IntelliImage::resizeImage(QImage *image, const QSize &newSize){
return;
// Create a new image to display and fill it with white
QImage newImage(newSize, QImage::Format_RGB32);
QImage newImage(newSize, QImage::Format_ARGB32);
newImage.fill(qRgb(255, 255, 255));
// Draw the image
@@ -68,4 +67,13 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co
void IntelliImage::floodFill(const QColor& color){
imageData.fill(color);
}
int IntelliImage::x(){
return imageData.size().width();
}
int IntelliImage::y(){
return imageData.size().height();
}

View File

@@ -5,6 +5,7 @@
#include<QPoint>
#include<QColor>
#include<QSize>
#include<QWidget>
#include<vector>
enum class ImageType{
@@ -13,6 +14,7 @@ enum class ImageType{
};
class IntelliImage{
protected:
void resizeImage(QImage *image, const QSize &newSize);
@@ -28,11 +30,17 @@ public:
//returns the filtered output
virtual QImage getDisplayable(const QSize& displaySize)=0;
virtual QImage getDisplayable()=0;
//returns the filtered output
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
virtual bool loadImage(const QString &fileName);
int x();
int y();
};
#endif

View File

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

View File

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

View File

@@ -12,12 +12,14 @@ IntelliShapedImage::~IntelliShapedImage(){
}
QImage IntelliShapedImage::getDisplayable(){
return getDisplayable(imageData.size());
}
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){
QImage copy = imageData;
QPoint extrem(copy.width()+1, 0);
QPoint startPoint(0,0);
//traverse through y direction
QPoint startPoint;
QPoint extrem(0,copy.width()+1);
for(int y = 0; y<copy.height(); y++){
extrem.setY(y);
startPoint.setY(y);
@@ -25,24 +27,27 @@ QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){
for(int x=0; x<copy.width(); x++){
startPoint.setX(x);
//traverse all edges
int cutNumber = 0;
int cutNumberX = 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);
cutNumberX+=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));
if(!(cutNumberX&1)){
QColor tmpColor(0,0,0);
tmpColor.setAlpha(0);
copy.setPixelColor(startPoint,tmpColor);
}
}
}
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
}
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
this->polygonData=polygonData;
for(auto element:polygonData){
this->polygonData.push_back(QPoint(element.x(), element.y()));
}
return;
}

View File

@@ -4,6 +4,7 @@
#include"Image/IntelliImage.h"
class IntelliShapedImage : public IntelliImage{
protected:
std::vector<QPoint> polygonData;
public:
@@ -12,6 +13,7 @@ public:
//returns the filtered output
virtual QImage getDisplayable(const QSize& displaySize) override;
virtual QImage getDisplayable() override;
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;