Tuesday, October 14, 2008

batch file scripts

refer to http://www.robvanderwoude.com/battech.html and any related pages for fantastic description 

also refer to http://weblogs.asp.net/jgalloway/archive/2006/11/20/top-10-dos-batch-tips-yes-dos-batch.aspx for some useful tips

<br /> Top 10 DOS Batch tips (Yes, DOS Batch...) - Jon Galloway <br />

  • Use PUSHD / POPD to change directories
    Read Scott Hanselman's writeup on PUSHD. The basic idea is that it keeps a stack, so at the simplest level you can do something like this:

    PUSHD "C:\Working Directory\"
    ::DO SOME WORK
    POPD

    That allows you to call the batch file from any directory and return to the original directory when you're done. The cool thing is that PUSHD can be nested, so you can move all over the place within your scripts and just POPD your way out when you're done.

  • Call FTP scripts
    This sample prompts for the username and password, but they can of course be hardcoded if you're feeling lucky.

    set FTPADDRESS=ftp.myserver.com
    set SITEBACKUPFILE=FileToTransfer.zip

    set /p FTPUSERNAME=Enter FTP User Name: 
    set /p FTPPASSWORD=Enter FTP Password: 
    CLS
    > script.ftp USER
    >>script.ftp ECHO %FTPUSERNAME%
    >>script.ftp ECHO %FTPPASSWORD%
    >>script.ftp ECHO binary
    >>script.ftp ECHO prompt n
    :: Use put instead of
    get to upload the file
    >>script.ftp ECHO get %SITEBACKUPFILE%
    >>script.ftp ECHO bye
    FTP
    -v -s:script.ftp %FTPADDRESS%
    TYPE NUL
    >script.ftp
    DEL script.ftp

  • Read from the registry
    You can make creative use of the FOR command to read from and parse a registry value (see my previous post for more info).

    FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" /v SQL2005') DO SET SQLINSTANCE=%%B

  • Run SQL Commands
    You can call OSQL (or SQLCMD on servers with SQL 2005 installed) to execute SQL commands: 
    osql -E -d master -Q "BACKUP DATABASE [%DATABASENAME%] TO DISK = N'D:\DataBase\Backups\%DATABASENAME%_backup' WITH INIT , NOUNLOAD , NAME = N'%DATABASENAME% backup', NOSKIP , STATS = 10, NOFORMAT"

  • Check if a file or folder exists
    I used this to do a quick and dirty check to see if a Windows Hotfix had been installed in my IE7 Standalone scripts:

    IF EXIST %SystemRoot%\$NtUninstallKB915865$\ GOTO KB_INSTALLED
    ECHO Installing Hotfix (KB915865) to allow tab support
    START
    /D "%~dp0/Installation/Update/" xmllitesetup.exe

  • Pause execution for a number of seconds
    There are different ways to do this from within a batch file, all with their tradeoffs. I use a ping to an invalid IP address with a timeout. The best way to do this is to find an invalid IP address and then pint it, but 1.1.1.1 is a pretty safe bet:

    ECHO Waiting 15 seconds
    PING
    1.1.1.1 -n 1 -w 15000 > NUL

  • Use defaults for optional parameters
    It's not really easy to check for a missing parameter. You have to use something like "IF dummy==%1dummy", which will only be true if %1 is empty. So, for example, here we're allowing a user to supply an application path via the third parameter, and defaulting it if it's missing. By the way, beware the IF syntax. The line spacing makes a difference, so this is one that I just copy and paste to avoid figuring it out every time.

    IF dummy==dummy%3 (
    SET APPLICATIONPATH
    ="C:\Program Files\MyApp\"
    ) ELSE (
    SET APPLICATIONPATH
    = %3
    )

  • Process each file matching a pattern in a directory
    I previously posted a script which iterates all files named *.bak in a directory and restores them on the local instance of SQL Server. Here's an excerpt:

    PUSHD %BACKUPDIRECTORY%
    FOR
    %%A in (*.bak) do CALL :Subroutine %%A
    POPD
    GOTO:EOF

    :Subroutine
    set DBNAME=%~n1
    ::RUN SOME OSQL COMMANDS TO RESTORE THE BACKUP
    GOTO:EOF

  • Use batch parameter expansion to avoid parsing file or directory info
    Batch file parameters are read as %1, %2, etc. DOS Command Extensions - available on Windows 2000 and up - add a lot of automatic parsing and expansion that really simplifies reading filenames passed in as parameters. I originally put this at the top of the list, but I moved it because I figured the insane syntax would drive people off. I wrote a simple batch script that shows some examples. I think that makes it a little more readable. Stick with me, I think this is one of the best features in DOS batch and is worth learning.

    First, here's the batch file which just echos the processed parameters:

  • @echo off
    echo
    %%~1 = %~1 
    echo
    %%~f1 = %~f1
    echo
    %%~d1 = %~d1
    echo
    %%~p1 = %~p1
    echo
    %%~n1 = %~n1
    echo
    %%~x1 = %~x1
    echo
    %%~s1 = %~s1
    echo
    %%~a1 = %~a1
    echo
    %%~t1 = %~t1
    echo
    %%~z1 = %~z1
    echo
    %%~$PATHATH:1 = %~$PATHATH:1
    echo
    %%~dp1 = %~dp1
    echo
    %%~nx1 = %~nx1
    echo
    %%~dp$PATH:1 = %~dp$PATH:1
    echo
    %%~ftza1 = %~ftza1



    Now we'll call it, passing in "C:\Windows\Notepad.exe" as a parameter:

    C:\Temp>batchparams.bat c:\windows\notepad.exe
    %~1 = c:\windows\notepad.exe
    %~f1 = c:\WINDOWS\NOTEPAD.EXE
    %~d1 = c:
    %~p1 = \WINDOWS\
    %~n1 = NOTEPAD
    %~x1 = .EXE
    %~s1 = c:\WINDOWS\NOTEPAD.EXE
    %~a1 = --a------
    %~t1 = 08/25/2005 01:50 AM
    %~z1 = 17920
    %~$PATHATH:1 =
    %~dp1 = c:\WINDOWS\
    %~nx1 = NOTEPAD.EXE
    %~dp$PATH:1 = c:\WINDOWS\
    %~ftza1 = --a------ 08/25/2005 01:50 AM 17920 c:\WINDOWS\NOTEPAD.EXE



    As I said, the syntax is completely crazy, but it's easy to look them up - just type HELP CALL at a DOS prompt; it gives you this:

    %~1 - expands %1 removing any surrounding quotes (")
    %~f1 - expands %1 to a fully qualified path name
    %~d1 - expands %1 to a drive letter only
    %~p1 - expands %1 to a path only
    %~n1 - expands %1 to a file name only
    %~x1 - expands %1 to a file extension only
    %~s1 - expanded path contains short names only
    %~a1 - expands %1 to file attributes
    %~t1 - expands %1 to date/time of file
    %~z1 - expands %1 to size of file
    %~$PATH:1 - searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string

    The modifiers can be combined to get compound results:

    %~dp1 - expands %1 to a drive letter and path only
    %~nx1 - expands %1 to a file name and extension only
    %~dp$PATH:1 - searches the directories listed in the PATH environment variable for %1 and expands to the drive letter and path of the first one found.
    %~ftza1 - expands %1 to a DIR like output line

    In the above examples %1 and PATH can be replaced by other valid values. The %~ syntax is terminated by a valid argument number. The %~ modifiers may not be used with %*


  • Learn from the masters
    By far, my favorite resource for DOS Batch trickery is the Batch Files section of Rob van der Woude's Scripting Pages. He's got some good PowerShell resources, too.

  • What about you? Got any favorite DOS Batch tricks?


       


    Friday, October 10, 2008

    video demystified

    YUV Color Space

    The YUV color space is used by the PAL

    (Phase Alternation Line), NTSC (National
    Television System Committee), and SECAM
    (Sequentiel Couleur Avec Mémoire or Sequential
    Color with Memory) composite color video
    standards. The black-and-white system used
    only luma (Y) information; color information
    (U and V) was added in such a way that a
    black-and-white receiver would still display a
    normal black-and-white picture. Color receivers
    decoded the additional color information to
    display a color picture.

    The basic equations to convert between

    gamma-corrected RGB (notated as R´G´B´ and
    discussed later in this chapter) and YUV are:
    Y = 0.299R´ + 0.587G´ + 0.114B´
    U = – 0.147R´ – 0.289G´ + 0.436B´
    = 0.492 (B´ – Y)
    V = 0.615R´ – 0.515G´ – 0.100B´
    = 0.877(R´ – Y)

    YIQ Color Space
    The YIQ color space, further discussed in
    Chapter 8, is derived from the YUV color space
    and is optionally used by the NTSC composite
    color video standard. (The “I” stands for “inphase”
    and the “Q” for “quadrature,”

    YCbCr Color Space
    The YCbCr color space was developed as
    part of ITU-R BT.601 during the development
    of a world-wide digital component video standard
    (discussed in Chapter 4). YCbCr is a
    scaled and offset version of the YUV color
    space. Y is defined to have a nominal 8-bit
    range of 16–235; Cb and Cr are defined to have
    a nominal range of 16–240. There are several
    YCbCr sampling formats, such as 4:4:4, 4:2:2,
    4:1:1, and 4:2:0 that are also described.

    4:4:4 YCbCr Format

    Figure 3.2 illustrates the positioning of
    YCbCr samples for the 4:4:4 format. Each sample
    has a Y, a Cb and a Cr value. Each sample is
    typically 8 bits (consumer applications) or 10
    bits (pro-video applications) per component.
    Each sample therefore requires 24 bits (or 30
    bits for pro-video applications).

    4:2:2 YCbCr Format
    Figure 3.3 illustrates the positioning of
    YCbCr samples for the 4:2:2 format. For every
    two horizontal Y samples, there is one Cb and
    Cr sample. Each sample is typically 8 bits (consumer
    applications) or 10 bits (pro-video applications)
    per component. Each sample
    therefore requires 16 bits (or 20 bits for provideo
    applications), usually formatted as
    shown in Figure 3.4.
    To display 4:2:2 YCbCr data, it is first converted
    to 4:4:4 YCbCr data, using interpolation
    to generate the missing Cb and Cr samples.

    4:2:0 YCbCr Format
    Rather than the horizontal-only 2:1 reduction
    of Cb and Cr used by 4:2:2, 4:2:0 YCbCr
    implements a 2:1 reduction of Cb and Cr in
    both the vertical and horizontal directions. It is
    commonly used for video compression.
    As shown in Figures 3.7 through 3.11,
    there are several 4:2:0 sampling formats. Table
    3.3 lists the YCbCr formats for various DV
    applications.
    To display 4:2:0 YCbCr data, it is first converted
    to 4:4:4 YCbCr data, using interpolation
    to generate the new Cb and Cr samples. Note
    that some MPEG decoders do not properly
    convert the 4:2:0 YCbCr data to the 4:4:4 format,
    resulting in a “chroma bug.”

    Gamma Correction
    The transfer function of most CRT displays
    produces an intensity that is proportional to
    some power (referred to as gamma) of the signal
    amplitude. As a result, high-intensity
    ranges are expanded and low-intensity ranges
    are compressed (see Figure 3.17). This is an
    advantage in combatting noise, as the eye is
    approximately equally sensitive to equally relative
    intensity changes. By “gamma correcting”
    the video signals before transmission, the
    intensity output of the display is roughly linear
    (the gray line in Figure 3.17), and transmission-
    induced noise is reduced.
    To minimize noise in the darker areas of
    the image, modern video systems limit the
    gain of the curve in the black region. This
    technique limits the gain close to black and
    stretches the remainder of the curve to maintain
    function and tangent continuity.
    Although video standards assume a display
    gamma of about 2.2, a gamma of about 2.5
    is more realistic for CRT displays. However,
    this difference improves the viewing in a dimly
    lit environment.

    Thursday, October 9, 2008

    cshell script

    basic

    Shell variables can be created using the set name=value construct; they are henceforth referenced by prepending the shell variable name with a dollar: say, echo $name

    variable

    Variables can be used in C shell by typing a dollar sign ($) before the variable name. If the variable is an array, the subscript can be specified using brackets, and the number of elements can be obtained using the form $#var2.

    The existence of variables can be checked using the form $?variable
         if (! $?var) set var=abc

    Simple integer calculations can be performed by C shell, using C language-type operators. To assign a calculated value, the @ command is used as follows: 
    @ var = $a + $x * $z

    quotions

    Ticks don't recognise certain characters in the shell. Ticks don't honour special characters such as the dollar sign. (')

    we can use ticks and quotes interchangeably unless we need to honour special characters in the shell.(")

    You can always use the backslash to quote a character. However, within the single quote mechanism, "\'" does not "quote the quote." The proper way to do this is as follows: 
    % echo 'Don' \' 't do that'
    Don ' t do that

    The purpose of a backtick is to be able to run a command, and capture the output of
    that command.  (`) Say:DATE=`date`

    job control

    Processes may be started in the background by following the command with an ampersand (&).

    When a job is placed in the background, information for the job is shown similar to the example given below: 
    [1] 15934

    This specifies that the process has been placed in the background, and is job 1. In order to recall jobs placed in the background, the fg command is used, while the bg command places a recently stopped process into the background. The jobs command gives a list of all processes under control of the current shell. Also, typing a percent sign (%) with the job number brings that particular job to the foreground.

    file judgement

    =~     If the right hand side matches a pattern, (i.e., similar to filename matching, with asterisks and question marks.) the condition is true.

     !~     If the right hand side doesn't match a pattern, the condition is true.

    -d $var     True if the file is a directory.

    -e $var     True if the file exists.

    -f $var     True if the file is a file. (I.e., not a directory)

    -o $var     True if the file is owned by the user.

    -r $var     True if the user has read access.

    -w $var     True if the user has write access.

    -x $var     True if the user has execute access.

    -z $var     True if the file is zero-length.

    parameters

    Command line arguments are in special shell variables 0, 1, 2 etc. $0 is the name of the script, $1 the first argument (if present), etc. All command line arguments $1, $2,.. are also pre-defined in an shell variable argv, which is actually a list (like an array). It can be referenced as $argv[1], $argv[2], ... etc. This form has the advantage that the construct $#argv (the same as $*) can be used to find the number of elements in the list

    $$ is a way of referring to the process number of the current shell. The
    characters $$ are often used as part of a filename in order to generate a
    unique name for a temporary file.

    Looping in a shell script

    The C-shell includes the following
    constructs: if, switch, foreach, while and goto.

    regular expression is supported, e.g. foreach varname (List*)

    repeat 100 DoSth

    foreach VariableName (SomeList)
        command1
        command2

        if (something1) break

        if (something2) continue
            ...
        commandn

    end

    done:

    switch ($year)
    case 92:
        set lyf = 1
        set soyf = 1
        breaksw
    case 93*:
        set lyf = 0
        set soyf = 3
        breaksw
    endsw

    while ( expr )
        statement_list
    end

    a list is words separated with comma,i.e. ","

    Labels are defined by a name, followed by a colon, label: jumping to a label is be done by using goto label.

    Decision making: using the if command

    simple format: if (expression) command

    if ( ! -d mydir &&  $a== `USER`) then
        commands
    else if ( expression ) then
        commands
    else
        commands
    endif

    else if can be replace with elif

    return value

    In terms of any programming language one has the boolean operators, true and false.

    In the shell, being "true" is represented by a 0 (zero) and anything else is
    false. use $? to get the return value. say: echo $?

    Aliases 

    Aliases provide a way of conveniently recalling frequently used commands with a user-defined shorthand name. The alias statement associates a list of words with an alias name. The "=" is optional. Parentheses are used around the wordlist if it contains special characters such as i/o redirection operators that should be part of the alias definition. 

    alias name [ = ] ( wordlist )
    alias name [ = ] wordlist 

    alias name prints the definition of that alias; alias pattern prints the definitions of all the aliases whose names match the pattern. alias without any arguments prints the definitions of all the aliases. 

    alias
    alias name
    alias pattern 

    unalias namelist discards the specified aliases; unalias pattern discards all the aliases whose names match the pattern. 

    unalias namelist
    unalias pattern

    Procedures 

    this may be of problem
    Procedures defined by the proc statement can recursively call other procedures. They can be referred to inside an expression or as a new command, in which case any value returned is written to stdout. There is an implicit return statement at the end of every procedure definition. 

    proc name ( [ namelist ] )
        statement_list
    return [ expr ]
    end 

    The proc statement with no arguments prints a list of all the procedures that have been defined; if the argument is a name, that one procedure is listed; if the argument is a pattern, all procedures whose names match the pattern are listed. 

    proc
    proc name
    proc pattern 

    unproc namelist (where namelist is a series of names separated by commas) discards the specified procedures. unproc pattern discards all procedures whose names match the pattern are discarded. 

    unproc namelist
    unproc pattern



    sed usage:

    Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]
    -n, --quiet, --silent
        suppress automatic printing of pattern space
    -e script, --expression=script
        add the script to the commands to be executed
    -f script-file, --file=script-file
        add the contents of script-file to the commands to be executed
    -i[SUFFIX], --in-place[=SUFFIX]
        edit files in place (makes backup if extension supplied)
    -c, --copy
        use copy instead of rename when shuffling files in -i mode
        (avoids change of input file ownership)
    -l N, --line-length=N
        specify the desired line-wrap length for the `l' command
    --posix
        disable all GNU extensions.
    -r, --regexp-extended
        use extended regular expressions in the script.
    -s, --separate
        consider files as separate rather than as a single continuouslong stream.
    -u, --unbuffered
        load minimal amounts of data from the input files and flush the output buffers more often
    --help display this help and exit
    --version output version information and exit

    To delete trailing whitespace from end of each line, enter:
        $ cat input.txt | sed 's/[ \t]*$//;s/abc/def/' > output.txt
    to delete all empty lines from a file called /tmp/data.txt, enter:
        $ sed '/^$/d' /tmp/data.txt
    GNU Sed support -i option to edit files in place:
        $ sed -i '/Windows/d' /tmp/data.txt

    Tuesday, October 7, 2008

    视频接口及其它

    from zh.wikipedia.org
    color space
    YUV, YCbCr,是一種顏色編碼方法。
    YUV是編譯true-color顏色空間(color space)的種類。「Y」表示明亮度(Luminance、Luma),「U」和「V」則是色度、濃度(Chrominance、Chroma)。
    The scope of the terms Y'UV, YUV, YCbCr, YPbPr, etc., is sometimes ambiguous and overlapping. Historically, the terms YUV and Y'UV was used for a specific analog encoding of color information in television systems, while YCbCr was used for digital encoding of color information suited for video and still-image compression and transmission such as MPEG and JPEG. Today, the term YUV is commonly used in the computer industry to describe file-formats that are encoded using YCbCr.

    电视制式
    PAL制式
    PAL制式是电视广播中色彩编码的一种方法。全名为 Phase Alternating Line 逐行倒相。除了北美,东亚部分地区使用 NTSC制式 ,中东、法国及东欧采用 SECAM制式 以外,世界上大部份地区都是采用 PAL。PAL 由德国人 Walter Bruch 在1967年提出,当时他是为德律风根(Telefunken)工作。“PAL”有时亦被用来指625 线,每秒25格,隔行扫瞄,PAL色彩编码的电视制式。

    PAL 发明的原意是要在兼容原有黑白电视广播格式的情况下加入彩色讯号。PAL 的原理与 NTSC 接近。“逐行倒相”的意思是每行扫瞄线的彩色讯号,会跟上一行倒相。作用是自动改正在传播中可能出现的错相。早期的 PAL 电视机没有特别的组件改正错相,有时严重的错相仍然会被肉眼明显看到。近年的电视会把上行的色彩讯号跟下一行的平均起来才显示。这样 PAL 的垂直色彩解像度会低于NTSC 。但由于人眼对色彩的灵敏不及对光暗,因此这并不是明显问题。

    PAL 本身是指色彩系統,經常被配以 625線,每秒25格畫面,隔行掃瞄的電視廣播格式

    NTSC制式
    NTSC制式,又简称为N制,是1952年12月由美国国家电视标准委员会(National Television System Committee,缩写为NTSC)制定的彩色电视广播标准,两大主要分支是NTSC-J与NTSC-US(又名NTSC-U/C)。

    它属于同时制,帧频为每秒29.97fps,扫描线为525,逐行扫描,画面比例为4:3,分辨率为720x480

    分辨率
    480p 是一种视频显示格式。字母p表示逐行扫描 (progressive scan),数字 480 表示其垂直解析度,也就是垂直方向有480条水平线的扫描线;而每条水平线分辨率有640个像素,纵横比(aspect ratio)为4:3,即通常所说的标准电视格式(standard-definition television,SDTV)。帧频通常为30赫兹或者60赫兹。


    通常1080p的画面解析度为1920×1080,即一般所说的高解析度电视(HDTV)。

    通常720p的画面解像度为1280×720,一般亦可称为HD。


    显示接口
    VGA端子(其他的名称包括RGB端子,D-sub 15,或mini D15),是一种3排共15针的DE-15。VGA端子通常在电脑的显示卡、显示器及其他设备。是用作传送类比讯号

    AV端子(又称复合端子)原文为Composite video connector,是家用影音电器用来传送类比视讯如NTSC、PAL、SECAM)的常见端子。AV端子通常是黄色的RCA端子,另外配合两条红色与白色的RCA端子传送音讯。欧洲的电视机通常以SCART端子取代RCA端子,不过SCART的设计上可以载送画质比YUV更好的RGB讯号,故也被用来连接显示器、电视游乐器或DVD播放机。在专业应用当中,也有使用BNC端子以求获得更佳讯号品质。

    在AV端子中传送的是类比电视讯号的三个来源要素:Y、U、V,以及作为同步化基准的脉冲信号。Y代表影像的亮度(luminance,又称brightness),并且包含了同步脉冲,只要有Y信号存在就可以看到黑白的电视影像(事实上,这是彩色电视与早期黑白电视相容的方法)。U信号与V信号之间承载了颜色的资料,U和V先被混合成一个信号中的两组正交相位(此混合后的信号称为彩度(chrominance)),再与Y信号作加总。因为Y是基频信号而UV是与载波混合在一起,所以这个加总的动作等同于分频多工。


    S-端子,或称“独立视讯端子” ,而当中的S是“Separate”的简称。也称为Y/C (或被错误的称为S-VHS和“超级端子”) 。它是一种将视频数据分成两个单独的讯号(光亮度和色度)进行传送的模拟视频讯号,不像合成视频讯号(composite video)是将所有讯号打包成一个整体进行传送。

    S-端子能在480i或576i的解析度下工作。

    在S-端子中,光亮度(Y; greyscale)的讯号和调制色度(C; colour)的讯号也是由独立的电线或电线组所传送。

    在合成视频中,光亮度的讯号是被低通滤波器变成低通滤波,以防以因线路而干扰,因高频率的光亮度资讯及色度讯号的一部分是重叠的。而S-端子把两种讯号分开,这种就不用把光亮度的讯号再转成低通滤波。这样可以给予光亮度的讯号有更大的频宽,也解决了讯号重叠的问题。因此,受干扰的点阵讯号事被排除
    但是,影像讯号被分离为亮度与色度两部分,因此S-端子有时也被视为是一种合成影像讯号,但就品质上而言,S-Video是component讯号中最差的一种,远不如其他更为复杂的component影像讯号(如RGB),但较之另外一种模拟信号 CVBS 锐利

    目前S-Video的讯号一般采用4 接脚(pin)的mini-DIN连接端子,终端阻抗须为75欧姆

    色差端子(Component Video Connector,简体中文译为分量接口)是把类比视频中的明度、彩度、同步脉冲分解开来各自传送的端子
    分量传送的视频有许多种方式,例如将三原色直接传送的RGB方式,以及从RGB转换为明度(Y)与色差(Cb/Cr或Pb/Pr)的方式。RGB方式将所有的颜色信息作同等的处理,虽然有最高的画质,但由于RGB方式对传输带宽和储存空间的消耗太大,为节省带宽,使用色差方式来传送与记录分量视频是现在的主流。

    色差在设计上利用了“人眼对明度较敏感,而对色度较不敏感”的特性,将视讯中的色彩信息加以削减,转换公式如下:
    明度: Y=0.299*R + 0.587*G + 0.114*B
    色差: Cb=0.564*(B-Y) = -0.169*R - 0.331*G + 0.500*B
       Cr=0.713*(R-Y) = 0.500*R - 0.419*G - 0.081*B


    所谓的“色差”即为颜色值与明度之间的差值。转换过后的颜色信息量被删减了约一半,但由于人眼的特性,使得色差处理过后的影像与原始影像的差异很难被察觉。最终的色差数据与RGB数据相比节省了1/3的带宽


    DVI的英文全名为Digital Visual Interface,中文称为“数位视讯介面”。是一种视讯介面标准,设计的目标是透过数位化的传送来强化个人电脑显示器的画面品质。目前广泛应用于LCD,数位投影机等显示设备上。此标准由显示业界数家领导厂商所组成的论坛:“数位显示工作小组”(Digital Display Working Group,DDWG)制订。DVI介面可以传送未压缩的数位视频资料到显示装置。本规格部分相容于HDMI标准。

    HDMI(英语:High Definition Multimedia Interface),即高清晰度多媒体介面,是一种全数位化影像/声音传送介面,可以传送无压缩的音频信号及视频信号。HDMI提供所有相容装置——如机上盒、DVD播放机、个人电脑、电视游乐器、综合扩大机、数位音响与电视机——一个共通的资料连接管道。HDMI可以同时传送音频和影音信号,由于音频和视频信号采用同一条电缆,大大简化了系统的安装。
    HDMI支援各类电视与电脑影像格式,包括SDTV、HDTV视频画面,再加上多声道数位音频。在传送时,各种视频资料将被HDMI收发晶片以“Transition Minimized Differential Signaling”(TMDS)技术编码成资料封包。规格初制订时其最大画素传输率为165Mpx/sec,足以支援1080p画质每秒60张画面,或者UXGA解像度(1600x1200);后来在HDMI 1.3规格中扩增为340Mpx/sec,以符合未来可能的需求。

    HDMI也支援非压缩的8声道数位音频传送(取样率192kHz,资料长度24bits/sample),以及任何压缩音频串流如Dolby Digital或DTS,亦支援SACD所使用的8声道的1bit DSD信号。在HDMI 1.3规格中,又追加了超高资料量的非压缩音频串流如Dolby TrueHD与DTS-HD的支援


    DisplayPort 是Video Electronics Standards Association(VESA)推动的数位式视讯介面标准,订定于2006年5月,目前1.1版本订定于2007年4月2日。该介面订定免认证、免授权金,发展中的新型数位式音讯/视讯界面,有意要取代旧有电脑萤幕,或是电脑的家庭剧院界面。
    技术规格
    10.8 Gbit/s 的频宽,只需单条传输线即可支援 2560×1600 的高解析度显示器。
    8B/10B 资料传输

    streaming
    ITU656
    ITU-R Recommendation BT.656, sometimes also called ITU656, describes a simple digital video protocol for streaming uncompressed PAL or NTSC Standard Definition TV (525 or 625 lines) signals. The protocol builds upon the 4:2:2 digital video encoding parameters defined in ITU-R Recommendation BT.601, which provides interlaced video data, streaming each field separately, and uses the YCbCr color space and a 13.5 MHz sampling frequency for pixels.
    The standard can be implemented to transmit either 8-bit values (the standard in consumer electronics) or 10-bit values (sometimes used in studio environments). Both a parallel and a serial transmission format are defined. For the parallel format, a 25-pin Sub-D connector pinout and ECL logic levels are defined. The serial format can be transmitted over 75-ohm coaxial cable with BNC connectors, but there is also a fibre-optical version defined.
    The parallel version of the ITU-R BT.656 protocol is also used in many TV sets between chips using CMOS logic levels. Typical applications include the interface between a PAL/NTSC decoder chip and a DAC integrated circuit for driving a CRT in a TV set.
    Data format
    A BT.656 data stream is a sequence of 8-bit or 10-bit bytes, transmitted at a rate of 27 Mbyte/s. Horizontal scan lines of video pixel data are delimited in the stream by 4-byte long SAV (Start of Active Video) and EAV (End of Active Video) code sequences. SAV codes also contain status bits indicating line position in a video field or frame. Line position in a full frame can be determined by tracking SAV status bits, allowing receivers to 'synchronize' with an incoming stream.
    Individual pixels in a line are coded in YCbCr format. After an SAV code (4 bytes) is sent, the first 8 bits of Cb (chroma U) data are sent then 8 bits of Y (luma), followed by 8 bits of Cr (chroma V) for the next pixel and then 8 bits of Y. To reconstruct full resolution Y,Cb, Cr pixel values, chroma upsampling must be used.

    ITU601
    ITU-R Recommendation BT.601, more commonly know by the abbreviations Rec. 601 or BT.601 or its former name, CCIR 601, is a standard published by the CCIR (now ITU-R) for encoding interlaced analogue video signals in digital form. It includes methods of encoding 525 line 60 Hz and 625-line 50 Hz signals, both with 720 luminance samples and 360 chrominance samples per line. The colour encoding system is known as YUV 4:2:2, that being the ratio of Y:Cb:Cr samples (luminance data:blue chroma data:red chroma data). For a pair of pixels, the data are stored in the order Y1:Y2:Cb:Cr, with the chrominance samples co-sited with the first luminance sample.
    The CCIR 601 signal can be regarded as if it is a digitally encoded analog component video signal, and thus includes data for the horizontal and vertical sync and blanking intervals. Regardless of the frame rate, the luminance sampling frequency is 13.5 MHz. The luminance sample is at least 8 bits, and the chrominance samples are at least 4 bits each.

    Saturday, September 27, 2008

    搬入新居

    此志。
    2008.9.27晚正式入住并开伙。
    当晚吃的是清汤挂面。由于来不及做饭,甚至连点儿合适的菜都没有,在庆丰包子点了2个凉菜打包回来吃。

    浴房很舒服,箭牌的花洒无论大水小水量都很舒适。
    1.8的大床睡起来也很舒服的。
    一切都很好。除了环境还有点凌乱,墙壁还有些空。

    国美、大中、苏宁国庆活动

    2008.9.27 消息
    sharp 46gx3 国庆要降到 8k?
    据说要很能砍价才能拿到这个价格。 某苏宁的销售坚持说降价不超过2k
    大中标价据说还在1w以上,国庆价格尚未出台

    pchome 目前报价11480

    前面报到还分析:sharp 低端 46a63 预计不超过7.5k, 46RX1最低12k,


    有人说:sharp坏点很多,尤其a区3点,全部10点的承诺尤其吓人. 现在据说都用台湾屏。

    又有人 8.3买入, rmb 11500

    消息:花园桥国美GX3询价归来
    42gx3已经停产,目前没货,样品1W
    46gx3库存不多,十一最高不超过1W2,也许还能再便宜四五百
    感觉这个价格还是有下调的空间

    Wednesday, September 24, 2008

    tcl reference manual


    Basic Language Features

    #

    comment (continues to end of line)

    " "

    allows embedding whitespace in arguments;

    substitutions made

    { }

    group arguments; substitutions not made

    [ ]

    command substitution; replace with result of

    command

    $var

    variable substitution

    ;

    command separator

    Backslash Substitution

    \b

    backspace

    \[

    close bracket

    \n

    newline

    \$

    dollar sign

    \r

    carriage return

    \<space> space

    \t

    tab

    \;

    semi-colon

    \v

    vertical tab

    \"

    double-quote

    \{

    left brace

    \<newln> newline

    \}

    right brace

    \\

    backslash

    \ddd

    octal digits

    Built-in Variables

    env

    errorCode

    errorInfo

    Operators (in decreasing order of precedence)

    - !

    unary minus, bit-wise NOT, logical NOT

    * / %

    multiply, divide, remainder

    + -

    add, subtract

    << >>

    left and right shift

    < > <= >=

    boolean comparisons

    == !=

    boolean equal, not equa

    &

    bit-wise AND

    ^

    bit-wise exclusive OR

    |

    bit-wise inclusive OR &&

    logical AND

    ||

    logical OR

    x?y:z

    conditional operator

    All operators support integers.

    All support floating point except , %, <<, >>, &, ^, and |

    Boolean operators can also be used on strings.

    Regular Expressions

    regex | regex

    match either expression

    regex*

    match zero or more of regex

    regex+

    match one or more of regex

    regex?

    match zero or one of regex

    .

    any single character (except newline)

    ^

    match beginning of line

    $

    match end of line

    \c

    match character c

    c

    match character c

    []

    match set of characters

    [a-z]

    match range of characters

    [^]

    match characters not in range or set

    ()

    group expressions

    Keywords

    append varName value [value value ...]

    array anymore arrayName searchId

    array donesearch arrayName searchId

    array names arrayName

    array nextelement arrayName searchId

    array size arrayName

    array startsearch arrayName

    break

    case string [in] patList body [patList body ...]

    case string [in] {patList body [patList body ...]

    catch command [varName]

    cd [dirName]

    close fileId

    concat arg [arg ...]

    continue

    error message [info] [code]

    eof fileId

    error $errMsg $savedInfo

    eval arg [arg ...]

    exec arg [arg ...]

    exit [returnCode]

    expr arg

    file atime name

    file dirname name

    file executable name

    file exists name

    file extension name

    file isdirectory name

    file isfile name

    file lstat name varName

    file mtime name

    file owned name

    file readable name

    file readlink name

    file rootname name

    file size name

    file stat name varName

    file tail name

    file type name

    file writable name

    flush fileId

    for start test next body

    foreach varname list body


    format formatString [arg arg ...]

    gets fileId [varName]

    glob [-nocomplain] filename [filename ...]

    global varname [varname ...]

    history

    history add command [exec]

    history change newValue [event]

    history event [event]

    history info [count]

    history keep count

    history nextid

    history redo [event]

    history substitute old new [event]

    history words selector [event]

    if test [then] trueBody [else] [falseBody]

    incr varName [increment]

    info args procname

    info body procname

    info cmdcount

    info commands [pattern]

    info default procname arg varname

    into variable varname

    info exists varName

    info globals [pattern]

    info level [number]

    info library

    info locals [pattern]

    info procs [pattern]

    info script

    info tclversion

    info vars [pattern]

    join list [joinString]

    lappend varName value [value value ...]

    lindex list index

    linsert list index element [element element ...]

    list arg [arg ...]

    llength list

    lrange list first last

    lreplace list first last [element element ...]

    lsearch list pattern

    lsort list

    open fileName [access]

    proc name args body

    puts fileId string [nonewline]

    pwd

    read fileId

    read fileId nonewline

    read fileId numBytes

    regexp [-indices] [-nocase] exp string [matchVar] [subMatchVar

    subMatchVar ...]

    regsub [-all] [-nocase] exp string subSpec varName

    rename oldName newName

    return [value]

    scan string format varname1 [varname2 ...]

    seek fileId offset [origin]

    set varname [value]

    source fileName

    split string [splitChars]

    string compare string1 string2

    string first string1 string2

    string index string charIndex

    string last string1 string2

    string length string

    string match pattern string

    string range string first last

    string tolower string

    string toupper string

    string trim string [chars]

    string trimleft string [chars]

    string trimright string [chars]

    tell fileId

    time command [count]

    trace variable name ops command

    trace vdelete name ops command

    trace vinfo name

    unknown cmdName [arg arg ...]

    unset name [name name ...]

    uplevel [level] command [command ...]

    upvar [level] otherVar myVar [otherVar myVar ...]

    while test body