@@ -21,6 +21,7 @@ ID3D11Texture2D* load_tex(ID3D11Device* pd3dDevice, const char* tex_path, bool b
21
21
int xsize = 0 ;
22
22
int ysize = 0 ;
23
23
int components = 0 ;
24
+ stbi_set_flip_vertically_on_load (1 );
24
25
stbi_uc* image = stbi_load (tex_path, &xsize, &ysize, &components, STBI_rgb_alpha);
25
26
if (image == nullptr ) {
26
27
// 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)
139
140
bool parse_cmd (int argc, char ** argv, encode_option& option)
140
141
{
141
142
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 ;
144
145
return true ;
145
146
}
146
147
return false ;
147
148
};
148
149
149
150
for (int i = 2 ; i < argc; ++i) {
150
151
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 )) {
152
158
return false ;
153
159
}
154
160
}
155
161
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 )) {
157
168
return false ;
158
169
}
159
170
}
160
171
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 )) {
162
173
return false ;
163
174
}
164
175
}
@@ -182,7 +193,8 @@ int main(int argc, char** argv)
182
193
std::cout << " encode option setting:\n "
183
194
<< " has_alpha\t " << std::boolalpha << option.has_alpha << std::endl
184
195
<< " 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;
186
198
187
199
HWND hwnd = ::GetDesktopWindow ();
188
200
@@ -199,7 +211,7 @@ int main(int argc, char** argv)
199
211
std::string src_tex = argv[1 ];
200
212
201
213
// 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 ) );
203
215
if (pSrcTexture == nullptr ) {
204
216
std::cout << " load source texture failed! [" << src_tex << " ]" << std::endl;
205
217
return -1 ;
0 commit comments