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 17th April 2011, 10:32   #41  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by PitifulInsect View Post
Some functions like Mask() and Layer() do internal conversions, so you know that they're not right - I always use Overlay() instead, which is colour-space native (YV12, YUY2, and RGB).
Mask() only accepts RGB32, so no conversions there.
Layer() accepts either RGB32 or YUY2, but both clips must be the same, so no conversions there either.
Overlay(), on the other hand, converts everything into an internal YUV 4:4:4 format, so there is a colorspace conversion for RGB and chroma resampling for YUY2 and YV12. In addition, there is a rounding bug in the RGB conversion in v2.58 - see this post, and posts #24 and #30 above and below it.

Quote:
Almost no PC software (almost certainly not AVISynth either) even rescales images correctly!: http://www.4p8.com/eric.brasseur/gamma.html.
We now have PhrostByte's gamma-aware resizer.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 17th April 2011, 12:30   #42  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,309
Quote:
If you're curious: I have found that unfortunately AVISynth's regular ImageSource() and ImageWriter() functions do perform internal colour-space conversions
Please elaborate in which cases this happens. Sure there is a conversion if you feed it with YCbCr or the image formats don't support RGB.
Wilbert is offline   Reply With Quote
Old 17th April 2011, 15:35   #43  |  Link
Yellow_
Registered User
 
Join Date: Sep 2009
Posts: 378
Quote:
Originally Posted by PitifulInsect View Post
Hey Yellow_,

As long as your sRGB is 8 bits per sample, any software (including AVISynth) will handle it, it just won't know that the RGB samples that are being processed have a different display interpretation. If you have such samples in a file, Sashimi can pick them up into AVISynth or if you have them in AVISynth it can put them down do disk, and doesn't manipulate their values at all - I really designed it for research and scientific uses, so I've taken care to make sure that it doesn't mess with data. So your answer is that Sashimi is completely agnostic to the data that it handles.
Ok, I'll give it another go, thanks.

Quote:
If you're curious: I have found that unfortunately AVISynth's regular ImageSource() and ImageWriter() functions do perform internal colour-space conversions, but I don't know the details and you can probably read more elsewhere, this isn't the thread for that. If you're processing any data internally, keep in mind that it no-longer means what the processing functions think that it means, so you won't know if they're treating it correctly. Some functions like Mask() and Layer() do internal conversions, so you know that they're not right - I always use Overlay() instead, which is colour-space native (YV12, YUY2, and RGB).

Only vaguely relevant, but interesting: The problem with using any nonlinear colour space of course is that things will be wrong when you try to manipulate the data in any way. Almost no PC software (almost certainly not AVISynth either) even rescales images correctly!: http://www.4p8.com/eric.brasseur/gamma.html. These sorts of problems get fixed and updated over time, but I think generally the best advice might be to just make sure that your colour space is appropriate for the software that you're using. Good luck!
That's ok, I'm going to RGB with yCMS and now Phrostbytes gamma aware resizer, then have been using Wilberts Imagemagick plugin. Thanks for the details.
Yellow_ is offline   Reply With Quote
Old 5th September 2011, 19:21   #44  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
Pitiful,
That link to google sites is down. Is there a mirror for Sashimi hosting?
And I might have to finish my v210 import soon
jmac698 is offline   Reply With Quote
Old 6th September 2011, 15:36   #45  |  Link
PitifulInsect
Registered User
 
Join Date: Nov 2008
Location: Sydney, Australia
Posts: 26
Hi jmac,

The URL's just changed, apologies:
http://sites.google.com/site/ourenthusiasmsasham/soft
You should get an automatic redirect suggestion though.

In case of future trouble, I've been keeping the first post of this thread updated with the latest stable version of the plugin so that as long as you can see the thread, you can get a copy.

Either way, I'll update the links soon and put out the next version of Sashimi. No big changes to announce - bugfixes in the multi-byte support and updates of the documentation. It's all delayed because I developed a set of tests and examples for the multi-bit-depth stuff and found bugs. I've squashed two, but there is at least one more bug, and I want to find and kill it before releasing.
PitifulInsect is offline   Reply With Quote
Old 16th September 2011, 12:49   #46  |  Link
18fps
Registered User
 
