Krita Source Code Documentation
Loading...
Searching...
No Matches
RGBEExport Class Reference

#include <RGBEExport.h>

+ Inheritance diagram for RGBEExport:

Public Member Functions

KisImportExportErrorCode convert (KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP cfg=nullptr) override
 
KisConfigWidgetcreateConfigurationWidget (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/export filter
 
KisPropertiesConfigurationSP defaultConfiguration (const QByteArray &from="", const QByteArray &to="") const override
 defaultConfiguration defines the default settings for the given import export filter
 
void initializeCapabilities () override
 
 RGBEExport (QObject *parent, const QVariantList &)
 
 ~RGBEExport () override=default
 
- Public Member Functions inherited from KisImportExportFilter
virtual QMap< QString, KisExportCheckBase * > exportChecks ()
 generate and return the list of capabilities of this export filter. The list
 
virtual bool exportSupportsGuides () const
 exportSupportsGuides Because guides are in the document and not the image, checking for guides cannot be made an exportCheck.
 
KisPropertiesConfigurationSP lastSavedConfiguration (const QByteArray &from="", const QByteArray &to="") const
 lastSavedConfiguration return the last saved configuration for this filter
 
 Private ()
 
void setBatchMode (bool batchmode)
 
void setFilename (const QString &filename)
 
void setImportUserFeedBackInterface (KisImportUserFeedbackInterface *interface)
 
void setMimeType (const QString &mime)
 
void setRealFilename (const QString &filename)
 
void setUpdater (QPointer< KoUpdater > updater)
 
virtual bool supportsIO () const
 Override and return false for the filters that use a library that cannot handle file handles, only file names.
 
QPointer< KoUpdaterupdater ()
 
virtual QString verify (const QString &fileName) const
 Verify whether the given file is correct and readable.
 
 ~KisImportExportFilter () override
 
 ~Private ()
 

Additional Inherited Members

- Public Attributes inherited from KisImportExportFilter
bool batchmode
 
QMap< QString, KisExportCheckBase * > capabilities
 
QString filename
 
KisImportUserFeedbackInterfaceimportUserFeedBackInterface {nullptr}
 
QByteArray mime
 
QString realFilename
 
QPointer< KoUpdaterupdater
 
- Static Public Attributes inherited from KisImportExportFilter
static const QString CICPPrimariesTag = "CICPCompatiblePrimaries"
 
static const QString CICPTransferCharacteristicsTag = "CICPCompatibleTransferFunction"
 
static const QString ColorDepthIDTag = "ColorDepthID"
 
static const QString ColorModelIDTag = "ColorModelID"
 
static const QString HDRTag = "HDRSupported"
 
static const QString ImageContainsTransparencyTag = "ImageContainsTransparency"
 
static const QString sRGBTag = "sRGB"
 
- Protected Member Functions inherited from KisImportExportFilter
void addCapability (KisExportCheckBase *capability)
 
void addSupportedColorModels (QList< QPair< KoID, KoID > > supportedColorModels, const QString &name, KisExportCheckBase::Level level=KisExportCheckBase::PARTIALLY)
 
bool batchMode () const
 
QString filename () const
 
KisImportUserFeedbackInterfaceimportUserFeedBackInterface () const
 
 KisImportExportFilter (QObject *parent=0)
 
QByteArray mimeType () const
 
QString realFilename () const
 
void setProgress (int value)
 
QString verifyZiPBasedFiles (const QString &fileName, const QStringList &filesToCheck) const
 

Detailed Description

Definition at line 12 of file RGBEExport.h.

Constructor & Destructor Documentation

◆ RGBEExport()

RGBEExport::RGBEExport ( QObject * parent,
const QVariantList &  )

Definition at line 130 of file RGBEExport.cpp.

132{
133}
The base class for import and export filters.
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

◆ ~RGBEExport()

RGBEExport::~RGBEExport ( )
overridedefault

Member Function Documentation

◆ convert()

KisImportExportErrorCode RGBEExport::convert ( KisDocument * document,
QIODevice * io,
KisPropertiesConfigurationSP configuration = nullptr )
overridevirtual

The filter chain calls this method to perform the actual conversion. The passed mimetypes should be a pair of those you specified in your .desktop file. You have to implement this method to make the filter work.

Returns
The error status, see the #ConversionStatus enum. KisImportExportFilter::OK means that everything is alright.

Implements KisImportExportFilter.

Definition at line 135 of file RGBEExport.cpp.

136{
138
139 KisImageSP image = document->savingImage();
140 const QRect bounds = image->bounds();
141
142 const KoColorSpace *cs = image->colorSpace();
146 targetProfile);
147
148 if (image->root()->childCount() > 1) {
149 KisLayerUtils::flattenImage(image, nullptr);
150 image->waitForDone();
151 }
152
153 const bool isLinearSrgb = [&]() {
154 const bool hasPrimaries = cs->profile()->hasColorants();
156 if (hasPrimaries) {
157 const ColorPrimaries primaries = cs->profile()->getColorPrimaries();
158 if (gamma == TRC_LINEAR && primaries == PRIMARIES_ITU_R_BT_709_5) {
159 return true;
160 }
161 }
162 return false;
163 }();
164
165 // Color profile will be lost on RGBE export; so convert it to F32, linear sRGB
166 if (cs->colorModelId() != RGBAColorModelID || cs->colorDepthId() != Float32BitsColorDepthID || !isLinearSrgb) {
167 dbgFile << "Image is not in linear sRGB, converting...";
168 image->convertImageColorSpace(targetCs,
171 image->waitForDone();
172 }
173
174 // Fill transparent pixels with full opacity
175 KoColor bgColor(Qt::white, targetCs);
176 bgColor.fromKoColor(cfg->getColor("transparencyFillcolor"));
177
178 KisPaintDeviceSP dev = new KisPaintDevice(targetCs);
179 KisPainter gc(dev);
180
181 dev->fill(QRect(0, 0, image->width(), image->height()), bgColor);
182 gc.bitBlt(QPoint(0, 0), image->projection(), QRect(0, 0, image->width(), image->height()));
183 gc.end();
184
185 // Get pixel data and convert it to RGBE format
186 const QByteArray pixels = RGBE::floatToRGBE(bounds.width(), bounds.height(), dev);
187
188 QByteArray fileBuffer;
189 {
190 // Write header
191 QByteArray header;
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());
196
197 fileBuffer.append(header);
198 }
199
200 {
201 // Write pixel data
202 const int scanWidth = image->width();
203 const int scanHeight = image->height();
204
205 if ((scanWidth < 8) || (scanWidth > 0x7fff)) {
206 // Invalid width, save without RLE
207 fileBuffer.append(pixels);
208 io->write(fileBuffer);
209 } else {
210 // Save with RLE
211 QByteArray rleBuffer;
212 QByteArray outputBuffer;
213
214 int numScanline = scanHeight;
215 quint8 rgbe[4];
216
217 rleBuffer.resize(sizeof(quint8) * 4 * scanWidth);
218 auto *src = reinterpret_cast<const quint8 *>(pixels.data());
219 auto *rle = reinterpret_cast<quint8 *>(rleBuffer.data());
220
221 while (numScanline-- > 0) {
222 rgbe[0] = 2;
223 rgbe[1] = 2;
224 rgbe[2] = scanWidth >> 8;
225 rgbe[3] = scanWidth & 0xFF;
226 outputBuffer.append(reinterpret_cast<const char *>(rgbe), sizeof(rgbe));
227
228 for (int i = 0; i < scanWidth; i++) {
229 rle[i] = src[0];
230 rle[i + scanWidth] = src[1];
231 rle[i + 2 * scanWidth] = src[2];
232 rle[i + 3 * scanWidth] = src[3];
233 src += 4;
234 }
235
236 for (int i = 0; i < 4; i++) {
237 RGBE::writeBytesRLE(outputBuffer, &rle[i * scanWidth], scanWidth);
238 fileBuffer.append(outputBuffer);
239 outputBuffer.clear();
240 }
241 }
242
243 io->write(fileBuffer);
244 }
245 }
246
248}
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 ...
void waitForDone()
const KoColorSpace * colorSpace() const
void convertImageColorSpace(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
KisPaintDeviceSP projection() const
qint32 width() const
qint32 height() const
QRect bounds() const override
void fill(const QRect &rc, const KoColor &color)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
QString id() const
Definition KoID.cpp:63
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define bounds(x, a, b)
#define dbgFile
Definition kis_debug.h:53
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
Definition kis_node.cpp:414
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

References KisPainter::bitBlt(), KisImage::bounds(), bounds, KisNode::childCount(), KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), KisImage::colorSpace(), KoColorSpaceRegistry::colorSpace(), KisImage::convertImageColorSpace(), dbgFile, KisPainter::end(), KisPaintDevice::fill(), KisLayerUtils::flattenImage(), Float32BitsColorDepthID, RGBE::floatToRGBE(), KoColor::fromKoColor(), KoColorProfile::getColorPrimaries(), KoColorProfile::getTransferCharacteristics(), KoColorProfile::hasColorants(), KisImage::height(), KoID::id(), KoColorSpaceRegistry::instance(), KoColorConversionTransformation::internalConversionFlags(), KoColorConversionTransformation::internalRenderingIntent(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, ImportExportCodes::NoAccessToWrite, ImportExportCodes::OK, KoColorSpaceRegistry::p709G10Profile(), PRIMARIES_ITU_R_BT_709_5, KoColorSpace::profile(), KisImage::projection(), RGBAColorModelID, KisNodeFacade::root, TRC_LINEAR, KisImage::waitForDone(), KisImage::width(), and RGBE::writeBytesRLE().

◆ createConfigurationWidget()

KisConfigWidget * RGBEExport::createConfigurationWidget ( QWidget * parent,
const QByteArray & from = "",
const QByteArray & to = "" ) const
overridevirtual

createConfigurationWidget creates a widget that can be used to define the settings for a given import/export filter

Parameters
parentthe owner of the widget; the caller is responsible for deleting
fromThe mimetype of the source file/document
toThe mimetype of the destination file/document
Returns
the widget

Reimplemented from KisImportExportFilter.

Definition at line 263 of file RGBEExport.cpp.

264{
265 return new KisWdgOptionsRGBE(parent);
266}

◆ defaultConfiguration()

KisPropertiesConfigurationSP RGBEExport::defaultConfiguration ( const QByteArray & from = "",
const QByteArray & to = "" ) const
overridevirtual

defaultConfiguration defines the default settings for the given import export filter

Parameters
fromThe mimetype of the source file/document
toThe mimetype of the destination file/document
Returns
a serializable KisPropertiesConfiguration object

Reimplemented from KisImportExportFilter.

Definition at line 268 of file RGBEExport.cpp.

269{
271
272 KoColor background(KoColorSpaceRegistry::instance()->rgb8());
273 background.fromQColor(Qt::white);
274 QVariant v;
275 v.setValue(background);
276
277 cfg->setProperty("transparencyFillcolor", v);
278
279 return cfg;
280}
qreal v

References KoColor::fromQColor(), KoColorSpaceRegistry::instance(), and v.

◆ initializeCapabilities()

void RGBEExport::initializeCapabilities ( )
overridevirtual

Reimplemented from KisImportExportFilter.

Definition at line 250 of file RGBEExport.cpp.

251{
252 QList<QPair<KoID, KoID>> supportedColorModels;
258 supportedColorModels << QPair<KoID, KoID>() << QPair<KoID, KoID>(RGBAColorModelID, Float32BitsColorDepthID);
259 addSupportedColorModels(supportedColorModels, "RGBE");
260}
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
static KisExportCheckRegistry * instance()
void addSupportedColorModels(QList< QPair< KoID, KoID > > supportedColorModels, const QString &name, KisExportCheckBase::Level level=KisExportCheckBase::PARTIALLY)
void addCapability(KisExportCheckBase *capability)
QPainterPath create(const char32_t codepoint, double height)
Creates a tofu missing glyph indicator representing the provided Unicode codepoint.

References KisImportExportFilter::addCapability(), KisImportExportFilter::addSupportedColorModels(), Float32BitsColorDepthID, get(), KisExportCheckRegistry::instance(), KisExportCheckBase::PARTIALLY, and RGBAColorModelID.


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