IntelliPhoto  0.4
IntelliShapedImage.cpp
Go to the documentation of this file.
3 #include<QPainter>
4 #include<QRect>
5 #include<QDebug>
6 
8  :IntelliRasterImage(weight, height){
9 }
10 
12 
13 }
14 
16  return getDisplayable(imageData.size(),alpha);
17 }
18 
20  IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
21  shaped->setPolygon(this->polygonData);
22  shaped->imageData.fill(Qt::transparent);
23  return shaped;
24 }
25 
27  if(polygonData.size()<=2){
28  QColor clr;
29  for(int y=0; y<imageData.height(); y++){
30  for(int x=0; x<imageData.width(); x++){
31  clr = imageData.pixel(x,y);
32  clr.setAlpha(255);
33  imageData.setPixelColor(x,y,clr);
34  }
35  }
36  return;
37  }
38  QPoint A = polygonData[0];
39  QColor clr;
40  for(int y=0; y<imageData.height(); y++){
41  for(int x=0; x<imageData.width(); x++){
42  int cutNumeber=0;
43  for(int i=1; i<static_cast<int>(polygonData.size()-1); i++){
44  QPoint B = polygonData[static_cast<size_t>(i)];
45  QPoint C = polygonData[static_cast<size_t>(i+1)];
46  QPoint P(x,y);
47  cutNumeber+=IntelliHelper::isInTriangle(A,B,C,P);
48  }
49  if(cutNumeber%2==0){
50  clr = imageData.pixelColor(x,y);
51  clr.setAlpha(0);
52  imageData.setPixelColor(x,y,clr);
53  }else{
54  clr = imageData.pixelColor(x,y);
55  clr.setAlpha(std::min(255, clr.alpha()));
56  imageData.setPixelColor(x,y,clr);
57  }
58  }
59  }
60 }
61 
62 QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
63  QImage copy = imageData;
64  for(int y = 0; y<copy.height(); y++){
65  for(int x = 0; x<copy.width(); x++){
66  QColor clr = copy.pixelColor(x,y);
67  clr.setAlpha(std::min(alpha,clr.alpha()));
68  copy.setPixelColor(x,y, clr);
69  }
70  }
71  return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
72 }
73 
74 void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
75  if(polygonData.size()<3){
76  this->polygonData.clear();
77  }else{
78  this->polygonData.clear();
79  for(auto element:polygonData){
80  this->polygonData.push_back(QPoint(element.x(), element.y()));
81  }
82  }
84  return;
85 }
IntelliShapedImage::getDisplayable
virtual QImage getDisplayable(const QSize &displaySize, int alpha=255) override
Definition: IntelliShapedImage.cpp:62
IntelliShapedImage.h
IntelliHelper::isInTriangle
static bool isInTriangle(QPoint &A, QPoint &B, QPoint &C, QPoint &P)
Definition: IntelliHelper.h:15
IntelliHelper.h
IntelliShapedImage
Definition: IntelliShapedImage.h:6
IntelliShapedImage::getDeepCopy
virtual IntelliImage * getDeepCopy() override
Definition: IntelliShapedImage.cpp:19
IntelliImage::imageData
QImage imageData
Definition: IntelliImage.h:23
IntelliImage
Definition: IntelliImage.h:18
IntelliShapedImage::polygonData
std::vector< QPoint > polygonData
Definition: IntelliShapedImage.h:10
IntelliShapedImage::IntelliShapedImage
IntelliShapedImage(int weight, int height)
Definition: IntelliShapedImage.cpp:7
IntelliShapedImage::~IntelliShapedImage
virtual ~IntelliShapedImage() override
Definition: IntelliShapedImage.cpp:11
IntelliRasterImage
Definition: IntelliRasterImage.h:6
IntelliShapedImage::calculateVisiblity
virtual void calculateVisiblity() override
Definition: IntelliShapedImage.cpp:26
IntelliShapedImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData) override
Definition: IntelliShapedImage.cpp:74