11#include <kpluginfactory.h>
48 res.resize(width * height * 4);
50 quint8 rgbe[4] = {0, 0, 0, 0};
52 quint8 *ptr =
reinterpret_cast<quint8 *
>(res.data());
53 while (it.nextPixel()) {
54 auto *src =
reinterpret_cast<const float *
>(it.rawDataConst());
55 auto *dst =
reinterpret_cast<quint8 *
>(ptr);
56 float vMax = std::max(src[2], std::max(src[0], src[1]));
60 rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
62 vMax = frexp(vMax, &exp) * 256.0f / vMax;
64 rgbe[0] =
static_cast<quint8
>(std::max(src[0], 0.0f) * vMax);
65 rgbe[1] =
static_cast<quint8
>(std::max(src[1], 0.0f) * vMax);
66 rgbe[2] =
static_cast<quint8
>(std::max(src[2], 0.0f) * vMax);
67 rgbe[3] =
static_cast<quint8
>(exp + 128);
70 std::memcpy(dst, rgbe, 4);
78inline void writeBytesRLE(QByteArray &rleBuffer, quint8 *data,
int nBytes)
80 static constexpr int minRunLen = 4;
89 while (cur < nBytes) {
92 runCount = oldRunCount = 0;
93 while ((runCount < minRunLen) && (begRun < nBytes)) {
95 oldRunCount = runCount;
97 while ((begRun + runCount < nBytes) && (runCount < 127) && (data[begRun] == data[begRun + runCount])) {
102 if ((oldRunCount > 1) && (oldRunCount == begRun - cur)) {
103 buf[0] = 128 + oldRunCount;
105 rleBuffer.append(
reinterpret_cast<const char *
>(buf),
sizeof(buf));
109 while (cur < begRun) {
110 nonRunCount = begRun - cur;
111 if (nonRunCount > 128) {
114 buf[0] = nonRunCount;
115 rleBuffer.append(buf[0]);
116 rleBuffer.append(
reinterpret_cast<const char *
>(data + cur),
sizeof(data[0]) * nonRunCount);
120 if (runCount >= minRunLen) {
121 buf[0] = 128 + runCount;
122 buf[1] = data[begRun];
123 rleBuffer.append(
reinterpret_cast<const char *
>(buf),
sizeof(buf));
153 const bool isLinearSrgb = [&]() {
167 dbgFile <<
"Image is not in linear sRGB, converting...";
175 KoColor bgColor(Qt::white, targetCs);
176 bgColor.
fromKoColor(cfg->getColor(
"transparencyFillcolor"));
188 QByteArray fileBuffer;
192 header.append(
"#?RADIANCE\n");
193 header.append(
"# Created with Krita RGBE Export\n");
194 header.append(
"FORMAT=32-bit_rle_rgbe\n\n");
195 header.append(QStringLiteral(
"-Y %1 +X %2\n").arg(image->
height()).arg(image->
width()).toUtf8());
197 fileBuffer.append(header);
202 const int scanWidth = image->
width();
203 const int scanHeight = image->
height();
205 if ((scanWidth < 8) || (scanWidth > 0x7fff)) {
207 fileBuffer.append(pixels);
208 io->write(fileBuffer);
211 QByteArray rleBuffer;
212 QByteArray outputBuffer;
214 int numScanline = scanHeight;
217 rleBuffer.resize(
sizeof(quint8) * 4 * scanWidth);
218 auto *src =
reinterpret_cast<const quint8 *
>(pixels.data());
219 auto *rle =
reinterpret_cast<quint8 *
>(rleBuffer.data());
221 while (numScanline-- > 0) {
224 rgbe[2] = scanWidth >> 8;
225 rgbe[3] = scanWidth & 0xFF;
226 outputBuffer.append(
reinterpret_cast<const char *
>(rgbe),
sizeof(rgbe));
228 for (
int i = 0; i < scanWidth; i++) {
230 rle[i + scanWidth] = src[1];
231 rle[i + 2 * scanWidth] = src[2];
232 rle[i + 3 * scanWidth] = src[3];
236 for (
int i = 0; i < 4; i++) {
238 fileBuffer.append(outputBuffer);
239 outputBuffer.clear();
243 io->write(fileBuffer);
275 v.setValue(background);
277 cfg->setProperty(
"transparencyFillcolor",
v);
282#include <RGBEExport.moc>
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/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 ...
static KisExportCheckRegistry * instance()
const KoColorSpace * colorSpace() const
void convertImageColorSpace(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
KisPaintDeviceSP projection() const
QRect bounds() const override
The base class for import and export filters.
void addSupportedColorModels(QList< QPair< KoID, KoID > > supportedColorModels, const QString &name, KisExportCheckBase::Level level=KisExportCheckBase::PARTIALLY)
void addCapability(KisExportCheckBase *capability)
void fill(const QRect &rc, const KoColor &color)
void bitBlt(qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
void fromKoColor(const KoColor &src)
void initializeCapabilities() override
KisConfigWidget * createConfigurationWidget(QWidget *parent, const QByteArray &from="", const QByteArray &to="") const override
createConfigurationWidget creates a widget that can be used to define the settings for a given import...
RGBEExport(QObject *parent, const QVariantList &)
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP cfg=nullptr) override
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray &from="", const QByteArray &to="") const override
defaultConfiguration defines the default settings for the given import export filter
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
void flattenImage(KisImageSP image, KisNodeSP activeNode, MergeFlags flags)
void writeBytesRLE(QByteArray &rleBuffer, quint8 *data, int nBytes)
QByteArray floatToRGBE(const int width, const int height, KisPaintDeviceSP &dev)
quint32 childCount() const
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...
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorProfile * p709G10Profile() const