Skip to content

Commit b70097a

Browse files
committed
Alpha/Mask channel export
1 parent aa9b7f2 commit b70097a

File tree

4 files changed

+107
-21
lines changed

4 files changed

+107
-21
lines changed

Solidify/Solidify.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ xcopy /y e:\DVR\bin\libwebpmuxd.dll "$(TargetDir)"</Command>
251251
<AdditionalIncludeDirectories>
252252
</AdditionalIncludeDirectories>
253253
<MultiProcessorCompilation>true</MultiProcessorCompilation>
254-
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
254+
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
255255
<Optimization>Disabled</Optimization>
256256
</ClCompile>
257257
<Link>

Solidify/src/UI.CPP

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ MainWindow::MainWindow() {
222222

223223
// Connect the Settings action's triggered signal
224224

225-
//connect(sld_enable, &QAction::toggled, this, &MainWindow::sldfSettings);
225+
connect(sld_enable, &QAction::toggled, this, &MainWindow::sldfSettings);
226226
//connect(alf_enable, &QAction::toggled, this, &MainWindow::alfSettings);
227227
QList<QAction*> alf_act = { alf_Disb, alf_Embed, alf_Only };
228228
for (QAction* action : alf_act) {
@@ -381,6 +381,12 @@ void MainWindow::repSettings() {
381381
break;
382382
}
383383
}
384+
if (action != rep_Dis) {
385+
nrm_Dis->setChecked(true);
386+
settings.normMode = 0;
387+
emit updateTextSignal("Normalizing are part of Repair");
388+
qDebug() << "Normalizing are part of Repair";
389+
}
384390
}
385391

386392
void MainWindow::sldfSettings(bool checked) {
@@ -393,12 +399,12 @@ void MainWindow::sldfSettings(bool checked) {
393399
qDebug() << "Export Alpha Disabled";
394400
}
395401
else {
396-
nrm_Smrt->setChecked(false);
397-
nrm_Dis->setChecked(true);
398-
settings.normMode = 0;
402+
//nrm_Smrt->setChecked(false);
403+
//nrm_Dis->setChecked(true);
404+
//settings.normMode = 0;
399405
emit updateTextSignal("Solidify Disabled");
400-
emit updateTextSignal("Normalizing disabled");
401-
qDebug() << "Normalizing disabled";
406+
//emit updateTextSignal("Normalizing disabled");
407+
//qDebug() << "Normalizing disabled";
402408
qDebug() << "Solidify Disabled";
403409
}
404410
}
@@ -414,6 +420,22 @@ void MainWindow::alfSettings() {
414420
break;
415421
}
416422
}
423+
if (action == alf_Only) {
424+
sld_enable->setChecked(false);
425+
emit updateTextSignal("Solidify Disabled");
426+
qDebug() << "Solidify Disabled";
427+
settings.isSolidify = false;
428+
429+
nrm_Dis->setChecked(true);
430+
settings.normMode = 0;
431+
emit updateTextSignal("Normalizing disabled");
432+
qDebug() << "Normalizing disabled";
433+
434+
rep_Dis->setChecked(true);
435+
settings.repairMode = 0;
436+
emit updateTextSignal("Repair mode set to Disable");
437+
qDebug() << "Repair mode set to Disable";
438+
}
417439
}
418440

