ConvertBits: Difference between revisions
From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs) TODO - placeholder |
Raffriff42 (talk | contribs) create page |
||
| Line 1: | Line 1: | ||
[[TODO]] | <div style="max-width:82em; min-width:42em;" > | ||
{{AvsPlusFilter}} | |||
</div> | |||
__NOTOC__ | |||
<div style="max-width:62em; min-width:42em;" > | |||
<!-- ==== Syntax and Parameters ==== --> | |||
==== ConvertBits ==== | |||
Changes bit depth while keeping [[Avisynthplus_color_formats|color format]] the same, if possible. <br> | |||
If the conversion is not possible – for example, converting [[RGB32]] to 16bit – an error is raised. | |||
{{FuncDef | |||
|ConvertBits(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )}} | |||
''(older bit-depth conversion filters – deprecated)'' | |||
{{Func3Def | |||
|ConvertToFloat(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] ) | |||
|ConvertTo16bit(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] ) | |||
|ConvertTo8bit(clip, int bits [, bool ''truerange'', int ''dither'', float ''scale'', int ''dither_bits'', bool ''fulls'', bool ''fulld'' ] )}} | |||
:{{Par2||clip|(required)}} | |||
::Source clip. | |||
:{{Par2||bits|(required)}} | |||
::Bit depth of output clip. Valid values: ''8'', ''10'', ''12'', ''14'', ''16'' (integer) or ''32'' (floating point). | |||
:{{Par2|truerange|bool|true}} | |||
::([[TODO]] if ''false'', seems to either do nothing or corrupt output) | |||
::Only allowed with [[Planar]] color formats. | |||
::If ''true'' (default), convert 10-16 bit formats without re-scaling underlying pixel data. For example, | |||
:: <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 – use the default value.'' | |||
:{{Par2|dither|int|-1}} | |||
::If ''0'', add [[Ordered_dithering|ordered dither]]; if ''-1'' (default), do not add dither. | |||
::Currently works only for 10-16bit → 8bit conversions. | |||
:{{Par2|scale|float|1.0}} | |||
::([[TODO]] no apparent change in output) | |||
::Only allowed for 32bit → 32bit. | |||
:: | |||
::''Current recommendation: do not specify a {{FuncArg|scale}} argument – use the default value.'' | |||
:{{Par2|dither_bits|int|{{Template:FuncArg|bits}}}} | |||
::Dither to a lower color depth than selected {{FuncArg|bits}} (default = {{FuncArg|bits}}) | |||
::No effect if {{FuncArg|dither}}=-1 (off). | |||
::* Must be an even number between 2 to {{FuncArg|bits}}, inclusive. | |||
::* In addition, {{FuncArg|dither_bits}} must be >= ({{FuncArg|clip}}.[[Clip_properties#Color_Format|BitsPerComponent]]-8) | |||
:::{| class="wikitable" | |||
|+ style="text-align:left"|''Examples'' | |||
!Conversion | |||
!Allowed Values | |||
|- | |||
|16 → 12bit | |||
|8, 10, 12 | |||
|- | |||
|16 → 10bit | |||
|8, 10 | |||
|- | |||
|16 → 8bit | |||
|8 | |||
|- | |||
|14 → 10bit | |||
|6, 8, 10 | |||
|- | |||
|14 → 8bit | |||
|6, 8 | |||
|- | |||
|12 → 10bit | |||
|4, 6, 8, 10 | |||
|- | |||
|12 → 8bit | |||
|4, 6, 8 | |||
|- | |||
|10 → 8bit | |||
|2, 4, 6, 8 | |||
|} | |||
:{{Par2|fulls|bool|(auto)}} | |||
::If ''true'' (rgb default), scale by multiplication: 0-255 → 0-65535; | |||
::if ''false'' (yuv default), scale by [[wikipedia:Arithmetic_shift|bit-shifting]]. | |||
::Use case: override greyscale conversion to fullscale instead of bit-shifts | |||
::''Notes:'' | |||
::* Conversion from and to float is always full-scale | |||
::* Alpha plane is always treated as full scale | |||
::* At the moment, {{FuncArg|fulld}} ''must'' equal {{FuncArg|fulls}}. | |||
:: | |||
::''Current recommendation: do not specify a {{FuncArg|fulls}} argument – use the default value.'' | |||
:{{Par2|fulld|bool|{{Template:FuncArg|fulls}}}} | |||
::''Current recommendation: do not specify a {{FuncArg|fulld}} argument – use the default value.'' | |||
<!-- | |||
==== Examples ==== | |||
<div style="max-width:62em; min-width:42em;" > | |||
<div {{BoxWidthIndent|54|2}} > | |||
#combine greyscale clips into YUVA clip | |||
U8 = source.UToY8() | |||
V8 = source.VToY8() | |||
Y8 = source.ConvertToY() | |||
A8 = source.AddAlphaPlane(128).AToY8() | |||
CombinePlanes(Y8, U8, V8, A8, planes="YUVA", source_planes="YYYY", | |||
\ sample_clip=source) #pixel_type="YUV444P8" | |||
</div> | |||
<div {{BoxWidthIndent|54|2}} > | |||
# Copy planes between planar RGB(A) and YUV(A) without any conversion | |||
# yuv 4:4:4 <-> planar rgb | |||
source = last.ConvertBits(32) # 4:4:4 | |||
cast_to_planarrgb = CombinePlanes(source, planes="RGB", source_planes="YUV", | |||
\ pixel_type="RGBPS") | |||
# get back a clip identical with "source" | |||
cast_to_yuv = CombinePlanes(cast_to_planarrgb, planes="YUV", source_planes="RGB", | |||
\ pixel_type="YUV444PS") | |||
</div> | |||
<div {{BoxWidthIndent|54|2}} > | |||
#create a black and white planar RGB clip using Y channel | |||
#source is a YUV clip | |||
grey = CombinePlanes(source, planes="RGB", source_planes="YYY", | |||
\ pixel_type="RGBP8") | |||
</div> | |||
<div {{BoxWidthIndent|54|2}} > | |||
#copy luma from one clip, U and V from another | |||
#source is the template | |||
#sourceY is a Y or YUV clip | |||
#sourceUV is a YUV clip | |||
grey = CombinePlanes(sourceY, sourceUV, planes="YUV", | |||
\ source_planes="YUV", sample_clip = source) | |||
</div> | |||
--> | |||
==== Changes ==== | |||
{|border=1 cellspacing=1 cellpadding=4 | |||
|- | |||
| 20170310 r2440 | |||
| parameter ''dither_bits'' | |||
|- | |||
| 20170202 r2420 | |||
| parameters ''fulls'', ''fulld'' | |||
|} | |||
</div> | |||
[[Category:Internal_filters]] | |||
[[Category:Colourspace_Conversion]] | |||
[[Category:Deep_color_tools]] | |||
[[Category:Avisynthplus]] | [[Category:Avisynthplus]] | ||
Revision as of 07:36, 7 June 2017
| 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 16bit – an error is raised.
ConvertBits(clip, int bits [, bool truerange, int dither, float scale, int dither_bits, bool fulls, bool fulld ] )
(older bit-depth conversion filters – deprecated)
ConvertToFloat(clip, int bits [, bool truerange, int dither, float scale, int dither_bits, bool fulls, bool fulld ] )
ConvertTo16bit(clip, int bits [, bool truerange, int dither, float scale, int dither_bits, bool fulls, bool fulld ] )
ConvertTo8bit(clip, int bits [, bool truerange, int dither, float scale, int dither_bits, bool fulls, bool fulld ] )
- clip = (required)
- Source clip.
- bits = (required)
- Bit depth of output clip. Valid values: 8, 10, 12, 14, 16 (integer) or 32 (floating point).
- bool truerange = true
- (TODO if false, seems to either do nothing or corrupt output)
- Only allowed with Planar color formats.
- If true (default), convert 10-16 bit formats without re-scaling underlying pixel data. For example,
-
clip10bit.ConvertBits(16, truerange=false) - will leave pixel data in the 0..1023 range, but will change the color format from YUVxxxP10 to YUVxxxP16.
- Current recommendation: do not specify a truerange argument – use the default value.
- int dither = -1
- If 0, add ordered dither; if -1 (default), do not add dither.
- Currently works only for 10-16bit → 8bit conversions.
- float scale = 1.0
- (TODO no apparent change in output)
- Only allowed for 32bit → 32bit.
- Current recommendation: do not specify a scale argument – use the default value.
- int dither_bits = bits
- Dither to a lower color depth than selected bits (default = bits)
- No effect if dither=-1 (off).
- Must be an even number between 2 to bits, inclusive.
- In addition, dither_bits must be >= (clip.BitsPerComponent-8)
Examples Conversion Allowed Values 16 → 12bit 8, 10, 12 16 → 10bit 8, 10 16 → 8bit 8 14 → 10bit 6, 8, 10 14 → 8bit 6, 8 12 → 10bit 4, 6, 8, 10 12 → 8bit 4, 6, 8 10 → 8bit 2, 4, 6, 8
- bool fulls = (auto)
- If true (rgb default), scale by multiplication: 0-255 → 0-65535;
- if false (yuv default), scale by bit-shifting.
- Use case: override greyscale conversion to fullscale instead of bit-shifts
- Notes:
- Conversion from and to float is always full-scale
- Alpha plane is always treated as full scale
- At the moment, fulld must equal fulls.
- Current recommendation: do not specify a fulls argument – use the default value.
- bool fulld = fulls
- Current recommendation: do not specify a fulld argument – use the default value.
Changes
| 20170310 r2440 | parameter dither_bits |
| 20170202 r2420 | parameters fulls, fulld |