Skip to content

Commit 4e58472

Browse files
committed
Repair/Unpack 2ch Normal + Temp fix for EXIF tag and Lbraw crash
• Temp fix for incorrectly read EXIF tag that crashed Libraw plugin on TIFF export • Repar/Reconstruct Normal map third channel (uxually Z channel)
1 parent 39f2e61 commit 4e58472

File tree

7 files changed

+213
-53
lines changed

7 files changed

+213
-53
lines changed

Solidify/Solidify.vcxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ xcopy /y e:\DVR\lib\boost_log_setup-vc143-mt-x64-1_84.dll "$(TargetDir)"
121121
xcopy /y e:\DVR\lib\boost_log-vc143-mt-x64-1_84.dll "$(TargetDir)"
122122
xcopy /y e:\DVR\lib\boost_thread-vc143-mt-x64-1_84.dll "$(TargetDir)"
123123

124-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Core.dll "$(TargetDir)"
125-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Gui.dll "$(TargetDir)"
126-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Widgets.dll "$(TargetDir)"
127-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Svg.dll "$(TargetDir)"
124+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Core.dll "$(TargetDir)"
125+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Gui.dll "$(TargetDir)"
126+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Widgets.dll "$(TargetDir)"
127+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Svg.dll "$(TargetDir)"
128128

129129
mkdir "$(TargetDir)\plugins\platforms"
130130
mkdir "$(TargetDir)\plugins\imageformats"
@@ -213,10 +213,10 @@ xcopy /y e:\DVR\lib\boost_log_setup-vc143-mt-gd-x64-1_84.dll "$(TargetDir)"
213213
xcopy /y e:\DVR\lib\boost_log-vc143-mt-gd-x64-1_84.dll "$(TargetDir)"
214214
xcopy /y e:\DVR\lib\boost_thread-vc143-mt-gd-x64-1_84.dll "$(TargetDir)"
215215

216-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Cored.dll "$(TargetDir)"
217-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Guid.dll "$(TargetDir)"
218-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Widgetsd.dll "$(TargetDir)"
219-
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt6Svgd.dll "$(TargetDir)"
216+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Cored.dll "$(TargetDir)"
217+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Guid.dll "$(TargetDir)"
218+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Widgetsd.dll "$(TargetDir)"
219+
xcopy /y c:\Qt\5.15.2\msvc2019_64\bin\Qt5Svgd.dll "$(TargetDir)"
220220

221221
mkdir "$(TargetDir)\plugins\platforms"
222222
mkdir "$(TargetDir)\plugins\imageformats"

Solidify/src/IMAGEIO.CPP

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -264,27 +264,39 @@ bool img_load(ImageBuf& outBuf, const std::string& inputFileName, bool external_
264264
}
265265

