## Smart Resize
(Version 1.0)

[Place this text file in the VirtualDub plugins directory to make it available via the Help button on the filter configuration dialog box. The computer must have an HTML browser, such as Internet Explorer or Netscape, available in its search path.]

VirtualDub's internal resize filter has a very powerful and fast resampling engine, but its user interface is primitive. For example, there is no way to scale the picture by a percentage; you have to hand calculate and enter both the new width and new height. The Smart Resize filter duplicates the internal resize functionality while greatly enhancing the user interface. The basic idea is that a size calculator is added to the filter's dialog box. When enabled, the configuration calculated is exported back into the main filter parameters, which work the same as the internal filter's parameters. Smart Resize supports adjustment of the aspect ratio, several scaling and fitting modes, and "snapping" to required pixel multiples for the output height and/or width. Batch processing is supported so that if the processing parameters are saved with the size calculator enabled, the filter will dynamically calculate the main filter settings based on the parameters of the input clips encountered while processing the batch files. They need not be calculated manually in advance.

This help file will first describe the calculator "pipeline". You'll need to understand this to properly use the filter. Then the configuration options will be described. Finally some usage examples will be presented.

### The Calculator Pipeline

If a clip is loaded into VirtualDub and the Smart Resize filter is added, the Input width and Input height boxes in the Size Calculator will show the dimensions of the frame arriving at the filter. These two values are the input to a pipeline of calculations, as depicted below:

--> Aspect ratio adjust --> Fitting/scaling --> Snapping -->

When the calculator is enabled by checking the Enable checkbox, the output values from the pipeline are calculated and transferred to the main filter configuration and the preview (if any) is refreshed. Any changes to the calculator settings cause an automatic recalculation and update of the main filter parameters. Let us now consider the three stages of the pipeline.

Aspect ratio adjust This stage allows for conversion of the aspect ratio. For example, you might have a source clip from NTSC DV that has a pixel aspect ratio (not frame aspect ratio!) of 11/10 (pixel width/pixel height) and you want to convert it to a 1/1 pixel aspect ratio for display on the PC monitor (PAL/SECAM DV is 54/59). This stage works as follows. The source aspect ratio is SW/SH. The desired aspect ratio is DW/DH. The Input width value is now scaled as follows:

Input width' = Input width * (DW * SH) / (DH * SW)

The Input height is not changed. For example, in the DV case described above the source aspect ratio is 11/10 and the desired aspect ratio is 1/1. The adjustment factor is thus 10/11 and these are the values loaded into the Aspect ratio adjust edit boxes. (If you prefer to simply view these boxes as permitting a horizontal scaling, and then use them that way, that is fine! But the formula above tells you how to determine the desired scaling to convert between aspect ratios.)

Fitting/Scaling This stage takes the values from the previous stage and scales them according to the selected mode. For example, if the Percent mode is selected and 50 entered, the width and height will both be reduced to 50% of their incoming values. Refer to the description of the configuration options for details on the available modes.

Snapping Often we require that the output width and/or height are exact multiples of some number of pixels. For example, many MPEG encoders require the width to be a multiple of 4 pixels. The snapping controls allow this to be done automatically. Note that if both the width and height are snapped, it might occur that to satisfy this, either the aspect ratio must be changed slightly, or the borders of the frame must be padded. The controls allow for selecting the desired treatment in these cases. Refer to the description of the configuration options for details on the available modes.

### The Configuration Options

Enable When this checkbox is checked, the size calculator is enabled. The main filter parameters are automatically calculated and their values updated, but their controls are disabled. To use the filter in batch mode, save the processing settings with Enable checked.

Aspect ratio adjust Using the edit boxes, enter the scaling fraction by which the width is to be scaled (the height is left as is). For example, use 2/1 to double the width. Note that in order to avoid crashing VirtualDub or Windows, the aspect ratio cannot be set higher than 10/1 or lower than 1/10. Sometimes you might want to enter a ratio using high numbers, such as 720/640. The constraint just mentioned would not permit this as the edit boxes can only be typed one at a time. However, the constraint is not enforced if the Enable box is not checked. When the Enable box is subsequently checked the constraint is tested and if it is violated, the aspect ratio is reset to 1/1. Thus, you can enter high numbers by first unchecking the Enable box.

Fit width When this mode is selected, the picture will be scaled (maintaining the aspect ratio) so that the width is made equal to the specified value.

Fit height When this mode is selected, the picture will be scaled (maintaining the aspect ratio) so that the height is made equal to the specified value.

