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

#include <RGBEImport.h>

+ Inheritance diagram for RGBEImport:

Public Member Functions

KisImportExportErrorCode convert (KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration=nullptr) override
 
 RGBEImport (QObject *parent, const QVariantList &)
 
bool supportsIO () const override
 Override and return false for the filters that use a library that cannot handle file handles, only file names.
 
 ~RGBEImport () override=default
 
- Public Member Functions inherited from KisImportExportFilter
virtual KisConfigWidgetcreateConfigurationWidget (QWidget *parent, const QByteArray &from="", const QByteArray &to="") const
 createConfigurationWidget creates a widget that can be used to define the settings for a given import/export filter
 
virtual KisPropertiesConfigurationSP defaultConfiguration (const QByteArray &from="", const QByteArray &to="") const
 defaultConfiguration defines the default settings for the given import export filter
 
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)
 
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
 
virtual void initializeCapabilities ()
 
 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 RGBEImport.h.

Constructor & Destructor Documentation

◆ RGBEImport()

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

Definition at line 201 of file RGBEImport.cpp.

202 : KisImportExportFilter(parent)
203{
204}
KisImportExportFilter(QObject *parent=0)

◆ ~RGBEImport()

RGBEImport::~RGBEImport ( )
overridedefault

Member Function Documentation

◆ convert()

KisImportExportErrorCode RGBEImport::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 207 of file RGBEImport.cpp.

