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 (KisPaintDeviceSP 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 ()
 
int writeFrame (int index)
 

Public Attributes

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

Detailed Description

Definition at line 117 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 120 of file recorder_writer.cpp.

121 : canvas(c)
122 , settings(&s)
123 , outputDir(&d)
124 {}
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 198 of file recorder_writer.cpp.

199 {
200 return (((c1 ^ c2) & 0xfefefefeUL) >> 1) + (c1 & c2);
201 }

◆ blendSourceOver()

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

Definition at line 226 of file recorder_writer.cpp.

227 {
228 // co = αs x Cs + αb x Cb x (1 – αs)
229 // αo = 1, αb = 1
230
231 const int inverseAlpha = 255 - alpha;
232 return qRgb(
233 (alpha * qRed(source) + inverseAlpha * qRed(destination)) >> 8,
234 (alpha * qGreen(source) + inverseAlpha * qGreen(destination)) >> 8,
235 (alpha * qBlue(source) + inverseAlpha * qBlue(destination)) >> 8
236 );
237 }
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)

References source().

◆ captureImage()

void RecorderWriter::Private::captureImage ( KisPaintDeviceSP device)
inline

Definition at line 147 of file recorder_writer.cpp.

148 {
149 KisImageSP image = canvas->image();
150
151 const bool needSrgbConversion = [&]() {
153 || image->colorSpace()->colorModelId() != RGBAColorModelID) {
154 return true;
155 }
156 const bool hasPrimaries = image->colorSpace()->profile()->hasColorants();
158 if (hasPrimaries) {
159 const ColorPrimaries primaries = image->colorSpace()->profile()->getColorPrimaries();
160 if (gamma == TRC_IEC_61966_2_1 && primaries == PRIMARIES_ITU_R_BT_709_5) {
161 return false;
162 }
163 }
164 return true;
165 }();
166
167 if (targetCs && needSrgbConversion) {
168 device->convertTo(targetCs);
169 }
170
171 // truncate uneven image width/height making it even for subdivided size too
172 const quint32 bitmask = ~(0xFFFFFFFFu >> (31 - settings->resolution));
173 const quint32 width = image->width() & bitmask;
174 const quint32 height = image->height() & bitmask;
175 const int bufferSize = device->pixelSize() * width * height;
176
177 bool resize = imageBuffer.size() != bufferSize;
178 if (resize)
179 imageBuffer.resize(bufferSize);
180
181 if (resize || frameResolution != settings->resolution) {
182 const int divider = 1 << settings->resolution;
183 const int outWidth = width / divider;
184 const int outHeight = height / divider;
185 uchar *outData = reinterpret_cast<uchar *>(imageBuffer.data());
186
187 frame = QImage(outData, outWidth, outHeight, QImage::Format_ARGB32);
188 }
189
190 device->readBytes(reinterpret_cast<quint8 *>(imageBuffer.data()), 0, 0, width, height);
191
192 imageBufferWidth = width;
193 imageBufferHeight = height;
194 }
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
const KoColorSpace * colorSpace() const
qint32 width() const
qint32 height() const
quint32 pixelSize() 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 canvas, KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), KisImage::colorSpace(), KisPaintDevice::convertTo(), frame, frameResolution, KoColorProfile::getColorPrimaries(), KoColorProfile::getTransferCharacteristics(), KoColorProfile::hasColorants(), KisImage::height(), imageBuffer, imageBufferHeight, imageBufferWidth, Integer8BitsColorDepthID, KisPaintDevice::pixelSize(), PRIMARIES_ITU_R_BT_709_5, KoColorSpace::profile(), KisPaintDevice::readBytes(), RecorderWriterSettings::resolution, RGBAColorModelID, settings, targetCs, TRC_IEC_61966_2_1, and KisImage::width().

◆ halfSizeImageBuffer()

void RecorderWriter::Private::halfSizeImageBuffer ( )
inline

