From 67b623a63adcbbee53b0d27239acb28adeab5fda Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Thu, 9 Jan 2020 10:35:01 +0100 Subject: [PATCH] bring the fastrenderer back again... hihihi --- src/Image/IntelliImage.cpp | 65 ++++++++++++++++++++++++++------ src/Image/IntelliImage.h | 23 +++++++++-- src/Image/IntelliRasterImage.cpp | 13 +++++-- src/Image/IntelliRasterImage.h | 3 +- src/Image/IntelliShapedImage.cpp | 29 +++++++++++--- src/Image/IntelliShapedImage.h | 3 +- src/Layer/PaintingArea.cpp | 14 ++++--- 7 files changed, 119 insertions(+), 31 deletions(-) diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 48deb91..ef14700 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -2,9 +2,16 @@ #include #include -IntelliImage::IntelliImage(int weight, int height) - : imageData(QSize(weight, height), QImage::Format_ARGB32){ - imageData.fill(QColor(255,255,255,255)); +IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) + : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ + 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; } @@ -23,7 +30,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 +40,23 @@ 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; + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } 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 +64,32 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } 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); + 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){ - // 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,16 +97,34 @@ 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); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPlain(const QColor& color){ - imageData.fill(color); + if(fastRenderer){ + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + imageData.fill(color); + 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); } QImage IntelliImage::getImageData(){ - return imageData; + return this->imageData; +} + +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 06edc4b..ff7608d 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -8,8 +8,8 @@ #include #include -#include "IntelliHelper/IntelliRenderSettings.h" #include "IntelliHelper/IntelliTriangulation.h" +#include "IntelliHelper/IntelliRenderSettings.h" class IntelliTool; @@ -40,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. @@ -142,7 +149,17 @@ virtual bool loadImage(const QString &filePath); */ virtual QColor getPixelColor(QPoint& point); -QImage getImageData(); +/*! + * \brief updateRendererSetting updates the existing image format to the new format. + * \param fastRendererOn flag for the 8bit image handeling. + */ +virtual void updateRendererSetting(bool fastRendererOn); + +/*! + * \brief getImageData returns the data of the current image. + */ +virtual QImage getImageData(); + }; #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; @@ -42,7 +50,7 @@ void IntelliShapedImage::calculateVisiblity(){ for(int x=0; ximageData = 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; y& polygonData){ for(auto element:polygonData) { this->polygonData.push_back(QPoint(element.x(), element.y())); } - triangles = IntelliTriangulation::calculateTriangles(polygonData); + triangles = IntelliTriangulation::calculateTriangles(polygonData); } calculateVisiblity(); return; diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 0140aa8..220ad75 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -30,8 +30,9 @@ public: * \brief The Construcor of the IntelliShapedImage. 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. */ -IntelliShapedImage(int width, int height); +IntelliShapedImage(int width, int height, bool fastRendererOn); /*! * \brief An Destructor. diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 0550c0d..5e47d00 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -60,9 +60,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); @@ -158,10 +158,12 @@ void PaintingArea::movePositionActive(int x, int 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();