From c04d8d681505bba349936678291cf905b3093caa Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 8 Jan 2020 19:01:05 +0100 Subject: [PATCH 1/3] [W.I.P.] Added a FasterRenderOption Still completly buggy. and it crashes imediatly after input --- src/Image/IntelliImage.cpp | 39 ++++++++++++++++----- src/Image/IntelliImage.h | 17 ++++++++- src/Image/IntelliRasterImage.cpp | 13 +++++-- src/Image/IntelliRasterImage.h | 3 +- src/Image/IntelliShapedImage.cpp | 25 ++++++++++--- src/Image/IntelliShapedImage.h | 3 +- src/IntelliHelper/IntelliRenderSettings.cpp | 10 ++++++ src/IntelliHelper/IntelliRenderSettings.h | 20 +++++++++++ src/IntelliPhoto.pro | 2 ++ src/Layer/PaintingArea.cpp | 11 ++++-- src/Layer/PaintingArea.h | 4 ++- src/Tool/IntelliTool.cpp | 6 ++++ 12 files changed, 131 insertions(+), 22 deletions(-) create mode 100644 src/IntelliHelper/IntelliRenderSettings.cpp create mode 100644 src/IntelliHelper/IntelliRenderSettings.h diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 0a4b919..5e5e62d 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -2,9 +2,10 @@ #include #include -IntelliImage::IntelliImage(int weight, int height) - : imageData(QSize(weight, height), QImage::Format_ARGB32){ +IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) + : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ imageData.fill(QColor(255,255,255,255)); + this->fastRenderer = fastRendererOn; } @@ -23,7 +24,7 @@ bool IntelliImage::loadImage(const QString &filePath){ // scaled Image to size of Layer loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); - imageData = loadedImage.convertToFormat(QImage::Format_ARGB32); + imageData = loadedImage.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32); return true; } @@ -33,17 +34,21 @@ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){ return; // Create a new image to display and fill it with white - QImage newImage(newSize, QImage::Format_ARGB32); + 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; + updateRendererSetting(fastRenderer); } void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ - // Used to draw on the widget + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + // Used to draw on the widget QPainter painter(&imageData); // Set the current settings for the pen @@ -51,20 +56,28 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); + updateRendererSetting(fastRenderer); } void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ - // Used to draw on the widget + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + // 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.drawPoint(p1); + updateRendererSetting(fastRenderer); } void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ - // Used to draw on the widget + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + // Used to draw on the widget QPainter painter(&imageData); // Set the current settings for the pen @@ -72,12 +85,22 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co // Draw a line from the last registered point to the current painter.drawLine(p1, p2); + updateRendererSetting(fastRenderer); } void IntelliImage::drawPlain(const QColor& color){ - imageData.fill(color); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + imageData.fill(color); + updateRendererSetting(fastRenderer); } QColor IntelliImage::getPixelColor(QPoint& point){ return imageData.pixelColor(point); } + +void IntelliImage::updateRendererSetting(bool fastRendererOn){ + this->fastRenderer = fastRendererOn; + this->imageData = this->imageData.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32); +} diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index 04315c3..454a704 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -9,6 +9,7 @@ #include #include "IntelliHelper/IntelliHelper.h" +#include "IntelliHelper/IntelliRenderSettings.h" class IntelliTool; @@ -39,13 +40,20 @@ QImage imageData; * \brief The Type, an Image is. */ ImageType TypeOfImage; + +/*! + * \brief fastRenderer is the flag that represents the usage of 8bit pictures. + */ +bool fastRenderer; + public: /*! * \brief The Construcor of the IntelliImage. Given the Image dimensions. * \param width - The width of the Image. * \param height - The height of the Image. + * \param fastRendererOn - Represents the flag for 8bit picture handelling. */ -IntelliImage(int width, int height); +IntelliImage(int width, int height, bool fastRendererOn); /*! * \brief An Abstract Destructor. @@ -140,6 +148,13 @@ virtual bool loadImage(const QString &filePath); * \return The color of the Pixel as QColor. */ virtual QColor getPixelColor(QPoint& point); + +/*! + * \brief updateRendererSetting updates the existing image format to the new format. + * \param fastRendererOn flag for the 8bit image handeling. + */ +virtual void updateRendererSetting(bool fastRendererOn); + }; #endif diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index 8e8f918..7e97e55 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -3,9 +3,10 @@ #include #include -IntelliRasterImage::IntelliRasterImage(int weight, int height) - : IntelliImage(weight, height){ +IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) + : IntelliImage(width, height, fastRendererOn){ TypeOfImage = IntelliImage::ImageType::Raster_Image; + this->fastRenderer = fastRendererOn; } IntelliRasterImage::~IntelliRasterImage(){ @@ -13,7 +14,7 @@ IntelliRasterImage::~IntelliRasterImage(){ } IntelliImage* IntelliRasterImage::getDeepCopy(){ - IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height()); + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), false); raster->imageData.fill(Qt::transparent); raster->TypeOfImage = IntelliImage::ImageType::Raster_Image; return raster; @@ -29,6 +30,9 @@ QImage IntelliRasterImage::getDisplayable(int alpha){ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ QImage copy = imageData; + if(fastRenderer){ + copy = copy.convertToFormat(QImage::Format_ARGB32); + } for(int y = 0; y #include -IntelliShapedImage::IntelliShapedImage(int weight, int height) - : IntelliRasterImage(weight, height){ +IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) + : IntelliRasterImage(width, height, fastRendererOn){ TypeOfImage = IntelliImage::ImageType::Shaped_Image; + this->fastRenderer = fastRendererOn; } IntelliShapedImage::~IntelliShapedImage(){ @@ -18,7 +19,7 @@ QImage IntelliShapedImage::getDisplayable(int alpha){ } IntelliImage* IntelliShapedImage::getDeepCopy(){ - IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height()); + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false); shaped->setPolygon(this->polygonData); shaped->imageData.fill(Qt::transparent); shaped->TypeOfImage = IntelliImage::ImageType::Shaped_Image; @@ -26,7 +27,11 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){ } void IntelliShapedImage::calculateVisiblity(){ - if(polygonData.size()<=2) { + if(fastRenderer){ + this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + + if(polygonData.size()<=2) { QColor clr; for(int y=0; yimageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } return; } QColor clr; @@ -51,10 +59,16 @@ void IntelliShapedImage::calculateVisiblity(){ imageData.setPixelColor(x,y,clr); } } + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ QImage copy = imageData; + if(fastRenderer){ + copy = copy.convertToFormat(QImage::Format_ARGB32); + } for(int y = 0; yTool = nullptr; + this->renderSettings = IntelliRenderSettings(); this->setLayerDimensions(maxWidth, maxHeight); this->addLayer(200,200,0,0,IntelliImage::ImageType::Shaped_Image); layerBundle[0].image->drawPlain(QColor(0,0,255,255)); @@ -36,6 +37,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) layerBundle[1].alpha=200; activeLayer=0; + } PaintingArea::~PaintingArea(){ @@ -46,7 +48,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ //set standart parameter this->maxWidth = maxWidth; this->maxHeight = maxHeight; - Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); + Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); // Roots the widget to the top left even if resized setAttribute(Qt::WA_StaticContents); @@ -60,9 +62,9 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff newLayer.widthOffset = widthOffset; newLayer.heightOffset = heightOffset; if(type==IntelliImage::ImageType::Raster_Image) { - newLayer.image = new IntelliRasterImage(width,height); + newLayer.image = new IntelliRasterImage(width,height,renderSettings.getFastRenderer()); }else if(type==IntelliImage::ImageType::Shaped_Image) { - newLayer.image = new IntelliShapedImage(width, height); + newLayer.image = new IntelliShapedImage(width, height, renderSettings.getFastRenderer()); } newLayer.alpha = 255; this->layerBundle.push_back(newLayer); @@ -340,6 +342,9 @@ void PaintingArea::drawLayers(bool forSaving){ for(size_t i=0; igetDisplayable(layer.alpha); + if(renderSettings.getFastRenderer()){ + cpy = cpy.convertToFormat(QImage::Format_ARGB32); + } QColor clr_0; QColor clr_1; for(int y=0; y layerBundle; int activeLayer=-1; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index fce3ff5..43d0c31 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -56,6 +56,9 @@ void IntelliTool::createToolLayer(){ void IntelliTool::mergeToolLayer(){ QColor clr_0; QColor clr_1; + if(Area->renderSettings.getFastRenderer()){ + activeLayer->image->imageData.convertToFormat(QImage::Format_ARGB32); + } for(int y=0; yheight; y++) { for(int x=0; xwidth; x++) { clr_0=activeLayer->image->imageData.pixelColor(x,y); @@ -73,6 +76,9 @@ void IntelliTool::mergeToolLayer(){ activeLayer->image->imageData.setPixelColor(x, y, clr_0); } } + if(Area->renderSettings.getFastRenderer()){ + activeLayer->image->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliTool::deleteToolLayer(){ From 78272a57903034c23d667429e314ca138631e832 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 8 Jan 2020 19:40:35 +0100 Subject: [PATCH 2/3] now working 100% :D Fixed a bug where a not activatet tool caused trouble. --- src/Image/IntelliImage.cpp | 26 +++++++++++++++++------ src/IntelliHelper/IntelliRenderSettings.h | 2 +- src/Layer/PaintingArea.cpp | 24 +++++++++++++-------- src/Tool/IntelliTool.cpp | 4 ++-- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 5e5e62d..9c65bd5 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -41,7 +41,9 @@ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){ QPainter painter(&newImage); painter.drawImage(QPoint(0, 0), *image); *image = newImage; - updateRendererSetting(fastRenderer); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ @@ -56,7 +58,9 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); - updateRendererSetting(fastRenderer); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ @@ -70,7 +74,9 @@ void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& p painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); // Draw a line from the last registered point to the current painter.drawPoint(p1); - updateRendererSetting(fastRenderer); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ @@ -85,7 +91,9 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co // Draw a line from the last registered point to the current painter.drawLine(p1, p2); - updateRendererSetting(fastRenderer); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPlain(const QColor& color){ @@ -93,11 +101,17 @@ void IntelliImage::drawPlain(const QColor& color){ this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); } imageData.fill(color); - updateRendererSetting(fastRenderer); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } QColor IntelliImage::getPixelColor(QPoint& point){ - return imageData.pixelColor(point); + if(fastRenderer){ + QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32); + return copy.pixelColor(point); + } + return imageData.pixelColor(point); } void IntelliImage::updateRendererSetting(bool fastRendererOn){ diff --git a/src/IntelliHelper/IntelliRenderSettings.h b/src/IntelliHelper/IntelliRenderSettings.h index b7ee8a0..5763bb0 100644 --- a/src/IntelliHelper/IntelliRenderSettings.h +++ b/src/IntelliHelper/IntelliRenderSettings.h @@ -14,7 +14,7 @@ public: bool getFastRenderer(); private: - bool fastRenderer = false; + bool fastRenderer = true; }; #endif // INTELLIRENDERSETTINGS_H diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index f859001..e5a8a19 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -147,21 +147,25 @@ void PaintingArea::floodFill(int r, int g, int b, int a){ } void PaintingArea::movePositionActive(int x, int y){ - if(Tool->getIsDrawing()){ - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; + if(Tool!=nullptr){ + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } } layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; } void PaintingArea::moveActiveLayer(int idx){ - if(Tool->getIsDrawing()){ - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } + if(Tool!=nullptr){ + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } + } if(idx==1) { this->selectLayerUp(); }else if(idx==-1) { @@ -170,11 +174,13 @@ void PaintingArea::moveActiveLayer(int idx){ } void PaintingArea::slotActivateLayer(int a){ + if(Tool!=nullptr){ if(Tool->getIsDrawing()){ IntelliTool* temp = copyActiveTool(); delete this->Tool; this->Tool = temp; } + } if(a>=0 && a < static_cast(layerBundle.size())) { this->setLayerActive(a); } diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 43d0c31..88d2e07 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -57,7 +57,7 @@ void IntelliTool::mergeToolLayer(){ QColor clr_0; QColor clr_1; if(Area->renderSettings.getFastRenderer()){ - activeLayer->image->imageData.convertToFormat(QImage::Format_ARGB32); + activeLayer->image->imageData = activeLayer->image->imageData.convertToFormat(QImage::Format_ARGB32); } for(int y=0; yheight; y++) { for(int x=0; xwidth; x++) { @@ -77,7 +77,7 @@ void IntelliTool::mergeToolLayer(){ } } if(Area->renderSettings.getFastRenderer()){ - activeLayer->image->imageData.convertToFormat(QImage::Format_Indexed8); + activeLayer->image->imageData = activeLayer->image->imageData.convertToFormat(QImage::Format_Indexed8); } } From 7ed8e858afee28d6a7771f9b10da069b7be3646b Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 8 Jan 2020 19:56:56 +0100 Subject: [PATCH 3/3] Now everything is Indexe 8 :astonished: Job done. --- src/Image/IntelliImage.cpp | 8 +++++++- src/Layer/PaintingArea.cpp | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 9c65bd5..4c1b01d 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -4,7 +4,13 @@ IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ - imageData.fill(QColor(255,255,255,255)); + if(fastRendererOn){ + imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + imageData.fill(QColor(255,255,255,255)); + if(fastRendererOn){ + imageData = imageData.convertToFormat(QImage::Format_Indexed8); + } this->fastRenderer = fastRendererOn; } diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index e5a8a19..7388487 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -48,7 +48,8 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ //set standart parameter this->maxWidth = maxWidth; this->maxHeight = maxHeight; - Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); + if(renderSettings.getFastRenderer()) Canvas = new QImage(maxWidth,maxHeight, QImage::Format_Indexed8); + else Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); // Roots the widget to the top left even if resized setAttribute(Qt::WA_StaticContents); @@ -66,7 +67,10 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff }else if(type==IntelliImage::ImageType::Shaped_Image) { newLayer.image = new IntelliShapedImage(width, height, renderSettings.getFastRenderer()); } - newLayer.alpha = 255; + + newLayer.alpha = 255; + + this->layerBundle.push_back(newLayer); return static_cast(layerBundle.size())-1; } @@ -120,7 +124,7 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){ this->drawLayers(true); if(!strcmp(fileFormat,"PNG")) { - QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8); + QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8); fileFormat = "png"; if (visibleImage.save(filePath, fileFormat)) { return true; @@ -310,7 +314,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){ QPainter painter(this); QRect dirtyRec = event->rect(); - painter.drawImage(dirtyRec, *Canvas, dirtyRec); + painter.drawImage(dirtyRec, *Canvas, dirtyRec); update(); } @@ -341,15 +345,16 @@ void PaintingArea::selectLayerDown(){ void PaintingArea::drawLayers(bool forSaving){ if(forSaving) { - Canvas->fill(Qt::GlobalColor::transparent); + Canvas->fill(Qt::GlobalColor::transparent); }else{ - Canvas->fill(Qt::GlobalColor::black); + Canvas->fill(Qt::GlobalColor::black); } for(size_t i=0; igetDisplayable(layer.alpha); if(renderSettings.getFastRenderer()){ cpy = cpy.convertToFormat(QImage::Format_ARGB32); + *Canvas = Canvas->convertToFormat(QImage::Format_ARGB32); } QColor clr_0; QColor clr_1; @@ -359,7 +364,7 @@ void PaintingArea::drawLayers(bool forSaving){ for(int x=0; x=maxWidth) break; - clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y); + clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y); clr_1=cpy.pixelColor(x,y); float t = static_cast(clr_1.alpha())/255.f; int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); @@ -375,6 +380,9 @@ void PaintingArea::drawLayers(bool forSaving){ } } } + if(renderSettings.getFastRenderer()){ + *Canvas = Canvas->convertToFormat(QImage::Format_Indexed8); + } } void PaintingArea::createTempTopLayer(int idx){