8#ifndef __KIS_ASL_WRITER_UTILS_H
9#define __KIS_ASL_WRITER_UTILS_H
11#include "kritapsdutils_export.h"
32 :
std::runtime_error(msg.toLatin1().data())
39#define SAFE_WRITE_EX(byteOrder, device, varname) \
40 if (!psdwrite<byteOrder>(device, varname)) { \
41 QString msg = QString("Failed to write \'%1\' tag!").arg(#varname); \
42 throw KisAslWriterUtils::ASLWriteException(msg); \
48template<psd_
byte_order
byteOrder>
52 const qint32 rectY0 =
static_cast<qint32
>(
rect.y());
56 const qint32 rectX0 =
static_cast<qint32
>(
rect.x());
60 const qint32 rectY1 =
static_cast<qint32
>(
rect.y() +
rect.height());
64 const qint32 rectX1 =
static_cast<qint32
>(
rect.x() +
rect.width());
69template<psd_
byte_order
byteOrder>
72 const quint32 len =
static_cast<quint32
>(
value.length() + 1);
75 const quint16 *ptr =
value.utf16();
76 for (quint32 i = 0; i < len; i++) {
81template<psd_
byte_order
byteOrder>
84 const quint32 lenTag =
static_cast<quint32
>(
value.length() != 4 ?
value.length() : 0);
87 if (!device.write(
value.toLatin1().data(),
value.length())) {
93template<psd_
byte_order
byteOrder>
98 const quint8 lenTag =
static_cast<quint8
>(
value.length());
101 if (!device.write(
value.toLatin1().data(),
value.length())) {
107template<psd_
byte_order
byteOrder>
112 QByteArray data =
value.toLatin1();
115 std::reverse(data.begin(), data.end());
118 if (!device.write(data.data(),
value.length())) {
125template<psd_
byte_order
byteOrder = psd_
byte_order::psdBigEndian>
129 QString patternFileName = pattern->filename();
131 if (patternFileName.endsWith(
".pat", Qt::CaseInsensitive)) {
132 QString strUuid = patternFileName.left(patternFileName.size() - 4);
134 uuid = QUuid(strUuid);
138 warnKrita <<
"WARNING: Saved pattern doesn't have a UUID, generating...";
140 uuid = QUuid::createUuid();
143 return uuid.toString().mid(1, 36);
155 qint64 mask = alignment - 1;
156 return (pos + mask) & ~mask;
159template<
class OffsetType, psd_
byte_order
byteOrder>
170 if (externalSizeTagOffset < 0) {
171 const OffsetType fakeObjectSize = OffsetType(0xdeadbeef);
183 for (; currentPos < alignedPos; currentPos++) {
189 const qint64 currentPos =
m_device.pos();
191 qint64 writtenDataSize = 0;
192 qint64 sizeFiledOffset = 0;
203 const OffsetType realObjectSize = writtenDataSize;
float value(const T *src, size_t ch)
qint64 m_externalSizeTagOffset
OffsetStreamPusher(QIODevice &device, qint64 alignOnExit=0, qint64 externalSizeTagOffset=-1)
#define SAFE_WRITE_EX(byteOrder, device, varname)
#define KIS_ASSERT_RECOVER_RETURN(cond)
#define PREPEND_METHOD(msg)
void writeVarString(const QString &value, QIODevice &device)
void writePascalString(const QString &value, QIODevice &device)
void writeFixedString(const QString &value, QIODevice &device)
void writeUnicodeString(const QString &value, QIODevice &device)
void writeRect(const QRect &rect, QIODevice &device)
QString getPatternUuidLazy(const KoPatternSP pattern)
qint64 alignOffsetCeil(qint64 pos, qint64 alignment)
ASLWriteException(const QString &msg)