@@ -671,6 +671,35 @@ u64min(uint64_t a, uint64_t b) {
671
671
return (a < b ) ? a : b ;
672
672
}
673
673
674
+ static bool //
675
+ resize_wh (int * inout_w , int * inout_h , int dst_wh ) {
676
+ // Check arguments.
677
+ if (!inout_w || !inout_h || (dst_wh <= 0 ) || (0x4000 < dst_wh ) || //
678
+ (* inout_w <= 0 ) || (0xffffff < * inout_w ) || //
679
+ (* inout_h <= 0 ) || (0xffffff < * inout_h )) {
680
+ printf ("main: resize failed: invalid argument\n" );
681
+ return false;
682
+ }
683
+
684
+ // Compute dst width × height from src width × height.
685
+ uint64_t dw = 0 ;
686
+ uint64_t dh = 0 ;
687
+ uint64_t sw = (uint64_t )(* inout_w );
688
+ uint64_t sh = (uint64_t )(* inout_h );
689
+ if (sw < sh ) {
690
+ dw = intmax (1 , (int )(((sw * dst_wh * 2 ) + sh ) / (2 * sh )));
691
+ dh = dst_wh ;
692
+ } else {
693
+ dw = dst_wh ;
694
+ dh = intmax (1 , (int )(((sh * dst_wh * 2 ) + sw ) / (2 * sw )));
695
+ }
696
+
697
+ // Return width and height.
698
+ * inout_w = (int )dw ;
699
+ * inout_h = (int )dh ;
700
+ return true;
701
+ }
702
+
674
703
static unsigned char * //
675
704
resize (int * inout_w ,
676
705
int * inout_h ,
@@ -808,8 +837,21 @@ handle(const char* filename,
808
837
elapsed_micros = micros_since_start (& now );
809
838
#endif
810
839
811
- printf ("\n%s (%" PRIu64 " bytes, %" PRIi64 " microseconds)\n" , filename ,
812
- filesize , elapsed_micros );
840
+ char resize_info_string [64 ];
841
+ resize_info_string [0 ] = 0 ;
842
+ if (g_flags .resize > 0 ) {
843
+ int resize_w = src_w ;
844
+ int resize_h = src_h ;
845
+ if (!resize_wh (& resize_w , & resize_h , g_flags .resize )) {
846
+ stbi_image_free (src_pixels );
847
+ return ;
848
+ }
849
+ snprintf (resize_info_string , sizeof (resize_info_string ), " → %d×%d" ,
850
+ resize_w , resize_h );
851
+ }
852
+
853
+ printf ("\n%s (%" PRIu64 " bytes, %d×%d%s pixels, %" PRIi64 " microseconds)\n" ,
854
+ filename , filesize , src_w , src_h , resize_info_string , elapsed_micros );
813
855
814
856
if (!src_pixels ) {
815
857
printf ("%s\n" , stbi_failure_reason ());
0 commit comments