Join Date: Oct 2008
Posts: 53
I'd like to read a headerless file that is 2048 * 2048 pixels, 16 bits per channel, RGB, 2 "channels", the second has to be debayered. How sould I use the filter to read it, maybe at last to get a b&w image? Thank you!
18fps is offline   Reply With Quote
Old 16th September 2011, 21:00   #47  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
Code:
# Read the content in from the file with 32 bits/pixel (to be sorted later)
raw=RawReader("C:\Myfiles\sensor.raw", "argb", 2048, 2048, filehead=0, framehead=0)
IR25uMhi8bits=raw.showalpha
IR50uMhi8bits=raw.showgreen#If this doesn't look right try showblue, showred etc.
black=blankclip(width=2048,height=2048,pixel_type="RGB")
black.mergergb(black,IR50uM,black)#Make the sensor data "green" to work with debayer (you have to know what your's doing here, the pixel layout of the sensor, if it's 2 channel green is like a checkerboard and should work)
demosaic(xoffset = 1, yoffset = 0, method = "bilinear")#I've assumed the 2nd channel is offset 1 pixel..
Get the debayer plugin from http://forum.doom9.org/showthread.php?p=1108152

Last edited by jmac698; 16th September 2011 at 21:04.
jmac698 is offline   Reply With Quote
Old 16th September 2011, 23:00   #48  |  Link
PitifulInsect
Registered User
 
Join Date: Nov 2008
Location: Sydney, Australia
Posts: 26
Gee people are quick on here! I was halfway through typing my own answer when jmac698 beat me to it!
Anyway, there are a lot of unknowns, so I'll just post some notes.

You say RGB, then you say 2 channels, which is a little confusing, I'll assume you simply have a bayer-grid dump. If you don't and you need more help, please make a sample file and more detail available.

jmac698's code is one neat way to do it, an alternative is
Code:
# Double-width and height for the bayer pattern, double width for 16-bit
RawReader("file.raw", Y8, 2048*4, 2048*2)
# Take out every second byte to cut down to 8-bit (in case of failure, try SelectOdd() instead.
TurnRight().AssumeFrameBased().AssumeTFF().SeparateFields().TurnLeft().SelectEven()
The reason I offer this alternative way of thinking about it, is that if you get the most recent Beta version of Sashimi (I promise to post an update soon, keep an eye on this thread), you can simplify still further to:
Code:
# Double-width and height for the bayer pattern, 16-bit
RawReader("file.raw", Y8, 2048*2, 2048*2, packing="16")
The advantage of doing it this way is that if you find that your image is very low contrast, you can try dropping some of the higher bits by changing the packing from "16" to "16:1" or even "16:2" or "16:3" etc (dropping 1, 2, or 3 high-end bits).

Removing the Bayer pattern is the hardest thing to do well - it's a whole research area of its own. A quick Google for me though, showed that there are a lot of tools in astronomy and science that take "Y800" files and give you various de-bayer algorithms. Lucky that there's a de-facto standard! You can make a "Y800" AVI file by saving your successfully loaded greyscale file directly out of VirtualDubMod using the ffdshow encoder, after setting the ffdshow encoder to "Uncompressed", colorspace "Y800". Then you can play with existing debayer tools as you find them.

Last edited by PitifulInsect; 16th September 2011 at 23:05. Reason: Originallt hit "post" too soon by accident, wasn't finished.
PitifulInsect is offline   Reply With Quote
Old 16th September 2011, 23:22   #49  |  Link
PitifulInsect
Registered User
 
Join Date: Nov 2008
Location: Sydney, Australia
Posts: 26
Ooops - forgot the good link that I found. Here:
http://www.theimagingsourceforums.co...Using-AviSynth
PitifulInsect is offline   Reply With Quote
Old 17th September 2011, 03:48   #50  |  Link
PitifulInsect
Registered User
 
Join Date: Nov 2008
Location: Sydney, Australia
Posts: 26
Good news! The last bug in bit-depth support turned out to be an old bug - sashimi has apparently always barfed on YUY2. It's now fixed (error message if you try to use YUY2 - use YV12 instead), and the new version of Sashimi is available, either from the first post of this thread (attachments have an approval delay, please be patient), or directly from my site:
https://sites.google.com/site/ourenthusiasmsasham/soft
Cheers!
-- PitifulInsect.
PitifulInsect is offline   Reply With Quote
Old 17th September 2011, 05:10   #51  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
@pitfiul..
lesson learned, never draw with me in a gunfight
Look forward to the new version..

