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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th April 2005, 15:18   #1  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,605
feature request: extractred/green/blue() ; mergergb()

I want to start a feature request for a functionality AVIsynth already offers for YUV-based video:

y=greyscale()
u=utoy()
v=vtoy()

ytouv(u,v,y)


I would like to see the same for rgb24 and rgb32 chroma:

r=extractred() / rtoy()
b=extractgreen() / gtoy()
g=extractblue() / btoy()

mergergb(r,g,b)

is there a chance to get these functions?
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 16th April 2005, 16:07   #2  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,268
Splitting can be done with RGBAdjust:
Code:
r = c.RGBAdjust(1, 0, 0, 0)
g = c.RGBAdjust(0, 1, 0, 0)
b = c.RGBAdjust(0, 0, 1, 0)
I haven't figured out how to merge though, if it's possible at all.
stickboy is offline   Reply With Quote
Old 16th April 2005, 16:34   #3  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,605
That's what I've already found out.

but merging with overlay introduces big brightness loss

and abusing subtract & invert to build an add() function also fails
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 16th April 2005, 17:57   #4  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
I'm on it. First version should be ready in a couple of hours.
tsp is offline   Reply With Quote
Old 16th April 2005, 20:23   #5  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
get it here

From the readme:

syntax
RtoRGB()
copies the Red value to Green and Blue resulting in a greyscale image.

GtoRGB()
copies the Green value to Red and Blue resulting in a greyscale image.

BtoRGB()
copies the Blue value to Red and Green resulting in a greyscale image.

MergeRGB(clip R,clip G,clip B)
copies the green value from G to R and the blue value from B to R

Todo:
Add mmx support.

0.1 first release.

sourcecode released under GPL se copying.txt

Last edited by tsp; 17th April 2005 at 14:11.
tsp is offline   Reply With Quote
Old 17th April 2005, 15:13   #6  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
cool! thanks! i've been wanting something like this for ages (though only idly - otherwise i'd have made a thread...).

IMHO this should end up in the avs core, alongside it's cousins utoy, vtoy, etc.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 17th April 2005, 15:57   #7  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,295
Quote:
IMHO this should end up in the avs core, alongside it's cousins utoy, vtoy, etc.
If tsp adds mmx support i will look at it ...
Wilbert is offline   Reply With Quote
Old 17th April 2005, 17:39   #8  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,605
Many thanks TSP!

I've digged out an about 1.5 years old function from me to test it:
Clearscale.

Code:
function clearscale(clip i, int width, int height, int "filter")
{
filter=default(filter,2)

i.converttorgb32()

#resize to destination size with triple width; 
#add 3 pixels on the right side to get room for image shifting
bicubicresize((width*3),height).addborders(0,0,3,0)                  

#do a prefiltering to supress color speckling
(filter==0) ? last : (filter==1) ? last.blur(1,0) : last.blur(1,0).blur(1,0)

# select spatial correct color planes
R=crop(2,0,-1,0).pointresize(width,height).RtoRGB()
G=crop(1,0,-2,0).pointresize(width,height).GtoRGB()
B=crop(0,0,-3,0).pointresize(width,height).BtoRGB()

#finally merge color planes
MergeRGB(R,G,B)
}
Clearscale will scale your input video paying attention to our LCDs subpixel structure. You'll actually gain a factor of three regarding phase information in the horizontal direction.
Of coure, the images needs to be saved either lossless (PNG, BMP, TIF)
or with non-subsampled-chroma JPG.

With your plugin I got it working again without cracking my brain about subtract, layers and so on
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.

Last edited by scharfis_brain; 17th April 2005 at 20:37.
scharfis_brain is offline   Reply With Quote
Old 17th April 2005, 19:44   #9  |  Link
vinetu
Registered User
 
