mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-12 19:40:28 +02:00
Updated it works kinda
TOdo: fix BUGS
This commit is contained in:
@@ -27,14 +27,17 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||
}
|
||||
|
||||
void IntelliShapedImage::calculateVisiblity(){
|
||||
if(fastRenderering) {
|
||||
if(polygonData.size()<2){
|
||||
return;
|
||||
}
|
||||
if(fastRenderering) {
|
||||
this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
if(polygonData.size()<=2) {
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++) {
|
||||
for(int x=0; x<imageData.width(); x++) {
|
||||
for(int x=0; x<imageData.width(); x++) {
|
||||
clr = imageData.pixel(x,y);
|
||||
clr.setAlpha(255);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
@@ -52,7 +55,7 @@ void IntelliShapedImage::calculateVisiblity(){
|
||||
clr = imageData.pixelColor(x,y);
|
||||
bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr);
|
||||
if(isInPolygon) {
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
}else{
|
||||
clr.setAlpha(0);
|
||||
}
|
||||
@@ -91,6 +94,19 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||
}
|
||||
triangles = IntelliTriangulation::calculateTriangles(polygonData);
|
||||
if(fastRenderering){
|
||||
imageData = imageData.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
for(int y = 0; y<imageData.height(); y++) {
|
||||
for(int x = 0; x<imageData.width(); x++) {
|
||||
QColor clr = imageData.pixelColor(x,y);
|
||||
clr.setAlpha(255);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
if(fastRenderering){
|
||||
imageData = imageData.convertToFormat(QImage::Format_Indexed8);
|
||||
}
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
|
||||
@@ -113,7 +113,8 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
|
||||
void PaintingArea::setPolygon(int idx){
|
||||
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
|
||||
if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){
|
||||
qDebug() << "Todo Implement here set Polygon";
|
||||
delete this->Tool;
|
||||
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,5 +439,20 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){
|
||||
if(activeLayer<0) {
|
||||
return nullptr;
|
||||
}
|
||||
return layerBundle[activeLayer].image;
|
||||
return layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
}
|
||||
|
||||
QImage PaintingArea::getImageDataOfActiveLayer(){
|
||||
QImage returnImage;
|
||||
if(activeLayer<0) {
|
||||
returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
|
||||
returnImage.fill(QColor(255,255,255,255));
|
||||
}
|
||||
else{
|
||||
returnImage = layerBundle[static_cast<size_t>(activeLayer)].image->getImageData();
|
||||
if(renderSettings.isFastRenderering()){
|
||||
returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
}
|
||||
return returnImage;
|
||||
}
|
||||
|
||||
@@ -182,6 +182,12 @@ int getNumberOfActiveLayer();
|
||||
|
||||
IntelliImage* getImageOfActiveLayer();
|
||||
|
||||
/*!
|
||||
* \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture)
|
||||
* \return return the image as an rgba32bit qImage
|
||||
*/
|
||||
QImage getImageDataOfActiveLayer();
|
||||
|
||||
IntelliToolsettings Toolsettings;
|
||||
IntelliColorPicker colorPicker;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ void IntelliTool::onMouseLeftPressed(int x, int y){
|
||||
void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||
if(isDrawing) {
|
||||
isDrawing=false;
|
||||
this->mergeToolLayer();
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
activeLayer->image->calculateVisiblity();
|
||||
}
|
||||
@@ -62,25 +62,25 @@ void IntelliTool::mergeToolLayer(){
|
||||
QColor clr_1;
|
||||
QImage updatedImage = activeLayer->image->getImageData();
|
||||
|
||||
for(int y=0; y<activeLayer->height; y++) {
|
||||
for(int x=0; x<activeLayer->width; x++) {
|
||||
clr_0=updatedImage.pixelColor(x,y);
|
||||
clr_1=Canvas->image->imageData.pixelColor(x,y);
|
||||
float t = static_cast<float>(clr_1.alpha())/255.f;
|
||||
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
|
||||
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
|
||||
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
|
||||
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
for(int y=0; y<activeLayer->height; y++) {
|
||||
for(int x=0; x<activeLayer->width; x++) {
|
||||
clr_0=updatedImage.pixelColor(x,y);
|
||||
clr_1=Canvas->image->imageData.pixelColor(x,y);
|
||||
float t = static_cast<float>(clr_1.alpha())/255.f;
|
||||
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
|
||||
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
|
||||
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
|
||||
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
|
||||
updatedImage.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
updatedImage.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
activeLayer->image->setImageData(updatedImage);
|
||||
if(Canvas->image->getPolygonData().size() != 0){
|
||||
if(Canvas->image->getPolygonData().size() > 0){
|
||||
activeLayer->image->setPolygon(Canvas->image->getPolygonData());
|
||||
}
|
||||
Area->DummyGui->UpdateGui();
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <QInputDialog>
|
||||
#include <QDebug>
|
||||
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon)
|
||||
: IntelliTool(Area, colorPicker, Toolsettings){
|
||||
isPointNearStart = false;
|
||||
isDrawing = false;
|
||||
isInside = false;
|
||||
this->isSettingPolygon = isSettingPolygon;
|
||||
this->ActiveType = Tooltype::POLYGON;
|
||||
}
|
||||
|
||||
@@ -19,10 +20,13 @@ IntelliToolPolygon::~IntelliToolPolygon(){
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
|
||||
QPoint Point(x,y);
|
||||
isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
|
||||
if(isSettingPolygon){
|
||||
isInside = true;
|
||||
}
|
||||
}
|
||||
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
isInside = true;
|
||||
@@ -36,14 +40,18 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
QPointList.push_back(drawingPoint);
|
||||
|
||||
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
if(!isSettingPolygon){
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
|
||||
if(QPointList.size() > 2) {
|
||||
isPointNearStart = true;
|
||||
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
if(!isSettingPolygon){
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
else{
|
||||
isInside = false;
|
||||
isDrawing = false;
|
||||
@@ -56,7 +64,9 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
QPoint drawingPoint(x,y);
|
||||
QPointList.push_back(drawingPoint);
|
||||
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
if(!isSettingPolygon){
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +83,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
isInside = false;
|
||||
isPointNearStart = false;
|
||||
isDrawing = false;
|
||||
if(false){
|
||||
if(!isSettingPolygon){
|
||||
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
|
||||
QPoint Point;
|
||||
QColor colorTwo(colorPicker->getSecondColor());
|
||||
@@ -94,6 +104,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
}
|
||||
else{
|
||||
Canvas->image->setPolygon(QPointList);
|
||||
Canvas->image->setImageData(Area->getImageDataOfActiveLayer());
|
||||
}
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
QPointList.clear();
|
||||
|
||||
@@ -29,6 +29,11 @@ bool isDrawing;
|
||||
*/
|
||||
bool isInside;
|
||||
|
||||
/*!
|
||||
* \brief isSettingPolygon is the flag for calling the setPolygon method.
|
||||
*/
|
||||
bool isSettingPolygon;
|
||||
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||
*/
|
||||
@@ -43,8 +48,9 @@ public:
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
* \param isSettingPolygon - The flag for the set polygon method, standart is false
|
||||
*/
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon = false);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user