and I gave him a debayer plugin, which might actually work for him..
jmac698 is offline   Reply With Quote
Old 17th September 2011, 07:35   #52  |  Link
SAPikachu
Registered User
 
SAPikachu's Avatar
 
Join Date: Aug 2007
Posts: 218
@jmac698
I have made a new script based on your v210 reader 0.4, it can now read v210 file into full-color 8bit/16bit clip. May be useful to you.

You can check it here:
http://forum.doom9.org/showthread.ph...31#post1526131
__________________
f3kdb 1.5.1 / MP_Pipeline 0.18

ffms2 builds with 10bit output hack:
libav-9a60b1f / ffmpeg-1e4d049 / FFmbc-0.7.1
Built from ffms2 6e0d654 (hack a9fe004)

Mirrors: http://bit.ly/19TwDD3

Last edited by SAPikachu; 17th September 2011 at 07:37.
SAPikachu is offline   Reply With Quote
Old 17th September 2011, 11:42   #53  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
That's awesome!
@pit:
I just realized, if you could make a plugin like sashimi but to read data files directly into script variables, like filereader(int a, float b, string c)
tweak(bright=a, constrast=b)
subtitle(c)
I have many uses for parsing text files, for example to read the histogram file from colorlike, or the logs from dgindex, etc. Something a bit more powerful than conidtionalreader.

It would be a set of vars per frame, so above would parse repeated values during the clip.
jmac698 is offline   Reply With Quote
Old 19th September 2011, 09:09   #54  |  Link
18fps
Registered User
 
Join Date: Oct 2008
Posts: 53
jmac698 and jmac698: thank you for your fast answers! I'll try them today.
18fps is offline   Reply With Quote
Old 28th September 2011, 07:14   #55  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,862
@Pit
I finally got around to writing my own readv210 with your new version, and I found another way to do it in just 2 passes. Not sure if it's any faster or not though; the code certainly seems simpler to me.
Code:
#v210 Reader Ver 0.5 by jmac698
#Read v210 Quicktime files with Sashimi, by jmac698
#Ver 0.5 - reads grey image in a new way with sashimi 0.85
#Requirements - only Sashimi 0.85
fn="D:\project001a\deepcolor\v210 samples\v210.mov"
readv210new(fn, 48, 1920, 1080)

function readv210new(string fn, int file_head, int frame_width, int frame_height) {#greyscale v210 file
    line_size = (frame_width * 16 / 6 + 127) / 128 * 128 # all lines are padded to 128 bytes boundary
    LeftWords = RawReader(fn, "RGB", line_size/4, frame_height, filehead=file_head, packing="8:0:8; 6:0:6; 18:0:2")#3 bitfields in 32bits
    RightWords = RawReader(fn, "RGB", line_size/4, frame_height, filehead=file_head, packing="20:16:4; 4:0:4; 8:2:6")
    p2 = LeftWords.every(2,1)
    p3 = RightWords.every(2,1)
    p0 = LeftWords.every(2,0)
    p1 = RightWords.every(2,0)
    Cb0_7_0=p0.showred
    Y0_5_0=p0.showgreen
    Cb0_9_8=p0.showblue 
    Cr0_3_0=p1.ShowRed
    Y0_9_6=p1.ShowGreen
    Cr0_9_4=p1.showblue 
    Y1_7_0=p2.showred 
    Cb1_5_0=p2.showgreen 
    Y1_9_8=p2.showblue 
    Y2_3_0=p3.showred 
    Cb1_9_6=p3.showgreen 
    Y2_9_4=p3.showblue 
    
    Y0_9_2=CombineBits(Y0_9_6,Y0_5_0,4)
    Y1_9_2=CombineBits(Y1_9_8,Y1_7_0,2)
    Y2_9_2=CombineBits(Y2_9_4,Y2_3_0,6)
    Weave3h(Y0_9_2,Y1_9_2,Y2_9_2)
}

function weave3h(clip a, clip b, clip c) {#horizontally weave 3 clips
    a=a.turnright
    b=b.turnright
    c=c.turnright
    interleave(a,b,a,c)#0 1 2 3->01 23->0213->213 or abc
    assumefieldbased
    assumetff
    weave
    assumefieldbased
    assumetff
    weave
    pointresize(width,height*3/4)#deletes every 4th line offset 0
    turnleft
}

