- /* Verify we're still within max dimensions */
- if( job->maxWidth && width > job->maxWidth )
- width = job->maxWidth - (mod/2);
- if( job->maxHeight && height > job->maxHeight )
- height = job->maxHeight - (mod/2);
-
- /* Re-ensure we have picture dimensions that divide cleanly. */
- width = MULTIPLE_MOD( width, mod );
- height = MULTIPLE_MOD( height, mod );
+ /* Bind to max dimensions */
+ if( maxWidth && width > maxWidth )
+ {
+ width = maxWidth;
+ // If we are keeping the display aspect, then we are going
+ // to be modifying the PAR anyway. So it's preferred
+ // to let the width/height stray some from the original
+ // requested storage aspect.
+ //
+ // But otherwise, PAR and DAR will change the least
+ // if we stay as close as possible to the requested
+ // storage aspect.
+ if ( !job->anamorphic.keep_display_aspect )
+ {
+ height = ((double)width / storage_aspect) + 0.5;
+ height = MULTIPLE_MOD( height, mod);
+ }
+ }
+ if( maxHeight && height > maxHeight )
+ {
+ height = maxHeight;
+ // Ditto, see comment above
+ if ( !job->anamorphic.keep_display_aspect )
+ {
+ width = ((double)height * storage_aspect) + 0.5;
+ width = MULTIPLE_MOD( width, mod);
+ }
+ }