266266
template<class Rtype>
267-
static bool normalize_impl(ImageBuf& R, const ImageBuf& A, float inCenter, float outCenter, float scale, ROI roi, int nthreads)
267+
static bool recalc_normal_impl(ImageBuf& R, const ImageBuf& A, uint channel, int sign, float inCenter, float outCenter, float scale, ROI roi, int nthreads)
268268
{
269269
ImageBufAlgo::parallel_image(roi, nthreads, [&](ROI roi) {
270270
ImageBuf::ConstIterator<Rtype> a(A, roi);
271271
for (ImageBuf::Iterator<Rtype> r(R, roi); !r.done(); ++r, ++a)
272272
{
273-
float x = a[0];
274-
float y = a[1];
275-
float z = a[2];
276273

277-
x = x - inCenter;
278-
y = y - inCenter;
279-
z = z - inCenter;
274+
// axis = sqrt(1 - (x^2 + y^2))
275+
// axs = sqrt(1 - (x*x + y*y + z*z))
280276

281-
float length = std::hypot(x, y, z);
277+
float t[3];
278+
279+
t[0] = channel == 0 ? 0.0f : (a[0] - inCenter) / scale;
280+
t[1] = channel == 1 ? 0.0f : (a[1] - inCenter) / scale;
281+
t[2] = channel == 2 ? 0.0f : (a[2] - inCenter) / scale;
282+
283+
bool isZero = (abs(t[0]) + abs(t[1]) + abs(t[2])) == 0.0f;
284+
285+
float recomp = 0.0f;
286+
287+
if (!isZero) {
288+
recomp = sqrt(1.0f - (t[0] * t[0] + t[1] * t[1] + t[2] * t[2]));
289+
}
290+
291+
t[channel] = sign * recomp;
292+
293+
float length = sqrt(t[0] * t[0] + t[1] * t[1] + t[2] * t[2]);
282294

283295
float s = (length > 0.0f) ? scale / length : scale;
284296

285-
r[0] = x * s + outCenter;
286-
r[1] = y * s + outCenter;
287-
r[2] = z * s + outCenter;
297+
r[0] = t[0] * s + outCenter;
298+
r[1] = t[1] * s + outCenter;
299+
r[2] = t[2] * s + outCenter;
288300

289301
if (A.spec().nchannels == 4) {
290302
r[3] = a[3];
@@ -294,42 +306,21 @@ static bool normalize_impl(ImageBuf& R, const ImageBuf& A, float inCenter, float
294306
return true;
295307
}
296308

297-
bool normalize(ImageBuf& dst, const ImageBuf& A, float inCenter, float outCenter, float scale, ROI roi, int nthreads)
309+
bool recalc_normal(ImageBuf& dst, const ImageBuf& A, uint channel, int sign, float inCenter, float outCenter, float scale, ROI roi, int nthreads)
298310
{
299311
if (!ImageBufAlgo::IBAprep(roi, &dst, &A))
300312
return false;
301313
bool ok;
302-
//OIIO_DISPATCH_COMMON_TYPES(ok, "normalize", normalize_impl, dst.spec().format, dst, A, fullRange, roi, nthreads);
303-
switch (dst.spec().format.basetype) {
304-
case TypeDesc::FLOAT:
305-
ok = normalize_impl<float>(dst, A, inCenter, outCenter, scale, roi, nthreads);
306-
break;
307-
case TypeDesc::UINT8:
308-
ok = normalize_impl<unsigned char>(dst, A, inCenter, outCenter, scale, roi, nthreads);
309-
break;
310-
case TypeDesc::HALF: // should be half but it give me an error
311-
ok = normalize_impl<float>(dst, A, inCenter, outCenter, scale, roi, nthreads);
312-
break;
313-
case TypeDesc::UINT16:
314-
ok = normalize_impl<unsigned short>(dst, A, inCenter, outCenter, scale, roi, nthreads);
315-
break;
316-
default:
317-
{
318-
ImageBuf Rtmp;
319-
if ((dst).initialized()) Rtmp.copy(dst, TypeDesc::FLOAT);
320-
ok = normalize_impl<float>(Rtmp, A, inCenter, outCenter, scale, roi, nthreads);
321-
if (ok) (dst).copy(Rtmp);
322-
else (dst).errorfmt("{}", Rtmp.geterror());
323-
}
324-
};
314+
OIIO_DISPATCH_COMMON_TYPES(ok, "recalc_normal", recalc_normal_impl, dst.spec().format, dst, A,
315+
channel, sign, inCenter, outCenter, scale, roi, nthreads);
325316
return ok;
326317
}
327318

328-
ImageBuf normalize(const ImageBuf& A, float inCenter, float outCenter, float scale, ROI roi, int nthreads)
319+
ImageBuf recalc_normal(const ImageBuf& A, uint channel, int sign, float inCenter, float outCenter, float scale, ROI roi, int nthreads)
329320
{
330321
ImageBuf result;
331-
bool ok = normalize(result, A, inCenter, outCenter, scale, roi, nthreads);
322+
bool ok = recalc_normal(result, A, channel, sign, inCenter, outCenter, scale, roi, nthreads);
332323
if (!ok && !result.has_error())
333-
result.errorfmt("normalize error");
324+
result.errorfmt("recalculation error");
334325
return result;
335326
}

Solidify/src/UI.CPP

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ MainWindow::MainWindow() {
122122
QMenu* fmt_submenu = new QMenu("Formats", s_menu);
123123
QMenu* bit_submenu = new QMenu("Bits Depth", s_menu);
124124
QMenu* raw_submenu = new QMenu("Camera Raw", s_menu);
125+
QMenu* rep_submenu = new QMenu("Repair", s_menu);
126+
125127
QActionGroup* NormGroup = new QActionGroup(nm_submenu);
128+
QActionGroup* RepairGroup = new QActionGroup(rep_submenu);
126129
QActionGroup* RangeGroup = new QActionGroup(rng_submenu);
127130
QActionGroup* FrmtGroup = new QActionGroup(fmt_submenu);
128131
QActionGroup* BitsGroup = new QActionGroup(bit_submenu);
@@ -141,6 +144,15 @@ MainWindow::MainWindow() {
141144
nrm_Smrt = createAction("Smart", NormGroup, nm_submenu, true, (settings.normMode == 1));
142145
nrm_Force = createAction("Force", NormGroup, nm_submenu, true, (settings.normMode == 2));
143146

147+
// Repair
148+
rep_Dis = createAction("Disable", RepairGroup, rep_submenu, true, (settings.repairMode == 0));
149+
rep_Z = createAction("X", RepairGroup, rep_submenu, true, (settings.repairMode == 1));
150+
rep_Y = createAction("Y", RepairGroup, rep_submenu, true, (settings.repairMode == 2));
151+
rep_X = createAction("Z", RepairGroup, rep_submenu, true, (settings.repairMode == 3));
152+
rep_mZ = createAction("-X", RepairGroup, rep_submenu, true, (settings.repairMode == 4));
153+
rep_mY = createAction("-Y", RepairGroup, rep_submenu, true, (settings.repairMode == 5));
154+
rep_mX = createAction("-Z", RepairGroup, rep_submenu, true, (settings.repairMode == 6));
155+
144156
// Range
145157
rng_Unsg = createAction("Unsigned", RangeGroup, rng_submenu, true, (settings.rangeMode == 0));
146158
rng_Sign = createAction("Signed", RangeGroup, rng_submenu, true, (settings.rangeMode == 1));
@@ -178,6 +190,7 @@ MainWindow::MainWindow() {
178190
s_menu->addAction(alf_enable);
179191
s_menu->addSeparator();
180192
s_menu->addMenu(nm_submenu);
193+
s_menu->addMenu(rep_submenu);
181194
s_menu->addMenu(rng_submenu);
182195
s_menu->addSeparator();
183196
s_menu->addMenu(fmt_submenu);
@@ -210,6 +223,10 @@ MainWindow::MainWindow() {
210223
for (QAction* action : norm_act) {
211224
connect(action, &QAction::triggered, this, &MainWindow::normSettings);
212225
}
226+
QList<QAction*> rep_act = { rep_Dis, rep_Z, rep_Y, rep_X, rep_mZ, rep_mY, rep_mX };
227+
for (QAction* action : rep_act) {
228+
connect(action, &QAction::triggered, this, &MainWindow::repSettings);
229+
}
213230
QList<QAction*> rng_act = { rng_Unsg, rng_Sign, rng_US, rng_SU };
214231
for (QAction* action : rng_act) {
215232
connect(action, &QAction::triggered, this, &MainWindow::rngSettings);
@@ -342,6 +359,21 @@ void MainWindow::normSettings() {
342359
}
343360
}
344361

362+
void MainWindow::repSettings() {
363+
std::vector<std::pair<QString, uint>> actionMap =
364+
{ { "Disable", 0 }, { "X", 1 }, { "Y", 2 }, { "Z", 3 },
365+
{ "-X", 4 }, { "-Y", 5 }, { "-Z", 6 } };
366+
QAction* action = qobject_cast<QAction*>(sender());
367+
for (int i = 0; i < actionMap.size(); i++) {
368+
if (action->text() == actionMap[i].first) {
369+
settings.repairMode = actionMap[i].second;
370+
emit updateTextSignal(QString("Repair mode set to %1").arg(actionMap[i].first));
371+
qDebug() << QString("Repair mode set to %1").arg(actionMap[i].first);
372+
break;
373+
}
374+
}
375+
}
376+
345377
void MainWindow::sldfSettings(bool checked) {
346378
settings.isSolidify = sld_enable->isChecked();
347379
if (checked) {

Solidify/src/imageio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ void debugImageBufWrite(const ImageBuf& buf, const std::string& filename);
4949
//bool NormalizeMap(ImageBuf& img, bool fullRange);
5050
//bool mulNormalizeMap(ImageBuf& img, bool fullRange);
5151

52-
bool normalize(ImageBuf& dst, const ImageBuf& A, float inCenter, float outCenter, float scale, ROI roi, int nthreads);
53-
ImageBuf normalize(const ImageBuf& A, float inCenter, float outCenter, float scale, ROI roi, int nthreads);
52+
bool recalc_normal(ImageBuf& dst, const ImageBuf& A, uint channel, int sign, float inCenter, float outCenter, float scale, ROI roi, int nthreads);
53+
ImageBuf recalc_normal(const ImageBuf& A, uint channel, int sign, float inCenter, float outCenter, float scale, ROI roi, int nthreads);

Solidify/src/settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef unsigned long ulong;
3030

3131
struct Settings {
3232
bool isSolidify, expAlpha, conEnable;
33-
uint normMode, rangeMode;
33+
uint normMode, rangeMode, repairMode;
3434
int fileFormat, defFormat;
3535
int bitDepth, defBDepth;
3636
int rawRot;
@@ -52,6 +52,8 @@ struct Settings {
5252
expAlpha = false; // Export alpha channel
5353
numThreads = 3; // Number of threads: 0 - auto, >0 - number of threads
5454
normMode = 1; // Normalize mode: 0 - disabled, 1 - smart, 2 - force
55+
repairMode = 0; // Repair mode: 0 - disabled, 1 - Z, 2 - Y, 3 - X, 4 - -Z, 5 - -Y, 6 - -X
56+
5557
rangeMode = 0; // Float type: 0 - unsigned, 1 - signed, 2 - unsigned -> signed, 3 - signed -> unsigned
5658
fileFormat = -1; // File format: -1 - original, 0 - TIFF, 1 - OpenEXR, 2 - PNG, 3 - JPEG, 4 - JPEG-2000, 5 - PPM
5759
defFormat = 0; // Default file format = TIFF

0 commit comments

Comments
 (0)