function every(clip v, int n, int offset) {#select every n bytes horizontally with offset, works on yv12 only
    v
    w=width
    h=height
    pointresize(v,w*2,h)
    crop(offset*2,0,0,0).addborders(0,0,offset*2,0)#shift left offset pixels
    pointresize(w/n,h)
}

function CombineBits(clip left, clip right, int bits) {
    #Combine first bitsl of left with first bitsr of right
    #e.g. 9876xxxx and 5432xxxx with bitsl=4, bitsr=4 gives 98765432
    bitsright=8-bits
    pwr=pow(2,bitsright)
    Overlay(left, right.Levels(0,1,256, 0,int(pwr), false), mode="Add")
}
jmac698 is offline   Reply With Quote
Old 6th June 2013, 20:19   #56  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
Resurrecting an old very helpful thread

I modified the ReadV210 script included in Sashimi 0.85 to support Stack16 output, enabling use of tools like Dither. I also made it so you can define the fh in the function call, as this works better for me. I realize its a bit dirtier than jmac698's version, but that's the one I started with, it works, and I don't want to spend any more time on it

I double checked using Dither and my input file matched my output file bit for bit.

Checking that input file matches output file bit for bit:
Code:
Readv210(input.yuv, 1920, 1080)
Dither_quantize(10,reducerange=true)
Dither_out()

#Command to generate output.yuv
#avs2yuv -raw -csp I422 "input.avs" - | ffmpeg -y -f rawvideo -pix_fmt yuv422p10le -s 1920x1080 -r 60000/1001 -i - -c:v v210 "output.yuv"
Modified ReadV210:
Code:
#
# Example of reading a really difficult file format.
# See http://developer.apple.com/quicktime/icefloe/dispatch019.html#v210
#
# Peter Pakulski, 2011
#
# Stack16 output added by Aegwyn11, 2013 (requires AVIsynth 2.6)
#

function ReadV210(string filename, int width, int height, int "fh")
{
    fh	= Default (fh, 0)
	
    #OldReadV210(filename, width, height, fh)
    #OptimisedReadV210(filename, width, height, fh)
    Readv210Stack16(filename, width, height, fh)
}

