Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum ManualColorMatrix - Can perform any matrix-based color conversion
 Register FAQ Calendar Search Today's Posts Mark Forums Read

1st July 2011, 13:49   #1  |  Link
xv
Registered User

Join Date: Mar 2010
Posts: 98
ManualColorMatrix - Can perform any matrix-based color conversion

This plug-in can perform any matrix-based color conversion (if you know how to use it ):
Code:
```     Out      Add         Matrix       In
/ \     /    \     /        \     / \
| Y |   | yadd |   | yy yu yv |   | Y |
| U | = | uadd | + | uy uu uv | * | U |
| V |   | vadd |   | vy vu vv |   | V |
\ /     \    /     \        /     \ /```
Supports YV24, RGB24 and RGB32 input and YV24, RGB24, RGB32, YUY2 and YV12 output.

Examples:

Convert YCgCo to RGB32:
ManualColorMatrix(2, 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, -1.0, 0.0, -128.0, 256.0)

Convert RGB to YV24 (bt601 matrix, range 16-235):
ManualColorMatrix(0, 0.255785, 0.504129, 0.097906, -0.148223, -0.290992, 0.439215, 0.439215, -0.367789, -0.071426, 16.0, 128.0, 128.0)

Convert YCgCo to YUY2 (bt601 matrix, range 16-235):
ManualColorMatrix(3, 0.85782, 0.150438, 0.157879, 0.0, -0.581984, -0.587438, 0.0, -0.735578, 0.510641, -23.4645, 277.686, 156.792)

http://www.mediafire.com/?9yyj1uepe5ir5w7
Attached Files
 ManualColorMatrix.zip (54.9 KB, 366 views)

 1st July 2011, 18:50 #2  |  Link pandy Registered User   Join Date: Mar 2006 Posts: 1,044 THX and waiting for YV12/YUY2 input support (and interlace as for YV12 if this is possible)
 1st July 2011, 23:52 #3  |  Link xv Registered User   Join Date: Mar 2010 Posts: 98 Even for YV12->YV12 or YUY2->YUY2 transform I would have to convert it internally to YV24 first, there is no way to do the color conversion with chroma subsampled material. That would mean I would do it the same way I did with YUY2/YV12 output, calling a resizer and upsample chroma. For interlaced material I cannot use a resizer, but you could just do SeperateFields().ManualColorMatrix(...).Weave()
2nd July 2011, 08:41   #4  |  Link
Gavino
Avisynth language lover

Join Date: Dec 2007
Location: Spain
Posts: 3,390
Quote:
 Originally Posted by xv For interlaced material I cannot use a resizer, but you could just do SeperateFields().ManualColorMatrix(...).Weave()
Why can't you use a resizer?
You could do the equivalent of my YV12ToYUY2i_26 function in this post.

Note that if ManualColorMatrix did support YV12 input, SeperateFields().ManualColorMatrix(...).Weave() would give incorrect results, since separated YV12 fields have a different chroma placement.
__________________
GScript and GRunT - complex Avisynth scripting made easier

 2nd July 2011, 14:57 #5  |  Link xv Registered User   Join Date: Mar 2010 Posts: 98 Your script only works with AviSynth 2.6, in Avisynth 2.6 you can just convert to YV24 and convert back to YV12 afterwards, no reason to double that functionality in this plugin. Could you please explain the problem with SeperateFields and Weave, I could do that internally and use different chroma offsets, but I do not see what chroma offset I should use at the moment (you can use the nice image on page 381 in H.264 standard to explain: http://www.itu.int/rec/T-REC-H.264-201003-I/en )
2nd July 2011, 17:11   #6  |  Link
Gavino
Avisynth language lover

Join Date: Dec 2007
Location: Spain
Posts: 3,390
Quote:
 Originally Posted by xv Your script only works with AviSynth 2.6, in Avisynth 2.6 you can just convert to YV24 and convert back to YV12 afterwards, no reason to double that functionality in this plugin.
Agreed.

Quote:
 Could you please explain the problem with SeperateFields and Weave, I could do that internally and use different chroma offsets, but I do not see what chroma offset I should use at the moment
Basically, you would do the equivalent of what I did for the 2.5 version in that same post (function YV12ToYUY2i), where the (vertical) offset is 0.125 (1/8) for top fields and -0.125 for bottom fields. This is because, although the chroma placement in the frame is the same for both progressive and interlaced, once separated it has a different relationship to luma (because the luma spacing has doubled).
See http://avisynth.org/mediawiki/Sampli...2_color_format.
__________________
GScript and GRunT - complex Avisynth scripting made easier

 2nd July 2011, 17:58 #7  |  Link xv Registered User   Join Date: Mar 2010 Posts: 98 Thatīs the same for MPEG-2 / MPEG-1 subsampling (type 0 and 1 in H.264 spec) if I see that correct? For type 2/3 subsampling (as in H.264 spec) it should be +0.25 for top field and 0 for bottom field, for type 4/5 itīs 0 for top field and -0.25 for bottom field?
 2nd July 2011, 18:52 #8  |  Link Gavino Avisynth language lover   Join Date: Dec 2007 Location: Spain Posts: 3,390 Yes, all correct. And conversely for output (downsampling from YV24), all those offsets get multiplied by -2. I think I'll have to lie down for a while - my eyes and brain are still recovering from viewing that funky diagram Figure E-1 in the H.264 spec. __________________ GScript and GRunT - complex Avisynth scripting made easier
 11th July 2011, 19:22 #9  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,867 There's still stuff missing, I wish it could do this http://www.brucelindbloom.com/index....YZ_to_Lab.html That would make it a lot more complicated though, I might have to script it myself.. or get back into figuring out how to make a plugin. Man, if I could make plugins, I would be one of the most prolific ones here
 14th October 2018, 17:16 #10  |  Link Soulnight Registered User   Join Date: Jan 2017 Location: Germany Posts: 21 What happens if you for example convert from RGB REC2020 to RGB rec709 with the correct conversion matrix? All the color outside REC709 will have illegal values. Are the illegal RGB value left "untouched", negative etc... or are they getting clipped to the nearest legal value? Thank you!