419441
void MainWindow::rngSettings() {

Solidify/src/processing.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,41 @@ QString getOutName(const QString& fileName, Settings* settings) {
102102
}
103103
else if (settings->normMode > 0)
104104
{
105-
// check if filename have any of settings.normNames as substring, case insensitive
106-
std::string lowName = toLower(baseName.toStdString());
107-
108-
for (auto& name : settings->normNames) {
109-
if (lowName.find(name, 0) != std::string::npos) {
110-
proc_sfx += "_norm";
111-
break;
105+
if (settings->normMode == 2) {
106+
proc_sfx += "_norm";
107+
}
108+
else {
109+
// check if filename have any of settings.normNames as substring, case insensitive
110+
std::string lowName = toLower(baseName.toStdString());
111+
112+
for (auto& name : settings->normNames) {
113+
if (lowName.find(name, 0) != std::string::npos) {
114+
proc_sfx += "_norm";
115+
break;
116+
}
112117
}
113118
}
114119
}
120+
else if (settings->repairMode > 0)
121+
{
122+
if (settings->repairMode == 2) {
123+
proc_sfx += "_rep";
124+
}
125+
else {
126+
// check if filename have any of settings.normNames as substring, case insensitive
127+
std::string lowName = toLower(baseName.toStdString());
128+
129+
for (auto& name : settings->normNames) {
130+
if (lowName.find(name, 0) != std::string::npos) {
131+
proc_sfx += "_rep";
132+
break;
133+
}
134+
}
135+
}
136+
}
137+
else if (settings->alphaMode == 2) {
138+
proc_sfx += "_mask";
139+
}
115140
else {
116141
proc_sfx += "_conv";
117142
}

Solidify/src/solidify.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@
3434

3535
using namespace OIIO;
3636

37+
void* getTypedPointer(OIIO::ImageBuf& buf, const OIIO::TypeDesc& type) {
38+
switch (type.basetype) {
39+
case OIIO::TypeDesc::UINT8:
40+
return (uint8_t*)buf.localpixels();
41+
case OIIO::TypeDesc::UINT16:
42+
return (uint16_t*)buf.localpixels();
43+
case OIIO::TypeDesc::UINT32:
44+
return (uint32_t*)buf.localpixels();
45+
case OIIO::TypeDesc::UINT64:
46+
return (uint64_t*)buf.localpixels();
47+
case OIIO::TypeDesc::HALF:
48+
return (half*)buf.localpixels();
49+
case OIIO::TypeDesc::FLOAT:
50+
return (float*)buf.localpixels();
51+
case OIIO::TypeDesc::DOUBLE:
52+
return (double*)buf.localpixels();
53+
default:
54+
return nullptr;
55+
}
56+
}
57+
3758
bool solidify_main(const std::string& inputFileName, const std::string& outputFileName, std::pair<ImageBuf, ImageBuf> mask_pair,
3859
QProgressBar* progressBar, MainWindow* mainWindow) {
3960
Timer g_timer;
@@ -42,7 +63,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
4263
// Generate a random delay
4364
std::random_device rd;
4465
std::mt19937 gen(rd());
45-
std::uniform_int_distribution<> distr(1, 1000); // delay range in milliseconds
66+
std::uniform_int_distribution<> distr(1, 500); // delay range in milliseconds
4667

4768
// Sleep for the random delay
4869
std::this_thread::sleep_for(std::chrono::milliseconds(distr(gen)));
@@ -335,11 +356,14 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
335356

336357
ImageSpec& ospec = out_buf.specmod();
337358
if (settings.alphaMode == 1) {
338-
ospec.nchannels = grayscale ? 2 : 4; // Only write RGB channels
359+
ospec.nchannels = grayscale ? 2 : 4; // Write RGB and alpha channels
360+
}
361+
else if (settings.alphaMode == 0) {
362+
ospec.nchannels = grayscale ? 1 : 3; // Only write RGB channels
339363
}
340364
else {
341-
ospec.nchannels = grayscale ? 1 : 3; // Write RGB and alpha channels
342-
}
365+
ospec.nchannels = 1; // Only write alpha channel
366+
}
343367

344368
ospec.erase_attribute("Exif:LensSpecification");
345369
LOG(info) << "OIIO Libtiff EXIF fix deleting: " << "Exif:LensSpecification" << std::endl;
@@ -368,7 +392,6 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
368392
ospec.erase_attribute(name);
369393
}
370394
*/
371-
///////
372395
/*
373396
// Initialize a vector to hold pairs of old and new attribute names
374397
std::vector<std::pair<std::string, std::string>> attrs_to_rename;
@@ -414,7 +437,6 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
414437

415438
ospec.alpha_channel = -1; // No alpha channel
416439
//int bits = settings.bitDepth != -1 ? settings.getBitDepth() : 2;
417-
418440
//rspec.attribute("oiio:BitsPerSample", bits);
419441
ospec.attribute("pnm:binary", 1);
420442
ospec.attribute("oiio:UnassociatedAlpha", 1);
@@ -447,7 +469,24 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
447469

448470
LOG(info) << "Writing " << outputFileName << std::endl;
449471

450-
auto ok = out->write_image(out_format, out_buf.localpixels(),out_buf.pixel_stride(), out_buf.scanline_stride(), out_buf.z_stride(), *m_progress_callback, progressBar);
472+
bool ok = false;
473+
474+
if (settings.alphaMode != 2) {
475+
ok = out->write_image(out_format, out_buf.localpixels(), out_buf.pixel_stride(), out_buf.scanline_stride(), out_buf.z_stride(), *m_progress_callback, progressBar);
476+
}
477+
else {
478+
int channel_to_extract = grayscale ? 1 : 3; // for Alpha channle from RGBA
479+
int channels = grayscale ? 2 : 4;
480+
int bytes = input_buf.spec().format.size(); //
481+
482+
ok = out->write_image(out_format,
483+
(char*)out_buf.localpixels() + channel_to_extract * bytes, // pointer to the first pixel to write
484+
channels * bytes, // x stride
485+
out_buf.scanline_stride(), // y stride
486+
out_buf.z_stride(), // z stride
487+
*m_progress_callback, progressBar);
488+
}
489+
451490
if (!ok) {
452491
LOG(error) << "Error writing " << outputFileName << std::endl;
453492
LOG(error) << out->geterror() << std::endl;

0 commit comments

Comments
 (0)