#
# A straightforwards interpretation of a curly file format.
#
function OldReadV210(string filename, int width, int height, int "fh")
{
    #
    # There seems to be a standard file-header length, and it's only 48 bytes.
    # The rest of the specification (there's more) is after the file body.
    #fh = 48
    fh	= Default (fh, 0)

    # The Read-width of the image is the width padded up to the nearest 48-byte
    # boundary as per the specification, and divided by 6 because of the
    # effective interlacing you get from reading only one value per pass.
    rwidth = (width/48 + (width%48==0 ? 0 : 1)) * 48 / 6

    #
    # What a NUISANCE!  The v210 format is little-endian 32-bit words, 128 bits at
    # a time.  So from the specification, for example, starting with the first 32:
    #   _______  _______  _______  ______
    #  / Byte3 \/ Byte2 \/ Byte1 \/ Byte0\
    #  XX 9876543210 9876543210 9876543210
    #     \___Cr___/ \___Y0___/ \___Cb___/
    #
    # Is actually stored all mixed up, if reading it in, in byte order:
    #   ______    _______    _______    _______  
    #  / Byte0\  / Byte1 \  / Byte2 \  / Byte3 \ 
    #  76543210  543210 98  3210 9876  XX 987654 
    #  \__Cb__/  \_Y0_/ Cb  \Cr/ \Y0/     \_Cr_/ 
    #
    # This pattern repeats.
    #
    # So below:  Extract the muddled pixel colour components, half at a time, in
    # multiple reads. Assemble them, then assemble them into colour planes, and
    # finally assemble the colour planes into a colour image.
    #
    # 4-byte word #0 - as above (Cr0, Y0, Cb0)
    Cb0H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:14:2")
    Cb0L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:0:6")
    Cb0 = Cb0H.Overlay(Cb0L.Levels(0,1,256, 0,64, false), mode="Add")

    Y0H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:20:4")
    Y0L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:8:4")
    Y0 = Y0H.Overlay(Y0L.Levels(0,1,256, 0,16, false), mode="Add")

    Cr0H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:26:6")
    Cr0L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:16:2")
    Cr0 = Cr0H.Overlay(Cr0L.Levels(0,1,256, 0,4, false), mode="Add")

    # 4-byte word #1 - Y2, CB1, Y1
    Y1H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:46:2")
    Y1L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:32:6")
    Y1 = Y1H.Overlay(Y1L.Levels(0,1,256, 0,64, false), mode="Add")

    Cb1H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:52:4")
    Cb1L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:40:4")
    Cb1 = Cb1H.Overlay(Cb1L.Levels(0,1,256, 0,16, false), mode="Add")

    Y2H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:58:6")
    Y2L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:48:2")
    Y2 = Y2H.Overlay(Y2L.Levels(0,1,256, 0,4, false), mode="Add")

    # 4-byte word #2 - Cb2, Y3, Cr1
    Cr1H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:78:2")
    Cr1L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:64:6")
    Cr1 = Cr1H.Overlay(Cr1L.Levels(0,1,256, 0,64, false), mode="Add")

    Y3H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:84:4")
    Y3L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:72:4")
    Y3 = Y3H.Overlay(Y3L.Levels(0,1,256, 0,16, false), mode="Add")

    Cb2H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:90:6")
    Cb2L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:80:2")
    Cb2 = Cb2H.Overlay(Cb2L.Levels(0,1,256, 0,4, false), mode="Add")

    # 4-byte word #3 - Y5, Cr2, Y4
    Y4H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:110:2")
    Y4L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:96:6")
    Y4 = Y4H.Overlay(Y4L.Levels(0,1,256, 0,64, false), mode="Add")

    Cr2H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:116:4")
    Cr2L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:104:4")
    Cr2 = Cr2H.Overlay(Cr2L.Levels(0,1,256, 0,16, false), mode="Add")

    Y5H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:122:6")
    Y5L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="128:112:2")
    Y5 = Y5H.Overlay(Y5L.Levels(0,1,256, 0,4, false), mode="Add")

    # Next, assemble the three planes of the image:
    # Y (with components 0, 1, 2, 3, 4, and 5),
    # and Cb and Cr (each with components 0, 1, and 2).
    # Assemble padded to even numbers, then use PointResize to remove the padding.
    Y0_3_2_5_1_4_p_p = Interleave(Y0, Y3, Y2, Y5, Y1, Y4, Y0, Y0).TurnRight()
    Y03_25_14_pp     = Y0_3_2_5_1_4_p_p.AssumeFieldBased().AssumeTFF().Weave()
    Y0235_1p4p       =     Y03_25_14_pp.AssumeFieldBased().AssumeTFF().Weave()
    Y012p345p        =       Y0235_1p4p.AssumeFieldBased().AssumeTFF().Weave()
    Y012p345p = Y012p345p.TurnLeft()
    Y012345   = Y012p345p.PointResize(Y012p345p.Width()*3/4, Y012p345p.Height())

    Cb0_2_1_p = Interleave(Cb0, Cb2, Cb1, Cb0).TurnRight()
    Cb02_1p   = Cb0_2_1_p.AssumeFieldBased().AssumeTFF().Weave()
    Cb012p    =  Cb02_1p.AssumeFieldBased().AssumeTFF().Weave()
    Cb012p = Cb012p.TurnLeft()
    Cb012  = Cb012p.PointResize(Cb012p.Width()*3/4, Cb012p.Height())

    Cr0_2_1_p = Interleave(Cr0, Cr2, Cr1, Cr0).TurnRight()
    Cr02_1p   = Cr0_2_1_p.AssumeFieldBased().AssumeTFF().Weave()
    Cr012p    =  Cr02_1p.AssumeFieldBased().AssumeTFF().Weave()
    Cr012p = Cr012p.TurnLeft()
    Cr012  = Cr012p.PointResize(Cr012p.Width()*3/4, Cr012p.Height())

    Y012345 = Y012345.ConvertToYUY2()
    Cb012   =   Cb012.ConvertToYUY2()
    Cr012   =   Cr012.ConvertToYUY2()
    YToUV(Cb012, Cr012, Y012345)

    # Each row is padded out, so crop back to the actual size.
    Crop(0, 0, width, height)
}

