43 float min = 999999.0f;
47 for (
int index = 0; index < run; index++ ) {
57 printf(
"%s: %0.2f ms (med %0.1f ms, min %0.1f ms, max %0.1f ms)\n",
name, avg, middle, min, max);
66 fprintf(stderr,
"Failed to load image [%s]!\n", filename_in);
75 fprintf(stderr,
"Create DXT encoder failed!\n");
79 unsigned char* image_compressed = NULL;
80 int image_compressed_size = 0;
82 fprintf(stderr,
"DXT encoder allocation failed!\n");
87 for (
int index = 0; index < run; index++ ) {
90 fprintf(stderr,
"DXT encoder compressing failed!\n");
102 fprintf(stderr,
"Failed to save compressed image [%s]!\n", filename_out);
117 unsigned char* image_compressed = NULL;
118 int image_compressed_size = 0;
120 fprintf(stderr,
"Failed to load compressed image [%s]!\n", filename_in);
128 if ( decoder == NULL ) {
129 fprintf(stderr,
"Create DXT decoder failed!\n");
136 fprintf(stderr,
"DXT decoder allocation failed!\n");
141 for (
int index = 0; index < run; index++ ) {
144 fprintf(stderr,
"DXT decoder decompressing failed!\n");
156 fprintf(stderr,
"Failed to save image [%s]!\n", filename_out);
170 char * ext = strrchr(filename,
'.');
184 if ( strncasecmp(ext,
"rgb", 3) == 0 ) {
187 fprintf(stderr,
"Failed to load image [%s]!\n", filename);
195 unsigned char* image_compressed = NULL;
196 int image_compressed_size = 0;
198 fprintf(stderr,
"Failed to load compressed image [%s]!\n", filename);
214 const char * filename_image = NULL;
215 const char * filename_image_compressed = NULL;
216 if ( strncasecmp(input_ext,
"rgb", 3) == 0 )
217 filename_image = input;
219 filename_image_compressed = input;
220 if ( strncasecmp(output_ext,
"rgb", 3) == 0 )
221 filename_image = output;
223 filename_image_compressed = output;
225 if ( filename_image == NULL || filename_image_compressed == NULL ) {
226 fprintf(stderr,
"Display comparison can't be performed, one file must be RGB image and one compressed image!\n");
232 unsigned char* image_compressed = NULL;
233 int image_compressed_size = 0;
235 fprintf(stderr,
"Failed to load image [%s]!\n", filename_image);
239 fprintf(stderr,
"Failed to load compressed image [%s]!\n", filename_image_compressed);
254 "dxt_compress [options]\n"
255 " -h, --help\t\tprint help\n"
256 " -e, --encode\t\tencode image from RGB format to DXT data buffer\n"
257 " -d, --decode\t\tdecode image from DXT data buffer to RGB format\n"
258 " -s, --size\t\timage size in pixels, e.g. 1920x1080\n"
259 " -i, --input\t\tinput image in RGB format\n"
260 " -o, --output\t\toutput image in RGB format\n"
261 " --display\tdisplay image or compare images\n"
262 " -t, --type\t\tdxt type 'dxt1' or 'dxt5ycocg' (default 'dxt5ycocg')\n"
263 " -f, --format\t\tcolor format 'rgb' or 'yuv' (default 'rgb')\n"
264 " -r, --run\t\tmultiple run times for debugging (default 1)\n"
271 struct option longopts[] = {
272 {
"help", no_argument, 0,
'h'},
273 {
"encode", no_argument, 0,
'e'},
274 {
"decode", no_argument, 0,
'd'},
275 {
"size", required_argument, 0,
's'},
276 {
"input", required_argument, 0,
'i'},
277 {
"output", required_argument, 0,
'o'},
278 {
"display", no_argument, 0, 1 },
279 {
"type", required_argument, 0,
't'},
280 {
"format", required_argument, 0,
'f'},
281 {
"run", required_argument, 0,
'r'},
282 {
"batch", no_argument, 0,
'b'},
292 char input[255] = {
'\0' };
293 char output[255] = {
'\0' };
302 while ( (ch = getopt_long(argc, argv,
"heds:i:o:t:f:b", longopts, &optindex)) != -1 ) {
314 width = atoi(optarg);
315 pos = strstr(optarg,
"x");
316 if ( pos == NULL || width == 0 || (strlen(pos) >= strlen(optarg)) ) {
320 height = atoi(pos + 1);
323 strncpy(input, optarg, 255);
326 strncpy(output, optarg, 255);
329 if ( strcasecmp(optarg,
"dxt1") == 0 )
331 else if ( strcasecmp(optarg,
"dxt5ycocg") == 0 )
335 if ( strcasecmp(optarg,
"rgb") == 0 )
337 else if ( strcasecmp(optarg,
"yuv") == 0 ) {
339 fprintf(stderr,
"yuv not supported!\n");
363 printf(
"Warning: Maximum run times is %d using that number!\n",
RUN_MAX);
368 if ( !batch && input[0] ==
'\0' ) {
369 printf(
"Please supply input image filename!\n");
375 if ( !batch && output[0] ==
'\0' && (encode == 1 || decode == 1) ) {
376 printf(
"Please supply output image filename!\n");
391 fprintf(stderr,
"Create DXT encoder failed!\n");
395 unsigned char* image_compressed = NULL;
396 int image_compressed_size = 0;
398 fprintf(stderr,
"DXT encoder allocation failed!\n");
403 char *in_filename = argv[0];
404 char out_filename[512];
406 printf(
"encoding %s\n", in_filename);
408 snprintf(out_filename, 512,
"%s.dxt", in_filename);
410 fprintf(stderr,
"Failed to load image [%s]!\n", in_filename);
415 fprintf(stderr,
"DXT encoder compressing failed!\n");
420 fprintf(stderr,
"Failed to save compressed image [%s]!\n", out_filename);
433 fprintf(stderr,
"Failed to encode image [%s]!\n", input);
440 if ( encode == 1 && decode == 1 ) {
441 char new_output[255];
442 snprintf(new_output, 255,
"decoded_%s", input);
443 strncpy(input, output, 255);
444 strncpy(output, new_output, 255);
450 fprintf(stderr,
"Failed to decode image [%s]!\n", input);
456 if (
display == 1 && encode == 0 && decode == 0 ) {
457 if ( output[0] !=
'\0' ) {
459 fprintf(stderr,
"Failed to perform comparison for images [%s, %s]!\n", input, output);
464 fprintf(stderr,
"Failed to display image [%s]!\n", input);
int dxt_image_compressed_load_from_file(const char *filename, unsigned char **data, int *data_size)
int dxt_image_destroy(DXT_IMAGE_TYPE *image)
int dxt_image_load_from_file(const char *filename, int width, int height, DXT_IMAGE_TYPE **image)
int dxt_image_save_to_file(const char *filename, DXT_IMAGE_TYPE *image, int width, int height)
int dxt_image_compressed_destroy(unsigned char *image_compressed)
int dxt_image_compressed_save_to_file(const char *filename, unsigned char *image, int image_size)
int dxt_decoder_buffer_free(unsigned char *image)
struct dxt_decoder * dxt_decoder_create(enum dxt_type type, int width, int height, enum dxt_format out_format, int legacy)
int dxt_decoder_buffer_allocate(struct dxt_decoder *decoder, unsigned char **image, int *image_size)
int dxt_decoder_destroy(struct dxt_decoder *decoder)
int dxt_decoder_decompress(struct dxt_decoder *decoder, unsigned char *image_compressed, DXT_IMAGE_TYPE *image)
int dxt_display_image(const char *title, DXT_IMAGE_TYPE *image, int width, int height)
int dxt_display_image_comparison(DXT_IMAGE_TYPE *image, unsigned char *image_compressed, int image_compressed_size, enum dxt_type type, int width, int height)
int dxt_display_image_compressed(const char *title, unsigned char *image_compressed, int image_compressed_size, enum dxt_type type, int width, int height)
int dxt_encoder_buffer_allocate(struct dxt_encoder *encoder, unsigned char **image_compressed, int *image_compressed_size)
int dxt_encoder_compress(struct dxt_encoder *encoder, DXT_IMAGE_TYPE *image, unsigned char *image_compressed)
struct dxt_encoder * dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format format, int legacy)
int dxt_encoder_destroy(struct dxt_encoder *encoder)
int dxt_encoder_buffer_free(unsigned char *image_compressed)
steady_clock::duration duration
int perform_encode(const char *filename_in, const char *filename_out, enum dxt_type type, int width, int height, enum dxt_format format, int display, int run)
int perform_decode(const char *filename_in, const char *filename_out, enum dxt_type type, int width, int height, int display, int run)
const char * get_filename_extension(const char *filename)
void printf_duration(const char *name, int run)
int perform_comparison(const char *input, const char *output, enum dxt_type type, int width, int height, enum dxt_format format)
int perform_display(const char *filename, enum dxt_type type, int width, int height, enum dxt_format format)
This struct represents initialized video display state.