Join Date: Oct 2001
Posts: 195
scharfis_brain,
I can't get it - the Clearscale.
In fact every 3 subpixels on LCD matrix are threaded as single pixel, so by this script you'll probably change the overall image look,collor crispness etc...
It's somehow an opposite to debayer filter?
Did you see an improvement on your side (I don't have a LCD panel around yet) ?
vinetu is offline   Reply With Quote
Old 17th April 2005, 20:36   #10  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,605
Nonono...
the clearscale effekt only becomes visible if you are downsizing a crisp image at least by a factor of three in the horizontal dimension!

It works similar to Microsofts Cleartype or Adobes Cooltype.

Have a look:
the original (360x360):


bicubic to 120x120: pointscaling:





clearscale with 2pass, 1pass and without filtering:


__________________
Don't forget the 'c'!

Don't PM me for technical support, please.

Last edited by scharfis_brain; 18th April 2005 at 16:57.
scharfis_brain is offline   Reply With Quote
Old 17th April 2005, 22:29   #11  |  Link
vinetu
Registered User
 
Join Date: Oct 2001
Posts: 195
Ah! It's much clear now

Thank You for this Example!
vinetu is offline   Reply With Quote
Old 18th April 2005, 01:12   #12  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
I added some mmx optimization to the code. I'm not sure it was worth it but try and see if you get any speed increase.

link to version 0.2: http://www.tsp.person.dk/RGBmanipulate02.zip
tsp is offline   Reply With Quote
Old 18th April 2005, 05:03   #13  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
the twopass pic doesn't look any different on this LCD panel... but that might be because the screen's set to 16bpp (the viddy card is pretty old unfortunately, and can't go as high as the screen it's plugged into without going to 16bpp)
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 18th April 2005, 16:58   #14  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,605
Edited my samples above.
The effect should be more visible now.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 21st April 2005, 01:45   #15  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
Tsp,

Neat

It's not easy getting MMX to work fast. Try using flavours of punpck[lh][bwd][wdq] to distribute the colour channels throughout the pixel rather than masking and shifting. Try to access memory aligned 64bits at a time.


Dear all,

Also might it be useful (it could be faster) to export the colour channels to a YV12[0..255] luma plane, dummying up the chroma planes as grey or maybe the colour for bonus points.

This feature rates going into the core. Just need some time...

IanB
IanB is offline   Reply With Quote
Old 22nd April 2005, 02:29   #16  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
IanB: Is it okay to overwrite the alpha channel or is there anything that uses it?

with the current optimization(not released yet) the mmx version is about 20% faster than the c version.
tsp is offline   Reply With Quote
Old 23rd April 2005, 09:10   #17  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
tsp,

Layer and Overlay make use of the Alpha channel. Generally it is preferable not to clobber the alpha channel. However given this filter currently copies a chosen channel to the other 2 it is not a great stretch to define it to copy a channel to the other 3. It certainly makes the MMX code easier. And the core currently has a ShowAlpha(clip, string pixel_type) which is just C code, it copies the Alpha to the R, G and B channels, so there is a precedent.

For the MMX code I was thinking along the lines of
Code:
  movq      mm0,[src]
  movq      mm1,[src+8]
  pand      mm0,k000000ff000000ff  // dd p1, p0
  pand      mm1,k000000ff000000ff  // dd p3, p2
  packssdw  mm0,mm1  // dw p3, p2, p1, p0
  packuswb  mm0,mm0  // db p3, p2, p1, p0, p3, p2, p1, p0
  punpcklbw mm0,mm0  // db p3, p3, p2, p2, p1, p1, p0, p0
  movq      mm1,mm0
  punpcklbw mm0,mm0  // db p1, p1, p1, p1, p0, p0, p0, p0
  punpckhbw mm1,mm1  // db p3, p3, p3, p3, p2, p2, p2, p2  
  movq      [dst],mm0
  movq      [dst+8],mm1
as this code only uses 3 registers you could add a 2nd (or 3rd) stream and process 8 (or 12) pixels at once, it should really scream

IanB
IanB is offline   Reply With Quote
Old 24th April 2005, 18:20   #18  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Quote:
Originally posted by IanB
Layer and Overlay make use of the Alpha channel.
Just for the record - overlay uses luma from a separate video stream for alpha. Too many filters destroy alpha information anyway, so I figured it was easier to not rely on it. That being said there is no reason to kill alpha on purpose.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 25th April 2005, 00:13   #19  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
more update. now the mmx should work correctly. Get version 0.3 here.

The current mmx code preserves the alpha channel. The reason to kill the channel would be speed. IanB's code performce about 22% faster than the c code in my last test(RtoRGB). The current mmx code is about 15% faster than the c code. I think I will just add an option to keep the alpha channel then people get a choice what to get. Also I will convert the inline assembly to softwire there is to much repeated mmx code.
tsp is offline   Reply With Quote
Old 30th April 2005, 01:00   #20  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
Version 0.4 is ready. Get it here.
Softwire is really nice but it's irritating that I can't convert a __cdecl function pointer to a thiscall function pointer without using inline asm. I thought reinterpret_cast would work but it didn't.

scharfis_brain: you don't need RtoRGB,GtoRGB,BtoRGB for your function MergeRGB will do.

From the readme.txt


RGBmanipulate mirrors the function utoy vtoy mergeLuma/chroma for the rgb colorspace

syntax:

RtoRGB(bool useMMX,bool overwritealpha, bool usemmx)
copies the Red channel to Green and Blue resulting in a greyscale image.


GtoRGB(bool useMMX,bool overwritealpha, bool usemmx)
copies the Green channel to Red and Blue resulting in a greyscale image.


BtoRGB(bool useMMX,bool overwritealpha, bool usemmx)
copies the Blue channel to Red and Green resulting in a greyscale image.

usemmx: enables mmx optimization. Default true
overwritealpha: If true the alpha channel is also overwriten (this is faster). Default false


MergeRGB(clip R,clip G,clip B,clip A,int alphachannel,bool usemmx)
Merge the Red channel from R the green channel from G and the blue channel from B
if A is specified(you don't have to) the alpha channel from A is used.

alphachannel specifies where the alpha channels should be used from if A isn't specified:
0 copies the alpha channel from R
1 copies the alpha channel from G
2 copies the alpha channel from B
3 zeroes the alpha channel
Default 0
tsp is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:01.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.