File indexing completed on 2024-05-12 04:19:40

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0018 
0019 */
0020 
0021 #ifndef RASTERIMAGEITEM_H
0022 #define RASTERIMAGEITEM_H
0023 
0024 #include <QGraphicsItem>
0025 
0026 #include "lib/renderingintent.h"
0027 
0028 namespace Gwenview
0029 {
0030 class RasterImageView;
0031 
0032 /**
0033  * A QGraphicsItem subclass responsible for rendering the main raster image.
0034  *
0035  * This class is resposible for painting the main image when it is a raster
0036  * image. It will get the visible area from the main image, translate and scale
0037  * this based on the values from the parent ImageView, then apply color
0038  * correction. Finally the result will be drawn to the screen.
0039  *
0040  * For performance, two extra images are cached, one at a third of the image
0041  * size and one at a sixth. These are used at low zoom levels, to avoid having
0042  * to copy large amounts of image data that later gets discarded.
0043  */
0044 class RasterImageItem : public QGraphicsItem
0045 {
0046 public:
0047     RasterImageItem(RasterImageView *parent);
0048     ~RasterImageItem() override;
0049 
0050     /**
0051      * Set the rendering intent for color correction.
0052      */
0053     void setRenderingIntent(RenderingIntent::Enum intent);
0054 
0055     /**
0056      * Update the internal, smaller cached versions of the main image.
0057      */
0058     void updateCache();
0059 
0060     /**
0061      * Reimplemented from QGraphicsItem::paint
0062      */
0063     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0064 
0065     /**
0066      * Reimplemented from QGraphicsItem::boundingRect
0067      */
0068     virtual QRectF boundingRect() const override;
0069 
0070 private:
0071     void applyDisplayTransform(QImage &image);
0072     void updateDisplayTransform(QImage::Format format);
0073 
0074     RasterImageView *mParentView;
0075     bool mApplyDisplayTransform = true;
0076     cmsHTRANSFORM mDisplayTransform = nullptr;
0077     cmsUInt32Number mRenderingIntent = INTENT_PERCEPTUAL;
0078 
0079     QImage mOriginalImage;
0080     QImage mThirdScaledImage;
0081     QImage mSixthScaledImage;
0082 };
0083 
0084 }
0085 
0086 #endif // RASTERIMAGEITEM_H