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

@@ -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;
}