208{
209 if (!io->isReadable()) {
210 errFile << "Cannot read image contents";
212 }
213
214 if (!(io->peek(11) == "#?RADIANCE\n" || io->peek(7) == "#?RGBE\n")) {
215 errFile << "Invalid RGBE header!";
217 }
218
220
221 int len;
222 QByteArray line(MAXLINE + 1, Qt::Uninitialized);
223 QByteArray rawFormat;
224 QByteArray rawGamma;
225 QByteArray rawExposure;
226 QByteArray rawHeaderInfo;
227
228 // Parse header
229 do {
230 len = io->readLine(line.data(), MAXLINE);
231 if (line.startsWith("# ")) {
232 rawHeaderInfo = line.mid(2, len - 2 - 1 /*\n*/);
233 } else if (line.startsWith("GAMMA=")) {
234 rawGamma = line.mid(6, len - 6 - 1 /*\n*/);
235 } else if (line.startsWith("EXPOSURE=")) {
236 rawExposure = line.mid(9, len - 9 - 1 /*\n*/);
237 } else if (line.startsWith("FORMAT=")) {
238 rawFormat = line.mid(7, len - 7 - 1 /*\n*/);
239 }
240 } while ((len > 0) && (line[0] != '\n'));
241
242 if (rawFormat != "32-bit_rle_rgbe") {
243 errFile << "Invalid RGBE format!";
245 }
246
247 const QString headerInfo = [&]() {
248 if (!rawHeaderInfo.isEmpty()) {
249 return QString(rawHeaderInfo).trimmed();
250 }
251 return QString();
252 }();
253
254 // Unused fields, I don't know what to do with gamma and exposure fields yet.
255 if (!rawGamma.isEmpty()) {
256 bool gammaOk = false;
257 const float gammaTemp = QString(rawGamma).toFloat(&gammaOk);
258 if (gammaOk) {
259 d.m_gamma = gammaTemp;
260 }
261 }
262 if (!rawExposure.isEmpty()) {
263 bool exposureOk = false;
264 const float expTemp = QString(rawExposure).toFloat(&exposureOk);
265 if (exposureOk) {
266 d.m_exposure = expTemp;
267 }
268 }
269
270 len = io->readLine(line.data(), MAXLINE);
271 line.resize(len);
272
273 /*
274 TODO: handle flipping and rotation, as per the spec below
275 The single resolution line consists of 4 values, a X and Y label each followed by a numerical
276 integer value. The X and Y are immediately preceded by a sign which can be used to indicate
277 flipping, the order of the X and Y indicate rotation. The standard coordinate system for
278 Radiance images would have the following resolution string -Y N +X N. This indicates that the
279 vertical axis runs down the file and the X axis is to the right (imagining the image as a
280 rectangular block of data). A -X would indicate a horizontal flip of the image. A +Y would
281 indicate a vertical flip. If the X value appears before the Y value then that indicates that
282 the image is stored in column order rather than row order, that is, it is rotated by 90 degrees.
283 The reader can convince themselves that the 8 combinations cover all the possible image orientations
284 and rotations.
285 */
286 QRegularExpression resolutionRegExp(QStringLiteral("([+\\-][XY]) ([0-9]+) ([+\\-][XY]) ([0-9]+)\n"));
287 QRegularExpressionMatch match = resolutionRegExp.match(QString::fromLatin1(line));
288 if (!match.hasMatch()) {
289 errFile << "Invalid HDR file, the first line after the header didn't have the expected format:" << line;
291 }
292
293 if ((match.captured(1).at(1) != u'Y') || (match.captured(3).at(1) != u'X')) {
294 errFile << "Unsupported image orientation in HDR file.";
296 }
297
298 const int width = match.captured(4).toInt();
299 const int height = match.captured(2).toInt();
300
301 dbgFile << "RGBE image information:";
302 dbgFile << "Program info:" << headerInfo;
303 if (!rawGamma.isEmpty()) {
304 dbgFile << "Gamma:" << d.m_gamma;
305 } else {
306 dbgFile << "No gamma metadata provided";
307 }
308 if (!rawExposure.isEmpty()) {
309 dbgFile << "Exposure:" << d.m_exposure;
310 } else {
311 dbgFile << "No exposure metadata provided";
312 }
313 dbgFile << "Dimension:" << width << "x" << height;
314
315 KisImageSP image;
316 KisLayerSP layer;
317
318 const KoColorProfile *profile = nullptr;
319
320 d.m_colorID = RGBAColorModelID;
321 d.m_depthID = Float32BitsColorDepthID;
322
324 d.cs = KoColorSpaceRegistry::instance()->colorSpace(d.m_colorID.id(), d.m_depthID.id(), profile);
325
326 image = new KisImage(document->createUndoStore(), width, height, d.cs, "RGBE image");
327 layer = new KisPaintLayer(image, image->nextLayerName(), OPACITY_OPAQUE_U8);
328 d.m_currentFrame = new KisPaintDevice(image->colorSpace());
329
330 QDataStream stream(io);
331 KisSequentialIterator it(d.m_currentFrame, {0, 0, width, height});
332
333 if (!RGBEIMPORT::LoadHDR(stream, width, height, it)) {
334 errFile << "Error loading HDR file.";
336 }
337
338 layer->paintDevice()->makeCloneFrom(d.m_currentFrame, image->bounds());
339 image->addNode(layer, image->rootLayer().data());
340
341 document->setCurrentImage(image);
342
344}
qreal u
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
const quint8 OPACITY_OPAQUE_U8
#define MAXLINE
KisGroupLayerSP rootLayer() const
const KoColorSpace * colorSpace() const
QString nextLayerName(const QString &baseName="") const
Definition kis_image.cc:715
QRect bounds() const override
void makeCloneFrom(KisPaintDeviceSP src, const QRect &rect)
#define errFile
Definition kis_debug.h:115
#define dbgFile
Definition kis_debug.h:53
static bool LoadHDR(QDataStream &s, const int width, const int height, KisSequentialIterator &it)
virtual KisPaintDeviceSP paintDevice() const =0
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorProfile * p709G10Profile() const

References KisNodeFacade::addNode(), KisImage::bounds(), KisImage::colorSpace(), KoColorSpaceRegistry::colorSpace(), KisImportExportFilter::d, KisSharedPtr< T >::data(), dbgFile, errFile, ImportExportCodes::ErrorWhileReading, Float32BitsColorDepthID, KoColorSpaceRegistry::instance(), ImportExportCodes::InternalError, RGBEIMPORT::LoadHDR(), KisPaintDevice::makeCloneFrom(), MAXLINE, KisImage::nextLayerName(), ImportExportCodes::NoAccessToRead, ImportExportCodes::OK, OPACITY_OPAQUE_U8, KoColorSpaceRegistry::p709G10Profile(), KisBaseNode::paintDevice(), RGBAColorModelID, KisImage::rootLayer(), and u.

◆ supportsIO()

bool RGBEImport::supportsIO ( ) const
inlineoverridevirtual

Override and return false for the filters that use a library that cannot handle file handles, only file names.

Reimplemented from KisImportExportFilter.

Definition at line 18 of file RGBEImport.h.

18{ return true; }

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