#
# This version as above, but optimised, taking some shortcuts.
# As is, it is very hard to read, which is why the above exists.
#
function OptimisedReadV210(string filename, int width, int height, int "fh")
{
    #fh = 48
    fh	= Default (fh, 0)
	
    rwidth = (width/48 + (width%48==0 ? 0 : 1)) * 48  * 2/3

    Cb0Y1Cr1Y4_H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:14:2")
    Cb0Y1Cr1Y4_L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:0:6")
    Cb0Y1Cr1Y4 = Cb0Y1Cr1Y4_H.Overlay(Cb0Y1Cr1Y4_L.Levels(0,1,256, 0,64, false), mode="Add")

    Y0Cb1Y3Cr2_H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:20:4")
    Y0Cb1Y3Cr2_L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:8:4")
    Y0Cb1Y3Cr2 = Y0Cb1Y3Cr2_H.Overlay(Y0Cb1Y3Cr2_L.Levels(0,1,256, 0,16, false), mode="Add")

    Cr0Y2Cb2Y5_H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:26:6")
    Cr0Y2Cb2Y5_L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:16:2")
    Cr0Y2Cb2Y5 = Cr0Y2Cb2Y5_H.Overlay(Cr0Y2Cb2Y5_L.Levels(0,1,256, 0,4, false), mode="Add")

    Cb0Y1Cr1Y4  = Cb0Y1Cr1Y4.TurnRight()
    Cb0Cr1_Y1Y4 = Cb0Y1Cr1Y4.AssumeFrameBased().AssumeTFF().SeparateFields()
    Y1Y4        = Cb0Cr1_Y1Y4.SelectOdd()
    Cb0_Cr1     = Cb0Cr1_Y1Y4.SelectEven().AssumeFrameBased().AssumeTFF().SeparateFields()
    Cb0 = Cb0_Cr1.SelectEven()
    Cr1 = Cb0_Cr1.SelectOdd()

    Y0Cb1Y3Cr2  = Y0Cb1Y3Cr2.TurnRight()
    Y0Y3_Cb1Cr2 = Y0Cb1Y3Cr2.AssumeFrameBased().AssumeTFF().SeparateFields()
    Y0Y3        = Y0Y3_Cb1Cr2.SelectEven()
    Cb1_Cr2     = Y0Y3_Cb1Cr2.SelectOdd().AssumeFrameBased().AssumeTFF().SeparateFields()
    Cb1 = Cb1_Cr2.SelectEven()
    Cr2 = Cb1_Cr2.SelectOdd()

    Cr0Y2Cb2Y5  = Cr0Y2Cb2Y5.TurnRight()
    Cr0Cb2_Y2Y5 = Cr0Y2Cb2Y5.AssumeFrameBased().AssumeTFF().SeparateFields()
    Y2Y5        = Cr0Cb2_Y2Y5.SelectOdd()
    Cr0_Cb2     = Cr0Cb2_Y2Y5.SelectEven().AssumeFrameBased().AssumeTFF().SeparateFields()
    Cr0 = Cr0_Cb2.SelectEven()
    Cb2 = Cr0_Cb2.SelectOdd()

    Y03_25_14_pp     = Interleave(Y0Y3, Y2Y5, Y1Y4, Y0Y3)
    Y0235_1p4p       = Y03_25_14_pp.AssumeFieldBased().AssumeTFF().Weave()
    Y012p345p        =   Y0235_1p4p.AssumeFieldBased().AssumeTFF().Weave()
    Y012345   = Y012p345p.PointResize(Y012p345p.Width(), Y012p345p.Height()*3/4)
    Y012345   = Y012345.TurnLeft()

    Cb0_2_1_p = Interleave(Cb0, Cb2, Cb1, Cb0)
    Cb02_1p   = Cb0_2_1_p.AssumeFieldBased().AssumeTFF().Weave()
    Cb012p    =   Cb02_1p.AssumeFieldBased().AssumeTFF().Weave()
    Cb012  = Cb012p.PointResize(Cb012p.Width(), Cb012p.Height()*3/4)
    Cb012  = Cb012.TurnLeft()

    Cr0_2_1_p = Interleave(Cr0, Cr2, Cr1, Cr0)
    Cr02_1p   = Cr0_2_1_p.AssumeFieldBased().AssumeTFF().Weave()
    Cr012p    =   Cr02_1p.AssumeFieldBased().AssumeTFF().Weave()
    Cr012  = Cr012p.PointResize(Cr012p.Width(), Cr012p.Height()*3/4)
    Cr012  = Cr012.TurnLeft()

    Y012345 = Y012345.ConvertToYUY2()
    Cb012   =   Cb012.ConvertToYUY2()
    Cr012   =   Cr012.ConvertToYUY2()
    YToUV(Cb012, Cr012, Y012345)

    Crop(0, 0, width, height)
}

