Skip to content

Commit aa9b7f2

Browse files
committed
Export alpha/mask
1 parent 4e58472 commit aa9b7f2

File tree

6 files changed

+51
-32
lines changed

6 files changed

+51
-32
lines changed

Solidify/src/UI.CPP

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,25 @@ MainWindow::MainWindow() {
108108
sld_enable->setCheckable(true);
109109
sld_enable->setChecked(settings.isSolidify);
110110
// preserve alpha
111-
alf_enable = new QAction("With Alpha", s_menu);
112-
alf_enable->setCheckable(true);
113-
alf_enable->setChecked(settings.expAlpha);
111+
//alf_enable = new QAction("With Alpha", s_menu);
112+
//alf_enable->setCheckable(true);
113+
//alf_enable->setChecked(settings.alphaMode == 1);
114114

115115
QAction* con_enable = new QAction("Enable Console", s_menu);
116116
con_enable->setCheckable(true);
117117
con_enable->setChecked(settings.conEnable);
118118

119119
// Submenu
120+
QMenu* alf_submenu = new QMenu("Alpha/Mask", s_menu);
120121
QMenu* nm_submenu = new QMenu("Normalize", s_menu);
122+
QMenu* rep_submenu = new QMenu("Repair", s_menu);
121123
QMenu* rng_submenu = new QMenu("Floats type", s_menu);
122124
QMenu* fmt_submenu = new QMenu("Formats", s_menu);
123125
QMenu* bit_submenu = new QMenu("Bits Depth", s_menu);
124126
QMenu* raw_submenu = new QMenu("Camera Raw", s_menu);
125-
QMenu* rep_submenu = new QMenu("Repair", s_menu);
126127

127128
QActionGroup* NormGroup = new QActionGroup(nm_submenu);
129+
QActionGroup* AlfGroup = new QActionGroup(alf_submenu);
128130
QActionGroup* RepairGroup = new QActionGroup(rep_submenu);
129131
QActionGroup* RangeGroup = new QActionGroup(rng_submenu);
130132
QActionGroup* FrmtGroup = new QActionGroup(fmt_submenu);
@@ -139,6 +141,11 @@ MainWindow::MainWindow() {
139141
menu->addAction(action);
140142
return action;
141143
};
144+
// Alpha/Mask
145+
alf_Disb = createAction("Disable", AlfGroup, alf_submenu, true, (settings.alphaMode == 0));
146+
alf_Embed = createAction("Preserve", AlfGroup, alf_submenu, true, (settings.alphaMode == 1));
147+
alf_Only = createAction("Export", AlfGroup, alf_submenu, true, (settings.alphaMode == 2));
148+
142149
// Normals
143150
nrm_Dis = createAction("Disable", NormGroup, nm_submenu, true, (settings.normMode == 0));
144151
nrm_Smrt = createAction("Smart", NormGroup, nm_submenu, true, (settings.normMode == 1));
@@ -187,8 +194,7 @@ MainWindow::MainWindow() {
187194

188195
s_menu->addAction(sld_enable);
189196
s_menu->addSeparator();
190-
s_menu->addAction(alf_enable);
191-
s_menu->addSeparator();
197+
s_menu->addMenu(alf_submenu);
192198
s_menu->addMenu(nm_submenu);
193199
s_menu->addMenu(rep_submenu);
194200
s_menu->addMenu(rng_submenu);
@@ -216,9 +222,12 @@ MainWindow::MainWindow() {
216222

217223
// Connect the Settings action's triggered signal
218224

219-
connect(sld_enable, &QAction::toggled, this, &MainWindow::sldfSettings);
220-
connect(alf_enable, &QAction::toggled, this, &MainWindow::alfSettings);
221-
225+
//connect(sld_enable, &QAction::toggled, this, &MainWindow::sldfSettings);
226+
//connect(alf_enable, &QAction::toggled, this, &MainWindow::alfSettings);
227+
QList<QAction*> alf_act = { alf_Disb, alf_Embed, alf_Only };
228+
for (QAction* action : alf_act) {
229+
connect(action, &QAction::triggered, this, &MainWindow::alfSettings);
230+
}
222231
QList<QAction*> norm_act = { nrm_Dis, nrm_Smrt, nrm_Force };
223232
for (QAction* action : norm_act) {
224233
connect(action, &QAction::triggered, this, &MainWindow::normSettings);
@@ -377,7 +386,7 @@ void MainWindow::repSettings() {
377386
void MainWindow::sldfSettings(bool checked) {
378387
settings.isSolidify = sld_enable->isChecked();
379388
if (checked) {
380-
alf_enable->setChecked(false);
389+
//alf_enable->setChecked(false);
381390
emit updateTextSignal("Solidify Enabled");
382391
qDebug() << "Solidify Enabled";
383392
emit updateTextSignal("Export Alpha Disabled");
@@ -394,16 +403,17 @@ void MainWindow::sldfSettings(bool checked) {
394403
}
395404
}
396405

397-
void MainWindow::alfSettings(bool checked) {
398-
settings.expAlpha = alf_enable->isChecked();
399-
if (checked) {
400-
emit updateTextSignal("Export Alpha Enabled");
401-
qDebug() << "Export Alpha Enabled";
402-
}
403-
else {
404-
emit updateTextSignal("Export Alpha Disabled");
405-
qDebug() << "Export Alpha Disabled";
406-
}
406+
void MainWindow::alfSettings() {
407+
std::vector<std::pair<QString, uint>> actionMap ={ { "Disable", 0 }, { "Preserve", 1 }, { "Export", 2 } };
408+
QAction* action = qobject_cast<QAction*>(sender());
409+
for (int i = 0; i < actionMap.size(); i++) {
410+
if (action->text() == actionMap[i].first) {
411+
settings.alphaMode = actionMap[i].second;
412+
emit updateTextSignal(QString("Alpha/Mask set to %1").arg(actionMap[i].first));
413+
qDebug() << QString("Alpha/Mask set to %1").arg(actionMap[i].first);
414+
break;
415+
}
416+
}
407417
}
408418

409419
void MainWindow::rngSettings() {

Solidify/src/settings.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ bool loadSettings(Settings& settings, const std::string& filename) {
6363
settings.isSolidify = parsed["Global"]["Solidify"].as_boolean();
6464

6565
if (!check("Global", "ExportAlpha")) return false;
66-
settings.expAlpha = parsed["Global"]["ExportAlpha"].as_boolean();
66+
settings.alphaMode = parsed["Global"]["ExportAlpha"].as_integer();
67+
if (settings.alphaMode < 0 || settings.alphaMode > 2) {
68+
LOG(error) << "Error parsing settings file: [Global] section: \"ExportAlpha\" key value is out of range." << std::endl;
69+
return false;
70+
}
6771

6872
settings.mask_substr.clear();
6973
auto it = parsed["Global"]["MaskNames"].as_array();
@@ -158,7 +162,7 @@ bool loadSettings(Settings& settings, const std::string& filename) {
158162
void printSettings(Settings& settings) {
159163
QString mode;
160164
qDebug() << "Solidify: " << (settings.isSolidify ? "Enabled" : "Disabled");
161-
qDebug() << "Export with Alpha/Mask: " << (settings.expAlpha ? "Enabled" : "Disabled");
165+
qDebug() << "Export Alpha/Mask: " << (settings.alphaMode == 0 ? "Remove Alpha" : (settings.alphaMode == 1 ? "Preserver Alpha" : "Export Alpha only"));
162166
qDebug() << "Parallel Threads: " << settings.numThreads;
163167
qDebug() << "Normalize Mode: " << (settings.normMode == 0 ? "Disabled" : (settings.normMode == 1 ? "Smart" : "Force"));
164168
switch (settings.rangeMode)

Solidify/src/settings.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ typedef unsigned int uint;
2929
typedef unsigned long ulong;
3030

3131
struct Settings {
32-
bool isSolidify, expAlpha, conEnable;
33-
uint normMode, rangeMode, repairMode;
32+
bool isSolidify, conEnable;
33+
uint normMode, rangeMode, repairMode, alphaMode;
3434
int fileFormat, defFormat;
3535
int bitDepth, defBDepth;
3636
int rawRot;
@@ -49,7 +49,8 @@ struct Settings {
4949
void reSettings() {
5050
conEnable = false; // Console enabled/disabled
5151
isSolidify = true; // Solidify enabled/disabled
52-
expAlpha = false; // Export alpha channel
52+
53+
alphaMode = 0; // Alpha mode: 0 - without alpha, 1 - with alpha, 2 - alpha only
5354
numThreads = 3; // Number of threads: 0 - auto, >0 - number of threads
5455
normMode = 1; // Normalize mode: 0 - disabled, 1 - smart, 2 - force
5556
repairMode = 0; // Repair mode: 0 - disabled, 1 - Z, 2 - Y, 3 - X, 4 - -Z, 5 - -Y, 6 - -X

Solidify/src/sldf_config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Global]
22
# Global app settings
33
Solidify = true
4-
ExportAlpha = false
4+
ExportAlpha = 0
55
MaskNames = ["_mask.", "_mask_", "_alpha.", "_alpha_"]
66
Console = true
77
Threads = 3

Solidify/src/solidify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
195195
rgba_buf.specmod().channelnames[rgba_buf.nchannels() - 1] = "A";
196196
rgba_buf.specmod().alpha_channel = rgba_buf.nchannels() - 1;
197197
}
198-
else if (settings.expAlpha) { // if Export alpha channel is enabled, copy the original alpha channel to a separate buffer
198+
else if (settings.alphaMode == 1) { // if Export alpha channel is enabled, copy the original alpha channel to a separate buffer
199199
original_alpha = ImageBufAlgo::channels(input_buf, 1, 3);
200200
}
201201

@@ -210,7 +210,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
210210
return false;
211211
}
212212

213-
if (settings.expAlpha) {
213+
if (settings.alphaMode == 1) {
214214
ImageBufAlgo::paste(result_buf, 0, 0, 0, result_buf.spec().alpha_channel, external_alpha ? bit_alpha_buf : original_alpha);
215215
if (result_buf.has_error()) {
216216
LOG(error) << "paste error: " << result_buf.geterror() << std::endl;
@@ -334,7 +334,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
334334
}
335335

336336
ImageSpec& ospec = out_buf.specmod();
337-
if (settings.expAlpha) {
337+
if (settings.alphaMode == 1) {
338338
ospec.nchannels = grayscale ? 2 : 4; // Only write RGB channels
339339
}
340340
else {

Solidify/src/ui.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "processing.h"
4141

4242
#define VERSION_MAJOR 1
43-
#define VERSION_MINOR 34
43+
#define VERSION_MINOR 38
4444

4545
void setPBarColor(QProgressBar* progressBar, const QColor& color = QColor("#05B8CC"));
4646

@@ -82,15 +82,19 @@ private slots:
8282
void rngSettings();
8383
void frmtSettings();
8484
void bitSettings();
85-
void alfSettings(bool checked);
85+
void alfSettings();
8686
void rawSettings();
8787

8888
private:
8989
QFutureWatcher<bool> processingWatcher;
9090
QProgressBar* progressBar;
9191

9292
QAction* sld_enable;
93-
QAction* alf_enable;
93+
94+
QAction* alf_Disb;
95+
QAction* alf_Embed;
96+
QAction* alf_Only;
97+
9498
QAction* con_enable;
9599

96100
QAction* nrm_Dis;

0 commit comments

Comments
 (0)