From ed8000e3581e99778d474df082887c4b82597855 Mon Sep 17 00:00:00 2001 From: Darcy Clarke Date: Wed, 31 Jul 2013 13:07:01 -0400 Subject: [PATCH 1/3] Initial commit --- .gitignore | 2 + LICENSE-MIT | 22 + README | 0 README.md | 32 +- dixie.js | 7930 ----------------- example/assets/css/style.css | 72 + example/assets/js/example.js | 28 + example/assets/js/jquery-1.9.1.min.js | 5 + .../assets/videos/video.webm | Bin example/index.html | 58 + js/ajax.js | 87 - js/script.js | 84 - vpxdec.html | 110 - webm.js | 7788 ++++++++++++++++ webm/sync_def_PF-0_AF-33-BG_FF-33.webm | Bin 2001417 -> 0 bytes 15 files changed, 8004 insertions(+), 8214 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE-MIT delete mode 100644 README delete mode 100644 dixie.js create mode 100755 example/assets/css/style.css create mode 100644 example/assets/js/example.js create mode 100755 example/assets/js/jquery-1.9.1.min.js rename webm/The_Google_Story.webm => example/assets/videos/video.webm (100%) create mode 100644 example/index.html delete mode 100644 js/ajax.js delete mode 100644 js/script.js delete mode 100644 vpxdec.html create mode 100755 webm.js delete mode 100644 webm/sync_def_PF-0_AF-33-BG_FF-33.webm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..58b805f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +node_modules/ \ No newline at end of file diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..c92846b --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,22 @@ +Copyright (c) 2013 darcyclarke + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 1eef5cc..54e5f70 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,33 @@ -VP8---WebM-JavaScript-Decoder +VP8 WebM JavaScript Decoder ============================= -Source code in dixie.js +A JavaScript WEBM Decoder. +# Example + +An example of implementing the decoder can be found in `example/`. The example requires you run on a server. To do this locally, you can spin up a simple Python server with by navigating to the root directory and running the following code: + +```` +$ python -m SimpleHTTPServer +```` + +**Example JS** + +```javascript +var canvas = document.getElementBy('canvas'); +var player = new webm(canvas); +player.run(videoData); +```` + +# Options + +Currently, there is only the option to `loop` the video. + +**Example JS** + +```javascript +var canvas = document.getElementBy('canvas'); +var player = new webm(canvas, { loop:true }); +player.run(videoData); +```` -http://webpjs.appspot.com \ No newline at end of file diff --git a/dixie.js b/dixie.js deleted file mode 100644 index d7860d2..0000000 --- a/dixie.js +++ /dev/null @@ -1,7930 +0,0 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ -// ----------------------------------------------------------------------------- -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// ----------------------------------------------------------------------------- -// -// Author: John Koleszar (jkoleszar@google.com) -// Dominik Homberger (dominik.homberger@gmail.com) - -"use strict"; - - - -/* Definition of the argument values for the exit() function stdlib.h*/ - -//int strcmp ( const char * str1, const char * str2 ); -function strcmp (str1, str2 ) { - return ((str1 == str2) ? 0 : ((str1 > str2) ? 1 : -1)); -} - -var ptr = 0; - -//stdio.h -/* Seek method constants */ - -var EXIT_SUCCESS = 0; -var EXIT_FAILURE = 1; - -var SEEK_CUR = 1; -var SEEK_END = 2; -var SEEK_SET = 0; - -var buffer8k=function() {return Arr(8800,0)}; -//fread -//size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); -function fread ( ptr, size, count, stream ) { - ptr.val=new buffer8k();//new Array(); - //todo: size include - - if(stream.data.length= 0; --a) - val = newObjectIt(Arr(AOfLen[a],val)); - return val; -} - -/////////////////////////////// -//if(!Object.keys) Object.keys = function(o){ -//// if (o !== Object(o)) -//// throw new TypeError('Object.keys called on non-object'); -// var ret=[],p; -// for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p); -// return ret; -//} -// -function create_obj_vals_from_arrayChilds(Obj,Arr) { - var i; - for(i=0;ilibnestegg C API. */ - -var NESTEGG_TRACK_VIDEO = 0; /**< Track is of type video. */ -var NESTEGG_TRACK_AUDIO = 1; /**< Track is of type audio. */ - -var NESTEGG_CODEC_VP8 = 0; /**< Track uses Google On2 VP8 codec. */ -var NESTEGG_CODEC_VORBIS = 1; /**< Track uses Xiph Vorbis codec. */ - -//71 -var NESTEGG_SEEK_SET = 0; /**< Seek offset relative to beginning of stream. */ -var NESTEGG_SEEK_CUR = 1; /**< Seek offset relative to current position in stream. */ -var NESTEGG_SEEK_END = 2; /**< Seek offset relative to end of stream. */ - -//76 -var NESTEGG_LOG_DEBUG = 1; /**< Debug level log message. */ -var NESTEGG_LOG_INFO = 10; /**< Informational level log message. */ -var NESTEGG_LOG_WARNING = 100; /**< Warning level log message. */ -var NESTEGG_LOG_ERROR = 1000; /**< Error level log message. */ -var NESTEGG_LOG_CRITICAL = 10000; /**< Critical level log message. */ - -/** User supplied IO context. 84 */ -var nestegg_io = function(){ - /** User supplied read callback. - @param buffer Buffer to read data into. - @param length Length of supplied buffer in bytes. - @param userdata The #userdata supplied by the user. - @retval 1 Read succeeded. - @retval 0 End of stream. - @retval -1 Error. */ - //int (* read)(void * buffer, size_t length, void * userdata); - this.read=int_, - - /** User supplied seek callback. - @param offset Offset within the stream to seek to. - @param whence Seek direction. One of #NESTEGG_SEEK_SET, - #NESTEGG_SEEK_CUR, or #NESTEGG_SEEK_END. - @param userdata The #userdata supplied by the user. - @retval 0 Seek succeeded. - @retval -1 Error. */ - //int (* seek)(int64_t offset, int whence, void * userdata); - this.seek=int_, - - /** User supplied tell callback. - @param userdata The #userdata supplied by the user. - @returns Current position within the stream. - @retval -1 Error. */ - //int64_t (* tell)(void * userdata); - this.tell=int64_t, - - /** User supplied pointer to be passed to the IO callbacks. */ - //void * userdata; - - - this.userdata=void_ //* -} ; - -/** Parameters specific to a video track. */ -var nestegg_video_params = function(){ - this.width=int_, /**< Width of the video frame in pixels. */ - this.height=int_, /**< Height of the video frame in pixels. */ - this.display_width=int_, /**< Display width of the video frame in pixels. */ - this.display_height=int_, /**< Display height of the video frame in pixels. */ - this.crop_bottom=int_, /**< Pixels to crop from the bottom of the frame. */ - this.crop_top=int_, /**< Pixels to crop from the top of the frame. */ - this.crop_left=int_, /**< Pixels to crop from the left of the frame. */ - this.crop_right=int_ /**< Pixels to crop from the right of the frame. */ -} ; - - - - -/* EBML Elements 14 */ -var ID_EBML = 0x1a45dfa3; -var ID_EBML_VERSION = 0x4286; -var ID_EBML_READ_VERSION = 0x42f7; -var ID_EBML_MAX_ID_LENGTH = 0x42f2; -var ID_EBML_MAX_SIZE_LENGTH = 0x42f3; -var ID_DOCTYPE = 0x4282; -var ID_DOCTYPE_VERSION = 0x4287; -var ID_DOCTYPE_READ_VERSION = 0x4285; - -/* Global Elements */ -var ID_VOID = 0xec; -var ID_CRC32 = 0xbf; - -/* WebMedia Elements */ -var ID_SEGMENT = 0x18538067; - -/* Seek Head Elements */ -var ID_SEEK_HEAD = 0x114d9b74; -var ID_SEEK = 0x4dbb; -var ID_SEEK_ID = 0x53ab; -var ID_SEEK_POSITION = 0x53ac; - -/* Info Elements */ -var ID_INFO = 0x1549a966; -var ID_TIMECODE_SCALE = 0x2ad7b1; -var ID_DURATION = 0x4489; - -/* Cluster Elements */ -var ID_CLUSTER = 0x1f43b675; -var ID_TIMECODE = 0xe7; -var ID_BLOCK_GROUP = 0xa0; -var ID_SIMPLE_BLOCK = 0xa3; - -/* BlockGroup Elements */ -var ID_BLOCK = 0xa1; -var ID_BLOCK_DURATION = 0x9b; -var ID_REFERENCE_BLOCK = 0xfb; - -/* Tracks Elements */ -var ID_TRACKS = 0x1654ae6b; -var ID_TRACK_ENTRY = 0xae; -var ID_TRACK_NUMBER = 0xd7; -var ID_TRACK_UID = 0x73c5; -var ID_TRACK_TYPE = 0x83; -var ID_FLAG_ENABLED = 0xb9; -var ID_FLAG_DEFAULT = 0x88; -var ID_FLAG_LACING = 0x9c; -var ID_TRACK_TIMECODE_SCALE=0x23314f; -var ID_LANGUAGE = 0x22b59c; -var ID_CODEC_ID = 0x86; -var ID_CODEC_PRIVATE = 0x63a2; - -/* Video Elements */ -var ID_VIDEO = 0xe0; -var ID_PIXEL_WIDTH = 0xb0; -var ID_PIXEL_HEIGHT = 0xba; -var ID_PIXEL_CROP_BOTTOM = 0x54aa; -var ID_PIXEL_CROP_TOP = 0x54bb; -var ID_PIXEL_CROP_LEFT = 0x54cc; -var ID_PIXEL_CROP_RIGHT = 0x54dd; -var ID_DISPLAY_WIDTH = 0x54b0; -var ID_DISPLAY_HEIGHT = 0x54ba; - -/* Audio Elements */ -var ID_AUDIO = 0xe1; -var ID_SAMPLING_FREQUENCY = 0xb5; -var ID_CHANNELS = 0x9f; -var ID_BIT_DEPTH = 0x6264; - -/* Cues Elements */ -var ID_CUES = 0x1c53bb6b; -var ID_CUE_POINT = 0xbb; -var ID_CUE_TIME = 0xb3; -var ID_CUE_TRACK_POSITIONS= 0xb7; -var ID_CUE_TRACK = 0xf7; -var ID_CUE_CLUSTER_POSITION=0xf1; -var ID_CUE_BLOCK_NUMBER = 0x5378; - -/* EBML Types 93 */ -var //ebml_type_enum = { - TYPE_UNKNOWN=0, - TYPE_MASTER=1, - TYPE_UINT=2, - TYPE_FLOAT=3, - TYPE_INT=4, - TYPE_STRING=5, - TYPE_BINARY=6 -//} -; - -var LIMIT_STRING = (1 << 20); -var LIMIT_BINARY = (1 << 24); -var LIMIT_BLOCK = (1 << 30); -var LIMIT_FRAME = (1 << 28); - -/* Field Flags 109 */ -var DESC_FLAG_NONE = 0; -var DESC_FLAG_MULTI = (1 << 0); -var DESC_FLAG_SUSPEND = (1 << 1); -var DESC_FLAG_OFFSET = (1 << 2); - -/* Block Header Flags */ -var BLOCK_FLAGS_LACING = 6; - -/* Lacing Constants */ -var LACING_NONE = 0; -var LACING_XIPH = 1; -var LACING_FIXED = 2; -var LACING_EBML = 3; - -/* Track Types */ -var TRACK_TYPE_VIDEO = 1; -var TRACK_TYPE_AUDIO = 2; - -/* Track IDs */ -var TRACK_ID_VP8 = "V_VP8"; -var TRACK_ID_VORBIS = "A_VORBIS"; - -var// vint_mask { - MASK_NONE=0, - MASK_FIRST_BIT=1 -//} -; - -//137 -var ebml_binary = function(){ - this.data=char_,//* - this.length=size_t -}; - -var ebml_list_node = function(){ - this.next=null,//'ebml_list_node',//* - this.id=uint64_t, - this.data=void_//* -}; - -var ebml_list = function(){ - this.head=null,//'newObjectI(ebml_list_node)',//* - this.tail=null//'newObjectI(ebml_list_node)'//* -}; - -var ebml_type = function(){ - this.v=new Object({//union ebml_value - u:uint64_t, - f:double_, - i:int64_t, - s:char_,//* - b:new ebml_binary() - }), - this.type=0, //enum'ebml_type_enum' - this.read=int_ -}; - -/* EBML Definitions 165 */ -var ebml = window["ebml"] = function(){ - this.ebml_version=this["ebml_version"]=new ebml_type(), - this.ebml_read_version=this["ebml_read_version"]=new ebml_type(), - this.ebml_max_id_length=this["ebml_max_id_length"]=new ebml_type(), - this.ebml_max_size_length=this["ebml_max_size_length"]=new ebml_type(), - this.doctype=this["doctype"]=new ebml_type(), - this.doctype_version=this["doctype_version"]=new ebml_type(), - this.doctype_read_version=this["doctype_read_version"]=new ebml_type() -}; - -/* Matroksa Definitions */ -var seek = window["seek"] = function(){ - this.id=this["id"]=new ebml_type(), - this.position=this["position"]=new ebml_type() -}; - -var seek_head = window["seek_head"] = function(){ - this.seek=this["seek"]=new ebml_list() -}; - -var info = window["info"] = function(){ - this.timecode_scale=this["timecode_scale"]=new ebml_type(), - this.duration=this["duration"]=new ebml_type() -}; - -var block_group = window["block_group"] = function(){ - this.duration=this["duration"]=new ebml_type(), - this.reference_block=this["reference_block"]=new ebml_type() -}; - -var cluster = window["cluster"] = function(){ - this.timecode=this["timecode"]=new ebml_type(), - this.block_group=this["block_group"]=new ebml_list() -}; - -var video = window["video"] = function(){ - this.pixel_width=this["pixel_width"]=new ebml_type(), - this.pixel_height=this["pixel_height"]=new ebml_type(), - this.pixel_crop_bottom=this["pixel_crop_bottom"]=new ebml_type(), - this.pixel_crop_top=this["pixel_crop_top"]=new ebml_type(), - this.pixel_crop_left=this["pixel_crop_left"]=new ebml_type(), - this.pixel_crop_right=this["pixel_crop_right"]=new ebml_type(), - this.display_width=this["display_width"]=new ebml_type(), - this.display_height=this["display_height"]=new ebml_type() -}; - -var audio = window["audio"] = function(){ - this.sampling_frequency=this["sampling_frequency"]=new ebml_type(), - this.channels=this["channels"]=new ebml_type(), - this.bit_depth=this["bit_depth"]=new ebml_type() -}; - -var track_entry = window["track_entry"] = function(){ - this.number=this["number"]=new ebml_type(), - this.uid=this["uid"]=new ebml_type(), - this.type=this["type"]=new ebml_type(), - this.flag_enabled=this["flag_enabled"]=new ebml_type(), - this.flag_default=this["flag_default"]=new ebml_type(), - this.flag_lacing=this["flag_lacing"]=new ebml_type(), - this.track_timecode_scale=this["track_timecode_scale"]=new ebml_type(), - this.language=this["language"]=new ebml_type(), - this.codec_id=this["codec_id"]=new ebml_type(), - this.codec_private=this["codec_private"]=new ebml_type(), - this.video=this["video"]=new video(), - this.audio=this["audio"]=new audio() -}; - -var tracks = window["tracks"] = function(){ - this.track_entry=this["track_entry"]=new ebml_list() -}; - -var cue_track_positions = window["cue_track_positions"] = function(){ - this.track=this["track"]=new ebml_type(), - this.cluster_position=this["cluster_position"]=new ebml_type(), - this.block_number=this["block_number"]=new ebml_type() -}; - -var cue_point = window["cue_point"] = function(){ - this.time=this["time"]=new ebml_type(), - this.cue_track_positions=this["cue_track_positions"]=new ebml_list() -}; - -var cues = window["cues"] = function(){ - this.cue_point=this["cue_point"]=new ebml_list() -}; - -var segment = window["segment"] = function(){ - this.seek_head=this["seek_head"]=new ebml_list(), - this.info=this["info"]=new info(), - this.cluster=this["cluster"]=new ebml_list(), - this.tracks=this["tracks"]=new tracks(), - this.cues=this["cues"]=new cues() -}; - -/* Misc. 260 */ -var pool_ctx = function(){ - this.dummy=char_ -}; - -var list_node = function(){ - this.previous=0, //todo: endlosschleife verhindern //*'list_node' - this.node=new ebml_element_desc(),//* - this.data=char_ //* -}; - -var frame = function() { - this.data=char_, - this.length=size_t, - this.next=null//'frame' -}; - -/* Public (opaque) Structures 284 */ -var nestegg = function(){ - this.io=new nestegg_io(), //* - this.log_=0,//'nestegg_log' todo: - this.alloc_pool=new pool_ctx(), //* - this.last_id=uint64_t, - this.last_size=uint64_t, - this.ancestor=null,//'newObjectI(list_node)',//* - this.ebml=this["ebml"]=new ebml(), - this.segment=this["segment"]=new segment(), - this.segment_offset=int64_t, - this.track_count=int_ -}; - -var nestegg_packet = function() { - this.track=uint64_t, - this.timecode=uint64_t, - this.frame=new frame()//* -}; - -/* Element Descriptor 304 */ -var ebml_element_desc = function(){ - this.name=char_,//const * - this.id=uint64_t, - this.type=0, //enum'ebml_type_enum' - this.offset=size_t, - this.flags=int_, - this.children=null,//wiederholungsschleife //*'ebml_element_desc' - this.size=size_t, - this.data_offset=size_t -}; - -function E_FIELD(ID, _ID, TYPE, STRUCT, FIELD) { - return new Array( ID, _ID, TYPE, FIELD/*offsetof(STRUCT, FIELD)*/, DESC_FLAG_NONE, null, 0, 0 ) } -function E_MASTER(ID, _ID, TYPE, STRUCT, FIELD, NE_FIELD_ELEMENTS) { - return new Array( ID, _ID, TYPE, FIELD/*offsetof(STRUCT, FIELD)*/, DESC_FLAG_MULTI, NE_FIELD_ELEMENTS, - 1/*sizeof(FIELD)*/, 0 ) } -function E_SINGLE_MASTER_O(ID, _ID, TYPE, STRUCT, FIELD, NE_FIELD_ELEMENTS) { - return new Array( ID, _ID, TYPE, FIELD/*offsetof(STRUCT, FIELD)*/, DESC_FLAG_OFFSET, NE_FIELD_ELEMENTS, 0, - FIELD+'_offset'/*offsetof(STRUCT, FIELD+'_offset')*/ ) } -function E_SINGLE_MASTER(ID, _ID, TYPE, STRUCT, FIELD, NE_FIELD_ELEMENTS) { - return new Array( ID, _ID, TYPE, FIELD/*offsetof(STRUCT, FIELD)*/, DESC_FLAG_NONE, NE_FIELD_ELEMENTS, 0, 0 ) } -function E_SUSPEND(ID, _ID, TYPE) { - return new Array( ID, _ID, TYPE, 0, DESC_FLAG_SUSPEND, null, 0, 0 ) } -var E_LAST = - new Array( null, 0, 0, 0, DESC_FLAG_NONE, null, 0, 0 ); - -/* EBML Element Lists */ -var ne_ebml_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_EBML_VERSION', ID_EBML_VERSION, TYPE_UINT, 'ebml', 'ebml_version'), - E_FIELD('ID_EBML_READ_VERSION', ID_EBML_READ_VERSION, TYPE_UINT, 'ebml', 'ebml_read_version'), - E_FIELD('ID_EBML_MAX_ID_LENGTH', ID_EBML_MAX_ID_LENGTH, TYPE_UINT, 'ebml', 'ebml_max_id_length'), - E_FIELD('ID_EBML_MAX_SIZE_LENGTH', ID_EBML_MAX_SIZE_LENGTH, TYPE_UINT, 'ebml', 'ebml_max_size_length'), - E_FIELD('ID_DOCTYPE', ID_DOCTYPE, TYPE_STRING, 'ebml', 'doctype'), - E_FIELD('ID_DOCTYPE_VERSION', ID_DOCTYPE_VERSION, TYPE_UINT, 'ebml', 'doctype_version'), - E_FIELD('ID_DOCTYPE_READ_VERSION', ID_DOCTYPE_READ_VERSION, TYPE_UINT, 'ebml', 'doctype_read_version'), - E_LAST -)); - -/* WebMedia Element Lists */ -var ne_seek_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_SEEK_ID', ID_SEEK_ID, TYPE_BINARY, 'seek', 'id'), - E_FIELD('ID_SEEK_POSITION', ID_SEEK_POSITION, TYPE_UINT, 'seek', 'position'), - E_LAST -)); - -var ne_seek_head_elements = create_ebml_element_desc(new Array( - E_MASTER('ID_SEEK', ID_SEEK, TYPE_MASTER, 'seek_head', 'seek', ne_seek_elements), - E_LAST -)); - -var ne_info_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_TIMECODE_SCALE', ID_TIMECODE_SCALE, TYPE_UINT, 'info', 'timecode_scale'), - E_FIELD('ID_DURATION', ID_DURATION, TYPE_FLOAT, 'info', 'duration'), - E_LAST -)); - -var ne_block_group_elements = create_ebml_element_desc(new Array( - E_SUSPEND('ID_BLOCK', ID_BLOCK, TYPE_BINARY), - E_FIELD('ID_BLOCK_DURATION', ID_BLOCK_DURATION, TYPE_UINT, 'block_group', 'duration'), - E_FIELD('ID_REFERENCE_BLOCK', ID_REFERENCE_BLOCK, TYPE_INT, 'block_group', 'reference_block'), - E_LAST -)); - -var ne_cluster_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_TIMECODE', ID_TIMECODE, TYPE_UINT, 'cluster', 'timecode'), - E_MASTER('ID_BLOCK_GROUP', ID_BLOCK_GROUP, TYPE_MASTER, 'cluster', 'block_group', ne_block_group_elements), - E_SUSPEND('ID_SIMPLE_BLOCK', ID_SIMPLE_BLOCK, TYPE_BINARY), - E_LAST -)); - -var ne_video_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_PIXEL_WIDTH', ID_PIXEL_WIDTH, TYPE_UINT, 'video', 'pixel_width'), - E_FIELD('ID_PIXEL_HEIGHT', ID_PIXEL_HEIGHT, TYPE_UINT, 'video', 'pixel_height'), - E_FIELD('ID_PIXEL_CROP_BOTTOM', ID_PIXEL_CROP_BOTTOM, TYPE_UINT, 'video', 'pixel_crop_bottom'), - E_FIELD('ID_PIXEL_CROP_TOP', ID_PIXEL_CROP_TOP, TYPE_UINT, 'video', 'pixel_crop_top'), - E_FIELD('ID_PIXEL_CROP_LEFT', ID_PIXEL_CROP_LEFT, TYPE_UINT, 'video', 'pixel_crop_left'), - E_FIELD('ID_PIXEL_CROP_RIGHT', ID_PIXEL_CROP_RIGHT, TYPE_UINT, 'video', 'pixel_crop_right'), - E_FIELD('ID_DISPLAY_WIDTH', ID_DISPLAY_WIDTH, TYPE_UINT, 'video', 'display_width'), - E_FIELD('ID_DISPLAY_HEIGHT', ID_DISPLAY_HEIGHT, TYPE_UINT, 'video', 'display_height'), - E_LAST -)); - -var ne_audio_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_SAMPLING_FREQUENCY', ID_SAMPLING_FREQUENCY, TYPE_FLOAT, 'audio', 'sampling_frequency'), - E_FIELD('ID_CHANNELS', ID_CHANNELS, TYPE_UINT, 'audio', 'channels'), - E_FIELD('ID_BIT_DEPTH', ID_BIT_DEPTH, TYPE_UINT, 'audio', 'bit_depth'), - E_LAST -)); - -var ne_track_entry_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_TRACK_NUMBER', ID_TRACK_NUMBER, TYPE_UINT, 'track_entry', 'number'), - E_FIELD('ID_TRACK_UID', ID_TRACK_UID, TYPE_UINT, 'track_entry', 'uid'), - E_FIELD('ID_TRACK_TYPE', ID_TRACK_TYPE, TYPE_UINT, 'track_entry', 'type'), - E_FIELD('ID_FLAG_ENABLED', ID_FLAG_ENABLED, TYPE_UINT, 'track_entry', 'flag_enabled'), - E_FIELD('ID_FLAG_DEFAULT', ID_FLAG_DEFAULT, TYPE_UINT, 'track_entry', 'flag_default'), - E_FIELD('ID_FLAG_LACING', ID_FLAG_LACING, TYPE_UINT, 'track_entry', 'flag_lacing'), - E_FIELD('ID_TRACK_TIMECODE_SCALE', ID_TRACK_TIMECODE_SCALE, TYPE_FLOAT, 'track_entry', 'track_timecode_scale'), - E_FIELD('ID_LANGUAGE', ID_LANGUAGE, TYPE_STRING, 'track_entry', 'language'), - E_FIELD('ID_CODEC_ID', ID_CODEC_ID, TYPE_STRING, 'track_entry', 'codec_id'), - E_FIELD('ID_CODEC_PRIVATE', ID_CODEC_PRIVATE, TYPE_BINARY, 'track_entry', 'codec_private'), - E_SINGLE_MASTER('ID_VIDEO', ID_VIDEO, TYPE_MASTER, 'track_entry', 'video', ne_video_elements), - E_SINGLE_MASTER('ID_AUDIO', ID_AUDIO, TYPE_MASTER, 'track_entry', 'audio', ne_audio_elements), - E_LAST -)); - -var ne_tracks_elements = create_ebml_element_desc(new Array( - E_MASTER('ID_TRACK_ENTRY', ID_TRACK_ENTRY, TYPE_MASTER, 'tracks', 'track_entry', ne_track_entry_elements), - E_LAST -)); - -var ne_cue_track_positions_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_CUE_TRACK', ID_CUE_TRACK, TYPE_UINT, 'cue_track_positions', 'track'), - E_FIELD('ID_CUE_CLUSTER_POSITION', ID_CUE_CLUSTER_POSITION, TYPE_UINT, 'cue_track_positions', 'cluster_position'), - E_FIELD('ID_CUE_BLOCK_NUMBER', ID_CUE_BLOCK_NUMBER, TYPE_UINT, 'cue_track_positions', 'block_number'), - E_LAST -)) - -var ne_cue_point_elements = create_ebml_element_desc(new Array( - E_FIELD('ID_CUE_TIME', ID_CUE_TIME, TYPE_UINT, 'cue_point', 'time'), - E_MASTER('ID_CUE_TRACK_POSITIONS', ID_CUE_TRACK_POSITIONS, TYPE_MASTER, 'cue_point', 'cue_track_positions', ne_cue_track_positions_elements), - E_LAST -)); - -var ne_cues_elements = create_ebml_element_desc(new Array( - E_MASTER('ID_CUE_POINT', ID_CUE_POINT, TYPE_MASTER, 'cues', 'cue_point', ne_cue_point_elements), - E_LAST -)); - -var ne_segment_elements = create_ebml_element_desc(new Array( - E_MASTER('ID_SEEK_HEAD', ID_SEEK_HEAD, TYPE_MASTER, 'segment', 'seek_head', ne_seek_head_elements), - E_SINGLE_MASTER('ID_INFO', ID_INFO, TYPE_MASTER, 'segment', 'info', ne_info_elements), - E_MASTER('ID_CLUSTER', ID_CLUSTER, TYPE_MASTER, 'segment', 'cluster', ne_cluster_elements), - E_SINGLE_MASTER('ID_TRACKS', ID_TRACKS, TYPE_MASTER, 'segment', 'tracks', ne_tracks_elements), - E_SINGLE_MASTER('ID_CUES', ID_CUES, TYPE_MASTER, 'segment', 'cues', ne_cues_elements), - E_LAST -)); - -//442 -var ne_top_level_elements = create_ebml_element_desc(new Array( - E_SINGLE_MASTER('ID_EBML', ID_EBML, TYPE_MASTER, 'nestegg', 'ebml', ne_ebml_elements), - E_SINGLE_MASTER_O('ID_SEGMENT', ID_SEGMENT, TYPE_MASTER, 'nestegg', 'segment', ne_segment_elements), - E_LAST -)); - -function create_ebml_element_desc(Arr) { - var newArr=new Array(); - for(var i=0;i 0) { - get_ = length < /*sizeof(buf)**/buf.val.length ? length : /*sizeof(buf)**/buf.val.length; - r = ne_io_read(io, buf, get_); - if (r != 1) - break; - length -= get_; - } - - return r; -} - -function //526 -ne_io_tell(io) -{ - return io.tell(io.userdata); -} - -function -ne_bare_read_vint(io, value, length, maskflag) -{ - var r=int_; - var b={val:char_}; - var maxlen = 8; - var count = 1, mask = 1 << 7; - - r = ne_io_read(io, b, 1);//&b - if (r != 1) - return r; - - while (count < maxlen) { - if ((b.val[0] & mask) != 0) - break; - mask >>= 1; - count += 1; - } - - if (length) - length.val = count; - value.val = b.val[0]; - - if (maskflag == MASK_FIRST_BIT) - value.val = b.val[0] & ~mask; - - while (--count) { - r = ne_io_read(io, b, 1);//&b - if (r != 1) - return r; - value.val <<= 8; - value.val |= b.val[0]; - } - - return 1; -} - -function -ne_io_read(io, buffer, length) -{ - //io.userdata={val:io.userdata}; - var r = io.read(buffer, length, io.userdata); - //io.userdata=io.userdata.val; - return r; -} - -function //569 -ne_read_id(io, value, length) -{ - return ne_bare_read_vint(io, value, length, MASK_NONE); -} - -function -ne_read_vint(io, value, length) -{ - return ne_bare_read_vint(io, value, length, MASK_FIRST_BIT); -} - -function //581 -ne_read_svint(io, value, length) -{ - var r=int_; - var uvalue=[uint64_t]; - var ulength=[uint64_t]; - var svint_subtr = new Array( - 0x3f, 0x1fff, - 0xfffff, 0x7ffffff, - 0x3ffffffff, 0x1ffffffffff, - 0xffffffffffff, 0x7fffffffffffff - ); - - var r = ne_bare_read_vint(io, uvalue, ulength, MASK_FIRST_BIT); - if (r != 1) - return r; - value[0] = uvalue - svint_subtr[ulength - 1]; - if (length) - length[0] = ulength; - return r; -} - -function //603 -ne_read_uint(io, val, length) -{ - var b={val:char_}; - var r=int_; - - if (length == 0 || length > 8) - return -1; - r = ne_io_read(io, b, 1); - if (r != 1) - return r; - val[0] = b.val[0];//result - while (--length) { - r = ne_io_read(io, b, 1); - if (r != 1) - return r; - val[0] <<= 8;//result - val[0] |= b.val[0];//result - } - return 1; -} - -function //625 -ne_read_int(io, val, length) -{ - var r=int_; - var uval=[uint64_t], base=uint64_t; - - r = ne_read_uint(io, uval, length); - if (r != 1) - return r; - - if (length < /*sizeof(int64_t)**/8) { - base = 1; - base <<= length * 8 - 1; - if (uval >= base) { - base = 1; - base <<= length * 8; - } else { - base = 0; - } - val[0] = uval - base; - } else { - val[0] = uval;//(int64_t) - } - - return 1; -} - -function //652 -ne_read_float(io, val, length) -{ - var value = {//union - u:[uint64_t], - f:[float_], - d:[double_] - } ; - var r=int_; - - /* length == 10 not implemented */ - if (length != 4 && length != 8) - return -1; - r = ne_read_uint(io, value.u, length); - if (r != 1) - return r; - if (length == 4) - val[0] = value.f = value.u;//'u'+ - else - val[0] = value.d = value.u;//'u'+ - return 1; -} - -function //675 -ne_read_string(ctx, val, length) -{ - var str={val:char_};//* - var r=int_; - - if (length == 0 || length > LIMIT_STRING) - return -1; - //str = ne_pool_alloc(length + 1, ctx->alloc_pool); - r = ne_io_read(ctx.io, str, length); - if (r != 1) - return r; - var str2='';for(var i=0;i LIMIT_BINARY) - return -1; - val.data = {val:0};//'ne_pool_alloc(length, ctx->alloc_pool)' - val.length = length; - return ne_io_read(ctx.io, val.data, length); -} - -function //702 -ne_get_uint(type, value) -{ - if (!type.read) - return -1; - - assert(type.type == TYPE_UINT); - - value[0] = type.v.u; - - return 0; -} - -function //728 -ne_get_string(type, value) -{ - if (!type.read) - return -1; - - assert(type.type == TYPE_STRING); - - value[0] = type.v.s; - - return 0; -} - -function //754 -ne_is_ancestor_element(id, ancestor) -{ - //var element;//=new ebml_element_desc();//* - - for (; ancestor; ancestor = ancestor.previous) - for (var element = ancestor.node,element_pos = 0; element[element_pos].id; ++element_pos) - //for (element = ancestor->node; element->id; ++element) - if (element[element_pos].id == id) - return 1; - - return 0; -} - -function //767 -ne_find_element(id, elements) -{ - //todo: why is this set? -> var element=newObjectI(ebml_element_desc); - //for (element = elements; element.id; ++element) - for (var element = elements,element_pos = 0; element[element_pos].id; ++element_pos) - if (element[element_pos].id == id) - return element[element_pos]; - - return null; -} - -function //779 -ne_ctx_push(ctx, ancestor, data) -{ - var item_=new list_node();//* - - //todo: item_ = ne_alloc(sizeof(item_)); - item_.previous = ctx.ancestor; - item_.node = ancestor; - item_.data = data; - ctx.ancestor = item_; -} - -function //791 -ne_ctx_pop(ctx) -{ - var item_;//=new list_node();//* - - item_ = ctx.ancestor; - ctx.ancestor = item_.previous; - //free(item_); - item_=''; -} - -//827 -function -ne_peek_element(ctx, id, size) -{ - var r=int_; - - if (ctx.last_id && ctx.last_size) { - if (id) - id[0] = ctx.last_id; - if (size) - size[0] = ctx.last_size; - return 1; - } - ctx.last_id = {val:ctx.last_id}; - r = ne_read_id(ctx.io, ctx.last_id, null);//&ctx.last_id - ctx.last_id = ctx.last_id.val; - if (r != 1) - return r; - - ctx.last_size = {val:ctx.last_size}; - r = ne_read_vint(ctx.io, ctx.last_size, null); - ctx.last_size = ctx.last_size.val; - if (r != 1) - return r; - - if (id) - id[0] = ctx.last_id; - if (size) - size[0] = ctx.last_size; - - return 1; -} - -function //856 -ne_read_element(ctx, id, size) -{ - var r=int_; - - r = ne_peek_element(ctx, id, size); - if (r != 1) - return r; - - ctx.last_id = 0; - ctx.last_size = 0; - - return 1; -} - -function //871 -ne_read_master(ctx, desc) -{ - var list; //todo must it set? //*=new ebml_list() - var node=new ebml_list_node(), oldtail;//*=new ebml_list_node() - - assert(desc.type == TYPE_MASTER && desc.flags & DESC_FLAG_MULTI); - -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "multi master element %llx (%s)", -// desc.id, desc.name); -if (!!ctx.ancestor.data[desc.offset]) - list = (ctx.ancestor.data[desc.offset]);// (struct ebml_list *) - - //node = ne_pool_alloc(sizeof(*node), ctx->alloc_pool); - node.id = desc.id; - node.data = new window[desc.offset]();//newObjectI(ebml_list);//'ne_pool_alloc(desc.size, ctx.alloc_pool)'; - - oldtail = list.tail; - if (oldtail) - oldtail.next = node; - list.tail = node; - if (!list.head) - list.head = node; - -// ctx.log(ctx, NESTEGG_LOG_DEBUG, " -> using data %p", node.data); - - ne_ctx_push(ctx, desc.children, node.data); -} - - -function //900 -ne_read_single_master(ctx, desc) -{ - assert(desc.type == TYPE_MASTER && !(desc.flags & DESC_FLAG_MULTI)); - -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "single master element %llx (%s)", -// desc.id, desc.name); -// ctx.log(ctx, NESTEGG_LOG_DEBUG, " -> using data %p (%u)", -// ctx.ancestor.data + desc.offset, desc.offset); - - ne_ctx_push(ctx, desc.children, ctx.ancestor.data[desc.offset]); -} - -function //913 -ne_read_simple(ctx, desc, length) -{ - var storage; //*=new ebml_type() - var r=int_; -if (!!ctx.ancestor.data[desc.offset]) - storage = (ctx.ancestor.data[desc.offset]);//todo: (struct ebml_type *) - - if (storage.read) { -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "element %llx (%s) already read, skipping", -// desc.id, desc.name); - return 0; - } - - storage.type = desc.type; - -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "element %llx (%s) -> %p (%u)", -// desc.id, desc.name, storage, desc.offset); - - r = -1; - - switch (desc.type) {//second value with "&" return value - case TYPE_UINT: - storage.v.u=[storage.v.u]; - r = ne_read_uint(ctx.io, storage.v.u, length); - storage.v.u=storage.v.u[0]; - break; - case TYPE_FLOAT: - storage.v.f=[storage.v.f]; - r = ne_read_float(ctx.io, storage.v.f, length); - storage.v.f=storage.v.f[0]; - break; - case TYPE_INT: - storage.v.i=[storage.v.i]; - r = ne_read_int(ctx.io, storage.v.i, length); - storage.v.i=storage.v.i[0]; - break; - case TYPE_STRING: - storage.v.s=[storage.v.s]; - r = ne_read_string(ctx, storage.v.s, length); - storage.v.s=storage.v.s[0]; - break; - case TYPE_BINARY: - //storage.v.b=[storage.v.b]; - r = ne_read_binary(ctx, storage.v.b, length); - break; - case TYPE_MASTER: - case TYPE_UNKNOWN: - assert(0); - break; - } - - if (r == 1) - storage.read = 1; - - return r; -} - -function //962 -ne_parse(ctx, top_level) -{ - var r=int_; - var data_offset=int64_t;//* - var id=[uint64_t], size=[uint64_t]; - var element;//=new ebml_element_desc();//* - - /* loop until we need to return: - - hit suspend point - - parse complete - - error occurred */ - - /* loop over elements at current level reading them if sublevel found, - push ctx onto stack and continue if sublevel ended, pop ctx off stack - and continue */ - - if (!ctx.ancestor) - return -1; -//var aa=0; - while(1) {//for (;;) {//aa++; - r = ne_peek_element(ctx, id, size); - if (r != 1) - break; - - element = ne_find_element(id[0], ctx.ancestor.node); - if (element) { - if (element.flags & DESC_FLAG_SUSPEND) { - assert(element.type == TYPE_BINARY); -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "suspend parse at %llx", id[0]); - r = 1; - break; - } - - r = ne_read_element(ctx, id, size); - if (r != 1) - break; - - if (element.flags & DESC_FLAG_OFFSET) { - data_offset = (ctx.ancestor.data[element.data_offset])={v:null};//(int64_t *) - data_offset.v = ne_io_tell(ctx.io);//* - if (data_offset < 0) { - r = -1; - break; - } - } - - if (element.type == TYPE_MASTER) { - if (element.flags & DESC_FLAG_MULTI) - ne_read_master(ctx, element); - else - ne_read_single_master(ctx, element); - continue; - } else { - r = ne_read_simple(ctx, element, size[0]); - if (r < 0) - break; - } - } else if (ne_is_ancestor_element(id, ctx.ancestor.previous)) { -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "parent element %llx", id); - if (top_level && ctx.ancestor.node == top_level) { -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "*** parse about to back up past top_level"); - r = 1; - break; - } - ne_ctx_pop(ctx); - } else { - r = ne_read_element(ctx, id, size); - if (r != 1) - break; - -// if (id != ID_VOID && id != ID_CRC32) -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "unknown element %llx", id); - r = ne_io_read_skip(ctx.io, size[0]); - if (r != 1) - break; - } - } - - if (r != 1) - while (ctx.ancestor) - ne_ctx_pop(ctx); - - return r; -} - -function //1067 -ne_read_xiph_lace_value(io, value, value_off, consumed) -{ - var r=int_; - var lace=[uint64_t]; - - r = ne_read_uint(io, lace, 1); - if (r != 1) - return r; - consumed[0] += 1; - - value[value_off+ 0] = lace[0]; - while (lace[0] == 255) { - r = ne_read_uint(io, lace, 1); - if (r != 1) - return r; - consumed[0] += 1; - value[value_off+ 0] += lace[0]; - } - - return 1; -} - -function // 1090 -ne_read_xiph_lacing(io, block, read, n, sizes) -{ - var r=int_; - var i = 0; - var sum = 0; - - while (--n) { - r = ne_read_xiph_lace_value(io, sizes, i, read); - if (r != 1) - return r; - sum += sizes[i]; - i += 1; - } - - if (read[0] + sum > block) - return -1; - - /* last frame is the remainder of the block */ - sizes[i] = block - read[0] - sum; - return 1; -} - -function //1113 -ne_read_ebml_lacing(io, block, read, n, sizes) -{ - var r=int_; - var lace=[uint64_t], sum=uint64_t, length=[uint64_t]; - var slace=[int64_t]; - var i = 0; - - r = ne_read_vint(io, lace, length); - if (r != 1) - return r; - read[0] += length[0]; - - sizes[i] = lace[0]; - sum = sizes[i]; - - i += 1; - n -= 1; - - while (--n) { - r = ne_read_svint(io, slace, length); - if (r != 1) - return r; - read[0] += length[0]; - sizes[i] = sizes[i - 1] + slace[0]; - sum += sizes[i]; - i += 1; - } - - if (read[0] + sum > block) - return -1; - - /* last frame is the remainder of the block */ - sizes[i] = block - read[0] - sum; - return 1; -} - -function //1150 -ne_get_timecode_scale(ctx) -{ - var scale=[uint64_t]; - - if (ne_get_uint(ctx.segment.info.timecode_scale, scale) != 0) - scale[0] = 1000000; - - return scale[0]; -} - -function //1161 -ne_find_track_entry(ctx, track) -{ - //struct ebml_list_node * node; - var tracks = 0; - - var node = ctx.segment.tracks.track_entry.head; - while (node) { - assert(node.id == ID_TRACK_ENTRY); - if (track == tracks) - return node.data; - tracks += 1; - node = node.next; - } - - return null; -} - -var frame_sizes_256=Arr(256,0); -function //1179 -ne_read_block(ctx, block_id, block_size, data)//nestegg_packet ** data -{ - var r=int_; - var timecode=[int64_t], abs_timecode=int64_t; - var pkt;//*=new nestegg_packet() - var cluster;//=new cluster(); - var f, last;//=new frame()=new frame() - var entry;//=new track_entry() - var track_scale=double_; - var track={val:uint64_t}, length={val:uint64_t}, frame_sizes=frame_sizes_256, cluster_tc=[uint64_t], flags=[uint64_t], frames=[uint64_t], tc_scale=uint64_t, total=uint64_t;//,uint64_t - var i=int_, lacing=int_; - var consumed = [0]; - - data[0] = null; - - if (block_size > LIMIT_BLOCK) - return -1; - - r = ne_read_vint(ctx.io, track, length); - if (r != 1) - return r; - - if (track.val == 0 || track.val > ctx.track_count) - return -1; - - consumed[0] += length.val; - - r = ne_read_int(ctx.io, timecode, 2); - if (r != 1) - return r; - - consumed[0] += 2; - - r = ne_read_uint(ctx.io, flags, 1); - if (r != 1) - return r; - - consumed[0] += 1; - - frames[0] = 0; - - /* flags are different between block and simpleblock, but lacing is - encoded the same way */ - lacing = (flags[0] & BLOCK_FLAGS_LACING) >> 1; - - switch (lacing) { - case LACING_NONE: - frames[0] = 1; - break; - case LACING_XIPH: - case LACING_FIXED: - case LACING_EBML: - r = ne_read_uint(ctx.io, frames, 1); - if (r != 1) - return r; - consumed[0] += 1; - frames[0] += 1; - } - - if (frames[0] > 256) - return -1; - - switch (lacing) { - case LACING_NONE: - frame_sizes[0] = block_size - consumed[0]; - break; - case LACING_XIPH: - if (frames == 1) - return -1; - r = ne_read_xiph_lacing(ctx.io, block_size, consumed, frames, frame_sizes); - if (r != 1) - return r; - break; - case LACING_FIXED: - if ((block_size - consumed[0]) % frames[0]) - return -1; - for (i = 0; i < frames[0]; ++i) - frame_sizes[i] = ((block_size - consumed[0]) / frames)>>0;//todo: parseInt add - break; - case LACING_EBML: - if (frames[0] == 1) - return -1; - r = ne_read_ebml_lacing(ctx.io, block_size, consumed, frames, frame_sizes); - if (r != 1) - return r; - break; - } - - /* sanity check unlaced frame sizes against total block size. */ - total = consumed[0]; - for (i = 0; i < frames[0]; ++i) - total += frame_sizes[i]; - if (total > block_size) - return -1; - - entry = ne_find_track_entry(ctx, track.val - 1); - if (!entry) - return -1; - - track_scale = 1.0; - - tc_scale = ne_get_timecode_scale(ctx); - - assert(ctx.segment.cluster.tail.id == ID_CLUSTER); - cluster = ctx.segment.cluster.tail.data; - if (ne_get_uint(cluster.timecode, cluster_tc) != 0) - return -1; - - abs_timecode = timecode[0] + cluster_tc[0]; - if (abs_timecode < 0) - return -1; - - //todo: pkt = ne_alloc(sizeof(*pkt)); - pkt=new nestegg_packet();//* - pkt.track = track.val - 1; - pkt.timecode = abs_timecode * tc_scale * track_scale; - -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "%sblock t %lld pts %f f %llx frames: %llu", -// block_id == ID_BLOCK ? "" : "simple", pkt.track, pkt.timecode / 1e9, flags, frames); - - last = null; - for (i = 0; i < frames[0]; ++i) { - if (frame_sizes[i] > LIMIT_FRAME) { - nestegg_free_packet(pkt); - return -1; - } - //todo: f = ne_alloc(sizeof(*f)); - f=new frame(); - f.data = []/*'reserved space '+*///frame_sizes[i];//frame_sizes[i];//'ne_alloc(frame_sizes[i])'; - f.length = frame_sizes[i]; - f.data={val:f.data}; - r = ne_io_read(ctx.io, f.data, frame_sizes[i]);f.data=f.data.val; - if (r != 1) { - //free(f.data); - f.data=null; - //free(f); - f=null; - nestegg_free_packet(pkt); - return -1; - } - - if (!last) - pkt.frame = f; - else - last.next = f; - last = f; - } - - data[0] = pkt; - - return 1; -} - -//ne_null_log_callback(nestegg * ctx, unsigned int severity, char const * fmt, ...) -function -ne_null_log_callback(ctx, severity, fmt, ppp) //todo fmt[ptr]? -{ - if (ctx && severity && fmt) - return; -} - -function //1354 -ne_is_suspend_element(id) -{ - /* this could search the tree of elements for DESC_FLAG_SUSPEND */ - if (id == ID_SIMPLE_BLOCK || id == ID_BLOCK) - return 1; - return 0; -} - -var ctx_=new nestegg(); -//1410 -function -nestegg_init(context, io, callback) -{ - var r=int_; - var id=[0], version=[0], docversion=[uint64_t]; - var track;//*=new ebml_list_node() - var doctype=[char_];//* - var ctx = ctx_;//todo: null * - - if (!(io.read && io.seek && io.tell)) - return -1; - - //todo: ctx = ne_alloc(sizeof(ctx));//* - - //todo: ctx.io = ne_alloc(sizeof(*ctx->io)); - ctx.io = io;//* -// ctx.log = callback; - ctx.alloc_pool = ne_pool_init(); - -// if (!ctx.log) -// ctx.log = ne_null_log_callback; - - r = ne_peek_element(ctx, id, null); - if (r != 1) { - nestegg_destroy(ctx); - return -1; - } - - if (id[0] != ID_EBML) { - nestegg_destroy(ctx); - return -1; - } - -// ctx.log(ctx, NESTEGG_LOG_DEBUG, "ctx %p", ctx); - - ne_ctx_push(ctx, ne_top_level_elements, ctx); - - r = ne_parse(ctx, null); - - if (r != 1) { - nestegg_destroy(ctx); - return -1; - } - - if (ne_get_uint(ctx.ebml.ebml_read_version, version) != 0) - version = 1; - if (version[0] != 1) { - nestegg_destroy(ctx); - return -1; - } - - if (ne_get_string(ctx.ebml.doctype, doctype) != 0) - doctype[0] = "matroska"; - if (strcmp(doctype[0], "webm") != 0) { - nestegg_destroy(ctx); - return -1; - } - - if (ne_get_uint(ctx.ebml.doctype_read_version, docversion) != 0) - docversion[0] = 1; - if (docversion[0] < 1 || docversion[0] > 2) { - nestegg_destroy(ctx); - return -1; - } - - if (!ctx.segment.tracks.track_entry.head) { - nestegg_destroy(ctx); - return -1; - } - - track = ctx.segment.tracks.track_entry.head; - ctx.track_count = 0; - - while (track) { - ctx.track_count += 1; - track = track.next; - } - - context[0]=ctx; - - return 0; -} - -function //1494 -nestegg_destroy(ctx) -{ - /*alert('todo:nestegg_destroy()'); - - while (ctx->ancestor) - ne_ctx_pop(ctx); - ne_pool_destroy(ctx->alloc_pool); - free(ctx->io); - free(ctx);*/ -} - -function //1525 -nestegg_track_count(ctx, tracks) -{ - tracks[0] = ctx.track_count; - return 0; -} - -function //1634 -nestegg_track_type(ctx, track) -{ - //struct track_entry * entry; - var type=[uint64_t]; - - var entry = ne_find_track_entry(ctx, track); - if (!entry) - return -1; - - if (ne_get_uint(entry.type, type) != 0) - return -1; - - if (type[0] & TRACK_TYPE_VIDEO) - return NESTEGG_TRACK_VIDEO; - - if (type[0] & TRACK_TYPE_AUDIO) - return NESTEGG_TRACK_AUDIO; - - return -1; -} - -function //1656 -nestegg_track_codec_id(ctx, track) -{ - var codec_id=[char_];//* - //struct track_entry * entry; - - var entry = ne_find_track_entry(ctx, track); - if (!entry) - return -1; - - if (ne_get_string(entry.codec_id, codec_id) != 0) - return -1; - - if (strcmp(codec_id[0], TRACK_ID_VP8) == 0) - return NESTEGG_CODEC_VP8; - - if (strcmp(codec_id[0], TRACK_ID_VORBIS) == 0) - return NESTEGG_CODEC_VORBIS; - - return -1; -} - -function //1759 -nestegg_track_video_params(ctx, track, - params) -{ - //struct track_entry * entry; - var value=[uint64_t]; - - //todo: memset(params, 0, sizeof(params)); - - var entry = ne_find_track_entry(ctx, track); - if (!entry) - return -1; - - if (nestegg_track_type(ctx, track) != NESTEGG_TRACK_VIDEO) - return -1; - - if (ne_get_uint(entry.video.pixel_width, value) != 0) - return -1; - params.width = value[0]; - - if (ne_get_uint(entry.video.pixel_height, value) != 0) - return -1; - params.height = value[0]; - - value[0] = 0; - ne_get_uint(entry.video.pixel_crop_bottom, value); - params.crop_bottom = value[0]; - - value[0] = 0; - ne_get_uint(entry.video.pixel_crop_top, value); - params.crop_top = value[0]; - - value[0] = 0; - ne_get_uint(entry.video.pixel_crop_left, value); - params.crop_left = value[0]; - - value[0] = 0; - ne_get_uint(entry.video.pixel_crop_right, value); - params.crop_right = value[0]; - - value[0] = params.width; - ne_get_uint(entry.video.display_width, value); - params.display_width = value[0]; - - value[0] = params.height; - ne_get_uint(entry.video.display_height, value); - params.display_height = value[0]; - - return 0; -} - -function //1840 -nestegg_read_packet(ctx, pkt) -{ - var r=int_; - var id=[uint64_t], size=[uint64_t]; - - pkt[0] = null; - - while(1) {//for (;;) { - r = ne_peek_element(ctx, id, size); - if (r != 1) - return r; - - /* any suspend fields must be handled here */ - if (ne_is_suspend_element(id)) { - r = ne_read_element(ctx, id, size); - if (r != 1) - return r; - - /* the only suspend fields are blocks and simple blocks, which we - handle directly. */ - r = ne_read_block(ctx, id, size[0], pkt); - return r; - } - - r = ne_parse(ctx, null); - if (r != 1) - return r; - } - - return 1; -} - -function //1873 -nestegg_free_packet(pkt) -{ - var frame;//=new frame();//* - - while (pkt.frame) { - frame = pkt.frame; - pkt.frame = frame.next; - //free(frame.data); - frame.data=''; - //free(frame); - frame=''; - } - - //free(pkt); - pkt=''; -} - -function //1888 -nestegg_packet_track(pkt, track) -{ - track[0] = pkt[0].track;//todo add 0, is this the best solution? - return 0; -} - -function //1902 -nestegg_packet_count(pkt, count) -{ - var f = pkt[0].frame;//todo: best solution?? //* - - count[0] = 0; - - while (f) { - count[0] += 1; - f = f.next; - } - - return 0; -} - -function //1917 -nestegg_packet_data(pkt, item_, - data, length) //todo: data_off??? -{ - var f = pkt[0].frame;//todo: best solution?? - var count = 0; - - data[0] = null; - length[0] = 0; - - while (f) { - if (count == item_) { - data[0] = f.data;//data_off??? - length[0] = f.length; - return 0; - } - count += 1; - f = f.next; - } - - return -1; -} - - - -var VPX_IMAGE_ABI_VERSION = (1); /**<\hideinitializer*/ - - -var VPX_IMG_FMT_PLANAR = 0x100; /**< Image is a planar format */ -var VPX_IMG_FMT_UV_FLIP = 0x200; /**< V plane precedes U plane in memory */ -var VPX_IMG_FMT_HAS_ALPHA = 0x400; /**< Image has an alpha channel component */ - - - /*!\brief List of supported image formats */ -var - VPX_IMG_FMT_NONE=0, - VPX_IMG_FMT_RGB24=1, /**< 24 bit per pixel packed RGB */ - VPX_IMG_FMT_RGB32=2, /**< 32 bit per pixel packed 0RGB */ - VPX_IMG_FMT_RGB565=3, /**< 16 bit per pixel, 565 */ - VPX_IMG_FMT_RGB555=4, /**< 16 bit per pixel, 555 */ - VPX_IMG_FMT_UYVY=5, /**< UYVY packed YUV */ - VPX_IMG_FMT_YUY2=6, /**< YUYV packed YUV */ - VPX_IMG_FMT_YVYU=7, /**< YVYU packed YUV */ - VPX_IMG_FMT_BGR24=8, /**< 24 bit per pixel packed BGR */ - VPX_IMG_FMT_RGB32_LE=9, /**< 32 bit packed BGR0 */ - VPX_IMG_FMT_ARGB=10, /**< 32 bit packed ARGB, alpha=255 */ - VPX_IMG_FMT_ARGB_LE=11, /**< 32 bit packed BGRA, alpha=255 */ - VPX_IMG_FMT_RGB565_LE=12, /**< 16 bit per pixel, gggbbbbb rrrrrggg */ - VPX_IMG_FMT_RGB555_LE=13, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */ - VPX_IMG_FMT_YV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ - VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2, - VPX_IMG_FMT_VPXYV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 3, /** < planar 4:2:0 format with vpx color space */ - VPX_IMG_FMT_VPXI420 = VPX_IMG_FMT_PLANAR | 4; /** < planar 4:2:0 format with vpx color space */ - ; /**< alias for enum vpx_img_fmt */ - -//#if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT -var IMG_FMT_PLANAR = VPX_IMG_FMT_PLANAR; /**< \deprecated Use #VPX_IMG_FMT_PLANAR */ -var IMG_FMT_UV_FLIP = VPX_IMG_FMT_UV_FLIP; /**< \deprecated Use #VPX_IMG_FMT_UV_FLIP */ -var IMG_FMT_HAS_ALPHA = VPX_IMG_FMT_HAS_ALPHA; /**< \deprecated Use #VPX_IMG_FMT_HAS_ALPHA */ - - /*!\brief Deprecated list of supported image formats - * \deprecated New code should use #vpx_img_fmt - */ -//var img_fmt = vpx_img_fmt - /*!\brief alias for enum img_fmt. - * \deprecated New code should use #vpx_img_fmt_t - */ -//var img_fmt_t = vpx_img_fmt_t - -var IMG_FMT_NONE = VPX_IMG_FMT_NONE; /**< \deprecated Use #VPX_IMG_FMT_NONE */ -var IMG_FMT_RGB24 = VPX_IMG_FMT_RGB24; /**< \deprecated Use #VPX_IMG_FMT_RGB24 */ -var IMG_FMT_RGB32 = VPX_IMG_FMT_RGB32; /**< \deprecated Use #VPX_IMG_FMT_RGB32 */ -var IMG_FMT_RGB565 = VPX_IMG_FMT_RGB565; /**< \deprecated Use #VPX_IMG_FMT_RGB565 */ -var IMG_FMT_RGB555 = VPX_IMG_FMT_RGB555; /**< \deprecated Use #VPX_IMG_FMT_RGB555 */ -var IMG_FMT_UYVY = VPX_IMG_FMT_UYVY; /**< \deprecated Use #VPX_IMG_FMT_UYVY */ -var IMG_FMT_YUY2 = VPX_IMG_FMT_YUY2; /**< \deprecated Use #VPX_IMG_FMT_YUY2 */ -var IMG_FMT_YVYU = VPX_IMG_FMT_YVYU; /**< \deprecated Use #VPX_IMG_FMT_YVYU */ -var IMG_FMT_BGR24 = VPX_IMG_FMT_BGR24; /**< \deprecated Use #VPX_IMG_FMT_BGR24 */ -var IMG_FMT_RGB32_LE = VPX_IMG_FMT_RGB32_LE; /**< \deprecated Use #VPX_IMG_FMT_RGB32_LE */ -var IMG_FMT_ARGB = VPX_IMG_FMT_ARGB; /**< \deprecated Use #VPX_IMG_FMT_ARGB */ -var IMG_FMT_ARGB_LE = VPX_IMG_FMT_ARGB_LE; /**< \deprecated Use #VPX_IMG_FMT_ARGB_LE */ -var IMG_FMT_RGB565_LE = VPX_IMG_FMT_RGB565_LE; /**< \deprecated Use #VPX_IMG_FMT_RGB565_LE */ -var IMG_FMT_RGB555_LE = VPX_IMG_FMT_RGB555_LE; /**< \deprecated Use #VPX_IMG_FMT_RGB555_LE */ -var IMG_FMT_YV12 = VPX_IMG_FMT_YV12; /**< \deprecated Use #VPX_IMG_FMT_YV12 */ -var IMG_FMT_I420 = VPX_IMG_FMT_I420; /**< \deprecated Use #VPX_IMG_FMT_I420 */ -var IMG_FMT_VPXYV12 = VPX_IMG_FMT_VPXYV12; /**< \deprecated Use #VPX_IMG_FMT_VPXYV12 */ -var IMG_FMT_VPXI420 = VPX_IMG_FMT_VPXI420; /**< \deprecated Use #VPX_IMG_FMT_VPXI420 */ -//#endif /* VPX_CODEC_DISABLE_COMPAT */ - - - - -function img_alloc_helper(img, - fmt, - d_w, - d_h, - stride_align, - img_data) -{ - - var h=int_, w=int_, s=int_, xcs=int_, ycs=int_, bps=int_; - var align=int_; - - /* Treat align==0 like align==1 */ - if (!stride_align) - stride_align = 1; - - /* Validate alignment (must be power of 2) */ - if (stride_align & (stride_align - 1)) - alert('goto fail'); - - /* Get sample size for this format */ - switch (fmt) - { - case VPX_IMG_FMT_RGB32: - case VPX_IMG_FMT_RGB32_LE: - case VPX_IMG_FMT_ARGB: - case VPX_IMG_FMT_ARGB_LE: - bps = 32; - break; - case VPX_IMG_FMT_RGB24: - case VPX_IMG_FMT_BGR24: - bps = 24; - break; - case VPX_IMG_FMT_RGB565: - case VPX_IMG_FMT_RGB565_LE: - case VPX_IMG_FMT_RGB555: - case VPX_IMG_FMT_RGB555_LE: - case VPX_IMG_FMT_UYVY: - case VPX_IMG_FMT_YUY2: - case VPX_IMG_FMT_YVYU: - bps = 16; - break; - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_VPXI420: - case VPX_IMG_FMT_VPXYV12: - bps = 12; - break; - default: - bps = 16; - break; - } - - /* Get chroma shift values for this format */ - switch (fmt) - { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_VPXI420: - case VPX_IMG_FMT_VPXYV12: - xcs = 1; - break; - default: - xcs = 0; - break; - } - - switch (fmt) - { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_VPXI420: - case VPX_IMG_FMT_VPXYV12: - ycs = 1; - break; - default: - ycs = 0; - break; - } - - /* Calculate storage sizes given the chroma subsampling */ - align = (1 << xcs) - 1; - w = (d_w + align) & ~align; - align = (1 << ycs) - 1; - h = (d_h + align) & ~align; - s = (fmt & VPX_IMG_FMT_PLANAR) ? w : bps * w / 8; - s = (s + stride_align - 1) & ~(stride_align - 1); - - /* Allocate the new image */ - if (!img) - { - img = new vpx_image_t();//(vpx_image_t *)calloc(1, sizeof(vpx_image_t)); - - if (!img) - alert('goto fail'); - - img.self_allocd = 1; - } - else - { - //todo: memset(img, 0, sizeof(vpx_image_t)); - } - - img.img_data = img_data; - - if (!img_data) - { - img.img_data = malloc((fmt & VPX_IMG_FMT_PLANAR) ? h * w * bps / 8 : h * s,0); - img.img_data_owner = 1; - } - - if (!img.img_data) - alert('goto fail'); - - img.fmt = img["fmt"] = fmt; - img.w = img["w"] = w; - img.h = img["h"] = h; - img.x_chroma_shift = img["x_chroma_shift"] = xcs; - img.y_chroma_shift = img["y_chroma_shift"] = ycs; - img.bps = img["bps"] = bps; - - /* Calculate strides */ - img.stride[VPX_PLANE_Y] = img.stride[VPX_PLANE_ALPHA] = s; - img.stride[VPX_PLANE_U] = img.stride[VPX_PLANE_V] = s >> xcs; - - /* Default viewport to entire image */ - if (!vpx_img_set_rect(img, 0, 0, d_w, d_h)) - return img; - -//fail: - vpx_img_free(img); - return null; -} - -function vpx_img_alloc(img, - fmt, - d_w, - d_h, - stride_align) -{ - return img_alloc_helper(img, fmt, d_w, d_h, stride_align, null); -} - -//vpx_image_t *vpx_img_wrap(vpx_image_t *img, -// vpx_img_fmt_t fmt, -// unsigned int d_w, -// unsigned int d_h, -// unsigned int stride_align, -// unsigned char *img_data) -//{ -// return img_alloc_helper(img, fmt, d_w, d_h, stride_align, img_data); -//} - -function vpx_img_set_rect(img, - x, - y, - w, - h) -{ - var data=char_;var data_off=0; - - if (x + w <= img.w && y + h <= img.h) - { - img.d_w = img["d_w"] = w; - img.d_h = img["d_h"] = h; - - /* Calculate plane pointers */ - if (!(img.fmt & VPX_IMG_FMT_PLANAR)) - { - img.planes[VPX_PLANE_PACKED] = - img.img_data; img.img_data_of + parseInt(x * img.bps / 8 + y * img.stride[VPX_PLANE_PACKED],10); - } - else - { - data = img.img_data; data_off = img.img_data_off; - - if (img.fmt & VPX_IMG_FMT_HAS_ALPHA) - { - img.planes[VPX_PLANE_ALPHA] = - data; - img.planes_off[VPX_PLANE_ALPHA] = - data_off + x + y * img.stride[VPX_PLANE_ALPHA]; - data_off += img.h * img.stride[VPX_PLANE_ALPHA]; - } - - img.planes[VPX_PLANE_Y] = data; img.planes_off[VPX_PLANE_Y] = data_off + x + y * img.stride[VPX_PLANE_Y]; - data_off += img.h * img.stride[VPX_PLANE_Y]; - - if (!(img.fmt & VPX_IMG_FMT_UV_FLIP)) - { - img.planes[VPX_PLANE_U] = data; - img.planes_off[VPX_PLANE_U] = data_off - + (x >> img.x_chroma_shift) - + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_U]; - data_off += (img.h >> img.y_chroma_shift) * img.stride[VPX_PLANE_U]; - img.planes[VPX_PLANE_V] = data; - img.planes_off[VPX_PLANE_V] = data_off - + (x >> img.x_chroma_shift) - + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_V]; - } - else - { - img.planes[VPX_PLANE_V] = data; - img.planes_off[VPX_PLANE_V] = data_off - + (x >> img.x_chroma_shift) - + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_V]; - data_off += (img.h >> img.y_chroma_shift) * img.stride[VPX_PLANE_V]; - img.planes[VPX_PLANE_U] = data; - img.planes_off[VPX_PLANE_U] = data_off - + (x >> img.x_chroma_shift) - + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_U]; - } - } - - return 0; - } - - return -1; -} - -//void vpx_img_flip(vpx_image_t *img) -//{ -// /* Note: In the calculation pointer adjustment calculation, we want the -// * rhs to be promoted to a signed type. Section 6.3.1.8 of the ISO C99 -// * standard indicates that if the adjustment parameter is unsigned, the -// * stride parameter will be promoted to unsigned, causing errors when -// * the lhs is a larger type than the rhs. -// */ -// img->planes[VPX_PLANE_Y] += (signed)(img->d_h - 1) * img->stride[VPX_PLANE_Y]; -// img->stride[VPX_PLANE_Y] = -img->stride[VPX_PLANE_Y]; -// -// img->planes[VPX_PLANE_U] += (signed)((img->d_h >> img->y_chroma_shift) - 1) -// * img->stride[VPX_PLANE_U]; -// img->stride[VPX_PLANE_U] = -img->stride[VPX_PLANE_U]; -// -// img->planes[VPX_PLANE_V] += (signed)((img->d_h >> img->y_chroma_shift) - 1) -// * img->stride[VPX_PLANE_V]; -// img->stride[VPX_PLANE_V] = -img->stride[VPX_PLANE_V]; -// -// img->planes[VPX_PLANE_ALPHA] += (signed)(img->d_h - 1) * img->stride[VPX_PLANE_ALPHA]; -// img->stride[VPX_PLANE_ALPHA] = -img->stride[VPX_PLANE_ALPHA]; -//} -// -function vpx_img_free(img) -{ - if (img) - { - if (img.img_data && img.img_data_owner) - img.img_data='';//free(img.img_data); - - if (img.self_allocd) - img='';//free(img); - } -} - - - -//15 -var bool_decoder = function() -{ - this.input=char_,// * /* next compressed data byte */ - this.input_off=0,// * /* next compressed data byte */ - this.input_len=size_t, /* length of the input buffer */ - this.range=int_, /* identical to encoder's range */ - this.value=int_, /* contains at least 8 significant - * bits */ - this.bit_count=int_ /* # of bits shifted out of value, - * max 7 */ -}; - - -//27 -function -init_bool_decoder(d, - start_partition, - start_partition_off, - sz) -{ - if (sz >= 2) - { - d.value = (start_partition[start_partition_off+0] << 8) /* first 2 input bytes */ - | start_partition[start_partition_off+1]; - d.input = start_partition; d.input_off = start_partition_off + 2; /* ptr to next byte */ - d.input_len = sz - 2; - } - else - { - d.value = 0; - d.input = null; - d.input_len = 0; - } - - d.range = 255; /* initial range is full */ - d.bit_count = 0; /* have not yet shifted out any bits */ -} - - -function bool_get(d, probability) -{ - /* range and split are identical to the corresponding values - used by the encoder when this bool was written */ - - var splitt = 1 + (((d.range - 1) * probability) >> 8); - var SPLIT = splitt << 8; - var retval=int_; /* will be 0 or 1 */ - - if (d.value >= SPLIT) /* encoded a one */ - { - retval = 1; - d.range -= splitt; /* reduce range */ - d.value -= SPLIT; /* subtract off left endpoint of interval */ - } - else /* encoded a zero */ - { - retval = 0; - d.range = splitt; /* reduce range, no change in left endpoint */ - } - - while (d.range < 128) /* shift out irrelevant value bits */ - { - d.value <<= 1; - d.range <<= 1; - - if (++d.bit_count == 8) /* shift in new bits 8 at a time */ - { - d.bit_count = 0; - - if (d.input_len) - { - d.value |= d.input[d.input_off++]; - d.input_len--; - } - } - } - - return retval; -} - - -function bool_get_bit(br) -{ - return bool_get(br, 128); -} - - -function bool_get_uint(br, bits) -{ - var z = 0; - var bit=int_; - - for (bit = bits - 1; bit >= 0; bit--) - { - z |= (bool_get_bit(br) << bit); - } - - return z; -} - - -function bool_get_int(br, bits) -{ - var z = 0; - var bit=int_; - - for (bit = bits - 1; bit >= 0; bit--) - { - z |= (bool_get_bit(br) << bit); - } - - return bool_get_bit(br) ? -z : z; -} - - -function bool_maybe_get_int(br, bits) -{ - return bool_get_bit(br) ? bool_get_int(br, bits) : 0; -} - - -//133 -function -bool_read_tree(bool, - t, - p, - p_off) -{ - var i = 0; - - if(typeof p_off!=='undefined') - while ((i = t[ i + bool_get(bool, p[p_off +(i>>1)])]) > 0) ; - else - while ((i = t[ i + bool_get(bool, p[i>>1])]) > 0) ; - - return -i; -} - - -/* Evaluates to a mask with n bits set */ -function BITS_MASK(n) { return ((1<<(n))-1) } - -/* Returns len bits, with the LSB at position bit */ -function BITS_GET(val, bit, len) { return (((val)>>(bit))&BITS_MASK(len)) } - - - - -var vp8_frame_hdr = function() -{ - this.is_keyframe=int_, /* Frame is a keyframe */ - this.is_experimental=int_, /* Frame is a keyframe */ - this.version=int_, /* Bitstream version */ - this.is_shown=int_, /* Frame is to be displayed. */ - this.part0_sz=int_, /* Partition 0 length, in bytes */ - - this.kf=new Object(//vp8_kf_hdr: - { - w:int_, /* Width */ - h:int_, /* Height */ - scale_w:int_, /* Scaling factor, Width */ - scale_h:int_ /* Scaling factor, Height */ - }),// kf; - - this.frame_size_updated=int_ /* Flag to indicate a resolution - * update. - */ -}; - - -var - MB_FEATURE_TREE_PROBS = 3, - MAX_MB_SEGMENTS = 4 -; - - -var vp8_segment_hdr = function() -{ - this.enabled=int_, - this.update_data=int_, - this.update_map=int_, - this.abs_=int_, /* 0=deltas, 1=absolute values */ - this.tree_probs=new Array(MB_FEATURE_TREE_PROBS),//,int_), - this.lf_level=new Array(MAX_MB_SEGMENTS),//,int_), - this.quant_idx=new Array(MAX_MB_SEGMENTS)//,int_) -}; - - -var - BLOCK_CONTEXTS = 4 -; - - -var vp8_loopfilter_hdr = function() -{ - this.use_simple=int_, - this.level=int_, - this.sharpness=int_, - this.delta_enabled=int_, - this.ref_delta=new Array(BLOCK_CONTEXTS),//,int_), - this.mode_delta=new Array(BLOCK_CONTEXTS)//,int_) -}; - - -var - MAX_PARTITIONS = 8 -; - -var vp8_token_hdr = function() -{ - this.partitions=int_, - this.partition_sz=new Array(MAX_PARTITIONS)//,int_) -}; - - -var vp8_quant_hdr = function() -{ - this.q_index=int_, - this.delta_update=int_, - this.y1_dc_delta_q=int_, - this.y2_dc_delta_q=int_, - this.y2_ac_delta_q=int_, - this.uv_dc_delta_q=int_, - this.uv_ac_delta_q=int_ -}; - - -var vp8_reference_hdr = function() -{ - this.refresh_last=int_, - this.refresh_gf=int_, - this.refresh_arf=int_, - this.copy_gf=int_, - this.copy_arf=int_, - this.sign_bias=new Array(4),//,int_), - this.refresh_entropy=int_ -}; - - -var - BLOCK_TYPES = 4, - PREV_COEF_CONTEXTS = 3, - COEF_BANDS = 8, - ENTROPY_NODES = 11 -; -var coeff_probs_table_t=function() {return ArrM(new Array(BLOCK_TYPES,COEF_BANDS, -PREV_COEF_CONTEXTS, -ENTROPY_NODES),char_);} - - -var - MV_PROB_CNT = 2 + 8 - 1 + 10 /* from entropymv.h */ -; -var mv_component_probs_t=function(){return new Array(MV_PROB_CNT)};//,char_); - -var Arr_1056=Arr(1056,0); -var vp8_entropy_hdr = function() -{ - this.coeff_probs=new coeff_probs_table_t(), - this.coeff_probs_=Arr(1056,0),//Arr_1056, - this.mv_probs=Arr_new(2,mv_component_probs_t), - this.coeff_skip_enabled=int_, - this.coeff_skip_prob=char_, - this.y_mode_probs=new Array(0,0,0,0),//4,char_ - this.uv_mode_probs=new Array(0,0,0),//3,char_ - this.prob_inter=char_, - this.prob_last=char_, - this.prob_gf=char_ -}; - - -var - CURRENT_FRAME=0, - LAST_FRAME=1, - GOLDEN_FRAME=2, - ALTREF_FRAME=3, - NUM_REF_FRAMES=4 -; - - -var filter_t=function() {return new Array(6);}//,short_ - - -var mv = function() -{ - this.d= - { - x:int16_t, y:int16_t - } - //uint32_t raw; -};// mv_t; - - -var mb_base_info = function() -{ - this.y_mode = char_,//4; - this.uv_mode = char_,//4; - this.segment_id = char_,//2; - this.ref_frame = char_,//2; - this.skip_coeff = char_,//1; - this.need_mc_border = char_,//1; - this.partitioning = null,//2;'enum splitmv_partitioning' - this.mv =new mv(), - this.eob_mask =int_ -}; - - -var mb_info = function() -{ - this.base =new mb_base_info(), - this.splitt=new Object( - { - mvs:Arr_new(16,mv), - modes:new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)//16,'todo:enum prediction_mode') - }) -}; - - -/* A "token entropy context" has 4 Y values, 2 U, 2 V, and 1 Y2 */ -var token_entropy_ctx_t=function() {return new Array(4 + 2 + 2 + 1);}//Arr,int_ - -var token_decoder = function() -{ - this.bool =new bool_decoder(), - this.left_token_entropy_ctx =new token_entropy_ctx_t(), - this.coeffs =short_//* -}; - -var - TOKEN_BLOCK_Y1=0, - TOKEN_BLOCK_UV=1, - TOKEN_BLOCK_Y2=2, - TOKEN_BLOCK_TYPES=3 -; - -var dequant_factors = function() -{ - this.quant_idx =int_, - this.factor =ArrM(new Array(TOKEN_BLOCK_TYPES,2),short_) /* [ Y1, UV, Y2 ] [ DC, AC ] */ -}; - - -var ref_cnt_img = function() -{ - this.img =new vpx_image_t(), - this.ref_cnt =int_ -}; - - -var vp8_decoder_ctx = function() -{ - this.error=[],//todo: newObjectI(vpx_internal_error_info), - this.frame_cnt=int_, - - this.frame_hdr= new vp8_frame_hdr(), - this.segment_hdr= new vp8_segment_hdr(), - this.loopfilter_hdr= new vp8_loopfilter_hdr(), - this.token_hdr= new vp8_token_hdr(), - this.quant_hdr= new vp8_quant_hdr(), - this.reference_hdr= new vp8_reference_hdr(), - this.entropy_hdr= new vp8_entropy_hdr(), - - this.saved_entropy= new vp8_entropy_hdr(), - this.saved_entropy_valid=int_, - - this.mb_rows=int_, - this.mb_cols=int_, - this.mb_info_storage =null,//* - this.mb_info_storage_off =0, - this.mb_info_storage_object =(mb_info),//new - - this.mb_info_rows_storage =null,//** - this.mb_info_rows_storage_off =0, - this.mb_info_rows_storage_object =(mb_info),//new - this.mb_info_rows =null,//mb_info** - this.mb_info_rows_off =0, - - this.above_token_entropy_ctx =null,//*'token_entropy_ctx_t' - this.above_token_entropy_ctx_object =(token_entropy_ctx_t),//* - this.tokens =Arr_new(MAX_PARTITIONS,token_decoder), - this.dequant_factors =Arr_new(MAX_MB_SEGMENTS,dequant_factors), - - this.frame_strg =Arr_new(NUM_REF_FRAMES,ref_cnt_img), - this.ref_frames =Arr_new(NUM_REF_FRAMES,ref_cnt_img),//* - this.ref_frame_offsets =new Array(0,0,0,0),//4,ptrdiff_t - this.ref_frame_offsets_ =new Array(0,0,0,0),//4,ptrdiff_t - - this.subpixel_filters =new filter_t()//* -}; - - -//306 -function CLAMP_255(x) { return (x<0?0:x>255?255:x) }//{ return ((x)<0?0:((x)>255?255:(x))) } - - - -//14 -function -vp8_dixie_walsh(input, input_off, output, output_off) -{ - var i=int_; - var a1=int_, b1=int_, c1=int_, d1=int_; - var a2=int_, b2=int_, c2=int_, d2=int_; - var ip = input; var ip_off = input_off; - var op = output; var op_off = output_off; - - for (i = 0; i < 4; i++) - { - a1 = ip[ip_off+ 0] + ip[ip_off+ 12]; - b1 = ip[ip_off+ 4] + ip[ip_off+ 8]; - c1 = ip[ip_off+ 4] - ip[ip_off+ 8]; - d1 = ip[ip_off+ 0] - ip[ip_off+ 12]; - - op[op_off+ 0] = a1 + b1; - op[op_off+ 4] = c1 + d1; - op[op_off+ 8] = a1 - b1; - op[op_off+ 12] = d1 - c1; - ip_off++; - op_off++; - } - - ip = output; ip_off = output_off; - op = output; op_off = output_off; - - for (i = 0; i < 4; i++) - { - a1 = ip[ip_off+ 0] + ip[ip_off+ 3]; - b1 = ip[ip_off+ 1] + ip[ip_off+ 2]; - c1 = ip[ip_off+ 1] - ip[ip_off+ 2]; - d1 = ip[ip_off+ 0] - ip[ip_off+ 3]; - - a2 = a1 + b1; - b2 = c1 + d1; - c2 = a1 - b1; - d2 = d1 - c1; - - op[op_off+ 0] = (a2 + 3) >> 3; - op[op_off+ 1] = (b2 + 3) >> 3; - op[op_off+ 2] = (c2 + 3) >> 3; - op[op_off+ 3] = (d2 + 3) >> 3; - - ip_off += 4; - op_off += 4; - } -} - - -var cospi8sqrt2minus1 = 20091; -var sinpi8sqrt2 = 35468; -/*var rounding = 0;*/ -//67 -function -idct_columns(input, input_off, output, output_off) -{ - var i=int_; - var a1=int_, b1=int_, c1=int_, d1=int_; - - var ip = input; var ip_off = input_off; - var op = output; var op_off = output_off; - var temp1=int_, temp2=int_; - var shortpitch = 4; - - for (i = 0; i < 4; i++) - { - a1 = ip[ip_off+ 0] + ip[ip_off+ 8]; - b1 = ip[ip_off+ 0] - ip[ip_off+ 8]; - - temp1 = (ip[ip_off+ 4] * sinpi8sqrt2/* + rounding */) >> 16; - temp2 = ip[ip_off+ 12] + - ((ip[ip_off+ 12] * cospi8sqrt2minus1/* + rounding */) >> 16); - c1 = temp1 - temp2; - - temp1 = ip[ip_off+ 4] + - ((ip[ip_off+ 4] * cospi8sqrt2minus1/* + rounding */) >> 16); - temp2 = (ip[ip_off+ 12] * sinpi8sqrt2/* + rounding */) >> 16; - d1 = temp1 + temp2; - - op[op_off+ shortpitch*0] = a1 + d1; - op[op_off+ shortpitch*3] = a1 - d1; - - op[op_off+ shortpitch*1] = b1 + c1; - op[op_off+ shortpitch*2] = b1 - c1; - - ip_off++; - op_off++; - } -} - -var tmp_2=Arr(16,0); -//105 -function -vp8_dixie_idct_add(recon, - recon_off, - predict, - predict_off, - stride, - coeffs, - coeffs_off) -{ - var i=int_; - var a1=int_, b1=int_, c1=int_, d1=int_, temp1=int_, temp2=int_; - /*Arr(16,short_);*/ var tmp_off=0; - - idct_columns(coeffs, coeffs_off, tmp_2, tmp_off); - coeffs = tmp_2; coeffs_off = tmp_off;//todo: pinter tmp coeffs? - - for (i = 0; i < 4; i++) - { - a1 = coeffs[coeffs_off+ 0] + coeffs[coeffs_off+ 2]; - b1 = coeffs[coeffs_off+ 0] - coeffs[coeffs_off+ 2]; - - temp1 = (coeffs[coeffs_off+ 1] * sinpi8sqrt2/* + rounding */) >> 16; - temp2 = coeffs[coeffs_off+ 3] + - ((coeffs[coeffs_off+ 3] * cospi8sqrt2minus1/* + rounding */) >> 16); - c1 = temp1 - temp2; - - temp1 = coeffs[coeffs_off+ 1] + - ((coeffs[coeffs_off+ 1] * cospi8sqrt2minus1/* + rounding */) >> 16); - temp2 = (coeffs[coeffs_off+ 3] * sinpi8sqrt2/* + rounding */) >> 16; - d1 = temp1 + temp2; - - recon[recon_off+ 0] = (predict[predict_off+ 0] + ((a1 + d1 + 4) >> 3));//CLAMP_255 - recon[recon_off+ 3] = (predict[predict_off+ 3] + ((a1 - d1 + 4) >> 3));//CLAMP_255 - recon[recon_off+ 1] = (predict[predict_off+ 1] + ((b1 + c1 + 4) >> 3));//CLAMP_255 - recon[recon_off+ 2] = (predict[predict_off+ 2] + ((b1 - c1 + 4) >> 3));//CLAMP_255 - - coeffs_off += 4; - recon_off += stride; - predict_off += stride; - } -} - - -var k_coeff_entropy_update_probs = -new Array( - new Array( - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255 ), - new Array(250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ) - ), - new Array( - new Array( - new Array(217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255 ), - new Array(234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ) - ), - new Array( - new Array( - new Array(186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255 ), - new Array(251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ) - ), - new Array( - new Array( - new Array(248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255 ), - new Array(248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ), - new Array( - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ), - new Array(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ) - ) - ) -); - - -var k_default_y_mode_probs = -new Array( 112, 86, 140, 37); - - -var k_default_uv_mode_probs = -new Array( 162, 101, 204); - - -var k_default_coeff_probs = -new Array( - new Array( /* block type 0 */ - new Array( /* coeff band 0 */ - new Array( 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 1 */ - new Array( 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128), - new Array( 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128), - new Array( 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128) - ), - new Array( /* coeff band 2 */ - new Array( 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128), - new Array( 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128), - new Array( 78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128) - ), - new Array( /* coeff band 3 */ - new Array( 1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128), - new Array( 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128), - new Array( 77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 4 */ - new Array( 1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128), - new Array( 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128), - new Array( 37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128) - ), - new Array( /* coeff band 5 */ - new Array( 1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128), - new Array( 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128), - new Array( 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 6 */ - new Array( 1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128), - new Array( 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128), - new Array( 80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 7 */ - new Array( 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 246, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128) - ) - ), - new Array( /* block type 1 */ - new Array( /* coeff band 0 */ - new Array( 198, 35, 237, 223, 193, 187, 162, 160, 145, 155, 62), - new Array( 131, 45, 198, 221, 172, 176, 220, 157, 252, 221, 1), - new Array( 68, 47, 146, 208, 149, 167, 221, 162, 255, 223, 128) - ), - new Array( /* coeff band 1 */ - new Array( 1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128), - new Array( 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128), - new Array( 81, 99, 181, 242, 176, 190, 249, 202, 255, 255, 128) - ), - new Array( /* coeff band 2 */ - new Array( 1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128), - new Array( 99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128), - new Array( 23, 91, 163, 242, 170, 187, 247, 210, 255, 255, 128) - ), - new Array( /* coeff band 3 */ - new Array( 1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128), - new Array( 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128), - new Array( 44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128) - ), - new Array( /* coeff band 4 */ - new Array( 1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128), - new Array( 94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128), - new Array( 22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128) - ), - new Array( /* coeff band 5 */ - new Array( 1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128), - new Array( 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128), - new Array( 35, 77, 181, 251, 193, 211, 255, 205, 128, 128, 128) - ), - new Array( /* coeff band 6 */ - new Array( 1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128), - new Array( 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128), - new Array( 45, 99, 188, 251, 195, 217, 255, 224, 128, 128, 128) - ), - new Array( /* coeff band 7 */ - new Array( 1, 1, 251, 255, 213, 255, 128, 128, 128, 128, 128), - new Array( 203, 1, 248, 255, 255, 128, 128, 128, 128, 128, 128), - new Array( 137, 1, 177, 255, 224, 255, 128, 128, 128, 128, 128) - ) - ), - new Array( /* block type 2 */ - new Array( /* coeff band 0 */ - new Array( 253, 9, 248, 251, 207, 208, 255, 192, 128, 128, 128), - new Array( 175, 13, 224, 243, 193, 185, 249, 198, 255, 255, 128), - new Array( 73, 17, 171, 221, 161, 179, 236, 167, 255, 234, 128) - ), - new Array( /* coeff band 1 */ - new Array( 1, 95, 247, 253, 212, 183, 255, 255, 128, 128, 128), - new Array( 239, 90, 244, 250, 211, 209, 255, 255, 128, 128, 128), - new Array( 155, 77, 195, 248, 188, 195, 255, 255, 128, 128, 128) - ), - new Array( /* coeff band 2 */ - new Array( 1, 24, 239, 251, 218, 219, 255, 205, 128, 128, 128), - new Array( 201, 51, 219, 255, 196, 186, 128, 128, 128, 128, 128), - new Array( 69, 46, 190, 239, 201, 218, 255, 228, 128, 128, 128) - ), - new Array( /* coeff band 3 */ - new Array( 1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128), - new Array( 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128), - new Array( 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 4 */ - new Array( 1, 16, 248, 255, 255, 128, 128, 128, 128, 128, 128), - new Array( 190, 36, 230, 255, 236, 255, 128, 128, 128, 128, 128), - new Array( 149, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 5 */ - new Array( 1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 6 */ - new Array( 1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128), - new Array( 213, 62, 250, 255, 255, 128, 128, 128, 128, 128, 128), - new Array( 55, 93, 255, 128, 128, 128, 128, 128, 128, 128, 128) - ), - new Array( /* coeff band 7 */ - new Array( 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128) - ) - ), - new Array( /* block type 3 */ - new Array( /* coeff band 0 */ - new Array( 202, 24, 213, 235, 186, 191, 220, 160, 240, 175, 255), - new Array( 126, 38, 182, 232, 169, 184, 228, 174, 255, 187, 128), - new Array( 61, 46, 138, 219, 151, 178, 240, 170, 255, 216, 128) - ), - new Array( /* coeff band 1 */ - new Array( 1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128), - new Array( 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128), - new Array( 39, 77, 162, 232, 172, 180, 245, 178, 255, 255, 128) - ), - new Array( /* coeff band 2 */ - new Array( 1, 52, 220, 246, 198, 199, 249, 220, 255, 255, 128), - new Array( 124, 74, 191, 243, 183, 193, 250, 221, 255, 255, 128), - new Array( 24, 71, 130, 219, 154, 170, 243, 182, 255, 255, 128) - ), - new Array( /* coeff band 3 */ - new Array( 1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128), - new Array( 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128), - new Array( 28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128) - ), - new Array( /* coeff band 4 */ - new Array( 1, 81, 230, 252, 204, 203, 255, 192, 128, 128, 128), - new Array( 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128), - new Array( 20, 95, 153, 243, 164, 173, 255, 203, 128, 128, 128) - ), - new Array( /* coeff band 5 */ - new Array( 1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128), - new Array( 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128), - new Array( 47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128) - ), - new Array( /* coeff band 6 */ - new Array( 1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128), - new Array( 141, 84, 213, 252, 201, 202, 255, 219, 128, 128, 128), - new Array( 42, 80, 160, 240, 162, 185, 255, 205, 128, 128, 128) - ), - new Array( /* coeff band 7 */ - new Array( 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128), - new Array( 238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128) - ) - ) -); - - -var k_mv_entropy_update_probs = -new Array( - new Array( - 237, - 246, - 253, 253, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 250, 250, 252, 254, 254 - ), - new Array( - 231, - 243, - 245, 253, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 251, 251, 254, 254, 254 - ) -); - - -var k_default_mv_probs = function() { -return new Array( - new Array( /* row */ - 162, /* is short */ - 128, /* sign */ - 225, 146, 172, 147, 214, 39, 156, /* short tree */ - 128, 129, 132, 75, 145, 178, 206, 239, 254, 254 /* long bits */ - ), - new Array( - 164, - 128, - 204, 170, 119, 235, 140, 230, 228, - 128, 130, 130, 74, 148, 180, 203, 236, 254, 254 - - ) -) -}; - - -var dc_q_lookup = -new Array( - 4, 5, 6, 7, 8, 9, 10, 10, - 11, 12, 13, 14, 15, 16, 17, 17, - 18, 19, 20, 20, 21, 21, 22, 22, - 23, 23, 24, 25, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, - 37, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, - 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, 74, - 75, 76, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, - 91, 93, 95, 96, 98, 100, 101, 102, - 104, 106, 108, 110, 112, 114, 116, 118, - 122, 124, 126, 128, 130, 132, 134, 136, - 138, 140, 143, 145, 148, 151, 154, 157 -); -var ac_q_lookup = -new Array( - 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, 58, 60, - 62, 64, 66, 68, 70, 72, 74, 76, - 78, 80, 82, 84, 86, 88, 90, 92, - 94, 96, 98, 100, 102, 104, 106, 108, - 110, 112, 114, 116, 119, 122, 125, 128, - 131, 134, 137, 140, 143, 146, 149, 152, - 155, 158, 161, 164, 167, 170, 173, 177, - 181, 185, 189, 193, 197, 201, 205, 209, - 213, 217, 221, 225, 229, 234, 239, 245, - 249, 254, 259, 264, 269, 274, 279, 284 -); - - -var kf_y_mode_probs = new Array( 145, 156, 163, 128); -var kf_uv_mode_probs = new Array( 142, 114, 183); -var kf_b_mode_probs = -new Array( - new Array( /* above mode 0 */ - new Array( /* left mode 0 */ 231, 120, 48, 89, 115, 113, 120, 152, 112), - new Array( /* left mode 1 */ 152, 179, 64, 126, 170, 118, 46, 70, 95), - new Array( /* left mode 2 */ 175, 69, 143, 80, 85, 82, 72, 155, 103), - new Array( /* left mode 3 */ 56, 58, 10, 171, 218, 189, 17, 13, 152), - new Array( /* left mode 4 */ 144, 71, 10, 38, 171, 213, 144, 34, 26), - new Array( /* left mode 5 */ 114, 26, 17, 163, 44, 195, 21, 10, 173), - new Array( /* left mode 6 */ 121, 24, 80, 195, 26, 62, 44, 64, 85), - new Array( /* left mode 7 */ 170, 46, 55, 19, 136, 160, 33, 206, 71), - new Array( /* left mode 8 */ 63, 20, 8, 114, 114, 208, 12, 9, 226), - new Array( /* left mode 9 */ 81, 40, 11, 96, 182, 84, 29, 16, 36) - ), - new Array( /* above mode 1 */ - new Array( /* left mode 0 */ 134, 183, 89, 137, 98, 101, 106, 165, 148), - new Array( /* left mode 1 */ 72, 187, 100, 130, 157, 111, 32, 75, 80), - new Array( /* left mode 2 */ 66, 102, 167, 99, 74, 62, 40, 234, 128), - new Array( /* left mode 3 */ 41, 53, 9, 178, 241, 141, 26, 8, 107), - new Array( /* left mode 4 */ 104, 79, 12, 27, 217, 255, 87, 17, 7), - new Array( /* left mode 5 */ 74, 43, 26, 146, 73, 166, 49, 23, 157), - new Array( /* left mode 6 */ 65, 38, 105, 160, 51, 52, 31, 115, 128), - new Array( /* left mode 7 */ 87, 68, 71, 44, 114, 51, 15, 186, 23), - new Array( /* left mode 8 */ 47, 41, 14, 110, 182, 183, 21, 17, 194), - new Array( /* left mode 9 */ 66, 45, 25, 102, 197, 189, 23, 18, 22) - ), - new Array( /* above mode 2 */ - new Array( /* left mode 0 */ 88, 88, 147, 150, 42, 46, 45, 196, 205), - new Array( /* left mode 1 */ 43, 97, 183, 117, 85, 38, 35, 179, 61), - new Array( /* left mode 2 */ 39, 53, 200, 87, 26, 21, 43, 232, 171), - new Array( /* left mode 3 */ 56, 34, 51, 104, 114, 102, 29, 93, 77), - new Array( /* left mode 4 */ 107, 54, 32, 26, 51, 1, 81, 43, 31), - new Array( /* left mode 5 */ 39, 28, 85, 171, 58, 165, 90, 98, 64), - new Array( /* left mode 6 */ 34, 22, 116, 206, 23, 34, 43, 166, 73), - new Array( /* left mode 7 */ 68, 25, 106, 22, 64, 171, 36, 225, 114), - new Array( /* left mode 8 */ 34, 19, 21, 102, 132, 188, 16, 76, 124), - new Array( /* left mode 9 */ 62, 18, 78, 95, 85, 57, 50, 48, 51) - ), - new Array( /* above mode 3 */ - new Array( /* left mode 0 */ 193, 101, 35, 159, 215, 111, 89, 46, 111), - new Array( /* left mode 1 */ 60, 148, 31, 172, 219, 228, 21, 18, 111), - new Array( /* left mode 2 */ 112, 113, 77, 85, 179, 255, 38, 120, 114), - new Array( /* left mode 3 */ 40, 42, 1, 196, 245, 209, 10, 25, 109), - new Array( /* left mode 4 */ 100, 80, 8, 43, 154, 1, 51, 26, 71), - new Array( /* left mode 5 */ 88, 43, 29, 140, 166, 213, 37, 43, 154), - new Array( /* left mode 6 */ 61, 63, 30, 155, 67, 45, 68, 1, 209), - new Array( /* left mode 7 */ 142, 78, 78, 16, 255, 128, 34, 197, 171), - new Array( /* left mode 8 */ 41, 40, 5, 102, 211, 183, 4, 1, 221), - new Array( /* left mode 9 */ 51, 50, 17, 168, 209, 192, 23, 25, 82) - ), - new Array( /* above mode 4 */ - new Array( /* left mode 0 */ 125, 98, 42, 88, 104, 85, 117, 175, 82), - new Array( /* left mode 1 */ 95, 84, 53, 89, 128, 100, 113, 101, 45), - new Array( /* left mode 2 */ 75, 79, 123, 47, 51, 128, 81, 171, 1), - new Array( /* left mode 3 */ 57, 17, 5, 71, 102, 57, 53, 41, 49), - new Array( /* left mode 4 */ 115, 21, 2, 10, 102, 255, 166, 23, 6), - new Array( /* left mode 5 */ 38, 33, 13, 121, 57, 73, 26, 1, 85), - new Array( /* left mode 6 */ 41, 10, 67, 138, 77, 110, 90, 47, 114), - new Array( /* left mode 7 */ 101, 29, 16, 10, 85, 128, 101, 196, 26), - new Array( /* left mode 8 */ 57, 18, 10, 102, 102, 213, 34, 20, 43), - new Array( /* left mode 9 */ 117, 20, 15, 36, 163, 128, 68, 1, 26) - ), - new Array( /* above mode 5 */ - new Array( /* left mode 0 */ 138, 31, 36, 171, 27, 166, 38, 44, 229), - new Array( /* left mode 1 */ 67, 87, 58, 169, 82, 115, 26, 59, 179), - new Array( /* left mode 2 */ 63, 59, 90, 180, 59, 166, 93, 73, 154), - new Array( /* left mode 3 */ 40, 40, 21, 116, 143, 209, 34, 39, 175), - new Array( /* left mode 4 */ 57, 46, 22, 24, 128, 1, 54, 17, 37), - new Array( /* left mode 5 */ 47, 15, 16, 183, 34, 223, 49, 45, 183), - new Array( /* left mode 6 */ 46, 17, 33, 183, 6, 98, 15, 32, 183), - new Array( /* left mode 7 */ 65, 32, 73, 115, 28, 128, 23, 128, 205), - new Array( /* left mode 8 */ 40, 3, 9, 115, 51, 192, 18, 6, 223), - new Array( /* left mode 9 */ 87, 37, 9, 115, 59, 77, 64, 21, 47) - ), - new Array( /* above mode 6 */ - new Array( /* left mode 0 */ 104, 55, 44, 218, 9, 54, 53, 130, 226), - new Array( /* left mode 1 */ 64, 90, 70, 205, 40, 41, 23, 26, 57), - new Array( /* left mode 2 */ 54, 57, 112, 184, 5, 41, 38, 166, 213), - new Array( /* left mode 3 */ 30, 34, 26, 133, 152, 116, 10, 32, 134), - new Array( /* left mode 4 */ 75, 32, 12, 51, 192, 255, 160, 43, 51), - new Array( /* left mode 5 */ 39, 19, 53, 221, 26, 114, 32, 73, 255), - new Array( /* left mode 6 */ 31, 9, 65, 234, 2, 15, 1, 118, 73), - new Array( /* left mode 7 */ 88, 31, 35, 67, 102, 85, 55, 186, 85), - new Array( /* left mode 8 */ 56, 21, 23, 111, 59, 205, 45, 37, 192), - new Array( /* left mode 9 */ 55, 38, 70, 124, 73, 102, 1, 34, 98) - ), - new Array( /* above mode 7 */ - new Array( /* left mode 0 */ 102, 61, 71, 37, 34, 53, 31, 243, 192), - new Array( /* left mode 1 */ 69, 60, 71, 38, 73, 119, 28, 222, 37), - new Array( /* left mode 2 */ 68, 45, 128, 34, 1, 47, 11, 245, 171), - new Array( /* left mode 3 */ 62, 17, 19, 70, 146, 85, 55, 62, 70), - new Array( /* left mode 4 */ 75, 15, 9, 9, 64, 255, 184, 119, 16), - new Array( /* left mode 5 */ 37, 43, 37, 154, 100, 163, 85, 160, 1), - new Array( /* left mode 6 */ 63, 9, 92, 136, 28, 64, 32, 201, 85), - new Array( /* left mode 7 */ 86, 6, 28, 5, 64, 255, 25, 248, 1), - new Array( /* left mode 8 */ 56, 8, 17, 132, 137, 255, 55, 116, 128), - new Array( /* left mode 9 */ 58, 15, 20, 82, 135, 57, 26, 121, 40) - ), - new Array( /* above mode 8 */ - new Array( /* left mode 0 */ 164, 50, 31, 137, 154, 133, 25, 35, 218), - new Array( /* left mode 1 */ 51, 103, 44, 131, 131, 123, 31, 6, 158), - new Array( /* left mode 2 */ 86, 40, 64, 135, 148, 224, 45, 183, 128), - new Array( /* left mode 3 */ 22, 26, 17, 131, 240, 154, 14, 1, 209), - new Array( /* left mode 4 */ 83, 12, 13, 54, 192, 255, 68, 47, 28), - new Array( /* left mode 5 */ 45, 16, 21, 91, 64, 222, 7, 1, 197), - new Array( /* left mode 6 */ 56, 21, 39, 155, 60, 138, 23, 102, 213), - new Array( /* left mode 7 */ 85, 26, 85, 85, 128, 128, 32, 146, 171), - new Array( /* left mode 8 */ 18, 11, 7, 63, 144, 171, 4, 4, 246), - new Array( /* left mode 9 */ 35, 27, 10, 146, 174, 171, 12, 26, 128) - ), - new Array( /* above mode 9 */ - new Array( /* left mode 0 */ 190, 80, 35, 99, 180, 80, 126, 54, 45), - new Array( /* left mode 1 */ 85, 126, 47, 87, 176, 51, 41, 20, 32), - new Array( /* left mode 2 */ 101, 75, 128, 139, 118, 146, 116, 128, 85), - new Array( /* left mode 3 */ 56, 41, 15, 176, 236, 85, 37, 9, 62), - new Array( /* left mode 4 */ 146, 36, 19, 30, 171, 255, 97, 27, 20), - new Array( /* left mode 5 */ 71, 30, 17, 119, 118, 255, 17, 18, 138), - new Array( /* left mode 6 */ 101, 38, 60, 138, 55, 70, 43, 26, 142), - new Array( /* left mode 7 */ 138, 45, 61, 62, 219, 1, 81, 188, 64), - new Array( /* left mode 8 */ 32, 41, 20, 117, 151, 142, 20, 21, 163), - new Array( /* left mode 9 */ 112, 19, 12, 61, 195, 128, 48, 4, 24) - ) -); -var kf_y_mode_tree = -new Array( - -B_PRED, 2, - 4, 6, - -DC_PRED, -V_PRED, - -H_PRED, -TM_PRED -); -var y_mode_tree = -new Array( - -DC_PRED, 2, - 4, 6, - -V_PRED, -H_PRED, - -TM_PRED, -B_PRED -); -var uv_mode_tree = -new Array( - -DC_PRED, 2, - -V_PRED, 4, - -H_PRED, -TM_PRED -); -var b_mode_tree = -new Array( - -B_DC_PRED, 2, /* 0 = DC_NODE */ - -B_TM_PRED, 4, /* 1 = TM_NODE */ - -B_VE_PRED, 6, /* 2 = VE_NODE */ - 8, 12, /* 3 = COM_NODE */ - -B_HE_PRED, 10, /* 4 = HE_NODE */ - -B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */ - -B_LD_PRED, 14, /* 6 = LD_NODE */ - -B_VL_PRED, 16, /* 7 = VL_NODE */ - -B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */ -); -var small_mv_tree = -new Array( - 2, 8, - 4, 6, - -0, -1, - -2, -3, - 10, 12, - -4, -5, - -6, -7 -); -var mv_ref_tree = -new Array( - -ZEROMV, 2, - -NEARESTMV, 4, - -NEARMV, 6, - -NEWMV, -SPLITMV -); -var submv_ref_tree = -new Array( - -LEFT4X4, 2, - -ABOVE4X4, 4, - -ZERO4X4, -NEW4X4 -); -var split_mv_tree = -new Array( - -3, 2, - -2, 4, - -0, -1 -); -var default_b_mode_probs = -new Array( 120, 90, 79, 133, 87, 85, 80, 111, 151); -var mv_counts_to_probs = -new Array( - new Array( 7, 1, 1, 143 ), - new Array( 14, 18, 14, 107 ), - new Array( 135, 64, 57, 68 ), - new Array( 60, 56, 128, 65 ), - new Array( 159, 134, 128, 34 ), - new Array( 234, 188, 128, 28 ) - -); -var split_mv_probs = -new Array( 110, 111, 150); -var submv_ref_probs2 = -new Array( - new Array( 147, 136, 18 ), - new Array( 106, 145, 1 ), - new Array( 179, 121, 1 ), - new Array( 223, 1, 34 ), - new Array( 208, 1, 1 ) -); - -var mv_partitions = -new Array( - new Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 ), - new Array(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 ), - new Array(0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 ), - new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ) -); - - -//16 -var mv_clamp_rect = function() -{ - this.to_left=int_, this.to_right=int_, this.to_top=int_, this.to_bottom=int_ -}; - - -//22 -function - clamp_mv(raw, bounds) -{ - var newmv=new mv(); - - - newmv.d.x = (raw.d.x < bounds.to_left) - ? bounds.to_left : raw.d.x; - newmv.d.x = (raw.d.x > bounds.to_right) - ? bounds.to_right : newmv.d.x; - newmv.d.y = (raw.d.y < bounds.to_top) - ? bounds.to_top : raw.d.y; - newmv.d.y = (raw.d.y > bounds.to_bottom) - ? bounds.to_bottom : newmv.d.y; - return newmv; -} - - -//39 -function -read_segment_id(bool, seg) -{ - return bool_get(bool, seg.tree_probs[0]) - ? 2 + bool_get(bool, seg.tree_probs[2]) - : bool_get(bool, seg.tree_probs[1]); -} - - -//48 -function -above_block_mode(this_,//* - above,//* - b) -{ - if (b < 4) - { - switch (above.base.y_mode) - { - case DC_PRED: - return B_DC_PRED; - case V_PRED: - return B_VE_PRED; - case H_PRED: - return B_HE_PRED; - case TM_PRED: - return B_TM_PRED; - case B_PRED: - return above.splitt.mvs[b+12].d.x; - default: - assert(0); - } - } - - return this_.splitt.mvs[b-4].d.x; -} - - -//76 -function -left_block_mode(this_,//* - left,//* - b) -{ - if (!(b & 3)) - { - switch (left.base.y_mode) - { - case DC_PRED: - return B_DC_PRED; - case V_PRED: - return B_VE_PRED; - case H_PRED: - return B_HE_PRED; - case TM_PRED: - return B_TM_PRED; - case B_PRED: - return left.splitt.mvs[b+3].d.x; - default: - assert(0); - } - } - - return this_.splitt.mvs[b-1].d.x; -} - - -//104 -function -decode_kf_mb_mode(this_, this_off,//* - left, left_off,//* - above, above_off,//* - bool)//* -{ - var y_mode=int_, uv_mode=int_; - - y_mode = bool_read_tree(bool, kf_y_mode_tree, kf_y_mode_probs); - - if (y_mode == B_PRED) - { - var i=int_; - - for (i = 0; i < 16; i++) - { - var a = above_block_mode(this_[this_off], above[above_off], i); - var l = left_block_mode(this_[this_off], left[left_off], i); - var b=0;//enum prediction_mode - - b = bool_read_tree(bool, b_mode_tree, - kf_b_mode_probs[a][l]); - this_[this_off].splitt.modes[i] = this_[this_off].splitt.mvs[i].d.x = b;this_[this_off].splitt.mvs[i].d.y = 0; - } - } - - uv_mode = bool_read_tree(bool, uv_mode_tree, kf_uv_mode_probs); - - this_[this_off].base.y_mode = y_mode; - this_[this_off].base.uv_mode = uv_mode; - this_[this_off].base.mv.d.x = this_[this_off].base.mv.d.y = 0;//raw = 0; - this_[this_off].base.ref_frame = 0; -} - - -//139 -function -decode_intra_mb_mode(this_, - hdr, - bool) -{ - /* Like decode_kf_mb_mode, but with probabilities transmitted in the - * bitstream and no context on the above/left block mode. - */ - var y_mode=int_, uv_mode=int_; - - y_mode = bool_read_tree(bool, y_mode_tree, hdr.y_mode_probs); - - if (y_mode == B_PRED) - { - var i=int_; - - for (i = 0; i < 16; i++) - { - var b;//enum ='prediction_mode' - - b = bool_read_tree(bool, b_mode_tree, default_b_mode_probs); - this_.splitt.modes[i] = this_.splitt.mvs[i].d.x = b;this_.splitt.mvs[i].d.y = 0; - } - } - - uv_mode = bool_read_tree(bool, uv_mode_tree, hdr.uv_mode_probs); - - this_.base.y_mode = y_mode; - this_.base.uv_mode = uv_mode; - this_.base.mv.d.x = this_.base.mv.d.y = 0;//.raw - this_.base.ref_frame = CURRENT_FRAME; -} - - -//173 -function -read_mv_component(bool, - mvc) -{ - var IS_SHORT=0, SIGN=1, SHORT=2, BITS = SHORT + 8 - 1, LONG_WIDTH = 10; - var x = 0; - - if (bool_get(bool, mvc[IS_SHORT])) /* Large */ - { - var i = 0; - - for (i = 0; i < 3; i++) - x += bool_get(bool, mvc[BITS + i]) << i; - - /* Skip bit 3, which is sometimes implicit */ - for (i = LONG_WIDTH - 1; i > 3; i--) - x += bool_get(bool, mvc[BITS + i]) << i; - - if (!(x & 0xFFF0) || bool_get(bool, mvc[BITS + 3])) - x += 8; - } - else /* small */ - x = bool_read_tree(bool, small_mv_tree, mvc, + SHORT);//todo - - if (x && bool_get(bool, mvc[SIGN])) - x = -x; - - return (x << 1); -} - - -//204 -function -above_block_mv(this_, - above_, - b) -{ - if (b < 4) - { - if (above_.base.y_mode == SPLITMV) - return above_.splitt.mvs[b+12]; - - return above_.base.mv; - } - - return this_.splitt.mvs[b-4]; -} - - -//221 -function -left_block_mv(this_, - left_, - b) -{ - if (!(b & 3)) - { - if (left_.base.y_mode == SPLITMV) - return left_.splitt.mvs[b+3]; - - return left_.base.mv; - } - - return this_.splitt.mvs[b-1]; -} - - -//238 -function -submv_ref(bool, l, a) -{ - var - SUBMVREF_NORMAL=0, - SUBMVREF_LEFT_ZED=1, - SUBMVREF_ABOVE_ZED=2, - SUBMVREF_LEFT_ABOVE_SAME=3, - SUBMVREF_LEFT_ABOVE_ZED=4 - ; - - var lez = !(l.d.x || l.d.y)+0;//.raw - var aez = !(a.d.x || a.d.y)+0;//.raw - var lea = (l.d.x == a.d.x && l.d.y == a.d.y)+0;//l.raw == a.raw - var ctx = SUBMVREF_NORMAL; - - if (lea && lez) - ctx = SUBMVREF_LEFT_ABOVE_ZED; - else if (lea) - ctx = SUBMVREF_LEFT_ABOVE_SAME; - else if (aez) - ctx = SUBMVREF_ABOVE_ZED; - else if (lez) - ctx = SUBMVREF_LEFT_ZED; - - return bool_read_tree(bool, submv_ref_tree, submv_ref_probs2[ctx]); -} - - -//268 -function -read_mv(bool, - mv, - mvc) -{ - mv.d.y = read_mv_component(bool, mvc[0]); - mv.d.x = read_mv_component(bool, mvc[1]); -} - - -//278 -function -mv_bias(mb, - sign_bias, - ref_frame, - mv) -{ - if (sign_bias[mb.base.ref_frame] ^ sign_bias[ref_frame]) - { - mv.d.x *= -1; - mv.d.y *= -1; - } -} - -//292 -var - CNT_BEST = 0, - CNT_ZEROZERO = 0, - CNT_NEAREST = 1, - CNT_NEAR = 2, - CNT_SPLITMV = 3 -; - -var this_mv_1=new mv();var this_mv_2=new mv(); -//302 -function -find_near_mvs(this_, - left, - left_off, - above, - above_off, - sign_bias, - near_mvs, - cnt) -{ - var aboveleft = above; var aboveleft_off = above_off - 1; - var mv_ = (near_mvs);var mv_off = 0; - var cntx = cnt; var cntx_off = 0; - - /* Zero accumulators */ - mv_[0].d.x = mv_[1].d.x = mv_[2].d.x = 0;//.raw - mv_[0].d.y = mv_[1].d.y = mv_[2].d.y = 0;//.raw - cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0; - - var above_ = above[above_off]; var left_ = left[left_off]; var aboveleft_ = aboveleft[aboveleft_off]; - /* Process above */ - if (above_.base.ref_frame != CURRENT_FRAME) - { - if (above_.base.mv.d.x || above_.base.mv.d.y)//.raw - { - mv_[(++mv_off)].d.x = above_.base.mv.d.x;//.raw - mv_[( mv_off)].d.y = above_.base.mv.d.y;//.raw - mv_bias(above_, sign_bias, this_.base.ref_frame, mv_[mv_off]); - ++cntx_off; - } - - cntx[cntx_off] += 2; - } - - /* Process left */ - if (left_.base.ref_frame != CURRENT_FRAME) - { - if (left_.base.mv.d.x || left_.base.mv.d.y)//.raw - { - var this_mv=this_mv_1; - - this_mv.d.x = left_.base.mv.d.x;//.raw - this_mv.d.y = left_.base.mv.d.y;//.raw - mv_bias(left_, sign_bias, this_.base.ref_frame, this_mv); - - if (this_mv.d.x != mv_[mv_off].d.x || this_mv.d.y != mv_[mv_off].d.y)//.raw!=->raw - { - mv_[(++mv_off)].d.x = this_mv.d.x;//->raw - mv_[( mv_off)].d.y = this_mv.d.y;//->raw - ++cntx_off; - } - - cntx[cntx_off] += 2; - } - else - cnt[CNT_ZEROZERO] += 2; - } - - /* Process above left */ - if (aboveleft_.base.ref_frame != CURRENT_FRAME) - { - if (aboveleft_.base.mv.d.x || aboveleft_.base.mv.d.y)//.raw - { - var this_mv=this_mv_2; - - this_mv.d.x = aboveleft_.base.mv.d.x;//.raw - this_mv.d.y = aboveleft_.base.mv.d.y;//.raw - mv_bias(aboveleft_, sign_bias, this_.base.ref_frame, - this_mv); - - if (this_mv.d.x != mv_[mv_off].d.x || this_mv.d.y != mv_[mv_off].d.y)//.raw - { - mv_[(++mv_off)].d.x = this_mv.d.x;//.raw - mv_[( mv_off)].d.y = this_mv.d.y;//.raw - ++cntx_off; - } - - cntx[cntx_off] += 1; - } - else - cnt[CNT_ZEROZERO] += 1; - } - - /* If we have three distinct MV's ... */ - if (cnt[CNT_SPLITMV]) - { - /* See if above-left MV can be merged with NEAREST */ - if (mv_[mv_off].d.x == near_mvs[CNT_NEAREST].d.x && mv_[mv_off].d.y == near_mvs[CNT_NEAREST].d.y)//.raw - cnt[CNT_NEAREST] += 1; - } - - cnt[CNT_SPLITMV] = ((above_.base.y_mode == SPLITMV) - + (left_.base.y_mode == SPLITMV)) * 2 - + (aboveleft_.base.y_mode == SPLITMV); - - /* Swap near and nearest if necessary */ - if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) - { - var tmp=int_;var tmp2=int_; - tmp = cnt[CNT_NEAREST]; - cnt[CNT_NEAREST] = cnt[CNT_NEAR]; - cnt[CNT_NEAR] = tmp; - tmp = near_mvs[CNT_NEAREST].d.x;//.raw; - tmp2 = near_mvs[CNT_NEAREST].d.y;//.raw; - near_mvs[CNT_NEAREST].d.x = near_mvs[CNT_NEAR].d.x; - near_mvs[CNT_NEAREST].d.y = near_mvs[CNT_NEAR].d.y; - near_mvs[CNT_NEAR].d.x = tmp; - near_mvs[CNT_NEAR].d.y = tmp2; - } - - /* Use near_mvs[CNT_BEST] to store the "best" MV. Note that this - * storage shares the same address as near_mvs[CNT_ZEROZERO]. - */ - if (cnt[CNT_NEAREST] >= cnt[CNT_BEST]) { - near_mvs[CNT_BEST].d.x = near_mvs[CNT_NEAREST].d.x; - near_mvs[CNT_BEST].d.y = near_mvs[CNT_NEAREST].d.y; - } -} - - -//408 -function -decode_split_mv(this_, - left_, - above_, - hdr, - best_mv, - bool) -{ - var partition=int_;//* - var j=int_, k=int_, mask=int_, partition_id=int_; - - partition_id = bool_read_tree(bool, split_mv_tree, split_mv_probs); - partition = mv_partitions[partition_id]; - this_.base.partitioning = partition_id; - - for (j = 0, mask = 0; mask < 65535; j++) - { - var mv_=new mv(), left_mv, above_mv;//='mv'='mv' - var subblock_mode;//='prediction_mode' - - /* Find the first subblock in this partition. */ - for (k = 0; j != partition[k]; k++); - - /* Decode the next MV */ - left_mv = left_block_mv(this_, left_, k); - above_mv = above_block_mv(this_, above_, k); - subblock_mode = submv_ref(bool, left_mv, above_mv); - - switch (subblock_mode) - { - case LEFT4X4: - mv_ = left_mv; - break; - case ABOVE4X4: - mv_ = above_mv; - break; - case ZERO4X4: - mv_.d.x = mv_.d.y = 0;//.raw - break; - case NEW4X4: - read_mv(bool, mv_, hdr.mv_probs); - mv_.d.x += best_mv.d.x; - mv_.d.y += best_mv.d.y; - break; - default: - assert(0); - } - - /* Fill the MV's for this partition */ - for (; k < 16; k++) - if (j == partition[k]) - { - this_.splitt.mvs[k].d.x = mv_.d.x; - this_.splitt.mvs[k].d.y = mv_.d.y; - mask |= 1 << k; - } - } -} - - -//467 -function -need_mc_border(mv, l, t, b_w, w, h) -{ - var b=int_, r=int_; - - /* Get distance to edge for top-left pixel */ - l += (mv.d.x >> 3); - t += (mv.d.y >> 3); - - /* Get distance to edge for bottom-right pixel */ - r = w - (l + b_w); - b = h - (t + b_w); - - return (l >> 1 < 2 || r >> 1 < 3 || t >> 1 < 2 || b >> 1 < 3); -} - -var near_mvs_4=Arr_new(4,mv),mv_cnts_4=new Array(0,0,0,0);//4 -var probs_4=new Array(0,0,0,0);//4 -var chroma_mv_4=Arr_new(4,mv); -var clamped_best_mv_1=new mv(); -//483 -function -decode_mvs(ctx, - this_, - this_off, - left, - left_off, - above, - above_off, - bounds, - bool) -{ - var hdr = ctx.entropy_hdr; - var near_mvs=near_mvs_4; - var clamped_best_mv=clamped_best_mv_1; - var mv_cnts=mv_cnts_4;//Arr(4,int_); - var probs=probs_4;//Arr(4,char_); - var BEST=0, NEAREST=1, NEAR=2; - var x=int_, y=int_, w=int_, h=int_, b=int_; - - this_[this_off].base.ref_frame = bool_get(bool, hdr.prob_last) - ? 2 + bool_get(bool, hdr.prob_gf) - : 1; - - find_near_mvs(this_[this_off], this_, this_off - 1, above, above_off, ctx.reference_hdr.sign_bias, - near_mvs, mv_cnts); - probs[0] = mv_counts_to_probs[mv_cnts[0]][0]; - probs[1] = mv_counts_to_probs[mv_cnts[1]][1]; - probs[2] = mv_counts_to_probs[mv_cnts[2]][2]; - probs[3] = mv_counts_to_probs[mv_cnts[3]][3]; - - this_=this_[this_off]; - - this_.base.y_mode = bool_read_tree(bool, mv_ref_tree, probs); - this_.base.uv_mode = this_.base.y_mode; - - this_.base.need_mc_border = 0; - x = (-bounds.to_left - 128) >> 3; - y = (-bounds.to_top - 128) >> 3; - w = ctx.mb_cols * 16; - h = ctx.mb_rows * 16; - - switch (this_.base.y_mode) - { - case NEARESTMV: - this_.base.mv = clamp_mv(near_mvs[NEAREST], bounds); - break; - case NEARMV: - this_.base.mv = clamp_mv(near_mvs[NEAR], bounds); - break; - case ZEROMV: - this_.base.mv.d.x = this_.base.mv.d.y = 0;//.raw - return; //skip need_mc_border check - case NEWMV: - clamped_best_mv = clamp_mv(near_mvs[BEST], bounds); - read_mv(bool, this_.base.mv, hdr.mv_probs);//&this->base.mv - this_.base.mv.d.x += clamped_best_mv.d.x; - this_.base.mv.d.y += clamped_best_mv.d.y; - break; - case SPLITMV: - { - var chroma_mv=chroma_mv_4;// = {{{0}}}; - - clamped_best_mv = clamp_mv(near_mvs[BEST], bounds); - decode_split_mv(this_, left[left_off], above[above_off], hdr, clamped_best_mv, bool);//&clamped_best_mv - this_.base.mv.d.x = this_.splitt.mvs[15].d.x;this_.base.mv.d.y = this_.splitt.mvs[15].d.y; - - for (b = 0; b < 16; b++) - { - chroma_mv[(b>>1&1) + (b>>2&2)].d.x += - this_.splitt.mvs[b].d.x; - chroma_mv[(b>>1&1) + (b>>2&2)].d.y += - this_.splitt.mvs[b].d.y; - - if (need_mc_border(this_.splitt.mvs[b], - x + (b & 3) * 4, y + (b & ~3), 4, w, h)) - { - this_.base.need_mc_border = 1; - break; - } - } - - for (b = 0; b < 4; b++) - { - chroma_mv[b].d.x += 4/* + 8 * (chroma_mv[b].d.x >> 31)*/; - chroma_mv[b].d.y += 4/* + 8 * (chroma_mv[b].d.y >> 31)*/; - chroma_mv[b].d.x >>= 2;//chroma_mv[b].d.x=parseInt(chroma_mv[b].d.x,10); - chroma_mv[b].d.y >>= 2;//chroma_mv[b].d.y=parseInt(chroma_mv[b].d.y,10); - - //note we're passing in non-subsampled coordinates - if (need_mc_border(chroma_mv[b], - x + (b & 1) * 8, y + (b >> 1) * 8, 16, w, h)) - { - this_.base.need_mc_border = 1; - break; - } - } - - return; //skip need_mc_border check - } - default: - assert(0); - } - - if (need_mc_border(this_.base.mv, x, y, 16, w, h)) - this_.base.need_mc_border = 1; -} - -var bounds_=new mv_clamp_rect(); -//586 -function -vp8_dixie_modemv_process_row(ctx, -bool, -row, -start_col, -num_cols) -{ - var above, above_off=0, this_, this_off=0;//*='(mb_info)'='(mb_info)' - var col=int_; - var bounds=bounds_; - - this_ = ctx.mb_info_rows[1+ row]; this_off = ctx.mb_info_rows_off[1+ row] + start_col; - above = ctx.mb_info_rows[1+ row - 1]; above_off = ctx.mb_info_rows_off[1+ row - 1] + start_col; - - /* Calculate the eighth-pel MV bounds using a 1 MB border. */ - bounds.to_left = -((start_col + 1) << 7); - bounds.to_right = (ctx.mb_cols - start_col) << 7; - bounds.to_top = -((row + 1) << 7); - bounds.to_bottom = (ctx.mb_rows - row) << 7; - - for (col = start_col; col < start_col + num_cols; col++) - { - if (ctx.segment_hdr.update_map) - this_[this_off].base.segment_id = read_segment_id(bool, - ctx.segment_hdr); - - if (ctx.entropy_hdr.coeff_skip_enabled) - this_[this_off].base.skip_coeff = bool_get(bool, - ctx.entropy_hdr.coeff_skip_prob); - - if (ctx.frame_hdr.is_keyframe) - { - if (!ctx.segment_hdr.update_map) - this_[this_off].base.segment_id = 0; - - decode_kf_mb_mode(this_, this_off, this_, this_off - 1, above, above_off, bool); - } - else - { - if (bool_get(bool, ctx.entropy_hdr.prob_inter)) - decode_mvs(ctx, this_, this_off, this_, this_off - 1, above, above_off, bounds, bool); - else - decode_intra_mb_mode(this_[this_off], ctx.entropy_hdr, bool); - - bounds.to_left -= 16 << 3; - bounds.to_right -= 16 << 3; - } - - /* Advance to next mb */ - this_off++; - above_off++; - } -} - - -//641 -function -vp8_dixie_modemv_init(ctx) -{ - var mbi_w=int_, mbi_h=int_, i=int_; - var mbi=new mb_info(); var mbi_off=0;//* - - mbi_w = ctx.mb_cols + 1; /* For left border col */ - mbi_h = ctx.mb_rows + 1; /* For above border row */ - - if (ctx.frame_hdr.frame_size_updated) - { - //free(ctx.mb_info_storage); - ctx.mb_info_storage = null; - //free(ctx.mb_info_rows_storage); - ctx.mb_info_rows_storage = null; - } - - if (!ctx.mb_info_storage) { - ctx.mb_info_storage = Arr_new(mbi_w * mbi_h,//calloc - ctx.mb_info_storage_object); - - ctx.mb_info_storage_off = 0; - }//todo: //sizeof(*ctx->mb_info_storage) - - if (!ctx.mb_info_rows_storage) { - ctx.mb_info_rows_storage = Arr_new(mbi_h,//calloc - ctx.mb_info_rows_storage_object); - - ctx.mb_info_rows_storage_off = new Array(mbi_h);//Arr(mbi_h,0); - }//sizeof(*ctx->mb_info_rows_storage) - - /* Set up row pointers */ - mbi = ctx.mb_info_storage; mbi_off = ctx.mb_info_storage_off + 1; - - for (i = 0; i < mbi_h; i++) - { - ctx.mb_info_rows_storage[i] = mbi; - ctx.mb_info_rows_storage_off[i] = mbi_off; - mbi_off += mbi_w; - } - - ctx.mb_info_rows = ctx.mb_info_rows_storage; ctx.mb_info_rows_off = ctx.mb_info_rows_storage_off;//todo: + 1; -} - - - - - -//18 -var - EOB_CONTEXT_NODE=0, - ZERO_CONTEXT_NODE=1, - ONE_CONTEXT_NODE=2, - LOW_VAL_CONTEXT_NODE=3, - TWO_CONTEXT_NODE=4, - THREE_CONTEXT_NODE=5, - HIGH_LOW_CONTEXT_NODE=6, - CAT_ONE_CONTEXT_NODE=7, - CAT_THREEFOUR_CONTEXT_NODE=8, - CAT_THREE_CONTEXT_NODE=9, - CAT_FIVE_CONTEXT_NODE=10 -; -//32 -var - ZERO_TOKEN=0, - ONE_TOKEN=1, - TWO_TOKEN=2, - THREE_TOKEN=3, - FOUR_TOKEN=4, - DCT_VAL_CATEGORY1=5, - DCT_VAL_CATEGORY2=6, - DCT_VAL_CATEGORY3=7, - DCT_VAL_CATEGORY4=8, - DCT_VAL_CATEGORY5=9, - DCT_VAL_CATEGORY6=10, - DCT_EOB_TOKEN=11, - MAX_ENTROPY_TOKENS=12 -; -//struct extrabits -//{ -// short min_val; -// short length; -// unsigned char probs[12]; -//}; -//54 -var left_context_index = -new Array( - 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, - 4, 4, 5, 5, 6, 6, 7, 7, 8 -); -//59 -var above_context_index = -new Array( - 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, - 4, 5, 4, 5, 6, 7, 6, 7, 8 -); -//64 -function X(n) { return ((n) * PREV_COEF_CONTEXTS * ENTROPY_NODES) } -var bands_x = -new Array( - X(0), X(1), X(2), X(3), X(6), X(4), X(5), X(6), - X(6), X(6), X(6), X(6), X(6), X(6), X(6), X(7) -); -var extrabits = -new Array( - { min_val:0, length:-1, probs:new Array( 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //ZERO_TOKEN - { min_val:1, length:0, probs:new Array( 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //ONE_TOKEN - { min_val:2, length:0, probs:new Array( 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //TWO_TOKEN - { min_val:3, length:0, probs:new Array( 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //THREE_TOKEN - { min_val:4, length:0, probs:new Array( 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //FOUR_TOKEN - { min_val:5, length:0, probs:new Array( 159, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //DCT_VAL_CATEGORY1 - { min_val:7, length:1, probs:new Array( 145, 165, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //DCT_VAL_CATEGORY2 - { min_val:11, length:2, probs:new Array( 140, 148, 173, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //DCT_VAL_CATEGORY3 - { min_val:19, length:3, probs:new Array( 135, 140, 155, 176, 0, 0, - 0, 0, 0, 0, 0, 0 ) }, //DCT_VAL_CATEGORY4 - { min_val:35, length:4, probs:new Array( 130, 134, 141, 157, 180, 0, - 0, 0, 0, 0, 0, 0 ) }, //DCT_VAL_CATEGORY5 - { min_val:67, length:10, probs:new Array( 129, 130, 133, 140, 153, 177, - 196, 230, 243, 254, 254, 0 ) }, //DCT_VAL_CATEGORY6 - { min_val:0, length:-1, probs:new Array( 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 ) } // EOB TOKEN -); -var zigzag = -new Array( - 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 -); - -var BLOCK_LOOP=0,DO_WHILE=1,CHECK_0_=2,CAT_FIVE_CONTEXT_NODE_0_=3,CAT_THREEFOUR_CONTEXT_NODE_0_=4,CAT_THREE_CONTEXT_NODE_0_=5,HIGH_LOW_CONTEXT_NODE_0_=6,CAT_ONE_CONTEXT_NODE_0_=7,LOW_VAL_CONTEXT_NODE_0_=8,THREE_CONTEXT_NODE_0_=9,TWO_CONTEXT_NODE_0_=10,ONE_CONTEXT_NODE_0_=11,BLOCK_FINISHED=12,END=13; -function -decode_mb_tokens(bool, - left, - above, - tokens, - tokens_off, - mode, - probs, - factor) -{ -//103 -function DECODE_AND_APPLYSIGN(value_to_sign) { - v = (bool_get_bit(bool) ? -value_to_sign - : value_to_sign) * dqf[(!!c)+0]; -} -function DECODE_AND_BRANCH_IF_ZERO(probability,branch) { - if (!bool_get(bool, probability)) { goto_ = branch; return 1; } -} -function DECODE_AND_LOOP_IF_ZERO(probability,branch) { - if (!bool_get(bool, probability)) - { - prob_off = type_probs_off; - if(c<15) { - ++c; - prob_off += bands_x[c]; - goto_ = branch; return 1; - } - else { - goto_ = BLOCK_FINISHED; return 1; /*for malformed input */ - } - } -} -function DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) { - DECODE_AND_APPLYSIGN(val); - prob_off = type_probs_off + (ENTROPY_NODES*2); - if(c < 15){ - b_tokens[b_tokens_off+ zigzag[c]] = v; - ++c; - goto_ = DO_WHILE; return 1; } - b_tokens[b_tokens_off+ zigzag[15]] = v; - goto_ = BLOCK_FINISHED; return 1; -} - -function DECODE_EXTRABIT_AND_ADJUST_VAL(t,bits_count) { - val += bool_get(bool, extrabits[t].probs[bits_count]) << bits_count; -} - -//138 - var i=int_, stopp=int_, type=int_; - var c=int_, t=int_, v=int_; - var val=int_, bits_count=int_; - var eob_mask=int_; - var b_tokens=short_;var b_tokens_off=0;//* /* tokens for this block */ - var type_probs=char_;var type_probs_off=0;//* /* probabilities for this block type */ - var prob=char_;var prob_off=0;//* - var dqf=short_;//* - - eob_mask = 0; - - if (mode != B_PRED && mode != SPLITMV) - { - i = 24; - stopp = 24; - type = 1; - b_tokens = tokens; b_tokens_off = tokens_off + 24 * 16; - dqf = factor[TOKEN_BLOCK_Y2]; - } - else - { - i = 0; - stopp = 16; - type = 3; - b_tokens = tokens; b_tokens_off = tokens_off; - dqf = factor[TOKEN_BLOCK_Y1]; - } - - /* Save a pointer to the coefficient probs for the current type. - * Need to repeat this whenever type changes. - */ - type_probs = probs; /*[type][0][0];*/ type_probs_off = type*COEF_BANDS*PREV_COEF_CONTEXTS*ENTROPY_NODES; - - var goto_=BLOCK_LOOP; -do { -if(goto_==BLOCK_LOOP) { - t = left[left_context_index[i]] + above[above_context_index[i]]; - c = (!type)+0; /* all blocks start at 0 except type 0, which starts - * at 1. */ - - prob = type_probs; prob_off = type_probs_off; - prob_off += t * ENTROPY_NODES; - - goto_=DO_WHILE; -} -if(goto_==DO_WHILE) { - prob_off += bands_x[c]; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ EOB_CONTEXT_NODE], BLOCK_FINISHED)) continue; - -goto_=CHECK_0_; -} -if(goto_==CHECK_0_) { - if(DECODE_AND_LOOP_IF_ZERO(prob[prob_off+ ZERO_CONTEXT_NODE], CHECK_0_)) continue; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ ONE_CONTEXT_NODE], - ONE_CONTEXT_NODE_0_)) continue; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ LOW_VAL_CONTEXT_NODE], - LOW_VAL_CONTEXT_NODE_0_)) continue; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ HIGH_LOW_CONTEXT_NODE], - HIGH_LOW_CONTEXT_NODE_0_)) continue; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ CAT_THREEFOUR_CONTEXT_NODE], - CAT_THREEFOUR_CONTEXT_NODE_0_)) continue; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ CAT_FIVE_CONTEXT_NODE], - CAT_FIVE_CONTEXT_NODE_0_)) continue; - val = extrabits[DCT_VAL_CATEGORY6].min_val; - bits_count = extrabits[DCT_VAL_CATEGORY6].length; - - do - { - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY6, bits_count); - bits_count -- ; - } - while (bits_count >= 0); - - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val)) continue; - -} -if(goto_==CAT_FIVE_CONTEXT_NODE_0_) { - val = extrabits[DCT_VAL_CATEGORY5].min_val; - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 4); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 3); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 2); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 1); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 0); - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val)) continue; - -} -if(goto_==CAT_THREEFOUR_CONTEXT_NODE_0_) { - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ CAT_THREE_CONTEXT_NODE], - CAT_THREE_CONTEXT_NODE_0_)) continue; - val = extrabits[DCT_VAL_CATEGORY4].min_val; - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 3); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 2); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 1); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 0); - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val)) continue; - -} -if(goto_==CAT_THREE_CONTEXT_NODE_0_) { - val = extrabits[DCT_VAL_CATEGORY3].min_val; - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 2); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 1); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 0); - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val)) continue; - -} -if(goto_==HIGH_LOW_CONTEXT_NODE_0_) { - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ CAT_ONE_CONTEXT_NODE], - CAT_ONE_CONTEXT_NODE_0_)) continue; - - val = extrabits[DCT_VAL_CATEGORY2].min_val; - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 1); - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 0); - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val)) continue; - -} -if(goto_==CAT_ONE_CONTEXT_NODE_0_) { - val = extrabits[DCT_VAL_CATEGORY1].min_val; - DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY1, 0); - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val)) continue; - -} -if(goto_==LOW_VAL_CONTEXT_NODE_0_) { - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ TWO_CONTEXT_NODE], - TWO_CONTEXT_NODE_0_)) continue; - if(DECODE_AND_BRANCH_IF_ZERO(prob[prob_off+ THREE_CONTEXT_NODE], - THREE_CONTEXT_NODE_0_)) continue; - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(4)) continue; - -} -if(goto_==THREE_CONTEXT_NODE_0_) { - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(3)) continue; - -} -if(goto_==TWO_CONTEXT_NODE_0_) { - if(DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(2)) continue; - -} -if(goto_==ONE_CONTEXT_NODE_0_) { - DECODE_AND_APPLYSIGN(1); - prob_off = type_probs_off + ENTROPY_NODES; - - if (c < 15) - { - b_tokens[b_tokens_off+ zigzag[c]] = v; - ++c; - goto_ = DO_WHILE; continue; - } - - b_tokens[b_tokens_off+ zigzag[15]] = v; -goto_=BLOCK_FINISHED; -} -if(goto_==BLOCK_FINISHED) { - eob_mask = (eob_mask | ((c > 1)+0 << i))>>>0; - t = (c != !type)+0; // any nonzero data? - eob_mask = (eob_mask | (t << 31))>>>0;//intBitLeft(t , 31); - - left[left_context_index[i]] = above[above_context_index[i]] = t; - b_tokens_off += 16; - - i++; - - if (i < stopp) { - goto_ = BLOCK_LOOP; continue;} - - if (i == 25) - { - type = 0; - i = 0; - stopp = 16; - type_probs_off = type*COEF_BANDS*PREV_COEF_CONTEXTS*ENTROPY_NODES;//type_probs = probs[type][0][0]; - b_tokens_off = tokens_off; - dqf = factor[TOKEN_BLOCK_Y1]; - goto_ = BLOCK_LOOP; continue; - } - - if (i == 16) - { - type = 2; - type_probs_off = type*COEF_BANDS*PREV_COEF_CONTEXTS*ENTROPY_NODES;//type_probs = probs[type][0][0]; - stopp = 24; - dqf = factor[TOKEN_BLOCK_UV]; - goto_ = BLOCK_LOOP; continue; - } -} -goto_ = END; -} while(goto_!=END); - - return eob_mask; -} - - -//318 -function -reset_row_context(left) -{ - memset(left, 0, 0, left.length/**sizeof(left)*/); -} - - -//325 -function -reset_above_context(above, cols) -{ - var col=0; - for(col=0;col= 0 ? (x) : -(x)) } - -//25 -function -saturate_int8(x) -{ - if (x < -128) - return -128; - - if (x > 127) - return 127; - - return x; -} - -//38 -function -saturate_uint8(x) -{ - if (x < 0) - return 0; - - if (x > 255) - return 255; - - return x; -} - - -//51 -function -high_edge_variance(pixels, - pixels_off, - stride, - hev_threshold) -{ -//var p3 = pixels[pixels_off -4*stride]; -//var p2 = pixels[pixels_off -3*stride]; -var p1 = pixels[pixels_off -2*stride]; -var p0 = pixels[pixels_off -1*stride]; -var q0 = pixels[pixels_off+ 0*stride]; -var q1 = pixels[pixels_off+ 1*stride]; -//var q2 = pixels[pixels_off+ 2*stride]; -//var q3 = pixels[pixels_off+ 3*stride]; - - return ABS(p1 - p0) > hev_threshold || ABS(q1 - q0) > hev_threshold; -} - - -//60 -function -simple_threshold(pixels, - pixels_off, - stride, - filter_limit) -{ -//var p3 = pixels[pixels_off -4*stride]; -//var p2 = pixels[pixels_off -3*stride]; -var p1 = pixels[pixels_off -2*stride]; -var p0 = pixels[pixels_off -1*stride]; -var q0 = pixels[pixels_off+ 0*stride]; -var q1 = pixels[pixels_off+ 1*stride]; -//var q2 = pixels[pixels_off+ 2*stride]; -//var q3 = pixels[pixels_off+ 3*stride]; - - return (ABS(p0 - q0) * 2 + (ABS(p1 - q1) >> 1)) <= filter_limit; -} - - -//69 -function -normal_threshold(pixels, - pixels_off, - stride, - edge_limit, - interior_limit) -{ -var p3 = pixels[pixels_off -4*stride]; -var p2 = pixels[pixels_off -3*stride]; -var p1 = pixels[pixels_off -2*stride]; -var p0 = pixels[pixels_off -1*stride]; -var q0 = pixels[pixels_off+ 0*stride]; -var q1 = pixels[pixels_off+ 1*stride]; -var q2 = pixels[pixels_off+ 2*stride]; -var q3 = pixels[pixels_off+ 3*stride]; - - var E = edge_limit; - var I = interior_limit; - - return simple_threshold(pixels, pixels_off, stride, 2 * E + I) - && ABS(p3 - p2) <= I && ABS(p2 - p1) <= I - && ABS(p1 - p0) <= I && ABS(q3 - q2) <= I - && ABS(q2 - q1) <= I && ABS(q1 - q0) <= I; -} - - -//85 -function -filter_common(pixels, - pixels_off, - stride, - use_outer_taps) -{ -//var p3 = pixels[pixels_off -4*stride]; -//var p2 = pixels[pixels_off -3*stride]; -var p1 = pixels[pixels_off -2*stride]; -var p0 = pixels[pixels_off -1*stride]; -var q0 = pixels[pixels_off+ 0*stride]; -var q1 = pixels[pixels_off+ 1*stride]; -//var q2 = pixels[pixels_off+ 2*stride]; -//var q3 = pixels[pixels_off+ 3*stride]; - var a=int_, f1=int_, f2=int_; - - a = 3 * (q0 - p0); - - if (use_outer_taps) - a += saturate_int8(p1 - q1); - - a = saturate_int8(a); - - f1 = ((a + 4 > 127) ? 127 : a + 4) >> 3; - f2 = ((a + 3 > 127) ? 127 : a + 3) >> 3; - - p0 = saturate_uint8(p0 + f2); - q0 = saturate_uint8(q0 - f1); - - if (!use_outer_taps) - { - /* This handles the case of subblock_filter() - * (from the bitstream guide. - */ - a = (f1 + 1) >> 1; - p1 = saturate_uint8(p1 + a); - q1 = saturate_uint8(q1 - a); - } -//pixels[pixels_off -4*stride] = p3; -//pixels[pixels_off -3*stride] = p2; -pixels[pixels_off -2*stride] = p1; -pixels[pixels_off -1*stride] = p0; -pixels[pixels_off+ 0*stride] = q0; -pixels[pixels_off+ 1*stride] = q1; -//pixels[pixels_off+ 2*stride] = q2; -//pixels[pixels_off+ 3*stride] = q3; -} - -//117 -function -filter_mb_edge(pixels, - pixels_off, - stride) -{ -//var p3 = pixels[pixels_off -4*stride]; -var p2 = pixels[pixels_off -3*stride]; -var p1 = pixels[pixels_off -2*stride]; -var p0 = pixels[pixels_off -1*stride]; -var q0 = pixels[pixels_off+ 0*stride]; -var q1 = pixels[pixels_off+ 1*stride]; -var q2 = pixels[pixels_off+ 2*stride]; -//var q3 = pixels[pixels_off+ 3*stride]; - var w=int_, a=int_; - - w = saturate_int8(saturate_int8(p1 - q1) + 3 * (q0 - p0)); - - a = (27 * w + 63) >> 7; - p0 = saturate_uint8(p0 + a); - q0 = saturate_uint8(q0 - a); - - a = (18 * w + 63) >> 7; - p1 = saturate_uint8(p1 + a); - q1 = saturate_uint8(q1 - a); - - a = (9 * w + 63) >> 7; - p2 = saturate_uint8(p2 + a); - q2 = saturate_uint8(q2 - a); - -//pixels[pixels_off -4*stride] = p3; -pixels[pixels_off -3*stride] = p2; -pixels[pixels_off -2*stride] = p1; -pixels[pixels_off -1*stride] = p0; -pixels[pixels_off+ 0*stride] = q0; -pixels[pixels_off+ 1*stride] = q1; -pixels[pixels_off+ 2*stride] = q2; -//pixels[pixels_off+ 3*stride] = q3; -} - - -//140 -function -filter_mb_v_edge(src, - src_off, - stride, - edge_limit, - interior_limit, - hev_threshold, - size) -{ - var i=int_; - - for (i = 0; i < 8 * size; i++) - { - if (normal_threshold(src, src_off, 1, edge_limit, interior_limit)) - { - if (high_edge_variance(src, src_off, 1, hev_threshold)) - filter_common(src, src_off, 1, 1); - else - filter_mb_edge(src, src_off, 1); - } - - src_off += stride; - } -} - - -//165 -function -filter_subblock_v_edge(src, - src_off, - stride, - edge_limit, - interior_limit, - hev_threshold, - size) -{ - var i=int_; - - for (i = 0; i < 8 * size; i++) - { - if (normal_threshold(src, src_off, 1, edge_limit, interior_limit)) - filter_common(src, src_off, 1, - high_edge_variance(src, src_off, 1, hev_threshold)); - - src_off += stride; - } -} - - -//186 -function -filter_mb_h_edge(src, - src_off, - stride, - edge_limit, - interior_limit, - hev_threshold, - size) -{ - var i=int_; - - for (i = 0; i < 8 * size; i++) - { - if (normal_threshold(src, src_off, stride, edge_limit, interior_limit)) - { - if (high_edge_variance(src, src_off, stride, hev_threshold)) - filter_common(src, src_off, stride, 1); - else - filter_mb_edge(src, src_off, stride); - } - - src_off += 1; - } -} - - -//211 -function -filter_subblock_h_edge(src, - src_off, - stride, - edge_limit, - interior_limit, - hev_threshold, - size) -{ - var i=int_; - - for (i = 0; i < 8 * size; i++) - { - if (normal_threshold(src, src_off, stride, edge_limit, interior_limit)) - filter_common(src, src_off, stride, - high_edge_variance(src, src_off, stride, - hev_threshold)); - - src_off += 1; - } -} - - -//233 -function -filter_v_edge_simple(src, - src_off, - stride, - filter_limit) -{ - var i=int_; - - for (i = 0; i < 16; i++) - { - if (simple_threshold(src, src_off, 1, filter_limit)) - filter_common(src, src_off, 1, 1); - - src_off += stride; - } -} - - -//250 -function -filter_h_edge_simple(src, - src_off, - stride, - filter_limit) -{ - var i=int_; - - for (i = 0; i < 16; i++) - { - if (simple_threshold(src, src_off, stride, filter_limit)) - filter_common(src, src_off, stride, 1); - - src_off += 1; - } -} - - -//267 -function -calculate_filter_parameters(ctx, - mbi, - edge_limit_, - interior_limit_, - hev_threshold_) -{ - var filter_level=int_, interior_limit=int_, hev_threshold=int_; - - /* Reference code/spec seems to conflate filter_level and - * edge_limit - */ - - filter_level = ctx.loopfilter_hdr.level; - - if (ctx.segment_hdr.enabled) - { - if (!ctx.segment_hdr.abs_) - filter_level += - ctx.segment_hdr.lf_level[mbi.base.segment_id]; - else - filter_level = - ctx.segment_hdr.lf_level[mbi.base.segment_id]; - } - - if (ctx.loopfilter_hdr.delta_enabled) - { - filter_level += - ctx.loopfilter_hdr.ref_delta[mbi.base.ref_frame]; - - if (mbi.base.ref_frame == CURRENT_FRAME) - { - if (mbi.base.y_mode == B_PRED) - filter_level += ctx.loopfilter_hdr.mode_delta[0]; - } - else if (mbi.base.y_mode == ZEROMV) - filter_level += ctx.loopfilter_hdr.mode_delta[1]; - else if (mbi.base.y_mode == SPLITMV) - filter_level += ctx.loopfilter_hdr.mode_delta[3]; - else - filter_level += ctx.loopfilter_hdr.mode_delta[2]; - } - - if (filter_level > 63) - filter_level = 63; - else if (filter_level < 0) - filter_level = 0; - - interior_limit = filter_level; - - if (ctx.loopfilter_hdr.sharpness) - { - interior_limit >>= ctx.loopfilter_hdr.sharpness > 4 ? 2 : 1; - - if (interior_limit > 9 - ctx.loopfilter_hdr.sharpness) - interior_limit = 9 - ctx.loopfilter_hdr.sharpness; - } - - if (interior_limit < 1) - interior_limit = 1; - - hev_threshold = (filter_level >= 15); - - if (filter_level >= 40) - hev_threshold++; - - if (filter_level >= 20 && !ctx.frame_hdr.is_keyframe) - hev_threshold++; - - edge_limit_[0] = filter_level; - interior_limit_[0] = interior_limit; - hev_threshold_[0] = hev_threshold; -} - - -//342 -function -filter_row_normal(ctx, - row, - start_col, - num_cols) -{ - var y=char_, u=char_, v=char_; - var y_off=0, u_off=0, v_off=0; - var stride=int_, uv_stride=int_; - var mbi; var mbi_off=0;//='mb_info' - var col=int_; - - /* Adjust pointers based on row, start_col */ - stride = ctx.ref_frames[CURRENT_FRAME].img.stride[PLANE_Y]; - uv_stride = ctx.ref_frames[CURRENT_FRAME].img.stride[PLANE_U]; - y = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_Y]; - y_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_Y]; - u = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_U]; - u_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_U]; - v = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_V]; - v_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_V]; - y_off += (stride * row + start_col) * 16; - u_off += (uv_stride * row + start_col) * 8; - v_off += (uv_stride * row + start_col) * 8; - mbi = ctx.mb_info_rows[1+ row]; mbi_off = ctx.mb_info_rows_off[1+ row] + start_col; - - for (col = start_col; col < start_col + num_cols; col++) - { - var edge_limit=[int_], interior_limit=[int_], hev_threshold=[int_]; - - /* TODO: only need to recalculate every MB if segmentation is - * enabled. - */ - calculate_filter_parameters(ctx, mbi[mbi_off], edge_limit, - interior_limit, hev_threshold); - edge_limit=edge_limit[0], interior_limit=interior_limit[0], hev_threshold=hev_threshold[0]; - - if (edge_limit) - { - if (col) - { - filter_mb_v_edge(y, y_off, stride, edge_limit + 2, - interior_limit, hev_threshold, 2); - filter_mb_v_edge(u, u_off, uv_stride, edge_limit + 2, - interior_limit, hev_threshold, 1); - filter_mb_v_edge(v, v_off, uv_stride, edge_limit + 2, - interior_limit, hev_threshold, 1); - } - - /* NOTE: This conditional is actually dependent on the - * number of coefficients decoded, not the skip flag as - * coded in the bitstream. The tokens task is expected to - * set 31 if there is *any* non-zero data. - */ - if (mbi[mbi_off].base.eob_mask - || mbi[mbi_off].base.y_mode == SPLITMV - || mbi[mbi_off].base.y_mode == B_PRED) - { - filter_subblock_v_edge(y, y_off + 4, stride, edge_limit, - interior_limit, hev_threshold, - 2); - filter_subblock_v_edge(y, y_off + 8, stride, edge_limit, - interior_limit, hev_threshold, - 2); - filter_subblock_v_edge(y, y_off + 12, stride, edge_limit, - interior_limit, hev_threshold, - 2); - filter_subblock_v_edge(u, y_off + 4, uv_stride, edge_limit, - interior_limit, hev_threshold, - 1); - filter_subblock_v_edge(v, y_off + 4, uv_stride, edge_limit, - interior_limit, hev_threshold, - 1); - } - - if (row) - { - filter_mb_h_edge(y, y_off, stride, edge_limit + 2, - interior_limit, hev_threshold, 2); - filter_mb_h_edge(u, u_off, uv_stride, edge_limit + 2, - interior_limit, hev_threshold, 1); - filter_mb_h_edge(v, v_off, uv_stride, edge_limit + 2, - interior_limit, hev_threshold, 1); - } - - if (mbi[mbi_off].base.eob_mask - || mbi[mbi_off].base.y_mode == SPLITMV - || mbi[mbi_off].base.y_mode == B_PRED) - { - filter_subblock_h_edge(y, y_off + 4 * stride, stride, - edge_limit, interior_limit, - hev_threshold, 2); - filter_subblock_h_edge(y, y_off + 8 * stride, stride, - edge_limit, interior_limit, - hev_threshold, 2); - filter_subblock_h_edge(y, y_off + 12 * stride, stride, - edge_limit, interior_limit, - hev_threshold, 2); - filter_subblock_h_edge(u, u_off + 4 * uv_stride, uv_stride, - edge_limit, interior_limit, - hev_threshold, 1); - filter_subblock_h_edge(v, v_off + 4 * uv_stride, uv_stride, - edge_limit, interior_limit, - hev_threshold, 1); - } - } - - y_off += 16; - u_off += 8; - v_off += 8; - mbi_off++; - } -} - - -//452 -function -filter_row_simple(ctx, - row, - start_col, - num_cols) -{ - var y=char_; var y_off=0; - var stride=int_; - var mbi; var mbi_off=0;//='mb_info' - var col=int_; - - /* Adjust pointers based on row, start_col */ - stride = ctx.ref_frames[CURRENT_FRAME].img.stride[PLANE_Y]; - y = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_Y]; - y_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_Y]; - y_off += (stride * row + start_col) * 16; - - mbi = ctx.mb_info_rows[1+row]; mbi_off = ctx.mb_info_rows_off[1+row] + start_col; - - for (col = start_col; col < start_col + num_cols; col++) - { - var edge_limit=[int_], interior_limit=[int_], hev_threshold=[int_]; - - /* TODO: only need to recalculate every MB if segmentation is - * enabled. - */ - calculate_filter_parameters(ctx, mbi[mbi_off], edge_limit, - interior_limit, hev_threshold); - - if (edge_limit[0]) - { - - /* NOTE: This conditional is actually dependent on the - * number of coefficients decoded, not the skip flag as - * coded in the bitstream. The tokens task is expected to - * set 31 if there is *any* non-zero data. - */ - var filter_subblocks = (mbi[mbi_off].base.eob_mask - || mbi[mbi_off].base.y_mode == SPLITMV - || mbi[mbi_off].base.y_mode == B_PRED)+0; - var mb_limit = (edge_limit[0] + 2) * 2 + interior_limit[0]; - var b_limit = edge_limit[0] * 2 + interior_limit[0]; - - if (col) - filter_v_edge_simple(y, y_off, stride, mb_limit); - - if (filter_subblocks) - { - filter_v_edge_simple(y, y_off + 4, stride, b_limit); - filter_v_edge_simple(y, y_off + 8, stride, b_limit); - filter_v_edge_simple(y, y_off + 12, stride, b_limit); - } - - if (row) - filter_h_edge_simple(y, y_off, stride, mb_limit); - - if (filter_subblocks) - { - filter_h_edge_simple(y, y_off + 4 * stride, stride, b_limit); - filter_h_edge_simple(y, y_off + 8 * stride, stride, b_limit); - filter_h_edge_simple(y, y_off + 12 * stride, stride, b_limit); - } - } - - y_off += 16; - mbi_off++; - } -} - - -//520 -function -vp8_dixie_loopfilter_process_row(ctx, - row, - start_col, - num_cols) -{ - if (ctx.loopfilter_hdr.use_simple) - filter_row_simple(ctx, row, start_col, num_cols); - else - filter_row_normal(ctx, row, start_col, num_cols); -} - - -var - BORDER_PIXELS = 16 -; - - -var sixtap_filters =//[8] -new Array( - - new Array( 0, 0, 128, 0, 0, 0 ), - new Array( 0, -6, 123, 12, -1, 0 ), - new Array( 2, -11, 108, 36, -8, 1 ), - new Array( 0, -9, 93, 50, -6, 0 ), - new Array( 3, -16, 77, 77, -16, 3 ), - new Array( 0, -6, 50, 93, -9, 0 ), - new Array( 1, -8, 36, 108, -11, 2 ), - new Array( 0, -1, 12, 123, -6, 0 ) -); - - -var bilinear_filters =//filter_t [8] -new Array( - - new Array( 0, 0, 128, 0, 0, 0 ), - new Array( 0, 0, 112, 16, 0, 0 ), - new Array( 0, 0, 96, 32, 0, 0 ), - new Array( 0, 0, 80, 48, 0, 0 ), - new Array( 0, 0, 64, 64, 0, 0 ), - new Array( 0, 0, 48, 80, 0, 0 ), - new Array( 0, 0, 32, 96, 0, 0 ), - new Array( 0, 0, 16, 112, 0, 0 ) -); - -//51 -function -predict_h_nxn(predict, - predict_off, - stride, - n) -{ - var left = predict; var left_off = predict_off - 1; - var i=int_, j=int_; - - for (i = 0; i < n; i++) - for (j = 0; j < n; j++) - predict[predict_off+ i *stride + j] = left[left_off+ i * stride]; -} - - -//65 -function -predict_v_nxn(predict, - predict_off, - stride, - n) -{ - var above = predict; var above_off = predict_off - stride; - var i=int_, j=int_; - - for (i = 0; i < n; i++) - for (j = 0; j < n; j++) - predict[predict_off+ i *stride + j] = above[above_off+ j]; -} - - -//79 -function -predict_tm_nxn(predict, - predict_off, - stride, - n) -{ - /* Transposes the left column to the top row for later consumption - * by the idct/recon stage - */ - var left = predict; var left_off = predict_off - 1; - var above = predict; var above_off = predict_off - stride; - var p = above[above_off -1]; - var i=int_, j=int_; - - for (j = 0; j < n; j++) - { - for (i = 0; i < n; i++) - predict[predict_off+ i] = CLAMP_255(left[left_off] + above[above_off+i] - p);//*left - - predict_off += stride; - left_off += stride; - } -} - -//102 -function -predict_dc_nxn(predict, - predict_off, - stride, - n) -{ - var left = predict; var left_off = predict_off - 1; - var above = predict; var above_off = predict_off - stride; - var i=int_, j=int_; var dc = 0; - - for (i = 0; i < n; i++) - { - dc += left[left_off] + above[above_off+ i];//*left - left_off += stride; - } - - switch (n) - { - case 16: - dc = (dc + 16) >> 5; - break; - case 8: - dc = (dc + 8) >> 4; - break; - case 4: - dc = (dc + 4) >> 3; - break; - } - - for (i = 0; i < n; i++) - for (j = 0; j < n; j++) - predict[predict_off+ i *stride + j] = dc; -} - - -//136 -function -predict_ve_4x4(predict, - predict_off, - stride) -{ - var above = predict; var above_off = predict_off - stride; - var i=int_, j=int_; - - predict[predict_off+ 0] = (above[above_off -1] + 2 * above[above_off+ 0] + above[above_off+ 1] + 2) >> 2; - predict[predict_off+ 1] = (above[above_off+ 0] + 2 * above[above_off+ 1] + above[above_off+ 2] + 2) >> 2; - predict[predict_off+ 2] = (above[above_off+ 1] + 2 * above[above_off+ 2] + above[above_off+ 3] + 2) >> 2; - predict[predict_off+ 3] = (above[above_off+ 2] + 2 * above[above_off+ 3] + above[above_off+ 4] + 2) >> 2; - - for (i = 1; i < 4; i++) - for (j = 0; j < 4; j++) - predict[predict_off+ i *stride + j] = predict[predict_off+ j]; -} - - -//154 -function -predict_he_4x4(predict, - predict_off, - stride) -{ - var left = predict; var left_off = predict_off - 1; - - predict[predict_off+ 0] = - predict[predict_off+ 1] = - predict[predict_off+ 2] = - predict[predict_off+ 3] = (left[left_off -stride] + 2 * left[left_off+ 0] + left[left_off+ stride] + 2) >> 2; - predict_off += stride; - left_off += stride; - - predict[predict_off+ 0] = - predict[predict_off+ 1] = - predict[predict_off+ 2] = - predict[predict_off+ 3] = (left[left_off -stride] + 2 * left[left_off+ 0] + left[left_off+ stride] + 2) >> 2; - predict_off += stride; - left_off += stride; - - predict[predict_off+ 0] = - predict[predict_off+ 1] = - predict[predict_off+ 2] = - predict[predict_off+ 3] = (left[left_off -stride] + 2 * left[left_off+ 0] + left[left_off+ stride] + 2) >> 2; - predict_off += stride; - left_off += stride; - - predict[predict_off+ 0] = - predict[predict_off+ 1] = - predict[predict_off+ 2] = - predict[predict_off+ 3] = (left[left_off -stride] + 2 * left[left_off+ 0] + left[left_off+ 0] + 2) >> 2; -} - - -//188 -function -predict_ld_4x4(predict, - predict_off, - stride) -{ - var above = predict; var above_off = predict_off - stride; - var pred0=int_, pred1=int_, pred2=int_, pred3=int_, pred4=int_, pred5=int_, pred6=int_; - - predict[predict_off+ 0] = pred0 = (above[above_off+ 0] + 2 * above[above_off+ 1] + above[above_off+ 2] + 2) >> 2; - predict[predict_off+ 1] = pred1 = (above[above_off+ 1] + 2 * above[above_off+ 2] + above[above_off+ 3] + 2) >> 2; - predict[predict_off+ 2] = pred2 = (above[above_off+ 2] + 2 * above[above_off+ 3] + above[above_off+ 4] + 2) >> 2; - predict[predict_off+ 3] = pred3 = (above[above_off+ 3] + 2 * above[above_off+ 4] + above[above_off+ 5] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred1; - predict[predict_off+ 1] = pred2; - predict[predict_off+ 2] = pred3; - predict[predict_off+ 3] = pred4 = (above[above_off+ 4] + 2 * above[above_off+ 5] + above[above_off+ 6] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred2; - predict[predict_off+ 1] = pred3; - predict[predict_off+ 2] = pred4; - predict[predict_off+ 3] = pred5 = (above[above_off+ 5] + 2 * above[above_off+ 6] + above[above_off+ 7] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred3; - predict[predict_off+ 1] = pred4; - predict[predict_off+ 2] = pred5; - predict[predict_off+ 3] = pred6 = (above[above_off+ 6] + 2 * above[above_off+ 7] + above[above_off+ 7] + 2) >> 2; -} - - -//220 -function -predict_rd_4x4(predict, - predict_off, - stride) -{ - var left = predict; var left_off = predict_off - 1; - var above = predict; var above_off = predict_off - stride; - var pred0=int_, pred1=int_, pred2=int_, pred3=int_, pred4=int_, pred5=int_, pred6=int_; - - predict[predict_off+ 0] = pred0 = - (left[left_off+ 0] + 2 * above[above_off -1] + above[above_off+ 0] + 2) >> 2; - predict[predict_off+ 1] = pred1 = - (above[above_off -1] + 2 * above[above_off+ 0] + above[above_off+ 1] + 2) >> 2; - predict[predict_off+ 2] = pred2 = - (above[above_off+ 0] + 2 * above[above_off+ 1] + above[above_off+ 2] + 2) >> 2; - predict[predict_off+ 3] = pred3 = - (above[above_off+ 1] + 2 * above[above_off+ 2] + above[above_off+ 3] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred4 = - (left[left_off+ stride] + 2 * left[left_off+ 0] + above[above_off -1] + 2) >> 2; - predict[predict_off+ 1] = pred0; - predict[predict_off+ 2] = pred1; - predict[predict_off+ 3] = pred2; - predict_off += stride; - - predict[predict_off+ 0] = pred5 = - (left[left_off+ stride*2] + 2 * left[left_off+ stride] + left[left_off+ 0] + 2) >> 2; - predict[predict_off+ 1] = pred4; - predict[predict_off+ 2] = pred0; - predict[predict_off+ 3] = pred1; - predict_off += stride; - - predict[predict_off+ 0] = pred6 = - (left[left_off+ stride*3] + 2 * left[left_off+ stride*2] + left[left_off+ stride] + 2) >> 2; - predict[predict_off+ 1] = pred5; - predict[predict_off+ 2] = pred4; - predict[predict_off+ 3] = pred0; -} - - -//260 -function -predict_vr_4x4(predict, - predict_off, - stride) -{ - var left = predict; var left_off = predict_off - 1; - var above = predict; var above_off = predict_off - stride; - var pred0=int_, pred1=int_, pred2=int_, pred3=int_, pred4=int_, pred5=int_, pred6=int_, - pred7=int_, pred8=int_, pred9=int_; - - predict[predict_off+ 0] = pred0 = (above[above_off -1] + above[above_off+ 0] + 1) >> 1; - predict[predict_off+ 1] = pred1 = (above[above_off+ 0] + above[above_off+ 1] + 1) >> 1; - predict[predict_off+ 2] = pred2 = (above[above_off+ 1] + above[above_off+ 2] + 1) >> 1; - predict[predict_off+ 3] = pred3 = (above[above_off+ 2] + above[above_off+ 3] + 1) >> 1; - predict_off += stride; - - predict[predict_off+ 0] = pred4 = - (left[left_off+ 0] + 2 * above[above_off -1] + above[above_off+ 0] + 2) >> 2; - predict[predict_off+ 1] = pred5 = - (above[above_off -1] + 2 * above[above_off+ 0] + above[above_off+ 1] + 2) >> 2; - predict[predict_off+ 2] = pred6 = - (above[above_off+ 0] + 2 * above[above_off+ 1] + above[above_off+ 2] + 2) >> 2; - predict[predict_off+ 3] = pred7 = - (above[above_off+ 1] + 2 * above[above_off+ 2] + above[above_off+ 3] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred8 = - (left[left_off+ stride] + 2 * left[left_off+ 0] + above[above_off -1] + 2) >> 2; - predict[predict_off+ 1] = pred0; - predict[predict_off+ 2] = pred1; - predict[predict_off+ 3] = pred2; - predict_off += stride; - - predict[predict_off+ 0] = pred9 = - (left[left_off+ stride*2] + 2 * left[left_off+ stride] + left[left_off+ 0] + 2) >> 2; - predict[predict_off+ 1] = pred4; - predict[predict_off+ 2] = pred5; - predict[predict_off+ 3] = pred6; -} - - -//300 -function -predict_vl_4x4(predict, - predict_off, - stride) -{ - var above = predict; var above_off = predict_off - stride; - var pred0=int_, pred1=int_, pred2=int_, pred3=int_, pred4=int_, pred5=int_, pred6=int_, - pred7=int_, pred8=int_, pred9=int_; - - predict[predict_off+ 0] = pred0 = (above[above_off+ 0] + above[above_off+ 1] + 1) >> 1; - predict[predict_off+ 1] = pred1 = (above[above_off+ 1] + above[above_off+ 2] + 1) >> 1; - predict[predict_off+ 2] = pred2 = (above[above_off+ 2] + above[above_off+ 3] + 1) >> 1; - predict[predict_off+ 3] = pred3 = (above[above_off+ 3] + above[above_off+ 4] + 1) >> 1; - predict_off += stride; - - predict[predict_off+ 0] = pred4 = - (above[above_off+ 0] + 2 * above[above_off+ 1] + above[above_off+ 2] + 2) >> 2; - predict[predict_off+ 1] = pred5 = - (above[above_off+ 1] + 2 * above[above_off+ 2] + above[above_off+ 3] + 2) >> 2; - predict[predict_off+ 2] = pred6 = - (above[above_off+ 2] + 2 * above[above_off+ 3] + above[above_off+ 4] + 2) >> 2; - predict[predict_off+ 3] = pred7 = - (above[above_off+ 3] + 2 * above[above_off+ 4] + above[above_off+ 5] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred1; - predict[predict_off+ 1] = pred2; - predict[predict_off+ 2] = pred3; - predict[predict_off+ 3] = pred8 = (above[above_off+ 4] + 2 * above[above_off+ 5] + above[above_off+ 6] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred5; - predict[predict_off+ 1] = pred6; - predict[predict_off+ 2] = pred7; - predict[predict_off+ 3] = pred9 = (above[above_off+ 5] + 2 * above[above_off+ 6] + above[above_off+ 7] + 2) >> 2; -} - - -//337 -function -predict_hd_4x4(predict, - predict_off, - stride) -{ - var left = predict; var left_off = predict_off - 1; - var above = predict; var above_off = predict_off - stride; - var pred0=int_, pred1=int_, pred2=int_, pred3=int_, pred4=int_, pred5=int_, pred6=int_, - pred7=int_, pred8=int_, pred9=int_; - - predict[predict_off+ 0] = pred0 = - (left[left_off+ 0] + above[above_off -1] + 1) >> 1; - predict[predict_off+ 1] = pred1 = - (left[left_off+ 0] + 2 * above[above_off -1] + above[above_off+ 0] + 2) >> 2; - predict[predict_off+ 2] = pred2 = - (above[above_off -1] + 2 * above[above_off+ 0] + above[above_off+ 1] + 2) >> 2; - predict[predict_off+ 3] = pred3 = - (above[above_off+ 0] + 2 * above[above_off+ 1] + above[above_off+ 2] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred4 = - (left[left_off+ stride] + left[left_off+ 0] + 1) >> 1; - predict[predict_off+ 1] = pred5 = - (left[left_off+ stride] + 2 * left[left_off+ 0] + above[above_off -1] + 2) >> 2; - predict[predict_off+ 2] = pred0; - predict[predict_off+ 3] = pred1; - predict_off += stride; - - predict[predict_off+ 0] = pred6 = - (left[left_off+ stride*2] + left[left_off+ stride] + 1) >> 1; - predict[predict_off+ 1] = pred7 = - (left[left_off+ stride*2] + 2 * left[left_off+ stride] + left[left_off+ 0] + 2) >> 2; - predict[predict_off+ 2] = pred4; - predict[predict_off+ 3] = pred5; - predict_off += stride; - - predict[predict_off+ 0] = pred8 = - (left[left_off+ stride*3] + left[left_off+ stride*2] + 1) >> 1; - predict[predict_off+ 1] = pred9 = - (left[left_off+ stride*3] + 2 * left[left_off+ stride*2] + left[left_off+ stride] + 2) >> 2; - predict[predict_off+ 2] = pred6; - predict[predict_off+ 3] = pred7; -} - - -//381 -function -predict_hu_4x4(predict, - predict_off, - stride) -{ - var left = predict; var left_off = predict_off - 1; - var pred0=int_, pred1=int_, pred2=int_, pred3=int_, pred4=int_, pred5=int_, pred6=int_; - - predict[predict_off+ 0] = pred0 = - (left[left_off+ stride*0] + left[left_off+ stride*1] + 1) >> 1; - predict[predict_off+ 1] = pred1 = - (left[left_off+ stride*0] + 2 * left[left_off+ stride*1] + left[left_off+ stride*2] + 2) >> 2; - predict[predict_off+ 2] = pred2 = - (left[left_off+ stride*1] + left[left_off+ stride*2] + 1) >> 1; - predict[predict_off+ 3] = pred3 = - (left[left_off+ stride*1] + 2 * left[left_off+ stride*2] + left[left_off+ stride*3] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred2; - predict[predict_off+ 1] = pred3; - predict[predict_off+ 2] = pred4 = - (left[left_off+ stride*2] + left[left_off+ stride*3] + 1) >> 1; - predict[predict_off+ 3] = pred5 = - (left[left_off+ stride*2] + 2 * left[left_off+ stride*3] + left[left_off+ stride*3] + 2) >> 2; - predict_off += stride; - - predict[predict_off+ 0] = pred4; - predict[predict_off+ 1] = pred5; - predict[predict_off+ 2] = pred6 = left[left_off+ stride*3]; - predict[predict_off+ 3] = pred6; - predict_off += stride; - - predict[predict_off+ 0] = pred6; - predict[predict_off+ 1] = pred6; - predict[predict_off+ 2] = pred6; - predict[predict_off+ 3] = pred6; -} - - -//419 -function -predict_h_16x16(predict, predict_off, stride) -{ - predict_h_nxn(predict, predict_off, stride, 16); -} - - -//426 -function -predict_v_16x16(predict, predict_off, stride) -{ - predict_v_nxn(predict, predict_off, stride, 16); -} - - -//433 -function -predict_tm_16x16(predict, predict_off, stride) -{ - predict_tm_nxn(predict, predict_off, stride, 16); -} - - -//440 -function -predict_h_8x8(predict, predict_off, stride) -{ - predict_h_nxn(predict, predict_off, stride, 8); -} - - -//447 -function -predict_v_8x8(predict, predict_off, stride) -{ - predict_v_nxn(predict, predict_off, stride, 8); -} - - -//454 -function -predict_tm_8x8(predict, predict_off, stride) -{ - predict_tm_nxn(predict, predict_off, stride, 8); -} - - -//461 -function -predict_tm_4x4(predict, predict_off, stride) -{ - predict_tm_nxn(predict, predict_off, stride, 4); -} - -var tmp_4=new Array(0,0,0,0);//4 -//468 -function -copy_down(recon, - recon_off, - stride) -{ - /* Copy the four pixels above-right of subblock 3 to - * above-right of subblocks 7, 11, and 15 - */ - var /*uint32_t,*/ tmp_off=0, copy = (recon); var copy_off = (recon_off + 16 - stride);//*(void *) - - //stride = stride / sizeof(unsigned int); - var i; - for(i=0;i<4;++i) - tmp_4[tmp_off+i] = copy[copy_off+i]; - copy_off += stride * 4; - for(i=0;i<4;++i) - copy[copy_off+i] = tmp_4[tmp_off+i]; - copy_off += stride * 4; - for(i=0;i<4;++i) - copy[copy_off+i] = tmp_4[tmp_off+i]; - copy_off += stride * 4; - for(i=0;i<4;++i) - copy[copy_off+i] = tmp_4[tmp_off+i]; -} - - -//488 -function -b_pred(predict, - predict_off, - stride, - mbi, - coeffs, - coeffs_off) -{ - var i=int_; - - copy_down(predict, predict_off, stride); - - for (i = 0; i < 16; i++) - { - var b_predict = predict; var b_predict_off = predict_off + (i & 3) * 4;//* - - switch (mbi.splitt.mvs[i].d.x) - { - case B_DC_PRED: - predict_dc_nxn(b_predict, b_predict_off, stride, 4); - break; - case B_TM_PRED: - predict_tm_4x4(b_predict, b_predict_off, stride); - break; - case B_VE_PRED: - predict_ve_4x4(b_predict, b_predict_off, stride); - break; - case B_HE_PRED: - predict_he_4x4(b_predict, b_predict_off, stride); - break; - case B_LD_PRED: - predict_ld_4x4(b_predict, b_predict_off, stride); - break; - case B_RD_PRED: - predict_rd_4x4(b_predict, b_predict_off, stride); - break; - case B_VR_PRED: - predict_vr_4x4(b_predict, b_predict_off, stride); - break; - case B_VL_PRED: - predict_vl_4x4(b_predict, b_predict_off, stride); - break; - case B_HD_PRED: - predict_hd_4x4(b_predict, b_predict_off, stride); - break; - case B_HU_PRED: - predict_hu_4x4(b_predict, b_predict_off, stride); - break; - default: - assert(0); - } - - vp8_dixie_idct_add(b_predict, b_predict_off, b_predict, b_predict_off, stride, coeffs, coeffs_off); - coeffs_off += 16; - - if ((i & 3) == 3) - { - predict_off += stride * 4; - } - } -} - -var y2_16=Arr(16,0); -//549 -function -fixup_dc_coeffs(mbi, - coeffs, - coeffs_off) -{ - /*Arr(16,short_);*/ var y2_off=0; - var i=int_; - - vp8_dixie_walsh(coeffs, coeffs_off + 24 * 16, y2_16, y2_off); - - for (i = 0; i < 16; i++) - coeffs[coeffs_off+ i*16] = y2_16[i];//no y2_off need -} - - -//563 -function -predict_intra_luma(predict, - predict_off, - stride, - mbi, - coeffs, - coeffs_off) -{ - if (mbi.base.y_mode == B_PRED) - b_pred(predict, predict_off, stride, mbi, coeffs, coeffs_off); - else - { - var i=int_; - - switch (mbi.base.y_mode) - { - case DC_PRED: - predict_dc_nxn(predict, predict_off, stride, 16); - break; - case V_PRED: - predict_v_16x16(predict, predict_off, stride); - break; - case H_PRED: - predict_h_16x16(predict, predict_off, stride); - break; - case TM_PRED: - predict_tm_16x16(predict, predict_off, stride); - break; - default: - assert(0); - } - - fixup_dc_coeffs(mbi, coeffs, coeffs_off); - - for (i = 0; i < 16; i++) - { - vp8_dixie_idct_add(predict, predict_off, predict, predict_off, stride, coeffs, coeffs_off); - coeffs_off += 16; - predict_off += 4; - - if ((i & 3) == 3) - predict_off += stride * 4 - 16; - } - - } -} - - -//609 -function -predict_intra_chroma(predict_u, - predict_u_off, - predict_v, - predict_v_off, - stride, - mbi, - coeffs, - coeffs_off) -{ - var i=int_; - - switch (mbi.base.uv_mode) - { - case DC_PRED: - predict_dc_nxn(predict_u, predict_u_off, stride, 8); - predict_dc_nxn(predict_v, predict_v_off, stride, 8); - break; - case V_PRED: - predict_v_8x8(predict_u, predict_u_off, stride); - predict_v_8x8(predict_v, predict_v_off, stride); - break; - case H_PRED: - predict_h_8x8(predict_u, predict_u_off, stride); - predict_h_8x8(predict_v, predict_v_off, stride); - break; - case TM_PRED: - predict_tm_8x8(predict_u, predict_u_off, stride); - predict_tm_8x8(predict_v, predict_v_off, stride); - break; - default: - assert(0); - } - - coeffs_off += 16 * 16; - - for (i = 16; i < 20; i++) - { - vp8_dixie_idct_add(predict_u, predict_u_off, predict_u, predict_u_off, stride, coeffs, coeffs_off); - coeffs_off += 16; - predict_u_off += 4; - - if (i & 1) - predict_u_off += stride * 4 - 8; - } - - for (i = 20; i < 24; i++) - { - vp8_dixie_idct_add(predict_v, predict_v_off, predict_v, predict_v_off, stride, coeffs, coeffs_off); - coeffs_off += 16; - predict_v_off += 4; - - if (i & 1) - predict_v_off += stride * 4 - 8; - } - -} - - -//665 -function -sixtap_horiz(output, - output_off, - output_stride, - reference, - reference_off, - reference_stride, - cols, - rows, - filter - ) -{ - var r=int_, c=int_, temp=int_; - - for (r = 0; r < rows; r++) - { - for (c = 0; c < cols; c++) - { - temp = (reference[reference_off -2] * filter[0]) + - (reference[reference_off -1] * filter[1]) + - (reference[reference_off+ 0] * filter[2]) + - (reference[reference_off+ 1] * filter[3]) + - (reference[reference_off+ 2] * filter[4]) + - (reference[reference_off+ 3] * filter[5]) + - 64; - temp >>= 7; - output[output_off+ c] = (temp);//CLAMP_255 - reference_off++; - } - - reference_off += reference_stride - cols; - output_off += output_stride; - } -} - - -//699 -function -sixtap_vert(output, - output_off, - output_stride, - reference, - reference_off, - reference_stride, - cols, - rows, - filter - ) -{ - var r=int_, c=int_, temp=int_; - - for (r = 0; r < rows; r++) - { - for (c = 0; c < cols; c++) - { - temp = (reference[reference_off -2*reference_stride] * filter[0]) + - (reference[reference_off -1*reference_stride] * filter[1]) + - (reference[reference_off+ 0*reference_stride] * filter[2]) + - (reference[reference_off+ 1*reference_stride] * filter[3]) + - (reference[reference_off+ 2*reference_stride] * filter[4]) + - (reference[reference_off+ 3*reference_stride] * filter[5]) + - 64; - temp >>= 7; - output[output_off+ c] = (temp);//CLAMP_255 - reference_off++; - } - - reference_off += reference_stride - cols; - output_off += output_stride; - } -} - - - var temp_=new Array(16*(16+5));//Arr(16*(16+5),char_);// DECLARE_ALIGNED(16, unsigned char, temp[16*(16+5)]); -//733 -function -sixtap_2d(output, - output_off, - output_stride, - reference, - reference_off, - reference_stride, - cols, - rows, - mx, - my, - filters - ) -{ - - sixtap_horiz(temp_, 0, 16, - reference, reference_off - 2 * reference_stride, reference_stride, - cols, rows + 5, filters[mx]); - sixtap_vert(output, output_off, output_stride, - temp_, + 2 * 16, 16, - cols, rows, filters[my]); -} - - -var img_index = function() -{ - this.y=char_, this.u=char_, this.v=char_, - this.y_off=0, this.u_off=0, this.v_off=0, - this.stride=int_, this.uv_stride=int_ -}; - - -//763 -function // * -filter_block(return_off, - output, - output_off, - reference, - reference_off, - stride, - mv_, - filters) -{ - var mx=int_, my=int_; - - /* Handle 0,0 as a special case. TODO: does this make it any - * faster? - */ - if (!mv_.d.x && !mv_.d.y) {//.raw - return_off[0]=reference_off; - return reference; - } - - mx = mv_.d.x & 7; - my = mv_.d.y & 7; - reference_off += ((mv_.d.y >> 3) * stride) + (mv_.d.x >> 3); - - if (mx | my) - { - sixtap_2d(output, output_off, stride, reference, reference_off, stride, 4, 4, mx, my, - filters); - reference = output; reference_off = output_off; - } - - return_off[0]=reference_off; - return reference; -} - - -//793 -function -recon_1_block(output, - output_off, - reference, - reference_off, - stride, - mv, - filters, - coeffs, - coeffs_off, - mbi, - b - ) -{ - var predict=char_; var predict_off=0; var filter_block_return_off=[0]; - - predict = filter_block(filter_block_return_off, output, output_off, reference, reference_off, stride, mv, filters); - predict_off = filter_block_return_off[0]; - vp8_dixie_idct_add(output, output_off, predict, predict_off, stride, coeffs, coeffs_off + 16 * b); -} - - -//811 -function -calculate_chroma_splitmv(mbi, - b, - full_pixel) -{ - var temp=int_; - var mv_=new mv(); - - temp = mbi.splitt.mvs[b].d.x + - mbi.splitt.mvs[b+1].d.x + - mbi.splitt.mvs[b+4].d.x + - mbi.splitt.mvs[b+5].d.x; - - if (temp < 0) - temp -= 4; - else - temp += 4; - - mv_.d.x = parseInt(temp / 8,10); - - temp = mbi.splitt.mvs[b].d.y + - mbi.splitt.mvs[b+1].d.y + - mbi.splitt.mvs[b+4].d.y + - mbi.splitt.mvs[b+5].d.y; - - if (temp < 0) - temp -= 4; - else - temp += 4; - - mv_.d.y = parseInt(temp / 8,10); - - if (full_pixel) - { - mv_.d.x &= ~7; - mv_.d.y &= ~7; - } - - return mv_; -} - - -/* Note: We rely on the reconstructed border having the same stride as - * the reference buffer because the filter_block can't adjust the - * stride with its return value, only the reference pointer. - */ -//857 -function -build_mc_border(dst, - dst_off, - src, - src_off, - stride, - x, - y, - b_w, - b_h, - w, - h - ) -{ - var ref_row=char_; var ref_row_off=char_; - - - /* Get a pointer to the start of the real data for this row */ - ref_row = src; ref_row_off = src_off - x - y * stride; - - if (y >= h) - ref_row_off += (h - 1) * stride; - else if (y > 0) - ref_row_off += y * stride; - - do - { - var left=int_, right = 0, copy=int_; - - left = x < 0 ? -x : 0; - - if (left > b_w) - left = b_w; - - if (x + b_w > w) - right = x + b_w - w; - - if (right > b_w) - right = b_w; - - copy = b_w - left - right; - - if (left) - memset(dst, dst_off, ref_row[ref_row_off+ 0], left); - - if (copy) - memcpy(dst, dst_off + left, ref_row, ref_row_off + x + left, copy); - - if (right) - memset(dst, dst_off + left + copy, ref_row[ref_row_off+ w-1], right); - - dst_off += stride; - y++; - - if (y < h && y > 0) - ref_row_off += stride; - } - while (--b_h); -} - - -//916 -function -recon_1_edge_block(output, - output_off, - emul_block, - emul_block_off, - reference, - reference_off, - stride, - mv_, - filters, - coeffs, - coeffs_off, - mbi, - x, - y, - w, - h, - start_b - ) -{ - var predict=char_; var predict_off=0; - var b = start_b; - var b_w = 4; - var b_h = 4; - - x += mv_.d.x >> 3; - y += mv_.d.y >> 3; - - /* Need two pixels left/above, 3 right/below for 6-tap */ - if (x < 2 || x + b_w - 1 + 3 >= w || y < 2 || y + b_h - 1 + 3 >= h) - { - reference_off += (mv_.d.x >> 3) + (mv_.d.y >> 3) * stride; - build_mc_border(emul_block, emul_block_off, - reference, reference_off - 2 - 2 * stride, stride, - x - 2, y - 2, b_w + 5, b_h + 5, w, h); - reference = emul_block; reference_off = emul_block_off + 2 * stride + 2; - reference_off -= (mv_.d.x >> 3) + (mv_.d.y >> 3) * stride; - } var filter_block_return_off=[0]; - - predict = filter_block(filter_block_return_off, output, output_off, reference, reference_off, stride, mv_, filters); - predict_off = filter_block_return_off[0]; - vp8_dixie_idct_add(output, output_off, predict, predict_off, stride, coeffs, coeffs_off + 16 * b); -} - -var uvmv_1=new mv(); -//956 -function -predict_inter_emulated_edge(ctx, - img, - coeffs, - coeffs_off, - mbi, - mb_col, - mb_row) -{ - /* TODO: move this into its own buffer. This only works because we - * still have a border allocated. - */ - var emul_block = ctx.frame_strg[0].img.img_data; var emul_block_off = ctx.frame_strg[0].img.img_data_off; - var reference=char_; var reference_off=0; - var output=char_; var output_off=0; - var reference_offset=ptrdiff_t; - var w=int_, h=int_, x=int_, y=int_, b=int_; - var chroma_mv=Arr_new(4,mv); - var u = img.u, v = img.v; var u_off = img.u_off, v_off = img.v_off; - var full_pixel = (ctx.frame_hdr.version == 3)+0; - - - x = mb_col * 16; - y = mb_row * 16; - w = ctx.mb_cols * 16; - h = ctx.mb_rows * 16; - output = img.y; output_off = img.y_off; - reference_offset = ctx.ref_frame_offsets[mbi.base.ref_frame]; reference = ctx.ref_frame_offsets_[mbi.base.ref_frame]; - /*reference = output;*/ reference_off = output_off + reference_offset; - - if (mbi.base.y_mode != SPLITMV) - { - var uvmv=uvmv_1; - - uvmv.d.x = mbi.base.mv.d.x;uvmv.d.y = mbi.base.mv.d.y; - uvmv.d.x = (uvmv.d.x + 1/* + (uvmv.d.x >> 31) * 2*/) >> 1; - uvmv.d.y = (uvmv.d.y + 1/* + (uvmv.d.y >> 31) * 2*/) >> 1; - - if (full_pixel) - { - uvmv.d.x &= ~7; - uvmv.d.y &= ~7; - } - - chroma_mv[0].d.x = uvmv.d.x; chroma_mv[0].d.y = uvmv.d.y;//todo: set pointer or copy? - chroma_mv[1].d.x = uvmv.d.x; chroma_mv[1].d.y = uvmv.d.y; - chroma_mv[2].d.x = uvmv.d.x; chroma_mv[2].d.y = uvmv.d.y; - chroma_mv[3].d.x = uvmv.d.x; chroma_mv[3].d.y = uvmv.d.y; - } - else - { - chroma_mv[0] = calculate_chroma_splitmv(mbi, 0, full_pixel); - chroma_mv[1] = calculate_chroma_splitmv(mbi, 2, full_pixel); - chroma_mv[2] = calculate_chroma_splitmv(mbi, 8, full_pixel); - chroma_mv[3] = calculate_chroma_splitmv(mbi, 10, full_pixel); - } - - - /* Luma */ - for (b = 0; b < 16; b++) - { - var ymv;//='mv' - - if (mbi.base.y_mode != SPLITMV) - ymv = mbi.base.mv; - else - ymv = mbi.splitt.mvs[ + b]; - - recon_1_edge_block(output, output_off, emul_block, emul_block_off, reference, reference_off, img.stride, - ymv, ctx.subpixel_filters, - coeffs, coeffs_off, mbi, x, y, w, h, b); - - x += 4; - output_off += 4; - reference_off += 4; - - if ((b & 3) == 3) - { - x -= 16; - y += 4; - output_off += 4 * img.stride - 16; - reference_off += 4 * img.stride - 16; - } - } - - x = mb_col * 16; - y = mb_row * 16; - - /* Chroma */ - x >>= 1; - y >>= 1; - w >>= 1; - h >>= 1; - - for (b = 0; b < 4; b++) - { - recon_1_edge_block(u, u_off, emul_block, emul_block_off, reference, u_off + reference_offset,//u - img.uv_stride, - chroma_mv[b], ctx.subpixel_filters, - coeffs, coeffs_off, mbi, x, y, w, h, b + 16); - recon_1_edge_block(v, v_off, emul_block, emul_block_off, reference, v_off + reference_offset,//v - img.uv_stride, - chroma_mv[b], ctx.subpixel_filters, - coeffs, coeffs_off, mbi, x, y, w, h, b + 20); - u_off += 4; - v_off += 4; - x += 4; - - if (b & 1) - { - x -= 8; - y += 4; - u_off += 4 * img.uv_stride - 8; - v_off += 4 * img.uv_stride - 8; - } - } - -} - -var uvmv_2=new mv(); -//1074 -function -predict_inter(ctx, - img, - coeffs, - coeffs_off, - mbi) -{ - var y = img.y; var y_off = img.y_off; - var u = img.u; var u_off = img.u_off; - var v = img.v; var v_off = img.v_off; - var reference; var reference_offset=ptrdiff_t; - var chroma_mv=Arr_new(4,mv); - var full_pixel = (ctx.frame_hdr.version == 3)+0; - var b=int_; - - if (mbi.base.y_mode != SPLITMV) - { - var uvmv=uvmv_2; - - uvmv.d.x = mbi.base.mv.d.x;uvmv.d.y = mbi.base.mv.d.y; - uvmv.d.x = (uvmv.d.x + 1/* + (uvmv.d.x >> 31) * 2*/) >> 1; - uvmv.d.y = (uvmv.d.y + 1/* + (uvmv.d.y >> 31) * 2*/) >> 1; - - if (full_pixel) - { - uvmv.d.x &= ~7; - uvmv.d.y &= ~7; - } - - chroma_mv[0].d.x = - chroma_mv[1].d.x = - chroma_mv[2].d.x = - chroma_mv[3].d.x = uvmv.d.x; - chroma_mv[0].d.y = - chroma_mv[1].d.y = - chroma_mv[2].d.y = - chroma_mv[3].d.y = uvmv.d.y; - } - else - { - chroma_mv[0] = calculate_chroma_splitmv(mbi, 0, full_pixel); - chroma_mv[1] = calculate_chroma_splitmv(mbi, 2, full_pixel); - chroma_mv[2] = calculate_chroma_splitmv(mbi, 8, full_pixel); - chroma_mv[3] = calculate_chroma_splitmv(mbi, 10, full_pixel); - } - - reference_offset = ctx.ref_frame_offsets[mbi.base.ref_frame];reference = ctx.ref_frame_offsets_[mbi.base.ref_frame]; - - for (b = 0; b < 16; b++) - { - var ymv;//='mv' - - if (mbi.base.y_mode != SPLITMV) - ymv = mbi.base.mv; - else - ymv = mbi.splitt.mvs[ + b];//newObjectI() - - - recon_1_block(y, y_off, reference, y_off + reference_offset, img.stride,//y - ymv, ctx.subpixel_filters, coeffs, coeffs_off, mbi, b); - y_off += 4; - - if ((b & 3) == 3) - y_off += 4 * img.stride - 16; - } - - for (b = 0; b < 4; b++) - { - recon_1_block(u, u_off, reference, u_off + reference_offset,//u - img.uv_stride, chroma_mv[b], - ctx.subpixel_filters, coeffs, coeffs_off, mbi, b + 16); - recon_1_block(v, v_off, reference, v_off + reference_offset,//v - img.uv_stride, chroma_mv[b], - ctx.subpixel_filters, coeffs, coeffs_off, mbi, b + 20); - u_off += 4; - v_off += 4; - - if (b & 1) - { - u_off += 4 * img.uv_stride - 8; - v_off += 4 * img.uv_stride - 8; - } - } -} - - -//1155 -function -vp8_dixie_release_ref_frame(rcimg) -{ - if (rcimg) - { - assert(rcimg.ref_cnt); - rcimg.ref_cnt--; - } -} - - -function -vp8_dixie_ref_frame(rcimg) -{ - rcimg.ref_cnt++; - return rcimg; -} - -//1174 -function -vp8_dixie_find_free_ref_frame(frames) -{ - var i=int_; - - for (i = 0; i < NUM_REF_FRAMES; i++) - if (frames[i].ref_cnt == 0) - { - frames[i].ref_cnt = 1; - return frames[i]; - } - - assert(0); - return null; -} - - -//1191 -function -fixup_left(predict, - predict_off, - width, - stride, - row, - mode) -{ - /* The left column of out-of-frame pixels is taken to be 129, - * unless we're doing DC_PRED, in which case we duplicate the - * above row, unless this is also row 0, in which case we use - * 129. - */ - var left = predict; var left_off = predict_off - 1;//* - var i=int_; - - if (mode == DC_PRED && row) - { - var above = predict; var above_off = predict_off - stride;//* - - for (i = 0; i < width; i++) - { - left[left_off] = above[above_off+ i];//* - left_off += stride; - } - } - else - { - /* Need to re-set the above row, in case the above MB was - * DC_PRED. - */ - left_off -= stride; - - for (i = -1; i < width; i++) - { - left[left_off] = 129;//* - left_off += stride; - } - } -} - - -//1232 -function -fixup_above(predict, - predict_off, - width, - stride, - col, - mode) -{ - /* The above row of out-of-frame pixels is taken to be 127, - * unless we're doing DC_PRED, in which case we duplicate the - * left col, unless this is also col 0, in which case we use - * 127. - */ - var above = predict; var above_off = predict_off - stride;//* - var i=int_; - - if (mode == DC_PRED && col) - { - var left = predict; var left_off = predict_off - 1;//* - - for (i = 0; i < width; i++) - { - above[above_off+ i] = left[left_off];//* - left_off += stride; - } - } - else - /* Need to re-set the left col, in case the last MB was - * DC_PRED. - */ - memset(above, above_off - 1, 127, width + 1); - - memset(above, above_off + width, 127, 4); // for above-right subblock modes -} - - -//1267 -function -vp8_dixie_predict_init(ctx) -{ - - var i=int_; - var this_frame_base=char_;var this_frame_base_off=0;//* - - if (ctx.frame_hdr.frame_size_updated) - { - for (i = 0; i < NUM_REF_FRAMES; i++) - { - var w = ctx.mb_cols * 16 + BORDER_PIXELS * 2; - var h = ctx.mb_rows * 16 + BORDER_PIXELS * 2; - - vpx_img_free(ctx.frame_strg[i].img); - ctx.frame_strg[i].ref_cnt = 0; - ctx.ref_frames[i] = null; - - if (!vpx_img_alloc(ctx.frame_strg[i].img, - IMG_FMT_I420, w, h, 16)) - vpx_internal_error(ctx.error, VPX_CODEC_MEM_ERROR, - "Failed to allocate %dx%d"+ - " framebuffer", - w, h); - - vpx_img_set_rect(ctx.frame_strg[i].img, - BORDER_PIXELS, BORDER_PIXELS, - ctx.frame_hdr.kf.w, ctx.frame_hdr.kf.h); - - } - - if (ctx.frame_hdr.version) - ctx.subpixel_filters = bilinear_filters; - else - ctx.subpixel_filters = sixtap_filters; - } - - /* Find a free framebuffer to predict into */ - if (ctx.ref_frames[CURRENT_FRAME]) - vp8_dixie_release_ref_frame(ctx.ref_frames[CURRENT_FRAME]); - - ctx.ref_frames[CURRENT_FRAME] = - vp8_dixie_find_free_ref_frame(ctx.frame_strg); - this_frame_base = ctx.ref_frames[CURRENT_FRAME].img.img_data; - - /* Calculate offsets to the other reference frames */ - for (i = 0; i < NUM_REF_FRAMES; i++) - { - var ref = ctx.ref_frames[i]; - - ctx.ref_frame_offsets[i] = - ref ? ref.img.img_data_off - this_frame_base_off : 0;ctx.ref_frame_offsets_[i] = ref ? ref.img.img_data : this_frame_base; - } - - /* TODO: No need to do this on every frame... */ -} - -var img_1=new img_index(); -//1339 -function -vp8_dixie_predict_process_row(ctx, - row, - start_col, - num_cols) -{ - var img=img_1; - var mbi;var mbi_off=0;//*='(mb_info)' - var col=int_; - var coeffs=short_;var coeffs_off=0;//* - - /* Adjust pointers based on row, start_col */ - img.stride = ctx.ref_frames[CURRENT_FRAME].img.stride[PLANE_Y]; - img.uv_stride = ctx.ref_frames[CURRENT_FRAME].img.stride[PLANE_U]; - img.y = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_Y]; - img.y_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_Y]; - img.u = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_U]; - img.u_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_U]; - img.v = ctx.ref_frames[CURRENT_FRAME].img.planes[PLANE_V]; - img.v_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_V]; - img.y_off += (img.stride * row + start_col) * 16; - img.u_off += (img.uv_stride * row + start_col) * 8; - img.v_off += (img.uv_stride * row + start_col) * 8; - mbi = ctx.mb_info_rows[1+ row]; mbi_off = ctx.mb_info_rows_off[1+ row] + start_col; - coeffs = ctx.tokens[row & (ctx.token_hdr.partitions - 1)].coeffs; - coeffs_off = //todo: mit coeffs off? - + 25 * 16 * start_col; - - /* Fix up the out-of-frame pixels */ - if (start_col == 0) - { - fixup_left(img.y, img.y_off, 16, img.stride, row, mbi[mbi_off].base.y_mode); - fixup_left(img.u, img.u_off, 8, img.uv_stride, row, mbi[mbi_off].base.uv_mode); - fixup_left(img.v, img.v_off, 8, img.uv_stride, row, mbi[mbi_off].base.uv_mode); - - if (row == 0) - (img.y[img.y_off - img.stride - 1]) = 127;//* - } - - for (col = start_col; col < start_col + num_cols; col++) - { - if (row == 0) - { - fixup_above(img.y, img.y_off, 16, img.stride, col, mbi[mbi_off].base.y_mode); - fixup_above(img.u, img.u_off, 8, img.uv_stride, col, - mbi[mbi_off].base.uv_mode); - fixup_above(img.v, img.v_off, 8, img.uv_stride, col, - mbi[mbi_off].base.uv_mode); - } - - if (mbi[mbi_off].base.y_mode <= B_PRED) - { - predict_intra_luma(img.y, img.y_off, img.stride, mbi[mbi_off], coeffs, coeffs_off); - predict_intra_chroma(img.u, img.u_off, img.v, img.v_off, img.uv_stride, mbi[mbi_off], - coeffs, coeffs_off); - } - else - { - if (mbi[mbi_off].base.y_mode != SPLITMV) // && != BPRED - fixup_dc_coeffs(mbi[mbi_off], coeffs, coeffs_off); - - if (mbi[mbi_off].base.need_mc_border) - predict_inter_emulated_edge(ctx, img, coeffs, coeffs_off, mbi[mbi_off], col, - row); - else - predict_inter(ctx, img, coeffs, coeffs_off, mbi[mbi_off]); - } - - /* Advance to the next macroblock */ - mbi_off++; - img.y_off += 16; - img.u_off += 8; - img.v_off += 8; - coeffs_off += 25 * 16; - } - - if (col == ctx.mb_cols) - { - /* Extend the last row by four pixels for intra prediction. - * This will be propagated later by copy_down. - */ - var extend = img.y; var extend_off = (img.y_off + 15 * img.stride);//(uint32_t *) - var val = img.y[img.y_off -1 + 15 * img.stride];//0x01010101 * - extend[extend_off] = extend[extend_off+1] = extend[extend_off+2] = extend[extend_off+3] = val; - } -} - - -//22 -var - FRAME_HEADER_SZ = 3, - KEYFRAME_HEADER_SZ = 7 -; - - -//29 -function ARRAY_COPY(a,b) { - assert(a.length==b.length);memcpy(a, 0, b, 0, a.length);} -//31 -function -decode_entropy_header(ctx, - bool, - hdr) -{ - var i=int_, j=int_, k=int_, l=int_; var ii=0; - - /* Read coefficient probability updates */ - for (i = 0; i < BLOCK_TYPES; i++) - for (j = 0; j < COEF_BANDS; j++) - for (k = 0; k < PREV_COEF_CONTEXTS; k++) - for (l = 0; l < ENTROPY_NODES; l++) { - if (bool_get(bool, - k_coeff_entropy_update_probs - [i][j][k][l])) - hdr.coeff_probs_[ii] = hdr.coeff_probs[i][j][k][l] = - bool_get_uint(bool, 8); - ii++; - } - - /* Read coefficient skip mode probability */ - hdr.coeff_skip_enabled = bool_get_bit(bool); - - if (hdr.coeff_skip_enabled) - hdr.coeff_skip_prob = bool_get_uint(bool, 8); - - /* Parse interframe probability updates */ - if (!ctx.frame_hdr.is_keyframe) - { - hdr.prob_inter = bool_get_uint(bool, 8); - hdr.prob_last = bool_get_uint(bool, 8); - hdr.prob_gf = bool_get_uint(bool, 8); - - if (bool_get_bit(bool)) - for (i = 0; i < 4; i++) - hdr.y_mode_probs[i] = bool_get_uint(bool, 8); - - if (bool_get_bit(bool)) - for (i = 0; i < 3; i++) - hdr.uv_mode_probs[i] = bool_get_uint(bool, 8); - - for (i = 0; i < 2; i++) - for (j = 0; j < MV_PROB_CNT; j++) - if (bool_get(bool, k_mv_entropy_update_probs[i][j])) - { - var x = bool_get_uint(bool, 7); - hdr.mv_probs[i][j] = x ? x << 1 : 1; - } - } -} - - -//81 -function -decode_reference_header(ctx, - bool, - hdr) -{ - var key = ctx.frame_hdr.is_keyframe; - - hdr.refresh_gf = key ? 1 : bool_get_bit(bool); - hdr.refresh_arf = key ? 1 : bool_get_bit(bool); - hdr.copy_gf = key ? 0 : !hdr.refresh_gf - ? bool_get_uint(bool, 2) : 0; - hdr.copy_arf = key ? 0 : !hdr.refresh_arf - ? bool_get_uint(bool, 2) : 0; - hdr.sign_bias[GOLDEN_FRAME] = key ? 0 : bool_get_bit(bool); - hdr.sign_bias[ALTREF_FRAME] = key ? 0 : bool_get_bit(bool); - hdr.refresh_entropy = bool_get_bit(bool); - hdr.refresh_last = key ? 1 : bool_get_bit(bool); -} - - -//101 -function -decode_quantizer_header(ctx, - bool, - hdr) -{ - var update=int_; - var last_q = hdr.q_index; - - hdr.q_index = bool_get_uint(bool, 7); - update = (last_q != hdr.q_index)+0; - update |= (hdr.y1_dc_delta_q = bool_maybe_get_int(bool, 4)); - update |= (hdr.y2_dc_delta_q = bool_maybe_get_int(bool, 4)); - update |= (hdr.y2_ac_delta_q = bool_maybe_get_int(bool, 4)); - update |= (hdr.uv_dc_delta_q = bool_maybe_get_int(bool, 4)); - update |= (hdr.uv_ac_delta_q = bool_maybe_get_int(bool, 4)); - hdr.delta_update = update; -} - - -//120 -function -decode_and_init_token_partitions(ctx, - bool, - data, - data_off, - sz, - hdr) -{ - var i=int_; - - hdr.partitions = 1 << bool_get_uint(bool, 2); - - if (sz < 3 *(hdr.partitions - 1)) - vpx_internal_error(ctx.error, VPX_CODEC_CORRUPT_FRAME, - "Truncated packet found parsing partition" + - " lengths."); - - sz -= 3 * (hdr.partitions - 1); - - for (i = 0; i < hdr.partitions; i++) - { - if (i < hdr.partitions - 1) - { - hdr.partition_sz[i] = (data[data_off+2] << 16) - | (data[data_off+1] << 8) | data[data_off+0]; - data_off += 3; - } - else - hdr.partition_sz[i] = sz; - - if (sz < hdr.partition_sz[i]) - vpx_internal_error(ctx.error, VPX_CODEC_CORRUPT_FRAME, - "Truncated partition %d", i); - - sz -= hdr.partition_sz[i]; - } - - - for (i = 0; i < ctx.token_hdr.partitions; i++) - { - init_bool_decoder(ctx.tokens[i].bool, data, data_off, - ctx.token_hdr.partition_sz[i]); - data_off += ctx.token_hdr.partition_sz[i]; - } -} - - -//166 -function -decode_loopfilter_header(ctx, - bool, - hdr) -{ - if (ctx.frame_hdr.is_keyframe) - memset(hdr, 0, 1/*sizeof(hdr)*/);//todo - - hdr.use_simple = bool_get_bit(bool); - hdr.level = bool_get_uint(bool, 6); - hdr.sharpness = bool_get_uint(bool, 3); - hdr.delta_enabled = bool_get_bit(bool); - - if (hdr.delta_enabled && bool_get_bit(bool)) - { - var i=int_; - - for (i = 0; i < BLOCK_CONTEXTS; i++) - hdr.ref_delta[i] = bool_maybe_get_int(bool, 6); - - for (i = 0; i < BLOCK_CONTEXTS; i++) - hdr.mode_delta[i] = bool_maybe_get_int(bool, 6); - } -} - - -//192 -function -decode_segmentation_header(ctx, - bool, - hdr) -{ - if (ctx.frame_hdr.is_keyframe) - memset(hdr, 0, 1/*sizeof(hdr)*/);//todo: - - hdr.enabled = bool_get_bit(bool); - - if (hdr.enabled) - { - var i=int_; - - hdr.update_map = bool_get_bit(bool); - hdr.update_data = bool_get_bit(bool); - - if (hdr.update_data) - { - hdr.abs_ = bool_get_bit(bool); - - for (i = 0; i < MAX_MB_SEGMENTS; i++) - hdr.quant_idx[i] = bool_maybe_get_int(bool, 7); - - for (i = 0; i < MAX_MB_SEGMENTS; i++) - hdr.lf_level[i] = bool_maybe_get_int(bool, 6); - } - - if (hdr.update_map) - { - for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) - hdr.tree_probs[i] = bool_get_bit(bool) - ? bool_get_uint(bool, 8) - : 255; - } - } - else - { - hdr.update_map = 0; - hdr.update_data = 0; - } -} - - -//246 -function -clamp_q(q) -{ - if (q < 0) return 0; - else if (q > 127) return 127; - - return q; -} - - -//256 -function -dc_q(q) -{ - return dc_q_lookup[clamp_q(q)]; -} - - -//263 -function -ac_q(q) -{ - return ac_q_lookup[clamp_q(q)]; -} - - -//270 -function -dequant_init(factors, - seg, - quant_hdr) -{ - var i=int_, q=int_; - var dqf = factors; var dqf_off = 0; - - for (i = 0; i < (seg.enabled ? MAX_MB_SEGMENTS : 1); i++) - { - q = quant_hdr.q_index; - - if (seg.enabled) - q = (!seg.abs_) ? q + seg.quant_idx[i] : seg.quant_idx[i]; - - if (dqf[dqf_off].quant_idx != q || quant_hdr.delta_update) - { - dqf[dqf_off].factor[TOKEN_BLOCK_Y1][0] = - dc_q(q + quant_hdr.y1_dc_delta_q); - dqf[dqf_off].factor[TOKEN_BLOCK_Y1][1] = - ac_q(q); - dqf[dqf_off].factor[TOKEN_BLOCK_UV][0] = - dc_q(q + quant_hdr.uv_dc_delta_q); - dqf[dqf_off].factor[TOKEN_BLOCK_UV][1] = - ac_q(q + quant_hdr.uv_ac_delta_q); - dqf[dqf_off].factor[TOKEN_BLOCK_Y2][0] = - dc_q(q + quant_hdr.y2_dc_delta_q) * 2; - dqf[dqf_off].factor[TOKEN_BLOCK_Y2][1] = - parseInt(ac_q(q + quant_hdr.y2_ac_delta_q) * 155 / 100); - - if (dqf[dqf_off].factor[TOKEN_BLOCK_Y2][1] < 8) - dqf[dqf_off].factor[TOKEN_BLOCK_Y2][1] = 8; - - if (dqf[dqf_off].factor[TOKEN_BLOCK_UV][0] > 132) - dqf[dqf_off].factor[TOKEN_BLOCK_UV][0] = 132; - - dqf[dqf_off].quant_idx = q; - } - - dqf_off++; - } -} - -var bool_1=new bool_decoder(); -//314 -function -decode_frame(ctx, - data, - data_off, - sz) -{ - var res;//='vpx_codec_err_t' - var bool=bool_1; - var i=int_, row=int_, partition=int_; - - ctx.saved_entropy_valid = 0; - - if ((res = vp8_parse_frame_header(data, sz, ctx.frame_hdr))) - vpx_internal_error(ctx.error, res, - "Failed to parse frame header"); - - if (ctx.frame_hdr.is_experimental) - vpx_internal_error(ctx.error, VPX_CODEC_UNSUP_BITSTREAM, - "Experimental bitstreams not supported."); - - data_off += FRAME_HEADER_SZ; - sz -= FRAME_HEADER_SZ; - - if (ctx.frame_hdr.is_keyframe) - { - data_off += KEYFRAME_HEADER_SZ; - sz -= KEYFRAME_HEADER_SZ; - ctx.mb_cols = parseInt((ctx.frame_hdr.kf.w + 15) / 16,10); - ctx.mb_rows = parseInt((ctx.frame_hdr.kf.h + 15) / 16,10); - } - - /* Start the bitreader for the header/entropy partition */ - init_bool_decoder(bool, data, data_off, ctx.frame_hdr.part0_sz); - - /* Skip the colorspace and clamping bits */ - if (ctx.frame_hdr.is_keyframe) - if (bool_get_uint(bool, 2)) - vpx_internal_error(ctx.error, VPX_CODEC_UNSUP_BITSTREAM, - "Reserved bits not supported."); - - decode_segmentation_header(ctx, bool, ctx.segment_hdr); - decode_loopfilter_header(ctx, bool, ctx.loopfilter_hdr); - decode_and_init_token_partitions(ctx, - bool, - data, data_off + ctx.frame_hdr.part0_sz, - sz - ctx.frame_hdr.part0_sz, - ctx.token_hdr); - decode_quantizer_header(ctx, bool, ctx.quant_hdr); - decode_reference_header(ctx, bool, ctx.reference_hdr); - - /* Set keyframe entropy defaults. These get updated on keyframes - * regardless of the refresh_entropy setting. - */ - if (ctx.frame_hdr.is_keyframe) - { - var i=int_, j=int_, k=int_, l=int_; var ii=0; - - /* Read coefficient probability updates */ - for (i = 0; i < BLOCK_TYPES; i++) - for (j = 0; j < COEF_BANDS; j++) - for (k = 0; k < PREV_COEF_CONTEXTS; k++) - for (l = 0; l < ENTROPY_NODES; l++) { - ctx.entropy_hdr.coeff_probs_[ii]=ctx.entropy_hdr.coeff_probs[i][j][k][l]=k_default_coeff_probs[i][j][k][l]; - ii++; - } - //=newObjectI(// ARRAY_COPY(ctx.entropy_hdr.coeff_probs, - // k_default_coeff_probs);//k_default_coeff_probs); - ctx.entropy_hdr.mv_probs=new //ARRAY_COPY( - k_default_mv_probs(); - ARRAY_COPY(ctx.entropy_hdr.y_mode_probs, - k_default_y_mode_probs); - ARRAY_COPY(ctx.entropy_hdr.uv_mode_probs, - k_default_uv_mode_probs); - } - - if (!ctx.reference_hdr.refresh_entropy) - { - //ctx.saved_entropy = newObjectI(ctx.entropy_hdr); - var to = ctx.saved_entropy, from = ctx.entropy_hdr; - var ii=0; - for (i = 0; i < BLOCK_TYPES; i++) - for (j = 0; j < COEF_BANDS; j++) - for (k = 0; k < PREV_COEF_CONTEXTS; k++) - for (l = 0; l < ENTROPY_NODES; l++) { - to.coeff_probs_[ii]=to.coeff_probs[i][j][k][l]=from.coeff_probs[i][j][k][l]; - ii++; - } - //for(i=0;i<1056;++i) - //to.coeff_probs_[i] = from.coeff_probs_[i]; - to.coeff_skip_enabled = from.coeff_skip_enabled; - to.coeff_skip_prob = from.coeff_skip_prob; - for(i=0;i<2;++i) - for(j=0;j<19;++j) - to.mv_probs[i][j] = from.mv_probs[i][j]; - to.prob_gf = from.prob_gf; - to.prob_inter = from.prob_inter; - to.prob_last = from.prob_last; - for(i=0;i<3;++i) - to.uv_mode_probs[i] = from.uv_mode_probs[i]; - for(i=0;i<4;++i) - to.y_mode_probs[i] = from.y_mode_probs[i]; - - ctx.saved_entropy_valid = 1; - } - - decode_entropy_header(ctx, bool, ctx.entropy_hdr); - - vp8_dixie_modemv_init(ctx); - vp8_dixie_tokens_init(ctx); - vp8_dixie_predict_init(ctx); - dequant_init(ctx.dequant_factors, ctx.segment_hdr, - ctx.quant_hdr); - - for (row = 0, partition = 0; row < ctx.mb_rows; row++) - { - vp8_dixie_modemv_process_row(ctx, bool, row, 0, ctx.mb_cols); - vp8_dixie_tokens_process_row(ctx, partition, row, 0, - ctx.mb_cols); - vp8_dixie_predict_process_row(ctx, row, 0, ctx.mb_cols); - -// if (ctx.loopfilter_hdr.level && row) -// vp8_dixie_loopfilter_process_row(ctx, row - 1, 0, -// ctx.mb_cols); - - if (++partition == ctx.token_hdr.partitions) - partition = 0; - } - -// if (ctx.loopfilter_hdr.level) -// vp8_dixie_loopfilter_process_row(ctx, row - 1, 0, ctx.mb_cols); - - ctx.frame_cnt++; - - if (!ctx.reference_hdr.refresh_entropy) - { - //ctx.entropy_hdr = ctx.saved_entropy; - var to = ctx.entropy_hdr, from = ctx.saved_entropy; - var ii=0; - for (i = 0; i < BLOCK_TYPES; i++) - for (j = 0; j < COEF_BANDS; j++) - for (k = 0; k < PREV_COEF_CONTEXTS; k++) - for (l = 0; l < ENTROPY_NODES; l++) { - to.coeff_probs_[ii]=to.coeff_probs[i][j][k][l]=from.coeff_probs[i][j][k][l]=from.coeff_probs_[ii]; - ii++; - } - //for(i=0;i<1056;++i) - //to.coeff_probs_[i] = from.coeff_probs_[i]; - to.coeff_skip_enabled = from.coeff_skip_enabled; - to.coeff_skip_prob = from.coeff_skip_prob; - for(i=0;i<2;++i) - for(j=0;j<19;++j) - to.mv_probs[i][j] = from.mv_probs[i][j]; - to.prob_gf = from.prob_gf; - to.prob_inter = from.prob_inter; - to.prob_last = from.prob_last; - for(i=0;i<3;++i) - to.uv_mode_probs[i] = from.uv_mode_probs[i]; - for(i=0;i<4;++i) - to.y_mode_probs[i] = from.y_mode_probs[i]; - - ctx.saved_entropy_valid = 0; - } - - /* Handle reference frame updates */ - if (ctx.reference_hdr.copy_arf == 1) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[ALTREF_FRAME]); - ctx.ref_frames[ALTREF_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[LAST_FRAME]); - } - else if (ctx.reference_hdr.copy_arf == 2) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[ALTREF_FRAME]); - ctx.ref_frames[ALTREF_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[GOLDEN_FRAME]); - } - - if (ctx.reference_hdr.copy_gf == 1) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[GOLDEN_FRAME]); - ctx.ref_frames[GOLDEN_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[LAST_FRAME]); - } - else if (ctx.reference_hdr.copy_gf == 2) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[GOLDEN_FRAME]); - ctx.ref_frames[GOLDEN_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[ALTREF_FRAME]); - } - - if (ctx.reference_hdr.refresh_gf) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[GOLDEN_FRAME]); - ctx.ref_frames[GOLDEN_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[CURRENT_FRAME]); - } - - if (ctx.reference_hdr.refresh_arf) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[ALTREF_FRAME]); - ctx.ref_frames[ALTREF_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[CURRENT_FRAME]); - } - - if (ctx.reference_hdr.refresh_last) - { - vp8_dixie_release_ref_frame(ctx.ref_frames[LAST_FRAME]); - ctx.ref_frames[LAST_FRAME] = - vp8_dixie_ref_frame(ctx.ref_frames[CURRENT_FRAME]); - } - -} - - -//476 -function CHECK_FOR_UPDATE(lval,rval,update_flag) {do { - var old = lval; - update_flag[0] |= (old != (lval = rval)); - } while(0) - return lval; -} - -//481 -function -vp8_parse_frame_header(data, - sz, - hdr) -{ - var raw=long_; - - if (sz < 10) - return VPX_CODEC_CORRUPT_FRAME; - - /* The frame header is defined as a three byte little endian - * value - */ - raw = data[0] | (data[1] << 8) | (data[2] << 16); - hdr.is_keyframe = !BITS_GET(raw, 0, 1); - hdr.version = BITS_GET(raw, 1, 2); - hdr.is_experimental = BITS_GET(raw, 3, 1); - hdr.is_shown = BITS_GET(raw, 4, 1); - hdr.part0_sz = BITS_GET(raw, 5, 19); - - if (sz <= hdr.part0_sz + (hdr.is_keyframe ? 10 : 3)) - return VPX_CODEC_CORRUPT_FRAME; - - hdr.frame_size_updated = 0; - - if (hdr.is_keyframe) - { - var update = [0]; - - /* Keyframe header consists of a three byte sync code followed - * by the width and height and associated scaling factors. - */ - if (data[3] != 0x9d || data[4] != 0x01 || data[5] != 0x2a) - return VPX_CODEC_UNSUP_BITSTREAM; - - raw = data[6] | (data[7] << 8) - | (data[8] << 16) | (data[9] << 24); - hdr.kf.w = CHECK_FOR_UPDATE(hdr.kf.w, BITS_GET(raw, 0, 14), - update); - hdr.kf.scale_w = CHECK_FOR_UPDATE(hdr.kf.scale_w, BITS_GET(raw, 14, 2), - update); - hdr.kf.h = CHECK_FOR_UPDATE(hdr.kf.h, BITS_GET(raw, 16, 14), - update); - hdr.kf.scale_h = CHECK_FOR_UPDATE(hdr.kf.scale_h, BITS_GET(raw, 30, 2), - update); - - hdr.frame_size_updated = update[0]; - - if (!hdr.kf.w || !hdr.kf.h) - return VPX_CODEC_UNSUP_BITSTREAM; - } - - return VPX_CODEC_OK; -} - - -//537 -function -vp8_dixie_decode_frame(ctx, - data, - sz) -{ - var ctx_ = ctx; - - ctx.error.error_code = VPX_CODEC_OK; - ctx.error.has_detail = 0; - - if (!setjmp(ctx.error.jmp)) - decode_frame(ctx, data, 0, sz); - - return ctx_.error.error_code; -} - - -//554 -function -vp8_dixie_decode_destroy(ctx) -{ - vp8_dixie_predict_destroy(ctx); - vp8_dixie_tokens_destroy(ctx); - vp8_dixie_modemv_destroy(ctx); -} - - -//var vpx_codec_stream_info_t = vp8_stream_info_t; - -var vpx_codec_alg_priv = function() -{ - //base=new vpx_codec_priv_t(), - //cfg=newObjectI(vpx_codec_dec_cfg_t), - //si=newObjectI(vp8_stream_info_t), - decoder_ctx=new vp8_decoder_ctx(), - img=new vpx_image_t(), - img_avail=int_ -}; - - -function -update_error_state(ctx, - error) -{ - var res;//='vpx_codec_err_t' - - if ((res = error.error_code)) - ctx.base.err_detail = error.has_detail - ? error.detail - : null; - - return res; -} - - -function vp8_init(ctx) -{ - var res = VPX_CODEC_OK; - - /* This function only allocates space for the vpx_codec_alg_priv_t - * structure. More memory may be required at the time the stream - * information becomes known. - */ - if (!ctx.priv) - - { - var priv = new vpx_codec_alg_priv_t();//vpx_calloc(1, sizeof(vpx_codec_alg_priv_t)); - - ctx.priv = priv; - - if (!ctx.priv) - return VPX_CODEC_MEM_ERROR; - - ctx.priv.sz = 1/*sizeof(vpx_codec_alg_priv_t)*/; - ctx.priv.iface = ctx.iface; - ctx.priv.alg_priv = priv; - ctx.priv.init_flags = ctx.init_flags; - - if (ctx.config.dec) - { - /* Update the reference to the config structure to our copy. */ - ctx.priv.alg_priv.cfg = ctx.config.dec; - ctx.config.dec = ctx.priv.alg_priv.cfg; - } - } - - return res; -} - - -function vp8_destroy(ctx) -{ - vp8_dixie_decode_destroy(ctx.decoder_ctx); - ctx.base.alg_priv='';//vpx_free(ctx.base.alg_priv); - return VPX_CODEC_OK; -} - - -function vp8_peek_si(data, - data_sz, - si) -{ - var hdr=new vp8_frame_hdr(); - var res = VPX_CODEC_OK; - - - if (!(res = vp8_parse_frame_header(data, data_sz, hdr))) - { - si.is_kf = hdr.is_keyframe; - - if (si.is_kf) - { - si.w = hdr.kf.w; - si.h = hdr.kf.h; - } - else - { - si.w = 0; - si.h = 0; - } - } - - return res; - -} - - -function vp8_get_si(ctx, - si) -{ - - var sz=int_; - - if (si.sz >= 1/*sizeof(vp8_stream_info_t)*/) - sz = 1/*sizeof(vp8_stream_info_t)*/; - else - sz = 1/*sizeof(vpx_codec_stream_info_t)*/; - - memcpy(si, ctx.si, sz);alert('todo'); - si.sz = sz; - - return VPX_CODEC_OK; -} - - -function vp8_decode(ctx, - data, - data_sz, - user_priv, - deadline) -{ - var res = VPX_CODEC_OK; - - res = vp8_dixie_decode_frame(ctx.decoder_ctx, data, data_sz); - if(res) - update_error_state(ctx, ctx.decoder_ctx.error); - - ctx.img_avail = ctx.decoder_ctx.frame_hdr.is_shown; - ctx.img = ctx.decoder_ctx.ref_frames[CURRENT_FRAME].img; - return res; -} - - -function vp8_get_frame(ctx, - iter) -{ - var img = null; - - if (ctx.img_avail) - { - /* iter acts as a flip flop, so an image is only returned on the first - * call to get_frame. - */ - if (!(iter[0])) - { - img = ctx.img; - iter[0] = img; - } - } - - return img; -} - - -var ctf_maps = create_obj_vals_from_arrayChilds(vpx_codec_ctrl_fn_map_t, -[ - [ -1, null] -] -); - - -//#ifndef VERSION_STRING -//#define VERSION_STRING -//#endif -CODEC_INTERFACE('vpx_codec_vp8_dx', -//vpx_codec_iface_t vpx_codec_vp8_dx_algo = -new Array( - "VP8 \"Dixie\" Decoder" + VERSION_STRING, - VPX_CODEC_INTERNAL_ABI_VERSION, - VPX_CODEC_CAP_DECODER, - /* vpx_codec_caps_t caps; */ - 'vp8_init', /* vpx_codec_init_fn_t init; */ - 'vp8_destroy', /* vpx_codec_destroy_fn_t destroy; */ - 'ctf_maps', /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ - null, /* vpx_codec_get_mmap_fn_t get_mmap; */ - null, /* vpx_codec_set_mmap_fn_t set_mmap; */ - new Array( - 'vp8_peek_si', /* vpx_codec_peek_si_fn_t peek_si; */ - 'vp8_get_si', /* vpx_codec_get_si_fn_t get_si; */ - 'vp8_decode', /* vpx_codec_decode_fn_t decode; */ - 'vp8_get_frame' /* vpx_codec_frame_get_fn_t frame_get; */ - )//, - //{NOT_IMPLEMENTED} /* encoder functions */ -) -); - - - -function webmdata(response) { - //alert(response); - main(response);//convertBinaryToArray() -} -window['webmdata']=webmdata; - -var VP8_FOURCC = (0x00385056); //row:51 -var ifaces = new Array( -{ - name:char_, - iface:0,//'newObjectI(vpx_codec_iface_t)' - fourcc:int_, - fourcc_mask:int_ -}); -//#if CONFIG_VP8_DECODER - ifaces[0] = {name:"vp8", iface:new vpx_codec_vp8_dx_algo(), fourcc:VP8_FOURCC, fourcc_mask:0x00FFFFFF}; -//#endif - -var //enum file_kind 202 -//{ - RAW_FILE=0, - IVF_FILE=1, - WEBM_FILE=2 -//} -; - -var IVF_FRAME_HDR_SZ = (/*sizeof(uint32_t)**/4 + /*sizeof(uint64_t)**/8); -var RAW_FRAME_HDR_SZ = (/*sizeof(uint32_t)**/4); -function read_frame(input, - buf, - buf_off, - buf_sz, - buf_alloc_sz) -{ - var raw_hdr=new Array(IVF_FRAME_HDR_SZ);//Arr(IVF_FRAME_HDR_SZ,char); - var new_buf_sz=size_t; - var infile = input.infile; - var kind = input.kind; - if(kind == WEBM_FILE) - { - if(input.chunk >= input.chunks) - { - var track=[int_]; - - do - { - /* End of this packet, get another. */ - if(input.pkt) - nestegg_free_packet(input.pkt); - - if(nestegg_read_packet(input.nestegg_ctx, input.pkt) <= 0 - || nestegg_packet_track(input.pkt, track)) - return 1; - - } while(track != input.video_track); - - if(nestegg_packet_count(input.pkt, input.chunks))//todo: input.chunks with return val (defined) - return 1; - input.chunk = 0; - } - - if(nestegg_packet_data(input.pkt, input.chunk, buf, buf_sz)) - return 1; - input.chunk++; - - return 0; - } - /* For both the raw and ivf formats, the frame size is the first 4 bytes - * of the frame header. We just need to special case on the header - * size. - */ - /*not implemented - else if (fread(raw_hdr, kind==IVF_FILE - ? IVF_FRAME_HDR_SZ : RAW_FRAME_HDR_SZ, 1, infile) != 1) - { - if (!feof(infile)) - fprintf(stderr, "Failed to read frame size\n"); - - new_buf_sz = 0; - } - else - { - new_buf_sz = mem_get_le32(raw_hdr); - - if (new_buf_sz > 256 * 1024 * 1024) - { - fprintf(stderr, "Error: Read invalid frame size (%u)\n", - (unsigned int)new_buf_sz); - new_buf_sz = 0; - } - - if (kind == RAW_FILE && new_buf_sz > 256 * 1024) - fprintf(stderr, "Warning: Read invalid frame size (%u)" - " - not a raw file?\n", (unsigned int)new_buf_sz); - - if (new_buf_sz > *buf_alloc_sz) - { - uint8_t *new_buf = realloc(*buf, 2 * new_buf_sz); - - if (new_buf) - { - *buf = new_buf; - *buf_alloc_sz = 2 * new_buf_sz; - } - else - { - fprintf(stderr, "Failed to allocate compressed data buffer\n"); - new_buf_sz = 0; - } - } - }not implemnted*/ - - buf_sz[0] = new_buf_sz; - - if (buf_sz) - { - if (fread(buf, 1, buf_sz[0], infile) != buf_sz[0]) - { - fprintf(stderr, "Failed to read full frame\n");//todo: - return 1; - } - - return 0; - } - - return 1; -} - -var input_ctx = function() -{ - this.kind=0,//enum'file_kind' - this.infile=0,//*'FILE' - this.nestegg_ctx=new nestegg(),//* - this.pkt=[null],//newObjectI(nestegg_packet),//* - this.chunk=int_, - this.chunks=[int_], - this.video_track=int_ -}; - -function //479 -nestegg_read_cb(buffer, length, userdata) -{ - var f = userdata;//* - //userdata.val; - - if(fread(buffer, 1, length, f) < length) - { - /*if (ferror(f)) - return -1;*/ - if (feof(f)) - return 0; - } - return 1; -} - - -function //495 -nestegg_seek_cb(offset, whence, userdata) -{ - switch(whence) { - case NESTEGG_SEEK_SET: whence = SEEK_SET; break; - case NESTEGG_SEEK_CUR: whence = SEEK_CUR; break; - case NESTEGG_SEEK_END: whence = SEEK_END; break; - }; - return fseek(userdata, offset, whence)? -1 : 0; -} - - -function//508 -nestegg_tell_cb(userdata) -{ - return ftell(userdata); -} - - -//570 -function -file_is_webm(input, - fourcc, - width, - height, - fps_den, - fps_num) -{ - var i=int_, n=[int_]; - var track_type = -1; - - //todo by d nestegg_io - var io = {read:nestegg_read_cb, seek:nestegg_seek_cb, tell:nestegg_tell_cb, - userdata:input.infile};//nestegg_io - var params=new nestegg_video_params(); - input.nestegg_ctx = [input.nestegg_ctx]; - if(nestegg_init(input.nestegg_ctx, io, null)) - alert('goto fail'); - input.nestegg_ctx=input.nestegg_ctx[0]; - - if(nestegg_track_count(input.nestegg_ctx, n)) - alert('goto fail'); - - for(i=0; i1000 && ii>164)alert(ii+' '+buf_sz);if(ii<1) continue; - buf=buf[0]; // added by d - startdatum = new Date(); - - vp8_dixie_decode_frame(decoder2, buf, buf_sz); - buf=[buf]; // added by d - var img_avail = decoder2.frame_hdr.is_shown; - var img = decoder2.ref_frames[0].img; -///// -// var iter = [null];//vpx_codec_iter_t -// var img=newObjectI(vpx_image_t);// -// var timer=newObjectI(vpx_usec_timer); -// var corrupted=int_; -// ii++;++frame_in; -// vpx_usec_timer_start(timer);//&timer -// -// if (vpx_codec_decode(decoder, buf, buf_sz, null, 0)) -// { -// var detail = vpx_codec_error_detail(decoder); -// fprintf(stderr, "Failed to decode frame: %s\n", vpx_codec_error(decoder)); -// -// if (detail) -// fprintf(stderr, " Additional information: %s\n", detail); -// -// alert('goto fail'); -// } -// -// vpx_usec_timer_mark(timer); -// dx_time += vpx_usec_timer_elapsed(timer); -// -// ++frame_in; -// -//// /*todo:if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) -//// { -//// fprintf(stderr, "Failed VP8_GET_FRAME_CORRUPTED: %s\n", -//// vpx_codec_error(&decoder)); -//// goto fail; -//// }*/ -// frames_corrupted += corrupted; -// -// if ((img = vpx_codec_get_frame(decoder, iter))) -// ++frame_out; -////// - enddatum =new Date(); - getElementById_timecode.innerHTML=input.pkt[0].timecode+' ('+((input.pkt[0].timecode/1000000000)>>0)+' sec)'; - if(img_avail) { - getElementById_render.innerHTML=(enddatum-startdatum)+'ms
FPS:'+(1000/(enddatum-startdatum)).toFixed(2); - if (img) - vpximg2canvas(img); - ii++; - getElementById_frame.innerHTML=ii; - } - readframe(); - },0); - } - readframe(); - var enddatum =new Date(); - //alert(enddatum-startdatum+' '+ii+'frames'); -} \ No newline at end of file diff --git a/example/assets/css/style.css b/example/assets/css/style.css new file mode 100755 index 0000000..459976d --- /dev/null +++ b/example/assets/css/style.css @@ -0,0 +1,72 @@ + +*, *:before, *:after { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} + +html, body { + padding: 0; + margin: 0; + font-family: sans-serif; + font-size: 12px; + line-height: 160%; + background: #000; + width: 100%; + height: 100%; + color: #444; +} + +#container { + margin: 0 auto; + padding: 20px; + width: 90%; + max-width: 800px; + min-height: 100%; + background: #fff; +} + +#container pre { + padding: 15px; + font-size: 12px; + color: #777; + border: 1px solid #efefef; + font-family: Consolas, "Liberation Mono", Courier, monospace; + white-space: pre-wrap; + white-space: -moz-pre-wrap; + white-space: -pre-wrap; + white-space: -o-pre-wrap; + word-wrap: break-word; +} + +#container iframe { + margin: 0 auto; +} + +#container hr { + border: none; + background: #efefef; + width: 100%; + height: 1px; + display: block; + clear: left; + float: left; + margin: 40px 0; +} + +.flixel { + height: 0; + overflow: hidden; + position: relative; + padding-bottom: 56.25%; +} + +.flixel iframe { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} \ No newline at end of file diff --git a/example/assets/js/example.js b/example/assets/js/example.js new file mode 100644 index 0000000..e9b2c88 --- /dev/null +++ b/example/assets/js/example.js @@ -0,0 +1,28 @@ + +// DOM Ready +jQuery(function($){ + + // Get canvas + var canvas = $('#example')[0]; + + // AJAX Request for video data + $.ajax({ + type: 'GET', + mimeType: 'text/plain; charset=x-user-defined', + url: 'assets/videos/video.webm', + success: function(data){ + + // Normalize the data + data = data.split('').map(function(e){ + return e.charCodeAt(0) & 0xff; + }); + + // Create new instance of webm player with canvas object + var player = new webm(canvas); + + // Run player with video data + player.run(data); + } + }); + +}); \ No newline at end of file diff --git a/example/assets/js/jquery-1.9.1.min.js b/example/assets/js/jquery-1.9.1.min.js new file mode 100755 index 0000000..32d50cb --- /dev/null +++ b/example/assets/js/jquery-1.9.1.min.js @@ -0,0 +1,5 @@ +/*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license +//@ sourceMappingURL=jquery.min.map +*/(function(e,t){var n,r,i=typeof t,o=e.document,a=e.location,s=e.jQuery,u=e.$,l={},c=[],p="1.9.1",f=c.concat,d=c.push,h=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=p.trim,b=function(e,t){return new b.fn.init(e,t,r)},x=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^[\],:{}\s]*$/,E=/(?:^|:|,)(?:\s*\[)+/g,S=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,A=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,j=/^-ms-/,D=/-([\da-z])/gi,L=function(e,t){return t.toUpperCase()},H=function(e){(o.addEventListener||"load"===e.type||"complete"===o.readyState)&&(q(),b.ready())},q=function(){o.addEventListener?(o.removeEventListener("DOMContentLoaded",H,!1),e.removeEventListener("load",H,!1)):(o.detachEvent("onreadystatechange",H),e.detachEvent("onload",H))};b.fn=b.prototype={jquery:p,constructor:b,init:function(e,n,r){var i,a;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof b?n[0]:n,b.merge(this,b.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:o,!0)),C.test(i[1])&&b.isPlainObject(n))for(i in n)b.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(a=o.getElementById(i[2]),a&&a.parentNode){if(a.id!==i[2])return r.find(e);this.length=1,this[0]=a}return this.context=o,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):b.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),b.makeArray(e,this))},selector:"",length:0,size:function(){return this.length},toArray:function(){return h.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=b.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return b.each(this,e,t)},ready:function(e){return b.ready.promise().done(e),this},slice:function(){return this.pushStack(h.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(b.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:d,sort:[].sort,splice:[].splice},b.fn.init.prototype=b.fn,b.extend=b.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},u=1,l=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},u=2),"object"==typeof s||b.isFunction(s)||(s={}),l===u&&(s=this,--u);l>u;u++)if(null!=(o=arguments[u]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(b.isPlainObject(r)||(n=b.isArray(r)))?(n?(n=!1,a=e&&b.isArray(e)?e:[]):a=e&&b.isPlainObject(e)?e:{},s[i]=b.extend(c,a,r)):r!==t&&(s[i]=r));return s},b.extend({noConflict:function(t){return e.$===b&&(e.$=u),t&&e.jQuery===b&&(e.jQuery=s),b},isReady:!1,readyWait:1,holdReady:function(e){e?b.readyWait++:b.ready(!0)},ready:function(e){if(e===!0?!--b.readyWait:!b.isReady){if(!o.body)return setTimeout(b.ready);b.isReady=!0,e!==!0&&--b.readyWait>0||(n.resolveWith(o,[b]),b.fn.trigger&&b(o).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===b.type(e)},isArray:Array.isArray||function(e){return"array"===b.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[m.call(e)]||"object":typeof e},isPlainObject:function(e){if(!e||"object"!==b.type(e)||e.nodeType||b.isWindow(e))return!1;try{if(e.constructor&&!y.call(e,"constructor")&&!y.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}var r;for(r in e);return r===t||y.call(e,r)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||o;var r=C.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=b.buildFragment([e],t,i),i&&b(i).remove(),b.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=b.trim(n),n&&k.test(n.replace(S,"@").replace(A,"]").replace(E,"")))?Function("return "+n)():(b.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||b.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&b.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(j,"ms-").replace(D,L)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:v&&!v.call("\ufeff\u00a0")?function(e){return null==e?"":v.call(e)}:function(e){return null==e?"":(e+"").replace(T,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?b.merge(n,"string"==typeof e?[e]:e):d.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(g)return g.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return f.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),b.isFunction(e)?(r=h.call(arguments,2),i=function(){return e.apply(n||this,r.concat(h.call(arguments)))},i.guid=e.guid=e.guid||b.guid++,i):t},access:function(e,n,r,i,o,a,s){var u=0,l=e.length,c=null==r;if("object"===b.type(r)){o=!0;for(u in r)b.access(e,n,u,r[u],!0,a,s)}else if(i!==t&&(o=!0,b.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(b(e),n)})),n))for(;l>u;u++)n(e[u],r,s?i:i.call(e[u],u,n(e[u],r)));return o?e:c?n.call(e):l?n(e[0],r):a},now:function(){return(new Date).getTime()}}),b.ready.promise=function(t){if(!n)if(n=b.Deferred(),"complete"===o.readyState)setTimeout(b.ready);else if(o.addEventListener)o.addEventListener("DOMContentLoaded",H,!1),e.addEventListener("load",H,!1);else{o.attachEvent("onreadystatechange",H),e.attachEvent("onload",H);var r=!1;try{r=null==e.frameElement&&o.documentElement}catch(i){}r&&r.doScroll&&function a(){if(!b.isReady){try{r.doScroll("left")}catch(e){return setTimeout(a,50)}q(),b.ready()}}()}return n.promise(t)},b.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=b.type(e);return b.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=b(o);var _={};function F(e){var t=_[e]={};return b.each(e.match(w)||[],function(e,n){t[n]=!0}),t}b.Callbacks=function(e){e="string"==typeof e?_[e]||F(e):b.extend({},e);var n,r,i,o,a,s,u=[],l=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=u.length,n=!0;u&&o>a;a++)if(u[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,u&&(l?l.length&&c(l.shift()):r?u=[]:p.disable())},p={add:function(){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this},remove:function(){return u&&b.each(arguments,function(e,t){var r;while((r=b.inArray(t,u,r))>-1)u.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?b.inArray(e,u)>-1:!(!u||!u.length)},empty:function(){return u=[],this},disable:function(){return u=l=r=t,this},disabled:function(){return!u},lock:function(){return l=t,r||p.disable(),this},locked:function(){return!l},fireWith:function(e,t){return t=t||[],t=[e,t.slice?t.slice():t],!u||i&&!l||(n?l.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},b.extend({Deferred:function(e){var t=[["resolve","done",b.Callbacks("once memory"),"resolved"],["reject","fail",b.Callbacks("once memory"),"rejected"],["notify","progress",b.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return b.Deferred(function(n){b.each(t,function(t,o){var a=o[0],s=b.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&b.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?b.extend(e,r):r}},i={};return r.pipe=r.then,b.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=h.call(arguments),r=n.length,i=1!==r||e&&b.isFunction(e.promise)?r:0,o=1===i?e:b.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?h.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,u,l;if(r>1)for(s=Array(r),u=Array(r),l=Array(r);r>t;t++)n[t]&&b.isFunction(n[t].promise)?n[t].promise().done(a(t,l,n)).fail(o.reject).progress(a(t,u,s)):--i;return i||o.resolveWith(l,n),o.promise()}}),b.support=function(){var t,n,r,a,s,u,l,c,p,f,d=o.createElement("div");if(d.setAttribute("className","t"),d.innerHTML="
a",n=d.getElementsByTagName("*"),r=d.getElementsByTagName("a")[0],!n||!r||!n.length)return{};s=o.createElement("select"),l=s.appendChild(o.createElement("option")),a=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t={getSetAttribute:"t"!==d.className,leadingWhitespace:3===d.firstChild.nodeType,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/top/.test(r.getAttribute("style")),hrefNormalized:"/a"===r.getAttribute("href"),opacity:/^0.5/.test(r.style.opacity),cssFloat:!!r.style.cssFloat,checkOn:!!a.value,optSelected:l.selected,enctype:!!o.createElement("form").enctype,html5Clone:"<:nav>"!==o.createElement("nav").cloneNode(!0).outerHTML,boxModel:"CSS1Compat"===o.compatMode,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},a.checked=!0,t.noCloneChecked=a.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!l.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}a=o.createElement("input"),a.setAttribute("value",""),t.input=""===a.getAttribute("value"),a.value="t",a.setAttribute("type","radio"),t.radioValue="t"===a.value,a.setAttribute("checked","t"),a.setAttribute("name","t"),u=o.createDocumentFragment(),u.appendChild(a),t.appendChecked=a.checked,t.checkClone=u.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;return d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip,b(function(){var n,r,a,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",u=o.getElementsByTagName("body")[0];u&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",u.appendChild(n).appendChild(d),d.innerHTML="
t
",a=d.getElementsByTagName("td"),a[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===a[0].offsetHeight,a[0].style.display="",a[1].style.display="none",t.reliableHiddenOffsets=p&&0===a[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",t.boxSizing=4===d.offsetWidth,t.doesNotIncludeMarginInBodyOffset=1!==u.offsetTop,e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(o.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="
",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(u.style.zoom=1)),u.removeChild(n),n=d=a=r=null)}),n=s=u=l=r=a=null,t}();var O=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,B=/([A-Z])/g;function P(e,n,r,i){if(b.acceptData(e)){var o,a,s=b.expando,u="string"==typeof n,l=e.nodeType,p=l?b.cache:e,f=l?e[s]:e[s]&&s;if(f&&p[f]&&(i||p[f].data)||!u||r!==t)return f||(l?e[s]=f=c.pop()||b.guid++:f=s),p[f]||(p[f]={},l||(p[f].toJSON=b.noop)),("object"==typeof n||"function"==typeof n)&&(i?p[f]=b.extend(p[f],n):p[f].data=b.extend(p[f].data,n)),o=p[f],i||(o.data||(o.data={}),o=o.data),r!==t&&(o[b.camelCase(n)]=r),u?(a=o[n],null==a&&(a=o[b.camelCase(n)])):a=o,a}}function R(e,t,n){if(b.acceptData(e)){var r,i,o,a=e.nodeType,s=a?b.cache:e,u=a?e[b.expando]:b.expando;if(s[u]){if(t&&(o=n?s[u]:s[u].data)){b.isArray(t)?t=t.concat(b.map(t,b.camelCase)):t in o?t=[t]:(t=b.camelCase(t),t=t in o?[t]:t.split(" "));for(r=0,i=t.length;i>r;r++)delete o[t[r]];if(!(n?$:b.isEmptyObject)(o))return}(n||(delete s[u].data,$(s[u])))&&(a?b.cleanData([e],!0):b.support.deleteExpando||s!=s.window?delete s[u]:s[u]=null)}}}b.extend({cache:{},expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(e){return e=e.nodeType?b.cache[e[b.expando]]:e[b.expando],!!e&&!$(e)},data:function(e,t,n){return P(e,t,n)},removeData:function(e,t){return R(e,t)},_data:function(e,t,n){return P(e,t,n,!0)},_removeData:function(e,t){return R(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&b.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),b.fn.extend({data:function(e,n){var r,i,o=this[0],a=0,s=null;if(e===t){if(this.length&&(s=b.data(o),1===o.nodeType&&!b._data(o,"parsedAttrs"))){for(r=o.attributes;r.length>a;a++)i=r[a].name,i.indexOf("data-")||(i=b.camelCase(i.slice(5)),W(o,i,s[i]));b._data(o,"parsedAttrs",!0)}return s}return"object"==typeof e?this.each(function(){b.data(this,e)}):b.access(this,function(n){return n===t?o?W(o,e,b.data(o,e)):null:(this.each(function(){b.data(this,e,n)}),t)},null,n,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){b.removeData(this,e)})}});function W(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(B,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:O.test(r)?b.parseJSON(r):r}catch(o){}b.data(e,n,r)}else r=t}return r}function $(e){var t;for(t in e)if(("data"!==t||!b.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}b.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=b._data(e,n),r&&(!i||b.isArray(r)?i=b._data(e,n,b.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=b.queue(e,t),r=n.length,i=n.shift(),o=b._queueHooks(e,t),a=function(){b.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),o.cur=i,i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return b._data(e,n)||b._data(e,n,{empty:b.Callbacks("once memory").add(function(){b._removeData(e,t+"queue"),b._removeData(e,n)})})}}),b.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?b.queue(this[0],e):n===t?this:this.each(function(){var t=b.queue(this,e,n);b._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&b.dequeue(this,e)})},dequeue:function(e){return this.each(function(){b.dequeue(this,e)})},delay:function(e,t){return e=b.fx?b.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=b.Deferred(),a=this,s=this.length,u=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=b._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(u));return u(),o.promise(n)}});var I,z,X=/[\t\r\n]/g,U=/\r/g,V=/^(?:input|select|textarea|button|object)$/i,Y=/^(?:a|area)$/i,J=/^(?:checked|selected|autofocus|autoplay|async|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped)$/i,G=/^(?:checked|selected)$/i,Q=b.support.getSetAttribute,K=b.support.input;b.fn.extend({attr:function(e,t){return b.access(this,b.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){b.removeAttr(this,e)})},prop:function(e,t){return b.access(this,b.prop,e,t,arguments.length>1)},removeProp:function(e){return e=b.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,u="string"==typeof e&&e;if(b.isFunction(e))return this.each(function(t){b(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(X," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=b.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,u=0===arguments.length||"string"==typeof e&&e;if(b.isFunction(e))return this.each(function(t){b(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(X," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?b.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e,r="boolean"==typeof t;return b.isFunction(e)?this.each(function(n){b(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var o,a=0,s=b(this),u=t,l=e.match(w)||[];while(o=l[a++])u=r?u:!s.hasClass(o),s[u?"addClass":"removeClass"](o)}else(n===i||"boolean"===n)&&(this.className&&b._data(this,"__className__",this.className),this.className=this.className||e===!1?"":b._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(X," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=b.isFunction(e),this.each(function(n){var o,a=b(this);1===this.nodeType&&(o=i?e.call(this,n,a.val()):e,null==o?o="":"number"==typeof o?o+="":b.isArray(o)&&(o=b.map(o,function(e){return null==e?"":e+""})),r=b.valHooks[this.type]||b.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=b.valHooks[o.type]||b.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(U,""):null==n?"":n)}}}),b.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,u=0>i?s:o?i:0;for(;s>u;u++)if(n=r[u],!(!n.selected&&u!==i||(b.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&b.nodeName(n.parentNode,"optgroup"))){if(t=b(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n=b.makeArray(t);return b(e).find("option").each(function(){this.selected=b.inArray(b(this).val(),n)>=0}),n.length||(e.selectedIndex=-1),n}}},attr:function(e,n,r){var o,a,s,u=e.nodeType;if(e&&3!==u&&8!==u&&2!==u)return typeof e.getAttribute===i?b.prop(e,n,r):(a=1!==u||!b.isXMLDoc(e),a&&(n=n.toLowerCase(),o=b.attrHooks[n]||(J.test(n)?z:I)),r===t?o&&a&&"get"in o&&null!==(s=o.get(e,n))?s:(typeof e.getAttribute!==i&&(s=e.getAttribute(n)),null==s?t:s):null!==r?o&&a&&"set"in o&&(s=o.set(e,r,n))!==t?s:(e.setAttribute(n,r+""),r):(b.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=b.propFix[n]||n,J.test(n)?!Q&&G.test(n)?e[b.camelCase("default-"+n)]=e[r]=!1:e[r]=!1:b.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!b.support.radioValue&&"radio"===t&&b.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!b.isXMLDoc(e),a&&(n=b.propFix[n]||n,o=b.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var n=e.getAttributeNode("tabindex");return n&&n.specified?parseInt(n.value,10):V.test(e.nodeName)||Y.test(e.nodeName)&&e.href?0:t}}}}),z={get:function(e,n){var r=b.prop(e,n),i="boolean"==typeof r&&e.getAttribute(n),o="boolean"==typeof r?K&&Q?null!=i:G.test(n)?e[b.camelCase("default-"+n)]:!!i:e.getAttributeNode(n);return o&&o.value!==!1?n.toLowerCase():t},set:function(e,t,n){return t===!1?b.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&b.propFix[n]||n,n):e[b.camelCase("default-"+n)]=e[n]=!0,n}},K&&Q||(b.attrHooks.value={get:function(e,n){var r=e.getAttributeNode(n);return b.nodeName(e,"input")?e.defaultValue:r&&r.specified?r.value:t},set:function(e,n,r){return b.nodeName(e,"input")?(e.defaultValue=n,t):I&&I.set(e,n,r)}}),Q||(I=b.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&("id"===n||"name"===n||"coords"===n?""!==r.value:r.specified)?r.value:t},set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},b.attrHooks.contenteditable={get:I.get,set:function(e,t,n){I.set(e,""===t?!1:t,n)}},b.each(["width","height"],function(e,n){b.attrHooks[n]=b.extend(b.attrHooks[n],{set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}})})),b.support.hrefNormalized||(b.each(["href","src","width","height"],function(e,n){b.attrHooks[n]=b.extend(b.attrHooks[n],{get:function(e){var r=e.getAttribute(n,2);return null==r?t:r}})}),b.each(["href","src"],function(e,t){b.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}})),b.support.style||(b.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),b.support.optSelected||(b.propHooks.selected=b.extend(b.propHooks.selected,{get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}})),b.support.enctype||(b.propFix.enctype="encoding"),b.support.checkOn||b.each(["radio","checkbox"],function(){b.valHooks[this]={get:function(e){return null===e.getAttribute("value")?"on":e.value}}}),b.each(["radio","checkbox"],function(){b.valHooks[this]=b.extend(b.valHooks[this],{set:function(e,n){return b.isArray(n)?e.checked=b.inArray(b(e).val(),n)>=0:t}})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}b.event={global:{},add:function(e,n,r,o,a){var s,u,l,c,p,f,d,h,g,m,y,v=b._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=b.guid++),(u=v.events)||(u=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof b===i||e&&b.event.triggered===e.type?t:b.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(w)||[""],l=n.length;while(l--)s=rt.exec(n[l])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),p=b.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=b.event.special[g]||{},d=b.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&b.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=u[g])||(h=u[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),b.event.global[g]=!0;e=null}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,p,f,d,h,g,m=b.hasData(e)&&b._data(e);if(m&&(c=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(s=rt.exec(t[l])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=b.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),u=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));u&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||b.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)b.event.remove(e,d+t[l],n,r,!0);b.isEmptyObject(c)&&(delete m.handle,b._removeData(e,"events"))}},trigger:function(n,r,i,a){var s,u,l,c,p,f,d,h=[i||o],g=y.call(n,"type")?n.type:n,m=y.call(n,"namespace")?n.namespace.split("."):[];if(l=f=i=i||o,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+b.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),u=0>g.indexOf(":")&&"on"+g,n=n[b.expando]?n:new b.Event(g,"object"==typeof n&&n),n.isTrigger=!0,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:b.makeArray(r,[n]),p=b.event.special[g]||{},a||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!a&&!p.noBubble&&!b.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(l=l.parentNode);l;l=l.parentNode)h.push(l),f=l;f===(i.ownerDocument||o)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((l=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(b._data(l,"events")||{})[n.type]&&b._data(l,"handle"),s&&s.apply(l,r),s=u&&l[u],s&&b.acceptData(l)&&s.apply&&s.apply(l,r)===!1&&n.preventDefault();if(n.type=g,!(a||n.isDefaultPrevented()||p._default&&p._default.apply(i.ownerDocument,r)!==!1||"click"===g&&b.nodeName(i,"a")||!b.acceptData(i)||!u||!i[g]||b.isWindow(i))){f=i[u],f&&(i[u]=null),b.event.triggered=g;try{i[g]()}catch(v){}b.event.triggered=t,f&&(i[u]=f)}return n.result}},dispatch:function(e){e=b.event.fix(e);var n,r,i,o,a,s=[],u=h.call(arguments),l=(b._data(this,"events")||{})[e.type]||[],c=b.event.special[e.type]||{};if(u[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=b.event.handlers.call(this,e,l),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((b.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,u),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],u=n.delegateCount,l=e.target;if(u&&l.nodeType&&(!e.button||"click"!==e.type))for(;l!=this;l=l.parentNode||this)if(1===l.nodeType&&(l.disabled!==!0||"click"!==e.type)){for(o=[],a=0;u>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?b(r,this).index(l)>=0:b.find(r,this,null,[l]).length),o[r]&&o.push(i);o.length&&s.push({elem:l,handlers:o})}return n.length>u&&s.push({elem:this,handlers:n.slice(u)}),s},fix:function(e){if(e[b.expando])return e;var t,n,r,i=e.type,a=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new b.Event(a),t=r.length;while(t--)n=r[t],e[n]=a[n];return e.target||(e.target=a.srcElement||o),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,a):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,a,s=n.button,u=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||o,a=i.documentElement,r=i.body,e.pageX=n.clientX+(a&&a.scrollLeft||r&&r.scrollLeft||0)-(a&&a.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(a&&a.scrollTop||r&&r.scrollTop||0)-(a&&a.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&u&&(e.relatedTarget=u===e.target?n.toElement:u),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},click:{trigger:function(){return b.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t}},focus:{trigger:function(){if(this!==o.activeElement&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===o.activeElement&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=b.extend(new b.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?b.event.trigger(i,null,t):b.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},b.removeEvent=o.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},b.Event=function(e,n){return this instanceof b.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&b.extend(this,n),this.timeStamp=e&&e.timeStamp||b.now(),this[b.expando]=!0,t):new b.Event(e,n)},b.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},b.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){b.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj; +return(!i||i!==r&&!b.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),b.support.submitBubbles||(b.event.special.submit={setup:function(){return b.nodeName(this,"form")?!1:(b.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=b.nodeName(n,"input")||b.nodeName(n,"button")?n.form:t;r&&!b._data(r,"submitBubbles")&&(b.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),b._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&b.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return b.nodeName(this,"form")?!1:(b.event.remove(this,"._submit"),t)}}),b.support.changeBubbles||(b.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(b.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),b.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),b.event.simulate("change",this,e,!0)})),!1):(b.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!b._data(t,"changeBubbles")&&(b.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||b.event.simulate("change",this.parentNode,e,!0)}),b._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return b.event.remove(this,"._change"),!Z.test(this.nodeName)}}),b.support.focusinBubbles||b.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){b.event.simulate(t,e.target,b.event.fix(e),!0)};b.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),b.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return b().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=b.guid++)),this.each(function(){b.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,b(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){b.event.remove(this,e,r,n)})},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},trigger:function(e,t){return this.each(function(){b.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?b.event.trigger(e,n,r,!0):t}}),function(e,t){var n,r,i,o,a,s,u,l,c,p,f,d,h,g,m,y,v,x="sizzle"+-new Date,w=e.document,T={},N=0,C=0,k=it(),E=it(),S=it(),A=typeof t,j=1<<31,D=[],L=D.pop,H=D.push,q=D.slice,M=D.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},_="[\\x20\\t\\r\\n\\f]",F="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=F.replace("w","w#"),B="([*^$|!~]?=)",P="\\["+_+"*("+F+")"+_+"*(?:"+B+_+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+O+")|)|)"+_+"*\\]",R=":("+F+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+P.replace(3,8)+")*)|.*)\\)|)",W=RegExp("^"+_+"+|((?:^|[^\\\\])(?:\\\\.)*)"+_+"+$","g"),$=RegExp("^"+_+"*,"+_+"*"),I=RegExp("^"+_+"*([\\x20\\t\\r\\n\\f>+~])"+_+"*"),z=RegExp(R),X=RegExp("^"+O+"$"),U={ID:RegExp("^#("+F+")"),CLASS:RegExp("^\\.("+F+")"),NAME:RegExp("^\\[name=['\"]?("+F+")['\"]?\\]"),TAG:RegExp("^("+F.replace("w","w*")+")"),ATTR:RegExp("^"+P),PSEUDO:RegExp("^"+R),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+_+"*(even|odd|(([+-]|)(\\d*)n|)"+_+"*(?:([+-]|)"+_+"*(\\d+)|))"+_+"*\\)|)","i"),needsContext:RegExp("^"+_+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+_+"*((?:-\\d)?\\d*)"+_+"*\\)|)(?=[^-]|$)","i")},V=/[\x20\t\r\n\f]*[+~]/,Y=/^[^{]+\{\s*\[native code/,J=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,G=/^(?:input|select|textarea|button)$/i,Q=/^h\d$/i,K=/'|\\/g,Z=/\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,et=/\\([\da-fA-F]{1,6}[\x20\t\r\n\f]?|.)/g,tt=function(e,t){var n="0x"+t-65536;return n!==n?t:0>n?String.fromCharCode(n+65536):String.fromCharCode(55296|n>>10,56320|1023&n)};try{q.call(w.documentElement.childNodes,0)[0].nodeType}catch(nt){q=function(e){var t,n=[];while(t=this[e++])n.push(t);return n}}function rt(e){return Y.test(e+"")}function it(){var e,t=[];return e=function(n,r){return t.push(n+=" ")>i.cacheLength&&delete e[t.shift()],e[n]=r}}function ot(e){return e[x]=!0,e}function at(e){var t=p.createElement("div");try{return e(t)}catch(n){return!1}finally{t=null}}function st(e,t,n,r){var i,o,a,s,u,l,f,g,m,v;if((t?t.ownerDocument||t:w)!==p&&c(t),t=t||p,n=n||[],!e||"string"!=typeof e)return n;if(1!==(s=t.nodeType)&&9!==s)return[];if(!d&&!r){if(i=J.exec(e))if(a=i[1]){if(9===s){if(o=t.getElementById(a),!o||!o.parentNode)return n;if(o.id===a)return n.push(o),n}else if(t.ownerDocument&&(o=t.ownerDocument.getElementById(a))&&y(t,o)&&o.id===a)return n.push(o),n}else{if(i[2])return H.apply(n,q.call(t.getElementsByTagName(e),0)),n;if((a=i[3])&&T.getByClassName&&t.getElementsByClassName)return H.apply(n,q.call(t.getElementsByClassName(a),0)),n}if(T.qsa&&!h.test(e)){if(f=!0,g=x,m=t,v=9===s&&e,1===s&&"object"!==t.nodeName.toLowerCase()){l=ft(e),(f=t.getAttribute("id"))?g=f.replace(K,"\\$&"):t.setAttribute("id",g),g="[id='"+g+"'] ",u=l.length;while(u--)l[u]=g+dt(l[u]);m=V.test(e)&&t.parentNode||t,v=l.join(",")}if(v)try{return H.apply(n,q.call(m.querySelectorAll(v),0)),n}catch(b){}finally{f||t.removeAttribute("id")}}}return wt(e.replace(W,"$1"),t,n,r)}a=st.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},c=st.setDocument=function(e){var n=e?e.ownerDocument||e:w;return n!==p&&9===n.nodeType&&n.documentElement?(p=n,f=n.documentElement,d=a(n),T.tagNameNoComments=at(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),T.attributes=at(function(e){e.innerHTML="";var t=typeof e.lastChild.getAttribute("multiple");return"boolean"!==t&&"string"!==t}),T.getByClassName=at(function(e){return e.innerHTML="",e.getElementsByClassName&&e.getElementsByClassName("e").length?(e.lastChild.className="e",2===e.getElementsByClassName("e").length):!1}),T.getByName=at(function(e){e.id=x+0,e.innerHTML="
",f.insertBefore(e,f.firstChild);var t=n.getElementsByName&&n.getElementsByName(x).length===2+n.getElementsByName(x+0).length;return T.getIdNotName=!n.getElementById(x),f.removeChild(e),t}),i.attrHandle=at(function(e){return e.innerHTML="",e.firstChild&&typeof e.firstChild.getAttribute!==A&&"#"===e.firstChild.getAttribute("href")})?{}:{href:function(e){return e.getAttribute("href",2)},type:function(e){return e.getAttribute("type")}},T.getIdNotName?(i.find.ID=function(e,t){if(typeof t.getElementById!==A&&!d){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(et,tt);return function(e){return e.getAttribute("id")===t}}):(i.find.ID=function(e,n){if(typeof n.getElementById!==A&&!d){var r=n.getElementById(e);return r?r.id===e||typeof r.getAttributeNode!==A&&r.getAttributeNode("id").value===e?[r]:t:[]}},i.filter.ID=function(e){var t=e.replace(et,tt);return function(e){var n=typeof e.getAttributeNode!==A&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=T.tagNameNoComments?function(e,n){return typeof n.getElementsByTagName!==A?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.NAME=T.getByName&&function(e,n){return typeof n.getElementsByName!==A?n.getElementsByName(name):t},i.find.CLASS=T.getByClassName&&function(e,n){return typeof n.getElementsByClassName===A||d?t:n.getElementsByClassName(e)},g=[],h=[":focus"],(T.qsa=rt(n.querySelectorAll))&&(at(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||h.push("\\["+_+"*(?:checked|disabled|ismap|multiple|readonly|selected|value)"),e.querySelectorAll(":checked").length||h.push(":checked")}),at(function(e){e.innerHTML="",e.querySelectorAll("[i^='']").length&&h.push("[*^$]="+_+"*(?:\"\"|'')"),e.querySelectorAll(":enabled").length||h.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),h.push(",.*:")})),(T.matchesSelector=rt(m=f.matchesSelector||f.mozMatchesSelector||f.webkitMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&at(function(e){T.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",R)}),h=RegExp(h.join("|")),g=RegExp(g.join("|")),y=rt(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},v=f.compareDocumentPosition?function(e,t){var r;return e===t?(u=!0,0):(r=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t))?1&r||e.parentNode&&11===e.parentNode.nodeType?e===n||y(w,e)?-1:t===n||y(w,t)?1:0:4&r?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return u=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:0;if(o===a)return ut(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?ut(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},u=!1,[0,0].sort(v),T.detectDuplicates=u,p):p},st.matches=function(e,t){return st(e,null,null,t)},st.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Z,"='$1']"),!(!T.matchesSelector||d||g&&g.test(t)||h.test(t)))try{var n=m.call(e,t);if(n||T.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(r){}return st(t,p,null,[e]).length>0},st.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},st.attr=function(e,t){var n;return(e.ownerDocument||e)!==p&&c(e),d||(t=t.toLowerCase()),(n=i.attrHandle[t])?n(e):d||T.attributes?e.getAttribute(t):((n=e.getAttributeNode(t))||e.getAttribute(t))&&e[t]===!0?t:n&&n.specified?n.value:null},st.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},st.uniqueSort=function(e){var t,n=[],r=1,i=0;if(u=!T.detectDuplicates,e.sort(v),u){for(;t=e[r];r++)t===e[r-1]&&(i=n.push(r));while(i--)e.splice(n[i],1)}return e};function ut(e,t){var n=t&&e,r=n&&(~t.sourceIndex||j)-(~e.sourceIndex||j);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function lt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ct(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function pt(e){return ot(function(t){return t=+t,ot(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}o=st.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=st.selectors={cacheLength:50,createPseudo:ot,match:U,find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(et,tt),e[3]=(e[4]||e[5]||"").replace(et,tt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||st.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&st.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return U.CHILD.test(e[0])?null:(e[4]?e[2]=e[4]:n&&z.test(n)&&(t=ft(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){return"*"===e?function(){return!0}:(e=e.replace(et,tt).toLowerCase(),function(t){return t.nodeName&&t.nodeName.toLowerCase()===e})},CLASS:function(e){var t=k[e+" "];return t||(t=RegExp("(^|"+_+")"+e+"("+_+"|$)"))&&k(e,function(e){return t.test(e.className||typeof e.getAttribute!==A&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=st.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!u&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[x]||(m[x]={}),l=c[e]||[],d=l[0]===N&&l[1],f=l[0]===N&&l[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[N,d,f];break}}else if(v&&(l=(t[x]||(t[x]={}))[e])&&l[0]===N)f=l[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[x]||(p[x]={}))[e]=[N,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||st.error("unsupported pseudo: "+e);return r[x]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?ot(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=M.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:ot(function(e){var t=[],n=[],r=s(e.replace(W,"$1"));return r[x]?ot(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:ot(function(e){return function(t){return st(e,t).length>0}}),contains:ot(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:ot(function(e){return X.test(e||"")||st.error("unsupported lang: "+e),e=e.replace(et,tt).toLowerCase(),function(t){var n;do if(n=d?t.getAttribute("xml:lang")||t.getAttribute("lang"):t.lang)return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return Q.test(e.nodeName)},input:function(e){return G.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:pt(function(){return[0]}),last:pt(function(e,t){return[t-1]}),eq:pt(function(e,t,n){return[0>n?n+t:n]}),even:pt(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:pt(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:pt(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:pt(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}};for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[n]=lt(n);for(n in{submit:!0,reset:!0})i.pseudos[n]=ct(n);function ft(e,t){var n,r,o,a,s,u,l,c=E[e+" "];if(c)return t?0:c.slice(0);s=e,u=[],l=i.preFilter;while(s){(!n||(r=$.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),u.push(o=[])),n=!1,(r=I.exec(s))&&(n=r.shift(),o.push({value:n,type:r[0].replace(W," ")}),s=s.slice(n.length));for(a in i.filter)!(r=U[a].exec(s))||l[a]&&!(r=l[a](r))||(n=r.shift(),o.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?st.error(e):E(e,u).slice(0)}function dt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function ht(e,t,n){var i=t.dir,o=n&&"parentNode"===i,a=C++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,s){var u,l,c,p=N+" "+a;if(s){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[x]||(t[x]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,s)||r,l[1]===!0)return!0}}function gt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function mt(e,t,n,r,i){var o,a=[],s=0,u=e.length,l=null!=t;for(;u>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),l&&t.push(s));return a}function yt(e,t,n,r,i,o){return r&&!r[x]&&(r=yt(r)),i&&!i[x]&&(i=yt(i,o)),ot(function(o,a,s,u){var l,c,p,f=[],d=[],h=a.length,g=o||xt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:mt(g,f,e,s,u),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,u),r){l=mt(y,d),r(l,[],s,u),c=l.length;while(c--)(p=l[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?M.call(o,p):f[c])>-1&&(o[l]=!(a[l]=p))}}else y=mt(y===a?y.splice(h,y.length):y),i?i(null,a,y,u):H.apply(a,y)})}function vt(e){var t,n,r,o=e.length,a=i.relative[e[0].type],s=a||i.relative[" "],u=a?1:0,c=ht(function(e){return e===t},s,!0),p=ht(function(e){return M.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==l)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>u;u++)if(n=i.relative[e[u].type])f=[ht(gt(f),n)];else{if(n=i.filter[e[u].type].apply(null,e[u].matches),n[x]){for(r=++u;o>r;r++)if(i.relative[e[r].type])break;return yt(u>1&>(f),u>1&&dt(e.slice(0,u-1)).replace(W,"$1"),n,r>u&&vt(e.slice(u,r)),o>r&&vt(e=e.slice(r)),o>r&&dt(e))}f.push(n)}return gt(f)}function bt(e,t){var n=0,o=t.length>0,a=e.length>0,s=function(s,u,c,f,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,T=l,C=s||a&&i.find.TAG("*",d&&u.parentNode||u),k=N+=null==T?1:Math.random()||.1;for(w&&(l=u!==p&&u,r=n);null!=(h=C[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,u,c)){f.push(h);break}w&&(N=k,r=++n)}o&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,o&&b!==v){g=0;while(m=t[g++])m(x,y,u,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=L.call(f));y=mt(y)}H.apply(f,y),w&&!s&&y.length>0&&v+t.length>1&&st.uniqueSort(f)}return w&&(N=k,l=T),x};return o?ot(s):s}s=st.compile=function(e,t){var n,r=[],i=[],o=S[e+" "];if(!o){t||(t=ft(e)),n=t.length;while(n--)o=vt(t[n]),o[x]?r.push(o):i.push(o);o=S(e,bt(i,r))}return o};function xt(e,t,n){var r=0,i=t.length;for(;i>r;r++)st(e,t[r],n);return n}function wt(e,t,n,r){var o,a,u,l,c,p=ft(e);if(!r&&1===p.length){if(a=p[0]=p[0].slice(0),a.length>2&&"ID"===(u=a[0]).type&&9===t.nodeType&&!d&&i.relative[a[1].type]){if(t=i.find.ID(u.matches[0].replace(et,tt),t)[0],!t)return n;e=e.slice(a.shift().value.length)}o=U.needsContext.test(e)?0:a.length;while(o--){if(u=a[o],i.relative[l=u.type])break;if((c=i.find[l])&&(r=c(u.matches[0].replace(et,tt),V.test(a[0].type)&&t.parentNode||t))){if(a.splice(o,1),e=r.length&&dt(a),!e)return H.apply(n,q.call(r,0)),n;break}}}return s(e,p)(r,t,d,n,V.test(e)),n}i.pseudos.nth=i.pseudos.eq;function Tt(){}i.filters=Tt.prototype=i.pseudos,i.setFilters=new Tt,c(),st.attr=b.attr,b.find=st,b.expr=st.selectors,b.expr[":"]=b.expr.pseudos,b.unique=st.uniqueSort,b.text=st.getText,b.isXMLDoc=st.isXML,b.contains=st.contains}(e);var at=/Until$/,st=/^(?:parents|prev(?:Until|All))/,ut=/^.[^:#\[\.,]*$/,lt=b.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};b.fn.extend({find:function(e){var t,n,r,i=this.length;if("string"!=typeof e)return r=this,this.pushStack(b(e).filter(function(){for(t=0;i>t;t++)if(b.contains(r[t],this))return!0}));for(n=[],t=0;i>t;t++)b.find(e,this[t],n);return n=this.pushStack(i>1?b.unique(n):n),n.selector=(this.selector?this.selector+" ":"")+e,n},has:function(e){var t,n=b(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(b.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e,!1))},filter:function(e){return this.pushStack(ft(this,e,!0))},is:function(e){return!!e&&("string"==typeof e?lt.test(e)?b(e,this.context).index(this[0])>=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(e,t){var n,r=0,i=this.length,o=[],a=lt.test(e)||"string"!=typeof e?b(e,t||this.context):0;for(;i>r;r++){n=this[r];while(n&&n.ownerDocument&&n!==t&&11!==n.nodeType){if(a?a.index(n)>-1:b.find.matchesSelector(n,e)){o.push(n);break}n=n.parentNode}}return this.pushStack(o.length>1?b.unique(o):o)},index:function(e){return e?"string"==typeof e?b.inArray(this[0],b(e)):b.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?b(e,t):b.makeArray(e&&e.nodeType?[e]:e),r=b.merge(this.get(),n);return this.pushStack(b.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),b.fn.andSelf=b.fn.addBack;function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}b.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(e,t,n){return b.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(e,t,n){return b.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return b.dir(e,"previousSibling",n)},siblings:function(e){return b.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.merge([],e.childNodes)}},function(e,t){b.fn[e]=function(n,r){var i=b.map(this,t,n);return at.test(e)||(r=n),r&&"string"==typeof r&&(i=b.filter(r,i)),i=this.length>1&&!ct[e]?b.unique(i):i,this.length>1&&st.test(e)&&(i=i.reverse()),this.pushStack(i)}}),b.extend({filter:function(e,t,n){return n&&(e=":not("+e+")"),1===t.length?b.find.matchesSelector(t[0],e)?[t[0]]:[]:b.find.matches(e,t)},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!b(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(t=t||0,b.isFunction(t))return b.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return b.grep(e,function(e){return e===t===n});if("string"==typeof t){var r=b.grep(e,function(e){return 1===e.nodeType});if(ut.test(t))return b.filter(t,r,!n);t=b.filter(t,r)}return b.grep(e,function(e){return b.inArray(e,t)>=0===n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/\s*$/g,At={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:b.support.htmlSerialize?[0,"",""]:[1,"X
","
"]},jt=dt(o),Dt=jt.appendChild(o.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,b.fn.extend({text:function(e){return b.access(this,function(e){return e===t?b.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},wrapAll:function(e){if(b.isFunction(e))return this.each(function(t){b(this).wrapAll(e.call(this,t))});if(this[0]){var t=b(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return b.isFunction(e)?this.each(function(t){b(this).wrapInner(e.call(this,t))}):this.each(function(){var t=b(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=b.isFunction(e);return this.each(function(n){b(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){b.nodeName(this,"body")||b(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&this.appendChild(e)})},prepend:function(){return this.domManip(arguments,!0,function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&this.insertBefore(e,this.firstChild)})},before:function(){return this.domManip(arguments,!1,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,!1,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=0;for(;null!=(n=this[r]);r++)(!e||b.filter(e,[n]).length>0)&&(t||1!==n.nodeType||b.cleanData(Ot(n)),n.parentNode&&(t&&b.contains(n.ownerDocument,n)&&Mt(Ot(n,"script")),n.parentNode.removeChild(n)));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&b.cleanData(Ot(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&b.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return b.clone(this,e,t)})},html:function(e){return b.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!b.support.htmlSerialize&&mt.test(e)||!b.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(b.cleanData(Ot(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(e){var t=b.isFunction(e);return t||"string"==typeof e||(e=b(e).not(this).detach()),this.domManip([e],!0,function(e){var t=this.nextSibling,n=this.parentNode;n&&(b(this).remove(),n.insertBefore(e,t))})},detach:function(e){return this.remove(e,!0)},domManip:function(e,n,r){e=f.apply([],e);var i,o,a,s,u,l,c=0,p=this.length,d=this,h=p-1,g=e[0],m=b.isFunction(g);if(m||!(1>=p||"string"!=typeof g||b.support.checkClone)&&Ct.test(g))return this.each(function(i){var o=d.eq(i);m&&(e[0]=g.call(this,i,n?o.html():t)),o.domManip(e,n,r)});if(p&&(l=b.buildFragment(e,this[0].ownerDocument,!1,this),i=l.firstChild,1===l.childNodes.length&&(l=i),i)){for(n=n&&b.nodeName(i,"tr"),s=b.map(Ot(l,"script"),Ht),a=s.length;p>c;c++)o=l,c!==h&&(o=b.clone(o,!0,!0),a&&b.merge(s,Ot(o,"script"))),r.call(n&&b.nodeName(this[c],"table")?Lt(this[c],"tbody"):this[c],o,c);if(a)for(u=s[s.length-1].ownerDocument,b.map(s,qt),c=0;a>c;c++)o=s[c],kt.test(o.type||"")&&!b._data(o,"globalEval")&&b.contains(u,o)&&(o.src?b.ajax({url:o.src,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0}):b.globalEval((o.text||o.textContent||o.innerHTML||"").replace(St,"")));l=i=null}return this}});function Lt(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function Ht(e){var t=e.getAttributeNode("type");return e.type=(t&&t.specified)+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function Mt(e,t){var n,r=0;for(;null!=(n=e[r]);r++)b._data(n,"globalEval",!t||b._data(t[r],"globalEval"))}function _t(e,t){if(1===t.nodeType&&b.hasData(e)){var n,r,i,o=b._data(e),a=b._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)b.event.add(t,n,s[n][r])}a.data&&(a.data=b.extend({},a.data))}}function Ft(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!b.support.noCloneEvent&&t[b.expando]){i=b._data(t);for(r in i.events)b.removeEvent(t,r,i.handle);t.removeAttribute(b.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),b.support.html5Clone&&e.innerHTML&&!b.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Nt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}b.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){b.fn[e]=function(e){var n,r=0,i=[],o=b(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),b(o[r])[t](n),d.apply(i,n.get());return this.pushStack(i)}});function Ot(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||b.nodeName(o,n)?s.push(o):b.merge(s,Ot(o,n));return n===t||n&&b.nodeName(e,n)?b.merge([e],s):s}function Bt(e){Nt.test(e.type)&&(e.defaultChecked=e.checked)}b.extend({clone:function(e,t,n){var r,i,o,a,s,u=b.contains(e.ownerDocument,e);if(b.support.html5Clone||b.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(b.support.noCloneEvent&&b.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||b.isXMLDoc(e)))for(r=Ot(o),s=Ot(e),a=0;null!=(i=s[a]);++a)r[a]&&Ft(i,r[a]);if(t)if(n)for(s=s||Ot(e),r=r||Ot(o),a=0;null!=(i=s[a]);a++)_t(i,r[a]);else _t(e,o);return r=Ot(o,"script"),r.length>0&&Mt(r,!u&&Ot(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,u,l,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===b.type(o))b.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),u=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[u]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!b.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!b.support.tbody){o="table"!==u||xt.test(o)?""!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)b.nodeName(l=o.childNodes[i],"tbody")&&!l.childNodes.length&&o.removeChild(l) +}b.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),b.support.appendChecked||b.grep(Ot(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===b.inArray(o,r))&&(a=b.contains(o.ownerDocument,o),s=Ot(f.appendChild(o),"script"),a&&Mt(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,u=b.expando,l=b.cache,p=b.support.deleteExpando,f=b.event.special;for(;null!=(n=e[s]);s++)if((t||b.acceptData(n))&&(o=n[u],a=o&&l[o])){if(a.events)for(r in a.events)f[r]?b.event.remove(n,r):b.removeEvent(n,r,a.handle);l[o]&&(delete l[o],p?delete n[u]:typeof n.removeAttribute!==i?n.removeAttribute(u):n[u]=null,c.push(o))}}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+x+")(.*)$","i"),Yt=RegExp("^("+x+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+x+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===b.css(e,"display")||!b.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=b._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=b._data(r,"olddisplay",un(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&b._data(r,"olddisplay",i?n:b.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}b.fn.extend({css:function(e,n){return b.access(this,function(e,n,r){var i,o,a={},s=0;if(b.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=b.css(e,n[s],!1,o);return a}return r!==t?b.style(e,n,r):b.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){var t="boolean"==typeof e;return this.each(function(){(t?e:nn(this))?b(this).show():b(this).hide()})}}),b.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":b.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,u=b.camelCase(n),l=e.style;if(n=b.cssProps[u]||(b.cssProps[u]=tn(l,u)),s=b.cssHooks[n]||b.cssHooks[u],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:l[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(b.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||b.cssNumber[u]||(r+="px"),b.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(l[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{l[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,u=b.camelCase(n);return n=b.cssProps[u]||(b.cssProps[u]=tn(e.style,u)),s=b.cssHooks[n]||b.cssHooks[u],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||b.isNumeric(o)?o||0:a):a},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),u=s?s.getPropertyValue(n)||s[n]:t,l=e.style;return s&&(""!==u||b.contains(e.ownerDocument,e)||(u=b.style(e,n)),Yt.test(u)&&Ut.test(n)&&(i=l.width,o=l.minWidth,a=l.maxWidth,l.minWidth=l.maxWidth=l.width=u,u=s.width,l.width=i,l.minWidth=o,l.maxWidth=a)),u}):o.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),u=s?s[n]:t,l=e.style;return null==u&&l&&l[n]&&(u=l[n]),Yt.test(u)&&!zt.test(n)&&(i=l.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),l.left="fontSize"===n?"1em":u,u=l.pixelLeft+"px",l.left=i,a&&(o.left=a)),""===u?"auto":u});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=b.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=b.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=b.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=b.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=b.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=b.support.boxSizing&&"border-box"===b.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(b.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function un(e){var t=o,n=Gt[e];return n||(n=ln(e,t),"none"!==n&&n||(Pt=(Pt||b("