@@ -145,6 +145,7 @@ static void print_usage()
145145 " -etc1_only: Only unpack to ETC1, skipping the other texture formats during -unpack\n "
146146 " -disable_hierarchical_endpoint_codebooks: Disable hierarchical endpoint codebook usage, slower but higher quality on some compression levels\n "
147147 " -compare_ssim: Compute and display SSIM of image comparison (slow)\n "
148+ " -compare_plot: Display histogram plots in -compare mode\n "
148149 " -bench: UASTC benchmark mode, for development only\n "
149150 " -resample X Y: Resample all input textures to XxY pixels using a box filter\n "
150151 " -resample_factor X: Resample all input textures by scale factor X using a box filter\n "
@@ -296,6 +297,7 @@ class command_line_params
296297 m_etc1_only (false ),
297298 m_fuzz_testing (false ),
298299 m_compare_ssim (false ),
300+ m_compare_plot (false ),
299301 m_bench (false ),
300302 m_parallel_compression (false )
301303 {
@@ -364,6 +366,8 @@ class command_line_params
364366 m_mode = cVersion;
365367 else if (strcasecmp (pArg, " -compare_ssim" ) == 0 )
366368 m_compare_ssim = true ;
369+ else if (strcasecmp (pArg, " -compare_plot" ) == 0 )
370+ m_compare_plot = true ;
367371 else if (strcasecmp (pArg, " -bench" ) == 0 )
368372 m_mode = cBench;
369373 else if (strcasecmp (pArg, " -comp_size" ) == 0 )
@@ -868,6 +872,7 @@ class command_line_params
868872 bool m_etc1_only;
869873 bool m_fuzz_testing;
870874 bool m_compare_ssim;
875+ bool m_compare_plot;
871876 bool m_bench;
872877 bool m_parallel_compression;
873878};
@@ -2749,180 +2754,184 @@ static bool compare_mode(command_line_params &opts)
27492754 save_png (" delta_img_a.png" , delta_img, cImageSaveGrayscale, 3 );
27502755 printf (" Wrote delta_img_a.png\n " );
27512756
2752- uint32_t bins[5 ][512 ];
2753- clear_obj (bins);
2757+ if (opts.m_compare_plot )
2758+ {
2759+ uint32_t bins[5 ][512 ];
2760+ clear_obj (bins);
27542761
2755- running_stat delta_stats[5 ];
2756- basisu::rand rm;
2762+ running_stat delta_stats[5 ];
2763+ basisu::rand rm;
27572764
2758- double avg[5 ];
2759- clear_obj (avg);
2765+ double avg[5 ];
2766+ clear_obj (avg);
27602767
2761- for (uint32_t y = 0 ; y < a.get_height (); y++)
2762- {
2763- for (uint32_t x = 0 ; x < a.get_width (); x++)
2768+ for (uint32_t y = 0 ; y < a.get_height (); y++)
27642769 {
2765- // color_rgba& d = delta_img(x, y);
2766-
2767- for (int c = 0 ; c < 4 ; c++)
2770+ for (uint32_t x = 0 ; x < a.get_width (); x++)
27682771 {
2769- int delta = a (x, y)[c] - b (x, y)[c];
2770-
2771- // delta = clamp<int>((int)std::round(rm.gaussian(70.0f, 10.0f)), -255, 255);
2772-
2773- bins[c][delta + 256 ]++;
2774- delta_stats[c].push (delta);
2772+ // color_rgba& d = delta_img(x, y);
27752773
2776- avg[c] += delta;
2777- }
2778-
2779- int y_delta = a (x, y).get_709_luma () - b (x, y).get_709_luma ();
2780- bins[4 ][y_delta + 256 ]++;
2781- delta_stats[4 ].push (y_delta);
2782-
2783- avg[4 ] += y_delta;
2774+ for (int c = 0 ; c < 4 ; c++)
2775+ {
2776+ int delta = a (x, y)[c] - b (x, y)[c];
27842777
2785- } // x
2786- } // y
2778+ // delta = clamp<int>((int)std::round(rm.gaussian(70.0f, 10.0f)), -255, 255);
27872779
2788- for ( uint32_t i = 0 ; i <= 4 ; i++)
2789- avg[i] /= a. get_total_pixels ( );
2780+ bins[c][delta + 256 ]++;
2781+ delta_stats[c]. push (delta );
27902782
2791- printf (" \n " );
2783+ avg[c] += delta;
2784+ }
27922785
2793- // bins[2][256+-255] = 100000;
2794- // bins[2][256-56] = 50000;
2786+ int y_delta = a (x, y).get_709_luma () - b (x, y).get_709_luma ();
2787+ bins[4 ][y_delta + 256 ]++;
2788+ delta_stats[4 ].push (y_delta);
27952789
2796- const uint32_t X_SIZE = 128 , Y_SIZE = 40 ;
2790+ avg[ 4 ] += y_delta ;
27972791
2798- for (uint32_t c = 0 ; c <= 4 ; c++)
2799- {
2800- std::vector<uint8_t > plot[Y_SIZE + 1 ];
2801- for (uint32_t i = 0 ; i < Y_SIZE; i++)
2802- {
2803- plot[i].resize (X_SIZE + 2 );
2804- memset (plot[i].data (), ' ' , X_SIZE + 1 );
2805- }
2792+ } // x
2793+ } // y
28062794
2807- uint32_t max_val = 0 ;
2808- int max_val_bin_index = 0 ;
2809- int lowest_bin_index = INT_MAX, highest_bin_index = INT_MIN;
2810- double avg_val = 0 ;
2811- double total_val = 0 ;
2812- running_stat bin_stats;
2795+ for (uint32_t i = 0 ; i <= 4 ; i++)
2796+ avg[i] /= a.get_total_pixels ();
28132797
2814- for (int y = -255 ; y <= 255 ; y++)
2815- {
2816- uint32_t val = bins[c][256 + y];
2817- if (!val)
2818- continue ;
2819-
2820- bin_stats.push (y);
2821-
2822- total_val += (double )val;
2798+ printf (" \n " );
28232799
2824- lowest_bin_index = minimum (lowest_bin_index, y) ;
2825- highest_bin_index = maximum (highest_bin_index, y) ;
2800+ // bins[2][256+-255] = 100000 ;
2801+ // bins[2][256-56] = 50000 ;
28262802
2827- if (val > max_val)
2828- {
2829- max_val = val;
2830- max_val_bin_index = y;
2831- }
2832- avg_val += y * (double )val;
2833- }
2834- avg_val /= total_val;
2803+ const uint32_t X_SIZE = 128 , Y_SIZE = 40 ;
28352804
2836- int lo_limit = -(int )X_SIZE / 2 ;
2837- int hi_limit = X_SIZE / 2 ;
2838- for (int x = lo_limit; x <= hi_limit; x++)
2805+ for (uint32_t c = 0 ; c <= 4 ; c++)
28392806 {
2840- uint32_t total = 0 ;
2841- if (x == lo_limit )
2807+ std::vector< uint8_t > plot[Y_SIZE + 1 ] ;
2808+ for ( uint32_t i = 0 ; i < Y_SIZE; i++ )
28422809 {
2843- for ( int i = - 255 ; i <= lo_limit; i++)
2844- total += bins[c][ 256 + i] ;
2810+ plot[i]. resize (X_SIZE + 2 );
2811+ memset (plot[i]. data (), ' ' , X_SIZE + 1 ) ;
28452812 }
2846- else if (x == hi_limit)
2847- {
2848- for (int i = hi_limit; i <= 255 ; i++)
2849- total += bins[c][256 + i];
2850- }
2851- else
2813+
2814+ uint32_t max_val = 0 ;
2815+ int max_val_bin_index = 0 ;
2816+ int lowest_bin_index = INT_MAX, highest_bin_index = INT_MIN;
2817+ double avg_val = 0 ;
2818+ double total_val = 0 ;
2819+ running_stat bin_stats;
2820+
2821+ for (int y = -255 ; y <= 255 ; y++)
28522822 {
2853- total = bins[c][256 + x];
2823+ uint32_t val = bins[c][256 + y];
2824+ if (!val)
2825+ continue ;
2826+
2827+ bin_stats.push (y);
2828+
2829+ total_val += (double )val;
2830+
2831+ lowest_bin_index = minimum (lowest_bin_index, y);
2832+ highest_bin_index = maximum (highest_bin_index, y);
2833+
2834+ if (val > max_val)
2835+ {
2836+ max_val = val;
2837+ max_val_bin_index = y;
2838+ }
2839+ avg_val += y * (double )val;
28542840 }
2841+ avg_val /= total_val;
28552842
2856- uint32_t height = max_val ? (total * Y_SIZE + max_val - 1 ) / max_val : 0 ;
2857-
2858- if (height )
2843+ int lo_limit = -( int )X_SIZE / 2 ;
2844+ int hi_limit = X_SIZE / 2 ;
2845+ for ( int x = lo_limit; x <= hi_limit; x++ )
28592846 {
2860- for (uint32_t y = (Y_SIZE - 1 ) - (height - 1 ); y <= (Y_SIZE - 1 ); y++)
2861- plot[y][x + X_SIZE / 2 ] = ' *' ;
2847+ uint32_t total = 0 ;
2848+ if (x == lo_limit)
2849+ {
2850+ for (int i = -255 ; i <= lo_limit; i++)
2851+ total += bins[c][256 + i];
2852+ }
2853+ else if (x == hi_limit)
2854+ {
2855+ for (int i = hi_limit; i <= 255 ; i++)
2856+ total += bins[c][256 + i];
2857+ }
2858+ else
2859+ {
2860+ total = bins[c][256 + x];
2861+ }
2862+
2863+ uint32_t height = max_val ? (total * Y_SIZE + max_val - 1 ) / max_val : 0 ;
2864+
2865+ if (height)
2866+ {
2867+ for (uint32_t y = (Y_SIZE - 1 ) - (height - 1 ); y <= (Y_SIZE - 1 ); y++)
2868+ plot[y][x + X_SIZE / 2 ] = ' *' ;
2869+ }
28622870 }
2863- }
28642871
2865- printf (" %c delta histogram: total samples: %5.0f, max bin value: %u index: %i (%3.3f%% of total), range %i [%i,%i], weighted mean: %f\n " , " RGBAY" [c], total_val, max_val, max_val_bin_index, max_val * 100 .0f / total_val, highest_bin_index - lowest_bin_index + 1 , lowest_bin_index, highest_bin_index, avg_val);
2866- printf (" bin mean: %f, bin std deviation: %f, non-zero bins: %u\n " , bin_stats.get_mean (), bin_stats.get_std_dev (), bin_stats.get_num ());
2867- printf (" delta mean: %f, delta std deviation: %f\n " , delta_stats[c].get_mean (), delta_stats[c].get_std_dev ());
2868- printf (" \n " );
2872+ printf (" %c delta histogram: total samples: %5.0f, max bin value: %u index: %i (%3.3f%% of total), range %i [%i,%i], weighted mean: %f\n " , " RGBAY" [c], total_val, max_val, max_val_bin_index, max_val * 100 .0f / total_val, highest_bin_index - lowest_bin_index + 1 , lowest_bin_index, highest_bin_index, avg_val);
2873+ printf (" bin mean: %f, bin std deviation: %f, non-zero bins: %u\n " , bin_stats.get_mean (), bin_stats.get_std_dev (), bin_stats.get_num ());
2874+ printf (" delta mean: %f, delta std deviation: %f\n " , delta_stats[c].get_mean (), delta_stats[c].get_std_dev ());
2875+ printf (" \n " );
28692876
2870- for (uint32_t y = 0 ; y < Y_SIZE; y++)
2871- printf (" %s\n " , (char *)plot[y].data ());
2877+ for (uint32_t y = 0 ; y < Y_SIZE; y++)
2878+ printf (" %s\n " , (char *)plot[y].data ());
28722879
2873- char tics[1024 ];
2874- tics[0 ] = ' \0 ' ;
2875- char tics2[1024 ];
2876- tics2[0 ] = ' \0 ' ;
2880+ char tics[1024 ];
2881+ tics[0 ] = ' \0 ' ;
2882+ char tics2[1024 ];
2883+ tics2[0 ] = ' \0 ' ;
28772884
2878- for (int x = 0 ; x <= (int )X_SIZE; x++)
2879- {
2880- char buf[64 ];
2881- if (x == X_SIZE / 2 )
2885+ for (int x = 0 ; x <= (int )X_SIZE; x++)
28822886 {
2883- while (( int ) strlen (tics) < x)
2884- strcat (tics, " . " );
2885-
2886- while ((int )strlen (tics2 ) < x)
2887- strcat (tics2 , " " );
2887+ char buf[ 64 ];
2888+ if (x == X_SIZE / 2 )
2889+ {
2890+ while ((int )strlen (tics ) < x)
2891+ strcat (tics , " . " );
28882892
2889- sprintf (buf, " 0" );
2890- strcat (tics, buf);
2891- }
2892- else if (((x & 7 ) == 0 ) || (x == X_SIZE))
2893- {
2894- while ((int )strlen (tics) < x)
2895- strcat (tics, " ." );
2896-
2897- while ((int )strlen (tics2) < x)
2898- strcat (tics2, " " );
2893+ while ((int )strlen (tics2) < x)
2894+ strcat (tics2, " " );
28992895
2900- int v = (x - (int )X_SIZE / 2 );
2901- sprintf (buf, " %i" , v / 10 );
2902- strcat (tics, buf);
2903-
2904- if (v < 0 )
2896+ sprintf (buf, " 0" );
2897+ strcat (tics, buf);
2898+ }
2899+ else if (((x & 7 ) == 0 ) || (x == X_SIZE))
29052900 {
2906- if (-v < 10 )
2907- sprintf (buf, " %i" , v % 10 );
2901+ while ((int )strlen (tics) < x)
2902+ strcat (tics, " ." );
2903+
2904+ while ((int )strlen (tics2) < x)
2905+ strcat (tics2, " " );
2906+
2907+ int v = (x - (int )X_SIZE / 2 );
2908+ sprintf (buf, " %i" , v / 10 );
2909+ strcat (tics, buf);
2910+
2911+ if (v < 0 )
2912+ {
2913+ if (-v < 10 )
2914+ sprintf (buf, " %i" , v % 10 );
2915+ else
2916+ sprintf (buf, " %i" , -v % 10 );
2917+ }
29082918 else
2909- sprintf (buf, " %i" , -v % 10 );
2919+ sprintf (buf, " %i" , v % 10 );
2920+ strcat (tics2, buf);
29102921 }
29112922 else
2912- sprintf (buf, " %i" , v % 10 );
2913- strcat (tics2, buf);
2914- }
2915- else
2916- {
2917- while ((int )strlen (tics) < x)
2918- strcat (tics, " ." );
2923+ {
2924+ while ((int )strlen (tics) < x)
2925+ strcat (tics, " ." );
2926+ }
29192927 }
2928+ printf (" %s\n " , tics);
2929+ printf (" %s\n " , tics2);
2930+
2931+ printf (" \n " );
29202932 }
2921- printf (" %s\n " , tics);
2922- printf (" %s\n " , tics2);
29232933
2924- printf (" \n " );
2925- }
2934+ } // display_plot
29262935
29272936 return true ;
29282937}
0 commit comments