#
# This version as a modified version of OptimisedReadV210 to output Stack16.
# Using this, you can use Stack16 capable plugins (such as Dither) to process all 10 bits.
#
function Readv210Stack16(string filename, int width, int height, int "fh")
{
    fh	= Default (fh, 0)
	
    rwidth = (width/48 + (width%48==0 ? 0 : 1)) * 48  * 2/3

    Cb0Y1Cr1Y4_H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:14:2")
    Cb0Y1Cr1Y4_L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:0:6")
    Cb0Y1Cr1Y4_8 = Cb0Y1Cr1Y4_H.Overlay(Cb0Y1Cr1Y4_L.Levels(0,1,256, 0,64, false), mode="Add")
    Cb0Y1Cr1Y4_10 = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:6:2")
    Cb0Y1Cr1Y4 = StackVertical(Cb0Y1Cr1Y4_8,Cb0Y1Cr1Y4_10)

    Y0Cb1Y3Cr2_H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:20:4")
    Y0Cb1Y3Cr2_L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:8:4")
    Y0Cb1Y3Cr2_8 = Y0Cb1Y3Cr2_H.Overlay(Y0Cb1Y3Cr2_L.Levels(0,1,256, 0,16, false), mode="Add")
    Y0Cb1Y3Cr2_10 = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:12:2")
    Y0Cb1Y3Cr2 = StackVertical(Y0Cb1Y3Cr2_8,Y0Cb1Y3Cr2_10)

    Cr0Y2Cb2Y5_H = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:26:6")
    Cr0Y2Cb2Y5_L = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:16:2")
    Cr0Y2Cb2Y5_8 = Cr0Y2Cb2Y5_H.Overlay(Cr0Y2Cb2Y5_L.Levels(0,1,256, 0,4, false), mode="Add")
    Cr0Y2Cb2Y5_10 = RawReader(filename, "Y8", rwidth, height, filehead=fh, packing="32:18:2")
    Cr0Y2Cb2Y5 = StackVertical(Cr0Y2Cb2Y5_8,Cr0Y2Cb2Y5_10)

    Cb0Y1Cr1Y4  = Cb0Y1Cr1Y4.TurnRight()
    Cb0Cr1_Y1Y4 = Cb0Y1Cr1Y4.AssumeFrameBased().AssumeTFF().SeparateFields()
    Y1Y4        = Cb0Cr1_Y1Y4.SelectOdd()
    Cb0_Cr1     = Cb0Cr1_Y1Y4.SelectEven().AssumeFrameBased().AssumeTFF().SeparateFields()
    Cb0 = Cb0_Cr1.SelectEven()
    Cr1 = Cb0_Cr1.SelectOdd()

    Y0Cb1Y3Cr2  = Y0Cb1Y3Cr2.TurnRight()
    Y0Y3_Cb1Cr2 = Y0Cb1Y3Cr2.AssumeFrameBased().AssumeTFF().SeparateFields()
    Y0Y3        = Y0Y3_Cb1Cr2.SelectEven()
    Cb1_Cr2     = Y0Y3_Cb1Cr2.SelectOdd().AssumeFrameBased().AssumeTFF().SeparateFields()
    Cb1 = Cb1_Cr2.SelectEven()
    Cr2 = Cb1_Cr2.SelectOdd()

    Cr0Y2Cb2Y5  = Cr0Y2Cb2Y5.TurnRight()
    Cr0Cb2_Y2Y5 = Cr0Y2Cb2Y5.AssumeFrameBased().AssumeTFF().SeparateFields()
    Y2Y5        = Cr0Cb2_Y2Y5.SelectOdd()
    Cr0_Cb2     = Cr0Cb2_Y2Y5.SelectEven().AssumeFrameBased().AssumeTFF().SeparateFields()
    Cr0 = Cr0_Cb2.SelectEven()
    Cb2 = Cr0_Cb2.SelectOdd()

    Y03_25_14_pp     = Interleave(Y0Y3, Y2Y5, Y1Y4, Y0Y3)
    Y0235_1p4p       = Y03_25_14_pp.AssumeFieldBased().AssumeTFF().Weave()
    Y012p345p        =   Y0235_1p4p.AssumeFieldBased().AssumeTFF().Weave()
    Y012345   = Y012p345p.PointResize(Y012p345p.Width(), Y012p345p.Height()*3/4)
    Y012345   = Y012345.TurnLeft()

    Cb0_2_1_p = Interleave(Cb0, Cb2, Cb1, Cb0)
    Cb02_1p   = Cb0_2_1_p.AssumeFieldBased().AssumeTFF().Weave()
    Cb012p    =   Cb02_1p.AssumeFieldBased().AssumeTFF().Weave()
    Cb012  = Cb012p.PointResize(Cb012p.Width(), Cb012p.Height()*3/4)
    Cb012  = Cb012.TurnLeft()

    Cr0_2_1_p = Interleave(Cr0, Cr2, Cr1, Cr0)
    Cr02_1p   = Cr0_2_1_p.AssumeFieldBased().AssumeTFF().Weave()
    Cr012p    =   Cr02_1p.AssumeFieldBased().AssumeTFF().Weave()
    Cr012  = Cr012p.PointResize(Cr012p.Width(), Cr012p.Height()*3/4)
    Cr012  = Cr012.TurnLeft()

    Y012345 = Y012345.ConvertToYV16()
    Cb012   =   Cb012.ConvertToYV16()
    Cr012   =   Cr012.ConvertToYV16()
    YToUV(Cb012, Cr012, Y012345)

    #This is commented out because I don't think its necessary. ## This IS required for some resolutions, DUH.
    Crop(0, 0, width, height*2)
}

Last edited by Aegwyn11; 7th June 2013 at 19:36. Reason: Uncommented final crop in code.
Aegwyn11 is offline   Reply With Quote
Old 7th June 2013, 19:54   #57  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
Does anyone know how to read AVI and/or MOV files with Sashimi?

Using FFmpeg, I created test.avi with v210 video, then created test.yuv from the test.avi file (using -c:v copy). I then subtracted the resulting two file sizes and put that number as my file header. My frame of video gets chopped, with some of what should be on the left showing on the right side (the amount changes as you advance frames with the amount of "frame on the left" increasing with each frame). Also, it looks like the chroma channels are getting reversed frame to frame.

Are there frame headers as well as a file header? I can use FFmpeg to copy my files to .yuv files, but I'd rather be able to read the avi's and mov's directly (saves time, effort, and disk space).
Aegwyn11 is offline   Reply With Quote
Old 7th June 2013, 20:45   #58  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: UK
Posts: 2,324
Use patched ffms2 source plugin.
kolak is offline   Reply With Quote
Old 7th June 2013, 21:42   #59  |  Link
tin3tin
Registered User
 
tin3tin's Avatar
 
Join Date: Mar 2005
Posts: 365
Strange that this thread was resurrected just as I needed it. :-)

I'm trying to import a 14 bit RAW file from a Canon 60D with Magic Lantern. 1280x720.

I've tried the various examples, but unfortunately there was no 14 bit example.

https://www.wetransfer.com/downloads...7200431/4cf428

This shows some resemblance with the original image:
Code:
LoadPlugin("Sashimi.dll")
RawReader("M03-1651.RAW", "RGB", 1280,720,packing="14")
But I don't know the "packing" of Magic Lantern Raw. Would be great if Avi/Vapour-synth could import those files for further correction.
__________________
DVD slideshow GUI(Freeware).
tin3tin is offline   Reply With Quote
Old 7th June 2013, 22:13   #60  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
Quote:
Originally Posted by tin3tin View Post
Strange that this thread was resurrected just as I needed it. :-)

I'm trying to import a 14 bit RAW file from a Canon 60D with Magic Lantern. 1280x720.

I've tried the various examples, but unfortunately there was no 14 bit example.
Unfortunate for you, camera RAW modes are NOT standard. And they vary from camera to camera, sometimes even within the same manufacturer. I could help show you how to read RGB from RGB16 files, but I don't think that would be helpful here.

http://en.wikipedia.org/wiki/Raw_image_format
Aegwyn11 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 11:06.


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