mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-13 20:00:32 +02:00
Image structure
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user