ConvertBits: Difference between revisions

From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs)
create page
FranceBB (talk | contribs)
 
(13 intermediate revisions by 2 users not shown)
Line 8: Line 8:
==== ConvertBits ====
==== ConvertBits ====
Changes bit depth while keeping [[Avisynthplus_color_formats|color format]] the same, if possible. <br>
Changes bit depth while keeping [[Avisynthplus_color_formats|color format]] the same, if possible. <br>
If the conversion is not possible &ndash; for example, converting [[RGB32]] to 16bit &ndash; an error is raised.
If the conversion is not possible &ndash; for example, converting [[RGB32]] to 14bit &ndash; an error is raised.




{{FuncDef
{{FuncDef
|ConvertBits(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )}}
|ConvertBits(clip, int bits [, bool ''truerange'', int ''dither'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )}}




Line 18: Line 18:


{{Func3Def
{{Func3Def
|ConvertToFloat(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )
|ConvertToFloat(clip, int bits [, bool ''truerange'', int ''dither'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )
|ConvertTo16bit(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )
|ConvertTo16bit(clip, int bits [, bool ''truerange'', int ''dither'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )
|ConvertTo8bit(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )}}
|ConvertTo8bit(clip, int bits [, bool ''truerange'', int ''dither'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )}}




Line 26: Line 26:
::Source clip.  
::Source clip.  


:{{Par2||bits|(required)}}
:{{Par2|bits|int|(actual bit depth)}}
::Bit depth of output clip. Valid values: ''8'', ''10'', ''12'', ''14'', ''16'' (integer) or ''32'' (floating point).  
::Bit depth of output clip. If provided valid values are: ''8'', ''10'', ''12'', ''14'', ''16'' (integer) or ''32'' (floating point).  
::From 3.7.1 parameter is optional since no bitdepth change is needed when doing only range conversion (fulls-fulld) or artistic dithering (dither_bits<bit depth)
::<3.7.1: required


:{{Par2|truerange|bool|true}}
:{{Par2|truerange|bool|true}}
::([[TODO]] if ''false'', seems to either do nothing or corrupt output)
::Hint: forget it. Deprecated, do not use. Maybe once removed.
::Only allowed with [[Planar]] color formats.
::When converting from true 10-16 bit formats, {{FuncArg|truerange}}=false indicates bitdepth of 16 bits regardless of the 10-12-14 bit format. Not applicable for non planar formats.
::If ''true'' (default), convert 10-16 bit formats without re-scaling underlying pixel data. For example,
::&nbsp; <code>clip10bit.'''ConvertBits'''(16, {{FuncArg|truerange}}=false)</code>
::will leave pixel data in the 0..1023 range, but will change the [[Avisynthplus_color_formats|color format]] from ''YUVxxxP10'' to ''YUVxxxP16''.
::
::''Current recommendation: do not specify a {{FuncArg|truerange}} argument &ndash; use the default value.''


{{HiddenAnchor|dither}}
:{{Par2|dither|int|-1}}
:{{Par2|dither|int|-1}}
::If ''0'', add [[Ordered_dithering|ordered dither]]; if ''-1'' (default), do not add dither.
::*If ''-1'' (default), do not add dither;
::Currently works only for 10-16bit &rarr; 8bit conversions.
::*If ''0'', add [[Ordered_dithering|ordered]] dither;
 
::*If ''1'', add [[wikipedia:Floyd–Steinberg_dithering|error diffusion (Floyd-Steinberg)]] dither <sup>[http://forum.doom9.org/showthread.php?p=1838145#post1838145 doom9]</sup>
:{{Par2|scale|float|1.0}}
::Dithering is allowed only for scaling down (bit depth reduction), not up. Bit depth can be kept though if a smaller dither_bits is given.
::([[TODO]] no apparent change in output)
::From 3.7.1: no limit. Note: (behind the scenes) 32 bit float clips are first converted down to 16 (or less if needed) bits, then are further dithered down from this intermediate clip.
::Only allowed for 32bit &rarr; 32bit.  
::<3.7.1: Dithering is allowed only for 10-16bit (not 32bit float) sources.
::
::''Current recommendation: do not specify a {{FuncArg|scale}} argument &ndash; use the default value.''


:{{Par2|dither_bits|int|{{Template:FuncArg|bits}}}}
:{{Par2|dither_bits|int|{{Template:FuncArg|bits}}}}
::Dither to a lower color depth than selected {{FuncArg|bits}} (default = {{FuncArg|bits}})
::Exaggerated dither effect: dither to a lower color depth than required by {{FuncArg|bits}} argument.
::No effect if {{FuncArg|dither}}=-1 (off).
::Has no effect if {{FuncArg|dither}}=''-1'' (off).
::* Must be an even number between 2 to {{FuncArg|bits}}, inclusive.
::* from 3.7.1 Arbitrary number from 1 to {{FuncArg|bits}}, inclusive.
::* In addition, {{FuncArg|dither_bits}} must be >= ({{FuncArg|clip}}.[[Clip_properties#Color_Format|BitsPerComponent]]-8)
::* <3.7.1: Must be an even number from ''2'' to {{FuncArg|bits}}, inclusive.
:::{| class="wikitable"
::* <3.7.1: In addition, must be >= ({{FuncArg|clip}}.[[Clip_properties#Color_Format|BitsPerComponent]]-8).
|+ style="text-align:left"|''Examples''
!Conversion&nbsp;&nbsp;
!Allowed Values&nbsp;
|-
|16 &rarr; 12bit
|8, 10, 12
|-
|16 &rarr; 10bit
|8, 10
|-
|16 &rarr; &nbsp;&nbsp;8bit
|8
|-
|14 &rarr; 10bit
|6, 8, 10
|-
|14 &rarr; &nbsp;&nbsp;8bit
|6, 8
|-
|12 &rarr; 10bit
|4, 6, 8, 10
|-
|12 &rarr; &nbsp;&nbsp;8bit
|4, 6, 8
|-
|10 &rarr; &nbsp;&nbsp;8bit
|2, 4, 6, 8
|}
 
:{{Par2|fulls|bool|(auto)}}
:{{Par2|fulls|bool|(auto)}}
::If ''true'' (rgb default), scale by multiplication: 0-255 &rarr; 0-65535;
::''Use the default value unless you know what you are doing.''
::if ''false'' (yuv default), scale by [[wikipedia:Arithmetic_shift|bit-shifting]].
::Default value can come from <code>_ChromaRange</code> frame property
::Use case: override greyscale conversion to fullscale instead of bit-shifts
::If ''true'' (RGB default), scale by multiplication: 0-255 &rarr; 0-65535; <p>Note: full scale U and V chroma is specially handled</p>
::''Notes:''
::if ''false'' (YUV default), scale by [[wikipedia:Arithmetic_shift|bit-shifting]].
::* Conversion from and to float is always full-scale
::Use case: override greyscale conversion to fullscale instead of bit-shifts.
::* Alpha plane is always treated as full scale
::Conversion from and to float is always full-scale.
::* At the moment, {{FuncArg|fulld}} ''must'' equal {{FuncArg|fulls}}.
::Alpha plane is always treated as full scale.
::
::''Current recommendation: do not specify a {{FuncArg|fulls}} argument &ndash; use the default value.''


:{{Par2|fulld|bool|{{Template:FuncArg|fulls}}}}
:{{Par2|fulld|bool|{{Template:FuncArg|fulls}}}}
::''Current recommendation: do not specify a {{FuncArg|fulld}} argument &ndash; use the default value.''
::''Use the default value unless you know what you are doing.''
::From 3.7.1: can be any combination with {{FuncArg|fulls}}.
::<3.7.1: ''must'' match {{FuncArg|fulls}}.


:ConvertBits writes <code>_ChromaRange</code> frame property (0-full or 1-limited)


<!--
<!--
Line 141: Line 110:
==== Changes ====
==== Changes ====
{|border=1 cellspacing=1 cellpadding=4
{|border=1 cellspacing=1 cellpadding=4
|-
| 3.7.1
|parameter ''bits'' optional
<p>_ChromaRange frame property handling</p>
<p>Free fulls-fulld combination</p>
<p>Free target dither_bits down to 1</p>
<p>Allow dithering from 32 bit float</p>
<p>Allow dithering while keeping actual bit depth (but with a smaller dither_bits)</p>
<p>Specially handled full scale chroma</p>
|-
|-
| 20170310 r2440
| 20170310 r2440

Latest revision as of 04:02, 3 December 2023

AVS+
This feature is specific to AviSynthPlus.

It is not supported in other AviSynth versions.


ConvertBits

Changes bit depth while keeping color format the same, if possible.
If the conversion is not possible – for example, converting RGB32 to 14bit – an error is raised.


ConvertBits(clip, int bits [, bool truerange, int dither, int dither_bits, bool fulls, bool fulld ] )


(older bit-depth conversion filters – deprecated)

ConvertToFloat(clip, int bits [, bool truerange, int dither, int dither_bits, bool fulls, bool fulld ] )
ConvertTo16bit(clip, int bits [, bool truerange, int dither, int dither_bits, bool fulls, bool fulld ] )
ConvertTo8bit(clip, int bits [, bool truerange, int dither, int dither_bits, bool fulls, bool fulld ] )


clip   = (required)
Source clip.
int  bits = (actual bit depth)
Bit depth of output clip. If provided valid values are: 8, 10, 12, 14, 16 (integer) or 32 (floating point).
From 3.7.1 parameter is optional since no bitdepth change is needed when doing only range conversion (fulls-fulld) or artistic dithering (dither_bits<bit depth)
<3.7.1: required
bool  truerange = true
Hint: forget it. Deprecated, do not use. Maybe once removed.
When converting from true 10-16 bit formats, truerange=false indicates bitdepth of 16 bits regardless of the 10-12-14 bit format. Not applicable for non planar formats.
int  dither = -1
Dithering is allowed only for scaling down (bit depth reduction), not up. Bit depth can be kept though if a smaller dither_bits is given.
From 3.7.1: no limit. Note: (behind the scenes) 32 bit float clips are first converted down to 16 (or less if needed) bits, then are further dithered down from this intermediate clip.
<3.7.1: Dithering is allowed only for 10-16bit (not 32bit float) sources.
int  dither_bits = bits
Exaggerated dither effect: dither to a lower color depth than required by bits argument.
Has no effect if dither=-1 (off).
  • from 3.7.1 Arbitrary number from 1 to bits, inclusive.
  • <3.7.1: Must be an even number from 2 to bits, inclusive.
  • <3.7.1: In addition, must be >= (clip.BitsPerComponent-8).
bool  fulls = (auto)
Use the default value unless you know what you are doing.
Default value can come from _ChromaRange frame property
If true (RGB default), scale by multiplication: 0-255 → 0-65535;

Note: full scale U and V chroma is specially handled

if false (YUV default), scale by bit-shifting.
Use case: override greyscale conversion to fullscale instead of bit-shifts.
Conversion from and to float is always full-scale.
Alpha plane is always treated as full scale.
bool  fulld = fulls
Use the default value unless you know what you are doing.
From 3.7.1: can be any combination with fulls.
<3.7.1: must match fulls.


ConvertBits writes _ChromaRange frame property (0-full or 1-limited)


Changes

3.7.1 parameter bits optional

_ChromaRange frame property handling

Free fulls-fulld combination

Free target dither_bits down to 1

Allow dithering from 32 bit float

Allow dithering while keeping actual bit depth (but with a smaller dither_bits)

Specially handled full scale chroma

20170310 r2440 parameter dither_bits
20170202 r2420 parameters fulls, fulld