mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-13 03:40:31 +02:00
Moved up src/ one level
This commit is contained in:
69
src/Image/IntelliImage.cpp
Normal file
69
src/Image/IntelliImage.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include"Image/IntelliImage.h"
|
||||
#include<QSize>
|
||||
#include<QPainter>
|
||||
|
||||
IntelliImage::IntelliImage(int weight, int height)
|
||||
:imageData(QSize(weight, height), QImage::Format_ARGB32){
|
||||
imageData.fill(QColor(255,255,255,255));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// scaled Image to size of Layer
|
||||
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
|
||||
|
||||
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
|
||||
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_ARGB32);
|
||||
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);
|
||||
}
|
||||
|
||||
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::drawPlain(const QColor& color){
|
||||
imageData.fill(color);
|
||||
}
|
||||
54
src/Image/IntelliImage.h
Normal file
54
src/Image/IntelliImage.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef INTELLIIMAGE_H
|
||||
#define INTELLIIMAGE_H
|
||||
|
||||
#include<QImage>
|
||||
#include<QPoint>
|
||||
#include<QColor>
|
||||
#include<QSize>
|
||||
#include<QWidget>
|
||||
#include<vector>
|
||||
|
||||
enum class ImageType{
|
||||
Raster_Image,
|
||||
Shaped_Image
|
||||
};
|
||||
|
||||
class IntelliTool;
|
||||
|
||||
class IntelliImage{
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
void resizeImage(QImage *image, const QSize &newSize);
|
||||
|
||||
QImage imageData;
|
||||
|
||||
//calculate with polygon
|
||||
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 drawPlain(const QColor& color);
|
||||
|
||||
//returns the filtered output
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0;
|
||||
virtual QImage getDisplayable(int alpha=255)=0;
|
||||
|
||||
//gets a copy of the image !allocated
|
||||
virtual IntelliImage* getDeepCopy()=0;
|
||||
virtual void calculateVisiblity()=0;
|
||||
|
||||
//returns the filtered output
|
||||
|
||||
//sets the data for the visible image
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
|
||||
virtual std::vector<QPoint> getPolygonData(){ return std::vector<QPoint>();}
|
||||
|
||||
//loads an image to the ColorBuffer
|
||||
virtual bool loadImage(const QString &fileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
44
src/Image/IntelliRasterImage.cpp
Normal file
44
src/Image/IntelliRasterImage.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include"Image/IntelliRasterImage.h"
|
||||
#include<QPainter>
|
||||
#include<QRect>
|
||||
#include<QDebug>
|
||||
|
||||
IntelliRasterImage::IntelliRasterImage(int weight, int height)
|
||||
:IntelliImage(weight, height){
|
||||
|
||||
}
|
||||
|
||||
IntelliRasterImage::~IntelliRasterImage(){
|
||||
|
||||
}
|
||||
|
||||
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||
raster->imageData.fill(Qt::transparent);
|
||||
return raster;
|
||||
}
|
||||
|
||||
void IntelliRasterImage::calculateVisiblity(){
|
||||
//not used in raster image
|
||||
}
|
||||
|
||||
QImage IntelliRasterImage::getDisplayable(int alpha){
|
||||
return getDisplayable(imageData.size(), alpha);
|
||||
}
|
||||
|
||||
QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
QImage copy = imageData;
|
||||
for(int y = 0; y<copy.height(); y++){
|
||||
for(int x = 0; x<copy.width(); x++){
|
||||
QColor clr = copy.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(alpha, clr.alpha()));
|
||||
copy.setPixelColor(x,y, clr);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
25
src/Image/IntelliRasterImage.h
Normal file
25
src/Image/IntelliRasterImage.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef INTELLIRASTER_H
|
||||
#define INTELLIRASTER_H
|
||||
|
||||
#include"Image/IntelliImage.h"
|
||||
|
||||
class IntelliRasterImage : public IntelliImage{
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
virtual void calculateVisiblity() override;
|
||||
public:
|
||||
IntelliRasterImage(int weight, int height);
|
||||
virtual ~IntelliRasterImage() override;
|
||||
|
||||
//returns the filtered output
|
||||
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
|
||||
//gets a copy of the image !allocated
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
|
||||
//sets the data for the visible image
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
85
src/Image/IntelliShapedImage.cpp
Normal file
85
src/Image/IntelliShapedImage.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include"Image/IntelliShapedImage.h"
|
||||
#include"IntelliHelper/IntelliHelper.h"
|
||||
#include<QPainter>
|
||||
#include<QRect>
|
||||
#include<QDebug>
|
||||
|
||||
IntelliShapedImage::IntelliShapedImage(int weight, int height)
|
||||
:IntelliRasterImage(weight, height){
|
||||
}
|
||||
|
||||
IntelliShapedImage::~IntelliShapedImage(){
|
||||
|
||||
}
|
||||
|
||||
QImage IntelliShapedImage::getDisplayable(int alpha){
|
||||
return getDisplayable(imageData.size(),alpha);
|
||||
}
|
||||
|
||||
IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||
shaped->setPolygon(this->polygonData);
|
||||
shaped->imageData.fill(Qt::transparent);
|
||||
return shaped;
|
||||
}
|
||||
|
||||
void IntelliShapedImage::calculateVisiblity(){
|
||||
if(polygonData.size()<=2){
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++){
|
||||
for(int x=0; x<imageData.width(); x++){
|
||||
clr = imageData.pixel(x,y);
|
||||
clr.setAlpha(255);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
QPoint A = polygonData[0];
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++){
|
||||
for(int x=0; x<imageData.width(); x++){
|
||||
int cutNumeber=0;
|
||||
for(int i=1; i<static_cast<int>(polygonData.size()-1); i++){
|
||||
QPoint B = polygonData[static_cast<size_t>(i)];
|
||||
QPoint C = polygonData[static_cast<size_t>(i+1)];
|
||||
QPoint P(x,y);
|
||||
cutNumeber+=IntelliHelper::isInTriangle(A,B,C,P);
|
||||
}
|
||||
if(cutNumeber%2==0){
|
||||
clr = imageData.pixelColor(x,y);
|
||||
clr.setAlpha(0);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}else{
|
||||
clr = imageData.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
QImage copy = imageData;
|
||||
for(int y = 0; y<copy.height(); y++){
|
||||
for(int x = 0; x<copy.width(); x++){
|
||||
QColor clr = copy.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(alpha,clr.alpha()));
|
||||
copy.setPixelColor(x,y, clr);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
}
|
||||
|
||||
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
if(polygonData.size()<3){
|
||||
this->polygonData.clear();
|
||||
}else{
|
||||
this->polygonData.clear();
|
||||
for(auto element:polygonData){
|
||||
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||
}
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
}
|
||||
29
src/Image/IntelliShapedImage.h
Normal file
29
src/Image/IntelliShapedImage.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef INTELLISHAPE_H
|
||||
#define INTELLISHAPE_H
|
||||
|
||||
#include"Image/IntelliRasterImage.h"
|
||||
|
||||
class IntelliShapedImage : public IntelliRasterImage{
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
|
||||
std::vector<QPoint> polygonData;
|
||||
public:
|
||||
IntelliShapedImage(int weight, int height);
|
||||
virtual ~IntelliShapedImage() override;
|
||||
|
||||
virtual void calculateVisiblity() override;
|
||||
|
||||
//returns the filtered output
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
|
||||
//gets a copy of the image !allocated
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
virtual std::vector<QPoint> getPolygonData() override{return polygonData;}
|
||||
|
||||
//sets the data for the visible image
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user