6 #define STB_IMAGE_IMPLEMENTATION
7 #define NBVTF_SHOW_STDERR
11 // Find file path extension, returns NULL if no ext (0x00)
12 char *str_findext( char *szPath
, char const delim
)
32 // gets rid of extension on string only left with folder/filename
33 void path_stripext( char *szPath
)
38 if( !(start
= str_findext( szPath
, '/' )) )
43 if( (point
= str_findext( start
, '.' )) )
52 EImageFormat_t
format_from_str( const char *str
)
54 if( !strcmp( str
, "dxt1" ) )
55 return k_EImageFormat_DXT1
;
56 if( !strcmp( str
, "dxt5" ) )
57 return k_EImageFormat_DXT5
;
58 if( !strcmp( str
, "rgb8" ) )
59 return k_EImageFormat_BGR888
;
60 if( !strcmp( str
, "rgba8" ) )
61 return k_EImageFormat_ABGR8888
;
63 return k_EImageFormat_NONE
;
66 EImageFormat_t
format_in_path( const char *path
)
70 strcpy( filepath
, path
);
71 path_stripext( filepath
);
73 char *format_str
= str_findext( filepath
, '.' );
78 fmt
= format_from_str( format_str
);
86 return k_EImageFormat_DXT1
;
89 void auto_output( const char *path
, char *dest
)
92 path_stripext( dest
);
93 strcat( dest
, ".vtf" );
96 int main( int argc
, char *argv
[] )
101 EImageFormat_t format
= k_EImageFormat_NONE
;
105 printf( "Usage: vmt_cmd <optional_format> input_file<.format_in_path>.png\nSupported Formats:\n\trgb8, rgba8, dxt1, dxt5\n" );
111 path_source
= argv
[2];
112 format
= format_from_str( argv
[1] );
117 path_source
= argv
[1];
118 format
= format_in_path( path_source
);
123 fprintf( stderr
, "tovtf: error with format choice. Unsupported\n" );
127 printf( "tovtf: Creating vtf with format '%s'\n", vtf_format_strings
[ format
] );
129 auto_output( path_source
, dest
);
131 nbvtf_convert( path_source
, 0, 0, 1, format
, 16, 0x00, dest
);