Skip to content

Commit 733f63a

Browse files
committed
“encode in linear color space” as an opiton
1 parent ec3e289 commit 733f63a

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

astc_encode.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
struct encode_option
1515
{
1616
bool is4x4;
17+
bool is6x6;
1718
bool is_normal_map;
1819
bool has_alpha;
20+
bool srgb;
1921
encode_option() : is4x4(true)
22+
, is6x6(false)
2023
, is_normal_map(false)
2124
, has_alpha(false)
25+
, srgb(false)
2226
{
2327
}
2428
};

main.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ID3D11Texture2D* load_tex(ID3D11Device* pd3dDevice, const char* tex_path, bool b
2121
int xsize = 0;
2222
int ysize = 0;
2323
int components = 0;
24+
stbi_set_flip_vertically_on_load(1);
2425
stbi_uc* image = stbi_load(tex_path, &xsize, &ysize, &components, STBI_rgb_alpha);
2526
if (image == nullptr) {
2627
// if we haven't returned, it's because we failed to load the file.
@@ -139,26 +140,36 @@ void strip_file_extension(std::string &file_path)
139140
bool parse_cmd(int argc, char** argv, encode_option& option)
140141
{
141142
auto func_arg_value = [](int index, int argc, char** argv, bool &ret) -> bool {
142-
if (index < argc && std::isdigit(*(argv[index])) > 0) {
143-
ret = (argv[index] != std::string("0"));
143+
if (index < argc && *(argv[index]) == '-') {
144+
ret = true;
144145
return true;
145146
}
146147
return false;
147148
};
148149

149150
for (int i = 2; i < argc; ++i) {
150151
if (argv[i] == std::string("-4x4")) {
151-
if (!func_arg_value(i + 1, argc, argv, option.is4x4)) {
152+
if (!func_arg_value(i, argc, argv, option.is4x4)) {
153+
return false;
154+
}
155+
}
156+
else if (argv[i] == std::string("-6x6")) {
157+
if (!func_arg_value(i, argc, argv, option.is6x6)) {
152158
return false;
153159
}
154160
}
155161
else if (argv[i] == std::string("-norm")) {
156-
if (!func_arg_value(i + 1, argc, argv, option.is_normal_map)) {
162+
if (!func_arg_value(i, argc, argv, option.is_normal_map)) {
163+
return false;
164+
}
165+
}
166+
else if (argv[i] == std::string("-srgb")) {
167+
if (!func_arg_value(i, argc, argv, option.srgb)) {
157168
return false;
158169
}
159170
}
160171
else if (argv[i] == std::string("-alpha")) {
161-
if (!func_arg_value(i + 1, argc, argv, option.has_alpha)) {
172+
if (!func_arg_value(i, argc, argv, option.has_alpha)) {
162173
return false;
163174
}
164175
}
@@ -182,7 +193,8 @@ int main(int argc, char** argv)
182193
std::cout << "encode option setting:\n"
183194
<< "has_alpha\t" << std::boolalpha << option.has_alpha << std::endl
184195
<< "is 4x4 block\t" << option.is4x4 << std::endl
185-
<< "normal map\t" << option.is_normal_map << std::endl;
196+
<< "normal map\t" << option.is_normal_map << std::endl
197+
<< "encode in gamma color space\t" << option.srgb << std::endl;
186198

187199
HWND hwnd = ::GetDesktopWindow();
188200

@@ -199,7 +211,7 @@ int main(int argc, char** argv)
199211
std::string src_tex = argv[1];
200212

201213
// shader resource view
202-
ID3D11Texture2D* pSrcTexture = load_tex(pd3dDevice, src_tex.c_str(), !option.is_normal_map);
214+
ID3D11Texture2D* pSrcTexture = load_tex(pd3dDevice, src_tex.c_str(), option.srgb && (!option.is_normal_map));
203215
if (pSrcTexture == nullptr) {
204216
std::cout << "load source texture failed! [" << src_tex << "]" << std::endl;
205217
return -1;

textures/leaf.astc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)