SimpleResize

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (Syntax and Parameters: typo)
m
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{FilterCat4|External_filters|Plugins|Adjustment_filters|Resizers}}
+
{{FilterCat5|External_filters|Plugins|Plugins_x64|Adjustment_filters|Resizers}}
 
{{Filter3
 
{{Filter3
| {{Author/Tom Barry}}
+
|1={{Author/Tom Barry}}
| v0.3.3.0
+
|2=v0.3.5.0
| [http://web.archive.org/web/20111205012101/http://neuron2.net/trbarry/SimpleResize.zip SimpleResize.zip]
+
|3=[https://drive.google.com/file/d/1laqsJCOkOwc1KD85d3Ymw-nzzZLa3BQK SimpleResize-0.3.5.7z]
| Resize  
+
|4=Resize  
 
|5=[http://www.gnu.org/licenses/gpl-2.0.txt GPLv2]
 
|5=[http://www.gnu.org/licenses/gpl-2.0.txt GPLv2]
 
|6=[http://forum.doom9.org/showthread.php?t=33753 Doom9 Thread]}}
 
|6=[http://forum.doom9.org/showthread.php?t=33753 Doom9 Thread]}}
Line 13: Line 13:
 
*{{Template:FuncDef3|SimpleResize}} will do a very simple 2 tap linear interpolation.  It is unfiltered which means it will not soften much.
 
*{{Template:FuncDef3|SimpleResize}} will do a very simple 2 tap linear interpolation.  It is unfiltered which means it will not soften much.
  
*{{Template:FuncDef3|WarpedResize}} will do a non-linear stretch/squeeze in both the horizontal and vertical dimensions. This can be useful when you want to change the aspect ratio of a video clip and have it mostly distorted at the top, bottom, and side edges. This is mostly experimental but I added it because it required few code changes and almost zero performance penalty.<br>
+
*{{Template:FuncDef3|WarpedResize}} will do a non-linear stretch/squeeze in both the horizontal and vertical dimensions. This can be useful when you want to change the aspect ratio of a video clip and have it mostly distorted at the top, bottom, and side edges. This is mostly experimental but I added it because it required few code changes and almost zero performance penalty. See the [[#Examples|Examples]] section below.<br>
  
 
*{{Template:FuncDef3|InterlacedResize}} and {{Template:FuncDef3|InterlacedWarpedResize}} work like <tt>SimpleResize</tt> and <tt>WarpedResize</tt> but are designed to operate on interlaced source, without either blending even/odd data or messing up the coordinates because of the even/odd line offsets. Theoretically these can lose a small amount of vertical detail or confuse a subsequent deinterlace or IVTC function but so far in my own testing I have not found it to be a problem.  So if you intend to keep your video in interlaced form, certainly use these.  And if you are downsizing you may find that doing the <tt>InterlacedResize</tt> first before a more costly deinterlacing step can give you a small performance advantage on other material. But this is still experimental. YMMV.
 
*{{Template:FuncDef3|InterlacedResize}} and {{Template:FuncDef3|InterlacedWarpedResize}} work like <tt>SimpleResize</tt> and <tt>WarpedResize</tt> but are designed to operate on interlaced source, without either blending even/odd data or messing up the coordinates because of the even/odd line offsets. Theoretically these can lose a small amount of vertical detail or confuse a subsequent deinterlace or IVTC function but so far in my own testing I have not found it to be a problem.  So if you intend to keep your video in interlaced form, certainly use these.  And if you are downsizing you may find that doing the <tt>InterlacedResize</tt> first before a more costly deinterlacing step can give you a small performance advantage on other material. But this is still experimental. YMMV.
 
<br>
 
<br>
 
== Requirements ==
 
== Requirements ==
* AviSynth 2.5.8 or later
+
* [x86]: [[AviSynth+]] or [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6]
 +
* [x64]: [[AviSynth+]]
 
* Supported color formats: [[YUY2]], [[YV12]]
 
* Supported color formats: [[YUY2]], [[YV12]]
  
Line 53: Line 54:
  
 
==Examples==
 
==Examples==
'''SimpleResize'''<br>
+
====SimpleResize====
Assume you have a 1920x1080 clip that you want to resize to 1280x720.
+
* Assume you have a 1920x1080 clip that you want to resize to 1280x720.
 +
<div {{BoxWidthIndent|46|1}} >
 
  [[AviSource]]("blah.avi")
 
  [[AviSource]]("blah.avi")
  SimpleResize(1280,720) #(width, height)
+
  SimpleResize(1280,720) # (width, height)
 
+
</div>
'''WarpResized'''<br>
+
====WarpedResize====
An example image of using {{Template:FuncDef3|WarpedResize}} for this can be seen in [http://web.archive.org/web/20110612082948/http://neuron2.net/trbarry/warptest.jpg WarpTest.jpg]. This image was from a short HDTV digital capture that was at a 1280x720 resolution, a 16:9 aspect ratio. It was downsized and warped to a 640x480  4:3 aspect ratio using the following script command:
+
* An example image of using {{Template:FuncDef3|WarpedResize}} for this can be seen in [http://web.archive.org/web/20110612082948/http://neuron2.net/trbarry/warptest.jpg WarpTest.jpg]. This image was from a short HDTV digital capture that was at a 1280x720 resolution, a 16:9 aspect ratio. It was downsized and warped to a 640x480  4:3 aspect ratio using the following script command:
 +
<div {{BoxWidthIndent|46|1}} >
 
  WarpedResize(640, 480, 1.15, 0.95) # (width, height, hWarp, vWarp)
 
  WarpedResize(640, 480, 1.15, 0.95) # (width, height, hWarp, vWarp)
Also, for an example of a 4:3 capture warped to fit on a 16:9 screen see [http://web.archive.org/web/20110627220545/http://neuron2.net/trbarry/Warptest2.jpg WarpTest2.jpg].
+
</div>
<br>
+
* Also, for an example of a 4:3 capture warped to fit on a 16:9 screen see [http://web.archive.org/web/20110627220545/http://neuron2.net/trbarry/Warptest2.jpg WarpTest2.jpg].
 +
 
 +
* There is a bug in {{Template:FuncDef3|WarpedResize}} with [[YV12]] sources (fixed in v0.3.5.0) &ndash; see [http://forum.doom9.org/showthread.php?p=1770004#post1770004 here] (doom9.org) for a report. Use the following script to work around the problem:
 +
<div {{BoxWidthIndent|56|1}} >
 +
## fix WarpedResize YV12 chroma bug; make warp arguments optional
 +
function WarpedResize2(clip C, int width, int height, float "hWarp", float "vWarp")
 +
{
 +
    [[Internal_functions/Assert|Assert]](C.IsYV12,
 +
    \  "WarpedResize2: source must be YV12")   
 +
    Assert(width % 4 == 0,
 +
    \  "WarpedResize2: 'width' arg must be mod 4")
 +
    Assert(height % 4 == 0,
 +
    \  "WarpedResize2: 'height' arg must be mod 4")
 +
   
 +
    hWarp = [[Internal functions/Default|Default]](hWarp, 1.0)
 +
    vWarp = Default(vWarp, 1.0)
 +
   
 +
    U = C.[[UToY]] .WarpedResize(width / 2, height / 2, hWarp, vWarp)
 +
    V = C.VToY .WarpedResize(width / 2, height / 2, hWarp, vWarp)
 +
    Y = C      .WarpedResize(width, height, hWarp, vWarp)
 +
   
 +
    return [[YToUV]](U, V, Y)
 +
}
 +
</div>
 +
* Squeezing aspect ratio: 21:9&rarr;16:9
 +
:Here is a comparison of adapting a widescreen image to a narrower target format, starting with [[Resize]]+[[AddBorders]]:
 +
:[[File:Sintel_frm6291_aspect_1_letterbox.jpg|600px]]
 +
 
 +
:next, [[Crop]]:
 +
:[[File:Sintel_frm6291_aspect_2_crop.jpg|600px]]
 +
 
 +
:and finally, '''WarpedResize''':
 +
:[[File:Sintel_frm6291_aspect_3_warp.jpg|600px]]
 +
:(the numbers across the bottom have been added for illustration purposes)
 +
<div {{BoxWidthIndent|42|2}} >
 +
''generated with:''
 +
## source = 1690x720
 +
[[Subtitle]]("9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9",
 +
\      align=2, size=[[Clip_properties|Height]]*0.12, font="Courier New",
 +
\      text_color=$99ffff00, halo_color=$ff000000)
 +
[[#WarpedResize|WarpedResize2]](1280, 720, hWarp=1.28)
 +
</div>
 
<br>
 
<br>
 
==Notes to Mathematicians: (and questions)==
 
==Notes to Mathematicians: (and questions)==
Line 85: Line 129:
 
== Changelog ==
 
== Changelog ==
 
  Version      Date            Changes<br>
 
  Version      Date            Changes<br>
 +
v0.3.5.0      2020/06/17      - Changes by Asd-g
 +
                              - Fixed memory leak
 +
                              - Fixed WarpedResize YV12 processing
 +
v0.3.4.0      2020/05/18      - Changes by Asd-g
 +
                              - Update to AviSynth+'s v8 interface
 +
                              - x64 version: used the original source code and just replaced 32-bit
 +
                                registers with 64-bit registers
 +
                              - Compiled with MSVC 2019 (Clang 10), x86 and x64 build included
 
  v0.3.3.0      2003/01/16      - AviSynth 2.5 YV12 support, AvisynthPluginit2
 
  v0.3.3.0      2003/01/16      - AviSynth 2.5 YV12 support, AvisynthPluginit2
 
  v0.3.2.0      2002/09/16      - Fix horizontal chroma shift bug
 
  v0.3.2.0      2002/09/16      - Fix horizontal chroma shift bug
Line 98: Line 150:
 
!!width="150px"| Download
 
!!width="150px"| Download
 
!!width="150px"| Mirror
 
!!width="150px"| Mirror
 +
|-
 +
!v0.3.5.0
 +
|[https://drive.google.com/file/d/1laqsJCOkOwc1KD85d3Ymw-nzzZLa3BQK SimpleResize-0.3.5.7z]
 +
|[https://web.archive.org/web/20200617162128if_/https://files.videohelp.com/u/223002/SimpleResize-0.3.5.7z SimpleResize-0.3.5.7z]
 +
|-
 +
!v0.3.4.0
 +
|[https://www.dropbox.com/s/hlj41rc91uloa0o/SimpleResize-0.3.4.7z?dl=1 SimpleResize-0.3.4.7z]
 +
|[https://web.archive.org/web/20200613002231if_/https://files.videohelp.com/u/223002/SimpleResize-0.3.4.7z SimpleResize-0.3.4.7z]
 
|-
 
|-
 
!v0.3.3.0
 
!v0.3.3.0
|[http://web.archive.org/web/20111205012101/http://neuron2.net/trbarry/SimpleResize.zip SimpleResize.zip]
+
|[https://web.archive.org/web/20111205012101if_/http://neuron2.net/trbarry/SimpleResize.zip SimpleResize.zip]
 
|[http://www.avisynth.nl/users/warpenterprises/files/simpleresize_5F25_dll_20030121.zip simpleresize_25_dll_20030121.zip]
 
|[http://www.avisynth.nl/users/warpenterprises/files/simpleresize_5F25_dll_20030121.zip simpleresize_25_dll_20030121.zip]
 
|}
 
|}

Latest revision as of 19:37, 26 June 2020

Abstract
Author Tom Barry
Version v0.3.5.0
Download SimpleResize-0.3.5.7z
Category Resize
License GPLv2
Discussion Doom9 Thread


Contents

[edit] Description

SimpleResize is an AviSynth plugin with 4 resizing filters:

  • SimpleResize will do a very simple 2 tap linear interpolation. It is unfiltered which means it will not soften much.
  • WarpedResize will do a non-linear stretch/squeeze in both the horizontal and vertical dimensions. This can be useful when you want to change the aspect ratio of a video clip and have it mostly distorted at the top, bottom, and side edges. This is mostly experimental but I added it because it required few code changes and almost zero performance penalty. See the Examples section below.
  • InterlacedResize and InterlacedWarpedResize work like SimpleResize and WarpedResize but are designed to operate on interlaced source, without either blending even/odd data or messing up the coordinates because of the even/odd line offsets. Theoretically these can lose a small amount of vertical detail or confuse a subsequent deinterlace or IVTC function but so far in my own testing I have not found it to be a problem. So if you intend to keep your video in interlaced form, certainly use these. And if you are downsizing you may find that doing the InterlacedResize first before a more costly deinterlacing step can give you a small performance advantage on other material. But this is still experimental. YMMV.


[edit] Requirements

  • MMX capable CPU
    • It will run faster on SSE2 capable CPU's if the target width is a multiple of 8 pixels and if the data starts on an 8 pixel boundary. I don't know if prior Clip() commands affect this or not.


[edit] Syntax and Parameters

SimpleResize (clip, int, int)
InterlacedResize (clip, int, int)
WarpedResize (clip, int, int, float, float)
InterlacedWarpedResize (clip, int, int, float, float)


clip   =
Input clip.


int   =
int   =
width, height: target width and height.


float   =
float   =
hWarp, vWarp: horizontal and vertical warp factors. These are decimal number, usually between .8 and 1.3 that determine how non-linear you really want the output to be.
  • Values above 1.0 cause the output image to be stretched more in the middle and squeezed at the edges. Values below 1.0 will do the reverse.
  • Specifying 1.0 for either of them will do a linear resize in that dimension, just as you would get using SimpleResize.
  • Values far from 1.0 will give some very strange results. See the "Notes to Mathematicians" below.
One reason to use WarpedResize would be when you have a clip with a 16:9 aspect ratio and want to resize it for a 4:3 aspect ratio display without either clipping off valuable info or having to display black bars. (or vice versa).


  • Note: all parameters are unnamed and do not have a default so they must be specified.


[edit] Examples

[edit] SimpleResize

  • Assume you have a 1920x1080 clip that you want to resize to 1280x720.
AviSource("blah.avi")
SimpleResize(1280,720) # (width, height)

[edit] WarpedResize

  • An example image of using WarpedResize for this can be seen in WarpTest.jpg. This image was from a short HDTV digital capture that was at a 1280x720 resolution, a 16:9 aspect ratio. It was downsized and warped to a 640x480 4:3 aspect ratio using the following script command:
WarpedResize(640, 480, 1.15, 0.95) # (width, height, hWarp, vWarp)
  • Also, for an example of a 4:3 capture warped to fit on a 16:9 screen see WarpTest2.jpg.
  • There is a bug in WarpedResize with YV12 sources (fixed in v0.3.5.0) – see here (doom9.org) for a report. Use the following script to work around the problem:
## fix WarpedResize YV12 chroma bug; make warp arguments optional 
function WarpedResize2(clip C, int width, int height, float "hWarp", float "vWarp")
{
    Assert(C.IsYV12, 
    \   "WarpedResize2: source must be YV12")     
    Assert(width % 4 == 0, 
    \   "WarpedResize2: 'width' arg must be mod 4")
    Assert(height % 4 == 0, 
    \   "WarpedResize2: 'height' arg must be mod 4")
   
    hWarp = Default(hWarp, 1.0)
    vWarp = Default(vWarp, 1.0)
   
    U = C.UToY .WarpedResize(width / 2, height / 2, hWarp, vWarp)
    V = C.VToY .WarpedResize(width / 2, height / 2, hWarp, vWarp)
    Y = C      .WarpedResize(width, height, hWarp, vWarp)
    
    return YToUV(U, V, Y)
}
  • Squeezing aspect ratio: 21:9→16:9
Here is a comparison of adapting a widescreen image to a narrower target format, starting with Resize+AddBorders:
Sintel frm6291 aspect 1 letterbox.jpg
next, Crop:
Sintel frm6291 aspect 2 crop.jpg
and finally, WarpedResize:
Sintel frm6291 aspect 3 warp.jpg
(the numbers across the bottom have been added for illustration purposes)

generated with:

## source = 1690x720
Subtitle("9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9", 
\       align=2, size=Height*0.12, font="Courier New",
\       text_color=$99ffff00, halo_color=$ff000000)
WarpedResize2(1280, 720, hWarp=1.28) 


[edit] Notes to Mathematicians: (and questions)

Imagine the screen was dimensions that went from -1.0 to 1.0. We'll only consider the horizontal dimension for the moment and only the right hand half of the screen. Assume we want to calculate the value of an output pixel at location x, where 0 <= x <=1.

The output value will be the source value from the input screen with the same dimensions, at location s. Right now I'm just calculating s = (1-w) * x^3 + w * x, where w is the warp factor mentioned above (Later note: w = 2 - warp factor, for compat with first release). This gets the job done and produces smooth numbers from 0 to one, without too much distortion as long as w is close to 1.0.

The same formula is reflected for the left half of the screen.

The warp equations are designed to:

  • Always be rising but yield results from 0 to 1
  • Have a first derivative that doesn't go to 0 or infinity, at least close to the center of the screen
  • Have a curvature (absolute val of 2nd derivative) that is small in the center and smoothly rises towards the edges. We would like the curvature to be everywhere = 0 when the warp factor = 1

Now, as near as I can tell the curvature is more or less just the absolute value of the second derivative. So if we wanted the curvature to be small when x = 0 and to grow toward the edges, what could be a useful warp function? The above function already represents a change since V 0.1 but I'm still not so sure it's the best.

It is easy to drop in another warp function. And there is no performance penalty either way because it's just calculated and tabled at startup. After that it runs at the same speed as SimpleResize.

Anyone have any ideas? (Anybody care about this part?)

[edit] Changelog

Version       Date            Changes
v0.3.5.0 2020/06/17 - Changes by Asd-g - Fixed memory leak - Fixed WarpedResize YV12 processing v0.3.4.0 2020/05/18 - Changes by Asd-g - Update to AviSynth+'s v8 interface - x64 version: used the original source code and just replaced 32-bit registers with 64-bit registers - Compiled with MSVC 2019 (Clang 10), x86 and x64 build included v0.3.3.0 2003/01/16 - AviSynth 2.5 YV12 support, AvisynthPluginit2 v0.3.2.0 2002/09/16 - Fix horizontal chroma shift bug v0.3.1.0 2002/07/29 - Removed 4x horizontal pixel count requirement v0.3.0.0 2002/02/04 - Added InterlacedResize & InterlacedWarpedResize functions v0.2.0.0 2002/01/29 - Additional SSE2 & SSEMMX optimizitions, Better warp formula v0.1.0.0 2002/01/20 - Initial release


[edit] Archived Downloads

Version Download Mirror
v0.3.5.0 SimpleResize-0.3.5.7z SimpleResize-0.3.5.7z
v0.3.4.0 SimpleResize-0.3.4.7z SimpleResize-0.3.4.7z
v0.3.3.0 SimpleResize.zip simpleresize_25_dll_20030121.zip


[edit] External Links




Back to External Filters

Personal tools