@@ -17,13 +17,34 @@ namespace fsb
17
17
{
18
18
// check and handle lodepng error
19
19
// @param i error code
20
- static void checkError (const unsigned int i)
20
+ static inline unsigned int checkError (const unsigned int i)
21
21
{
22
22
if (i != 0 )
23
23
{
24
24
output<level_t ::error>(" FSB: png error: {}" , lodepng_error_text (i));
25
25
}
26
26
checkpoint ();
27
+ return i;
28
+ }
29
+
30
+ static inline void texture_not_found (const std::filesystem::path& path, const bool overworldsky, const std::filesystem::path& save_dir, const std::u8string& sourcefile)
31
+ {
32
+ std::vector<uint8_t > buffer;
33
+ lodepng::State state;
34
+ state.info_png .color .colortype = LCT_RGBA;
35
+ state.info_png .color .bitdepth = 8 ;
36
+ state.encoder .auto_convert = false ;
37
+
38
+ mcpppp::output<level_t ::info>(" (warn) FSB: File not found: {}.png" , c8tomb (sourcefile));
39
+ std::filesystem::create_directories (save_dir);
40
+ lodepng::encode (buffer, { 0 , 0 , 0 , 1 }, 1 , 1 , state);
41
+ lodepng::save_file (buffer, c8tomb ((save_dir / (sourcefile + u8" _top" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
42
+ lodepng::save_file (buffer, c8tomb ((save_dir / (sourcefile + u8" _bottom" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
43
+ lodepng::save_file (buffer, c8tomb ((save_dir / (sourcefile + u8" _north" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
44
+ lodepng::save_file (buffer, c8tomb ((save_dir / (sourcefile + u8" _south" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
45
+ lodepng::save_file (buffer, c8tomb ((save_dir / (sourcefile + u8" _west" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
46
+ lodepng::save_file (buffer, c8tomb ((save_dir / (sourcefile + u8" _east" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
47
+ checkpoint ();
27
48
}
28
49
29
50
// convert optifine image format (1 image for all 6 sides) into fsb image format (1 image per side)
@@ -58,9 +79,16 @@ namespace fsb
58
79
state.info_raw .bitdepth = 8 ;
59
80
60
81
// don't let decode modify original state (later used for encoding)
82
+ // TODO: if unable to load/decode, create 1x1 transparent image
61
83
auto state_copy = state;
62
84
checkError (lodepng::load_file (buffer, c8tomb (entry.path ().generic_u8string ())));
63
- checkError (lodepng::decode (image, w, h, state_copy, buffer));
85
+ unsigned int err = checkError (lodepng::decode (image, w, h, state_copy, buffer));
86
+ if (err)
87
+ {
88
+ output<level_t ::error>(" FSB: corrupted png file, skipping: {}" , c8tomb (entry.path ().generic_u8string ()));
89
+ texture_not_found (path, overworldsky, path / output_path, filename);
90
+ return ;
91
+ }
64
92
if (w % 3 != 0 || h % 2 != 0 )
65
93
{
66
94
output<level_t ::info>(" (warn) FSB: Wrong dimensions: {}\n will be cropped to proper dimensions" , c8tomb (entry.path ().generic_u8string ()));
@@ -423,7 +451,7 @@ namespace fsb
423
451
const std::filesystem::directory_entry image = std::filesystem::directory_entry (std::filesystem::path (image_noext).replace_extension (" .png" ));
424
452
if (image.exists ())
425
453
{
426
- png (path, overworldsky, u8" assets/fabricskyboxes/sky/" + sourcefolder, image, image_noext. filename (). u8string () );
454
+ png (path, overworldsky, u8" assets/fabricskyboxes/sky/" + sourcefolder, image, sourcefile );
427
455
}
428
456
else
429
457
{
@@ -434,18 +462,7 @@ namespace fsb
434
462
{
435
463
fsb_save_dir /= sourcefolder;
436
464
}
437
- output<level_t ::info>(" (warn) FSB: File not found: {}.png" , c8tomb (sourcefolder + sourcefile));
438
- std::filesystem::create_directories (fsb_save_dir);
439
- lodepng::encode (buffer, { 0 , 0 , 0 , 1 }, 1 , 1 , state);
440
- lodepng::save_file (buffer, c8tomb ((fsb_save_dir / (sourcefile + u8" _top" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
441
- lodepng::save_file (buffer, c8tomb ((fsb_save_dir / (sourcefile + u8" _bottom" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
442
- lodepng::save_file (buffer, c8tomb ((fsb_save_dir / (sourcefile + u8" _north" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
443
- lodepng::save_file (buffer, c8tomb ((fsb_save_dir / (sourcefile + u8" _south" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
444
- lodepng::save_file (buffer, c8tomb ((fsb_save_dir / (sourcefile + u8" _west" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
445
- lodepng::save_file (buffer, c8tomb ((fsb_save_dir / (sourcefile + u8" _east" + (overworldsky ? u8" " : u8" _end" ) + u8" .png" )).generic_u8string ()));
446
- buffer.clear ();
447
- buffer.shrink_to_fit ();
448
- checkpoint ();
465
+ texture_not_found (path, overworldsky, fsb_save_dir, sourcefile);
449
466
}
450
467
mcpppp::conv::fixpathchars (sourcefolder);
451
468
mcpppp::conv::fixpathchars (sourcefile);
0 commit comments