Definition at line 203 of file recorder_writer.cpp.

204 {
205 quint32 *buffer = reinterpret_cast<quint32 *>(imageBuffer.data());
206 quint32 *out = buffer;
207
208 for (int y = 0; y < imageBufferHeight; y += 2) {
209 const quint32 *in1 = buffer + y * imageBufferWidth;
210 const quint32 *in2 = in1 + imageBufferWidth;
211
212 for (int x = 0; x < imageBufferWidth; x += 2) {
213 *out = avg(
214 avg(in1[x], in1[x + 1]),
215 avg(in2[x], in2[x + 1])
216 );
217
218 ++out;
219 }
220 }
221
222 imageBufferWidth /= 2;
224 }
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 239 of file recorder_writer.cpp.

240 {
241 const quint32 background = 0xFFFFFFFF;
242 quint32 *buffer = reinterpret_cast<quint32 *>(imageBuffer.data());
243 const quint32 *end = buffer + imageBufferWidth * imageBufferHeight;
244 while (buffer != end) {
245 const int alpha = qAlpha(*buffer);
246 switch (alpha) {
247 case 0xFF: // fully opaque
248 break;
249 case 0x00: // fully transparent - just replace to background
250 *buffer = background;
251 break;
252 default: // partly transparent - do color blending
253 *buffer = blendSourceOver(alpha, *buffer, background);
254 break;
255 }
256 ++buffer;
257 }
258 }
quint32 blendSourceOver(const int alpha, const quint32 source, const quint32 destination)

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

◆ writeFrame()

int RecorderWriter::Private::writeFrame ( int index)
inline

Definition at line 260 of file recorder_writer.cpp.

261 {
262 if (!outputDir->exists() && !outputDir->mkpath(settings->outputDirectory))
263 return false;
264
265 const QString fileName = QString("%1").arg(index, 7, 10, QLatin1Char('0'));
266 const QString &filePath = QString("%1%2.%3").arg(settings->outputDirectory, fileName,
268
269 int factor = -1; // default value
270 switch (settings->format) {
272 factor = settings->quality; // 0...100
273 break;
275 factor = qBound(0, 100 - (settings->compression * 10), 100); // 0..10 -> 100..0
276 break;
277 }
278
279 bool result = frame.save(filePath, RecorderFormatInfo::fileFormat(settings->format).data(), factor);
280 if (!result)
281 QFile(filePath).remove(); // remove corrupted frame
282 return result;
283 }
QLatin1String fileFormat(RecorderFormat format)
QLatin1String fileExtension(RecorderFormat format)

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

Member Data Documentation

◆ canvas

QPointer<KisCanvas2> RecorderWriter::Private::canvas

Definition at line 131 of file recorder_writer.cpp.

◆ frame

QImage RecorderWriter::Private::frame

Definition at line 135 of file recorder_writer.cpp.

◆ frameResolution

int RecorderWriter::Private::frameResolution = -1

Definition at line 136 of file recorder_writer.cpp.

◆ imageBuffer

QByteArray RecorderWriter::Private::imageBuffer

Definition at line 132 of file recorder_writer.cpp.

◆ imageBufferHeight

int RecorderWriter::Private::imageBufferHeight = 0

Definition at line 134 of file recorder_writer.cpp.

◆ imageBufferWidth

int RecorderWriter::Private::imageBufferWidth = 0

Definition at line 133 of file recorder_writer.cpp.

◆ isActive

bool RecorderWriter::Private::isActive = false

Definition at line 138 of file recorder_writer.cpp.

◆ outputDir

const QDir* RecorderWriter::Private::outputDir

Definition at line 140 of file recorder_writer.cpp.

◆ partIndex

int RecorderWriter::Private::partIndex = 0

Definition at line 137 of file recorder_writer.cpp.

◆ settings

const RecorderWriterSettings* RecorderWriter::Private::settings

Definition at line 139 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 142 of file recorder_writer.cpp.


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