- //fprintf( stderr, "composite: real %dx%d scaled %dx%d normalised %dx%d\n", real_width, real_height, scaled_width, scaled_height, normalised_width, normalised_height );
+ double output_sar = ( double ) geometry->nw / geometry->nh / output_ar;
+
+ // We always normalise pixel aspect by requesting a larger than normal
+ // image in order to maximise usage of the bounding rectangle
+
+ // These calcs are optimised by reducing factors in equations
+ if ( output_sar < 1.0 )
+ // If the output is skinny pixels (PAL) then stretch our input vertically
+ // derived from: input_sar / output_sar * real_height
+ scaled_height = ( double )real_width / input_ar / output_sar;
+
+ else
+ // If the output is fat pixels (NTSC) then stretch our input horizontally
+ // derived from: output_sar / input_sar * real_width
+ scaled_width = output_sar * real_height * input_ar;
+
+// fprintf( stderr, "composite: real %dx%d scaled %dx%d normalised %dx%d\n", real_width, real_height, scaled_width, scaled_height, normalised_width, normalised_height );