Krita Source Code Documentation
Loading...
Searching...
No Matches
RGBEIMPORT Namespace Reference

Functions

static bool LoadHDR (QDataStream &s, const int width, const int height, KisSequentialIterator &it)
 
static bool ReadOldLine (quint8 *image, int width, QDataStream &s)
 
static void RGBEToPaintDevice (quint8 *image, int width, KisSequentialIterator &it)
 

Function Documentation

◆ LoadHDR()

static bool RGBEIMPORT::LoadHDR ( QDataStream & s,
const int width,
const int height,
KisSequentialIterator & it )
static

Definition at line 115 of file RGBEImport.cpp.

116{
117 quint8 val;
118 quint8 code;
119
120 QByteArray lineArray;
121 lineArray.resize(4 * width);
122 quint8 *image = (quint8 *)lineArray.data();
123
124 for (int cline = 0; cline < height; cline++) {
125 // determine scanline type
126 if ((width < MINELEN) || (MAXELEN < width)) {
127 ReadOldLine(image, width, s);
128 RGBEToPaintDevice(image, width, it);
129 continue;
130 }
131
132 s >> val;
133
134 if (s.atEnd()) {
135 return true;
136 }
137
138 if (val != 2) {
139 s.device()->ungetChar(val);
140 ReadOldLine(image, width, s);
141 RGBEToPaintDevice(image, width, it);
142 continue;
143 }
144
145 s >> image[1];
146 s >> image[2];
147 s >> image[3];
148
149 if (s.atEnd()) {
150 return true;
151 }
152
153 if ((image[1] != 2) || (image[2] & 128)) {
154 image[0] = 2;
155 ReadOldLine(image + 4, width - 1, s);
156 RGBEToPaintDevice(image, width, it);
157 continue;
158 }
159
160 if ((image[2] << 8 | image[3]) != width) {
161 dbgFile << "Line of pixels had width" << (image[2] << 8 | image[3]) << "instead of" << width;
162 return false;
163 }
164
165 // read each component
166 for (int i = 0; i < 4; i++) {
167 for (int j = 0; j < width;) {
168 s >> code;
169 if (s.atEnd()) {
170 dbgFile << "Truncated HDR file";
171 return false;
172 }
173 if (code > 128) {
174 // run
175 code &= 127;
176 s >> val;
177 while (code != 0) {
178 image[i + j * 4] = val;
179 j++;
180 code--;
181 }
182 } else {
183 // non-run
184 while (code != 0) {
185 s >> image[i + j * 4];
186 j++;
187 code--;
188 }
189 }
190 }
191 }
192
193 RGBEToPaintDevice(image, width, it);
194 }
195
196 return true;
197}
#define MINELEN
#define MAXELEN
#define dbgFile
Definition kis_debug.h:53
static void RGBEToPaintDevice(quint8 *image, int width, KisSequentialIterator &it)
static bool ReadOldLine(quint8 *image, int width, QDataStream &s)

References dbgFile, MAXELEN, MINELEN, ReadOldLine(), and RGBEToPaintDevice().

◆ ReadOldLine()

static bool RGBEIMPORT::ReadOldLine ( quint8 * image,
int width,
QDataStream & s )
static

Definition at line 60 of file RGBEImport.cpp.

61{
62 int rshift = 0;
63 int i;
64
65 while (width > 0) {
66 s >> image[0];
67 s >> image[1];
68 s >> image[2];
69 s >> image[3];
70
71 if (s.atEnd()) {
72 return false;
73 }
74
75 if ((image[0] == 1) && (image[1] == 1) && (image[2] == 1)) {
76 for (i = image[3] << rshift; i > 0; i--) {
77 memcpy(image, image-4, 4);
78 image += 4;
79 width--;
80 }
81 rshift += 8;
82 } else {
83 image += 4;
84 width--;
85 rshift = 0;
86 }
87 }
88 return true;
89}

◆ RGBEToPaintDevice()

static void RGBEIMPORT::RGBEToPaintDevice ( quint8 * image,
int width,
KisSequentialIterator & it )
static

Definition at line 91 of file RGBEImport.cpp.

92{
93 for (int j = 0; j < width; j++) {
94 it.nextPixel();
95 auto *dst = reinterpret_cast<float *>(it.rawData());
96
97 if (image[3]) {
98 const float v = std::ldexp(1.0f, int(image[3]) - (128 + 8));
99 const float pixelData[4] = {float(image[0]) * v,
100 float(image[1]) * v,
101 float(image[2]) * v,
102 1.0f};
103 memcpy(dst, pixelData, 4 * sizeof(float));
104 } else {
105 // Zero exponent handle
106 const float pixelData[4] = {0.0f, 0.0f, 0.0f, 1.0f};
107 memcpy(dst, pixelData, 4 * sizeof(float));
108 }
109
110 image += 4;
111 }
112}
qreal v
ALWAYS_INLINE quint8 * rawData()

References KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and v.