Krita Source Code Documentation
Loading...
Searching...
No Matches
RecorderWriter::Private Class Reference

Public Member Functions

quint32 avg (quint32 c1, quint32 c2)
 
quint32 blendSourceOver (const int alpha, const quint32 source, const quint32 destination)
 
void captureImage (QRect area, KisPaintDevice *device)
 
void halfSizeImageBuffer ()
 
Private & operator= (const Private &)=default
 
Private & operator= (Private &&)=delete
 
 Private ()=delete
 
 Private (const Private &)=default
 
 Private (Private &&)=delete
 
 Private (QPointer< KisCanvas2 > c, const RecorderWriterSettings &s, const QDir &d)
 
void removeFrameTransparency ()
 
bool writeFrame ()
 

Public Attributes

QPointer< KisCanvas2 > canvas
 
QImage frame
 
int frameResolution = -1
 
QByteArray imageBuffer
 
int imageBufferHeight = 0
 
int imageBufferWidth = 0
 
const QDir * outputDir
 
int partIndex = 0
 
const RecorderWriterSettings * settings
 
const KoColorSpace * targetCs
 

Detailed Description

Definition at line 130 of file recorder_writer.cpp.

Constructor & Destructor Documentation

◆ Private() [1/4]

RecorderWriter::Private::Private ( QPointer< KisCanvas2 > c,
const RecorderWriterSettings & s,
const QDir & d )
inline

Definition at line 133 of file recorder_writer.cpp.

134 : canvas(c)
135 , settings(&s)
136 , outputDir(&d)
137 {}
QPointer< KisCanvas2 > canvas
const RecorderWriterSettings * settings
Private *const d

◆ Private() [2/4]

RecorderWriter::Private::Private ( )
delete

◆ Private() [3/4]

RecorderWriter::Private::Private ( const Private & )
default

◆ Private() [4/4]

RecorderWriter::Private::Private ( Private && )
delete

Member Function Documentation

◆ avg()

quint32 RecorderWriter::Private::avg ( quint32 c1,
quint32 c2 )
inline

Definition at line 208 of file recorder_writer.cpp.

209 {
210 return (((c1 ^ c2) & 0xfefefefeUL) >> 1) + (c1 & c2);
211 }

◆ blendSourceOver()

quint32 RecorderWriter::Private::blendSourceOver ( const int alpha,
const quint32 source,
const quint32 destination )
inline

Definition at line 236 of file recorder_writer.cpp.

237 {
238 // co = αs x Cs + αb x Cb x (1 – αs)
239 // αo = 1, αb = 1
240
241 const int inverseAlpha = 255 - alpha;
242 return qRgb(
243 (alpha * qRed(source) + inverseAlpha * qRed(destination)) >> 8,
244 (alpha * qGreen(source) + inverseAlpha * qGreen(destination)) >> 8,
245 (alpha * qBlue(source) + inverseAlpha * qBlue(destination)) >> 8
246 );
247 }
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)

References source().

◆ captureImage()

void RecorderWriter::Private::captureImage ( QRect area,
KisPaintDevice * device )
inline

Definition at line 159 of file recorder_writer.cpp.

160 {
161 const bool needSrgbConversion = [&]() {
163 || device->colorSpace()->colorModelId() != RGBAColorModelID) {
164 return true;
165 }
166 const bool hasPrimaries = device->colorSpace()->profile()->hasColorants();
168 if (hasPrimaries) {
169 const ColorPrimaries primaries = device->colorSpace()->profile()->getColorPrimaries();
170 if (gamma == TRC_IEC_61966_2_1 && primaries == PRIMARIES_ITU_R_BT_709_5) {
171 return false;
172 }
173 }
174 return true;
175 }();
176
177 if (targetCs && needSrgbConversion) {
178 device->convertTo(targetCs);
179 }
180
181 // truncate uneven image width/height making it even for subdivided size too
182 const quint32 bitmask = ~(0xFFFFFFFFu >> (31 - settings->resolution));
183 const quint32 width = area.width() & bitmask;
184 const quint32 height = area.height() & bitmask;
185 const int bufferSize = device->pixelSize() * width * height;
186
187 bool resize = imageBuffer.size() != bufferSize;
188 if (resize)
189 imageBuffer.resize(bufferSize);
190
191 if (resize || frameResolution != settings->resolution) {
192 const int divider = 1 << settings->resolution;
193 const int outWidth = width / divider;
194 const int outHeight = height / divider;
195 uchar *outData = reinterpret_cast<uchar *>(imageBuffer.data());
196
197 frame = QImage(outData, outWidth, outHeight, QImage::Format_ARGB32);
198 }
199
200 device->readBytes(reinterpret_cast<quint8 *>(imageBuffer.data()), area.x(), area.y(), width, height);
201
202 imageBufferWidth = width;
203 imageBufferHeight = height;
204 }
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
ColorPrimaries
The colorPrimaries enum Enum of colorants, follows ITU H.273 for values 0 to 255, and has extra known...
@ PRIMARIES_ITU_R_BT_709_5
TransferCharacteristics
The transferCharacteristics enum Enum of transfer characteristics, follows ITU H.273 for values 0 to ...
@ TRC_IEC_61966_2_1
quint32 pixelSize() 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 readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
const KoColorSpace * targetCs
virtual ColorPrimaries getColorPrimaries() const
getColorPrimaries
virtual bool hasColorants() const =0
virtual TransferCharacteristics getTransferCharacteristics() const
getTransferCharacteristics This function should be subclassed at some point so we can get the value f...

References KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), KisPaintDevice::colorSpace(), KisPaintDevice::convertTo(), frame, frameResolution, KoColorProfile::getColorPrimaries(), KoColorProfile::getTransferCharacteristics(), KoColorProfile::hasColorants(), imageBuffer, imageBufferHeight, imageBufferWidth, Integer8BitsColorDepthID, KisPaintDevice::pixelSize(), PRIMARIES_ITU_R_BT_709_5, KoColorSpace::profile(), KisPaintDevice::readBytes(), RecorderWriterSettings::resolution, RGBAColorModelID, settings, targetCs, and TRC_IEC_61966_2_1.

◆ halfSizeImageBuffer()

void RecorderWriter::Private::halfSizeImageBuffer ( )
inline

Definition at line 213 of file recorder_writer.cpp.

214 {
215 quint32 *buffer = reinterpret_cast<quint32 *>(imageBuffer.data());
216 quint32 *out = buffer;
217
218 for (int y = 0; y < imageBufferHeight; y += 2) {
219 const quint32 *in1 = buffer + y * imageBufferWidth;
220 const quint32 *in2 = in1 + imageBufferWidth;
221
222 for (int x = 0; x < imageBufferWidth; x += 2) {
223 *out = avg(
224 avg(in1[x], in1[x + 1]),
225 avg(in2[x], in2[x + 1])
226 );
227
228 ++out;
229 }
230 }
231
232 imageBufferWidth /= 2;
234 }
quint32 avg(quint32 c1, quint32 c2)

References avg(), imageBuffer, imageBufferHeight, and imageBufferWidth.

◆ operator=() [1/2]

Private & RecorderWriter::Private::operator= ( const Private & )
default

◆ operator=() [2/2]

Private & RecorderWriter::Private::operator= ( Private && )
delete

◆ removeFrameTransparency()

void RecorderWriter::Private::removeFrameTransparency ( )
inline

Definition at line 249 of file recorder_writer.cpp.

250 {
251 const quint32 background = 0xFFFFFFFF;
252 quint32 *buffer = reinterpret_cast<quint32 *>(imageBuffer.data());
253 const quint32 *end = buffer + imageBufferWidth * imageBufferHeight;
254 while (buffer != end) {
255 const int alpha = qAlpha(*buffer);
256 switch (alpha) {
257 case 0xFF: // fully opaque
258 break;
259 case 0x00: // fully transparent - just replace to background
260 *buffer = background;
261 break;
262 default: // partly transparent - do color blending
263 *buffer = blendSourceOver(alpha, *buffer, background);
264 break;
265 }
266 ++buffer;
267 }
268 }
quint32 blendSourceOver(const int alpha, const quint32 source, const quint32 destination)

References blendSourceOver(), imageBuffer, imageBufferHeight, and imageBufferWidth.

◆ writeFrame()

bool RecorderWriter::Private::writeFrame ( )
inline

Definition at line 270 of file recorder_writer.cpp.

271 {
272 if (!outputDir->exists() && !outputDir->mkpath(settings->outputDirectory))
273 return false;
274
275 const QString fileName = QString("%1").arg(partIndex, 7, 10, QLatin1Char('0'));
276 const QString &filePath = QString("%1%2.%3").arg(settings->outputDirectory,
277 fileName,
279
280 int factor = -1; // default value
281 switch (settings->format) {
283 factor = settings->quality; // 0...100
284 break;
286 factor = qBound(0, 100 - (settings->compression * 10), 100); // 0..10 -> 100..0
287 break;
288 }
289
290 bool result = frame.save(filePath, RecorderFormatInfo::fileFormat(settings->format).data(), factor);
291 if (!result) {
292 QFile(filePath).remove(); // remove corrupted frame
293 return false;
294 }
295
296 return true;
297 }
QLatin1String fileFormat(RecorderFormat format)
QLatin1String fileExtension(RecorderFormat format)

References RecorderWriterSettings::compression, RecorderFormatInfo::fileExtension(), RecorderFormatInfo::fileFormat(), RecorderWriterSettings::format, frame, JPEG, outputDir, RecorderWriterSettings::outputDirectory, partIndex, PNG, RecorderWriterSettings::quality, and settings.

Member Data Documentation

◆ canvas

QPointer<KisCanvas2> RecorderWriter::Private::canvas

Definition at line 144 of file recorder_writer.cpp.

◆ frame

QImage RecorderWriter::Private::frame

Definition at line 148 of file recorder_writer.cpp.

◆ frameResolution

int RecorderWriter::Private::frameResolution = -1

Definition at line 149 of file recorder_writer.cpp.

◆ imageBuffer

QByteArray RecorderWriter::Private::imageBuffer

Definition at line 145 of file recorder_writer.cpp.

◆ imageBufferHeight

int RecorderWriter::Private::imageBufferHeight = 0

Definition at line 147 of file recorder_writer.cpp.

◆ imageBufferWidth

int RecorderWriter::Private::imageBufferWidth = 0

Definition at line 146 of file recorder_writer.cpp.

◆ outputDir

const QDir* RecorderWriter::Private::outputDir

Definition at line 152 of file recorder_writer.cpp.

◆ partIndex

int RecorderWriter::Private::partIndex = 0

Definition at line 150 of file recorder_writer.cpp.

◆ settings

const RecorderWriterSettings* RecorderWriter::Private::settings

Definition at line 151 of file recorder_writer.cpp.

◆ targetCs

const KoColorSpace* RecorderWriter::Private::targetCs
Initial value:
=
QString id() const
Definition KoID.cpp:63
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorProfile * p709SRGBProfile() const

Definition at line 154 of file recorder_writer.cpp.


The documentation for this class was generated from the following file: