d5012791fea0192b11988ece056d3614a3328ca6
6 #define STB_IMAGE_IMPLEMENTATION
7 #define NBVTF_SHOW_STDERR
10 // Find file path extension, returns NULL if no ext (0x00)
11 char *str_findext( char *szPath
, char const delim
)
31 // gets rid of extension on string only left with folder/filename
32 void path_stripext( char *szPath
)
37 if( !(start
= str_findext( szPath
, '/' )) )
42 if( (point
= str_findext( start
, '.' )) )
51 EImageFormat_t
format_from_str( const char *str
)
53 if( !strcmp( str
, "dxt1" ) )
54 return k_EImageFormat_DXT1
;
55 if( !strcmp( str
, "dxt5" ) )
56 return k_EImageFormat_DXT5
;
57 if( !strcmp( str
, "rgb8" ) )
58 return k_EImageFormat_BGR888
;
59 if( !strcmp( str
, "rgba8" ) )
60 return k_EImageFormat_ABGR8888
;
62 return k_EImageFormat_NONE
;
65 EImageFormat_t
format_in_path( const char *path
)
69 strcpy( filepath
, path
);
70 path_stripext( filepath
);
72 char *format_str
= str_findext( filepath
, '.' );
77 fmt
= format_from_str( format_str
);
85 return k_EImageFormat_DXT1
;
88 void auto_output( const char *path
, char *dest
)
91 path_stripext( dest
);
92 strcat( dest
, ".vtf" );
95 int main( int argc
, char *argv
[] )
100 EImageFormat_t format
= k_EImageFormat_NONE
;
104 printf( "Usage: vmt_cmd <optional_format> input_file<.format_in_path>.png\nSupported Formats:\n\trgb8, rgba8, dxt1, dxt5\n" );
110 path_source
= argv
[2];
111 format
= format_from_str( argv
[1] );
116 path_source
= argv
[1];
117 format
= format_in_path( path_source
);
122 fprintf( stderr
, "tovtf: error with format choice. Unsupported\n" );
126 printf( "tovtf: Creating vtf with format '%s'\n", vtf_format_strings
[ format
] );
128 auto_output( path_source
, dest
);
130 nbvtf_convert( path_source
, 0, 0, 1, format
, 16, 0x00, dest
);