Skip to content

Commit 81445c5

Browse files
committed
Bit depth fix
Fixed issue when source image bit depth was changed to 32bit float or just higher bit depth on file export
1 parent 877e911 commit 81445c5

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ Dependencies
2929

3030
Changelog
3131
---------
32-
* 1.2 - Grayscale textures fix
33-
* 1.1 - External alpha/mask channel support. Drag&Drop window always on top
34-
* 1.0 - Initial release
32+
* 1.21 - Bit depth when using external alpha/mask fix
33+
* 1.2 - Grayscale textures fix
34+
* 1.1 - External alpha/mask channel support. Drag&Drop window always on top
35+
* 1.0 - Initial release
3536

3637
License
3738
-------

src/Solidify.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ std::pair<ImageBuf, ImageBuf> mask_load(const std::string& mask_file) {
4646
exit(-1);
4747
}
4848

49+
int width = alpha_buf.spec().width;
50+
int height = alpha_buf.spec().height;
51+
std::cout << "Mask size: " << width << "x" << height << std::endl;
52+
// get bit depth of the image channels
53+
//int bit_depth = alpha_buf.spec().format.basesize * 8;
54+
4955
// rename channel to alpha and set it as an alpha channel
5056
alpha_buf.specmod().channelnames[0] = "A";
5157
alpha_buf.specmod().alpha_channel = 0;
@@ -91,10 +97,41 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
9197
}
9298

9399
std::cout << std::endl;
94-
std::cout << "channels: " << input_buf.nchannels() << std::endl;
100+
101+
// Get the image's spec
102+
const ImageSpec& ispec = input_buf.spec();
103+
104+
// Get the format (bit depth and type)
105+
TypeDesc format = ispec.format;
106+
107+
if (format == TypeDesc::UINT8) {
108+
std::cout << "8-bit unsigned int" << std::endl;
109+
}
110+
else if (format == TypeDesc::UINT16) {
111+
std::cout << "16-bit unsigned int" << std::endl;
112+
}
113+
else if (format == TypeDesc::HALF) {
114+
std::cout << "16-bit float" << std::endl;
115+
}
116+
else if (format == TypeDesc::FLOAT) {
117+
std::cout << "32-bit float" << std::endl;
118+
}
119+
else if (format == TypeDesc::DOUBLE) {
120+
std::cout << "64-bit float" << std::endl;
121+
}
122+
else {
123+
std::cout << "Unknown or unsupported format" << std::endl;
124+
}
125+
126+
// get the image size
127+
int width = input_buf.spec().width;
128+
int height = input_buf.spec().height;
129+
std::cout << "Image size: " << width << "x" << height << std::endl;
130+
131+
std::cout << "Channels: " << input_buf.nchannels() << std::endl;
95132

96133
int alpha_channel = input_buf.spec().alpha_channel;
97-
std::cout << "alpha channel: " << alpha_channel << std::endl;
134+
std::cout << "Alpha channel: " << alpha_channel << std::endl;
98135

99136
bool isValid = true;
100137
int inputCh = input_buf.nchannels();
@@ -140,15 +177,23 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
140177
}
141178

142179
// Create an ImageBuf object to store the result
143-
ImageBuf result_buf, rgba_buf;
180+
ImageBuf result_buf, rgba_buf, bit_alpha_buf;
144181

145182
std::cout << "Filling holes in process...\n";
146183

147184
Timer pushpull_timer;
148185

149186
if (external_alpha) {
187+
188+
ImageBuf* alpha_buf_ptr = &mask_pair.first;
189+
190+
if (format != TypeDesc::FLOAT) {
191+
bit_alpha_buf = mask_pair.first.copy(format);
192+
alpha_buf_ptr = &bit_alpha_buf;
193+
}
194+
150195
bool ok = ImageBufAlgo::mul(input_buf, input_buf, grayscale ? mask_pair.first : mask_pair.second);
151-
ok = ok && ImageBufAlgo::channel_append(rgba_buf, input_buf, mask_pair.first);
196+
ok = ok && ImageBufAlgo::channel_append(rgba_buf, input_buf, bit_alpha_buf);
152197
if (!ok) {
153198
std::cerr << "Error: " << rgba_buf.geterror() << std::endl;
154199
return false;

src/processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ QString checkAlpha(std::vector<QString> fileNames) {
3232
return str.contains("_mask.", Qt::CaseInsensitive);
3333
});
3434
if (it != fileNames.end()) {
35-
qDebug() << "Found _mask. in: " << it->toStdString().c_str();
35+
//qDebug() << "Found _mask. in: " << it->toStdString().c_str();
3636
return *it;
3737
}
3838

@@ -41,7 +41,7 @@ QString checkAlpha(std::vector<QString> fileNames) {
4141
return str.contains("_alpha.", Qt::CaseInsensitive);
4242
});
4343
if (it != fileNames.end()) {
44-
qDebug() << "Found _alpha. in: " << it->toStdString().c_str();
44+
//qDebug() << "Found _alpha. in: " << it->toStdString().c_str();
4545
return *it;
4646
}
4747

src/ui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DropArea : public QLabel {
3333
setMinimumSize(400, 400);
3434
setMaximumSize(400, 400);
3535
setWindowFlags(Qt::WindowStaysOnTopHint);
36-
setWindowTitle("Solidify 1.2");
36+
setWindowTitle("Solidify 1.21");
3737
setText("Drag & drop files here"); // Set text
3838
setAlignment(Qt::AlignCenter); // Set alignment to center
3939

0 commit comments

Comments
 (0)