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 51 of file RGBEImport.cpp.

52 : KisImportExportFilter(parent)
53{
54}
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 57 of file RGBEImport.cpp.

58{
59 if (!io->isReadable()) {
60 errFile << "Cannot read image contents";
62 }
63
64 if (!(io->peek(11) == "#?RADIANCE\n" || io->peek(7) == "#?RGBE\n")) {
65 errFile << "Invalid RGBE header!";
67 }
68
70
71 int len;
72 QByteArray line(MAXLINE + 1, Qt::Uninitialized);
73 QByteArray rawFormat;
74 QByteArray rawGamma;
75 QByteArray rawExposure;
76 QByteArray rawHeaderInfo;
77
78 // Parse header
79 do {
80 len = io->readLine(line.data(), MAXLINE);
81 if (line.startsWith("# ")) {
82 rawHeaderInfo = line.mid(2, len - 2 - 1 /*\n*/);
83 } else if (line.startsWith("GAMMA=")) {
84 rawGamma = line.mid(6, len - 6 - 1 /*\n*/);
85 } else if (line.startsWith("EXPOSURE=")) {
86 rawExposure = line.mid(9, len - 9 - 1 /*\n*/);
87 } else if (line.startsWith("FORMAT=")) {
88 rawFormat = line.mid(7, len - 7 - 1 /*\n*/);
89 }
90 } while ((len > 0) && (line[0] != '\n'));
91
92 if (rawFormat != "32-bit_rle_rgbe") {
93 errFile << "Invalid RGBE format!";
95 }
96
97 const QString headerInfo = [&]() {
98 if (!rawHeaderInfo.isEmpty()) {
99 return QString(rawHeaderInfo).trimmed();
100 }
101 return QString();
102 }();
103
104 // Unused fields, I don't know what to do with gamma and exposure fields yet.
105 if (!rawGamma.isEmpty()) {
106 bool gammaOk = false;
107 const float gammaTemp = QString(rawGamma).toFloat(&gammaOk);
108 if (gammaOk) {
109 d.m_gamma = gammaTemp;
110 }
111 }
112 if (!rawExposure.isEmpty()) {
113 bool exposureOk = false;
114 const float expTemp = QString(rawExposure).toFloat(&exposureOk);
115 if (exposureOk) {
116 d.m_exposure = expTemp;
117 }
118 }
119
120 len = io->readLine(line.data(), MAXLINE);
121 line.resize(len);
122
123 /*
124 TODO: handle flipping and rotation, as per the spec below
125 The single resolution line consists of 4 values, a X and Y label each followed by a numerical
126 integer value. The X and Y are immediately preceded by a sign which can be used to indicate
127 flipping, the order of the X and Y indicate rotation. The standard coordinate system for
128 Radiance images would have the following resolution string -Y N +X N. This indicates that the
129 vertical axis runs down the file and the X axis is to the right (imagining the image as a
130 rectangular block of data). A -X would indicate a horizontal flip of the image. A +Y would
131 indicate a vertical flip. If the X value appears before the Y value then that indicates that
132 the image is stored in column order rather than row order, that is, it is rotated by 90 degrees.
133 The reader can convince themselves that the 8 combinations cover all the possible image orientations
134 and rotations.
135 */
136 QRegularExpression resolutionRegExp(QStringLiteral("([+\\-][XY]) ([0-9]+) ([+\\-][XY]) ([0-9]+)\n"));
137 QRegularExpressionMatch match = resolutionRegExp.match(QString::fromLatin1(line));
138 if (!match.hasMatch()) {
139 errFile << "Invalid HDR file, the first line after the header didn't have the expected format:" << line;
141 }
142
143 if ((match.captured(1).at(1) != u'Y') || (match.captured(3).at(1) != u'X')) {
144 errFile << "Unsupported image orientation in HDR file.";
146 }
147
148 const int width = match.captured(4).toInt();
149 const int height = match.captured(2).toInt();
150
151 dbgFile << "RGBE image information:";
152 dbgFile << "Program info:" << headerInfo;
153 if (!rawGamma.isEmpty()) {
154 dbgFile << "Gamma:" << d.m_gamma;
155 } else {
156 dbgFile << "No gamma metadata provided";
157 }
158 if (!rawExposure.isEmpty()) {
159 dbgFile << "Exposure:" << d.m_exposure;
160 } else {
161 dbgFile << "No exposure metadata provided";
162 }
163 dbgFile << "Dimension:" << width << "x" << height;
164
165 KisImageSP image;
166 KisLayerSP layer;
167
168 const KoColorProfile *profile = nullptr;
169
170 d.m_colorID = RGBAColorModelID;
171 d.m_depthID = Float32BitsColorDepthID;
172
174 d.cs = KoColorSpaceRegistry::instance()->colorSpace(d.m_colorID.id(), d.m_depthID.id(), profile);
175
176 image = new KisImage(document->createUndoStore(), width, height, d.cs, "RGBE image");
177 layer = new KisPaintLayer(image, image->nextLayerName(), OPACITY_OPAQUE_U8);
178 d.m_currentFrame = new KisPaintDevice(image->colorSpace());
179
180 QDataStream stream(io);
181 KisSequentialIterator it(d.m_currentFrame, {0, 0, width, height});
182
183 if (!RGBEIMPORT::LoadHDR(stream, width, height, it)) {
184 errFile << "Error loading HDR file.";
186 }
187
188 layer->paintDevice()->makeCloneFrom(d.m_currentFrame, image->bounds());
189 image->addNode(layer, image->rootLayer().data());
190
191 document->setCurrentImage(image);
192
194}
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
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: