Krita Source Code Documentation
Loading...
Searching...
No Matches
KisContentLightLevelProcessingVistor.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7#include <kis_hdr_metadata.h>
8#include <KoColorProfile.h>
10#include "kis_group_layer.h"
12
13
19
26
31
33{
34 Q_UNUSED(undoAdapter)
35
36 KisPaintDeviceSP projection = layer->projection();
37 KisPaintDeviceSP dev = new KisPaintDevice(layer->colorSpace());
38 dev->makeCloneFrom(projection, projection->extent());
39 d->clli.append(calculateForDev(dev));
40}
41
43{
45 double total = 0.0;
46 Q_FOREACH(const KisRelativeContentLightLevelInformation c, d->clli) {
49 }
50 clli.maxFrameAverageLightLevel = d->clli.isEmpty()? 0.0: total / d->clli.size();
51 clli.type = d->type;
52 return clli;
53}
54
56{
58 double average = 0.0;
59 int divider = 0;
60 const QRect imageBounds = d->cropRect.isValid()? d->cropRect: dev->exactBounds();
61
62 bool canConvertLinear = dev->colorSpace()->colorModelId() == RGBAColorModelID && dev->colorSpace()->profile()->getColorPrimaries() != PRIMARIES_UNSPECIFIED;
63
64 if ((d->type == KisRelativeContentLightLevelInformation::RGBComponent && canConvertLinear)
71 } else {
75 linP);
77 }
78 KisSequentialConstIterator srcIt(dev, imageBounds);
79
80 QVector<float> channels(dev->colorSpace()->channelCount());
81 while(srcIt.nextPixel()) {
82 const quint8* pixel = srcIt.rawDataConst();
83 dev->colorSpace()->normalisedChannelsValue(pixel, channels);
84
85 const double rgbMax = qMax(channels[0], qMax(channels[1], channels[2]));
86
87 average += rgbMax;
88 divider ++;
89 clli.maxContentLightLevel = qMax(clli.maxContentLightLevel, rgbMax);
90 }
91 } else {
100
101 KisSequentialConstIterator srcIt(dev, imageBounds);
102
103 while (srcIt.nextPixel()) {
104 const KoXyzF32Traits::Pixel* pixel = reinterpret_cast<const KoXyzF32Traits::Pixel*> (srcIt.rawDataConst());
105 clli.maxContentLightLevel = qMax(clli.maxContentLightLevel, double(pixel->y));
106 average += pixel->y;
107 divider ++;
108 }
109 }
110
111 clli.maxFrameAverageLightLevel = divider > 0? average / divider: 0;
112 return clli;
113}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID XYZAColorModelID("XYZA", ki18n("XYZ/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
@ PRIMARIES_UNSPECIFIED
void visit(KisGroupLayer *layer, KisUndoAdapter *undoAdapter) override
KisRelativeContentLightLevelInformation calculateForDev(KisPaintDeviceSP dev)
KisContentLightLevelProcessingVistor(KisRelativeContentLightLevelInformation::CalculationType type=KisRelativeContentLightLevelInformation::XYZLuminance, const QRect &cropRect=QRect())
KisRelativeContentLightLevelInformation contentLightLevelInformation() const
QRect exactBounds() const
QRect extent() const
const KoColorSpace * colorSpace() const
void convertTo(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags(), KUndo2Command *parentCommand=nullptr, KoUpdater *progressUpdater=nullptr)
void makeCloneFrom(KisPaintDeviceSP src, const QRect &rect)
ALWAYS_INLINE const quint8 * rawDataConst() const
virtual KoID colorModelId() const =0
virtual quint32 channelCount() const =0
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
virtual const KoColorProfile * profile() const =0
QString id() const
Definition KoID.cpp:63
KisRelativeContentLightLevelInformation::CalculationType type
QList< KisRelativeContentLightLevelInformation > clli
const KoColorSpace * colorSpace() const override
KisPaintDeviceSP projection() const override
Definition kis_layer.cc:826
@ Rec2020Component
Calculate luminance by converting to rec2020.
@ RGBComponent
Calculate luminance on the RGB components if possible.
double maxFrameAverageLightLevel
maxFrameAverage MaxFrameAverageLightLevel or MaxFALL is the average of average pixel brightnesses in ...
The KoColorProfileQuery struct.
virtual ColorPrimaries getColorPrimaries() const
getColorPrimaries
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorProfile * profileFor(const KoColorProfileQuery &query, const bool generate=true) const
profileFor tries to find the profile that matches these characteristics, if no such profile is found,...
const KoColorProfile * p2020G10Profile() const