Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_asl_patterns_writer.cpp File Reference
#include "kis_asl_patterns_writer.h"
#include <functional>
#include <compression.h>
#include <kis_debug.h>
#include <resources/KoPattern.h>
#include "kis_asl_callback_object_catcher.h"
#include "kis_asl_writer_utils.h"
#include "kis_asl_xml_parser.h"

Go to the source code of this file.

Functions

void sliceQImage (const QImage &image, QVector< QVector< QByteArray > > *dstPlanes, bool *isCompressed)
 

Function Documentation

◆ sliceQImage()

void sliceQImage ( const QImage & image,
QVector< QVector< QByteArray > > * dstPlanes,
bool * isCompressed )

Definition at line 38 of file kis_asl_patterns_writer.cpp.

39{
40 KIS_ASSERT_RECOVER_NOOP(image.format() == QImage::Format_ARGB32);
41
42 QVector<QVector<QByteArray>> uncompressedRows;
43 QVector<QVector<QByteArray>> compressedRows;
44
45 uncompressedRows.resize(3);
46 compressedRows.resize(3);
47
48 int compressedSize = 0;
49
50 for (int i = 0; i < 3; i++) {
51 const int srcRowOffset = 2 - i;
52 const int srcStep = 4;
53 const int dstStep = 1;
54
55 for (int row = 0; row < image.height(); row++) {
56 uncompressedRows[i].append(QByteArray(image.width(), '\0'));
57 quint8 *dstPtr = (quint8 *)uncompressedRows[i].last().data();
58
59 const quint8 *srcPtr = image.constScanLine(row) + srcRowOffset;
60
61 for (int col = 0; col < image.width(); col++) {
62 *dstPtr = *srcPtr;
63
64 srcPtr += srcStep;
65 dstPtr += dstStep;
66 }
67
68 compressedRows[i].append(Compression::compress(uncompressedRows[i].last(), psd_compression_type::RLE));
69 if (compressedRows[i].last().isEmpty()) {
70 throw KisAslWriterUtils::ASLWriteException("Failed to compress pattern plane");
71 }
72
73 compressedSize += compressedRows[i].last().size() + 2; // two bytes for offset tag
74 }
75 }
76
77 if (compressedSize < image.width() * image.height() * 3) {
78 *dstPlanes = compressedRows;
79 *isCompressed = true;
80 } else {
81 *dstPlanes = uncompressedRows;
82 *isCompressed = false;
83 }
84}
static QByteArray compress(QByteArray bytes, psd_compression_type compressionType, int row_size=0, int color_depth=0)
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97
@ RLE
Definition psd.h:41

References Compression::compress(), KIS_ASSERT_RECOVER_NOOP, and RLE.