Fit width and height When this mode is selected, the picture will be scaled (maintaining the aspect ratio) so that the width and height both best fit into the frame size defined by the values in the Fit width and Fit height edit boxes.

Fit width and height w/letterbox When this mode is selected, the picture will be scaled (maintaining the aspect ratio) so that the width and height both best fit into the frame size defined by the values in the Fit width and Fit height edit boxes, and either the width or height will be expanded and letterboxed so that the resulting frame is exactly the size defined by the edit boxes. See the Examples section for a typical application. Note that because the output frame size is directly defined by the edit boxes, snapping is not necessary and the snapping controls are disabled in this fitting mode.

Percent When this mode is selected, the picture will be scaled (maintaining the aspect ratio) by the specified percentage value. Do not enter excessively large values that create giant bitmaps or you may crash VirtualDub or Windows.

No enlarge This mode applies to all modes except the Percent mode. When this mode is selected in Fit width mode, the picture will not be enlarged if its width is already equal to or less than the specified fit width value. When this mode is selected in Fit height mode, the picture will not be enlarged if its height is already equal to or less than the specified fit height value. When this mode is selected in Fit width and height or Fit width and height w/letterbox modes, the picture will not be enlarged if the width and height are already equal to or less than the specified frame size. This option makes sense only in batch mode. For example, you might be processing a directory full of clips and you want to ensure that all the clips do not exceed a bounding box, but you don't want any that are already within the bounding box to be enlarged.

No reduce This mode applies to all modes except the Percent mode. When this mode is selected in Fit width mode, the picture will not be reduced if its width is already equal to or greater than the specified fit width value. When this mode is selected in Fit height mode, the picture will not be reduced if its height is already equal to or greater than the specified fit height value. When this mode is selected in Fit width and height or Fit width and height w/letterbox modes, the picture will not be enlarged if the width and height are already equal to or greater than the specified frame size.

Fix width to mult of This mode will cause the output width to be snapped to a multiple of the specified number of pixels.

Fix height to mult of This mode will cause the output height to be snapped to a multiple of the specified number of pixels.

Up/Down/Nearest This mode determines how to change the dimension when a snap is done. Use Up to round up. Use Down to round down. Use Nearest to round to the nearest multiple. Note that when both the width and the height are snapped, and the padding mode is not set to Adjust AR, only the rounding up mode is available (because the resize engine can only pad; it cannot crop).

Pad width/Pad height/Adjust AR These modes are active only when both the width and the height are snapped. These modes determine what to do if the two snaps cannot both be honored without padding or changing the aspect ratio. Use the Adjust AR mode to allow the calculator to change the aspect ratio in order to avoid padding. Use the Pad width mode to allow the calculator to letterbox the picture by padding the two sides. Use the Pad height mode to allow the calculator to letterbox the picture by padding the top and bottom. If padding is applied, it will be reflected in the Frame width and Frame height boxes in the main filter parameters.

### Examples

Example 1 Suppose the user wants to try different picture sizes while ensuring a width that is a multiple of 4. The clip is first loaded and then the filter added. The preview can be enabled. Then the Percent mode is selected and Fit width to mult of is selected and set to 4. The desired percentage is entered.

Example 2 Suppose the user wants to convert a DV clip at an 11/10 pixel aspect ratio for viewing on a PC's 1/1 monitor, and ensure an output width that is a multiple of 16 pixels (to make encoder happy). The clip is loaded and the filter added. The Aspect ratio adjust is set to 10/11. The Fix width to mult of mode is selected and its value set to 16.

Example 3 Suppose the user has a clip that is 512x398, cropped from a 640x480 picture. The user wants to make a 480x480 Video CD. So he must set the Aspect ratio adjust to 3/4 (because the Video CD requires a 1/1 aspect ratio). He sets the fit mode to Fit width and height w/letterbox, and he sets the Fit width and Fit height values to 480.

### Thanks and Credits

The original internal resize filter from which Smart Resize was adapted was created by Avery Lee, the author of VirtualDub. The performance and speed of his resize engine is truly awesome. Gunnar Thalin implemented a stand-alone video calculator. Jon C. Hodgson inspired me to create Smart Resize and assisted during the development process.

For additional information, version updates, and other filters, please go to the following web site:

Filters for VirtualDub
http://sauron.mordor.net/dgraft/index.html

Donald Graft
August 17, 2001
(C) Copyright 2001, All Rights Reserved