Added theora to libs

This commit is contained in:
pelya
2011-01-13 14:59:44 +00:00
parent 0a89f2b707
commit e7ac2e0295
56 changed files with 25221 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,166 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: apiwrapper.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "apiwrapper.h"
const char *theora_version_string(void){
return th_version_string();
}
ogg_uint32_t theora_version_number(void){
return th_version_number();
}
void theora_info_init(theora_info *_ci){
memset(_ci,0,sizeof(*_ci));
}
void theora_info_clear(theora_info *_ci){
th_api_wrapper *api;
api=(th_api_wrapper *)_ci->codec_setup;
memset(_ci,0,sizeof(*_ci));
if(api!=NULL){
if(api->clear!=NULL)(*api->clear)(api);
_ogg_free(api);
}
}
void theora_clear(theora_state *_th){
/*Provide compatibility with mixed encoder and decoder shared lib versions.*/
if(_th->internal_decode!=NULL){
(*((oc_state_dispatch_vtable *)_th->internal_decode)->clear)(_th);
}
if(_th->internal_encode!=NULL){
(*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th);
}
if(_th->i!=NULL)theora_info_clear(_th->i);
memset(_th,0,sizeof(*_th));
}
int theora_control(theora_state *_th,int _req,void *_buf,size_t _buf_sz){
/*Provide compatibility with mixed encoder and decoder shared lib versions.*/
if(_th->internal_decode!=NULL){
return (*((oc_state_dispatch_vtable *)_th->internal_decode)->control)(_th,
_req,_buf,_buf_sz);
}
else if(_th->internal_encode!=NULL){
return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th,
_req,_buf,_buf_sz);
}
else return TH_EINVAL;
}
ogg_int64_t theora_granule_frame(theora_state *_th,ogg_int64_t _gp){
/*Provide compatibility with mixed encoder and decoder shared lib versions.*/
if(_th->internal_decode!=NULL){
return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_frame)(
_th,_gp);
}
else if(_th->internal_encode!=NULL){
return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)(
_th,_gp);
}
else return -1;
}
double theora_granule_time(theora_state *_th, ogg_int64_t _gp){
/*Provide compatibility with mixed encoder and decoder shared lib versions.*/
if(_th->internal_decode!=NULL){
return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_time)(
_th,_gp);
}
else if(_th->internal_encode!=NULL){
return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)(
_th,_gp);
}
else return -1;
}
void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){
_info->version_major=_ci->version_major;
_info->version_minor=_ci->version_minor;
_info->version_subminor=_ci->version_subminor;
_info->frame_width=_ci->width;
_info->frame_height=_ci->height;
_info->pic_width=_ci->frame_width;
_info->pic_height=_ci->frame_height;
_info->pic_x=_ci->offset_x;
_info->pic_y=_ci->offset_y;
_info->fps_numerator=_ci->fps_numerator;
_info->fps_denominator=_ci->fps_denominator;
_info->aspect_numerator=_ci->aspect_numerator;
_info->aspect_denominator=_ci->aspect_denominator;
switch(_ci->colorspace){
case OC_CS_ITU_REC_470M:_info->colorspace=TH_CS_ITU_REC_470M;break;
case OC_CS_ITU_REC_470BG:_info->colorspace=TH_CS_ITU_REC_470BG;break;
default:_info->colorspace=TH_CS_UNSPECIFIED;break;
}
switch(_ci->pixelformat){
case OC_PF_420:_info->pixel_fmt=TH_PF_420;break;
case OC_PF_422:_info->pixel_fmt=TH_PF_422;break;
case OC_PF_444:_info->pixel_fmt=TH_PF_444;break;
default:_info->pixel_fmt=TH_PF_RSVD;
}
_info->target_bitrate=_ci->target_bitrate;
_info->quality=_ci->quality;
_info->keyframe_granule_shift=_ci->keyframe_frequency_force>0?
OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0;
}
int theora_packet_isheader(ogg_packet *_op){
return th_packet_isheader(_op);
}
int theora_packet_iskeyframe(ogg_packet *_op){
return th_packet_iskeyframe(_op);
}
int theora_granule_shift(theora_info *_ci){
/*This breaks when keyframe_frequency_force is not positive or is larger than
2**31 (if your int is more than 32 bits), but that's what the original
function does.*/
return oc_ilog(_ci->keyframe_frequency_force-1);
}
void theora_comment_init(theora_comment *_tc){
th_comment_init((th_comment *)_tc);
}
char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){
return th_comment_query((th_comment *)_tc,_tag,_count);
}
int theora_comment_query_count(theora_comment *_tc,char *_tag){
return th_comment_query_count((th_comment *)_tc,_tag);
}
void theora_comment_clear(theora_comment *_tc){
th_comment_clear((th_comment *)_tc);
}
void theora_comment_add(theora_comment *_tc,char *_comment){
th_comment_add((th_comment *)_tc,_comment);
}
void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){
th_comment_add_tag((th_comment *)_tc,_tag,_value);
}

View File

@@ -0,0 +1,54 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: apiwrapper.h 13596 2007-08-23 20:05:38Z tterribe $
********************************************************************/
#if !defined(_apiwrapper_H)
# define _apiwrapper_H (1)
# include <ogg/ogg.h>
# include <theora/theora.h>
# include "theora/theoradec.h"
# include "theora/theoraenc.h"
# include "internal.h"
typedef struct th_api_wrapper th_api_wrapper;
typedef struct th_api_info th_api_info;
/*Provide an entry point for the codec setup to clear itself in case we ever
want to break pieces off into a common base library shared by encoder and
decoder.
In addition, this makes several other pieces of the API wrapper cleaner.*/
typedef void (*oc_setup_clear_func)(void *_ts);
/*Generally only one of these pointers will be non-NULL in any given instance.
Technically we do not even really need this struct, since we should be able
to figure out which one from "context", but doing it this way makes sure we
don't flub it up.*/
struct th_api_wrapper{
oc_setup_clear_func clear;
th_setup_info *setup;
th_dec_ctx *decode;
th_enc_ctx *encode;
};
struct th_api_info{
th_api_wrapper api;
theora_info info;
};
void oc_theora_info2th_info(th_info *_info,const theora_info *_ci);
#endif

View File

@@ -0,0 +1,111 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggTheora SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function: packing variable sized words into an octet stream
last mod: $Id: bitpack.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <string.h>
#include <stdlib.h>
#include "bitpack.h"
/*We're 'MSb' endian; if we write a word but read individual bits,
then we'll read the MSb first.*/
void oc_pack_readinit(oc_pack_buf *_b,unsigned char *_buf,long _bytes){
memset(_b,0,sizeof(*_b));
_b->ptr=_buf;
_b->stop=_buf+_bytes;
}
static oc_pb_window oc_pack_refill(oc_pack_buf *_b,int _bits){
const unsigned char *ptr;
const unsigned char *stop;
oc_pb_window window;
int available;
window=_b->window;
available=_b->bits;
ptr=_b->ptr;
stop=_b->stop;
while(available<=OC_PB_WINDOW_SIZE-8&&ptr<stop){
available+=8;
window|=(oc_pb_window)*ptr++<<OC_PB_WINDOW_SIZE-available;
}
_b->ptr=ptr;
if(_bits>available){
if(ptr>=stop){
_b->eof=1;
available=OC_LOTS_OF_BITS;
}
else window|=*ptr>>(available&7);
}
_b->bits=available;
return window;
}
int oc_pack_look1(oc_pack_buf *_b){
oc_pb_window window;
int available;
window=_b->window;
available=_b->bits;
if(available<1)_b->window=window=oc_pack_refill(_b,1);
return window>>OC_PB_WINDOW_SIZE-1;
}
void oc_pack_adv1(oc_pack_buf *_b){
_b->window<<=1;
_b->bits--;
}
/*Here we assume that 0<=_bits&&_bits<=32.*/
long oc_pack_read(oc_pack_buf *_b,int _bits){
oc_pb_window window;
int available;
long result;
window=_b->window;
available=_b->bits;
if(_bits==0)return 0;
if(available<_bits){
window=oc_pack_refill(_b,_bits);
available=_b->bits;
}
result=window>>OC_PB_WINDOW_SIZE-_bits;
available-=_bits;
window<<=1;
window<<=_bits-1;
_b->bits=available;
_b->window=window;
return result;
}
int oc_pack_read1(oc_pack_buf *_b){
oc_pb_window window;
int available;
int result;
window=_b->window;
available=_b->bits;
if(available<1){
window=oc_pack_refill(_b,1);
available=_b->bits;
}
result=window>>OC_PB_WINDOW_SIZE-1;
available--;
window<<=1;
_b->bits=available;
_b->window=window;
return result;
}
long oc_pack_bytes_left(oc_pack_buf *_b){
if(_b->eof)return -1;
return _b->stop-_b->ptr+(_b->bits>>3);
}

View File

@@ -0,0 +1,59 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggTheora SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function: packing variable sized words into an octet stream
last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $
********************************************************************/
#if !defined(_bitpack_H)
# define _bitpack_H (1)
# include <limits.h>
typedef unsigned long oc_pb_window;
typedef struct oc_pack_buf oc_pack_buf;
# define OC_PB_WINDOW_SIZE ((int)sizeof(oc_pb_window)*CHAR_BIT)
/*This is meant to be a large, positive constant that can still be efficiently
loaded as an immediate (on platforms like ARM, for example).
Even relatively modest values like 100 would work fine.*/
# define OC_LOTS_OF_BITS (0x40000000)
struct oc_pack_buf{
oc_pb_window window;
const unsigned char *ptr;
const unsigned char *stop;
int bits;
int eof;
};
void oc_pack_readinit(oc_pack_buf *_b,unsigned char *_buf,long _bytes);
int oc_pack_look1(oc_pack_buf *_b);
void oc_pack_adv1(oc_pack_buf *_b);
/*Here we assume 0<=_bits&&_bits<=32.*/
long oc_pack_read(oc_pack_buf *_b,int _bits);
int oc_pack_read1(oc_pack_buf *_b);
/* returns -1 for read beyond EOF, or the number of whole bytes available */
long oc_pack_bytes_left(oc_pack_buf *_b);
/*These two functions are implemented locally in huffdec.c*/
/*Read in bits without advancing the bitptr.
Here we assume 0<=_bits&&_bits<=32.*/
/*static int oc_pack_look(oc_pack_buf *_b,int _bits);*/
/*static void oc_pack_adv(oc_pack_buf *_b,int _bits);*/
#endif

View File

@@ -0,0 +1,226 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
CPU capability detection for x86 processors.
Originally written by Rudolf Marek.
function:
last mod: $Id: cpu.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include "cpu.h"
#if !defined(OC_X86_ASM)
static ogg_uint32_t oc_cpu_flags_get(void){
return 0;
}
#else
# if !defined(_MSC_VER)
# if defined(__amd64__)||defined(__x86_64__)
/*On x86-64, gcc seems to be able to figure out how to save %rbx for us when
compiling with -fPIC.*/
# define cpuid(_op,_eax,_ebx,_ecx,_edx) \
__asm__ __volatile__( \
"cpuid\n\t" \
:[eax]"=a"(_eax),[ebx]"=b"(_ebx),[ecx]"=c"(_ecx),[edx]"=d"(_edx) \
:"a"(_op) \
:"cc" \
)
# else
/*On x86-32, not so much.*/
# define cpuid(_op,_eax,_ebx,_ecx,_edx) \
__asm__ __volatile__( \
"xchgl %%ebx,%[ebx]\n\t" \
"cpuid\n\t" \
"xchgl %%ebx,%[ebx]\n\t" \
:[eax]"=a"(_eax),[ebx]"=r"(_ebx),[ecx]"=c"(_ecx),[edx]"=d"(_edx) \
:"a"(_op) \
:"cc" \
)
# endif
# else
/*Why does MSVC need this complicated rigamarole?
At this point I honestly do not care.*/
/*Visual C cpuid helper function.
For VS2005 we could as well use the _cpuid builtin, but that wouldn't work
for VS2003 users, so we do it in inline assembler.*/
static void oc_cpuid_helper(ogg_uint32_t _cpu_info[4],ogg_uint32_t _op){
_asm{
mov eax,[_op]
mov esi,_cpu_info
cpuid
mov [esi+0],eax
mov [esi+4],ebx
mov [esi+8],ecx
mov [esi+12],edx
}
}
# define cpuid(_op,_eax,_ebx,_ecx,_edx) \
do{ \
ogg_uint32_t cpu_info[4]; \
oc_cpuid_helper(cpu_info,_op); \
(_eax)=cpu_info[0]; \
(_ebx)=cpu_info[1]; \
(_ecx)=cpu_info[2]; \
(_edx)=cpu_info[3]; \
}while(0)
static void oc_detect_cpuid_helper(ogg_uint32_t *_eax,ogg_uint32_t *_ebx){
_asm{
pushfd
pushfd
pop eax
mov ebx,eax
xor eax,200000h
push eax
popfd
pushfd
pop eax
popfd
mov ecx,_eax
mov [ecx],eax
mov ecx,_ebx
mov [ecx],ebx
}
}
# endif
static ogg_uint32_t oc_parse_intel_flags(ogg_uint32_t _edx,ogg_uint32_t _ecx){
ogg_uint32_t flags;
/*If there isn't even MMX, give up.*/
if(!(_edx&0x00800000))return 0;
flags=OC_CPU_X86_MMX;
if(_edx&0x02000000)flags|=OC_CPU_X86_MMXEXT|OC_CPU_X86_SSE;
if(_edx&0x04000000)flags|=OC_CPU_X86_SSE2;
if(_ecx&0x00000001)flags|=OC_CPU_X86_PNI;
if(_ecx&0x00000100)flags|=OC_CPU_X86_SSSE3;
if(_ecx&0x00080000)flags|=OC_CPU_X86_SSE4_1;
if(_ecx&0x00100000)flags|=OC_CPU_X86_SSE4_2;
return flags;
}
static ogg_uint32_t oc_parse_amd_flags(ogg_uint32_t _edx,ogg_uint32_t _ecx){
ogg_uint32_t flags;
/*If there isn't even MMX, give up.*/
if(!(_edx&0x00800000))return 0;
flags=OC_CPU_X86_MMX;
if(_edx&0x00400000)flags|=OC_CPU_X86_MMXEXT;
if(_edx&0x80000000)flags|=OC_CPU_X86_3DNOW;
if(_edx&0x40000000)flags|=OC_CPU_X86_3DNOWEXT;
if(_ecx&0x00000040)flags|=OC_CPU_X86_SSE4A;
if(_ecx&0x00000800)flags|=OC_CPU_X86_SSE5;
return flags;
}
static ogg_uint32_t oc_cpu_flags_get(void){
ogg_uint32_t flags;
ogg_uint32_t eax;
ogg_uint32_t ebx;
ogg_uint32_t ecx;
ogg_uint32_t edx;
# if !defined(__amd64__)&&!defined(__x86_64__)
/*Not all x86-32 chips support cpuid, so we have to check.*/
# if !defined(_MSC_VER)
__asm__ __volatile__(
"pushfl\n\t"
"pushfl\n\t"
"popl %[a]\n\t"
"movl %[a],%[b]\n\t"
"xorl $0x200000,%[a]\n\t"
"pushl %[a]\n\t"
"popfl\n\t"
"pushfl\n\t"
"popl %[a]\n\t"
"popfl\n\t"
:[a]"=r"(eax),[b]"=r"(ebx)
:
:"cc"
);
# else
oc_detect_cpuid_helper(&eax,&ebx);
# endif
/*No cpuid.*/
if(eax==ebx)return 0;
# endif
cpuid(0,eax,ebx,ecx,edx);
/* l e t n I e n i u n e G*/
if(ecx==0x6C65746E&&edx==0x49656E69&&ebx==0x756E6547||
/* 6 8 x M T e n i u n e G*/
ecx==0x3638784D&&edx==0x54656E69&&ebx==0x756E6547){
/*Intel, Transmeta (tested with Crusoe TM5800):*/
cpuid(1,eax,ebx,ecx,edx);
flags=oc_parse_intel_flags(edx,ecx);
}
/* D M A c i t n e h t u A*/
else if(ecx==0x444D4163&&edx==0x69746E65&&ebx==0x68747541||
/* C S N y b e d o e G*/
ecx==0x43534e20&&edx==0x79622065&&ebx==0x646f6547){
/*AMD, Geode:*/
cpuid(0x80000000,eax,ebx,ecx,edx);
if(eax<0x80000001)flags=0;
else{
cpuid(0x80000001,eax,ebx,ecx,edx);
flags=oc_parse_amd_flags(edx,ecx);
}
/*Also check for SSE.*/
cpuid(1,eax,ebx,ecx,edx);
flags|=oc_parse_intel_flags(edx,ecx);
}
/*Technically some VIA chips can be configured in the BIOS to return any
string here the user wants.
There is a special detection method that can be used to identify such
processors, but in my opinion, if the user really wants to change it, they
deserve what they get.*/
/* s l u a H r u a t n e C*/
else if(ecx==0x736C7561&&edx==0x48727561&&ebx==0x746E6543){
/*VIA:*/
/*I only have documentation for the C7 (Esther) and Isaiah (forthcoming)
chips (thanks to the engineers from Centaur Technology who provided it).
These chips support Intel-like cpuid info.
The C3-2 (Nehemiah) cores appear to, as well.*/
cpuid(1,eax,ebx,ecx,edx);
flags=oc_parse_intel_flags(edx,ecx);
if(eax>=0x80000001){
/*The (non-Nehemiah) C3 processors support AMD-like cpuid info.
We need to check this even if the Intel test succeeds to pick up 3DNow!
support on these processors.
Unlike actual AMD processors, we cannot _rely_ on this info, since
some cores (e.g., the 693 stepping of the Nehemiah) claim to support
this function, yet return edx=0, despite the Intel test indicating
MMX support.
Therefore the features detected here are strictly added to those
detected by the Intel test.*/
/*TODO: How about earlier chips?*/
cpuid(0x80000001,eax,ebx,ecx,edx);
/*Note: As of the C7, this function returns Intel-style extended feature
flags, not AMD-style.
Currently, this only defines bits 11, 20, and 29 (0x20100800), which
do not conflict with any of the AMD flags we inspect.
For the remaining bits, Intel tells us, "Do not count on their value",
but VIA assures us that they will all be zero (at least on the C7 and
Isaiah chips).
In the (unlikely) event a future processor uses bits 18, 19, 30, or 31
(0xC0C00000) for something else, we will have to add code to detect
the model to decide when it is appropriate to inspect them.*/
flags|=oc_parse_amd_flags(edx,ecx);
}
}
else{
/*Implement me.*/
flags=0;
}
return flags;
}
#endif

View File

@@ -0,0 +1,34 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: cpu.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_x86_cpu_H)
# define _x86_cpu_H (1)
#include "internal.h"
#define OC_CPU_X86_MMX (1<<0)
#define OC_CPU_X86_3DNOW (1<<1)
#define OC_CPU_X86_3DNOWEXT (1<<2)
#define OC_CPU_X86_MMXEXT (1<<3)
#define OC_CPU_X86_SSE (1<<4)
#define OC_CPU_X86_SSE2 (1<<5)
#define OC_CPU_X86_PNI (1<<6)
#define OC_CPU_X86_SSSE3 (1<<7)
#define OC_CPU_X86_SSE4_1 (1<<8)
#define OC_CPU_X86_SSE4_2 (1<<9)
#define OC_CPU_X86_SSE4A (1<<10)
#define OC_CPU_X86_SSE5 (1<<11)
#endif

View File

@@ -0,0 +1,31 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: dct.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
/*Definitions shared by the forward and inverse DCT transforms.*/
#if !defined(_dct_H)
# define _dct_H (1)
/*cos(n*pi/16) (resp. sin(m*pi/16)) scaled by 65536.*/
#define OC_C1S7 ((ogg_int32_t)64277)
#define OC_C2S6 ((ogg_int32_t)60547)
#define OC_C3S5 ((ogg_int32_t)54491)
#define OC_C4S4 ((ogg_int32_t)46341)
#define OC_C5S3 ((ogg_int32_t)36410)
#define OC_C6S2 ((ogg_int32_t)25080)
#define OC_C7S1 ((ogg_int32_t)12785)
#endif

View File

@@ -0,0 +1,193 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: decapiwrapper.c 13596 2007-08-23 20:05:38Z tterribe $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "apiwrapper.h"
#include "decint.h"
#include "theora/theoradec.h"
static void th_dec_api_clear(th_api_wrapper *_api){
if(_api->setup)th_setup_free(_api->setup);
if(_api->decode)th_decode_free(_api->decode);
memset(_api,0,sizeof(*_api));
}
static void theora_decode_clear(theora_state *_td){
if(_td->i!=NULL)theora_info_clear(_td->i);
memset(_td,0,sizeof(*_td));
}
static int theora_decode_control(theora_state *_td,int _req,
void *_buf,size_t _buf_sz){
return th_decode_ctl(((th_api_wrapper *)_td->i->codec_setup)->decode,
_req,_buf,_buf_sz);
}
static ogg_int64_t theora_decode_granule_frame(theora_state *_td,
ogg_int64_t _gp){
return th_granule_frame(((th_api_wrapper *)_td->i->codec_setup)->decode,_gp);
}
static double theora_decode_granule_time(theora_state *_td,ogg_int64_t _gp){
return th_granule_time(((th_api_wrapper *)_td->i->codec_setup)->decode,_gp);
}
static const oc_state_dispatch_vtable OC_DEC_DISPATCH_VTBL={
(oc_state_clear_func)theora_decode_clear,
(oc_state_control_func)theora_decode_control,
(oc_state_granule_frame_func)theora_decode_granule_frame,
(oc_state_granule_time_func)theora_decode_granule_time,
};
static void th_info2theora_info(theora_info *_ci,const th_info *_info){
_ci->version_major=_info->version_major;
_ci->version_minor=_info->version_minor;
_ci->version_subminor=_info->version_subminor;
_ci->width=_info->frame_width;
_ci->height=_info->frame_height;
_ci->frame_width=_info->pic_width;
_ci->frame_height=_info->pic_height;
_ci->offset_x=_info->pic_x;
_ci->offset_y=_info->pic_y;
_ci->fps_numerator=_info->fps_numerator;
_ci->fps_denominator=_info->fps_denominator;
_ci->aspect_numerator=_info->aspect_numerator;
_ci->aspect_denominator=_info->aspect_denominator;
switch(_info->colorspace){
case TH_CS_ITU_REC_470M:_ci->colorspace=OC_CS_ITU_REC_470M;break;
case TH_CS_ITU_REC_470BG:_ci->colorspace=OC_CS_ITU_REC_470BG;break;
default:_ci->colorspace=OC_CS_UNSPECIFIED;break;
}
switch(_info->pixel_fmt){
case TH_PF_420:_ci->pixelformat=OC_PF_420;break;
case TH_PF_422:_ci->pixelformat=OC_PF_422;break;
case TH_PF_444:_ci->pixelformat=OC_PF_444;break;
default:_ci->pixelformat=OC_PF_RSVD;
}
_ci->target_bitrate=_info->target_bitrate;
_ci->quality=_info->quality;
_ci->keyframe_frequency_force=1<<_info->keyframe_granule_shift;
}
int theora_decode_init(theora_state *_td,theora_info *_ci){
th_api_info *apiinfo;
th_api_wrapper *api;
th_info info;
api=(th_api_wrapper *)_ci->codec_setup;
/*Allocate our own combined API wrapper/theora_info struct.
We put them both in one malloc'd block so that when the API wrapper is
freed, the info struct goes with it.
This avoids having to figure out whether or not we need to free the info
struct in either theora_info_clear() or theora_clear().*/
apiinfo=(th_api_info *)_ogg_calloc(1,sizeof(*apiinfo));
if(apiinfo==NULL)return OC_FAULT;
/*Make our own copy of the info struct, since its lifetime should be
independent of the one we were passed in.*/
*&apiinfo->info=*_ci;
/*Convert the info struct now instead of saving the the one we decoded with
theora_decode_header(), since the user might have modified values (i.e.,
color space, aspect ratio, etc. can be specified from a higher level).
The user also might be doing something "clever" with the header packets if
they are not using an Ogg encapsulation.*/
oc_theora_info2th_info(&info,_ci);
/*Don't bother to copy the setup info; th_decode_alloc() makes its own copy
of the stuff it needs.*/
apiinfo->api.decode=th_decode_alloc(&info,api->setup);
if(apiinfo->api.decode==NULL){
_ogg_free(apiinfo);
return OC_EINVAL;
}
apiinfo->api.clear=(oc_setup_clear_func)th_dec_api_clear;
_td->internal_encode=NULL;
/*Provide entry points for ABI compatibility with old decoder shared libs.*/
_td->internal_decode=(void *)&OC_DEC_DISPATCH_VTBL;
_td->granulepos=0;
_td->i=&apiinfo->info;
_td->i->codec_setup=&apiinfo->api;
return 0;
}
int theora_decode_header(theora_info *_ci,theora_comment *_cc,ogg_packet *_op){
th_api_wrapper *api;
th_info info;
int ret;
api=(th_api_wrapper *)_ci->codec_setup;
/*Allocate an API wrapper struct on demand, since it will not also include a
theora_info struct like the ones that are used in a theora_state struct.*/
if(api==NULL){
_ci->codec_setup=_ogg_calloc(1,sizeof(*api));
if(_ci->codec_setup==NULL)return OC_FAULT;
api=(th_api_wrapper *)_ci->codec_setup;
api->clear=(oc_setup_clear_func)th_dec_api_clear;
}
/*Convert from the theora_info struct instead of saving our own th_info
struct between calls.
The user might be doing something "clever" with the header packets if they
are not using an Ogg encapsulation, and we don't want to break this.*/
oc_theora_info2th_info(&info,_ci);
/*We rely on the fact that theora_comment and th_comment structures are
actually identical.
Take care not to change this fact unless you change the code here as
well!*/
ret=th_decode_headerin(&info,(th_comment *)_cc,&api->setup,_op);
/*We also rely on the fact that the error return code values are the same,
and that the implementations of these two functions return the same set of
them.
Note that theora_decode_header() really can return OC_NOTFORMAT, even
though it is not currently documented to do so.*/
if(ret<0)return ret;
th_info2theora_info(_ci,&info);
return 0;
}
int theora_decode_packetin(theora_state *_td,ogg_packet *_op){
th_api_wrapper *api;
ogg_int64_t gp;
int ret;
if(!_td||!_td->i||!_td->i->codec_setup)return OC_FAULT;
api=(th_api_wrapper *)_td->i->codec_setup;
ret=th_decode_packetin(api->decode,_op,&gp);
if(ret<0)return OC_BADPACKET;
_td->granulepos=gp;
return 0;
}
int theora_decode_YUVout(theora_state *_td,yuv_buffer *_yuv){
th_api_wrapper *api;
th_dec_ctx *decode;
th_ycbcr_buffer buf;
int ret;
if(!_td||!_td->i||!_td->i->codec_setup)return OC_FAULT;
api=(th_api_wrapper *)_td->i->codec_setup;
decode=(th_dec_ctx *)api->decode;
if(!decode)return OC_FAULT;
ret=th_decode_ycbcr_out(decode,buf);
if(ret>=0){
_yuv->y_width=buf[0].width;
_yuv->y_height=buf[0].height;
_yuv->y_stride=buf[0].stride;
_yuv->uv_width=buf[1].width;
_yuv->uv_height=buf[1].height;
_yuv->uv_stride=buf[1].stride;
_yuv->y=buf[0].data;
_yuv->u=buf[1].data;
_yuv->v=buf[2].data;
}
return ret;
}

View File

@@ -0,0 +1,246 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: decinfo.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "decint.h"
/*Unpacks a series of octets from a given byte array into the pack buffer.
No checking is done to ensure the buffer contains enough data.
_opb: The pack buffer to read the octets from.
_buf: The byte array to store the unpacked bytes in.
_len: The number of octets to unpack.*/
static void oc_unpack_octets(oc_pack_buf *_opb,char *_buf,size_t _len){
while(_len-->0){
long val;
val=oc_pack_read(_opb,8);
*_buf++=(char)val;
}
}
/*Unpacks a 32-bit integer encoded by octets in little-endian form.*/
static long oc_unpack_length(oc_pack_buf *_opb){
long ret[4];
int i;
for(i=0;i<4;i++)ret[i]=oc_pack_read(_opb,8);
return ret[0]|ret[1]<<8|ret[2]<<16|ret[3]<<24;
}
static int oc_info_unpack(oc_pack_buf *_opb,th_info *_info){
long val;
/*Check the codec bitstream version.*/
val=oc_pack_read(_opb,8);
_info->version_major=(unsigned char)val;
val=oc_pack_read(_opb,8);
_info->version_minor=(unsigned char)val;
val=oc_pack_read(_opb,8);
_info->version_subminor=(unsigned char)val;
/*verify we can parse this bitstream version.
We accept earlier minors and all subminors, by spec*/
if(_info->version_major>TH_VERSION_MAJOR||
_info->version_major==TH_VERSION_MAJOR&&
_info->version_minor>TH_VERSION_MINOR){
return TH_EVERSION;
}
/*Read the encoded frame description.*/
val=oc_pack_read(_opb,16);
_info->frame_width=(ogg_uint32_t)val<<4;
val=oc_pack_read(_opb,16);
_info->frame_height=(ogg_uint32_t)val<<4;
val=oc_pack_read(_opb,24);
_info->pic_width=(ogg_uint32_t)val;
val=oc_pack_read(_opb,24);
_info->pic_height=(ogg_uint32_t)val;
val=oc_pack_read(_opb,8);
_info->pic_x=(ogg_uint32_t)val;
val=oc_pack_read(_opb,8);
_info->pic_y=(ogg_uint32_t)val;
val=oc_pack_read(_opb,32);
_info->fps_numerator=(ogg_uint32_t)val;
val=oc_pack_read(_opb,32);
_info->fps_denominator=(ogg_uint32_t)val;
if(_info->frame_width==0||_info->frame_height==0||
_info->pic_width+_info->pic_x>_info->frame_width||
_info->pic_height+_info->pic_y>_info->frame_height||
_info->fps_numerator==0||_info->fps_denominator==0){
return TH_EBADHEADER;
}
/*Note: The sense of pic_y is inverted in what we pass back to the
application compared to how it is stored in the bitstream.
This is because the bitstream uses a right-handed coordinate system, while
applications expect a left-handed one.*/
_info->pic_y=_info->frame_height-_info->pic_height-_info->pic_y;
val=oc_pack_read(_opb,24);
_info->aspect_numerator=(ogg_uint32_t)val;
val=oc_pack_read(_opb,24);
_info->aspect_denominator=(ogg_uint32_t)val;
val=oc_pack_read(_opb,8);
_info->colorspace=(th_colorspace)val;
val=oc_pack_read(_opb,24);
_info->target_bitrate=(int)val;
val=oc_pack_read(_opb,6);
_info->quality=(int)val;
val=oc_pack_read(_opb,5);
_info->keyframe_granule_shift=(int)val;
val=oc_pack_read(_opb,2);
_info->pixel_fmt=(th_pixel_fmt)val;
if(_info->pixel_fmt==TH_PF_RSVD)return TH_EBADHEADER;
val=oc_pack_read(_opb,3);
if(val!=0||oc_pack_bytes_left(_opb)<0)return TH_EBADHEADER;
return 0;
}
static int oc_comment_unpack(oc_pack_buf *_opb,th_comment *_tc){
long len;
int i;
/*Read the vendor string.*/
len=oc_unpack_length(_opb);
if(len<0||len>oc_pack_bytes_left(_opb))return TH_EBADHEADER;
_tc->vendor=_ogg_malloc((size_t)len+1);
if(_tc->vendor==NULL)return TH_EFAULT;
oc_unpack_octets(_opb,_tc->vendor,len);
_tc->vendor[len]='\0';
/*Read the user comments.*/
_tc->comments=(int)oc_unpack_length(_opb);
len=_tc->comments;
if(len<0||len>(LONG_MAX>>2)||len<<2>oc_pack_bytes_left(_opb)){
_tc->comments=0;
return TH_EBADHEADER;
}
_tc->comment_lengths=(int *)_ogg_malloc(
_tc->comments*sizeof(_tc->comment_lengths[0]));
_tc->user_comments=(char **)_ogg_malloc(
_tc->comments*sizeof(_tc->user_comments[0]));
for(i=0;i<_tc->comments;i++){
len=oc_unpack_length(_opb);
if(len<0||len>oc_pack_bytes_left(_opb)){
_tc->comments=i;
return TH_EBADHEADER;
}
_tc->comment_lengths[i]=len;
_tc->user_comments[i]=_ogg_malloc((size_t)len+1);
if(_tc->user_comments[i]==NULL){
_tc->comments=i;
return TH_EFAULT;
}
oc_unpack_octets(_opb,_tc->user_comments[i],len);
_tc->user_comments[i][len]='\0';
}
return oc_pack_bytes_left(_opb)<0?TH_EBADHEADER:0;
}
static int oc_setup_unpack(oc_pack_buf *_opb,th_setup_info *_setup){
int ret;
/*Read the quantizer tables.*/
ret=oc_quant_params_unpack(_opb,&_setup->qinfo);
if(ret<0)return ret;
/*Read the Huffman trees.*/
return oc_huff_trees_unpack(_opb,_setup->huff_tables);
}
static void oc_setup_clear(th_setup_info *_setup){
oc_quant_params_clear(&_setup->qinfo);
oc_huff_trees_clear(_setup->huff_tables);
}
static int oc_dec_headerin(oc_pack_buf *_opb,th_info *_info,
th_comment *_tc,th_setup_info **_setup,ogg_packet *_op){
char buffer[6];
long val;
int packtype;
int ret;
val=oc_pack_read(_opb,8);
packtype=(int)val;
/*If we're at a data packet and we have received all three headers, we're
done.*/
if(!(packtype&0x80)&&_info->frame_width>0&&_tc->vendor!=NULL&&*_setup!=NULL){
return 0;
}
/*Check the codec string.*/
oc_unpack_octets(_opb,buffer,6);
if(memcmp(buffer,"theora",6)!=0)return TH_ENOTFORMAT;
switch(packtype){
/*Codec info header.*/
case 0x80:{
/*This should be the first packet, and we should not already be
initialized.*/
if(!_op->b_o_s||_info->frame_width>0)return TH_EBADHEADER;
ret=oc_info_unpack(_opb,_info);
if(ret<0)th_info_clear(_info);
else ret=3;
}break;
/*Comment header.*/
case 0x81:{
if(_tc==NULL)return TH_EFAULT;
/*We shoud have already decoded the info header, and should not yet have
decoded the comment header.*/
if(_info->frame_width==0||_tc->vendor!=NULL)return TH_EBADHEADER;
ret=oc_comment_unpack(_opb,_tc);
if(ret<0)th_comment_clear(_tc);
else ret=2;
}break;
/*Codec setup header.*/
case 0x82:{
oc_setup_info *setup;
if(_tc==NULL||_setup==NULL)return TH_EFAULT;
/*We should have already decoded the info header and the comment header,
and should not yet have decoded the setup header.*/
if(_info->frame_width==0||_tc->vendor==NULL||*_setup!=NULL){
return TH_EBADHEADER;
}
setup=(oc_setup_info *)_ogg_calloc(1,sizeof(*setup));
if(setup==NULL)return TH_EFAULT;
ret=oc_setup_unpack(_opb,setup);
if(ret<0){
oc_setup_clear(setup);
_ogg_free(setup);
}
else{
*_setup=setup;
ret=1;
}
}break;
default:{
/*We don't know what this header is.*/
return TH_EBADHEADER;
}break;
}
return ret;
}
/*Decodes one header packet.
This should be called repeatedly with the packets at the beginning of the
stream until it returns 0.*/
int th_decode_headerin(th_info *_info,th_comment *_tc,
th_setup_info **_setup,ogg_packet *_op){
oc_pack_buf opb;
if(_op==NULL)return TH_EBADHEADER;
if(_info==NULL)return TH_EFAULT;
oc_pack_readinit(&opb,_op->packet,_op->bytes);
return oc_dec_headerin(&opb,_info,_tc,_setup,_op);
}
void th_setup_free(th_setup_info *_setup){
if(_setup!=NULL){
oc_setup_clear(_setup);
_ogg_free(_setup);
}
}

View File

@@ -0,0 +1,107 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: decint.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <limits.h>
#if !defined(_decint_H)
# define _decint_H (1)
# include "theora/theoradec.h"
# include "internal.h"
# include "bitpack.h"
typedef struct th_setup_info oc_setup_info;
typedef struct th_dec_ctx oc_dec_ctx;
# include "huffdec.h"
# include "dequant.h"
/*Constants for the packet-in state machine specific to the decoder.*/
/*Next packet to read: Data packet.*/
#define OC_PACKET_DATA (0)
struct th_setup_info{
/*The Huffman codes.*/
oc_huff_node *huff_tables[TH_NHUFFMAN_TABLES];
/*The quantization parameters.*/
th_quant_info qinfo;
};
struct th_dec_ctx{
/*Shared encoder/decoder state.*/
oc_theora_state state;
/*Whether or not packets are ready to be emitted.
This takes on negative values while there are remaining header packets to
be emitted, reaches 0 when the codec is ready for input, and goes to 1
when a frame has been processed and a data packet is ready.*/
int packet_state;
/*Buffer in which to assemble packets.*/
oc_pack_buf opb;
/*Huffman decode trees.*/
oc_huff_node *huff_tables[TH_NHUFFMAN_TABLES];
/*The index of the first token in each plane for each coefficient.*/
ptrdiff_t ti0[3][64];
/*The number of outstanding EOB runs at the start of each coefficient in each
plane.*/
ptrdiff_t eob_runs[3][64];
/*The DCT token lists.*/
unsigned char *dct_tokens;
/*The extra bits associated with DCT tokens.*/
unsigned char *extra_bits;
/*The number of dct tokens unpacked so far.*/
int dct_tokens_count;
/*The out-of-loop post-processing level.*/
int pp_level;
/*The DC scale used for out-of-loop deblocking.*/
int pp_dc_scale[64];
/*The sharpen modifier used for out-of-loop deringing.*/
int pp_sharp_mod[64];
/*The DC quantization index of each block.*/
unsigned char *dc_qis;
/*The variance of each block.*/
int *variances;
/*The storage for the post-processed frame buffer.*/
unsigned char *pp_frame_data;
/*Whether or not the post-processsed frame buffer has space for chroma.*/
int pp_frame_state;
/*The buffer used for the post-processed frame.
Note that this is _not_ guaranteed to have the same strides and offsets as
the reference frame buffers.*/
th_ycbcr_buffer pp_frame_buf;
/*The striped decode callback function.*/
th_stripe_callback stripe_cb;
# if defined(HAVE_CAIRO)
/*Output metrics for debugging.*/
int telemetry;
int telemetry_mbmode;
int telemetry_mv;
int telemetry_qi;
int telemetry_bits;
int telemetry_frame_bytes;
int telemetry_coding_bytes;
int telemetry_mode_bytes;
int telemetry_mv_bytes;
int telemetry_qi_bytes;
int telemetry_dc_bytes;
unsigned char *telemetry_frame_data;
# endif
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,182 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: dequant.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <ogg/ogg.h>
#include "dequant.h"
#include "decint.h"
int oc_quant_params_unpack(oc_pack_buf *_opb,th_quant_info *_qinfo){
th_quant_base *base_mats;
long val;
int nbase_mats;
int sizes[64];
int indices[64];
int nbits;
int bmi;
int ci;
int qti;
int pli;
int qri;
int qi;
int i;
val=oc_pack_read(_opb,3);
nbits=(int)val;
for(qi=0;qi<64;qi++){
val=oc_pack_read(_opb,nbits);
_qinfo->loop_filter_limits[qi]=(unsigned char)val;
}
val=oc_pack_read(_opb,4);
nbits=(int)val+1;
for(qi=0;qi<64;qi++){
val=oc_pack_read(_opb,nbits);
_qinfo->ac_scale[qi]=(ogg_uint16_t)val;
}
val=oc_pack_read(_opb,4);
nbits=(int)val+1;
for(qi=0;qi<64;qi++){
val=oc_pack_read(_opb,nbits);
_qinfo->dc_scale[qi]=(ogg_uint16_t)val;
}
val=oc_pack_read(_opb,9);
nbase_mats=(int)val+1;
base_mats=_ogg_malloc(nbase_mats*sizeof(base_mats[0]));
if(base_mats==NULL)return TH_EFAULT;
for(bmi=0;bmi<nbase_mats;bmi++){
for(ci=0;ci<64;ci++){
val=oc_pack_read(_opb,8);
base_mats[bmi][ci]=(unsigned char)val;
}
}
nbits=oc_ilog(nbase_mats-1);
for(i=0;i<6;i++){
th_quant_ranges *qranges;
th_quant_base *qrbms;
int *qrsizes;
qti=i/3;
pli=i%3;
qranges=_qinfo->qi_ranges[qti]+pli;
if(i>0){
val=oc_pack_read1(_opb);
if(!val){
int qtj;
int plj;
if(qti>0){
val=oc_pack_read1(_opb);
if(val){
qtj=qti-1;
plj=pli;
}
else{
qtj=(i-1)/3;
plj=(i-1)%3;
}
}
else{
qtj=(i-1)/3;
plj=(i-1)%3;
}
*qranges=*(_qinfo->qi_ranges[qtj]+plj);
continue;
}
}
val=oc_pack_read(_opb,nbits);
indices[0]=(int)val;
for(qi=qri=0;qi<63;){
val=oc_pack_read(_opb,oc_ilog(62-qi));
sizes[qri]=(int)val+1;
qi+=(int)val+1;
val=oc_pack_read(_opb,nbits);
indices[++qri]=(int)val;
}
/*Note: The caller is responsible for cleaning up any partially
constructed qinfo.*/
if(qi>63){
_ogg_free(base_mats);
return TH_EBADHEADER;
}
qranges->nranges=qri;
qranges->sizes=qrsizes=(int *)_ogg_malloc(qri*sizeof(qrsizes[0]));
if(qranges->sizes==NULL){
/*Note: The caller is responsible for cleaning up any partially
constructed qinfo.*/
_ogg_free(base_mats);
return TH_EFAULT;
}
memcpy(qrsizes,sizes,qri*sizeof(qrsizes[0]));
qrbms=(th_quant_base *)_ogg_malloc((qri+1)*sizeof(qrbms[0]));
if(qrbms==NULL){
/*Note: The caller is responsible for cleaning up any partially
constructed qinfo.*/
_ogg_free(base_mats);
return TH_EFAULT;
}
qranges->base_matrices=(const th_quant_base *)qrbms;
do{
bmi=indices[qri];
/*Note: The caller is responsible for cleaning up any partially
constructed qinfo.*/
if(bmi>=nbase_mats){
_ogg_free(base_mats);
return TH_EBADHEADER;
}
memcpy(qrbms[qri],base_mats[bmi],sizeof(qrbms[qri]));
}
while(qri-->0);
}
_ogg_free(base_mats);
return 0;
}
void oc_quant_params_clear(th_quant_info *_qinfo){
int i;
for(i=6;i-->0;){
int qti;
int pli;
qti=i/3;
pli=i%3;
/*Clear any duplicate pointer references.*/
if(i>0){
int qtj;
int plj;
qtj=(i-1)/3;
plj=(i-1)%3;
if(_qinfo->qi_ranges[qti][pli].sizes==
_qinfo->qi_ranges[qtj][plj].sizes){
_qinfo->qi_ranges[qti][pli].sizes=NULL;
}
if(_qinfo->qi_ranges[qti][pli].base_matrices==
_qinfo->qi_ranges[qtj][plj].base_matrices){
_qinfo->qi_ranges[qti][pli].base_matrices=NULL;
}
}
if(qti>0){
if(_qinfo->qi_ranges[1][pli].sizes==
_qinfo->qi_ranges[0][pli].sizes){
_qinfo->qi_ranges[1][pli].sizes=NULL;
}
if(_qinfo->qi_ranges[1][pli].base_matrices==
_qinfo->qi_ranges[0][pli].base_matrices){
_qinfo->qi_ranges[1][pli].base_matrices=NULL;
}
}
/*Now free all the non-duplicate storage.*/
_ogg_free((void *)_qinfo->qi_ranges[qti][pli].sizes);
_ogg_free((void *)_qinfo->qi_ranges[qti][pli].base_matrices);
}
}

View File

@@ -0,0 +1,27 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: dequant.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_dequant_H)
# define _dequant_H (1)
# include "quant.h"
# include "bitpack.h"
int oc_quant_params_unpack(oc_pack_buf *_opb,
th_quant_info *_qinfo);
void oc_quant_params_clear(th_quant_info *_qinfo);
#endif

View File

@@ -0,0 +1,168 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "apiwrapper.h"
#include "encint.h"
#include "theora/theoraenc.h"
static void th_enc_api_clear(th_api_wrapper *_api){
if(_api->encode)th_encode_free(_api->encode);
memset(_api,0,sizeof(*_api));
}
static void theora_encode_clear(theora_state *_te){
if(_te->i!=NULL)theora_info_clear(_te->i);
memset(_te,0,sizeof(*_te));
}
static int theora_encode_control(theora_state *_te,int _req,
void *_buf,size_t _buf_sz){
return th_encode_ctl(((th_api_wrapper *)_te->i->codec_setup)->encode,
_req,_buf,_buf_sz);
}
static ogg_int64_t theora_encode_granule_frame(theora_state *_te,
ogg_int64_t _gp){
return th_granule_frame(((th_api_wrapper *)_te->i->codec_setup)->encode,_gp);
}
static double theora_encode_granule_time(theora_state *_te,ogg_int64_t _gp){
return th_granule_time(((th_api_wrapper *)_te->i->codec_setup)->encode,_gp);
}
static const oc_state_dispatch_vtable OC_ENC_DISPATCH_VTBL={
(oc_state_clear_func)theora_encode_clear,
(oc_state_control_func)theora_encode_control,
(oc_state_granule_frame_func)theora_encode_granule_frame,
(oc_state_granule_time_func)theora_encode_granule_time,
};
int theora_encode_init(theora_state *_te,theora_info *_ci){
th_api_info *apiinfo;
th_info info;
ogg_uint32_t keyframe_frequency_force;
/*Allocate our own combined API wrapper/theora_info struct.
We put them both in one malloc'd block so that when the API wrapper is
freed, the info struct goes with it.
This avoids having to figure out whether or not we need to free the info
struct in either theora_info_clear() or theora_clear().*/
apiinfo=(th_api_info *)_ogg_malloc(sizeof(*apiinfo));
if(apiinfo==NULL)return TH_EFAULT;
/*Make our own copy of the info struct, since its lifetime should be
independent of the one we were passed in.*/
*&apiinfo->info=*_ci;
oc_theora_info2th_info(&info,_ci);
apiinfo->api.encode=th_encode_alloc(&info);
if(apiinfo->api.encode==NULL){
_ogg_free(apiinfo);
return OC_EINVAL;
}
apiinfo->api.clear=(oc_setup_clear_func)th_enc_api_clear;
/*Provide entry points for ABI compatibility with old decoder shared libs.*/
_te->internal_encode=(void *)&OC_ENC_DISPATCH_VTBL;
_te->internal_decode=NULL;
_te->granulepos=0;
_te->i=&apiinfo->info;
_te->i->codec_setup=&apiinfo->api;
/*Set the precise requested keyframe frequency.*/
keyframe_frequency_force=_ci->keyframe_auto_p?
_ci->keyframe_frequency_force:_ci->keyframe_frequency;
th_encode_ctl(apiinfo->api.encode,
TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
&keyframe_frequency_force,sizeof(keyframe_frequency_force));
/*TODO: Additional codec setup using the extra fields in theora_info.*/
return 0;
}
int theora_encode_YUVin(theora_state *_te,yuv_buffer *_yuv){
th_api_wrapper *api;
th_ycbcr_buffer buf;
int ret;
api=(th_api_wrapper *)_te->i->codec_setup;
buf[0].width=_yuv->y_width;
buf[0].height=_yuv->y_height;
buf[0].stride=_yuv->y_stride;
buf[0].data=_yuv->y;
buf[1].width=_yuv->uv_width;
buf[1].height=_yuv->uv_height;
buf[1].stride=_yuv->uv_stride;
buf[1].data=_yuv->u;
buf[2].width=_yuv->uv_width;
buf[2].height=_yuv->uv_height;
buf[2].stride=_yuv->uv_stride;
buf[2].data=_yuv->v;
ret=th_encode_ycbcr_in(api->encode,buf);
if(ret<0)return ret;
_te->granulepos=api->encode->state.granpos;
return ret;
}
int theora_encode_packetout(theora_state *_te,int _last_p,ogg_packet *_op){
th_api_wrapper *api;
api=(th_api_wrapper *)_te->i->codec_setup;
return th_encode_packetout(api->encode,_last_p,_op);
}
int theora_encode_header(theora_state *_te,ogg_packet *_op){
oc_enc_ctx *enc;
th_api_wrapper *api;
int ret;
api=(th_api_wrapper *)_te->i->codec_setup;
enc=api->encode;
/*If we've already started encoding, fail.*/
if(enc->packet_state>OC_PACKET_EMPTY||enc->state.granpos!=0){
return TH_EINVAL;
}
/*Reset the state to make sure we output an info packet.*/
enc->packet_state=OC_PACKET_INFO_HDR;
ret=th_encode_flushheader(api->encode,NULL,_op);
return ret>=0?0:ret;
}
int theora_encode_comment(theora_comment *_tc,ogg_packet *_op){
oggpack_buffer opb;
void *buf;
int packet_state;
int ret;
packet_state=OC_PACKET_COMMENT_HDR;
oggpackB_writeinit(&opb);
ret=oc_state_flushheader(NULL,&packet_state,&opb,NULL,NULL,
th_version_string(),(th_comment *)_tc,_op);
if(ret>=0){
/*The oggpack_buffer's lifetime ends with this function, so we have to
copy out the packet contents.
Presumably the application knows it is supposed to free this.
This part works nothing like the Vorbis API, and the documentation on it
has been wrong for some time, claiming libtheora owned the memory.*/
buf=_ogg_malloc(_op->bytes);
if(buf==NULL){
_op->packet=NULL;
ret=TH_EFAULT;
}
else{
memcpy(buf,_op->packet,_op->bytes);
_op->packet=buf;
ret=0;
}
}
oggpack_writeclear(&opb);
return ret;
}
int theora_encode_tables(theora_state *_te,ogg_packet *_op){
oc_enc_ctx *enc;
th_api_wrapper *api;
int ret;
api=(th_api_wrapper *)_te->i->codec_setup;
enc=api->encode;
/*If we've already started encoding, fail.*/
if(enc->packet_state>OC_PACKET_EMPTY||enc->state.granpos!=0){
return TH_EINVAL;
}
/*Reset the state to make sure we output a setup packet.*/
enc->packet_state=OC_PACKET_SETUP_HDR;
ret=th_encode_flushheader(api->encode,NULL,_op);
return ret>=0?0:ret;
}

View File

@@ -0,0 +1,388 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: encfrag.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include "encint.h"
void oc_enc_frag_sub(const oc_enc_ctx *_enc,ogg_int16_t _diff[64],
const unsigned char *_src,const unsigned char *_ref,int _ystride){
(*_enc->opt_vtable.frag_sub)(_diff,_src,_ref,_ystride);
}
void oc_enc_frag_sub_c(ogg_int16_t _diff[64],const unsigned char *_src,
const unsigned char *_ref,int _ystride){
int i;
for(i=0;i<8;i++){
int j;
for(j=0;j<8;j++)_diff[i*8+j]=(ogg_int16_t)(_src[j]-_ref[j]);
_src+=_ystride;
_ref+=_ystride;
}
}
void oc_enc_frag_sub_128(const oc_enc_ctx *_enc,ogg_int16_t _diff[64],
const unsigned char *_src,int _ystride){
(*_enc->opt_vtable.frag_sub_128)(_diff,_src,_ystride);
}
void oc_enc_frag_sub_128_c(ogg_int16_t *_diff,
const unsigned char *_src,int _ystride){
int i;
for(i=0;i<8;i++){
int j;
for(j=0;j<8;j++)_diff[i*8+j]=(ogg_int16_t)(_src[j]-128);
_src+=_ystride;
}
}
unsigned oc_enc_frag_sad(const oc_enc_ctx *_enc,const unsigned char *_x,
const unsigned char *_y,int _ystride){
return (*_enc->opt_vtable.frag_sad)(_x,_y,_ystride);
}
unsigned oc_enc_frag_sad_c(const unsigned char *_src,
const unsigned char *_ref,int _ystride){
unsigned sad;
int i;
sad=0;
for(i=8;i-->0;){
int j;
for(j=0;j<8;j++)sad+=abs(_src[j]-_ref[j]);
_src+=_ystride;
_ref+=_ystride;
}
return sad;
}
unsigned oc_enc_frag_sad_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref,int _ystride,
unsigned _thresh){
return (*_enc->opt_vtable.frag_sad_thresh)(_src,_ref,_ystride,_thresh);
}
unsigned oc_enc_frag_sad_thresh_c(const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _thresh){
unsigned sad;
int i;
sad=0;
for(i=8;i-->0;){
int j;
for(j=0;j<8;j++)sad+=abs(_src[j]-_ref[j]);
if(sad>_thresh)break;
_src+=_ystride;
_ref+=_ystride;
}
return sad;
}
unsigned oc_enc_frag_sad2_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref1,
const unsigned char *_ref2,int _ystride,unsigned _thresh){
return (*_enc->opt_vtable.frag_sad2_thresh)(_src,_ref1,_ref2,_ystride,
_thresh);
}
unsigned oc_enc_frag_sad2_thresh_c(const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride,
unsigned _thresh){
unsigned sad;
int i;
sad=0;
for(i=8;i-->0;){
int j;
for(j=0;j<8;j++)sad+=abs(_src[j]-(_ref1[j]+_ref2[j]>>1));
if(sad>_thresh)break;
_src+=_ystride;
_ref1+=_ystride;
_ref2+=_ystride;
}
return sad;
}
static void oc_diff_hadamard(ogg_int16_t _buf[64],const unsigned char *_src,
const unsigned char *_ref,int _ystride){
int i;
for(i=0;i<8;i++){
int t0;
int t1;
int t2;
int t3;
int t4;
int t5;
int t6;
int t7;
int r;
/*Hadamard stage 1:*/
t0=_src[0]-_ref[0]+_src[4]-_ref[4];
t4=_src[0]-_ref[0]-_src[4]+_ref[4];
t1=_src[1]-_ref[1]+_src[5]-_ref[5];
t5=_src[1]-_ref[1]-_src[5]+_ref[5];
t2=_src[2]-_ref[2]+_src[6]-_ref[6];
t6=_src[2]-_ref[2]-_src[6]+_ref[6];
t3=_src[3]-_ref[3]+_src[7]-_ref[7];
t7=_src[3]-_ref[3]-_src[7]+_ref[7];
/*Hadamard stage 2:*/
r=t0;
t0+=t2;
t2=r-t2;
r=t1;
t1+=t3;
t3=r-t3;
r=t4;
t4+=t6;
t6=r-t6;
r=t5;
t5+=t7;
t7=r-t7;
/*Hadamard stage 3:*/
_buf[0*8+i]=(ogg_int16_t)(t0+t1);
_buf[1*8+i]=(ogg_int16_t)(t0-t1);
_buf[2*8+i]=(ogg_int16_t)(t2+t3);
_buf[3*8+i]=(ogg_int16_t)(t2-t3);
_buf[4*8+i]=(ogg_int16_t)(t4+t5);
_buf[5*8+i]=(ogg_int16_t)(t4-t5);
_buf[6*8+i]=(ogg_int16_t)(t6+t7);
_buf[7*8+i]=(ogg_int16_t)(t6-t7);
_src+=_ystride;
_ref+=_ystride;
}
}
static void oc_diff_hadamard2(ogg_int16_t _buf[64],const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride){
int i;
for(i=0;i<8;i++){
int t0;
int t1;
int t2;
int t3;
int t4;
int t5;
int t6;
int t7;
int r;
/*Hadamard stage 1:*/
r=_ref1[0]+_ref2[0]>>1;
t4=_ref1[4]+_ref2[4]>>1;
t0=_src[0]-r+_src[4]-t4;
t4=_src[0]-r-_src[4]+t4;
r=_ref1[1]+_ref2[1]>>1;
t5=_ref1[5]+_ref2[5]>>1;
t1=_src[1]-r+_src[5]-t5;
t5=_src[1]-r-_src[5]+t5;
r=_ref1[2]+_ref2[2]>>1;
t6=_ref1[6]+_ref2[6]>>1;
t2=_src[2]-r+_src[6]-t6;
t6=_src[2]-r-_src[6]+t6;
r=_ref1[3]+_ref2[3]>>1;
t7=_ref1[7]+_ref2[7]>>1;
t3=_src[3]-r+_src[7]-t7;
t7=_src[3]-r-_src[7]+t7;
/*Hadamard stage 2:*/
r=t0;
t0+=t2;
t2=r-t2;
r=t1;
t1+=t3;
t3=r-t3;
r=t4;
t4+=t6;
t6=r-t6;
r=t5;
t5+=t7;
t7=r-t7;
/*Hadamard stage 3:*/
_buf[0*8+i]=(ogg_int16_t)(t0+t1);
_buf[1*8+i]=(ogg_int16_t)(t0-t1);
_buf[2*8+i]=(ogg_int16_t)(t2+t3);
_buf[3*8+i]=(ogg_int16_t)(t2-t3);
_buf[4*8+i]=(ogg_int16_t)(t4+t5);
_buf[5*8+i]=(ogg_int16_t)(t4-t5);
_buf[6*8+i]=(ogg_int16_t)(t6+t7);
_buf[7*8+i]=(ogg_int16_t)(t6-t7);
_src+=_ystride;
_ref1+=_ystride;
_ref2+=_ystride;
}
}
static void oc_intra_hadamard(ogg_int16_t _buf[64],const unsigned char *_src,
int _ystride){
int i;
for(i=0;i<8;i++){
int t0;
int t1;
int t2;
int t3;
int t4;
int t5;
int t6;
int t7;
int r;
/*Hadamard stage 1:*/
t0=_src[0]+_src[4];
t4=_src[0]-_src[4];
t1=_src[1]+_src[5];
t5=_src[1]-_src[5];
t2=_src[2]+_src[6];
t6=_src[2]-_src[6];
t3=_src[3]+_src[7];
t7=_src[3]-_src[7];
/*Hadamard stage 2:*/
r=t0;
t0+=t2;
t2=r-t2;
r=t1;
t1+=t3;
t3=r-t3;
r=t4;
t4+=t6;
t6=r-t6;
r=t5;
t5+=t7;
t7=r-t7;
/*Hadamard stage 3:*/
_buf[0*8+i]=(ogg_int16_t)(t0+t1);
_buf[1*8+i]=(ogg_int16_t)(t0-t1);
_buf[2*8+i]=(ogg_int16_t)(t2+t3);
_buf[3*8+i]=(ogg_int16_t)(t2-t3);
_buf[4*8+i]=(ogg_int16_t)(t4+t5);
_buf[5*8+i]=(ogg_int16_t)(t4-t5);
_buf[6*8+i]=(ogg_int16_t)(t6+t7);
_buf[7*8+i]=(ogg_int16_t)(t6-t7);
_src+=_ystride;
}
}
unsigned oc_hadamard_sad_thresh(const ogg_int16_t _buf[64],unsigned _thresh){
unsigned sad;
int t0;
int t1;
int t2;
int t3;
int t4;
int t5;
int t6;
int t7;
int r;
int i;
sad=0;
for(i=0;i<8;i++){
/*Hadamard stage 1:*/
t0=_buf[i*8+0]+_buf[i*8+4];
t4=_buf[i*8+0]-_buf[i*8+4];
t1=_buf[i*8+1]+_buf[i*8+5];
t5=_buf[i*8+1]-_buf[i*8+5];
t2=_buf[i*8+2]+_buf[i*8+6];
t6=_buf[i*8+2]-_buf[i*8+6];
t3=_buf[i*8+3]+_buf[i*8+7];
t7=_buf[i*8+3]-_buf[i*8+7];
/*Hadamard stage 2:*/
r=t0;
t0+=t2;
t2=r-t2;
r=t1;
t1+=t3;
t3=r-t3;
r=t4;
t4+=t6;
t6=r-t6;
r=t5;
t5+=t7;
t7=r-t7;
/*Hadamard stage 3:*/
r=abs(t0+t1);
r+=abs(t0-t1);
r+=abs(t2+t3);
r+=abs(t2-t3);
r+=abs(t4+t5);
r+=abs(t4-t5);
r+=abs(t6+t7);
r+=abs(t6-t7);
sad+=r;
if(sad>_thresh)break;
}
return sad;
}
unsigned oc_enc_frag_satd_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref,int _ystride,
unsigned _thresh){
return (*_enc->opt_vtable.frag_satd_thresh)(_src,_ref,_ystride,_thresh);
}
unsigned oc_enc_frag_satd_thresh_c(const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _thresh){
ogg_int16_t buf[64];
oc_diff_hadamard(buf,_src,_ref,_ystride);
return oc_hadamard_sad_thresh(buf,_thresh);
}
unsigned oc_enc_frag_satd2_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref1,
const unsigned char *_ref2,int _ystride,unsigned _thresh){
return (*_enc->opt_vtable.frag_satd2_thresh)(_src,_ref1,_ref2,_ystride,
_thresh);
}
unsigned oc_enc_frag_satd2_thresh_c(const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride,
unsigned _thresh){
ogg_int16_t buf[64];
oc_diff_hadamard2(buf,_src,_ref1,_ref2,_ystride);
return oc_hadamard_sad_thresh(buf,_thresh);
}
unsigned oc_enc_frag_intra_satd(const oc_enc_ctx *_enc,
const unsigned char *_src,int _ystride){
return (*_enc->opt_vtable.frag_intra_satd)(_src,_ystride);
}
unsigned oc_enc_frag_intra_satd_c(const unsigned char *_src,int _ystride){
ogg_int16_t buf[64];
oc_intra_hadamard(buf,_src,_ystride);
return oc_hadamard_sad_thresh(buf,UINT_MAX)
-abs(buf[0]+buf[1]+buf[2]+buf[3]+buf[4]+buf[5]+buf[6]+buf[7]);
}
void oc_enc_frag_copy2(const oc_enc_ctx *_enc,unsigned char *_dst,
const unsigned char *_src1,const unsigned char *_src2,int _ystride){
(*_enc->opt_vtable.frag_copy2)(_dst,_src1,_src2,_ystride);
}
void oc_enc_frag_copy2_c(unsigned char *_dst,
const unsigned char *_src1,const unsigned char *_src2,int _ystride){
int i;
int j;
for(i=8;i-->0;){
for(j=0;j<8;j++)_dst[j]=_src1[j]+_src2[j]>>1;
_dst+=_ystride;
_src1+=_ystride;
_src2+=_ystride;
}
}
void oc_enc_frag_recon_intra(const oc_enc_ctx *_enc,
unsigned char *_dst,int _ystride,const ogg_int16_t _residue[64]){
(*_enc->opt_vtable.frag_recon_intra)(_dst,_ystride,_residue);
}
void oc_enc_frag_recon_inter(const oc_enc_ctx *_enc,unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]){
(*_enc->opt_vtable.frag_recon_inter)(_dst,_src,_ystride,_residue);
}

View File

@@ -0,0 +1,121 @@
#include <stdlib.h>
#include <string.h>
#include "internal.h"
#include "enquant.h"
#include "huffenc.h"
/*Packs a series of octets from a given byte array into the pack buffer.
_opb: The pack buffer to store the octets in.
_buf: The byte array containing the bytes to pack.
_len: The number of octets to pack.*/
static void oc_pack_octets(oggpack_buffer *_opb,const char *_buf,int _len){
int i;
for(i=0;i<_len;i++)oggpackB_write(_opb,_buf[i],8);
}
int oc_state_flushheader(oc_theora_state *_state,int *_packet_state,
oggpack_buffer *_opb,const th_quant_info *_qinfo,
const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS],
const char *_vendor,th_comment *_tc,ogg_packet *_op){
unsigned char *packet;
int b_o_s;
if(_op==NULL)return TH_EFAULT;
switch(*_packet_state){
/*Codec info header.*/
case OC_PACKET_INFO_HDR:{
if(_state==NULL)return TH_EFAULT;
oggpackB_reset(_opb);
/*Mark this packet as the info header.*/
oggpackB_write(_opb,0x80,8);
/*Write the codec string.*/
oc_pack_octets(_opb,"theora",6);
/*Write the codec bitstream version.*/
oggpackB_write(_opb,TH_VERSION_MAJOR,8);
oggpackB_write(_opb,TH_VERSION_MINOR,8);
oggpackB_write(_opb,TH_VERSION_SUB,8);
/*Describe the encoded frame.*/
oggpackB_write(_opb,_state->info.frame_width>>4,16);
oggpackB_write(_opb,_state->info.frame_height>>4,16);
oggpackB_write(_opb,_state->info.pic_width,24);
oggpackB_write(_opb,_state->info.pic_height,24);
oggpackB_write(_opb,_state->info.pic_x,8);
oggpackB_write(_opb,_state->info.pic_y,8);
oggpackB_write(_opb,_state->info.fps_numerator,32);
oggpackB_write(_opb,_state->info.fps_denominator,32);
oggpackB_write(_opb,_state->info.aspect_numerator,24);
oggpackB_write(_opb,_state->info.aspect_denominator,24);
oggpackB_write(_opb,_state->info.colorspace,8);
oggpackB_write(_opb,_state->info.target_bitrate,24);
oggpackB_write(_opb,_state->info.quality,6);
oggpackB_write(_opb,_state->info.keyframe_granule_shift,5);
oggpackB_write(_opb,_state->info.pixel_fmt,2);
/*Spare configuration bits.*/
oggpackB_write(_opb,0,3);
b_o_s=1;
}break;
/*Comment header.*/
case OC_PACKET_COMMENT_HDR:{
int vendor_len;
int i;
if(_tc==NULL)return TH_EFAULT;
vendor_len=strlen(_vendor);
oggpackB_reset(_opb);
/*Mark this packet as the comment header.*/
oggpackB_write(_opb,0x81,8);
/*Write the codec string.*/
oc_pack_octets(_opb,"theora",6);
/*Write the vendor string.*/
oggpack_write(_opb,vendor_len,32);
oc_pack_octets(_opb,_vendor,vendor_len);
oggpack_write(_opb,_tc->comments,32);
for(i=0;i<_tc->comments;i++){
if(_tc->user_comments[i]!=NULL){
oggpack_write(_opb,_tc->comment_lengths[i],32);
oc_pack_octets(_opb,_tc->user_comments[i],_tc->comment_lengths[i]);
}
else oggpack_write(_opb,0,32);
}
b_o_s=0;
}break;
/*Codec setup header.*/
case OC_PACKET_SETUP_HDR:{
int ret;
oggpackB_reset(_opb);
/*Mark this packet as the setup header.*/
oggpackB_write(_opb,0x82,8);
/*Write the codec string.*/
oc_pack_octets(_opb,"theora",6);
/*Write the quantizer tables.*/
oc_quant_params_pack(_opb,_qinfo);
/*Write the huffman codes.*/
ret=oc_huff_codes_pack(_opb,_codes);
/*This should never happen, because we validate the tables when they
are set.
If you see, it's a good chance memory is being corrupted.*/
if(ret<0)return ret;
b_o_s=0;
}break;
/*No more headers to emit.*/
default:return 0;
}
/*This is kind of fugly: we hand the user a buffer which they do not own.
We will overwrite it when the next packet is output, so the user better be
done with it by then.
Vorbis is little better: it hands back buffers that it will free the next
time the headers are requested, or when the encoder is cleared.
Hopefully libogg2 will make this much cleaner.*/
packet=oggpackB_get_buffer(_opb);
/*If there's no packet, malloc failed while writing.*/
if(packet==NULL)return TH_EFAULT;
_op->packet=packet;
_op->bytes=oggpackB_bytes(_opb);
_op->b_o_s=b_o_s;
_op->e_o_s=0;
_op->granulepos=0;
_op->packetno=*_packet_state+3;
return ++(*_packet_state)+3;
}

View File

@@ -0,0 +1,493 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: encint.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_encint_H)
# define _encint_H (1)
# if defined(HAVE_CONFIG_H)
# include "config.h"
# endif
# include "theora/theoraenc.h"
# include "internal.h"
# include "ocintrin.h"
# include "mathops.h"
# include "enquant.h"
# include "huffenc.h"
/*# define OC_COLLECT_METRICS*/
typedef oc_mv oc_mv2[2];
typedef struct oc_enc_opt_vtable oc_enc_opt_vtable;
typedef struct oc_mb_enc_info oc_mb_enc_info;
typedef struct oc_mode_scheme_chooser oc_mode_scheme_chooser;
typedef struct oc_iir_filter oc_iir_filter;
typedef struct oc_frame_metrics oc_frame_metrics;
typedef struct oc_rc_state oc_rc_state;
typedef struct th_enc_ctx oc_enc_ctx;
typedef struct oc_token_checkpoint oc_token_checkpoint;
/*Constants for the packet-out state machine specific to the encoder.*/
/*Next packet to emit: Data packet, but none are ready yet.*/
#define OC_PACKET_EMPTY (0)
/*Next packet to emit: Data packet, and one is ready.*/
#define OC_PACKET_READY (1)
/*All features enabled.*/
#define OC_SP_LEVEL_SLOW (0)
/*Enable early skip.*/
#define OC_SP_LEVEL_EARLY_SKIP (1)
/*Disable motion compensation.*/
#define OC_SP_LEVEL_NOMC (2)
/*Maximum valid speed level.*/
#define OC_SP_LEVEL_MAX (2)
/*The bits used for each of the MB mode codebooks.*/
extern const unsigned char OC_MODE_BITS[2][OC_NMODES];
/*The bits used for each of the MV codebooks.*/
extern const unsigned char OC_MV_BITS[2][64];
/*The minimum value that can be stored in a SB run for each codeword.
The last entry is the upper bound on the length of a single SB run.*/
extern const ogg_uint16_t OC_SB_RUN_VAL_MIN[8];
/*The bits used for each SB run codeword.*/
extern const unsigned char OC_SB_RUN_CODE_NBITS[7];
/*The bits used for each block run length (starting with 1).*/
extern const unsigned char OC_BLOCK_RUN_CODE_NBITS[30];
/*Encoder specific functions with accelerated variants.*/
struct oc_enc_opt_vtable{
unsigned (*frag_sad)(const unsigned char *_src,
const unsigned char *_ref,int _ystride);
unsigned (*frag_sad_thresh)(const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _thresh);
unsigned (*frag_sad2_thresh)(const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride,
unsigned _thresh);
unsigned (*frag_satd_thresh)(const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _thresh);
unsigned (*frag_satd2_thresh)(const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride,
unsigned _thresh);
unsigned (*frag_intra_satd)(const unsigned char *_src,int _ystride);
void (*frag_sub)(ogg_int16_t _diff[64],const unsigned char *_src,
const unsigned char *_ref,int _ystride);
void (*frag_sub_128)(ogg_int16_t _diff[64],
const unsigned char *_src,int _ystride);
void (*frag_copy2)(unsigned char *_dst,
const unsigned char *_src1,const unsigned char *_src2,int _ystride);
void (*frag_recon_intra)(unsigned char *_dst,int _ystride,
const ogg_int16_t _residue[64]);
void (*frag_recon_inter)(unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]);
void (*fdct8x8)(ogg_int16_t _y[64],const ogg_int16_t _x[64]);
};
void oc_enc_vtable_init(oc_enc_ctx *_enc);
/*Encoder-specific macroblock information.*/
struct oc_mb_enc_info{
/*Neighboring macro blocks that have MVs available from the current frame.*/
unsigned cneighbors[4];
/*Neighboring macro blocks to use for MVs from the previous frame.*/
unsigned pneighbors[4];
/*The number of current-frame neighbors.*/
unsigned char ncneighbors;
/*The number of previous-frame neighbors.*/
unsigned char npneighbors;
/*Flags indicating which MB modes have been refined.*/
unsigned char refined;
/*Motion vectors for a macro block for the current frame and the
previous two frames.
Each is a set of 2 vectors against OC_FRAME_GOLD and OC_FRAME_PREV, which
can be used to estimate constant velocity and constant acceleration
predictors.
Uninitialized MVs are (0,0).*/
oc_mv2 analysis_mv[3];
/*Current unrefined analysis MVs.*/
oc_mv unref_mv[2];
/*Unrefined block MVs.*/
oc_mv block_mv[4];
/*Refined block MVs.*/
oc_mv ref_mv[4];
/*Minimum motion estimation error from the analysis stage.*/
ogg_uint16_t error[2];
/*MB error for half-pel refinement for each frame type.*/
unsigned satd[2];
/*Block error for half-pel refinement.*/
unsigned block_satd[4];
};
/*State machine to estimate the opportunity cost of coding a MB mode.*/
struct oc_mode_scheme_chooser{
/*Pointers to the a list containing the index of each mode in the mode
alphabet used by each scheme.
The first entry points to the dynamic scheme0_ranks, while the remaining 7
point to the constant entries stored in OC_MODE_SCHEMES.*/
const unsigned char *mode_ranks[8];
/*The ranks for each mode when coded with scheme 0.
These are optimized so that the more frequent modes have lower ranks.*/
unsigned char scheme0_ranks[OC_NMODES];
/*The list of modes, sorted in descending order of frequency, that
corresponds to the ranks above.*/
unsigned char scheme0_list[OC_NMODES];
/*The number of times each mode has been chosen so far.*/
int mode_counts[OC_NMODES];
/*The list of mode coding schemes, sorted in ascending order of bit cost.*/
unsigned char scheme_list[8];
/*The number of bits used by each mode coding scheme.*/
ptrdiff_t scheme_bits[8];
};
void oc_mode_scheme_chooser_init(oc_mode_scheme_chooser *_chooser);
/*A 2nd order low-pass Bessel follower.
We use this for rate control because it has fast reaction time, but is
critically damped.*/
struct oc_iir_filter{
ogg_int32_t c[2];
ogg_int64_t g;
ogg_int32_t x[2];
ogg_int32_t y[2];
};
/*The 2-pass metrics associated with a single frame.*/
struct oc_frame_metrics{
/*The log base 2 of the scale factor for this frame in Q24 format.*/
ogg_int32_t log_scale;
/*The number of application-requested duplicates of this frame.*/
unsigned dup_count:31;
/*The frame type from pass 1.*/
unsigned frame_type:1;
};
/*Rate control state information.*/
struct oc_rc_state{
/*The target average bits per frame.*/
ogg_int64_t bits_per_frame;
/*The current buffer fullness (bits available to be used).*/
ogg_int64_t fullness;
/*The target buffer fullness.
This is where we'd like to be by the last keyframe the appears in the next
buf_delay frames.*/
ogg_int64_t target;
/*The maximum buffer fullness (total size of the buffer).*/
ogg_int64_t max;
/*The log of the number of pixels in a frame in Q57 format.*/
ogg_int64_t log_npixels;
/*The exponent used in the rate model in Q8 format.*/
unsigned exp[2];
/*The number of frames to distribute the buffer usage over.*/
int buf_delay;
/*The total drop count from the previous frame.
This includes duplicates explicitly requested via the
TH_ENCCTL_SET_DUP_COUNT API as well as frames we chose to drop ourselves.*/
ogg_uint32_t prev_drop_count;
/*The log of an estimated scale factor used to obtain the real framerate, for
VFR sources or, e.g., 12 fps content doubled to 24 fps, etc.*/
ogg_int64_t log_drop_scale;
/*The log of estimated scale factor for the rate model in Q57 format.*/
ogg_int64_t log_scale[2];
/*The log of the target quantizer level in Q57 format.*/
ogg_int64_t log_qtarget;
/*Will we drop frames to meet bitrate target?*/
unsigned char drop_frames;
/*Do we respect the maximum buffer fullness?*/
unsigned char cap_overflow;
/*Can the reservoir go negative?*/
unsigned char cap_underflow;
/*Second-order lowpass filters to track scale and VFR.*/
oc_iir_filter scalefilter[2];
int inter_count;
int inter_delay;
int inter_delay_target;
oc_iir_filter vfrfilter;
/*Two-pass mode state.
0 => 1-pass encoding.
1 => 1st pass of 2-pass encoding.
2 => 2nd pass of 2-pass encoding.*/
int twopass;
/*Buffer for current frame metrics.*/
unsigned char twopass_buffer[48];
/*The number of bytes in the frame metrics buffer.
When 2-pass encoding is enabled, this is set to 0 after each frame is
submitted, and must be non-zero before the next frame will be accepted.*/
int twopass_buffer_bytes;
int twopass_buffer_fill;
/*Whether or not to force the next frame to be a keyframe.*/
unsigned char twopass_force_kf;
/*The metrics for the previous frame.*/
oc_frame_metrics prev_metrics;
/*The metrics for the current frame.*/
oc_frame_metrics cur_metrics;
/*The buffered metrics for future frames.*/
oc_frame_metrics *frame_metrics;
int nframe_metrics;
int cframe_metrics;
/*The index of the current frame in the circular metric buffer.*/
int frame_metrics_head;
/*The frame count of each type (keyframes, delta frames, and dup frames);
32 bits limits us to 2.268 years at 60 fps.*/
ogg_uint32_t frames_total[3];
/*The number of frames of each type yet to be processed.*/
ogg_uint32_t frames_left[3];
/*The sum of the scale values for each frame type.*/
ogg_int64_t scale_sum[2];
/*The start of the window over which the current scale sums are taken.*/
int scale_window0;
/*The end of the window over which the current scale sums are taken.*/
int scale_window_end;
/*The frame count of each type in the current 2-pass window; this does not
include dup frames.*/
int nframes[3];
/*The total accumulated estimation bias.*/
ogg_int64_t rate_bias;
};
void oc_rc_state_init(oc_rc_state *_rc,oc_enc_ctx *_enc);
void oc_rc_state_clear(oc_rc_state *_rc);
void oc_enc_rc_resize(oc_enc_ctx *_enc);
int oc_enc_select_qi(oc_enc_ctx *_enc,int _qti,int _clamp);
void oc_enc_calc_lambda(oc_enc_ctx *_enc,int _frame_type);
int oc_enc_update_rc_state(oc_enc_ctx *_enc,
long _bits,int _qti,int _qi,int _trial,int _droppable);
int oc_enc_rc_2pass_out(oc_enc_ctx *_enc,unsigned char **_buf);
int oc_enc_rc_2pass_in(oc_enc_ctx *_enc,unsigned char *_buf,size_t _bytes);
/*The internal encoder state.*/
struct th_enc_ctx{
/*Shared encoder/decoder state.*/
oc_theora_state state;
/*Buffer in which to assemble packets.*/
oggpack_buffer opb;
/*Encoder-specific macroblock information.*/
oc_mb_enc_info *mb_info;
/*DC coefficients after prediction.*/
ogg_int16_t *frag_dc;
/*The list of coded macro blocks, in coded order.*/
unsigned *coded_mbis;
/*The number of coded macro blocks.*/
size_t ncoded_mbis;
/*Whether or not packets are ready to be emitted.
This takes on negative values while there are remaining header packets to
be emitted, reaches 0 when the codec is ready for input, and becomes
positive when a frame has been processed and data packets are ready.*/
int packet_state;
/*The maximum distance between keyframes.*/
ogg_uint32_t keyframe_frequency_force;
/*The number of duplicates to produce for the next frame.*/
ogg_uint32_t dup_count;
/*The number of duplicates remaining to be emitted for the current frame.*/
ogg_uint32_t nqueued_dups;
/*The number of duplicates emitted for the last frame.*/
ogg_uint32_t prev_dup_count;
/*The current speed level.*/
int sp_level;
/*Whether or not VP3 compatibility mode has been enabled.*/
unsigned char vp3_compatible;
/*Whether or not any INTER frames have been coded.*/
unsigned char coded_inter_frame;
/*Whether or not previous frame was dropped.*/
unsigned char prevframe_dropped;
/*Stores most recently chosen Huffman tables for each frame type, DC and AC
coefficients, and luma and chroma tokens.
The actual Huffman table used for a given coefficient depends not only on
the choice made here, but also its index in the zig-zag ordering.*/
unsigned char huff_idxs[2][2][2];
/*Current count of bits used by each MV coding mode.*/
size_t mv_bits[2];
/*The mode scheme chooser for estimating mode coding costs.*/
oc_mode_scheme_chooser chooser;
/*The number of vertical super blocks in an MCU.*/
int mcu_nvsbs;
/*The SSD error for skipping each fragment in the current MCU.*/
unsigned *mcu_skip_ssd;
/*The DCT token lists for each coefficient and each plane.*/
unsigned char **dct_tokens[3];
/*The extra bits associated with each DCT token.*/
ogg_uint16_t **extra_bits[3];
/*The number of DCT tokens for each coefficient for each plane.*/
ptrdiff_t ndct_tokens[3][64];
/*Pending EOB runs for each coefficient for each plane.*/
ogg_uint16_t eob_run[3][64];
/*The offset of the first DCT token for each coefficient for each plane.*/
unsigned char dct_token_offs[3][64];
/*The last DC coefficient for each plane and reference frame.*/
int dc_pred_last[3][3];
#if defined(OC_COLLECT_METRICS)
/*Fragment SATD statistics for MB mode estimation metrics.*/
unsigned *frag_satd;
/*Fragment SSD statistics for MB mode estimation metrics.*/
unsigned *frag_ssd;
#endif
/*The R-D optimization parameter.*/
int lambda;
/*The huffman tables in use.*/
th_huff_code huff_codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS];
/*The quantization parameters in use.*/
th_quant_info qinfo;
oc_iquant *enquant_tables[64][3][2];
oc_iquant_table enquant_table_data[64][3][2];
/*An "average" quantizer for each quantizer type (INTRA or INTER) and qi
value.
This is used to paramterize the rate control decisions.
They are kept in the log domain to simplify later processing.
Keep in mind these are DCT domain quantizers, and so are scaled by an
additional factor of 4 from the pixel domain.*/
ogg_int64_t log_qavg[2][64];
/*The buffer state used to drive rate control.*/
oc_rc_state rc;
/*Table for encoder acceleration functions.*/
oc_enc_opt_vtable opt_vtable;
};
void oc_enc_analyze_intra(oc_enc_ctx *_enc,int _recode);
int oc_enc_analyze_inter(oc_enc_ctx *_enc,int _allow_keyframe,int _recode);
#if defined(OC_COLLECT_METRICS)
void oc_enc_mode_metrics_collect(oc_enc_ctx *_enc);
void oc_enc_mode_metrics_dump(oc_enc_ctx *_enc);
#endif
/*Perform fullpel motion search for a single MB against both reference frames.*/
void oc_mcenc_search(oc_enc_ctx *_enc,int _mbi);
/*Refine a MB MV for one frame.*/
void oc_mcenc_refine1mv(oc_enc_ctx *_enc,int _mbi,int _frame);
/*Refine the block MVs.*/
void oc_mcenc_refine4mv(oc_enc_ctx *_enc,int _mbi);
/*Used to rollback a tokenlog transaction when we retroactively decide to skip
a fragment.
A checkpoint is taken right before each token is added.*/
struct oc_token_checkpoint{
/*The color plane the token was added to.*/
unsigned char pli;
/*The zig-zag index the token was added to.*/
unsigned char zzi;
/*The outstanding EOB run count before the token was added.*/
ogg_uint16_t eob_run;
/*The token count before the token was added.*/
ptrdiff_t ndct_tokens;
};
void oc_enc_tokenize_start(oc_enc_ctx *_enc);
int oc_enc_tokenize_ac(oc_enc_ctx *_enc,int _pli,ptrdiff_t _fragi,
ogg_int16_t *_qdct,const ogg_uint16_t *_dequant,const ogg_int16_t *_dct,
int _zzi,oc_token_checkpoint **_stack,int _acmin);
void oc_enc_tokenlog_rollback(oc_enc_ctx *_enc,
const oc_token_checkpoint *_stack,int _n);
void oc_enc_pred_dc_frag_rows(oc_enc_ctx *_enc,
int _pli,int _fragy0,int _frag_yend);
void oc_enc_tokenize_dc_frag_list(oc_enc_ctx *_enc,int _pli,
const ptrdiff_t *_coded_fragis,ptrdiff_t _ncoded_fragis,
int _prev_ndct_tokens1,int _prev_eob_run1);
void oc_enc_tokenize_finish(oc_enc_ctx *_enc);
/*Utility routine to encode one of the header packets.*/
int oc_state_flushheader(oc_theora_state *_state,int *_packet_state,
oggpack_buffer *_opb,const th_quant_info *_qinfo,
const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS],
const char *_vendor,th_comment *_tc,ogg_packet *_op);
/*Encoder-specific accelerated functions.*/
void oc_enc_frag_sub(const oc_enc_ctx *_enc,ogg_int16_t _diff[64],
const unsigned char *_src,const unsigned char *_ref,int _ystride);
void oc_enc_frag_sub_128(const oc_enc_ctx *_enc,ogg_int16_t _diff[64],
const unsigned char *_src,int _ystride);
unsigned oc_enc_frag_sad(const oc_enc_ctx *_enc,const unsigned char *_src,
const unsigned char *_ref,int _ystride);
unsigned oc_enc_frag_sad_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref,int _ystride,
unsigned _thresh);
unsigned oc_enc_frag_sad2_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref1,
const unsigned char *_ref2,int _ystride,unsigned _thresh);
unsigned oc_enc_frag_satd_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref,int _ystride,
unsigned _thresh);
unsigned oc_enc_frag_satd2_thresh(const oc_enc_ctx *_enc,
const unsigned char *_src,const unsigned char *_ref1,
const unsigned char *_ref2,int _ystride,unsigned _thresh);
unsigned oc_enc_frag_intra_satd(const oc_enc_ctx *_enc,
const unsigned char *_src,int _ystride);
void oc_enc_frag_copy2(const oc_enc_ctx *_enc,unsigned char *_dst,
const unsigned char *_src1,const unsigned char *_src2,int _ystride);
void oc_enc_frag_recon_intra(const oc_enc_ctx *_enc,
unsigned char *_dst,int _ystride,const ogg_int16_t _residue[64]);
void oc_enc_frag_recon_inter(const oc_enc_ctx *_enc,unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]);
void oc_enc_fdct8x8(const oc_enc_ctx *_enc,ogg_int16_t _y[64],
const ogg_int16_t _x[64]);
/*Default pure-C implementations.*/
void oc_enc_vtable_init_c(oc_enc_ctx *_enc);
void oc_enc_frag_sub_c(ogg_int16_t _diff[64],
const unsigned char *_src,const unsigned char *_ref,int _ystride);
void oc_enc_frag_sub_128_c(ogg_int16_t _diff[64],
const unsigned char *_src,int _ystride);
void oc_enc_frag_copy2_c(unsigned char *_dst,
const unsigned char *_src1,const unsigned char *_src2,int _ystride);
unsigned oc_enc_frag_sad_c(const unsigned char *_src,
const unsigned char *_ref,int _ystride);
unsigned oc_enc_frag_sad_thresh_c(const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _thresh);
unsigned oc_enc_frag_sad2_thresh_c(const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride,
unsigned _thresh);
unsigned oc_enc_frag_satd_thresh_c(const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _thresh);
unsigned oc_enc_frag_satd2_thresh_c(const unsigned char *_src,
const unsigned char *_ref1,const unsigned char *_ref2,int _ystride,
unsigned _thresh);
unsigned oc_enc_frag_intra_satd_c(const unsigned char *_src,int _ystride);
void oc_enc_fdct8x8_c(ogg_int16_t _y[64],const ogg_int16_t _x[64]);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: enquant.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include "encint.h"
void oc_quant_params_pack(oggpack_buffer *_opb,const th_quant_info *_qinfo){
const th_quant_ranges *qranges;
const th_quant_base *base_mats[2*3*64];
int indices[2][3][64];
int nbase_mats;
int nbits;
int ci;
int qi;
int qri;
int qti;
int pli;
int qtj;
int plj;
int bmi;
int i;
i=_qinfo->loop_filter_limits[0];
for(qi=1;qi<64;qi++)i=OC_MAXI(i,_qinfo->loop_filter_limits[qi]);
nbits=OC_ILOG_32(i);
oggpackB_write(_opb,nbits,3);
for(qi=0;qi<64;qi++){
oggpackB_write(_opb,_qinfo->loop_filter_limits[qi],nbits);
}
/*580 bits for VP3.*/
i=1;
for(qi=0;qi<64;qi++)i=OC_MAXI(_qinfo->ac_scale[qi],i);
nbits=OC_ILOGNZ_32(i);
oggpackB_write(_opb,nbits-1,4);
for(qi=0;qi<64;qi++)oggpackB_write(_opb,_qinfo->ac_scale[qi],nbits);
/*516 bits for VP3.*/
i=1;
for(qi=0;qi<64;qi++)i=OC_MAXI(_qinfo->dc_scale[qi],i);
nbits=OC_ILOGNZ_32(i);
oggpackB_write(_opb,nbits-1,4);
for(qi=0;qi<64;qi++)oggpackB_write(_opb,_qinfo->dc_scale[qi],nbits);
/*Consolidate any duplicate base matrices.*/
nbase_mats=0;
for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
qranges=_qinfo->qi_ranges[qti]+pli;
for(qri=0;qri<=qranges->nranges;qri++){
for(bmi=0;;bmi++){
if(bmi>=nbase_mats){
base_mats[bmi]=qranges->base_matrices+qri;
indices[qti][pli][qri]=nbase_mats++;
break;
}
else if(memcmp(base_mats[bmi][0],qranges->base_matrices[qri],
sizeof(base_mats[bmi][0]))==0){
indices[qti][pli][qri]=bmi;
break;
}
}
}
}
/*Write out the list of unique base matrices.
1545 bits for VP3 matrices.*/
oggpackB_write(_opb,nbase_mats-1,9);
for(bmi=0;bmi<nbase_mats;bmi++){
for(ci=0;ci<64;ci++)oggpackB_write(_opb,base_mats[bmi][0][ci],8);
}
/*Now store quant ranges and their associated indices into the base matrix
list.
46 bits for VP3 matrices.*/
nbits=OC_ILOG_32(nbase_mats-1);
for(i=0;i<6;i++){
qti=i/3;
pli=i%3;
qranges=_qinfo->qi_ranges[qti]+pli;
if(i>0){
if(qti>0){
if(qranges->nranges==_qinfo->qi_ranges[qti-1][pli].nranges&&
memcmp(qranges->sizes,_qinfo->qi_ranges[qti-1][pli].sizes,
qranges->nranges*sizeof(qranges->sizes[0]))==0&&
memcmp(indices[qti][pli],indices[qti-1][pli],
(qranges->nranges+1)*sizeof(indices[qti][pli][0]))==0){
oggpackB_write(_opb,1,2);
continue;
}
}
qtj=(i-1)/3;
plj=(i-1)%3;
if(qranges->nranges==_qinfo->qi_ranges[qtj][plj].nranges&&
memcmp(qranges->sizes,_qinfo->qi_ranges[qtj][plj].sizes,
qranges->nranges*sizeof(qranges->sizes[0]))==0&&
memcmp(indices[qti][pli],indices[qtj][plj],
(qranges->nranges+1)*sizeof(indices[qti][pli][0]))==0){
oggpackB_write(_opb,0,1+(qti>0));
continue;
}
oggpackB_write(_opb,1,1);
}
oggpackB_write(_opb,indices[qti][pli][0],nbits);
for(qi=qri=0;qi<63;qri++){
oggpackB_write(_opb,qranges->sizes[qri]-1,OC_ILOG_32(62-qi));
qi+=qranges->sizes[qri];
oggpackB_write(_opb,indices[qti][pli][qri+1],nbits);
}
}
}
static void oc_iquant_init(oc_iquant *_this,ogg_uint16_t _d){
ogg_uint32_t t;
int l;
_d<<=1;
l=OC_ILOGNZ_32(_d)-1;
t=1+((ogg_uint32_t)1<<16+l)/_d;
_this->m=(ogg_int16_t)(t-0x10000);
_this->l=l;
}
/*See comments at oc_dequant_tables_init() for how the quantization tables'
storage should be initialized.*/
void oc_enquant_tables_init(ogg_uint16_t *_dequant[64][3][2],
oc_iquant *_enquant[64][3][2],const th_quant_info *_qinfo){
int qi;
int pli;
int qti;
/*Initialize the dequantization tables first.*/
oc_dequant_tables_init(_dequant,NULL,_qinfo);
/*Derive the quantization tables directly from the dequantization tables.*/
for(qi=0;qi<64;qi++)for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
int zzi;
int plj;
int qtj;
int dupe;
dupe=0;
for(qtj=0;qtj<=qti;qtj++){
for(plj=0;plj<(qtj<qti?3:pli);plj++){
if(_dequant[qi][pli][qti]==_dequant[qi][plj][qtj]){
dupe=1;
break;
}
}
if(dupe)break;
}
if(dupe){
_enquant[qi][pli][qti]=_enquant[qi][plj][qtj];
continue;
}
/*In the original VP3.2 code, the rounding offset and the size of the
dead zone around 0 were controlled by a "sharpness" parameter.
We now R-D optimize the tokens for each block after quantization,
so the rounding offset should always be 1/2, and an explicit dead
zone is unnecessary.
Hence, all of that VP3.2 code is gone from here, and the remaining
floating point code has been implemented as equivalent integer
code with exact precision.*/
for(zzi=0;zzi<64;zzi++){
oc_iquant_init(_enquant[qi][pli][qti]+zzi,
_dequant[qi][pli][qti][zzi]);
}
}
}
/*This table gives the square root of the fraction of the squared magnitude of
each DCT coefficient relative to the total, scaled by 2**16, for both INTRA
and INTER modes.
These values were measured after motion-compensated prediction, before
quantization, over a large set of test video (from QCIF to 1080p) encoded at
all possible rates.
The DC coefficient takes into account the DPCM prediction (using the
quantized values from neighboring blocks, as the encoder does, but still
before quantization of the coefficient in the current block).
The results differ significantly from the expected variance (e.g., using an
AR(1) model of the signal with rho=0.95, as is frequently done to compute
the coding gain of the DCT).
We use them to estimate an "average" quantizer for a given quantizer matrix,
as this is used to parameterize a number of the rate control decisions.
These values are themselves probably quantizer-matrix dependent, since the
shape of the matrix affects the noise distribution in the reference frames,
but they should at least give us _some_ amount of adaptivity to different
matrices, as opposed to hard-coding a table of average Q values for the
current set.
The main features they capture are that a) only a few of the quantizers in
the upper-left corner contribute anything significant at all (though INTER
mode is significantly flatter) and b) the DPCM prediction of the DC
coefficient gives a very minor improvement in the INTRA case and a quite
significant one in the INTER case (over the expected variance).*/
static const ogg_uint16_t OC_RPSD[2][64]={
{
52725,17370,10399, 6867, 5115, 3798, 2942, 2076,
17370, 9900, 6948, 4994, 3836, 2869, 2229, 1619,
10399, 6948, 5516, 4202, 3376, 2573, 2015, 1461,
6867, 4994, 4202, 3377, 2800, 2164, 1718, 1243,
5115, 3836, 3376, 2800, 2391, 1884, 1530, 1091,
3798, 2869, 2573, 2164, 1884, 1495, 1212, 873,
2942, 2229, 2015, 1718, 1530, 1212, 1001, 704,
2076, 1619, 1461, 1243, 1091, 873, 704, 474
},
{
23411,15604,13529,11601,10683, 8958, 7840, 6142,
15604,11901,10718, 9108, 8290, 6961, 6023, 4487,
13529,10718, 9961, 8527, 7945, 6689, 5742, 4333,
11601, 9108, 8527, 7414, 7084, 5923, 5175, 3743,
10683, 8290, 7945, 7084, 6771, 5754, 4793, 3504,
8958, 6961, 6689, 5923, 5754, 4679, 3936, 2989,
7840, 6023, 5742, 5175, 4793, 3936, 3522, 2558,
6142, 4487, 4333, 3743, 3504, 2989, 2558, 1829
}
};
/*The fraction of the squared magnitude of the residuals in each color channel
relative to the total, scaled by 2**16, for each pixel format.
These values were measured after motion-compensated prediction, before
quantization, over a large set of test video encoded at all possible rates.
TODO: These values are only from INTER frames; it should be re-measured for
INTRA frames.*/
static const ogg_uint16_t OC_PCD[4][3]={
{59926, 3038, 2572},
{55201, 5597, 4738},
{55201, 5597, 4738},
{47682, 9669, 8185}
};
/*Compute an "average" quantizer for each qi level.
We do one for INTER and one for INTRA, since their behavior is very
different, but average across chroma channels.
The basic approach is to compute a harmonic average of the squared quantizer,
weighted by the expected squared magnitude of the DCT coefficients.
Under the (not quite true) assumption that DCT coefficients are
Laplacian-distributed, this preserves the product Q*lambda, where
lambda=sqrt(2/sigma**2) is the Laplacian distribution parameter (not to be
confused with the lambda used in R-D optimization throughout most of the
rest of the code).
The value Q*lambda completely determines the entropy of the coefficients.*/
void oc_enquant_qavg_init(ogg_int64_t _log_qavg[2][64],
ogg_uint16_t *_dequant[64][3][2],int _pixel_fmt){
int qi;
int pli;
int qti;
int ci;
for(qti=0;qti<2;qti++)for(qi=0;qi<64;qi++){
ogg_int64_t q2;
q2=0;
for(pli=0;pli<3;pli++){
ogg_uint32_t qp;
qp=0;
for(ci=0;ci<64;ci++){
unsigned rq;
unsigned qd;
qd=_dequant[qi][pli][qti][OC_IZIG_ZAG[ci]];
rq=(OC_RPSD[qti][ci]+(qd>>1))/qd;
qp+=rq*(ogg_uint32_t)rq;
}
q2+=OC_PCD[_pixel_fmt][pli]*(ogg_int64_t)qp;
}
/*qavg=1.0/sqrt(q2).*/
_log_qavg[qti][qi]=OC_Q57(48)-oc_blog64(q2)>>1;
}
}

View File

@@ -0,0 +1,27 @@
#if !defined(_enquant_H)
# define _enquant_H (1)
# include "quant.h"
typedef struct oc_iquant oc_iquant;
#define OC_QUANT_MAX_LOG (OC_Q57(OC_STATIC_ILOG_32(OC_QUANT_MAX)-1))
/*Used to compute x/d via ((x*m>>16)+x>>l)+(x<0))
(i.e., one 16x16->16 mul, 2 shifts, and 2 adds).
This is not an approximation; for 16-bit x and d, it is exact.*/
struct oc_iquant{
ogg_int16_t m;
ogg_int16_t l;
};
typedef oc_iquant oc_iquant_table[64];
void oc_quant_params_pack(oggpack_buffer *_opb,const th_quant_info *_qinfo);
void oc_enquant_tables_init(ogg_uint16_t *_dequant[64][3][2],
oc_iquant *_enquant[64][3][2],const th_quant_info *_qinfo);
void oc_enquant_qavg_init(ogg_int64_t _log_qavg[2][64],
ogg_uint16_t *_dequant[64][3][2],int _pixel_fmt);
#endif

View File

@@ -0,0 +1,422 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: fdct.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include "encint.h"
#include "dct.h"
/*Performs a forward 8 point Type-II DCT transform.
The output is scaled by a factor of 2 from the orthonormal version of the
transform.
_y: The buffer to store the result in.
Data will be placed the first 8 entries (e.g., in a row of an 8x8 block).
_x: The input coefficients.
Every 8th entry is used (e.g., from a column of an 8x8 block).*/
static void oc_fdct8(ogg_int16_t _y[8],const ogg_int16_t *_x){
int t0;
int t1;
int t2;
int t3;
int t4;
int t5;
int t6;
int t7;
int r;
int s;
int u;
int v;
/*Stage 1:*/
/*0-7 butterfly.*/
t0=_x[0<<3]+(int)_x[7<<3];
t7=_x[0<<3]-(int)_x[7<<3];
/*1-6 butterfly.*/
t1=_x[1<<3]+(int)_x[6<<3];
t6=_x[1<<3]-(int)_x[6<<3];
/*2-5 butterfly.*/
t2=_x[2<<3]+(int)_x[5<<3];
t5=_x[2<<3]-(int)_x[5<<3];
/*3-4 butterfly.*/
t3=_x[3<<3]+(int)_x[4<<3];
t4=_x[3<<3]-(int)_x[4<<3];
/*Stage 2:*/
/*0-3 butterfly.*/
r=t0+t3;
t3=t0-t3;
t0=r;
/*1-2 butterfly.*/
r=t1+t2;
t2=t1-t2;
t1=r;
/*6-5 butterfly.*/
r=t6+t5;
t5=t6-t5;
t6=r;
/*Stages 3 and 4 are where all the approximation occurs.
These are chosen to be as close to an exact inverse of the approximations
made in the iDCT as possible, while still using mostly 16-bit arithmetic.
We use some 16x16->32 signed MACs, but those still commonly execute in 1
cycle on a 16-bit DSP.
For example, s=(27146*t5+0x4000>>16)+t5+(t5!=0) is an exact inverse of
t5=(OC_C4S4*s>>16).
That is, applying the latter to the output of the former will recover t5
exactly (over the valid input range of t5, -23171...23169).
We increase the rounding bias to 0xB500 in this particular case so that
errors inverting the subsequent butterfly are not one-sided (e.g., the
mean error is very close to zero).
The (t5!=0) term could be replaced simply by 1, but we want to send 0 to 0.
The fDCT of an all-zeros block will still not be zero, because of the
biases we added at the very beginning of the process, but it will be close
enough that it is guaranteed to round to zero.*/
/*Stage 3:*/
/*4-5 butterfly.*/
s=(27146*t5+0xB500>>16)+t5+(t5!=0)>>1;
r=t4+s;
t5=t4-s;
t4=r;
/*7-6 butterfly.*/
s=(27146*t6+0xB500>>16)+t6+(t6!=0)>>1;
r=t7+s;
t6=t7-s;
t7=r;
/*Stage 4:*/
/*0-1 butterfly.*/
r=(27146*t0+0x4000>>16)+t0+(t0!=0);
s=(27146*t1+0xB500>>16)+t1+(t1!=0);
u=r+s>>1;
v=r-u;
_y[0]=u;
_y[4]=v;
/*3-2 rotation by 6pi/16*/
u=(OC_C6S2*t2+OC_C2S6*t3+0x6CB7>>16)+(t3!=0);
s=(OC_C6S2*u>>16)-t2;
v=(s*21600+0x2800>>18)+s+(s!=0);
_y[2]=u;
_y[6]=v;
/*6-5 rotation by 3pi/16*/
u=(OC_C5S3*t6+OC_C3S5*t5+0x0E3D>>16)+(t5!=0);
s=t6-(OC_C5S3*u>>16);
v=(s*26568+0x3400>>17)+s+(s!=0);
_y[5]=u;
_y[3]=v;
/*7-4 rotation by 7pi/16*/
u=(OC_C7S1*t4+OC_C1S7*t7+0x7B1B>>16)+(t7!=0);
s=(OC_C7S1*u>>16)-t4;
v=(s*20539+0x3000>>20)+s+(s!=0);
_y[1]=u;
_y[7]=v;
}
void oc_enc_fdct8x8(const oc_enc_ctx *_enc,ogg_int16_t _y[64],
const ogg_int16_t _x[64]){
(*_enc->opt_vtable.fdct8x8)(_y,_x);
}
/*Performs a forward 8x8 Type-II DCT transform.
The output is scaled by a factor of 4 relative to the orthonormal version
of the transform.
_y: The buffer to store the result in.
This may be the same as _x.
_x: The input coefficients. */
void oc_enc_fdct8x8_c(ogg_int16_t _y[64],const ogg_int16_t _x[64]){
const ogg_int16_t *in;
ogg_int16_t *end;
ogg_int16_t *out;
ogg_int16_t w[64];
int i;
/*Add two extra bits of working precision to improve accuracy; any more and
we could overflow.*/
for(i=0;i<64;i++)w[i]=_x[i]<<2;
/*These biases correct for some systematic error that remains in the full
fDCT->iDCT round trip.*/
w[0]+=(w[0]!=0)+1;
w[1]++;
w[8]--;
/*Transform columns of w into rows of _y.*/
for(in=w,out=_y,end=out+64;out<end;in++,out+=8)oc_fdct8(out,in);
/*Transform columns of _y into rows of w.*/
for(in=_y,out=w,end=out+64;out<end;in++,out+=8)oc_fdct8(out,in);
/*Round the result back to the external working precision (which is still
scaled by four relative to the orthogonal result).
TODO: We should just update the external working precision.*/
for(i=0;i<64;i++)_y[i]=w[i]+2>>2;
}
/*This does not seem to outperform simple LFE border padding before MC.
It yields higher PSNR, but much higher bitrate usage.*/
#if 0
typedef struct oc_extension_info oc_extension_info;
/*Information needed to pad boundary blocks.
We multiply each row/column by an extension matrix that fills in the padding
values as a linear combination of the active values, so that an equivalent
number of coefficients are forced to zero.
This costs at most 16 multiplies, the same as a 1-D fDCT itself, and as
little as 7 multiplies.
We compute the extension matrices for every possible shape in advance, as
there are only 35.
The coefficients for all matrices are stored in a single array to take
advantage of the overlap and repetitiveness of many of the shapes.
A similar technique is applied to the offsets into this array.
This reduces the required table storage by about 48%.
See tools/extgen.c for details.
We could conceivably do the same for all 256 possible shapes.*/
struct oc_extension_info{
/*The mask of the active pixels in the shape.*/
short mask;
/*The number of active pixels in the shape.*/
short na;
/*The extension matrix.
This is (8-na)xna*/
const ogg_int16_t *const *ext;
/*The pixel indices: na active pixels followed by 8-na padding pixels.*/
unsigned char pi[8];
/*The coefficient indices: na unconstrained coefficients followed by 8-na
coefficients to be forced to zero.*/
unsigned char ci[8];
};
/*The number of shapes we need.*/
#define OC_NSHAPES (35)
static const ogg_int16_t OC_EXT_COEFFS[229]={
0x7FFF,0xE1F8,0x6903,0xAA79,0x5587,0x7FFF,0x1E08,0x7FFF,
0x5587,0xAA79,0x6903,0xE1F8,0x7FFF,0x0000,0x0000,0x0000,
0x7FFF,0x0000,0x0000,0x7FFF,0x8000,0x7FFF,0x0000,0x0000,
0x7FFF,0xE1F8,0x1E08,0xB0A7,0xAA1D,0x337C,0x7FFF,0x4345,
0x2267,0x4345,0x7FFF,0x337C,0xAA1D,0xB0A7,0x8A8C,0x4F59,
0x03B4,0xE2D6,0x7FFF,0x2CF3,0x7FFF,0xE2D6,0x03B4,0x4F59,
0x8A8C,0x1103,0x7AEF,0x5225,0xDF60,0xC288,0xDF60,0x5225,
0x7AEF,0x1103,0x668A,0xD6EE,0x3A16,0x0E6C,0xFA07,0x0E6C,
0x3A16,0xD6EE,0x668A,0x2A79,0x2402,0x980F,0x50F5,0x4882,
0x50F5,0x980F,0x2402,0x2A79,0xF976,0x2768,0x5F22,0x2768,
0xF976,0x1F91,0x76C1,0xE9AE,0x76C1,0x1F91,0x7FFF,0xD185,
0x0FC8,0xD185,0x7FFF,0x4F59,0x4345,0xED62,0x4345,0x4F59,
0xF574,0x5D99,0x2CF3,0x5D99,0xF574,0x5587,0x3505,0x30FC,
0xF482,0x953C,0xEAC4,0x7FFF,0x4F04,0x7FFF,0xEAC4,0x953C,
0xF482,0x30FC,0x4F04,0x273D,0xD8C3,0x273D,0x1E09,0x61F7,
0x1E09,0x273D,0xD8C3,0x273D,0x4F04,0x30FC,0xA57E,0x153C,
0x6AC4,0x3C7A,0x1E08,0x3C7A,0x6AC4,0x153C,0xA57E,0x7FFF,
0xA57E,0x5A82,0x6AC4,0x153C,0xC386,0xE1F8,0xC386,0x153C,
0x6AC4,0x5A82,0xD8C3,0x273D,0x7FFF,0xE1F7,0x7FFF,0x273D,
0xD8C3,0x4F04,0x30FC,0xD8C3,0x273D,0xD8C3,0x30FC,0x4F04,
0x1FC8,0x67AD,0x1853,0xE038,0x1853,0x67AD,0x1FC8,0x4546,
0xE038,0x1FC8,0x3ABA,0x1FC8,0xE038,0x4546,0x3505,0x5587,
0xF574,0xBC11,0x78F4,0x4AFB,0xE6F3,0x4E12,0x3C11,0xF8F4,
0x4AFB,0x3C7A,0xF88B,0x3C11,0x78F4,0xCAFB,0x7FFF,0x08CC,
0x070C,0x236D,0x5587,0x236D,0x070C,0xF88B,0x3C7A,0x4AFB,
0xF8F4,0x3C11,0x7FFF,0x153C,0xCAFB,0x153C,0x7FFF,0x1E08,
0xE1F8,0x7FFF,0x08CC,0x7FFF,0xCAFB,0x78F4,0x3C11,0x4E12,
0xE6F3,0x4AFB,0x78F4,0xBC11,0xFE3D,0x7FFF,0xFE3D,0x2F3A,
0x7FFF,0x2F3A,0x89BC,0x7FFF,0x89BC
};
static const ogg_int16_t *const OC_EXT_ROWS[96]={
OC_EXT_COEFFS+ 0,OC_EXT_COEFFS+ 0,OC_EXT_COEFFS+ 0,OC_EXT_COEFFS+ 0,
OC_EXT_COEFFS+ 0,OC_EXT_COEFFS+ 0,OC_EXT_COEFFS+ 0,OC_EXT_COEFFS+ 6,
OC_EXT_COEFFS+ 27,OC_EXT_COEFFS+ 38,OC_EXT_COEFFS+ 43,OC_EXT_COEFFS+ 32,
OC_EXT_COEFFS+ 49,OC_EXT_COEFFS+ 58,OC_EXT_COEFFS+ 67,OC_EXT_COEFFS+ 71,
OC_EXT_COEFFS+ 62,OC_EXT_COEFFS+ 53,OC_EXT_COEFFS+ 12,OC_EXT_COEFFS+ 15,
OC_EXT_COEFFS+ 14,OC_EXT_COEFFS+ 13,OC_EXT_COEFFS+ 76,OC_EXT_COEFFS+ 81,
OC_EXT_COEFFS+ 86,OC_EXT_COEFFS+ 91,OC_EXT_COEFFS+ 96,OC_EXT_COEFFS+ 98,
OC_EXT_COEFFS+ 93,OC_EXT_COEFFS+ 88,OC_EXT_COEFFS+ 83,OC_EXT_COEFFS+ 78,
OC_EXT_COEFFS+ 12,OC_EXT_COEFFS+ 15,OC_EXT_COEFFS+ 15,OC_EXT_COEFFS+ 12,
OC_EXT_COEFFS+ 12,OC_EXT_COEFFS+ 15,OC_EXT_COEFFS+ 12,OC_EXT_COEFFS+ 15,
OC_EXT_COEFFS+ 15,OC_EXT_COEFFS+ 12,OC_EXT_COEFFS+ 103,OC_EXT_COEFFS+ 108,
OC_EXT_COEFFS+ 126,OC_EXT_COEFFS+ 16,OC_EXT_COEFFS+ 137,OC_EXT_COEFFS+ 141,
OC_EXT_COEFFS+ 20,OC_EXT_COEFFS+ 130,OC_EXT_COEFFS+ 113,OC_EXT_COEFFS+ 116,
OC_EXT_COEFFS+ 146,OC_EXT_COEFFS+ 153,OC_EXT_COEFFS+ 160,OC_EXT_COEFFS+ 167,
OC_EXT_COEFFS+ 170,OC_EXT_COEFFS+ 163,OC_EXT_COEFFS+ 156,OC_EXT_COEFFS+ 149,
OC_EXT_COEFFS+ 119,OC_EXT_COEFFS+ 122,OC_EXT_COEFFS+ 174,OC_EXT_COEFFS+ 177,
OC_EXT_COEFFS+ 182,OC_EXT_COEFFS+ 187,OC_EXT_COEFFS+ 192,OC_EXT_COEFFS+ 197,
OC_EXT_COEFFS+ 202,OC_EXT_COEFFS+ 207,OC_EXT_COEFFS+ 210,OC_EXT_COEFFS+ 215,
OC_EXT_COEFFS+ 179,OC_EXT_COEFFS+ 189,OC_EXT_COEFFS+ 24,OC_EXT_COEFFS+ 204,
OC_EXT_COEFFS+ 184,OC_EXT_COEFFS+ 194,OC_EXT_COEFFS+ 212,OC_EXT_COEFFS+ 199,
OC_EXT_COEFFS+ 217,OC_EXT_COEFFS+ 100,OC_EXT_COEFFS+ 134,OC_EXT_COEFFS+ 135,
OC_EXT_COEFFS+ 135,OC_EXT_COEFFS+ 12,OC_EXT_COEFFS+ 15,OC_EXT_COEFFS+ 134,
OC_EXT_COEFFS+ 134,OC_EXT_COEFFS+ 135,OC_EXT_COEFFS+ 220,OC_EXT_COEFFS+ 223,
OC_EXT_COEFFS+ 226,OC_EXT_COEFFS+ 227,OC_EXT_COEFFS+ 224,OC_EXT_COEFFS+ 221
};
static const oc_extension_info OC_EXTENSION_INFO[OC_NSHAPES]={
{0x7F,7,OC_EXT_ROWS+ 0,{0,1,2,3,4,5,6,7},{0,1,2,4,5,6,7,3}},
{0xFE,7,OC_EXT_ROWS+ 7,{1,2,3,4,5,6,7,0},{0,1,2,4,5,6,7,3}},
{0x3F,6,OC_EXT_ROWS+ 8,{0,1,2,3,4,5,7,6},{0,1,3,4,6,7,5,2}},
{0xFC,6,OC_EXT_ROWS+ 10,{2,3,4,5,6,7,1,0},{0,1,3,4,6,7,5,2}},
{0x1F,5,OC_EXT_ROWS+ 12,{0,1,2,3,4,7,6,5},{0,2,3,5,7,6,4,1}},
{0xF8,5,OC_EXT_ROWS+ 15,{3,4,5,6,7,2,1,0},{0,2,3,5,7,6,4,1}},
{0x0F,4,OC_EXT_ROWS+ 18,{0,1,2,3,7,6,5,4},{0,2,4,6,7,5,3,1}},
{0xF0,4,OC_EXT_ROWS+ 18,{4,5,6,7,3,2,1,0},{0,2,4,6,7,5,3,1}},
{0x07,3,OC_EXT_ROWS+ 22,{0,1,2,7,6,5,4,3},{0,3,6,7,5,4,2,1}},
{0xE0,3,OC_EXT_ROWS+ 27,{5,6,7,4,3,2,1,0},{0,3,6,7,5,4,2,1}},
{0x03,2,OC_EXT_ROWS+ 32,{0,1,7,6,5,4,3,2},{0,4,7,6,5,3,2,1}},
{0xC0,2,OC_EXT_ROWS+ 32,{6,7,5,4,3,2,1,0},{0,4,7,6,5,3,2,1}},
{0x01,1,OC_EXT_ROWS+ 0,{0,7,6,5,4,3,2,1},{0,7,6,5,4,3,2,1}},
{0x80,1,OC_EXT_ROWS+ 0,{7,6,5,4,3,2,1,0},{0,7,6,5,4,3,2,1}},
{0x7E,6,OC_EXT_ROWS+ 42,{1,2,3,4,5,6,7,0},{0,1,2,5,6,7,4,3}},
{0x7C,5,OC_EXT_ROWS+ 44,{2,3,4,5,6,7,1,0},{0,1,4,5,7,6,3,2}},
{0x3E,5,OC_EXT_ROWS+ 47,{1,2,3,4,5,7,6,0},{0,1,4,5,7,6,3,2}},
{0x78,4,OC_EXT_ROWS+ 50,{3,4,5,6,7,2,1,0},{0,4,5,7,6,3,2,1}},
{0x3C,4,OC_EXT_ROWS+ 54,{2,3,4,5,7,6,1,0},{0,3,4,7,6,5,2,1}},
{0x1E,4,OC_EXT_ROWS+ 58,{1,2,3,4,7,6,5,0},{0,4,5,7,6,3,2,1}},
{0x70,3,OC_EXT_ROWS+ 62,{4,5,6,7,3,2,1,0},{0,5,7,6,4,3,2,1}},
{0x38,3,OC_EXT_ROWS+ 67,{3,4,5,7,6,2,1,0},{0,5,6,7,4,3,2,1}},
{0x1C,3,OC_EXT_ROWS+ 72,{2,3,4,7,6,5,1,0},{0,5,6,7,4,3,2,1}},
{0x0E,3,OC_EXT_ROWS+ 77,{1,2,3,7,6,5,4,0},{0,5,7,6,4,3,2,1}},
{0x60,2,OC_EXT_ROWS+ 82,{5,6,7,4,3,2,1,0},{0,2,7,6,5,4,3,1}},
{0x30,2,OC_EXT_ROWS+ 36,{4,5,7,6,3,2,1,0},{0,4,7,6,5,3,2,1}},
{0x18,2,OC_EXT_ROWS+ 90,{3,4,7,6,5,2,1,0},{0,1,7,6,5,4,3,2}},
{0x0C,2,OC_EXT_ROWS+ 34,{2,3,7,6,5,4,1,0},{0,4,7,6,5,3,2,1}},
{0x06,2,OC_EXT_ROWS+ 84,{1,2,7,6,5,4,3,0},{0,2,7,6,5,4,3,1}},
{0x40,1,OC_EXT_ROWS+ 0,{6,7,5,4,3,2,1,0},{0,7,6,5,4,3,2,1}},
{0x20,1,OC_EXT_ROWS+ 0,{5,7,6,4,3,2,1,0},{0,7,6,5,4,3,2,1}},
{0x10,1,OC_EXT_ROWS+ 0,{4,7,6,5,3,2,1,0},{0,7,6,5,4,3,2,1}},
{0x08,1,OC_EXT_ROWS+ 0,{3,7,6,5,4,2,1,0},{0,7,6,5,4,3,2,1}},
{0x04,1,OC_EXT_ROWS+ 0,{2,7,6,5,4,3,1,0},{0,7,6,5,4,3,2,1}},
{0x02,1,OC_EXT_ROWS+ 0,{1,7,6,5,4,3,2,0},{0,7,6,5,4,3,2,1}}
};
/*Pads a single column of a partial block and then performs a forward Type-II
DCT on the result.
The input is scaled by a factor of 4 and biased appropriately for the current
fDCT implementation.
The output is scaled by an additional factor of 2 from the orthonormal
version of the transform.
_y: The buffer to store the result in.
Data will be placed the first 8 entries (e.g., in a row of an 8x8 block).
_x: The input coefficients.
Every 8th entry is used (e.g., from a column of an 8x8 block).
_e: The extension information for the shape.*/
static void oc_fdct8_ext(ogg_int16_t _y[8],ogg_int16_t *_x,
const oc_extension_info *_e){
const unsigned char *pi;
int na;
na=_e->na;
pi=_e->pi;
if(na==1){
int ci;
/*While the branch below is still correct for shapes with na==1, we can
perform the entire transform with just 1 multiply in this case instead
of 23.*/
_y[0]=(ogg_int16_t)(OC_DIV2_16(OC_C4S4*(_x[pi[0]])));
for(ci=1;ci<8;ci++)_y[ci]=0;
}
else{
const ogg_int16_t *const *ext;
int zpi;
int api;
int nz;
/*First multiply by the extension matrix to compute the padding values.*/
nz=8-na;
ext=_e->ext;
for(zpi=0;zpi<nz;zpi++){
ogg_int32_t v;
v=0;
for(api=0;api<na;api++){
v+=ext[zpi][api]*(ogg_int32_t)(_x[pi[api]<<3]<<1);
}
_x[pi[na+zpi]<<3]=(ogg_int16_t)(v+0x8000>>16)+1>>1;
}
oc_fdct8(_y,_x);
}
}
/*Performs a forward 8x8 Type-II DCT transform on blocks which overlap the
border of the picture region.
This method ONLY works with rectangular regions.
_border: A description of which pixels are inside the border.
_y: The buffer to store the result in.
This may be the same as _x.
_x: The input pixel values.
Pixel values outside the border will be ignored.*/
void oc_fdct8x8_border(const oc_border_info *_border,
ogg_int16_t _y[64],const ogg_int16_t _x[64]){
ogg_int16_t *in;
ogg_int16_t *out;
ogg_int16_t w[64];
ogg_int64_t mask;
const oc_extension_info *cext;
const oc_extension_info *rext;
int cmask;
int rmask;
int ri;
int ci;
/*Identify the shapes of the non-zero rows and columns.*/
rmask=cmask=0;
mask=_border->mask;
for(ri=0;ri<8;ri++){
/*This aggregation is _only_ correct for rectangular masks.*/
cmask|=((mask&0xFF)!=0)<<ri;
rmask|=mask&0xFF;
mask>>=8;
}
/*Find the associated extension info for these shapes.*/
if(cmask==0xFF)cext=NULL;
else for(cext=OC_EXTENSION_INFO;cext->mask!=cmask;){
/*If we somehow can't find the shape, then just do an unpadded fDCT.
It won't be efficient, but it should still be correct.*/
if(++cext>=OC_EXTENSION_INFO+OC_NSHAPES){
oc_enc_fdct8x8_c(_y,_x);
return;
}
}
if(rmask==0xFF)rext=NULL;
else for(rext=OC_EXTENSION_INFO;rext->mask!=rmask;){
/*If we somehow can't find the shape, then just do an unpadded fDCT.
It won't be efficient, but it should still be correct.*/
if(++rext>=OC_EXTENSION_INFO+OC_NSHAPES){
oc_enc_fdct8x8_c(_y,_x);
return;
}
}
/*Add two extra bits of working precision to improve accuracy; any more and
we could overflow.*/
for(ci=0;ci<64;ci++)w[ci]=_x[ci]<<2;
/*These biases correct for some systematic error that remains in the full
fDCT->iDCT round trip.
We can safely add them before padding, since if these pixel values are
overwritten, we didn't care what they were anyway (and the unbiased values
will usually yield smaller DCT coefficient magnitudes).*/
w[0]+=(w[0]!=0)+1;
w[1]++;
w[8]--;
/*Transform the columns.
We can ignore zero columns without a problem.*/
in=w;
out=_y;
if(cext==NULL)for(ci=0;ci<8;ci++)oc_fdct8(out+(ci<<3),in+ci);
else for(ci=0;ci<8;ci++)if(rmask&(1<<ci))oc_fdct8_ext(out+(ci<<3),in+ci,cext);
/*Transform the rows.
We transform even rows that are supposedly zero, because rounding errors
may make them slightly non-zero, and this will give a more precise
reconstruction with very small quantizers.*/
in=_y;
out=w;
if(rext==NULL)for(ri=0;ri<8;ri++)oc_fdct8(out+(ri<<3),in+ri);
else for(ri=0;ri<8;ri++)oc_fdct8_ext(out+(ri<<3),in+ri,rext);
/*Round the result back to the external working precision (which is still
scaled by four relative to the orthogonal result).
TODO: We should just update the external working precision.*/
for(ci=0;ci<64;ci++)_y[ci]=w[ci]+2>>2;
}
#endif

View File

@@ -0,0 +1,87 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: fragment.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <string.h>
#include "internal.h"
void oc_frag_copy(const oc_theora_state *_state,unsigned char *_dst,
const unsigned char *_src,int _ystride){
(*_state->opt_vtable.frag_copy)(_dst,_src,_ystride);
}
void oc_frag_copy_c(unsigned char *_dst,const unsigned char *_src,int _ystride){
int i;
for(i=8;i-->0;){
memcpy(_dst,_src,8*sizeof(*_dst));
_dst+=_ystride;
_src+=_ystride;
}
}
void oc_frag_recon_intra(const oc_theora_state *_state,unsigned char *_dst,
int _ystride,const ogg_int16_t _residue[64]){
_state->opt_vtable.frag_recon_intra(_dst,_ystride,_residue);
}
void oc_frag_recon_intra_c(unsigned char *_dst,int _ystride,
const ogg_int16_t _residue[64]){
int i;
for(i=0;i<8;i++){
int j;
for(j=0;j<8;j++)_dst[j]=OC_CLAMP255(_residue[i*8+j]+128);
_dst+=_ystride;
}
}
void oc_frag_recon_inter(const oc_theora_state *_state,unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]){
_state->opt_vtable.frag_recon_inter(_dst,_src,_ystride,_residue);
}
void oc_frag_recon_inter_c(unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]){
int i;
for(i=0;i<8;i++){
int j;
for(j=0;j<8;j++)_dst[j]=OC_CLAMP255(_residue[i*8+j]+_src[j]);
_dst+=_ystride;
_src+=_ystride;
}
}
void oc_frag_recon_inter2(const oc_theora_state *_state,unsigned char *_dst,
const unsigned char *_src1,const unsigned char *_src2,int _ystride,
const ogg_int16_t _residue[64]){
_state->opt_vtable.frag_recon_inter2(_dst,_src1,_src2,_ystride,_residue);
}
void oc_frag_recon_inter2_c(unsigned char *_dst,const unsigned char *_src1,
const unsigned char *_src2,int _ystride,const ogg_int16_t _residue[64]){
int i;
for(i=0;i<8;i++){
int j;
for(j=0;j<8;j++)_dst[j]=OC_CLAMP255(_residue[i*8+j]+(_src1[j]+_src2[j]>>1));
_dst+=_ystride;
_src1+=_ystride;
_src2+=_ystride;
}
}
void oc_restore_fpu(const oc_theora_state *_state){
_state->opt_vtable.restore_fpu();
}
void oc_restore_fpu_c(void){}

View File

@@ -0,0 +1,489 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: huffdec.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <ogg/ogg.h>
#include "huffdec.h"
#include "decint.h"
/*The ANSI offsetof macro is broken on some platforms (e.g., older DECs).*/
#define _ogg_offsetof(_type,_field)\
((size_t)((char *)&((_type *)0)->_field-(char *)0))
/*The number of internal tokens associated with each of the spec tokens.*/
static const unsigned char OC_DCT_TOKEN_MAP_ENTRIES[TH_NDCT_TOKENS]={
1,1,1,4,8,1,1,8,1,1,1,1,1,2,2,2,2,4,8,2,2,2,4,2,2,2,2,2,8,2,4,8
};
/*The map from external spec-defined tokens to internal tokens.
This is constructed so that any extra bits read with the original token value
can be masked off the least significant bits of its internal token index.
In addition, all of the tokens which require additional extra bits are placed
at the start of the list, and grouped by type.
OC_DCT_REPEAT_RUN3_TOKEN is placed first, as it is an extra-special case, so
giving it index 0 may simplify comparisons on some architectures.
These requirements require some substantial reordering.*/
static const unsigned char OC_DCT_TOKEN_MAP[TH_NDCT_TOKENS]={
/*OC_DCT_EOB1_TOKEN (0 extra bits)*/
15,
/*OC_DCT_EOB2_TOKEN (0 extra bits)*/
16,
/*OC_DCT_EOB3_TOKEN (0 extra bits)*/
17,
/*OC_DCT_REPEAT_RUN0_TOKEN (2 extra bits)*/
88,
/*OC_DCT_REPEAT_RUN1_TOKEN (3 extra bits)*/
80,
/*OC_DCT_REPEAT_RUN2_TOKEN (4 extra bits)*/
1,
/*OC_DCT_REPEAT_RUN3_TOKEN (12 extra bits)*/
0,
/*OC_DCT_SHORT_ZRL_TOKEN (3 extra bits)*/
48,
/*OC_DCT_ZRL_TOKEN (6 extra bits)*/
14,
/*OC_ONE_TOKEN (0 extra bits)*/
56,
/*OC_MINUS_ONE_TOKEN (0 extra bits)*/
57,
/*OC_TWO_TOKEN (0 extra bits)*/
58,
/*OC_MINUS_TWO_TOKEN (0 extra bits)*/
59,
/*OC_DCT_VAL_CAT2 (1 extra bit)*/
60,
62,
64,
66,
/*OC_DCT_VAL_CAT3 (2 extra bits)*/
68,
/*OC_DCT_VAL_CAT4 (3 extra bits)*/
72,
/*OC_DCT_VAL_CAT5 (4 extra bits)*/
2,
/*OC_DCT_VAL_CAT6 (5 extra bits)*/
4,
/*OC_DCT_VAL_CAT7 (6 extra bits)*/
6,
/*OC_DCT_VAL_CAT8 (10 extra bits)*/
8,
/*OC_DCT_RUN_CAT1A (1 extra bit)*/
18,
20,
22,
24,
26,
/*OC_DCT_RUN_CAT1B (3 extra bits)*/
32,
/*OC_DCT_RUN_CAT1C (4 extra bits)*/
12,
/*OC_DCT_RUN_CAT2A (2 extra bits)*/
28,
/*OC_DCT_RUN_CAT2B (3 extra bits)*/
40
};
/*These three functions are really part of the bitpack.c module, but
they are only used here.
Declaring local static versions so they can be inlined saves considerable
function call overhead.*/
static oc_pb_window oc_pack_refill(oc_pack_buf *_b,int _bits){
const unsigned char *ptr;
const unsigned char *stop;
oc_pb_window window;
int available;
window=_b->window;
available=_b->bits;
ptr=_b->ptr;
stop=_b->stop;
/*This version of _refill() doesn't bother setting eof because we won't
check for it after we've started decoding DCT tokens.*/
if(ptr>=stop)available=OC_LOTS_OF_BITS;
while(available<=OC_PB_WINDOW_SIZE-8){
available+=8;
window|=(oc_pb_window)*ptr++<<OC_PB_WINDOW_SIZE-available;
if(ptr>=stop)available=OC_LOTS_OF_BITS;
}
_b->ptr=ptr;
if(_bits>available)window|=*ptr>>(available&7);
_b->bits=available;
return window;
}
/*Read in bits without advancing the bit pointer.
Here we assume 0<=_bits&&_bits<=32.*/
static long oc_pack_look(oc_pack_buf *_b,int _bits){
oc_pb_window window;
int available;
long result;
window=_b->window;
available=_b->bits;
if(_bits==0)return 0;
if(_bits>available)_b->window=window=oc_pack_refill(_b,_bits);
result=window>>OC_PB_WINDOW_SIZE-_bits;
return result;
}
/*Advance the bit pointer.*/
static void oc_pack_adv(oc_pack_buf *_b,int _bits){
/*We ignore the special cases for _bits==0 and _bits==32 here, since they are
never used actually used.
OC_HUFF_SLUSH (defined below) would have to be at least 27 to actually read
32 bits in a single go, and would require a 32 GB lookup table (assuming
8 byte pointers, since 4 byte pointers couldn't fit such a table).*/
_b->window<<=_bits;
_b->bits-=_bits;
}
/*The log_2 of the size of a lookup table is allowed to grow to relative to
the number of unique nodes it contains.
E.g., if OC_HUFF_SLUSH is 2, then at most 75% of the space in the tree is
wasted (each node will have an amortized cost of at most 20 bytes when using
4-byte pointers).
Larger numbers can decode tokens with fewer read operations, while smaller
numbers may save more space (requiring as little as 8 bytes amortized per
node, though there will be more nodes).
With a sample file:
32233473 read calls are required when no tree collapsing is done (100.0%).
19269269 read calls are required when OC_HUFF_SLUSH is 0 (59.8%).
11144969 read calls are required when OC_HUFF_SLUSH is 1 (34.6%).
10538563 read calls are required when OC_HUFF_SLUSH is 2 (32.7%).
10192578 read calls are required when OC_HUFF_SLUSH is 3 (31.6%).
Since a value of 1 gets us the vast majority of the speed-up with only a
small amount of wasted memory, this is what we use.*/
#define OC_HUFF_SLUSH (1)
/*Determines the size in bytes of a Huffman tree node that represents a
subtree of depth _nbits.
_nbits: The depth of the subtree.
If this is 0, the node is a leaf node.
Otherwise 1<<_nbits pointers are allocated for children.
Return: The number of bytes required to store the node.*/
static size_t oc_huff_node_size(int _nbits){
size_t size;
size=_ogg_offsetof(oc_huff_node,nodes);
if(_nbits>0)size+=sizeof(oc_huff_node *)*(1<<_nbits);
return size;
}
static oc_huff_node *oc_huff_node_init(char **_storage,size_t _size,int _nbits){
oc_huff_node *ret;
ret=(oc_huff_node *)*_storage;
ret->nbits=(unsigned char)_nbits;
(*_storage)+=_size;
return ret;
}
/*Determines the size in bytes of a Huffman tree.
_nbits: The depth of the subtree.
If this is 0, the node is a leaf node.
Otherwise storage for 1<<_nbits pointers are added for children.
Return: The number of bytes required to store the tree.*/
static size_t oc_huff_tree_size(const oc_huff_node *_node){
size_t size;
size=oc_huff_node_size(_node->nbits);
if(_node->nbits){
int nchildren;
int i;
nchildren=1<<_node->nbits;
for(i=0;i<nchildren;i+=1<<_node->nbits-_node->nodes[i]->depth){
size+=oc_huff_tree_size(_node->nodes[i]);
}
}
return size;
}
/*Unpacks a sub-tree from the given buffer.
_opb: The buffer to unpack from.
_binodes: The nodes to store the sub-tree in.
_nbinodes: The number of nodes available for the sub-tree.
Return: 0 on success, or a negative value on error.*/
static int oc_huff_tree_unpack(oc_pack_buf *_opb,
oc_huff_node *_binodes,int _nbinodes){
oc_huff_node *binode;
long bits;
int nused;
if(_nbinodes<1)return TH_EBADHEADER;
binode=_binodes;
nused=0;
bits=oc_pack_read1(_opb);
if(oc_pack_bytes_left(_opb)<0)return TH_EBADHEADER;
/*Read an internal node:*/
if(!bits){
int ret;
nused++;
binode->nbits=1;
binode->depth=1;
binode->nodes[0]=_binodes+nused;
ret=oc_huff_tree_unpack(_opb,_binodes+nused,_nbinodes-nused);
if(ret>=0){
nused+=ret;
binode->nodes[1]=_binodes+nused;
ret=oc_huff_tree_unpack(_opb,_binodes+nused,_nbinodes-nused);
}
if(ret<0)return ret;
nused+=ret;
}
/*Read a leaf node:*/
else{
int ntokens;
int token;
int i;
bits=oc_pack_read(_opb,OC_NDCT_TOKEN_BITS);
if(oc_pack_bytes_left(_opb)<0)return TH_EBADHEADER;
/*Find out how many internal tokens we translate this external token into.*/
ntokens=OC_DCT_TOKEN_MAP_ENTRIES[bits];
if(_nbinodes<2*ntokens-1)return TH_EBADHEADER;
/*Fill in a complete binary tree pointing to the internal tokens.*/
for(i=1;i<ntokens;i<<=1){
int j;
binode=_binodes+nused;
nused+=i;
for(j=0;j<i;j++){
binode[j].nbits=1;
binode[j].depth=1;
binode[j].nodes[0]=_binodes+nused+2*j;
binode[j].nodes[1]=_binodes+nused+2*j+1;
}
}
/*And now the leaf nodes with those tokens.*/
token=OC_DCT_TOKEN_MAP[bits];
for(i=0;i<ntokens;i++){
binode=_binodes+nused++;
binode->nbits=0;
binode->depth=1;
binode->token=token+i;
}
}
return nused;
}
/*Finds the depth of shortest branch of the given sub-tree.
The tree must be binary.
_binode: The root of the given sub-tree.
_binode->nbits must be 0 or 1.
Return: The smallest depth of a leaf node in this sub-tree.
0 indicates this sub-tree is a leaf node.*/
static int oc_huff_tree_mindepth(oc_huff_node *_binode){
int depth0;
int depth1;
if(_binode->nbits==0)return 0;
depth0=oc_huff_tree_mindepth(_binode->nodes[0]);
depth1=oc_huff_tree_mindepth(_binode->nodes[1]);
return OC_MINI(depth0,depth1)+1;
}
/*Finds the number of internal nodes at a given depth, plus the number of
leaves at that depth or shallower.
The tree must be binary.
_binode: The root of the given sub-tree.
_binode->nbits must be 0 or 1.
Return: The number of entries that would be contained in a jump table of the
given depth.*/
static int oc_huff_tree_occupancy(oc_huff_node *_binode,int _depth){
if(_binode->nbits==0||_depth<=0)return 1;
else{
return oc_huff_tree_occupancy(_binode->nodes[0],_depth-1)+
oc_huff_tree_occupancy(_binode->nodes[1],_depth-1);
}
}
/*Makes a copy of the given Huffman tree.
_node: The Huffman tree to copy.
Return: The copy of the Huffman tree.*/
static oc_huff_node *oc_huff_tree_copy(const oc_huff_node *_node,
char **_storage){
oc_huff_node *ret;
ret=oc_huff_node_init(_storage,oc_huff_node_size(_node->nbits),_node->nbits);
ret->depth=_node->depth;
if(_node->nbits){
int nchildren;
int i;
int inext;
nchildren=1<<_node->nbits;
for(i=0;i<nchildren;){
ret->nodes[i]=oc_huff_tree_copy(_node->nodes[i],_storage);
inext=i+(1<<_node->nbits-ret->nodes[i]->depth);
while(++i<inext)ret->nodes[i]=ret->nodes[i-1];
}
}
else ret->token=_node->token;
return ret;
}
static size_t oc_huff_tree_collapse_size(oc_huff_node *_binode,int _depth){
size_t size;
int mindepth;
int depth;
int loccupancy;
int occupancy;
if(_binode->nbits!=0&&_depth>0){
return oc_huff_tree_collapse_size(_binode->nodes[0],_depth-1)+
oc_huff_tree_collapse_size(_binode->nodes[1],_depth-1);
}
depth=mindepth=oc_huff_tree_mindepth(_binode);
occupancy=1<<mindepth;
do{
loccupancy=occupancy;
occupancy=oc_huff_tree_occupancy(_binode,++depth);
}
while(occupancy>loccupancy&&occupancy>=1<<OC_MAXI(depth-OC_HUFF_SLUSH,0));
depth--;
size=oc_huff_node_size(depth);
if(depth>0){
size+=oc_huff_tree_collapse_size(_binode->nodes[0],depth-1);
size+=oc_huff_tree_collapse_size(_binode->nodes[1],depth-1);
}
return size;
}
static oc_huff_node *oc_huff_tree_collapse(oc_huff_node *_binode,
char **_storage);
/*Fills the given nodes table with all the children in the sub-tree at the
given depth.
The nodes in the sub-tree with a depth less than that stored in the table
are freed.
The sub-tree must be binary and complete up until the given depth.
_nodes: The nodes table to fill.
_binode: The root of the sub-tree to fill it with.
_binode->nbits must be 0 or 1.
_level: The current level in the table.
0 indicates that the current node should be stored, regardless of
whether it is a leaf node or an internal node.
_depth: The depth of the nodes to fill the table with, relative to their
parent.*/
static void oc_huff_node_fill(oc_huff_node **_nodes,
oc_huff_node *_binode,int _level,int _depth,char **_storage){
if(_level<=0||_binode->nbits==0){
int i;
_binode->depth=(unsigned char)(_depth-_level);
_nodes[0]=oc_huff_tree_collapse(_binode,_storage);
for(i=1;i<1<<_level;i++)_nodes[i]=_nodes[0];
}
else{
_level--;
oc_huff_node_fill(_nodes,_binode->nodes[0],_level,_depth,_storage);
_nodes+=1<<_level;
oc_huff_node_fill(_nodes,_binode->nodes[1],_level,_depth,_storage);
}
}
/*Finds the largest complete sub-tree rooted at the current node and collapses
it into a single node.
This procedure is then applied recursively to all the children of that node.
_binode: The root of the sub-tree to collapse.
_binode->nbits must be 0 or 1.
Return: The new root of the collapsed sub-tree.*/
static oc_huff_node *oc_huff_tree_collapse(oc_huff_node *_binode,
char **_storage){
oc_huff_node *root;
size_t size;
int mindepth;
int depth;
int loccupancy;
int occupancy;
depth=mindepth=oc_huff_tree_mindepth(_binode);
occupancy=1<<mindepth;
do{
loccupancy=occupancy;
occupancy=oc_huff_tree_occupancy(_binode,++depth);
}
while(occupancy>loccupancy&&occupancy>=1<<OC_MAXI(depth-OC_HUFF_SLUSH,0));
depth--;
if(depth<=1)return oc_huff_tree_copy(_binode,_storage);
size=oc_huff_node_size(depth);
root=oc_huff_node_init(_storage,size,depth);
root->depth=_binode->depth;
oc_huff_node_fill(root->nodes,_binode,depth,depth,_storage);
return root;
}
/*Unpacks a set of Huffman trees, and reduces them to a collapsed
representation.
_opb: The buffer to unpack the trees from.
_nodes: The table to fill with the Huffman trees.
Return: 0 on success, or a negative value on error.*/
int oc_huff_trees_unpack(oc_pack_buf *_opb,
oc_huff_node *_nodes[TH_NHUFFMAN_TABLES]){
int i;
for(i=0;i<TH_NHUFFMAN_TABLES;i++){
oc_huff_node nodes[511];
char *storage;
size_t size;
int ret;
/*Unpack the full tree into a temporary buffer.*/
ret=oc_huff_tree_unpack(_opb,nodes,sizeof(nodes)/sizeof(*nodes));
if(ret<0)return ret;
/*Figure out how big the collapsed tree will be.*/
size=oc_huff_tree_collapse_size(nodes,0);
storage=(char *)_ogg_calloc(1,size);
if(storage==NULL)return TH_EFAULT;
/*And collapse it.*/
_nodes[i]=oc_huff_tree_collapse(nodes,&storage);
}
return 0;
}
/*Makes a copy of the given set of Huffman trees.
_dst: The array to store the copy in.
_src: The array of trees to copy.*/
int oc_huff_trees_copy(oc_huff_node *_dst[TH_NHUFFMAN_TABLES],
const oc_huff_node *const _src[TH_NHUFFMAN_TABLES]){
int i;
for(i=0;i<TH_NHUFFMAN_TABLES;i++){
size_t size;
char *storage;
size=oc_huff_tree_size(_src[i]);
storage=(char *)_ogg_calloc(1,size);
if(storage==NULL){
while(i-->0)_ogg_free(_dst[i]);
return TH_EFAULT;
}
_dst[i]=oc_huff_tree_copy(_src[i],&storage);
}
return 0;
}
/*Frees the memory used by a set of Huffman trees.
_nodes: The array of trees to free.*/
void oc_huff_trees_clear(oc_huff_node *_nodes[TH_NHUFFMAN_TABLES]){
int i;
for(i=0;i<TH_NHUFFMAN_TABLES;i++)_ogg_free(_nodes[i]);
}
/*Unpacks a single token using the given Huffman tree.
_opb: The buffer to unpack the token from.
_node: The tree to unpack the token with.
Return: The token value.*/
int oc_huff_token_decode(oc_pack_buf *_opb,const oc_huff_node *_node){
long bits;
while(_node->nbits!=0){
bits=oc_pack_look(_opb,_node->nbits);
_node=_node->nodes[bits];
oc_pack_adv(_opb,_node->depth);
}
return _node->token;
}

View File

@@ -0,0 +1,92 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: huffdec.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_huffdec_H)
# define _huffdec_H (1)
# include "huffman.h"
# include "bitpack.h"
typedef struct oc_huff_node oc_huff_node;
/*A node in the Huffman tree.
Instead of storing every branching in the tree, subtrees can be collapsed
into one node, with a table of size 1<<nbits pointing directly to its
descedents nbits levels down.
This allows more than one bit to be read at a time, and avoids following all
the intermediate branches with next to no increased code complexity once
the collapsed tree has been built.
We do _not_ require that a subtree be complete to be collapsed, but instead
store duplicate pointers in the table, and record the actual depth of the
node below its parent.
This tells us the number of bits to advance the stream after reaching it.
This turns out to be equivalent to the method described in \cite{Hash95},
without the requirement that codewords be sorted by length.
If the codewords were sorted by length (so-called ``canonical-codes''), they
could be decoded much faster via either Lindell and Moffat's approach or
Hashemian's Condensed Huffman Code approach, the latter of which has an
extremely small memory footprint.
We can't use Choueka et al.'s finite state machine approach, which is
extremely fast, because we can't allow multiple symbols to be output at a
time; the codebook can and does change between symbols.
It also has very large memory requirements, which impairs cache coherency.
@ARTICLE{Hash95,
author="Reza Hashemian",
title="Memory Efficient and High-Speed Search {Huffman} Coding",
journal="{IEEE} Transactions on Communications",
volume=43,
number=10,
pages="2576--2581",
month=Oct,
year=1995
}*/
struct oc_huff_node{
/*The number of bits of the code needed to descend through this node.
0 indicates a leaf node.
Otherwise there are 1<<nbits nodes in the nodes table, which can be
indexed by reading nbits bits from the stream.*/
unsigned char nbits;
/*The value of a token stored in a leaf node.
The value in non-leaf nodes is undefined.*/
unsigned char token;
/*The depth of the current node, relative to its parent in the collapsed
tree.
This can be less than its parent's nbits value, in which case there are
1<<nbits-depth copies of this node in the table, and the bitstream should
only be advanced depth bits after reaching this node.*/
unsigned char depth;
/*The table of child nodes.
The ACTUAL size of this array is 1<<nbits, despite what the declaration
below claims.
The exception is that for leaf nodes the size is 0.*/
oc_huff_node *nodes[2];
};
int oc_huff_trees_unpack(oc_pack_buf *_opb,
oc_huff_node *_nodes[TH_NHUFFMAN_TABLES]);
int oc_huff_trees_copy(oc_huff_node *_dst[TH_NHUFFMAN_TABLES],
const oc_huff_node *const _src[TH_NHUFFMAN_TABLES]);
void oc_huff_trees_clear(oc_huff_node *_nodes[TH_NHUFFMAN_TABLES]);
int oc_huff_token_decode(oc_pack_buf *_opb,const oc_huff_node *_node);
#endif

View File

@@ -0,0 +1,910 @@
#include <stdlib.h>
#include <string.h>
#include <ogg/ogg.h>
#include "huffenc.h"
/*The default Huffman codes used for VP3.1.*/
const th_huff_code TH_VP31_HUFF_CODES[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]={
{
{0x002D, 6},{0x0026, 7},{0x0166, 9},{0x004E, 8},
{0x02CE,10},{0x059E,11},{0x027D,11},{0x0008, 5},
{0x04F9,12},{0x000F, 4},{0x000E, 4},{0x001B, 5},
{0x0006, 4},{0x0008, 4},{0x0005, 4},{0x001A, 5},
{0x0015, 5},{0x0007, 4},{0x000C, 4},{0x0001, 3},
{0x0000, 3},{0x0009, 4},{0x0017, 5},{0x0029, 6},
{0x0028, 6},{0x00B2, 8},{0x04F8,12},{0x059F,11},
{0x009E, 9},{0x013F,10},{0x0012, 6},{0x0058, 7}
},
{
{0x0010, 5},{0x0047, 7},{0x01FF, 9},{0x008C, 8},
{0x03FC,10},{0x046A,11},{0x0469,11},{0x0022, 6},
{0x11A1,13},{0x000E, 4},{0x000D, 4},{0x0004, 4},
{0x0005, 4},{0x0009, 4},{0x0006, 4},{0x001E, 5},
{0x0016, 5},{0x0007, 4},{0x000C, 4},{0x0001, 3},
{0x0000, 3},{0x000A, 4},{0x0017, 5},{0x007D, 7},
{0x007E, 7},{0x011B, 9},{0x08D1,12},{0x03FD,10},
{0x046B,11},{0x11A0,13},{0x007C, 7},{0x00FE, 8}
},
{
{0x0016, 5},{0x0020, 6},{0x0086, 8},{0x0087, 8},
{0x0367,10},{0x06CC,11},{0x06CB,11},{0x006E, 7},
{0x366D,14},{0x000F, 4},{0x000E, 4},{0x0004, 4},
{0x0005, 4},{0x000A, 4},{0x0006, 4},{0x001A, 5},
{0x0011, 5},{0x0007, 4},{0x000C, 4},{0x0001, 3},
{0x0000, 3},{0x0009, 4},{0x0017, 5},{0x006F, 7},
{0x006D, 7},{0x0364,10},{0x0D9A,12},{0x06CA,11},
{0x1B37,13},{0x366C,14},{0x0042, 7},{0x00D8, 8}
},
{
{0x0000, 4},{0x002D, 6},{0x00F7, 8},{0x0058, 7},
{0x0167, 9},{0x02CB,10},{0x02CA,10},{0x000E, 6},
{0x1661,13},{0x0003, 3},{0x0002, 3},{0x0008, 4},
{0x0009, 4},{0x000D, 4},{0x0002, 4},{0x001F, 5},
{0x0017, 5},{0x0001, 4},{0x000C, 4},{0x000E, 4},
{0x000A, 4},{0x0006, 5},{0x0078, 7},{0x000F, 6},
{0x007A, 7},{0x0164, 9},{0x0599,11},{0x02CD,10},
{0x0B31,12},{0x1660,13},{0x0079, 7},{0x00F6, 8}
},
{
{0x0003, 4},{0x003C, 6},{0x000F, 7},{0x007A, 7},
{0x001D, 8},{0x0020, 9},{0x0072,10},{0x0006, 6},
{0x0399,13},{0x0004, 3},{0x0005, 3},{0x0005, 4},
{0x0006, 4},{0x000E, 4},{0x0004, 4},{0x0000, 4},
{0x0019, 5},{0x0002, 4},{0x000D, 4},{0x0007, 4},
{0x001F, 5},{0x0030, 6},{0x0011, 8},{0x0031, 6},
{0x0005, 6},{0x0021, 9},{0x00E7,11},{0x0038, 9},
{0x01CD,12},{0x0398,13},{0x007B, 7},{0x0009, 7}
},
{
{0x0009, 4},{0x0002, 5},{0x0074, 7},{0x0007, 6},
{0x00EC, 8},{0x00D1, 9},{0x01A6,10},{0x0006, 6},
{0x0D21,13},{0x0005, 3},{0x0006, 3},{0x0008, 4},
{0x0007, 4},{0x000F, 4},{0x0004, 4},{0x0000, 4},
{0x001C, 5},{0x0002, 4},{0x0005, 4},{0x0003, 4},
{0x000C, 5},{0x0035, 7},{0x01A7,10},{0x001B, 6},
{0x0077, 7},{0x01A5,10},{0x0349,11},{0x00D0, 9},
{0x0691,12},{0x0D20,13},{0x0075, 7},{0x00ED, 8}
},
{
{0x000A, 4},{0x000C, 5},{0x0012, 6},{0x001B, 6},
{0x00B7, 8},{0x016C, 9},{0x0099, 9},{0x005A, 7},
{0x16D8,13},{0x0007, 3},{0x0006, 3},{0x0009, 4},
{0x0008, 4},{0x0000, 3},{0x0005, 4},{0x0017, 5},
{0x000E, 5},{0x0002, 4},{0x0003, 4},{0x000F, 5},
{0x001A, 6},{0x004D, 8},{0x2DB3,14},{0x002C, 6},
{0x0011, 6},{0x02DA,10},{0x05B7,11},{0x0098, 9},
{0x0B6D,12},{0x2DB2,14},{0x0010, 6},{0x0027, 7}
},
{
{0x000D, 4},{0x000F, 5},{0x001D, 6},{0x0008, 5},
{0x0051, 7},{0x0056, 8},{0x00AF, 9},{0x002A, 7},
{0x148A,13},{0x0007, 3},{0x0000, 2},{0x0008, 4},
{0x0009, 4},{0x000C, 4},{0x0006, 4},{0x0017, 5},
{0x000B, 5},{0x0016, 5},{0x0015, 5},{0x0009, 5},
{0x0050, 7},{0x00AE, 9},{0x2917,14},{0x001C, 6},
{0x0014, 6},{0x0290,10},{0x0523,11},{0x0149, 9},
{0x0A44,12},{0x2916,14},{0x0053, 7},{0x00A5, 8}
},
{
{0x0001, 4},{0x001D, 6},{0x00F5, 8},{0x00F4, 8},
{0x024D,10},{0x0499,11},{0x0498,11},{0x0001, 5},
{0x0021, 6},{0x0006, 3},{0x0005, 3},{0x0006, 4},
{0x0005, 4},{0x0002, 4},{0x0007, 5},{0x0025, 6},
{0x007B, 7},{0x001C, 6},{0x0020, 6},{0x000D, 6},
{0x0048, 7},{0x0092, 8},{0x0127, 9},{0x000E, 4},
{0x0004, 4},{0x0011, 5},{0x000C, 6},{0x003C, 6},
{0x000F, 5},{0x0000, 5},{0x001F, 5},{0x0013, 5}
},
{
{0x0005, 4},{0x003C, 6},{0x0040, 7},{0x000D, 7},
{0x0031, 9},{0x0061,10},{0x0060,10},{0x0002, 5},
{0x00F5, 8},{0x0006, 3},{0x0005, 3},{0x0007, 4},
{0x0006, 4},{0x0002, 4},{0x0009, 5},{0x0025, 6},
{0x0007, 6},{0x0021, 6},{0x0024, 6},{0x0010, 6},
{0x0041, 7},{0x00F4, 8},{0x0019, 8},{0x000E, 4},
{0x0003, 4},{0x0011, 5},{0x0011, 6},{0x003F, 6},
{0x003E, 6},{0x007B, 7},{0x0000, 4},{0x0013, 5}
},
{
{0x000A, 4},{0x0007, 5},{0x0001, 6},{0x0009, 6},
{0x0131, 9},{0x0261,10},{0x0260,10},{0x0015, 6},
{0x0001, 7},{0x0007, 3},{0x0006, 3},{0x0008, 4},
{0x0007, 4},{0x0006, 4},{0x0012, 5},{0x002F, 6},
{0x0014, 6},{0x0027, 6},{0x002D, 6},{0x0016, 6},
{0x004D, 7},{0x0099, 8},{0x0000, 7},{0x0004, 4},
{0x0001, 4},{0x0005, 5},{0x0017, 6},{0x002E, 6},
{0x002C, 6},{0x0008, 6},{0x0006, 5},{0x0001, 5}
},
{
{0x0000, 3},{0x000E, 5},{0x0017, 6},{0x002A, 6},
{0x0010, 7},{0x00F9,10},{0x00F8,10},{0x001E, 7},
{0x003F, 8},{0x0007, 3},{0x0006, 3},{0x0009, 4},
{0x0008, 4},{0x0006, 4},{0x000F, 5},{0x0005, 5},
{0x0016, 6},{0x0029, 6},{0x002B, 6},{0x0015, 6},
{0x0050, 7},{0x0011, 7},{0x007D, 9},{0x0004, 4},
{0x0017, 5},{0x0006, 5},{0x0014, 6},{0x002C, 6},
{0x002D, 6},{0x000E, 6},{0x0009, 6},{0x0051, 7}
},
{
{0x0002, 3},{0x0018, 5},{0x002F, 6},{0x000D, 5},
{0x0053, 7},{0x0295,10},{0x0294,10},{0x00A4, 8},
{0x007C, 8},{0x0000, 2},{0x0007, 3},{0x0009, 4},
{0x0008, 4},{0x001B, 5},{0x000C, 5},{0x0028, 6},
{0x006A, 7},{0x001E, 6},{0x001D, 6},{0x0069, 7},
{0x00D7, 8},{0x007D, 8},{0x014B, 9},{0x0019, 5},
{0x0016, 5},{0x002E, 6},{0x001C, 6},{0x002B, 6},
{0x002A, 6},{0x0068, 7},{0x003F, 7},{0x00D6, 8}
},
{
{0x0002, 3},{0x001B, 5},{0x000C, 5},{0x0018, 5},
{0x0029, 6},{0x007F, 8},{0x02F0,10},{0x0198, 9},
{0x0179, 9},{0x0000, 2},{0x0007, 3},{0x0009, 4},
{0x0008, 4},{0x001A, 5},{0x000D, 5},{0x002A, 6},
{0x0064, 7},{0x001E, 6},{0x0067, 7},{0x005F, 7},
{0x00CD, 8},{0x007E, 8},{0x02F1,10},{0x0016, 5},
{0x000E, 5},{0x002E, 6},{0x0065, 7},{0x002B, 6},
{0x0028, 6},{0x003E, 7},{0x00BD, 8},{0x0199, 9}
},
{
{0x0002, 3},{0x0007, 4},{0x0016, 5},{0x0006, 4},
{0x0036, 6},{0x005C, 7},{0x015D, 9},{0x015C, 9},
{0x02BF,10},{0x0000, 2},{0x0007, 3},{0x0009, 4},
{0x0008, 4},{0x0018, 5},{0x0034, 6},{0x002A, 6},
{0x005E, 7},{0x006A, 7},{0x0064, 7},{0x005D, 7},
{0x00CB, 8},{0x00AD, 8},{0x02BE,10},{0x0014, 5},
{0x0033, 6},{0x006E, 7},{0x005F, 7},{0x006F, 7},
{0x006B, 7},{0x00CA, 8},{0x00AC, 8},{0x015E, 9}
},
{
{0x000F, 4},{0x001D, 5},{0x0018, 5},{0x000B, 4},
{0x0019, 5},{0x0029, 6},{0x00D6, 8},{0x0551,11},
{0x0AA1,12},{0x0001, 2},{0x0000, 2},{0x0009, 4},
{0x0008, 4},{0x001B, 5},{0x0038, 6},{0x0028, 6},
{0x0057, 7},{0x006A, 7},{0x0068, 7},{0x0056, 7},
{0x00E5, 8},{0x0155, 9},{0x0AA0,12},{0x0073, 7},
{0x0069, 7},{0x00D7, 8},{0x00AB, 8},{0x00E4, 8},
{0x00A9, 8},{0x0151, 9},{0x0150, 9},{0x02A9,10}
},
{
{0x0008, 5},{0x0025, 7},{0x017A, 9},{0x02F7,10},
{0x0BDB,12},{0x17B4,13},{0x2F6B,14},{0x001D, 5},
{0x2F6A,14},{0x0008, 4},{0x0007, 4},{0x0001, 4},
{0x0002, 4},{0x000A, 4},{0x0006, 4},{0x0000, 4},
{0x001C, 5},{0x0009, 4},{0x000D, 4},{0x000F, 4},
{0x000C, 4},{0x0003, 4},{0x000A, 5},{0x0016, 5},
{0x0013, 6},{0x005D, 7},{0x0024, 7},{0x00BC, 8},
{0x005C, 7},{0x05EC,11},{0x000B, 5},{0x005F, 7}
},
{
{0x000F, 5},{0x0010, 6},{0x004B, 8},{0x00C6, 8},
{0x031D,10},{0x0C71,12},{0x0C70,12},{0x0001, 4},
{0x0C73,12},{0x0008, 4},{0x0009, 4},{0x0002, 4},
{0x0003, 4},{0x000B, 4},{0x0006, 4},{0x0000, 4},
{0x001C, 5},{0x0005, 4},{0x000D, 4},{0x000F, 4},
{0x000A, 4},{0x0019, 5},{0x0013, 6},{0x001D, 5},
{0x0030, 6},{0x0062, 7},{0x0024, 7},{0x004A, 8},
{0x018F, 9},{0x0C72,12},{0x000E, 5},{0x0011, 6}
},
{
{0x001B, 5},{0x0003, 6},{0x008D, 8},{0x0040, 7},
{0x0239,10},{0x0471,11},{0x08E0,12},{0x0003, 4},
{0x11C3,13},{0x000A, 4},{0x0009, 4},{0x0004, 4},
{0x0005, 4},{0x000E, 4},{0x0007, 4},{0x0001, 4},
{0x001E, 5},{0x0006, 4},{0x000C, 4},{0x000B, 4},
{0x0002, 4},{0x0000, 5},{0x0041, 7},{0x001F, 5},
{0x0022, 6},{0x0002, 6},{0x008F, 8},{0x008C, 8},
{0x011D, 9},{0x11C2,13},{0x001A, 5},{0x0021, 6}
},
{
{0x001F, 5},{0x0003, 6},{0x0003, 7},{0x0043, 7},
{0x000B, 9},{0x0015,10},{0x0051,12},{0x0003, 4},
{0x0050,12},{0x000D, 4},{0x000C, 4},{0x0004, 4},
{0x0006, 4},{0x000E, 4},{0x000A, 4},{0x0001, 4},
{0x001E, 5},{0x0005, 4},{0x0009, 4},{0x0007, 4},
{0x0011, 5},{0x0002, 6},{0x0004, 8},{0x0002, 4},
{0x002D, 6},{0x0020, 6},{0x0042, 7},{0x0001, 7},
{0x0000, 7},{0x0029,11},{0x0017, 5},{0x002C, 6}
},
{
{0x0003, 4},{0x001F, 6},{0x003A, 7},{0x005D, 7},
{0x0173, 9},{0x02E4,10},{0x172D,13},{0x0004, 4},
{0x172C,13},{0x000F, 4},{0x000E, 4},{0x0009, 4},
{0x0008, 4},{0x000C, 4},{0x000A, 4},{0x0001, 4},
{0x0016, 5},{0x0002, 4},{0x0005, 4},{0x001A, 5},
{0x002F, 6},{0x0038, 7},{0x05CA,11},{0x0006, 4},
{0x0037, 6},{0x001E, 6},{0x003B, 7},{0x0039, 7},
{0x00B8, 8},{0x0B97,12},{0x0000, 4},{0x0036, 6}
},
{
{0x0006, 4},{0x0037, 6},{0x005D, 7},{0x000C, 6},
{0x00B9, 8},{0x02E3,10},{0x05C4,11},{0x0004, 4},
{0x1715,13},{0x0000, 3},{0x000F, 4},{0x0008, 4},
{0x0007, 4},{0x000C, 4},{0x0009, 4},{0x001D, 5},
{0x0016, 5},{0x001C, 5},{0x001A, 5},{0x000B, 5},
{0x005E, 7},{0x0170, 9},{0x1714,13},{0x000A, 4},
{0x000A, 5},{0x0036, 6},{0x005F, 7},{0x001B, 7},
{0x001A, 7},{0x0B8B,12},{0x0002, 4},{0x0007, 5}
},
{
{0x000C, 4},{0x000B, 5},{0x0079, 7},{0x0022, 6},
{0x00F0, 8},{0x0119, 9},{0x0230,10},{0x001D, 5},
{0x08C4,12},{0x0001, 3},{0x0000, 3},{0x000A, 4},
{0x0009, 4},{0x000B, 4},{0x0007, 4},{0x001C, 5},
{0x003D, 6},{0x000D, 5},{0x0008, 5},{0x0015, 6},
{0x008D, 8},{0x118B,13},{0x118A,13},{0x000D, 4},
{0x0010, 5},{0x0009, 5},{0x0014, 6},{0x0047, 7},
{0x00F1, 8},{0x0463,11},{0x001F, 5},{0x000C, 5}
},
{
{0x0000, 3},{0x001A, 5},{0x0033, 6},{0x000C, 5},
{0x0046, 7},{0x01E3, 9},{0x03C5,10},{0x0017, 5},
{0x1E21,13},{0x0002, 3},{0x0001, 3},{0x0009, 4},
{0x000A, 4},{0x0007, 4},{0x001B, 5},{0x003D, 6},
{0x001B, 6},{0x0022, 6},{0x0079, 7},{0x00F0, 8},
{0x1E20,13},{0x1E23,13},{0x1E22,13},{0x000E, 4},
{0x0016, 5},{0x0018, 5},{0x0032, 6},{0x001A, 6},
{0x0047, 7},{0x0789,11},{0x001F, 5},{0x0010, 5}
},
{
{0x001D, 5},{0x0061, 7},{0x004E, 8},{0x009E, 9},
{0x027C,11},{0x09F5,13},{0x09F4,13},{0x0003, 4},
{0x0060, 7},{0x0000, 3},{0x000F, 4},{0x000B, 4},
{0x000A, 4},{0x0009, 4},{0x0005, 4},{0x000D, 5},
{0x0031, 6},{0x0008, 5},{0x0038, 6},{0x0012, 6},
{0x0026, 7},{0x013F,10},{0x04FB,12},{0x000D, 4},
{0x0002, 4},{0x000C, 5},{0x0039, 6},{0x001C, 6},
{0x000F, 5},{0x001D, 6},{0x0008, 4},{0x0019, 5}
},
{
{0x0007, 4},{0x0019, 6},{0x00AB, 8},{0x00AA, 8},
{0x0119,10},{0x0461,12},{0x0460,12},{0x001B, 5},
{0x0047, 8},{0x0001, 3},{0x0000, 3},{0x000C, 4},
{0x000B, 4},{0x0009, 4},{0x0005, 4},{0x000D, 5},
{0x0035, 6},{0x003D, 6},{0x003C, 6},{0x0018, 6},
{0x0022, 7},{0x008D, 9},{0x0231,11},{0x000E, 4},
{0x001F, 5},{0x0009, 5},{0x002B, 6},{0x0010, 6},
{0x0034, 6},{0x0054, 7},{0x0008, 4},{0x0014, 5}
},
{
{0x000C, 4},{0x0005, 5},{0x0008, 6},{0x005B, 7},
{0x004D, 9},{0x0131,11},{0x0261,12},{0x001A, 5},
{0x0012, 7},{0x0000, 3},{0x000F, 4},{0x000A, 4},
{0x0009, 4},{0x0006, 4},{0x001B, 5},{0x0006, 5},
{0x001C, 6},{0x002C, 6},{0x0015, 6},{0x005A, 7},
{0x0027, 8},{0x0099,10},{0x0260,12},{0x000E, 4},
{0x0004, 4},{0x000F, 5},{0x0007, 5},{0x001D, 6},
{0x000B, 5},{0x0014, 6},{0x0008, 4},{0x0017, 5}
},
{
{0x000F, 4},{0x0013, 5},{0x0075, 7},{0x0024, 6},
{0x0095, 8},{0x0251,10},{0x04A0,11},{0x0010, 5},
{0x00C8, 8},{0x0002, 3},{0x0001, 3},{0x0001, 4},
{0x0000, 4},{0x001A, 5},{0x0011, 5},{0x002C, 6},
{0x0065, 7},{0x0074, 7},{0x004B, 7},{0x00C9, 8},
{0x0129, 9},{0x0943,12},{0x0942,12},{0x0003, 3},
{0x000A, 4},{0x001C, 5},{0x0018, 5},{0x0033, 6},
{0x0017, 5},{0x002D, 6},{0x001B, 5},{0x003B, 6}
},
{
{0x0003, 3},{0x001A, 5},{0x002D, 6},{0x0038, 6},
{0x0028, 7},{0x0395,10},{0x0E51,12},{0x0037, 6},
{0x00E4, 8},{0x0001, 3},{0x0000, 3},{0x001F, 5},
{0x001E, 5},{0x0017, 5},{0x003A, 6},{0x0073, 7},
{0x002A, 7},{0x002B, 7},{0x0029, 7},{0x01CB, 9},
{0x0729,11},{0x1CA1,13},{0x1CA0,13},{0x0004, 3},
{0x000A, 4},{0x0004, 4},{0x0018, 5},{0x0036, 6},
{0x000B, 5},{0x002C, 6},{0x0019, 5},{0x003B, 6}
},
{
{0x0004, 3},{0x0004, 4},{0x003F, 6},{0x0017, 5},
{0x0075, 7},{0x01F5, 9},{0x07D1,11},{0x0017, 6},
{0x01F6, 9},{0x0001, 3},{0x0000, 3},{0x001B, 5},
{0x001A, 5},{0x000A, 5},{0x0032, 6},{0x0074, 7},
{0x00F8, 8},{0x00F9, 8},{0x01F7, 9},{0x03E9,10},
{0x0FA0,12},{0x1F43,13},{0x1F42,13},{0x0003, 3},
{0x000A, 4},{0x001E, 5},{0x001C, 5},{0x003B, 6},
{0x0018, 5},{0x0016, 6},{0x0016, 5},{0x0033, 6}
},
{
{0x0004, 3},{0x0007, 4},{0x0018, 5},{0x001E, 5},
{0x0036, 6},{0x0031, 7},{0x0177, 9},{0x0077, 7},
{0x0176, 9},{0x0001, 3},{0x0000, 3},{0x001A, 5},
{0x0019, 5},{0x003A, 6},{0x0019, 6},{0x005C, 7},
{0x00BA, 8},{0x0061, 8},{0x00C1, 9},{0x0180,10},
{0x0302,11},{0x0607,12},{0x0606,12},{0x0002, 3},
{0x000A, 4},{0x001F, 5},{0x001C, 5},{0x0037, 6},
{0x0016, 5},{0x0076, 7},{0x000D, 5},{0x002F, 6}
},
{
{0x0000, 3},{0x000A, 4},{0x001A, 5},{0x000C, 4},
{0x001D, 5},{0x0039, 6},{0x0078, 7},{0x005E, 7},
{0x0393,11},{0x0002, 3},{0x0001, 3},{0x0016, 5},
{0x000F, 5},{0x002E, 6},{0x005F, 7},{0x0073, 8},
{0x00E5, 9},{0x01C8,10},{0x0E4A,13},{0x1C97,14},
{0x1C96,14},{0x0E49,13},{0x0E48,13},{0x0004, 3},
{0x0006, 4},{0x001F, 5},{0x001B, 5},{0x001D, 6},
{0x0038, 6},{0x0038, 7},{0x003D, 6},{0x0079, 7}
},
{
{0x000B, 5},{0x002B, 7},{0x0054, 8},{0x01B7, 9},
{0x06D9,11},{0x0DB1,12},{0x0DB0,12},{0x0002, 4},
{0x00AB, 9},{0x0009, 4},{0x000A, 4},{0x0007, 4},
{0x0008, 4},{0x000F, 4},{0x000C, 4},{0x0003, 4},
{0x001D, 5},{0x0004, 4},{0x000B, 4},{0x0006, 4},
{0x001A, 5},{0x0003, 6},{0x00AA, 9},{0x0001, 4},
{0x0000, 5},{0x0014, 6},{0x006C, 7},{0x00DA, 8},
{0x0002, 6},{0x036D,10},{0x001C, 5},{0x0037, 6}
},
{
{0x001D, 5},{0x0004, 6},{0x00B6, 8},{0x006A, 8},
{0x05B9,11},{0x16E1,13},{0x16E0,13},{0x0007, 4},
{0x016F, 9},{0x000C, 4},{0x000D, 4},{0x0009, 4},
{0x0008, 4},{0x000F, 4},{0x000A, 4},{0x0003, 4},
{0x0017, 5},{0x0002, 4},{0x0004, 4},{0x001C, 5},
{0x002C, 6},{0x006B, 8},{0x0B71,12},{0x0005, 4},
{0x0003, 5},{0x001B, 6},{0x005A, 7},{0x0034, 7},
{0x0005, 6},{0x02DD,10},{0x0000, 4},{0x000C, 5}
},
{
{0x0003, 4},{0x007F, 7},{0x00A1, 8},{0x00A0, 8},
{0x020C,10},{0x0834,12},{0x106B,13},{0x0007, 4},
{0x0082, 8},{0x000E, 4},{0x000D, 4},{0x000B, 4},
{0x000C, 4},{0x0000, 3},{0x0009, 4},{0x0002, 4},
{0x0011, 5},{0x001E, 5},{0x0015, 5},{0x003E, 6},
{0x0040, 7},{0x041B,11},{0x106A,13},{0x0006, 4},
{0x000A, 5},{0x0029, 6},{0x007E, 7},{0x0051, 7},
{0x0021, 6},{0x0107, 9},{0x0004, 4},{0x000B, 5}
},
{
{0x0007, 4},{0x001B, 6},{0x00F6, 8},{0x00E9, 8},
{0x03A1,10},{0x0740,11},{0x0E82,12},{0x001F, 5},
{0x01EF, 9},{0x0001, 3},{0x0002, 3},{0x000B, 4},
{0x000C, 4},{0x000D, 4},{0x0008, 4},{0x001C, 5},
{0x0003, 5},{0x0012, 5},{0x0002, 5},{0x0075, 7},
{0x01D1, 9},{0x1D07,13},{0x1D06,13},{0x000A, 4},
{0x0013, 5},{0x003B, 6},{0x001A, 6},{0x007A, 7},
{0x003C, 6},{0x01EE, 9},{0x0000, 4},{0x000C, 5}
},
{
{0x000D, 4},{0x003D, 6},{0x0042, 7},{0x0037, 7},
{0x00D9, 9},{0x0362,11},{0x06C6,12},{0x001F, 5},
{0x0086, 8},{0x0001, 3},{0x0002, 3},{0x000C, 4},
{0x000B, 4},{0x000A, 4},{0x0001, 4},{0x000F, 5},
{0x0025, 6},{0x003C, 6},{0x001A, 6},{0x0087, 8},
{0x01B0,10},{0x0D8F,13},{0x0D8E,13},{0x000E, 4},
{0x0013, 5},{0x000C, 5},{0x0024, 6},{0x0020, 6},
{0x0011, 5},{0x006D, 8},{0x0000, 4},{0x000E, 5}
},
{
{0x0000, 3},{0x0012, 5},{0x0076, 7},{0x0077, 7},
{0x014D, 9},{0x0533,11},{0x14C9,13},{0x0013, 5},
{0x00A5, 8},{0x0002, 3},{0x0003, 3},{0x000B, 4},
{0x000C, 4},{0x0008, 4},{0x001A, 5},{0x002B, 6},
{0x0075, 7},{0x0074, 7},{0x00A7, 8},{0x0298,10},
{0x14C8,13},{0x14CB,13},{0x14CA,13},{0x000F, 4},
{0x001C, 5},{0x0007, 5},{0x002A, 6},{0x0028, 6},
{0x001B, 5},{0x00A4, 8},{0x0002, 4},{0x0006, 5}
},
{
{0x0002, 3},{0x001A, 5},{0x002B, 6},{0x003A, 6},
{0x00ED, 8},{0x0283,10},{0x0A0A,12},{0x0004, 5},
{0x00A1, 8},{0x0004, 3},{0x0003, 3},{0x000B, 4},
{0x000C, 4},{0x001F, 5},{0x0006, 5},{0x0077, 7},
{0x00A3, 8},{0x00A2, 8},{0x0140, 9},{0x1417,13},
{0x1416,13},{0x0A09,12},{0x0A08,12},{0x0000, 3},
{0x001E, 5},{0x0007, 5},{0x002A, 6},{0x0029, 6},
{0x001C, 5},{0x00EC, 8},{0x001B, 5},{0x0005, 5}
},
{
{0x0002, 3},{0x0002, 4},{0x0018, 5},{0x001D, 5},
{0x0035, 6},{0x00E4, 8},{0x01CF,11},{0x001D, 7},
{0x0072, 9},{0x0004, 3},{0x0005, 3},{0x0006, 4},
{0x0007, 4},{0x0006, 5},{0x0073, 7},{0x0038, 8},
{0x01CE,11},{0x039B,12},{0x0398,12},{0x0733,13},
{0x0732,13},{0x0735,13},{0x0734,13},{0x0000, 3},
{0x001F, 5},{0x001B, 5},{0x0034, 6},{0x000F, 6},
{0x001E, 5},{0x00E5, 8},{0x0019, 5},{0x0038, 6}
},
{
{0x0016, 5},{0x0050, 7},{0x0172, 9},{0x02E7,10},
{0x1732,13},{0x2E67,14},{0x2E66,14},{0x0006, 4},
{0x0051, 7},{0x0001, 3},{0x0000, 3},{0x000D, 4},
{0x000C, 4},{0x0009, 4},{0x001C, 5},{0x0009, 5},
{0x001C, 6},{0x001D, 6},{0x005D, 7},{0x00B8, 8},
{0x05CD,11},{0x1731,13},{0x1730,13},{0x000F, 4},
{0x0005, 4},{0x000F, 5},{0x0008, 5},{0x0029, 6},
{0x001D, 5},{0x002F, 6},{0x0008, 4},{0x0015, 5}
},
{
{0x0009, 4},{0x0021, 6},{0x0040, 7},{0x00AD, 8},
{0x02B0,10},{0x1589,13},{0x1588,13},{0x001C, 5},
{0x005F, 7},{0x0000, 3},{0x000F, 4},{0x000D, 4},
{0x000C, 4},{0x0006, 4},{0x0011, 5},{0x002A, 6},
{0x0057, 7},{0x005E, 7},{0x0041, 7},{0x0159, 9},
{0x0563,11},{0x158B,13},{0x158A,13},{0x0001, 3},
{0x0005, 4},{0x0014, 5},{0x003B, 6},{0x002E, 6},
{0x0004, 4},{0x003A, 6},{0x0007, 4},{0x0016, 5}
},
{
{0x000E, 4},{0x0007, 5},{0x0046, 7},{0x0045, 7},
{0x0064, 9},{0x032A,12},{0x0657,13},{0x0018, 5},
{0x000D, 6},{0x0000, 3},{0x000F, 4},{0x000A, 4},
{0x000B, 4},{0x001A, 5},{0x0036, 6},{0x0047, 7},
{0x0044, 7},{0x0018, 7},{0x0033, 8},{0x00CB,10},
{0x0656,13},{0x0329,12},{0x0328,12},{0x0002, 3},
{0x0006, 4},{0x0019, 5},{0x000E, 5},{0x0037, 6},
{0x0009, 4},{0x000F, 5},{0x0002, 4},{0x0010, 5}
},
{
{0x0003, 3},{0x0018, 5},{0x0023, 6},{0x0077, 7},
{0x0194, 9},{0x1956,13},{0x32AF,14},{0x003A, 6},
{0x0076, 7},{0x0002, 3},{0x0001, 3},{0x001F, 5},
{0x001E, 5},{0x0014, 5},{0x0022, 6},{0x0064, 7},
{0x0197, 9},{0x0196, 9},{0x032B,10},{0x0654,11},
{0x32AE,14},{0x1955,13},{0x1954,13},{0x0000, 3},
{0x0009, 4},{0x001C, 5},{0x0015, 5},{0x0010, 5},
{0x000D, 4},{0x0017, 5},{0x0016, 5},{0x0033, 6}
},
{
{0x0005, 3},{0x0006, 4},{0x003E, 6},{0x0010, 5},
{0x0048, 7},{0x093F,12},{0x24FA,14},{0x0032, 6},
{0x0067, 7},{0x0002, 3},{0x0001, 3},{0x001B, 5},
{0x001E, 5},{0x0034, 6},{0x0066, 7},{0x0092, 8},
{0x0126, 9},{0x024E,10},{0x049E,11},{0x49F7,15},
{0x49F6,15},{0x24F9,14},{0x24F8,14},{0x0000, 3},
{0x0007, 4},{0x0018, 5},{0x0011, 5},{0x003F, 6},
{0x000E, 4},{0x0013, 5},{0x0035, 6},{0x0025, 6}
},
{
{0x0005, 3},{0x0008, 4},{0x0012, 5},{0x001C, 5},
{0x001C, 6},{0x00EA, 9},{0x1D75,14},{0x001E, 6},
{0x0066, 7},{0x0001, 3},{0x0002, 3},{0x001B, 5},
{0x001A, 5},{0x001F, 6},{0x003B, 7},{0x0074, 8},
{0x01D6,10},{0x03AF,11},{0x1D74,14},{0x1D77,14},
{0x1D76,14},{0x0EB9,13},{0x0EB8,13},{0x000F, 4},
{0x0006, 4},{0x0013, 5},{0x003B, 6},{0x003A, 6},
{0x0000, 3},{0x0018, 5},{0x0032, 6},{0x0067, 7}
},
{
{0x0004, 3},{0x000A, 4},{0x001B, 5},{0x000C, 4},
{0x000D, 5},{0x00E6, 8},{0x0684,11},{0x0072, 7},
{0x00E7, 8},{0x0002, 3},{0x0001, 3},{0x0017, 5},
{0x0016, 5},{0x0018, 6},{0x00D1, 8},{0x01A0, 9},
{0x0686,11},{0x0D0F,12},{0x0D0A,12},{0x1A17,13},
{0x1A16,13},{0x1A1D,13},{0x1A1C,13},{0x000F, 4},
{0x001D, 5},{0x000E, 5},{0x0035, 6},{0x0038, 6},
{0x0000, 3},{0x000F, 5},{0x0019, 6},{0x0069, 7}
},
{
{0x0003, 3},{0x000C, 4},{0x001B, 5},{0x0000, 3},
{0x0003, 4},{0x002E, 6},{0x0051, 9},{0x00BC, 8},
{0x0053, 9},{0x0004, 3},{0x0002, 3},{0x0016, 5},
{0x0015, 5},{0x0015, 7},{0x0050, 9},{0x00A4,10},
{0x0294,12},{0x052B,13},{0x052A,13},{0x052D,13},
{0x052C,13},{0x052F,13},{0x052E,13},{0x000E, 4},
{0x001A, 5},{0x0004, 5},{0x0028, 6},{0x0029, 6},
{0x000F, 4},{0x000B, 6},{0x005F, 7},{0x00BD, 8}
},
{
{0x0003, 4},{0x0009, 6},{0x00D0, 8},{0x01A3, 9},
{0x0344,10},{0x0D14,12},{0x1A2B,13},{0x0004, 4},
{0x0015, 7},{0x0000, 3},{0x000F, 4},{0x000B, 4},
{0x000C, 4},{0x000E, 4},{0x0009, 4},{0x001B, 5},
{0x000A, 5},{0x0014, 5},{0x000D, 5},{0x002A, 6},
{0x0014, 7},{0x068B,11},{0x1A2A,13},{0x0008, 4},
{0x000B, 5},{0x002B, 6},{0x000B, 6},{0x0069, 7},
{0x0035, 6},{0x0008, 6},{0x0007, 4},{0x000C, 5}
},
{
{0x000A, 4},{0x003C, 6},{0x0032, 7},{0x0030, 7},
{0x00C5, 9},{0x0621,12},{0x0620,12},{0x001F, 5},
{0x0033, 7},{0x0001, 3},{0x0000, 3},{0x000E, 4},
{0x000D, 4},{0x000C, 4},{0x0004, 4},{0x000D, 5},
{0x0026, 6},{0x0027, 6},{0x0014, 6},{0x0063, 8},
{0x0189,10},{0x0623,12},{0x0622,12},{0x000B, 4},
{0x0012, 5},{0x003D, 6},{0x0022, 6},{0x0015, 6},
{0x000B, 5},{0x0023, 6},{0x0007, 4},{0x0010, 5}
},
{
{0x000F, 4},{0x000C, 5},{0x0043, 7},{0x0010, 6},
{0x0044, 8},{0x0114,10},{0x0455,12},{0x0018, 5},
{0x0023, 7},{0x0001, 3},{0x0000, 3},{0x000E, 4},
{0x000D, 4},{0x0009, 4},{0x0019, 5},{0x0009, 5},
{0x0017, 6},{0x0016, 6},{0x0042, 7},{0x008B, 9},
{0x0454,12},{0x0457,12},{0x0456,12},{0x000B, 4},
{0x0015, 5},{0x000A, 5},{0x0029, 6},{0x0020, 6},
{0x000D, 5},{0x0028, 6},{0x0007, 4},{0x0011, 5}
},
{
{0x0001, 3},{0x001A, 5},{0x0029, 6},{0x002A, 6},
{0x00A0, 8},{0x0285,10},{0x1425,13},{0x0002, 5},
{0x0000, 7},{0x0002, 3},{0x0003, 3},{0x000C, 4},
{0x000B, 4},{0x0008, 4},{0x0012, 5},{0x0001, 6},
{0x0051, 7},{0x0001, 7},{0x0143, 9},{0x0508,11},
{0x1424,13},{0x1427,13},{0x1426,13},{0x000F, 4},
{0x001C, 5},{0x0003, 5},{0x0037, 6},{0x002B, 6},
{0x0013, 5},{0x0036, 6},{0x001D, 5},{0x0001, 5}
},
{
{0x0004, 3},{0x001F, 5},{0x003D, 6},{0x0006, 5},
{0x0016, 7},{0x0053, 9},{0x014A,11},{0x0034, 6},
{0x002A, 8},{0x0002, 3},{0x0003, 3},{0x000B, 4},
{0x000C, 4},{0x001C, 5},{0x0037, 6},{0x0017, 7},
{0x002B, 8},{0x0028, 8},{0x00A4,10},{0x052D,13},
{0x052C,13},{0x052F,13},{0x052E,13},{0x0000, 3},
{0x001D, 5},{0x0007, 5},{0x0004, 5},{0x0035, 6},
{0x0014, 5},{0x0036, 6},{0x0015, 5},{0x003C, 6}
},
{
{0x0004, 3},{0x000A, 4},{0x0007, 5},{0x001D, 5},
{0x0009, 6},{0x01F3, 9},{0x07C7,11},{0x0008, 6},
{0x01F0, 9},{0x0003, 3},{0x0002, 3},{0x000D, 4},
{0x000C, 4},{0x0017, 5},{0x007D, 7},{0x01F2, 9},
{0x07C6,11},{0x07C5,11},{0x1F12,13},{0x3E27,14},
{0x3E26,14},{0x1F11,13},{0x1F10,13},{0x0000, 3},
{0x001E, 5},{0x0006, 5},{0x0039, 6},{0x0038, 6},
{0x003F, 6},{0x002C, 6},{0x0005, 5},{0x002D, 6}
},
{
{0x0002, 3},{0x0007, 4},{0x0018, 5},{0x0003, 4},
{0x0005, 5},{0x0035, 7},{0x004F, 9},{0x0012, 7},
{0x04E5,13},{0x0005, 3},{0x0004, 3},{0x000D, 4},
{0x000E, 4},{0x0033, 6},{0x0026, 8},{0x009D,10},
{0x04E4,13},{0x04E7,13},{0x04E6,13},{0x04E1,13},
{0x04E0,13},{0x04E3,13},{0x04E2,13},{0x0000, 3},
{0x001F, 5},{0x000C, 5},{0x003D, 6},{0x003C, 6},
{0x0032, 6},{0x0034, 7},{0x001B, 6},{0x0008, 6}
},
{
{0x0000, 3},{0x0004, 4},{0x001C, 5},{0x000F, 4},
{0x0002, 4},{0x0007, 5},{0x0075, 7},{0x00E8, 8},
{0x1D2A,13},{0x0005, 3},{0x0004, 3},{0x000D, 4},
{0x000C, 4},{0x0077, 7},{0x0E96,12},{0x3A57,14},
{0x3A56,14},{0x3A5D,14},{0x3A5C,14},{0x3A5F,14},
{0x3A5E,14},{0x1D29,13},{0x1D28,13},{0x0003, 3},
{0x0006, 5},{0x000A, 5},{0x002C, 7},{0x0017, 6},
{0x0076, 7},{0x01D3, 9},{0x03A4,10},{0x002D, 7}
},
{
{0x000A, 4},{0x0024, 6},{0x00BF, 8},{0x0085, 8},
{0x0211,10},{0x0842,12},{0x1087,13},{0x0018, 5},
{0x0020, 6},{0x0001, 3},{0x0002, 3},{0x000E, 4},
{0x000D, 4},{0x0007, 4},{0x0013, 5},{0x0025, 6},
{0x005E, 7},{0x0043, 7},{0x00BE, 8},{0x0109, 9},
{0x1086,13},{0x0841,12},{0x0840,12},{0x000F, 4},
{0x0001, 4},{0x0011, 5},{0x0000, 5},{0x002E, 6},
{0x0019, 5},{0x0001, 5},{0x0006, 4},{0x0016, 5}
},
{
{0x0002, 3},{0x000F, 5},{0x006F, 7},{0x0061, 7},
{0x0374,10},{0x1BA8,13},{0x3753,14},{0x0012, 5},
{0x0036, 6},{0x0000, 3},{0x0001, 3},{0x000A, 4},
{0x000B, 4},{0x001A, 5},{0x0031, 6},{0x0060, 7},
{0x00DC, 8},{0x01BB, 9},{0x06EB,11},{0x1BAB,13},
{0x3752,14},{0x3755,14},{0x3754,14},{0x000E, 4},
{0x0006, 4},{0x0013, 5},{0x000E, 5},{0x003E, 6},
{0x0008, 4},{0x001E, 5},{0x0019, 5},{0x003F, 6}
},
{
{0x0003, 3},{0x001C, 5},{0x0025, 6},{0x0024, 6},
{0x01DA, 9},{0x1DBD,13},{0x3B7C,14},{0x003C, 6},
{0x003D, 6},{0x0000, 3},{0x0001, 3},{0x000B, 4},
{0x000A, 4},{0x000B, 5},{0x0077, 7},{0x00EC, 8},
{0x03B6,10},{0x076E,11},{0x1DBF,13},{0x76FB,15},
{0x76FA,15},{0x3B79,14},{0x3B78,14},{0x000D, 4},
{0x001F, 5},{0x0013, 5},{0x000A, 5},{0x0008, 5},
{0x000C, 4},{0x0008, 4},{0x0009, 5},{0x003A, 6}
},
{
{0x0005, 3},{0x0003, 4},{0x0004, 5},{0x0010, 5},
{0x008F, 8},{0x0475,11},{0x11D1,13},{0x0079, 7},
{0x0027, 6},{0x0002, 3},{0x0003, 3},{0x0001, 4},
{0x0000, 4},{0x0026, 6},{0x0046, 7},{0x011C, 9},
{0x0477,11},{0x08ED,12},{0x11D0,13},{0x11D3,13},
{0x11D2,13},{0x11D9,13},{0x11D8,13},{0x000D, 4},
{0x001F, 5},{0x0012, 5},{0x0005, 5},{0x003D, 6},
{0x000C, 4},{0x000E, 4},{0x0022, 6},{0x0078, 7}
},
{
{0x0005, 3},{0x000C, 4},{0x001B, 5},{0x0000, 4},
{0x0006, 6},{0x03E2,10},{0x3E3D,14},{0x000F, 7},
{0x0034, 6},{0x0003, 3},{0x0002, 3},{0x001E, 5},
{0x001D, 5},{0x007D, 7},{0x01F0, 9},{0x07C6,11},
{0x3E3C,14},{0x3E3F,14},{0x3E3E,14},{0x3E39,14},
{0x3E38,14},{0x3E3B,14},{0x3E3A,14},{0x0008, 4},
{0x001C, 5},{0x0002, 5},{0x003F, 6},{0x0035, 6},
{0x0009, 4},{0x0001, 3},{0x000E, 7},{0x00F9, 8}
},
{
{0x0004, 3},{0x000B, 4},{0x0001, 4},{0x000A, 4},
{0x001E, 6},{0x00E0, 9},{0x0E1E,13},{0x0071, 8},
{0x0039, 7},{0x0007, 3},{0x0006, 3},{0x000D, 5},
{0x000C, 5},{0x0020, 7},{0x01C2,10},{0x1C3F,14},
{0x1C3E,14},{0x0E19,13},{0x0E18,13},{0x0E1B,13},
{0x0E1A,13},{0x0E1D,13},{0x0E1C,13},{0x0000, 4},
{0x0009, 5},{0x001D, 6},{0x001F, 6},{0x0011, 6},
{0x0005, 4},{0x0001, 3},{0x0043, 8},{0x0042, 8}
},
{
{0x0004, 3},{0x000D, 4},{0x0007, 4},{0x0002, 3},
{0x0014, 5},{0x016C, 9},{0x16D1,13},{0x02DF,10},
{0x016E, 9},{0x0000, 2},{0x0007, 3},{0x002C, 6},
{0x002B, 6},{0x02DE,10},{0x16D0,13},{0x16D3,13},
{0x16D2,13},{0x2DB5,14},{0x2DB4,14},{0x2DB7,14},
{0x2DB6,14},{0x16D9,13},{0x16D8,13},{0x000C, 5},
{0x002A, 6},{0x005A, 7},{0x001B, 6},{0x001A, 6},
{0x0017, 5},{0x000C, 4},{0x05B7,11},{0x05B5,11}
},
{
{0x0002, 2},{0x000F, 4},{0x001C, 5},{0x000C, 4},
{0x003B, 6},{0x01AC, 9},{0x1AD8,13},{0x35B3,14},
{0x35B2,14},{0x0001, 2},{0x0000, 2},{0x0069, 7},
{0x0068, 7},{0x35BD,14},{0x35BC,14},{0x35BF,14},
{0x35BE,14},{0x35B9,14},{0x35B8,14},{0x35BB,14},
{0x35BA,14},{0x35B5,14},{0x35B4,14},{0x01A9, 9},
{0x01A8, 9},{0x035A,10},{0x00D7, 8},{0x00D5, 8},
{0x003A, 6},{0x001B, 5},{0x35B7,14},{0x35B6,14}
},
{
{0x0000, 3},{0x0010, 5},{0x0072, 7},{0x0071, 7},
{0x0154, 9},{0x0AAB,12},{0x0AA8,12},{0x0014, 5},
{0x0070, 7},{0x0002, 3},{0x0003, 3},{0x000C, 4},
{0x000B, 4},{0x0003, 4},{0x0011, 5},{0x0073, 7},
{0x0054, 7},{0x00AB, 8},{0x02AB,10},{0x1553,13},
{0x1552,13},{0x1555,13},{0x1554,13},{0x000D, 4},
{0x001E, 5},{0x0012, 5},{0x003E, 6},{0x002B, 6},
{0x0002, 4},{0x003F, 6},{0x001D, 5},{0x0013, 5}
},
{
{0x0003, 3},{0x001F, 5},{0x0029, 6},{0x003D, 6},
{0x000C, 7},{0x0069,10},{0x0345,13},{0x0002, 5},
{0x0028, 6},{0x0002, 3},{0x0001, 3},{0x000E, 4},
{0x000C, 4},{0x0015, 5},{0x0007, 6},{0x001B, 8},
{0x006B,10},{0x006A,10},{0x0344,13},{0x0347,13},
{0x0346,13},{0x01A1,12},{0x01A0,12},{0x000B, 4},
{0x001A, 5},{0x0012, 5},{0x0000, 5},{0x003C, 6},
{0x0008, 4},{0x001B, 5},{0x0013, 5},{0x0001, 5}
},
{
{0x0004, 3},{0x0004, 4},{0x003F, 6},{0x0014, 5},
{0x0056, 7},{0x015C, 9},{0x15D5,13},{0x003C, 6},
{0x002A, 6},{0x0000, 3},{0x0001, 3},{0x000E, 4},
{0x000D, 4},{0x000C, 5},{0x00AF, 8},{0x02BB,10},
{0x15D4,13},{0x15D7,13},{0x15D6,13},{0x15D1,13},
{0x15D0,13},{0x15D3,13},{0x15D2,13},{0x000B, 4},
{0x0019, 5},{0x000D, 5},{0x003E, 6},{0x0031, 6},
{0x0007, 4},{0x0005, 4},{0x003D, 6},{0x0030, 6}
},
{
{0x0005, 3},{0x0008, 4},{0x001A, 5},{0x0000, 4},
{0x0036, 6},{0x0011, 8},{0x0106,12},{0x000A, 7},
{0x006E, 7},{0x0002, 3},{0x0003, 3},{0x0003, 4},
{0x0002, 4},{0x006F, 7},{0x0021, 9},{0x020F,13},
{0x020E,13},{0x0101,12},{0x0100,12},{0x0103,12},
{0x0102,12},{0x0105,12},{0x0104,12},{0x000C, 4},
{0x001E, 5},{0x0003, 5},{0x003E, 6},{0x003F, 6},
{0x0009, 4},{0x000E, 4},{0x000B, 7},{0x0009, 7}
},
{
{0x0002, 3},{0x000E, 4},{0x001E, 5},{0x000C, 4},
{0x001F, 5},{0x006E, 7},{0x00AD,10},{0x00AF,10},
{0x0014, 7},{0x0004, 3},{0x0003, 3},{0x001A, 5},
{0x0017, 5},{0x002A, 8},{0x0576,13},{0x0AEF,14},
{0x0AEE,14},{0x0571,13},{0x0570,13},{0x0573,13},
{0x0572,13},{0x0575,13},{0x0574,13},{0x0003, 4},
{0x0016, 5},{0x0004, 5},{0x0036, 6},{0x000B, 6},
{0x000A, 4},{0x0000, 3},{0x006F, 7},{0x00AC,10}
},
{
{0x0004, 3},{0x0005, 4},{0x0003, 3},{0x0001, 3},
{0x0004, 4},{0x002F, 6},{0x0526,11},{0x1495,13},
{0x00A6, 8},{0x0007, 3},{0x0006, 3},{0x002D, 6},
{0x002C, 6},{0x1494,13},{0x1497,13},{0x1496,13},
{0x1491,13},{0x1490,13},{0x1493,13},{0x1492,13},
{0x293D,14},{0x293C,14},{0x293F,14},{0x0000, 3},
{0x0028, 6},{0x00A5, 8},{0x0148, 9},{0x00A7, 8},
{0x002E, 6},{0x0015, 5},{0x0A4E,12},{0x293E,14}
},
{
{0x0004, 3},{0x0005, 4},{0x0003, 3},{0x0001, 3},
{0x0004, 4},{0x002F, 6},{0x0526,11},{0x1495,13},
{0x00A6, 8},{0x0007, 3},{0x0006, 3},{0x002D, 6},
{0x002C, 6},{0x1494,13},{0x1497,13},{0x1496,13},
{0x1491,13},{0x1490,13},{0x1493,13},{0x1492,13},
{0x293D,14},{0x293C,14},{0x293F,14},{0x0000, 3},
{0x0028, 6},{0x00A5, 8},{0x0148, 9},{0x00A7, 8},
{0x002E, 6},{0x0015, 5},{0x0A4E,12},{0x293E,14}
},
{
{0x0004, 3},{0x0005, 4},{0x0003, 3},{0x0001, 3},
{0x0004, 4},{0x002F, 6},{0x0526,11},{0x1495,13},
{0x00A6, 8},{0x0007, 3},{0x0006, 3},{0x002D, 6},
{0x002C, 6},{0x1494,13},{0x1497,13},{0x1496,13},
{0x1491,13},{0x1490,13},{0x1493,13},{0x1492,13},
{0x293D,14},{0x293C,14},{0x293F,14},{0x0000, 3},
{0x0028, 6},{0x00A5, 8},{0x0148, 9},{0x00A7, 8},
{0x002E, 6},{0x0015, 5},{0x0A4E,12},{0x293E,14}
},
{
{0x0003, 3},{0x0011, 5},{0x0020, 6},{0x0074, 7},
{0x010D, 9},{0x0863,12},{0x0860,12},{0x000A, 5},
{0x0075, 7},{0x0001, 3},{0x0000, 3},{0x000B, 4},
{0x000A, 4},{0x0018, 5},{0x0038, 6},{0x0042, 7},
{0x010F, 9},{0x010E, 9},{0x0219,10},{0x10C3,13},
{0x10C2,13},{0x10C5,13},{0x10C4,13},{0x000F, 4},
{0x0004, 4},{0x0019, 5},{0x000B, 5},{0x0039, 6},
{0x0009, 4},{0x001B, 5},{0x001A, 5},{0x003B, 6}
},
{
{0x0005, 3},{0x0001, 4},{0x003E, 6},{0x0001, 5},
{0x00E2, 8},{0x1C6F,13},{0x38D9,14},{0x0039, 6},
{0x001F, 6},{0x0002, 3},{0x0001, 3},{0x0009, 4},
{0x0008, 4},{0x0000, 5},{0x0070, 7},{0x01C7, 9},
{0x038C,10},{0x071A,11},{0x38D8,14},{0x38DB,14},
{0x38DA,14},{0x38DD,14},{0x38DC,14},{0x000D, 4},
{0x001D, 5},{0x000E, 5},{0x003F, 6},{0x003C, 6},
{0x000C, 4},{0x0006, 4},{0x003D, 6},{0x001E, 6}
},
{
{0x0006, 3},{0x000B, 4},{0x0011, 5},{0x001E, 5},
{0x0074, 7},{0x03AA,10},{0x1D5C,13},{0x0001, 6},
{0x0021, 6},{0x0001, 3},{0x0002, 3},{0x0007, 4},
{0x0006, 4},{0x003E, 6},{0x00EB, 8},{0x01D4, 9},
{0x0EAF,12},{0x3ABB,14},{0x3ABA,14},{0x1D59,13},
{0x1D58,13},{0x1D5B,13},{0x1D5A,13},{0x000A, 4},
{0x001C, 5},{0x0001, 5},{0x003F, 6},{0x003B, 6},
{0x0001, 4},{0x0009, 4},{0x0020, 6},{0x0000, 6}
},
{
{0x0004, 3},{0x000A, 4},{0x0017, 5},{0x0004, 4},
{0x0016, 6},{0x016A, 9},{0x16B1,13},{0x0017, 7},
{0x005B, 7},{0x0006, 3},{0x0007, 3},{0x0001, 4},
{0x0000, 4},{0x000A, 6},{0x02D7,10},{0x0B5A,12},
{0x16B0,13},{0x16B3,13},{0x16B2,13},{0x2D6D,14},
{0x2D6C,14},{0x2D6F,14},{0x2D6E,14},{0x0006, 4},
{0x000A, 5},{0x0004, 5},{0x002C, 6},{0x0017, 6},
{0x0003, 4},{0x0007, 4},{0x0016, 7},{0x00B4, 8}
},
{
{0x0005, 3},{0x000D, 4},{0x0005, 4},{0x0009, 4},
{0x0033, 6},{0x0193, 9},{0x192C,13},{0x0061, 8},
{0x0031, 7},{0x0000, 2},{0x0007, 3},{0x0010, 5},
{0x0011, 5},{0x00C8, 8},{0x192F,13},{0x325B,14},
{0x325A,14},{0x1929,13},{0x1928,13},{0x192B,13},
{0x192A,13},{0x325D,14},{0x325C,14},{0x0018, 5},
{0x001A, 6},{0x001B, 6},{0x0065, 7},{0x0019, 6},
{0x0004, 4},{0x0007, 4},{0x0060, 8},{0x0324,10}
},
{
{0x0006, 3},{0x0000, 3},{0x0002, 4},{0x000F, 4},
{0x0039, 6},{0x01D9, 9},{0x1D82,13},{0x0761,11},
{0x03BE,10},{0x0001, 2},{0x0002, 2},{0x000F, 6},
{0x000E, 6},{0x0762,11},{0x3B07,14},{0x3B06,14},
{0x3B1D,14},{0x3B1C,14},{0x3B1F,14},{0x3B1E,14},
{0x3B19,14},{0x3B18,14},{0x3B1B,14},{0x0038, 6},
{0x01DE, 9},{0x00ED, 8},{0x03BF,10},{0x00EE, 8},
{0x003A, 6},{0x0006, 5},{0x0EC0,12},{0x3B1A,14}
},
{
{0x0000, 2},{0x0002, 3},{0x000F, 5},{0x0006, 4},
{0x001C, 6},{0x01D0,10},{0x0E8C,13},{0x1D1B,14},
{0x1D1A,14},{0x0003, 2},{0x0002, 2},{0x00EA, 9},
{0x00E9, 9},{0x0E89,13},{0x0E88,13},{0x0E8B,13},
{0x0E8A,13},{0x1D65,14},{0x1D64,14},{0x1D67,14},
{0x1D66,14},{0x1D61,14},{0x1D60,14},{0x03AD,11},
{0x1D63,14},{0x1D62,14},{0x1D1D,14},{0x1D1C,14},
{0x003B, 7},{0x01D7,10},{0x1D1F,14},{0x1D1E,14}
},
{
{0x0002, 2},{0x000F, 4},{0x001C, 5},{0x000C, 4},
{0x003B, 6},{0x01AC, 9},{0x1AD8,13},{0x35B3,14},
{0x35B2,14},{0x0001, 2},{0x0000, 2},{0x0069, 7},
{0x0068, 7},{0x35BD,14},{0x35BC,14},{0x35BF,14},
{0x35BE,14},{0x35B9,14},{0x35B8,14},{0x35BB,14},
{0x35BA,14},{0x35B5,14},{0x35B4,14},{0x01A9, 9},
{0x01A8, 9},{0x035A,10},{0x00D7, 8},{0x00D5, 8},
{0x003A, 6},{0x001B, 5},{0x35B7,14},{0x35B6,14}
}
};
/*A description of a Huffman code value used when encoding the tree.*/
typedef struct{
/*The bit pattern, left-shifted so that the MSB of all patterns is
aligned.*/
ogg_uint32_t pattern;
/*The amount the bit pattern was shifted.*/
int shift;
/*The token this bit pattern represents.*/
int token;
}oc_huff_entry;
/*Compares two oc_huff_entry structures by their bit patterns.
_c1: The first entry to compare.
_c2: The second entry to compare.
Return: <0 if _c1<_c2, >0 if _c1>_c2.*/
static int huff_entry_cmp(const void *_c1,const void *_c2){
ogg_uint32_t b1;
ogg_uint32_t b2;
b1=((const oc_huff_entry *)_c1)->pattern;
b2=((const oc_huff_entry *)_c2)->pattern;
return b1<b2?-1:b1>b2?1:0;
}
/*Encodes a description of the given Huffman tables.
Although the codes are stored in the encoder as flat arrays, in the bit
stream and in the decoder they are structured as a tree.
This function recovers the tree structure from the flat array and then
writes it out.
Note that the codes MUST form a Huffman code, and not merely a prefix-free
code, since the binary tree is assumed to be full.
_opb: The buffer to store the tree in.
_codes: The Huffman tables to pack.
Return: 0 on success, or a negative value if one of the given Huffman tables
does not form a full, prefix-free code.*/
int oc_huff_codes_pack(oggpack_buffer *_opb,
const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]){
int i;
for(i=0;i<TH_NHUFFMAN_TABLES;i++){
oc_huff_entry entries[TH_NDCT_TOKENS];
int bpos;
int maxlen;
int mask;
int j;
/*First, find the maximum code length so we can align all the bit
patterns.*/
maxlen=_codes[i][0].nbits;
for(j=1;j<TH_NDCT_TOKENS;j++){
maxlen=OC_MAXI(_codes[i][j].nbits,maxlen);
}
mask=(1<<(maxlen>>1)<<(maxlen+1>>1))-1;
/*Copy over the codes into our temporary workspace.
The bit patterns are aligned, and the original entry each code is from
is stored as well.*/
for(j=0;j<TH_NDCT_TOKENS;j++){
entries[j].shift=maxlen-_codes[i][j].nbits;
entries[j].pattern=_codes[i][j].pattern<<entries[j].shift&mask;
entries[j].token=j;
}
/*Sort the codes into ascending order.
This is the order the leaves of the tree will be traversed.*/
qsort(entries,TH_NDCT_TOKENS,sizeof(entries[0]),huff_entry_cmp);
/*For each leaf of the tree:*/
bpos=maxlen;
for(j=0;j<TH_NDCT_TOKENS;j++){
int bit;
/*If this code has any bits at all.*/
if(entries[j].shift<maxlen){
/*Descend into the tree, writing a bit for each branch.*/
for(;bpos>entries[j].shift;bpos--)oggpackB_write(_opb,0,1);
/*Mark this as a leaf node, and write its value.*/
oggpackB_write(_opb,1,1);
oggpackB_write(_opb,entries[j].token,5);
/*For each 1 branch we've descended, back up the tree until we reach a
0 branch.*/
bit=1<<bpos;
for(;entries[j].pattern&bit;bpos++)bit<<=1;
/*Validate the code.*/
if(j+1<TH_NDCT_TOKENS){
mask=~(bit-1)<<1;
/*The next entry should have a 1 bit where we had a 0, and should
match our code above that bit.
This verifies both fullness and prefix-freeness simultaneously.*/
if(!(entries[j+1].pattern&bit)||
(entries[j].pattern&mask)!=(entries[j+1].pattern&mask)){
return TH_EINVAL;
}
}
/*If there are no more codes, we should have ascended back to the top
of the tree.*/
else if(bpos<maxlen)return TH_EINVAL;
}
}
}
return 0;
}

View File

@@ -0,0 +1,19 @@
#if !defined(_huffenc_H)
# define _huffenc_H (1)
# include "huffman.h"
typedef th_huff_code th_huff_table[TH_NDCT_TOKENS];
extern const th_huff_code
TH_VP31_HUFF_CODES[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS];
int oc_huff_codes_pack(oggpack_buffer *_opb,
const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]);
#endif

View File

@@ -0,0 +1,70 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: huffman.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_huffman_H)
# define _hufffman_H (1)
# include "theora/codec.h"
# include "ocintrin.h"
/*The range of valid quantized DCT coefficient values.
VP3 used 511 in the encoder, but the bitstream is capable of 580.*/
#define OC_DCT_VAL_RANGE (580)
#define OC_NDCT_TOKEN_BITS (5)
#define OC_DCT_EOB1_TOKEN (0)
#define OC_DCT_EOB2_TOKEN (1)
#define OC_DCT_EOB3_TOKEN (2)
#define OC_DCT_REPEAT_RUN0_TOKEN (3)
#define OC_DCT_REPEAT_RUN1_TOKEN (4)
#define OC_DCT_REPEAT_RUN2_TOKEN (5)
#define OC_DCT_REPEAT_RUN3_TOKEN (6)
#define OC_DCT_SHORT_ZRL_TOKEN (7)
#define OC_DCT_ZRL_TOKEN (8)
#define OC_ONE_TOKEN (9)
#define OC_MINUS_ONE_TOKEN (10)
#define OC_TWO_TOKEN (11)
#define OC_MINUS_TWO_TOKEN (12)
#define OC_DCT_VAL_CAT2 (13)
#define OC_DCT_VAL_CAT3 (17)
#define OC_DCT_VAL_CAT4 (18)
#define OC_DCT_VAL_CAT5 (19)
#define OC_DCT_VAL_CAT6 (20)
#define OC_DCT_VAL_CAT7 (21)
#define OC_DCT_VAL_CAT8 (22)
#define OC_DCT_RUN_CAT1A (23)
#define OC_DCT_RUN_CAT1B (28)
#define OC_DCT_RUN_CAT1C (29)
#define OC_DCT_RUN_CAT2A (30)
#define OC_DCT_RUN_CAT2B (31)
#define OC_NDCT_EOB_TOKEN_MAX (7)
#define OC_NDCT_ZRL_TOKEN_MAX (9)
#define OC_NDCT_VAL_MAX (23)
#define OC_NDCT_VAL_CAT1_MAX (13)
#define OC_NDCT_VAL_CAT2_MAX (17)
#define OC_NDCT_VAL_CAT2_SIZE (OC_NDCT_VAL_CAT2_MAX-OC_DCT_VAL_CAT2)
#define OC_NDCT_RUN_MAX (32)
#define OC_NDCT_RUN_CAT1A_MAX (28)
extern const unsigned char OC_DCT_TOKEN_EXTRA_BITS[TH_NDCT_TOKENS];
#endif

View File

@@ -0,0 +1,335 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: idct.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <string.h>
#include "internal.h"
#include "dct.h"
/*Performs an inverse 8 point Type-II DCT transform.
The output is scaled by a factor of 2 relative to the orthonormal version of
the transform.
_y: The buffer to store the result in.
Data will be placed in every 8th entry (e.g., in a column of an 8x8
block).
_x: The input coefficients.
The first 8 entries are used (e.g., from a row of an 8x8 block).*/
static void idct8(ogg_int16_t *_y,const ogg_int16_t _x[8]){
ogg_int32_t t[8];
ogg_int32_t r;
/*Stage 1:*/
/*0-1 butterfly.*/
t[0]=OC_C4S4*(ogg_int16_t)(_x[0]+_x[4])>>16;
t[1]=OC_C4S4*(ogg_int16_t)(_x[0]-_x[4])>>16;
/*2-3 rotation by 6pi/16.*/
t[2]=(OC_C6S2*_x[2]>>16)-(OC_C2S6*_x[6]>>16);
t[3]=(OC_C2S6*_x[2]>>16)+(OC_C6S2*_x[6]>>16);
/*4-7 rotation by 7pi/16.*/
t[4]=(OC_C7S1*_x[1]>>16)-(OC_C1S7*_x[7]>>16);
/*5-6 rotation by 3pi/16.*/
t[5]=(OC_C3S5*_x[5]>>16)-(OC_C5S3*_x[3]>>16);
t[6]=(OC_C5S3*_x[5]>>16)+(OC_C3S5*_x[3]>>16);
t[7]=(OC_C1S7*_x[1]>>16)+(OC_C7S1*_x[7]>>16);
/*Stage 2:*/
/*4-5 butterfly.*/
r=t[4]+t[5];
t[5]=OC_C4S4*(ogg_int16_t)(t[4]-t[5])>>16;
t[4]=r;
/*7-6 butterfly.*/
r=t[7]+t[6];
t[6]=OC_C4S4*(ogg_int16_t)(t[7]-t[6])>>16;
t[7]=r;
/*Stage 3:*/
/*0-3 butterfly.*/
r=t[0]+t[3];
t[3]=t[0]-t[3];
t[0]=r;
/*1-2 butterfly.*/
r=t[1]+t[2];
t[2]=t[1]-t[2];
t[1]=r;
/*6-5 butterfly.*/
r=t[6]+t[5];
t[5]=t[6]-t[5];
t[6]=r;
/*Stage 4:*/
/*0-7 butterfly.*/
_y[0<<3]=(ogg_int16_t)(t[0]+t[7]);
/*1-6 butterfly.*/
_y[1<<3]=(ogg_int16_t)(t[1]+t[6]);
/*2-5 butterfly.*/
_y[2<<3]=(ogg_int16_t)(t[2]+t[5]);
/*3-4 butterfly.*/
_y[3<<3]=(ogg_int16_t)(t[3]+t[4]);
_y[4<<3]=(ogg_int16_t)(t[3]-t[4]);
_y[5<<3]=(ogg_int16_t)(t[2]-t[5]);
_y[6<<3]=(ogg_int16_t)(t[1]-t[6]);
_y[7<<3]=(ogg_int16_t)(t[0]-t[7]);
}
/*Performs an inverse 8 point Type-II DCT transform.
The output is scaled by a factor of 2 relative to the orthonormal version of
the transform.
_y: The buffer to store the result in.
Data will be placed in every 8th entry (e.g., in a column of an 8x8
block).
_x: The input coefficients.
Only the first 4 entries are used.
The other 4 are assumed to be 0.*/
static void idct8_4(ogg_int16_t *_y,const ogg_int16_t _x[8]){
ogg_int32_t t[8];
ogg_int32_t r;
/*Stage 1:*/
t[0]=OC_C4S4*_x[0]>>16;
t[2]=OC_C6S2*_x[2]>>16;
t[3]=OC_C2S6*_x[2]>>16;
t[4]=OC_C7S1*_x[1]>>16;
t[5]=-(OC_C5S3*_x[3]>>16);
t[6]=OC_C3S5*_x[3]>>16;
t[7]=OC_C1S7*_x[1]>>16;
/*Stage 2:*/
r=t[4]+t[5];
t[5]=OC_C4S4*(ogg_int16_t)(t[4]-t[5])>>16;
t[4]=r;
r=t[7]+t[6];
t[6]=OC_C4S4*(ogg_int16_t)(t[7]-t[6])>>16;
t[7]=r;
/*Stage 3:*/
t[1]=t[0]+t[2];
t[2]=t[0]-t[2];
r=t[0]+t[3];
t[3]=t[0]-t[3];
t[0]=r;
r=t[6]+t[5];
t[5]=t[6]-t[5];
t[6]=r;
/*Stage 4:*/
_y[0<<3]=(ogg_int16_t)(t[0]+t[7]);
_y[1<<3]=(ogg_int16_t)(t[1]+t[6]);
_y[2<<3]=(ogg_int16_t)(t[2]+t[5]);
_y[3<<3]=(ogg_int16_t)(t[3]+t[4]);
_y[4<<3]=(ogg_int16_t)(t[3]-t[4]);
_y[5<<3]=(ogg_int16_t)(t[2]-t[5]);
_y[6<<3]=(ogg_int16_t)(t[1]-t[6]);
_y[7<<3]=(ogg_int16_t)(t[0]-t[7]);
}
/*Performs an inverse 8 point Type-II DCT transform.
The output is scaled by a factor of 2 relative to the orthonormal version of
the transform.
_y: The buffer to store the result in.
Data will be placed in every 8th entry (e.g., in a column of an 8x8
block).
_x: The input coefficients.
Only the first 3 entries are used.
The other 5 are assumed to be 0.*/
static void idct8_3(ogg_int16_t *_y,const ogg_int16_t _x[8]){
ogg_int32_t t[8];
ogg_int32_t r;
/*Stage 1:*/
t[0]=OC_C4S4*_x[0]>>16;
t[2]=OC_C6S2*_x[2]>>16;
t[3]=OC_C2S6*_x[2]>>16;
t[4]=OC_C7S1*_x[1]>>16;
t[7]=OC_C1S7*_x[1]>>16;
/*Stage 2:*/
t[5]=OC_C4S4*t[4]>>16;
t[6]=OC_C4S4*t[7]>>16;
/*Stage 3:*/
t[1]=t[0]+t[2];
t[2]=t[0]-t[2];
r=t[0]+t[3];
t[3]=t[0]-t[3];
t[0]=r;
r=t[6]+t[5];
t[5]=t[6]-t[5];
t[6]=r;
/*Stage 4:*/
_y[0<<3]=(ogg_int16_t)(t[0]+t[7]);
_y[1<<3]=(ogg_int16_t)(t[1]+t[6]);
_y[2<<3]=(ogg_int16_t)(t[2]+t[5]);
_y[3<<3]=(ogg_int16_t)(t[3]+t[4]);
_y[4<<3]=(ogg_int16_t)(t[3]-t[4]);
_y[5<<3]=(ogg_int16_t)(t[2]-t[5]);
_y[6<<3]=(ogg_int16_t)(t[1]-t[6]);
_y[7<<3]=(ogg_int16_t)(t[0]-t[7]);
}
/*Performs an inverse 8 point Type-II DCT transform.
The output is scaled by a factor of 2 relative to the orthonormal version of
the transform.
_y: The buffer to store the result in.
Data will be placed in every 8th entry (e.g., in a column of an 8x8
block).
_x: The input coefficients.
Only the first 2 entries are used.
The other 6 are assumed to be 0.*/
static void idct8_2(ogg_int16_t *_y,const ogg_int16_t _x[8]){
ogg_int32_t t[8];
ogg_int32_t r;
/*Stage 1:*/
t[0]=OC_C4S4*_x[0]>>16;
t[4]=OC_C7S1*_x[1]>>16;
t[7]=OC_C1S7*_x[1]>>16;
/*Stage 2:*/
t[5]=OC_C4S4*t[4]>>16;
t[6]=OC_C4S4*t[7]>>16;
/*Stage 3:*/
r=t[6]+t[5];
t[5]=t[6]-t[5];
t[6]=r;
/*Stage 4:*/
_y[0<<3]=(ogg_int16_t)(t[0]+t[7]);
_y[1<<3]=(ogg_int16_t)(t[0]+t[6]);
_y[2<<3]=(ogg_int16_t)(t[0]+t[5]);
_y[3<<3]=(ogg_int16_t)(t[0]+t[4]);
_y[4<<3]=(ogg_int16_t)(t[0]-t[4]);
_y[5<<3]=(ogg_int16_t)(t[0]-t[5]);
_y[6<<3]=(ogg_int16_t)(t[0]-t[6]);
_y[7<<3]=(ogg_int16_t)(t[0]-t[7]);
}
/*Performs an inverse 8 point Type-II DCT transform.
The output is scaled by a factor of 2 relative to the orthonormal version of
the transform.
_y: The buffer to store the result in.
Data will be placed in every 8th entry (e.g., in a column of an 8x8
block).
_x: The input coefficients.
Only the first entry is used.
The other 7 are assumed to be 0.*/
static void idct8_1(ogg_int16_t *_y,const ogg_int16_t _x[1]){
_y[0<<3]=_y[1<<3]=_y[2<<3]=_y[3<<3]=
_y[4<<3]=_y[5<<3]=_y[6<<3]=_y[7<<3]=(ogg_int16_t)(OC_C4S4*_x[0]>>16);
}
/*Performs an inverse 8x8 Type-II DCT transform.
The input is assumed to be scaled by a factor of 4 relative to orthonormal
version of the transform.
All coefficients but the first 3 in zig-zag scan order are assumed to be 0:
x x 0 0 0 0 0 0
x 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
_y: The buffer to store the result in.
This may be the same as _x.
_x: The input coefficients.*/
static void oc_idct8x8_3(ogg_int16_t _y[64],const ogg_int16_t _x[64]){
const ogg_int16_t *in;
ogg_int16_t *end;
ogg_int16_t *out;
ogg_int16_t w[64];
/*Transform rows of x into columns of w.*/
idct8_2(w,_x);
idct8_1(w+1,_x+8);
/*Transform rows of w into columns of y.*/
for(in=w,out=_y,end=out+8;out<end;in+=8,out++)idct8_2(out,in);
/*Adjust for the scale factor.*/
for(out=_y,end=out+64;out<end;out++)*out=(ogg_int16_t)(*out+8>>4);
}
/*Performs an inverse 8x8 Type-II DCT transform.
The input is assumed to be scaled by a factor of 4 relative to orthonormal
version of the transform.
All coefficients but the first 10 in zig-zag scan order are assumed to be 0:
x x x x 0 0 0 0
x x x 0 0 0 0 0
x x 0 0 0 0 0 0
x 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
_y: The buffer to store the result in.
This may be the same as _x.
_x: The input coefficients.*/
static void oc_idct8x8_10(ogg_int16_t _y[64],const ogg_int16_t _x[64]){
const ogg_int16_t *in;
ogg_int16_t *end;
ogg_int16_t *out;
ogg_int16_t w[64];
/*Transform rows of x into columns of w.*/
idct8_4(w,_x);
idct8_3(w+1,_x+8);
idct8_2(w+2,_x+16);
idct8_1(w+3,_x+24);
/*Transform rows of w into columns of y.*/
for(in=w,out=_y,end=out+8;out<end;in+=8,out++)idct8_4(out,in);
/*Adjust for the scale factor.*/
for(out=_y,end=out+64;out<end;out++)*out=(ogg_int16_t)(*out+8>>4);
}
/*Performs an inverse 8x8 Type-II DCT transform.
The input is assumed to be scaled by a factor of 4 relative to orthonormal
version of the transform.
_y: The buffer to store the result in.
This may be the same as _x.
_x: The input coefficients.*/
static void oc_idct8x8_slow(ogg_int16_t _y[64],const ogg_int16_t _x[64]){
const ogg_int16_t *in;
ogg_int16_t *end;
ogg_int16_t *out;
ogg_int16_t w[64];
/*Transform rows of x into columns of w.*/
for(in=_x,out=w,end=out+8;out<end;in+=8,out++)idct8(out,in);
/*Transform rows of w into columns of y.*/
for(in=w,out=_y,end=out+8;out<end;in+=8,out++)idct8(out,in);
/*Adjust for the scale factor.*/
for(out=_y,end=out+64;out<end;out++)*out=(ogg_int16_t)(*out+8>>4);
}
void oc_idct8x8(const oc_theora_state *_state,ogg_int16_t _y[64],
int _last_zzi){
(*_state->opt_vtable.idct8x8)(_y,_last_zzi);
}
/*Performs an inverse 8x8 Type-II DCT transform.
The input is assumed to be scaled by a factor of 4 relative to orthonormal
version of the transform.*/
void oc_idct8x8_c(ogg_int16_t _y[64],int _last_zzi){
/*_last_zzi is subtly different from an actual count of the number of
coefficients we decoded for this block.
It contains the value of zzi BEFORE the final token in the block was
decoded.
In most cases this is an EOB token (the continuation of an EOB run from a
previous block counts), and so this is the same as the coefficient count.
However, in the case that the last token was NOT an EOB token, but filled
the block up with exactly 64 coefficients, _last_zzi will be less than 64.
Provided the last token was not a pure zero run, the minimum value it can
be is 46, and so that doesn't affect any of the cases in this routine.
However, if the last token WAS a pure zero run of length 63, then _last_zzi
will be 1 while the number of coefficients decoded is 64.
Thus, we will trigger the following special case, where the real
coefficient count would not.
Note also that a zero run of length 64 will give _last_zzi a value of 0,
but we still process the DC coefficient, which might have a non-zero value
due to DC prediction.
Although convoluted, this is arguably the correct behavior: it allows us to
use a smaller transform when the block ends with a long zero run instead
of a normal EOB token.
It could be smarter... multiple separate zero runs at the end of a block
will fool it, but an encoder that generates these really deserves what it
gets.
Needless to say we inherited this approach from VP3.*/
/*Then perform the iDCT.*/
if(_last_zzi<3)oc_idct8x8_3(_y,_y);
else if(_last_zzi<10)oc_idct8x8_10(_y,_y);
else oc_idct8x8_slow(_y,_y);
}

View File

@@ -0,0 +1,131 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: info.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "internal.h"
/*This is more or less the same as strncasecmp, but that doesn't exist
everywhere, and this is a fairly trivial function, so we include it.
Note: We take advantage of the fact that we know _n is less than or equal to
the length of at least one of the strings.*/
static int oc_tagcompare(const char *_s1,const char *_s2,int _n){
int c;
for(c=0;c<_n;c++){
if(toupper(_s1[c])!=toupper(_s2[c]))return !0;
}
return _s1[c]!='=';
}
void th_info_init(th_info *_info){
memset(_info,0,sizeof(*_info));
_info->version_major=TH_VERSION_MAJOR;
_info->version_minor=TH_VERSION_MINOR;
_info->version_subminor=TH_VERSION_SUB;
_info->keyframe_granule_shift=6;
}
void th_info_clear(th_info *_info){
memset(_info,0,sizeof(*_info));
}
void th_comment_init(th_comment *_tc){
memset(_tc,0,sizeof(*_tc));
}
void th_comment_add(th_comment *_tc,char *_comment){
char **user_comments;
int *comment_lengths;
int comment_len;
user_comments=_ogg_realloc(_tc->user_comments,
(_tc->comments+2)*sizeof(*_tc->user_comments));
if(user_comments==NULL)return;
_tc->user_comments=user_comments;
comment_lengths=_ogg_realloc(_tc->comment_lengths,
(_tc->comments+2)*sizeof(*_tc->comment_lengths));
if(comment_lengths==NULL)return;
_tc->comment_lengths=comment_lengths;
comment_len=strlen(_comment);
comment_lengths[_tc->comments]=comment_len;
user_comments[_tc->comments]=_ogg_malloc(comment_len+1);
if(user_comments[_tc->comments]==NULL)return;
memcpy(_tc->user_comments[_tc->comments],_comment,comment_len+1);
_tc->comments++;
_tc->user_comments[_tc->comments]=NULL;
}
void th_comment_add_tag(th_comment *_tc,char *_tag,char *_val){
char *comment;
int tag_len;
int val_len;
tag_len=strlen(_tag);
val_len=strlen(_val);
/*+2 for '=' and '\0'.*/
comment=_ogg_malloc(tag_len+val_len+2);
if(comment==NULL)return;
memcpy(comment,_tag,tag_len);
comment[tag_len]='=';
memcpy(comment+tag_len+1,_val,val_len+1);
th_comment_add(_tc,comment);
_ogg_free(comment);
}
char *th_comment_query(th_comment *_tc,char *_tag,int _count){
long i;
int found;
int tag_len;
tag_len=strlen(_tag);
found=0;
for(i=0;i<_tc->comments;i++){
if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len)){
/*We return a pointer to the data, not a copy.*/
if(_count==found++)return _tc->user_comments[i]+tag_len+1;
}
}
/*Didn't find anything.*/
return NULL;
}
int th_comment_query_count(th_comment *_tc,char *_tag){
long i;
int tag_len;
int count;
tag_len=strlen(_tag);
count=0;
for(i=0;i<_tc->comments;i++){
if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len))count++;
}
return count;
}
void th_comment_clear(th_comment *_tc){
if(_tc!=NULL){
long i;
for(i=0;i<_tc->comments;i++)_ogg_free(_tc->user_comments[i]);
_ogg_free(_tc->user_comments);
_ogg_free(_tc->comment_lengths);
_ogg_free(_tc->vendor);
memset(_tc,0,sizeof(*_tc));
}
}

View File

@@ -0,0 +1,262 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: internal.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include "internal.h"
/*A map from the index in the zig zag scan to the coefficient number in a
block.
All zig zag indices beyond 63 are sent to coefficient 64, so that zero runs
past the end of a block in bogus streams get mapped to a known location.*/
const unsigned char OC_FZIG_ZAG[128]={
0, 1, 8,16, 9, 2, 3,10,
17,24,32,25,18,11, 4, 5,
12,19,26,33,40,48,41,34,
27,20,13, 6, 7,14,21,28,
35,42,49,56,57,50,43,36,
29,22,15,23,30,37,44,51,
58,59,52,45,38,31,39,46,
53,60,61,54,47,55,62,63,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64
};
/*A map from the coefficient number in a block to its index in the zig zag
scan.*/
const unsigned char OC_IZIG_ZAG[64]={
0, 1, 5, 6,14,15,27,28,
2, 4, 7,13,16,26,29,42,
3, 8,12,17,25,30,41,43,
9,11,18,24,31,40,44,53,
10,19,23,32,39,45,52,54,
20,22,33,38,46,51,55,60,
21,34,37,47,50,56,59,61,
35,36,48,49,57,58,62,63
};
/*A map from physical macro block ordering to bitstream macro block
ordering within a super block.*/
const unsigned char OC_MB_MAP[2][2]={{0,3},{1,2}};
/*A list of the indices in the oc_mb.map array that can be valid for each of
the various chroma decimation types.*/
const unsigned char OC_MB_MAP_IDXS[TH_PF_NFORMATS][12]={
{0,1,2,3,4,8},
{0,1,2,3,4,5,8,9},
{0,1,2,3,4,6,8,10},
{0,1,2,3,4,5,6,7,8,9,10,11}
};
/*The number of indices in the oc_mb.map array that can be valid for each of
the various chroma decimation types.*/
const unsigned char OC_MB_MAP_NIDXS[TH_PF_NFORMATS]={6,8,8,12};
/*The number of extra bits that are coded with each of the DCT tokens.
Each DCT token has some fixed number of additional bits (possibly 0) stored
after the token itself, containing, for example, coefficient magnitude,
sign bits, etc.*/
const unsigned char OC_DCT_TOKEN_EXTRA_BITS[TH_NDCT_TOKENS]={
0,0,0,2,3,4,12,3,6,
0,0,0,0,
1,1,1,1,2,3,4,5,6,10,
1,1,1,1,1,3,4,
2,3
};
int oc_ilog(unsigned _v){
int ret;
for(ret=0;_v;ret++)_v>>=1;
return ret;
}
/*The function used to fill in the chroma plane motion vectors for a macro
block when 4 different motion vectors are specified in the luma plane.
This version is for use with chroma decimated in the X and Y directions
(4:2:0).
_cbmvs: The chroma block-level motion vectors to fill in.
_lbmvs: The luma block-level motion vectors.*/
static void oc_set_chroma_mvs00(oc_mv _cbmvs[4],const oc_mv _lbmvs[4]){
int dx;
int dy;
dx=_lbmvs[0][0]+_lbmvs[1][0]+_lbmvs[2][0]+_lbmvs[3][0];
dy=_lbmvs[0][1]+_lbmvs[1][1]+_lbmvs[2][1]+_lbmvs[3][1];
_cbmvs[0][0]=(signed char)OC_DIV_ROUND_POW2(dx,2,2);
_cbmvs[0][1]=(signed char)OC_DIV_ROUND_POW2(dy,2,2);
}
/*The function used to fill in the chroma plane motion vectors for a macro
block when 4 different motion vectors are specified in the luma plane.
This version is for use with chroma decimated in the Y direction.
_cbmvs: The chroma block-level motion vectors to fill in.
_lbmvs: The luma block-level motion vectors.*/
static void oc_set_chroma_mvs01(oc_mv _cbmvs[4],const oc_mv _lbmvs[4]){
int dx;
int dy;
dx=_lbmvs[0][0]+_lbmvs[2][0];
dy=_lbmvs[0][1]+_lbmvs[2][1];
_cbmvs[0][0]=(signed char)OC_DIV_ROUND_POW2(dx,1,1);
_cbmvs[0][1]=(signed char)OC_DIV_ROUND_POW2(dy,1,1);
dx=_lbmvs[1][0]+_lbmvs[3][0];
dy=_lbmvs[1][1]+_lbmvs[3][1];
_cbmvs[1][0]=(signed char)OC_DIV_ROUND_POW2(dx,1,1);
_cbmvs[1][1]=(signed char)OC_DIV_ROUND_POW2(dy,1,1);
}
/*The function used to fill in the chroma plane motion vectors for a macro
block when 4 different motion vectors are specified in the luma plane.
This version is for use with chroma decimated in the X direction (4:2:2).
_cbmvs: The chroma block-level motion vectors to fill in.
_lbmvs: The luma block-level motion vectors.*/
static void oc_set_chroma_mvs10(oc_mv _cbmvs[4],const oc_mv _lbmvs[4]){
int dx;
int dy;
dx=_lbmvs[0][0]+_lbmvs[1][0];
dy=_lbmvs[0][1]+_lbmvs[1][1];
_cbmvs[0][0]=(signed char)OC_DIV_ROUND_POW2(dx,1,1);
_cbmvs[0][1]=(signed char)OC_DIV_ROUND_POW2(dy,1,1);
dx=_lbmvs[2][0]+_lbmvs[3][0];
dy=_lbmvs[2][1]+_lbmvs[3][1];
_cbmvs[2][0]=(signed char)OC_DIV_ROUND_POW2(dx,1,1);
_cbmvs[2][1]=(signed char)OC_DIV_ROUND_POW2(dy,1,1);
}
/*The function used to fill in the chroma plane motion vectors for a macro
block when 4 different motion vectors are specified in the luma plane.
This version is for use with no chroma decimation (4:4:4).
_cbmvs: The chroma block-level motion vectors to fill in.
_lmbmv: The luma macro-block level motion vector to fill in for use in
prediction.
_lbmvs: The luma block-level motion vectors.*/
static void oc_set_chroma_mvs11(oc_mv _cbmvs[4],const oc_mv _lbmvs[4]){
memcpy(_cbmvs,_lbmvs,4*sizeof(_lbmvs[0]));
}
/*A table of functions used to fill in the chroma plane motion vectors for a
macro block when 4 different motion vectors are specified in the luma
plane.*/
const oc_set_chroma_mvs_func OC_SET_CHROMA_MVS_TABLE[TH_PF_NFORMATS]={
(oc_set_chroma_mvs_func)oc_set_chroma_mvs00,
(oc_set_chroma_mvs_func)oc_set_chroma_mvs01,
(oc_set_chroma_mvs_func)oc_set_chroma_mvs10,
(oc_set_chroma_mvs_func)oc_set_chroma_mvs11
};
void **oc_malloc_2d(size_t _height,size_t _width,size_t _sz){
size_t rowsz;
size_t colsz;
size_t datsz;
char *ret;
colsz=_height*sizeof(void *);
rowsz=_sz*_width;
datsz=rowsz*_height;
/*Alloc array and row pointers.*/
ret=(char *)_ogg_malloc(datsz+colsz);
if(ret==NULL)return NULL;
/*Initialize the array.*/
if(ret!=NULL){
size_t i;
void **p;
char *datptr;
p=(void **)ret;
i=_height;
for(datptr=ret+colsz;i-->0;p++,datptr+=rowsz)*p=(void *)datptr;
}
return (void **)ret;
}
void **oc_calloc_2d(size_t _height,size_t _width,size_t _sz){
size_t colsz;
size_t rowsz;
size_t datsz;
char *ret;
colsz=_height*sizeof(void *);
rowsz=_sz*_width;
datsz=rowsz*_height;
/*Alloc array and row pointers.*/
ret=(char *)_ogg_calloc(datsz+colsz,1);
if(ret==NULL)return NULL;
/*Initialize the array.*/
if(ret!=NULL){
size_t i;
void **p;
char *datptr;
p=(void **)ret;
i=_height;
for(datptr=ret+colsz;i-->0;p++,datptr+=rowsz)*p=(void *)datptr;
}
return (void **)ret;
}
void oc_free_2d(void *_ptr){
_ogg_free(_ptr);
}
/*Fills in a Y'CbCr buffer with a pointer to the image data in the first
buffer, but with the opposite vertical orientation.
_dst: The destination buffer.
This can be the same as _src.
_src: The source buffer.*/
void oc_ycbcr_buffer_flip(th_ycbcr_buffer _dst,
const th_ycbcr_buffer _src){
int pli;
for(pli=0;pli<3;pli++){
_dst[pli].width=_src[pli].width;
_dst[pli].height=_src[pli].height;
_dst[pli].stride=-_src[pli].stride;
_dst[pli].data=_src[pli].data
+(1-_dst[pli].height)*(ptrdiff_t)_dst[pli].stride;
}
}
const char *th_version_string(void){
return OC_VENDOR_STRING;
}
ogg_uint32_t th_version_number(void){
return (TH_VERSION_MAJOR<<16)+(TH_VERSION_MINOR<<8)+TH_VERSION_SUB;
}
/*Determines the packet type.
Note that this correctly interprets a 0-byte packet as a video data packet.
Return: 1 for a header packet, 0 for a data packet.*/
int th_packet_isheader(ogg_packet *_op){
return _op->bytes>0?_op->packet[0]>>7:0;
}
/*Determines the frame type of a video data packet.
Note that this correctly interprets a 0-byte packet as a delta frame.
Return: 1 for a key frame, 0 for a delta frame, and -1 for a header
packet.*/
int th_packet_iskeyframe(ogg_packet *_op){
return _op->bytes<=0?0:_op->packet[0]&0x80?-1:!(_op->packet[0]&0x40);
}

View File

@@ -0,0 +1,509 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: internal.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_internal_H)
# define _internal_H (1)
# include <stdlib.h>
# include <limits.h>
# if defined(HAVE_CONFIG_H)
# include <config.h>
# endif
# include "theora/codec.h"
# include "theora/theora.h"
# if defined(_MSC_VER)
/*Disable missing EMMS warnings.*/
# pragma warning(disable:4799)
/*Thank you Microsoft, I know the order of operations.*/
# pragma warning(disable:4554)
# endif
/*You, too, gcc.*/
# if defined(__GNUC_PREREQ)
# if __GNUC_PREREQ(4,2)
# pragma GCC diagnostic ignored "-Wparentheses"
# endif
# endif
# include "ocintrin.h"
# include "huffman.h"
# include "quant.h"
/*Some assembly constructs require aligned operands.*/
# if defined(OC_X86_ASM)
# if defined(__GNUC__)
# define OC_ALIGN8(expr) expr __attribute__((aligned(8)))
# define OC_ALIGN16(expr) expr __attribute__((aligned(16)))
# elif defined(_MSC_VER)
# define OC_ALIGN8(expr) __declspec (align(8)) expr
# define OC_ALIGN16(expr) __declspec (align(16)) expr
# endif
# endif
# if !defined(OC_ALIGN8)
# define OC_ALIGN8(expr) expr
# endif
# if !defined(OC_ALIGN16)
# define OC_ALIGN16(expr) expr
# endif
typedef struct oc_sb_flags oc_sb_flags;
typedef struct oc_border_info oc_border_info;
typedef struct oc_fragment oc_fragment;
typedef struct oc_fragment_plane oc_fragment_plane;
typedef struct oc_base_opt_vtable oc_base_opt_vtable;
typedef struct oc_base_opt_data oc_base_opt_data;
typedef struct oc_state_dispatch_vtable oc_state_dispatch_vtable;
typedef struct oc_theora_state oc_theora_state;
/*This library's version.*/
# define OC_VENDOR_STRING "Xiph.Org libtheora 1.1 20090822 (Thusnelda)"
/*Theora bitstream version.*/
# define TH_VERSION_MAJOR (3)
# define TH_VERSION_MINOR (2)
# define TH_VERSION_SUB (1)
# define TH_VERSION_CHECK(_info,_maj,_min,_sub) \
((_info)->version_major>(_maj)||(_info)->version_major==(_maj)&& \
((_info)->version_minor>(_min)||(_info)->version_minor==(_min)&& \
(_info)->version_subminor>=(_sub)))
/*A keyframe.*/
#define OC_INTRA_FRAME (0)
/*A predicted frame.*/
#define OC_INTER_FRAME (1)
/*A frame of unknown type (frame type decision has not yet been made).*/
#define OC_UNKWN_FRAME (-1)
/*The amount of padding to add to the reconstructed frame buffers on all
sides.
This is used to allow unrestricted motion vectors without special casing.
This must be a multiple of 2.*/
#define OC_UMV_PADDING (16)
/*Frame classification indices.*/
/*The previous golden frame.*/
#define OC_FRAME_GOLD (0)
/*The previous frame.*/
#define OC_FRAME_PREV (1)
/*The current frame.*/
#define OC_FRAME_SELF (2)
/*The input or output buffer.*/
#define OC_FRAME_IO (3)
/*Macroblock modes.*/
/*Macro block is invalid: It is never coded.*/
#define OC_MODE_INVALID (-1)
/*Encoded difference from the same macro block in the previous frame.*/
#define OC_MODE_INTER_NOMV (0)
/*Encoded with no motion compensated prediction.*/
#define OC_MODE_INTRA (1)
/*Encoded difference from the previous frame offset by the given motion
vector.*/
#define OC_MODE_INTER_MV (2)
/*Encoded difference from the previous frame offset by the last coded motion
vector.*/
#define OC_MODE_INTER_MV_LAST (3)
/*Encoded difference from the previous frame offset by the second to last
coded motion vector.*/
#define OC_MODE_INTER_MV_LAST2 (4)
/*Encoded difference from the same macro block in the previous golden
frame.*/
#define OC_MODE_GOLDEN_NOMV (5)
/*Encoded difference from the previous golden frame offset by the given motion
vector.*/
#define OC_MODE_GOLDEN_MV (6)
/*Encoded difference from the previous frame offset by the individual motion
vectors given for each block.*/
#define OC_MODE_INTER_MV_FOUR (7)
/*The number of (coded) modes.*/
#define OC_NMODES (8)
/*Determines the reference frame used for a given MB mode.*/
#define OC_FRAME_FOR_MODE(_x) \
OC_UNIBBLE_TABLE32(OC_FRAME_PREV,OC_FRAME_SELF,OC_FRAME_PREV,OC_FRAME_PREV, \
OC_FRAME_PREV,OC_FRAME_GOLD,OC_FRAME_GOLD,OC_FRAME_PREV,(_x))
/*Constants for the packet state machine common between encoder and decoder.*/
/*Next packet to emit/read: Codec info header.*/
#define OC_PACKET_INFO_HDR (-3)
/*Next packet to emit/read: Comment header.*/
#define OC_PACKET_COMMENT_HDR (-2)
/*Next packet to emit/read: Codec setup header.*/
#define OC_PACKET_SETUP_HDR (-1)
/*No more packets to emit/read.*/
#define OC_PACKET_DONE (INT_MAX)
/*Super blocks are 32x32 segments of pixels in a single color plane indexed
in image order.
Internally, super blocks are broken up into four quadrants, each of which
contains a 2x2 pattern of blocks, each of which is an 8x8 block of pixels.
Quadrants, and the blocks within them, are indexed in a special order called
a "Hilbert curve" within the super block.
In order to differentiate between the Hilbert-curve indexing strategy and
the regular image order indexing strategy, blocks indexed in image order
are called "fragments".
Fragments are indexed in image order, left to right, then bottom to top,
from Y' plane to Cb plane to Cr plane.
The co-located fragments in all image planes corresponding to the location
of a single quadrant of a luma plane super block form a macro block.
Thus there is only a single set of macro blocks for all planes, each of which
contains between 6 and 12 fragments, depending on the pixel format.
Therefore macro block information is kept in a separate set of arrays from
super blocks to avoid unused space in the other planes.
The lists are indexed in super block order.
That is, the macro block corresponding to the macro block mbi in (luma plane)
super block sbi is at index (sbi<<2|mbi).
Thus the number of macro blocks in each dimension is always twice the number
of super blocks, even when only an odd number fall inside the coded frame.
These "extra" macro blocks are just an artifact of our internal data layout,
and not part of the coded stream; they are flagged with a negative MB mode.*/
/*A single quadrant of the map from a super block to fragment numbers.*/
typedef ptrdiff_t oc_sb_map_quad[4];
/*A map from a super block to fragment numbers.*/
typedef oc_sb_map_quad oc_sb_map[4];
/*A single plane of the map from a macro block to fragment numbers.*/
typedef ptrdiff_t oc_mb_map_plane[4];
/*A map from a macro block to fragment numbers.*/
typedef oc_mb_map_plane oc_mb_map[3];
/*A motion vector.*/
typedef signed char oc_mv[2];
/*Super block information.*/
struct oc_sb_flags{
unsigned char coded_fully:1;
unsigned char coded_partially:1;
unsigned char quad_valid:4;
};
/*Information about a fragment which intersects the border of the displayable
region.
This marks which pixels belong to the displayable region.*/
struct oc_border_info{
/*A bit mask marking which pixels are in the displayable region.
Pixel (x,y) corresponds to bit (y<<3|x).*/
ogg_int64_t mask;
/*The number of pixels in the displayable region.
This is always positive, and always less than 64.*/
int npixels;
};
/*Fragment information.*/
struct oc_fragment{
/*A flag indicating whether or not this fragment is coded.*/
unsigned coded:1;
/*A flag indicating that this entire fragment lies outside the displayable
region of the frame.
Note the contrast with an invalid macro block, which is outside the coded
frame, not just the displayable one.
There are no fragments outside the coded frame by construction.*/
unsigned invalid:1;
/*The index of the quality index used for this fragment's AC coefficients.*/
unsigned qii:6;
/*The mode of the macroblock this fragment belongs to.*/
unsigned mb_mode:3;
/*The index of the associated border information for fragments which lie
partially outside the displayable region.
For fragments completely inside or outside this region, this is -1.
Note that the C standard requires an explicit signed keyword for bitfield
types, since some compilers may treat them as unsigned without it.*/
signed int borderi:5;
/*The prediction-corrected DC component.
Note that the C standard requires an explicit signed keyword for bitfield
types, since some compilers may treat them as unsigned without it.*/
signed int dc:16;
};
/*A description of each fragment plane.*/
struct oc_fragment_plane{
/*The number of fragments in the horizontal direction.*/
int nhfrags;
/*The number of fragments in the vertical direction.*/
int nvfrags;
/*The offset of the first fragment in the plane.*/
ptrdiff_t froffset;
/*The total number of fragments in the plane.*/
ptrdiff_t nfrags;
/*The number of super blocks in the horizontal direction.*/
unsigned nhsbs;
/*The number of super blocks in the vertical direction.*/
unsigned nvsbs;
/*The offset of the first super block in the plane.*/
unsigned sboffset;
/*The total number of super blocks in the plane.*/
unsigned nsbs;
};
/*The shared (encoder and decoder) functions that have accelerated variants.*/
struct oc_base_opt_vtable{
void (*frag_copy)(unsigned char *_dst,
const unsigned char *_src,int _ystride);
void (*frag_recon_intra)(unsigned char *_dst,int _ystride,
const ogg_int16_t _residue[64]);
void (*frag_recon_inter)(unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]);
void (*frag_recon_inter2)(unsigned char *_dst,const unsigned char *_src1,
const unsigned char *_src2,int _ystride,const ogg_int16_t _residue[64]);
void (*idct8x8)(ogg_int16_t _y[64],int _last_zzi);
void (*state_frag_recon)(const oc_theora_state *_state,ptrdiff_t _fragi,
int _pli,ogg_int16_t _dct_coeffs[64],int _last_zzi,ogg_uint16_t _dc_quant);
void (*state_frag_copy_list)(const oc_theora_state *_state,
const ptrdiff_t *_fragis,ptrdiff_t _nfragis,
int _dst_frame,int _src_frame,int _pli);
void (*state_loop_filter_frag_rows)(const oc_theora_state *_state,
int _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end);
void (*restore_fpu)(void);
};
/*The shared (encoder and decoder) tables that vary according to which variants
of the above functions are used.*/
struct oc_base_opt_data{
const unsigned char *dct_fzig_zag;
};
/*State information common to both the encoder and decoder.*/
struct oc_theora_state{
/*The stream information.*/
th_info info;
/*Table for shared accelerated functions.*/
oc_base_opt_vtable opt_vtable;
/*Table for shared data used by accelerated functions.*/
oc_base_opt_data opt_data;
/*CPU flags to detect the presence of extended instruction sets.*/
ogg_uint32_t cpu_flags;
/*The fragment plane descriptions.*/
oc_fragment_plane fplanes[3];
/*The list of fragments, indexed in image order.*/
oc_fragment *frags;
/*The the offset into the reference frame buffer to the upper-left pixel of
each fragment.*/
ptrdiff_t *frag_buf_offs;
/*The motion vector for each fragment.*/
oc_mv *frag_mvs;
/*The total number of fragments in a single frame.*/
ptrdiff_t nfrags;
/*The list of super block maps, indexed in image order.*/
oc_sb_map *sb_maps;
/*The list of super block flags, indexed in image order.*/
oc_sb_flags *sb_flags;
/*The total number of super blocks in a single frame.*/
unsigned nsbs;
/*The fragments from each color plane that belong to each macro block.
Fragments are stored in image order (left to right then top to bottom).
When chroma components are decimated, the extra fragments have an index of
-1.*/
oc_mb_map *mb_maps;
/*The list of macro block modes.
A negative number indicates the macro block lies entirely outside the
coded frame.*/
signed char *mb_modes;
/*The number of macro blocks in the X direction.*/
unsigned nhmbs;
/*The number of macro blocks in the Y direction.*/
unsigned nvmbs;
/*The total number of macro blocks.*/
size_t nmbs;
/*The list of coded fragments, in coded order.
Uncoded fragments are stored in reverse order from the end of the list.*/
ptrdiff_t *coded_fragis;
/*The number of coded fragments in each plane.*/
ptrdiff_t ncoded_fragis[3];
/*The total number of coded fragments.*/
ptrdiff_t ntotal_coded_fragis;
/*The index of the buffers being used for each OC_FRAME_* reference frame.*/
int ref_frame_idx[4];
/*The actual buffers used for the previously decoded frames.*/
th_ycbcr_buffer ref_frame_bufs[4];
/*The storage for the reference frame buffers.*/
unsigned char *ref_frame_data[4];
/*The strides for each plane in the reference frames.*/
int ref_ystride[3];
/*The number of unique border patterns.*/
int nborders;
/*The unique border patterns for all border fragments.
The borderi field of fragments which straddle the border indexes this
list.*/
oc_border_info borders[16];
/*The frame number of the last keyframe.*/
ogg_int64_t keyframe_num;
/*The frame number of the current frame.*/
ogg_int64_t curframe_num;
/*The granpos of the current frame.*/
ogg_int64_t granpos;
/*The type of the current frame.*/
unsigned char frame_type;
/*The bias to add to the frame count when computing granule positions.*/
unsigned char granpos_bias;
/*The number of quality indices used in the current frame.*/
unsigned char nqis;
/*The quality indices of the current frame.*/
unsigned char qis[3];
/*The dequantization tables, stored in zig-zag order, and indexed by
qi, pli, qti, and zzi.*/
ogg_uint16_t *dequant_tables[64][3][2];
OC_ALIGN16(oc_quant_table dequant_table_data[64][3][2]);
/*Loop filter strength parameters.*/
unsigned char loop_filter_limits[64];
};
/*The function type used to fill in the chroma plane motion vectors for a
macro block when 4 different motion vectors are specified in the luma
plane.
_cbmvs: The chroma block-level motion vectors to fill in.
_lmbmv: The luma macro-block level motion vector to fill in for use in
prediction.
_lbmvs: The luma block-level motion vectors.*/
typedef void (*oc_set_chroma_mvs_func)(oc_mv _cbmvs[4],const oc_mv _lbmvs[4]);
/*A map from the index in the zig zag scan to the coefficient number in a
block.*/
extern const unsigned char OC_FZIG_ZAG[128];
/*A map from the coefficient number in a block to its index in the zig zag
scan.*/
extern const unsigned char OC_IZIG_ZAG[64];
/*A map from physical macro block ordering to bitstream macro block
ordering within a super block.*/
extern const unsigned char OC_MB_MAP[2][2];
/*A list of the indices in the oc_mb_map array that can be valid for each of
the various chroma decimation types.*/
extern const unsigned char OC_MB_MAP_IDXS[TH_PF_NFORMATS][12];
/*The number of indices in the oc_mb_map array that can be valid for each of
the various chroma decimation types.*/
extern const unsigned char OC_MB_MAP_NIDXS[TH_PF_NFORMATS];
/*A table of functions used to fill in the Cb,Cr plane motion vectors for a
macro block when 4 different motion vectors are specified in the luma
plane.*/
extern const oc_set_chroma_mvs_func OC_SET_CHROMA_MVS_TABLE[TH_PF_NFORMATS];
int oc_ilog(unsigned _v);
void **oc_malloc_2d(size_t _height,size_t _width,size_t _sz);
void **oc_calloc_2d(size_t _height,size_t _width,size_t _sz);
void oc_free_2d(void *_ptr);
void oc_ycbcr_buffer_flip(th_ycbcr_buffer _dst,
const th_ycbcr_buffer _src);
int oc_state_init(oc_theora_state *_state,const th_info *_info,int _nrefs);
void oc_state_clear(oc_theora_state *_state);
void oc_state_vtable_init_c(oc_theora_state *_state);
void oc_state_borders_fill_rows(oc_theora_state *_state,int _refi,int _pli,
int _y0,int _yend);
void oc_state_borders_fill_caps(oc_theora_state *_state,int _refi,int _pli);
void oc_state_borders_fill(oc_theora_state *_state,int _refi);
void oc_state_fill_buffer_ptrs(oc_theora_state *_state,int _buf_idx,
th_ycbcr_buffer _img);
int oc_state_mbi_for_pos(oc_theora_state *_state,int _mbx,int _mby);
int oc_state_get_mv_offsets(const oc_theora_state *_state,int _offsets[2],
int _pli,int _dx,int _dy);
int oc_state_loop_filter_init(oc_theora_state *_state,int *_bv);
void oc_state_loop_filter(oc_theora_state *_state,int _frame);
#if defined(OC_DUMP_IMAGES)
int oc_state_dump_frame(const oc_theora_state *_state,int _frame,
const char *_suf);
#endif
/*Shared accelerated functions.*/
void oc_frag_copy(const oc_theora_state *_state,unsigned char *_dst,
const unsigned char *_src,int _ystride);
void oc_frag_recon_intra(const oc_theora_state *_state,
unsigned char *_dst,int _dst_ystride,const ogg_int16_t _residue[64]);
void oc_frag_recon_inter(const oc_theora_state *_state,unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]);
void oc_frag_recon_inter2(const oc_theora_state *_state,
unsigned char *_dst,const unsigned char *_src1,const unsigned char *_src2,
int _ystride,const ogg_int16_t _residue[64]);
void oc_idct8x8(const oc_theora_state *_state,ogg_int16_t _y[64],int _last_zzi);
void oc_state_frag_recon(const oc_theora_state *_state,ptrdiff_t _fragi,
int _pli,ogg_int16_t _dct_coeffs[64],int _last_zzi,ogg_uint16_t _dc_quant);
void oc_state_frag_copy_list(const oc_theora_state *_state,
const ptrdiff_t *_fragis,ptrdiff_t _nfragis,
int _dst_frame,int _src_frame,int _pli);
void oc_state_loop_filter_frag_rows(const oc_theora_state *_state,
int _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end);
void oc_restore_fpu(const oc_theora_state *_state);
/*Default pure-C implementations.*/
void oc_frag_copy_c(unsigned char *_dst,
const unsigned char *_src,int _src_ystride);
void oc_frag_recon_intra_c(unsigned char *_dst,int _dst_ystride,
const ogg_int16_t _residue[64]);
void oc_frag_recon_inter_c(unsigned char *_dst,
const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]);
void oc_frag_recon_inter2_c(unsigned char *_dst,const unsigned char *_src1,
const unsigned char *_src2,int _ystride,const ogg_int16_t _residue[64]);
void oc_idct8x8_c(ogg_int16_t _y[64],int _last_zzi);
void oc_state_frag_recon_c(const oc_theora_state *_state,ptrdiff_t _fragi,
int _pli,ogg_int16_t _dct_coeffs[64],int _last_zzi,ogg_uint16_t _dc_quant);
void oc_state_frag_copy_list_c(const oc_theora_state *_state,
const ptrdiff_t *_fragis,ptrdiff_t _nfragis,
int _dst_frame,int _src_frame,int _pli);
void oc_state_loop_filter_frag_rows_c(const oc_theora_state *_state,
int _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end);
void oc_restore_fpu_c(void);
/*We need a way to call a few encoder functions without introducing a link-time
dependency into the decoder, while still allowing the old alpha API which
does not distinguish between encoder and decoder objects to be used.
We do this by placing a function table at the start of the encoder object
which can dispatch into the encoder library.
We do a similar thing for the decoder in case we ever decide to split off a
common base library.*/
typedef void (*oc_state_clear_func)(theora_state *_th);
typedef int (*oc_state_control_func)(theora_state *th,int _req,
void *_buf,size_t _buf_sz);
typedef ogg_int64_t (*oc_state_granule_frame_func)(theora_state *_th,
ogg_int64_t _granulepos);
typedef double (*oc_state_granule_time_func)(theora_state *_th,
ogg_int64_t _granulepos);
struct oc_state_dispatch_vtable{
oc_state_clear_func clear;
oc_state_control_func control;
oc_state_granule_frame_func granule_frame;
oc_state_granule_time_func granule_time;
};
#endif

View File

@@ -0,0 +1,296 @@
#include "mathops.h"
#include <limits.h>
/*The fastest fallback strategy for platforms with fast multiplication appears
to be based on de Bruijn sequences~\cite{LP98}.
Tests confirmed this to be true even on an ARM11, where it is actually faster
than using the native clz instruction.
Define OC_ILOG_NODEBRUIJN to use a simpler fallback on platforms where
multiplication or table lookups are too expensive.
@UNPUBLISHED{LP98,
author="Charles E. Leiserson and Harald Prokop",
title="Using de {Bruijn} Sequences to Index a 1 in a Computer Word",
month=Jun,
year=1998,
note="\url{http://supertech.csail.mit.edu/papers/debruijn.pdf}"
}*/
#if !defined(OC_ILOG_NODEBRUIJN)&& \
!defined(OC_CLZ32)||!defined(OC_CLZ64)&&LONG_MAX<9223372036854775807LL
static const unsigned char OC_DEBRUIJN_IDX32[32]={
0, 1,28, 2,29,14,24, 3,30,22,20,15,25,17, 4, 8,
31,27,13,23,21,19,16, 7,26,12,18, 6,11, 5,10, 9
};
#endif
int oc_ilog32(ogg_uint32_t _v){
#if defined(OC_CLZ32)
return (OC_CLZ32_OFFS-OC_CLZ32(_v))&-!!_v;
#else
/*On a Pentium M, this branchless version tested as the fastest version without
multiplications on 1,000,000,000 random 32-bit integers, edging out a
similar version with branches, and a 256-entry LUT version.*/
# if defined(OC_ILOG_NODEBRUIJN)
int ret;
int m;
ret=_v>0;
m=(_v>0xFFFFU)<<4;
_v>>=m;
ret|=m;
m=(_v>0xFFU)<<3;
_v>>=m;
ret|=m;
m=(_v>0xFU)<<2;
_v>>=m;
ret|=m;
m=(_v>3)<<1;
_v>>=m;
ret|=m;
ret+=_v>1;
return ret;
/*This de Bruijn sequence version is faster if you have a fast multiplier.*/
# else
int ret;
ret=_v>0;
_v|=_v>>1;
_v|=_v>>2;
_v|=_v>>4;
_v|=_v>>8;
_v|=_v>>16;
_v=(_v>>1)+1;
ret+=OC_DEBRUIJN_IDX32[_v*0x77CB531U>>27&0x1F];
return ret;
# endif
#endif
}
int oc_ilog64(ogg_int64_t _v){
#if defined(OC_CLZ64)
return (OC_CLZ64_OFFS-OC_CLZ64(_v))&-!!_v;
#else
# if defined(OC_ILOG_NODEBRUIJN)
ogg_uint32_t v;
int ret;
int m;
ret=_v>0;
m=(_v>0xFFFFFFFFU)<<5;
v=(ogg_uint32_t)(_v>>m);
ret|=m;
m=(v>0xFFFFU)<<4;
v>>=m;
ret|=m;
m=(v>0xFFU)<<3;
v>>=m;
ret|=m;
m=(v>0xFU)<<2;
v>>=m;
ret|=m;
m=(v>3)<<1;
v>>=m;
ret|=m;
ret+=v>1;
return ret;
# else
/*If we don't have a 64-bit word, split it into two 32-bit halves.*/
# if LONG_MAX<9223372036854775807LL
ogg_uint32_t v;
int ret;
int m;
ret=_v>0;
m=(_v>0xFFFFFFFFU)<<5;
v=(ogg_uint32_t)(_v>>m);
ret|=m;
v|=v>>1;
v|=v>>2;
v|=v>>4;
v|=v>>8;
v|=v>>16;
v=(v>>1)+1;
ret+=OC_DEBRUIJN_IDX32[v*0x77CB531U>>27&0x1F];
return ret;
/*Otherwise do it in one 64-bit operation.*/
# else
static const unsigned char OC_DEBRUIJN_IDX64[64]={
0, 1, 2, 7, 3,13, 8,19, 4,25,14,28, 9,34,20,40,
5,17,26,38,15,46,29,48,10,31,35,54,21,50,41,57,
63, 6,12,18,24,27,33,39,16,37,45,47,30,53,49,56,
62,11,23,32,36,44,52,55,61,22,43,51,60,42,59,58
};
int ret;
ret=_v>0;
_v|=_v>>1;
_v|=_v>>2;
_v|=_v>>4;
_v|=_v>>8;
_v|=_v>>16;
_v|=_v>>32;
_v=(_v>>1)+1;
ret+=OC_DEBRUIJN_IDX64[_v*0x218A392CD3D5DBF>>58&0x3F];
return ret;
# endif
# endif
#endif
}
/*round(2**(62+i)*atanh(2**(-(i+1)))/log(2))*/
static const ogg_int64_t OC_ATANH_LOG2[32]={
0x32B803473F7AD0F4LL,0x2F2A71BD4E25E916LL,0x2E68B244BB93BA06LL,
0x2E39FB9198CE62E4LL,0x2E2E683F68565C8FLL,0x2E2B850BE2077FC1LL,
0x2E2ACC58FE7B78DBLL,0x2E2A9E2DE52FD5F2LL,0x2E2A92A338D53EECLL,
0x2E2A8FC08F5E19B6LL,0x2E2A8F07E51A485ELL,0x2E2A8ED9BA8AF388LL,
0x2E2A8ECE2FE7384ALL,0x2E2A8ECB4D3E4B1ALL,0x2E2A8ECA94940FE8LL,
0x2E2A8ECA6669811DLL,0x2E2A8ECA5ADEDD6ALL,0x2E2A8ECA57FC347ELL,
0x2E2A8ECA57438A43LL,0x2E2A8ECA57155FB4LL,0x2E2A8ECA5709D510LL,
0x2E2A8ECA5706F267LL,0x2E2A8ECA570639BDLL,0x2E2A8ECA57060B92LL,
0x2E2A8ECA57060008LL,0x2E2A8ECA5705FD25LL,0x2E2A8ECA5705FC6CLL,
0x2E2A8ECA5705FC3ELL,0x2E2A8ECA5705FC33LL,0x2E2A8ECA5705FC30LL,
0x2E2A8ECA5705FC2FLL,0x2E2A8ECA5705FC2FLL
};
/*Computes the binary exponential of _z, a log base 2 in Q57 format.*/
ogg_int64_t oc_bexp64(ogg_int64_t _z){
ogg_int64_t w;
ogg_int64_t z;
int ipart;
ipart=(int)(_z>>57);
if(ipart<0)return 0;
if(ipart>=63)return 0x7FFFFFFFFFFFFFFFLL;
z=_z-OC_Q57(ipart);
if(z){
ogg_int64_t mask;
long wlo;
int i;
/*C doesn't give us 64x64->128 muls, so we use CORDIC.
This is not particularly fast, but it's not being used in time-critical
code; it is very accurate.*/
/*z is the fractional part of the log in Q62 format.
We need 1 bit of headroom since the magnitude can get larger than 1
during the iteration, and a sign bit.*/
z<<=5;
/*w is the exponential in Q61 format (since it also needs headroom and can
get as large as 2.0); we could get another bit if we dropped the sign,
but we'll recover that bit later anyway.
Ideally this should start out as
\lim_{n->\infty} 2^{61}/\product_{i=1}^n \sqrt{1-2^{-2i}}
but in order to guarantee convergence we have to repeat iterations 4,
13 (=3*4+1), and 40 (=3*13+1, etc.), so it winds up somewhat larger.*/
w=0x26A3D0E401DD846DLL;
for(i=0;;i++){
mask=-(z<0);
w+=(w>>i+1)+mask^mask;
z-=OC_ATANH_LOG2[i]+mask^mask;
/*Repeat iteration 4.*/
if(i>=3)break;
z<<=1;
}
for(;;i++){
mask=-(z<0);
w+=(w>>i+1)+mask^mask;
z-=OC_ATANH_LOG2[i]+mask^mask;
/*Repeat iteration 13.*/
if(i>=12)break;
z<<=1;
}
for(;i<32;i++){
mask=-(z<0);
w+=(w>>i+1)+mask^mask;
z=z-(OC_ATANH_LOG2[i]+mask^mask)<<1;
}
wlo=0;
/*Skip the remaining iterations unless we really require that much
precision.
We could have bailed out earlier for smaller iparts, but that would
require initializing w from a table, as the limit doesn't converge to
61-bit precision until n=30.*/
if(ipart>30){
/*For these iterations, we just update the low bits, as the high bits
can't possibly be affected.
OC_ATANH_LOG2 has also converged (it actually did so one iteration
earlier, but that's no reason for an extra special case).*/
for(;;i++){
mask=-(z<0);
wlo+=(w>>i)+mask^mask;
z-=OC_ATANH_LOG2[31]+mask^mask;
/*Repeat iteration 40.*/
if(i>=39)break;
z<<=1;
}
for(;i<61;i++){
mask=-(z<0);
wlo+=(w>>i)+mask^mask;
z=z-(OC_ATANH_LOG2[31]+mask^mask)<<1;
}
}
w=(w<<1)+wlo;
}
else w=(ogg_int64_t)1<<62;
if(ipart<62)w=(w>>61-ipart)+1>>1;
return w;
}
/*Computes the binary logarithm of _w, returned in Q57 format.*/
ogg_int64_t oc_blog64(ogg_int64_t _w){
ogg_int64_t z;
int ipart;
if(_w<=0)return -1;
ipart=OC_ILOGNZ_64(_w)-1;
if(ipart>61)_w>>=ipart-61;
else _w<<=61-ipart;
z=0;
if(_w&_w-1){
ogg_int64_t x;
ogg_int64_t y;
ogg_int64_t u;
ogg_int64_t mask;
int i;
/*C doesn't give us 64x64->128 muls, so we use CORDIC.
This is not particularly fast, but it's not being used in time-critical
code; it is very accurate.*/
/*z is the fractional part of the log in Q61 format.*/
/*x and y are the cosh() and sinh(), respectively, in Q61 format.
We are computing z=2*atanh(y/x)=2*atanh((_w-1)/(_w+1)).*/
x=_w+((ogg_int64_t)1<<61);
y=_w-((ogg_int64_t)1<<61);
for(i=0;i<4;i++){
mask=-(y<0);
z+=(OC_ATANH_LOG2[i]>>i)+mask^mask;
u=x>>i+1;
x-=(y>>i+1)+mask^mask;
y-=u+mask^mask;
}
/*Repeat iteration 4.*/
for(i--;i<13;i++){
mask=-(y<0);
z+=(OC_ATANH_LOG2[i]>>i)+mask^mask;
u=x>>i+1;
x-=(y>>i+1)+mask^mask;
y-=u+mask^mask;
}
/*Repeat iteration 13.*/
for(i--;i<32;i++){
mask=-(y<0);
z+=(OC_ATANH_LOG2[i]>>i)+mask^mask;
u=x>>i+1;
x-=(y>>i+1)+mask^mask;
y-=u+mask^mask;
}
/*OC_ATANH_LOG2 has converged.*/
for(;i<40;i++){
mask=-(y<0);
z+=(OC_ATANH_LOG2[31]>>i)+mask^mask;
u=x>>i+1;
x-=(y>>i+1)+mask^mask;
y-=u+mask^mask;
}
/*Repeat iteration 40.*/
for(i--;i<62;i++){
mask=-(y<0);
z+=(OC_ATANH_LOG2[31]>>i)+mask^mask;
u=x>>i+1;
x-=(y>>i+1)+mask^mask;
y-=u+mask^mask;
}
z=z+8>>4;
}
return OC_Q57(ipart)+z;
}

View File

@@ -0,0 +1,141 @@
#if !defined(_mathops_H)
# define _mathops_H (1)
# include <ogg/ogg.h>
# ifdef __GNUC_PREREQ
# if __GNUC_PREREQ(3,4)
# include <limits.h>
/*Note the casts to (int) below: this prevents OC_CLZ{32|64}_OFFS from
"upgrading" the type of an entire expression to an (unsigned) size_t.*/
# if INT_MAX>=2147483647
# define OC_CLZ32_OFFS ((int)sizeof(unsigned)*CHAR_BIT)
# define OC_CLZ32(_x) (__builtin_clz(_x))
# elif LONG_MAX>=2147483647L
# define OC_CLZ32_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
# define OC_CLZ32(_x) (__builtin_clzl(_x))
# endif
# if INT_MAX>=9223372036854775807LL
# define OC_CLZ64_OFFS ((int)sizeof(unsigned)*CHAR_BIT)
# define OC_CLZ64(_x) (__builtin_clz(_x))
# elif LONG_MAX>=9223372036854775807LL
# define OC_CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
# define OC_CLZ64(_x) (__builtin_clzl(_x))
# elif LLONG_MAX>=9223372036854775807LL|| \
__LONG_LONG_MAX__>=9223372036854775807LL
# define OC_CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT)
# define OC_CLZ64(_x) (__builtin_clzll(_x))
# endif
# endif
# endif
/**
* oc_ilog32 - Integer binary logarithm of a 32-bit value.
* @_v: A 32-bit value.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* The OC_ILOG_32() or OC_ILOGNZ_32() macros may be able to use a builtin
* function instead, which should be faster.
*/
int oc_ilog32(ogg_uint32_t _v);
/**
* oc_ilog64 - Integer binary logarithm of a 64-bit value.
* @_v: A 64-bit value.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* The OC_ILOG_64() or OC_ILOGNZ_64() macros may be able to use a builtin
* function instead, which should be faster.
*/
int oc_ilog64(ogg_int64_t _v);
# if defined(OC_CLZ32)
/**
* OC_ILOGNZ_32 - Integer binary logarithm of a non-zero 32-bit value.
* @_v: A non-zero 32-bit value.
* Returns floor(log2(_v))+1.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* If _v is zero, the return value is undefined; use OC_ILOG_32() instead.
*/
# define OC_ILOGNZ_32(_v) (OC_CLZ32_OFFS-OC_CLZ32(_v))
/**
* OC_ILOG_32 - Integer binary logarithm of a 32-bit value.
* @_v: A 32-bit value.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
*/
# define OC_ILOG_32(_v) (OC_ILOGNZ_32(_v)&-!!(_v))
# else
# define OC_ILOGNZ_32(_v) (oc_ilog32(_v))
# define OC_ILOG_32(_v) (oc_ilog32(_v))
# endif
# if defined(CLZ64)
/**
* OC_ILOGNZ_64 - Integer binary logarithm of a non-zero 64-bit value.
* @_v: A non-zero 64-bit value.
* Returns floor(log2(_v))+1.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* If _v is zero, the return value is undefined; use OC_ILOG_64() instead.
*/
# define OC_ILOGNZ_64(_v) (CLZ64_OFFS-CLZ64(_v))
/**
* OC_ILOG_64 - Integer binary logarithm of a 64-bit value.
* @_v: A 64-bit value.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
*/
# define OC_ILOG_64(_v) (OC_ILOGNZ_64(_v)&-!!(_v))
# else
# define OC_ILOGNZ_64(_v) (oc_ilog64(_v))
# define OC_ILOG_64(_v) (oc_ilog64(_v))
# endif
# define OC_STATIC_ILOG0(_v) (!!(_v))
# define OC_STATIC_ILOG1(_v) (((_v)&0x2)?2:OC_STATIC_ILOG0(_v))
# define OC_STATIC_ILOG2(_v) \
(((_v)&0xC)?2+OC_STATIC_ILOG1((_v)>>2):OC_STATIC_ILOG1(_v))
# define OC_STATIC_ILOG3(_v) \
(((_v)&0xF0)?4+OC_STATIC_ILOG2((_v)>>4):OC_STATIC_ILOG2(_v))
# define OC_STATIC_ILOG4(_v) \
(((_v)&0xFF00)?8+OC_STATIC_ILOG3((_v)>>8):OC_STATIC_ILOG3(_v))
# define OC_STATIC_ILOG5(_v) \
(((_v)&0xFFFF0000)?16+OC_STATIC_ILOG4((_v)>>16):OC_STATIC_ILOG4(_v))
# define OC_STATIC_ILOG6(_v) \
(((_v)&0xFFFFFFFF00000000ULL)?32+OC_STATIC_ILOG5((_v)>>32):OC_STATIC_ILOG5(_v))
/**
* OC_STATIC_ILOG_32 - The integer logarithm of an (unsigned, 32-bit) constant.
* @_v: A non-negative 32-bit constant.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* This macro is suitable for evaluation at compile time, but it should not be
* used on values that can change at runtime, as it operates via exhaustive
* search.
*/
# define OC_STATIC_ILOG_32(_v) (OC_STATIC_ILOG5((ogg_uint32_t)(_v)))
/**
* OC_STATIC_ILOG_64 - The integer logarithm of an (unsigned, 64-bit) constant.
* @_v: A non-negative 64-bit constant.
* Returns floor(log2(_v))+1, or 0 if _v==0.
* This is the number of bits that would be required to represent _v in two's
* complement notation with all of the leading zeros stripped.
* This macro is suitable for evaluation at compile time, but it should not be
* used on values that can change at runtime, as it operates via exhaustive
* search.
*/
# define OC_STATIC_ILOG_64(_v) (OC_STATIC_ILOG6((ogg_int64_t)(_v)))
#define OC_Q57(_v) ((ogg_int64_t)(_v)<<57)
ogg_int64_t oc_bexp64(ogg_int64_t _z);
ogg_int64_t oc_blog64(ogg_int64_t _w);
#endif

View File

@@ -0,0 +1,767 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id$
********************************************************************/
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include "encint.h"
typedef struct oc_mcenc_ctx oc_mcenc_ctx;
/*Temporary state used for motion estimation.*/
struct oc_mcenc_ctx{
/*The candidate motion vectors.*/
int candidates[13][2];
/*The start of the Set B candidates.*/
int setb0;
/*The total number of candidates.*/
int ncandidates;
};
/*The maximum Y plane SAD value for accepting the median predictor.*/
#define OC_YSAD_THRESH1 (256)
/*The amount to right shift the minimum error by when inflating it for
computing the second maximum Y plane SAD threshold.*/
#define OC_YSAD_THRESH2_SCALE_BITS (4)
/*The amount to add to the second maximum Y plane threshold when inflating
it.*/
#define OC_YSAD_THRESH2_OFFSET (64)
/*The vector offsets in the X direction for each search site in the square
pattern.*/
static const int OC_SQUARE_DX[9]={-1,0,1,-1,0,1,-1,0,1};
/*The vector offsets in the Y direction for each search site in the square
pattern.*/
static const int OC_SQUARE_DY[9]={-1,-1,-1,0,0,0,1,1,1};
/*The number of sites to search for each boundary condition in the square
pattern.
Bit flags for the boundary conditions are as follows:
1: -16==dx
2: dx==15(.5)
4: -16==dy
8: dy==15(.5)*/
static const int OC_SQUARE_NSITES[11]={8,5,5,0,5,3,3,0,5,3,3};
/*The list of sites to search for each boundary condition in the square
pattern.*/
static const int OC_SQUARE_SITES[11][8]={
/* -15.5<dx<31, -15.5<dy<15(.5)*/
{0,1,2,3,5,6,7,8},
/*-15.5==dx, -15.5<dy<15(.5)*/
{1,2,5,7,8},
/* dx==15(.5), -15.5<dy<15(.5)*/
{0,1,3,6,7},
/*-15.5==dx==15(.5), -15.5<dy<15(.5)*/
{-1},
/* -15.5<dx<15(.5), -15.5==dy*/
{3,5,6,7,8},
/*-15.5==dx, -15.5==dy*/
{5,7,8},
/* dx==15(.5), -15.5==dy*/
{3,6,7},
/*-15.5==dx==15(.5), -15.5==dy*/
{-1},
/*-15.5dx<15(.5), dy==15(.5)*/
{0,1,2,3,5},
/*-15.5==dx, dy==15(.5)*/
{1,2,5},
/* dx==15(.5), dy==15(.5)*/
{0,1,3}
};
static void oc_mcenc_find_candidates(oc_enc_ctx *_enc,oc_mcenc_ctx *_mcenc,
int _accum[2],int _mbi,int _frame){
oc_mb_enc_info *embs;
int a[3][2];
int ncandidates;
unsigned nmbi;
int i;
embs=_enc->mb_info;
/*Skip a position to store the median predictor in.*/
ncandidates=1;
if(embs[_mbi].ncneighbors>0){
/*Fill in the first part of set A: the vectors from adjacent blocks.*/
for(i=0;i<embs[_mbi].ncneighbors;i++){
nmbi=embs[_mbi].cneighbors[i];
_mcenc->candidates[ncandidates][0]=embs[nmbi].analysis_mv[0][_frame][0];
_mcenc->candidates[ncandidates][1]=embs[nmbi].analysis_mv[0][_frame][1];
ncandidates++;
}
}
/*Add a few additional vectors to set A: the vectors used in the previous
frames and the (0,0) vector.*/
_mcenc->candidates[ncandidates][0]=OC_CLAMPI(-31,_accum[0],31);
_mcenc->candidates[ncandidates][1]=OC_CLAMPI(-31,_accum[1],31);
ncandidates++;
_mcenc->candidates[ncandidates][0]=OC_CLAMPI(-31,
embs[_mbi].analysis_mv[1][_frame][0]+_accum[0],31);
_mcenc->candidates[ncandidates][1]=OC_CLAMPI(-31,
embs[_mbi].analysis_mv[1][_frame][1]+_accum[1],31);
ncandidates++;
_mcenc->candidates[ncandidates][0]=0;
_mcenc->candidates[ncandidates][1]=0;
ncandidates++;
/*Use the first three vectors of set A to find our best predictor: their
median.*/
memcpy(a,_mcenc->candidates+1,sizeof(a));
OC_SORT2I(a[0][0],a[1][0]);
OC_SORT2I(a[0][1],a[1][1]);
OC_SORT2I(a[1][0],a[2][0]);
OC_SORT2I(a[1][1],a[2][1]);
OC_SORT2I(a[0][0],a[1][0]);
OC_SORT2I(a[0][1],a[1][1]);
_mcenc->candidates[0][0]=a[1][0];
_mcenc->candidates[0][1]=a[1][1];
/*Fill in set B: accelerated predictors for this and adjacent macro blocks.*/
_mcenc->setb0=ncandidates;
/*The first time through the loop use the current macro block.*/
nmbi=_mbi;
for(i=0;;i++){
_mcenc->candidates[ncandidates][0]=OC_CLAMPI(-31,
2*embs[_mbi].analysis_mv[1][_frame][0]
-embs[_mbi].analysis_mv[2][_frame][0]+_accum[0],31);
_mcenc->candidates[ncandidates][1]=OC_CLAMPI(-31,
2*embs[_mbi].analysis_mv[1][_frame][1]
-embs[_mbi].analysis_mv[2][_frame][1]+_accum[1],31);
ncandidates++;
if(i>=embs[_mbi].npneighbors)break;
nmbi=embs[_mbi].pneighbors[i];
}
/*Truncate to full-pel positions.*/
for(i=0;i<ncandidates;i++){
_mcenc->candidates[i][0]=OC_DIV2(_mcenc->candidates[i][0]);
_mcenc->candidates[i][1]=OC_DIV2(_mcenc->candidates[i][1]);
}
_mcenc->ncandidates=ncandidates;
}
#if 0
static unsigned oc_sad16_halfpel(const oc_enc_ctx *_enc,
const ptrdiff_t *_frag_buf_offs,const ptrdiff_t _fragis[4],
int _mvoffset0,int _mvoffset1,const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _best_err){
unsigned err;
int bi;
err=0;
for(bi=0;bi<4;bi++){
ptrdiff_t frag_offs;
frag_offs=_frag_buf_offs[_fragis[bi]];
err+=oc_enc_frag_sad2_thresh(_enc,_src+frag_offs,_ref+frag_offs+_mvoffset0,
_ref+frag_offs+_mvoffset1,_ystride,_best_err-err);
}
return err;
}
#endif
static unsigned oc_satd16_halfpel(const oc_enc_ctx *_enc,
const ptrdiff_t *_frag_buf_offs,const ptrdiff_t _fragis[4],
int _mvoffset0,int _mvoffset1,const unsigned char *_src,
const unsigned char *_ref,int _ystride,unsigned _best_err){
unsigned err;
int bi;
err=0;
for(bi=0;bi<4;bi++){
ptrdiff_t frag_offs;
frag_offs=_frag_buf_offs[_fragis[bi]];
err+=oc_enc_frag_satd2_thresh(_enc,_src+frag_offs,_ref+frag_offs+_mvoffset0,
_ref+frag_offs+_mvoffset1,_ystride,_best_err-err);
}
return err;
}
static unsigned oc_mcenc_ysad_check_mbcandidate_fullpel(const oc_enc_ctx *_enc,
const ptrdiff_t *_frag_buf_offs,const ptrdiff_t _fragis[4],int _dx,int _dy,
const unsigned char *_src,const unsigned char *_ref,int _ystride,
unsigned _block_err[4]){
unsigned err;
int mvoffset;
int bi;
mvoffset=_dx+_dy*_ystride;
err=0;
for(bi=0;bi<4;bi++){
ptrdiff_t frag_offs;
unsigned block_err;
frag_offs=_frag_buf_offs[_fragis[bi]];
block_err=oc_enc_frag_sad(_enc,
_src+frag_offs,_ref+frag_offs+mvoffset,_ystride);
_block_err[bi]=block_err;
err+=block_err;
}
return err;
}
static int oc_mcenc_ysatd_check_mbcandidate_fullpel(const oc_enc_ctx *_enc,
const ptrdiff_t *_frag_buf_offs,const ptrdiff_t _fragis[4],int _dx,int _dy,
const unsigned char *_src,const unsigned char *_ref,int _ystride){
int mvoffset;
int err;
int bi;
mvoffset=_dx+_dy*_ystride;
err=0;
for(bi=0;bi<4;bi++){
ptrdiff_t frag_offs;
frag_offs=_frag_buf_offs[_fragis[bi]];
err+=oc_enc_frag_satd_thresh(_enc,
_src+frag_offs,_ref+frag_offs+mvoffset,_ystride,UINT_MAX);
}
return err;
}
static unsigned oc_mcenc_ysatd_check_bcandidate_fullpel(const oc_enc_ctx *_enc,
ptrdiff_t _frag_offs,int _dx,int _dy,
const unsigned char *_src,const unsigned char *_ref,int _ystride){
return oc_enc_frag_satd_thresh(_enc,
_src+_frag_offs,_ref+_frag_offs+_dx+_dy*_ystride,_ystride,UINT_MAX);
}
/*Perform a motion vector search for this macro block against a single
reference frame.
As a bonus, individual block motion vectors are computed as well, as much of
the work can be shared.
The actual motion vector is stored in the appropriate place in the
oc_mb_enc_info structure.
_mcenc: The motion compensation context.
_accum: Drop frame/golden MV accumulators.
_mbi: The macro block index.
_frame: The frame to search, either OC_FRAME_PREV or OC_FRAME_GOLD.*/
void oc_mcenc_search_frame(oc_enc_ctx *_enc,int _accum[2],int _mbi,int _frame){
/*Note: Traditionally this search is done using a rate-distortion objective
function of the form D+lambda*R.
However, xiphmont tested this and found it produced a small degredation,
while requiring extra computation.
This is most likely due to Theora's peculiar MV encoding scheme: MVs are
not coded relative to a predictor, and the only truly cheap way to use a
MV is in the LAST or LAST2 MB modes, which are not being considered here.
Therefore if we use the MV found here, it's only because both LAST and
LAST2 performed poorly, and therefore the MB is not likely to be uniform
or suffer from the aperture problem.
Furthermore we would like to re-use the MV found here for as many MBs as
possible, so picking a slightly sub-optimal vector to save a bit or two
may cause increased degredation in many blocks to come.
We could artificially reduce lambda to compensate, but it's faster to just
disable it entirely, and use D (the distortion) as the sole criterion.*/
oc_mcenc_ctx mcenc;
const ptrdiff_t *frag_buf_offs;
const ptrdiff_t *fragis;
const unsigned char *src;
const unsigned char *ref;
int ystride;
oc_mb_enc_info *embs;
ogg_int32_t hit_cache[31];
ogg_int32_t hitbit;
unsigned best_block_err[4];
unsigned block_err[4];
unsigned best_err;
int best_vec[2];
int best_block_vec[4][2];
int candx;
int candy;
int bi;
embs=_enc->mb_info;
/*Find some candidate motion vectors.*/
oc_mcenc_find_candidates(_enc,&mcenc,_accum,_mbi,_frame);
/*Clear the cache of locations we've examined.*/
memset(hit_cache,0,sizeof(hit_cache));
/*Start with the median predictor.*/
candx=mcenc.candidates[0][0];
candy=mcenc.candidates[0][1];
hit_cache[candy+15]|=(ogg_int32_t)1<<candx+15;
frag_buf_offs=_enc->state.frag_buf_offs;
fragis=_enc->state.mb_maps[_mbi][0];
src=_enc->state.ref_frame_data[OC_FRAME_IO];
ref=_enc->state.ref_frame_data[_enc->state.ref_frame_idx[_frame]];
ystride=_enc->state.ref_ystride[0];
/*TODO: customize error function for speed/(quality+size) tradeoff.*/
best_err=oc_mcenc_ysad_check_mbcandidate_fullpel(_enc,
frag_buf_offs,fragis,candx,candy,src,ref,ystride,block_err);
best_vec[0]=candx;
best_vec[1]=candy;
if(_frame==OC_FRAME_PREV){
for(bi=0;bi<4;bi++){
best_block_err[bi]=block_err[bi];
best_block_vec[bi][0]=candx;
best_block_vec[bi][1]=candy;
}
}
/*If this predictor fails, move on to set A.*/
if(best_err>OC_YSAD_THRESH1){
unsigned err;
unsigned t2;
int ncs;
int ci;
/*Compute the early termination threshold for set A.*/
t2=embs[_mbi].error[_frame];
ncs=OC_MINI(3,embs[_mbi].ncneighbors);
for(ci=0;ci<ncs;ci++){
t2=OC_MAXI(t2,embs[embs[_mbi].cneighbors[ci]].error[_frame]);
}
t2+=(t2>>OC_YSAD_THRESH2_SCALE_BITS)+OC_YSAD_THRESH2_OFFSET;
/*Examine the candidates in set A.*/
for(ci=1;ci<mcenc.setb0;ci++){
candx=mcenc.candidates[ci][0];
candy=mcenc.candidates[ci][1];
/*If we've already examined this vector, then we would be using it if it
was better than what we are using.*/
hitbit=(ogg_int32_t)1<<candx+15;
if(hit_cache[candy+15]&hitbit)continue;
hit_cache[candy+15]|=hitbit;
err=oc_mcenc_ysad_check_mbcandidate_fullpel(_enc,
frag_buf_offs,fragis,candx,candy,src,ref,ystride,block_err);
if(err<best_err){
best_err=err;
best_vec[0]=candx;
best_vec[1]=candy;
}
if(_frame==OC_FRAME_PREV){
for(bi=0;bi<4;bi++)if(block_err[bi]<best_block_err[bi]){
best_block_err[bi]=block_err[bi];
best_block_vec[bi][0]=candx;
best_block_vec[bi][1]=candy;
}
}
}
if(best_err>t2){
/*Examine the candidates in set B.*/
for(;ci<mcenc.ncandidates;ci++){
candx=mcenc.candidates[ci][0];
candy=mcenc.candidates[ci][1];
hitbit=(ogg_int32_t)1<<candx+15;
if(hit_cache[candy+15]&hitbit)continue;
hit_cache[candy+15]|=hitbit;
err=oc_mcenc_ysad_check_mbcandidate_fullpel(_enc,
frag_buf_offs,fragis,candx,candy,src,ref,ystride,block_err);
if(err<best_err){
best_err=err;
best_vec[0]=candx;
best_vec[1]=candy;
}
if(_frame==OC_FRAME_PREV){
for(bi=0;bi<4;bi++)if(block_err[bi]<best_block_err[bi]){
best_block_err[bi]=block_err[bi];
best_block_vec[bi][0]=candx;
best_block_vec[bi][1]=candy;
}
}
}
/*Use the same threshold for set B as in set A.*/
if(best_err>t2){
int best_site;
int nsites;
int sitei;
int site;
int b;
/*Square pattern search.*/
for(;;){
best_site=4;
/*Compose the bit flags for boundary conditions.*/
b=OC_DIV16(-best_vec[0]+1)|OC_DIV16(best_vec[0]+1)<<1|
OC_DIV16(-best_vec[1]+1)<<2|OC_DIV16(best_vec[1]+1)<<3;
nsites=OC_SQUARE_NSITES[b];
for(sitei=0;sitei<nsites;sitei++){
site=OC_SQUARE_SITES[b][sitei];
candx=best_vec[0]+OC_SQUARE_DX[site];
candy=best_vec[1]+OC_SQUARE_DY[site];
hitbit=(ogg_int32_t)1<<candx+15;
if(hit_cache[candy+15]&hitbit)continue;
hit_cache[candy+15]|=hitbit;
err=oc_mcenc_ysad_check_mbcandidate_fullpel(_enc,
frag_buf_offs,fragis,candx,candy,src,ref,ystride,block_err);
if(err<best_err){
best_err=err;
best_site=site;
}
if(_frame==OC_FRAME_PREV){
for(bi=0;bi<4;bi++)if(block_err[bi]<best_block_err[bi]){
best_block_err[bi]=block_err[bi];
best_block_vec[bi][0]=candx;
best_block_vec[bi][1]=candy;
}
}
}
if(best_site==4)break;
best_vec[0]+=OC_SQUARE_DX[best_site];
best_vec[1]+=OC_SQUARE_DY[best_site];
}
/*Final 4-MV search.*/
/*Simply use 1/4 of the macro block set A and B threshold as the
individual block threshold.*/
if(_frame==OC_FRAME_PREV){
t2>>=2;
for(bi=0;bi<4;bi++){
if(best_block_err[bi]>t2){
/*Square pattern search.
We do this in a slightly interesting manner.
We continue to check the SAD of all four blocks in the
macro block.
This gives us two things:
1) We can continue to use the hit_cache to avoid duplicate
checks.
Otherwise we could continue to read it, but not write to it
without saving and restoring it for each block.
Note that we could still eliminate a large number of
duplicate checks by taking into account the site we came
from when choosing the site list.
We can still do that to avoid extra hit_cache queries, and
it might even be a speed win.
2) It gives us a slightly better chance of escaping local
minima.
We would not be here if we weren't doing a fairly bad job
in finding a good vector, and checking these vectors can
save us from 100 to several thousand points off our SAD 1
in 15 times.
TODO: Is this a good idea?
Who knows.
It needs more testing.*/
for(;;){
int bestx;
int besty;
int bj;
bestx=best_block_vec[bi][0];
besty=best_block_vec[bi][1];
/*Compose the bit flags for boundary conditions.*/
b=OC_DIV16(-bestx+1)|OC_DIV16(bestx+1)<<1|
OC_DIV16(-besty+1)<<2|OC_DIV16(besty+1)<<3;
nsites=OC_SQUARE_NSITES[b];
for(sitei=0;sitei<nsites;sitei++){
site=OC_SQUARE_SITES[b][sitei];
candx=bestx+OC_SQUARE_DX[site];
candy=besty+OC_SQUARE_DY[site];
hitbit=(ogg_int32_t)1<<candx+15;
if(hit_cache[candy+15]&hitbit)continue;
hit_cache[candy+15]|=hitbit;
err=oc_mcenc_ysad_check_mbcandidate_fullpel(_enc,
frag_buf_offs,fragis,candx,candy,src,ref,ystride,block_err);
if(err<best_err){
best_err=err;
best_vec[0]=candx;
best_vec[1]=candy;
}
for(bj=0;bj<4;bj++)if(block_err[bj]<best_block_err[bj]){
best_block_err[bj]=block_err[bj];
best_block_vec[bj][0]=candx;
best_block_vec[bj][1]=candy;
}
}
if(best_block_vec[bi][0]==bestx&&best_block_vec[bi][1]==besty){
break;
}
}
}
}
}
}
}
}
embs[_mbi].error[_frame]=(ogg_uint16_t)best_err;
candx=best_vec[0];
candy=best_vec[1];
embs[_mbi].satd[_frame]=oc_mcenc_ysatd_check_mbcandidate_fullpel(_enc,
frag_buf_offs,fragis,candx,candy,src,ref,ystride);
embs[_mbi].analysis_mv[0][_frame][0]=(signed char)(candx<<1);
embs[_mbi].analysis_mv[0][_frame][1]=(signed char)(candy<<1);
if(_frame==OC_FRAME_PREV){
for(bi=0;bi<4;bi++){
candx=best_block_vec[bi][0];
candy=best_block_vec[bi][1];
embs[_mbi].block_satd[bi]=oc_mcenc_ysatd_check_bcandidate_fullpel(_enc,
frag_buf_offs[fragis[bi]],candx,candy,src,ref,ystride);
embs[_mbi].block_mv[bi][0]=(signed char)(candx<<1);
embs[_mbi].block_mv[bi][1]=(signed char)(candy<<1);
}
}
}
void oc_mcenc_search(oc_enc_ctx *_enc,int _mbi){
oc_mv2 *mvs;
int accum_p[2];
int accum_g[2];
mvs=_enc->mb_info[_mbi].analysis_mv;
if(_enc->prevframe_dropped){
accum_p[0]=mvs[0][OC_FRAME_PREV][0];
accum_p[1]=mvs[0][OC_FRAME_PREV][1];
}
else accum_p[1]=accum_p[0]=0;
accum_g[0]=mvs[2][OC_FRAME_GOLD][0];
accum_g[1]=mvs[2][OC_FRAME_GOLD][1];
mvs[0][OC_FRAME_PREV][0]-=mvs[2][OC_FRAME_PREV][0];
mvs[0][OC_FRAME_PREV][1]-=mvs[2][OC_FRAME_PREV][1];
/*Move the motion vector predictors back a frame.*/
memmove(mvs+1,mvs,2*sizeof(*mvs));
/*Search the last frame.*/
oc_mcenc_search_frame(_enc,accum_p,_mbi,OC_FRAME_PREV);
mvs[2][OC_FRAME_PREV][0]=accum_p[0];
mvs[2][OC_FRAME_PREV][1]=accum_p[1];
/*GOLDEN MVs are different from PREV MVs in that they're each absolute
offsets from some frame in the past rather than relative offsets from the
frame before.
For predictor calculation to make sense, we need them to be in the same
form as PREV MVs.*/
mvs[1][OC_FRAME_GOLD][0]-=mvs[2][OC_FRAME_GOLD][0];
mvs[1][OC_FRAME_GOLD][1]-=mvs[2][OC_FRAME_GOLD][1];
mvs[2][OC_FRAME_GOLD][0]-=accum_g[0];
mvs[2][OC_FRAME_GOLD][1]-=accum_g[1];
/*Search the golden frame.*/
oc_mcenc_search_frame(_enc,accum_g,_mbi,OC_FRAME_GOLD);
/*Put GOLDEN MVs back into absolute offset form.
The newest MV is already an absolute offset.*/
mvs[2][OC_FRAME_GOLD][0]+=accum_g[0];
mvs[2][OC_FRAME_GOLD][1]+=accum_g[1];
mvs[1][OC_FRAME_GOLD][0]+=mvs[2][OC_FRAME_GOLD][0];
mvs[1][OC_FRAME_GOLD][1]+=mvs[2][OC_FRAME_GOLD][1];
}
#if 0
static int oc_mcenc_ysad_halfpel_mbrefine(const oc_enc_ctx *_enc,int _mbi,
int _vec[2],int _best_err,int _frame){
const unsigned char *src;
const unsigned char *ref;
const ptrdiff_t *frag_buf_offs;
const ptrdiff_t *fragis;
int offset_y[9];
int ystride;
int mvoffset_base;
int best_site;
int sitei;
int err;
src=_enc->state.ref_frame_data[OC_FRAME_IO];
ref=_enc->state.ref_frame_data[_enc->state.ref_frame_idx[_framei]];
frag_buf_offs=_enc->state.frag_buf_offs;
fragis=_enc->state.mb_maps[_mbi][0];
ystride=_enc->state.ref_ystride[0];
mvoffset_base=_vec[0]+_vec[1]*ystride;
offset_y[0]=offset_y[1]=offset_y[2]=-ystride;
offset_y[3]=offset_y[5]=0;
offset_y[6]=offset_y[7]=offset_y[8]=ystride;
best_site=4;
for(sitei=0;sitei<8;sitei++){
int site;
int xmask;
int ymask;
int dx;
int dy;
int mvoffset0;
int mvoffset1;
site=OC_SQUARE_SITES[0][sitei];
dx=OC_SQUARE_DX[site];
dy=OC_SQUARE_DY[site];
/*The following code SHOULD be equivalent to
oc_state_get_mv_offsets(&_mcenc->enc.state,&mvoffset0,&mvoffset1,
(_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
However, it should also be much faster, as it involves no multiplies and
doesn't have to handle chroma vectors.*/
xmask=OC_SIGNMASK(((_vec[0]<<1)+dx)^dx);
ymask=OC_SIGNMASK(((_vec[1]<<1)+dy)^dy);
mvoffset0=mvoffset_base+(dx&xmask)+(offset_y[site]&ymask);
mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
err=oc_sad16_halfpel(_enc,frag_buf_offs,fragis,
mvoffset0,mvoffset1,src,ref,ystride,_best_err);
if(err<_best_err){
_best_err=err;
best_site=site;
}
}
_vec[0]=(_vec[0]<<1)+OC_SQUARE_DX[best_site];
_vec[1]=(_vec[1]<<1)+OC_SQUARE_DY[best_site];
return _best_err;
}
#endif
static unsigned oc_mcenc_ysatd_halfpel_mbrefine(const oc_enc_ctx *_enc,
int _mbi,int _vec[2],unsigned _best_err,int _frame){
const unsigned char *src;
const unsigned char *ref;
const ptrdiff_t *frag_buf_offs;
const ptrdiff_t *fragis;
int offset_y[9];
int ystride;
int mvoffset_base;
int best_site;
int sitei;
int err;
src=_enc->state.ref_frame_data[OC_FRAME_IO];
ref=_enc->state.ref_frame_data[_enc->state.ref_frame_idx[_frame]];
frag_buf_offs=_enc->state.frag_buf_offs;
fragis=_enc->state.mb_maps[_mbi][0];
ystride=_enc->state.ref_ystride[0];
mvoffset_base=_vec[0]+_vec[1]*ystride;
offset_y[0]=offset_y[1]=offset_y[2]=-ystride;
offset_y[3]=offset_y[5]=0;
offset_y[6]=offset_y[7]=offset_y[8]=ystride;
best_site=4;
for(sitei=0;sitei<8;sitei++){
int site;
int xmask;
int ymask;
int dx;
int dy;
int mvoffset0;
int mvoffset1;
site=OC_SQUARE_SITES[0][sitei];
dx=OC_SQUARE_DX[site];
dy=OC_SQUARE_DY[site];
/*The following code SHOULD be equivalent to
oc_state_get_mv_offsets(&_mcenc->enc.state,&mvoffset0,&mvoffset1,
(_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
However, it should also be much faster, as it involves no multiplies and
doesn't have to handle chroma vectors.*/
xmask=OC_SIGNMASK(((_vec[0]<<1)+dx)^dx);
ymask=OC_SIGNMASK(((_vec[1]<<1)+dy)^dy);
mvoffset0=mvoffset_base+(dx&xmask)+(offset_y[site]&ymask);
mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
err=oc_satd16_halfpel(_enc,frag_buf_offs,fragis,
mvoffset0,mvoffset1,src,ref,ystride,_best_err);
if(err<_best_err){
_best_err=err;
best_site=site;
}
}
_vec[0]=(_vec[0]<<1)+OC_SQUARE_DX[best_site];
_vec[1]=(_vec[1]<<1)+OC_SQUARE_DY[best_site];
return _best_err;
}
void oc_mcenc_refine1mv(oc_enc_ctx *_enc,int _mbi,int _frame){
oc_mb_enc_info *embs;
int vec[2];
embs=_enc->mb_info;
vec[0]=OC_DIV2(embs[_mbi].analysis_mv[0][_frame][0]);
vec[1]=OC_DIV2(embs[_mbi].analysis_mv[0][_frame][1]);
embs[_mbi].satd[_frame]=oc_mcenc_ysatd_halfpel_mbrefine(_enc,
_mbi,vec,embs[_mbi].satd[_frame],_frame);
embs[_mbi].analysis_mv[0][_frame][0]=(signed char)vec[0];
embs[_mbi].analysis_mv[0][_frame][1]=(signed char)vec[1];
}
#if 0
static int oc_mcenc_ysad_halfpel_brefine(const oc_enc_ctx *_enc,
int _vec[2],const unsigned char *_src,const unsigned char *_ref,int _ystride,
int _offset_y[9],unsigned _best_err){
int mvoffset_base;
int best_site;
int sitei;
mvoffset_base=_vec[0]+_vec[1]*_ystride;
best_site=4;
for(sitei=0;sitei<8;sitei++){
unsigned err;
int site;
int xmask;
int ymask;
int dx;
int dy;
int mvoffset0;
int mvoffset1;
site=OC_SQUARE_SITES[0][sitei];
dx=OC_SQUARE_DX[site];
dy=OC_SQUARE_DY[site];
/*The following code SHOULD be equivalent to
oc_state_get_mv_offsets(&_mcenc->enc.state,&mvoffset0,&mvoffset1,
(_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
However, it should also be much faster, as it involves no multiplies and
doesn't have to handle chroma vectors.*/
xmask=OC_SIGNMASK(((_vec[0]<<1)+dx)^dx);
ymask=OC_SIGNMASK(((_vec[1]<<1)+dy)^dy);
mvoffset0=mvoffset_base+(dx&xmask)+(_offset_y[site]&ymask);
mvoffset1=mvoffset_base+(dx&~xmask)+(_offset_y[site]&~ymask);
err=oc_enc_frag_sad2_thresh(_enc,_src,
_ref+mvoffset0,_ref+mvoffset1,ystride,_best_err);
if(err<_best_err){
_best_err=err;
best_site=site;
}
}
_vec[0]=(_vec[0]<<1)+OC_SQUARE_DX[best_site];
_vec[1]=(_vec[1]<<1)+OC_SQUARE_DY[best_site];
return _best_err;
}
#endif
static unsigned oc_mcenc_ysatd_halfpel_brefine(const oc_enc_ctx *_enc,
int _vec[2],const unsigned char *_src,const unsigned char *_ref,int _ystride,
int _offset_y[9],unsigned _best_err){
int mvoffset_base;
int best_site;
int sitei;
mvoffset_base=_vec[0]+_vec[1]*_ystride;
best_site=4;
for(sitei=0;sitei<8;sitei++){
unsigned err;
int site;
int xmask;
int ymask;
int dx;
int dy;
int mvoffset0;
int mvoffset1;
site=OC_SQUARE_SITES[0][sitei];
dx=OC_SQUARE_DX[site];
dy=OC_SQUARE_DY[site];
/*The following code SHOULD be equivalent to
oc_state_get_mv_offsets(&_enc->state,&mvoffsets,0,
(_vec[0]<<1)+dx,(_vec[1]<<1)+dy);
However, it should also be much faster, as it involves no multiplies and
doesn't have to handle chroma vectors.*/
xmask=OC_SIGNMASK(((_vec[0]<<1)+dx)^dx);
ymask=OC_SIGNMASK(((_vec[1]<<1)+dy)^dy);
mvoffset0=mvoffset_base+(dx&xmask)+(_offset_y[site]&ymask);
mvoffset1=mvoffset_base+(dx&~xmask)+(_offset_y[site]&~ymask);
err=oc_enc_frag_satd2_thresh(_enc,_src,
_ref+mvoffset0,_ref+mvoffset1,_ystride,_best_err);
if(err<_best_err){
_best_err=err;
best_site=site;
}
}
_vec[0]=(_vec[0]<<1)+OC_SQUARE_DX[best_site];
_vec[1]=(_vec[1]<<1)+OC_SQUARE_DY[best_site];
return _best_err;
}
void oc_mcenc_refine4mv(oc_enc_ctx *_enc,int _mbi){
oc_mb_enc_info *embs;
const ptrdiff_t *frag_buf_offs;
const ptrdiff_t *fragis;
const unsigned char *src;
const unsigned char *ref;
int offset_y[9];
int ystride;
int bi;
ystride=_enc->state.ref_ystride[0];
frag_buf_offs=_enc->state.frag_buf_offs;
fragis=_enc->state.mb_maps[_mbi][0];
src=_enc->state.ref_frame_data[OC_FRAME_IO];
ref=_enc->state.ref_frame_data[_enc->state.ref_frame_idx[OC_FRAME_PREV]];
offset_y[0]=offset_y[1]=offset_y[2]=-ystride;
offset_y[3]=offset_y[5]=0;
offset_y[6]=offset_y[7]=offset_y[8]=ystride;
embs=_enc->mb_info;
for(bi=0;bi<4;bi++){
ptrdiff_t frag_offs;
int vec[2];
frag_offs=frag_buf_offs[fragis[bi]];
vec[0]=OC_DIV2(embs[_mbi].block_mv[bi][0]);
vec[1]=OC_DIV2(embs[_mbi].block_mv[bi][1]);
embs[_mbi].block_satd[bi]=oc_mcenc_ysatd_halfpel_brefine(_enc,vec,
src+frag_offs,ref+frag_offs,ystride,offset_y,embs[_mbi].block_satd[bi]);
embs[_mbi].ref_mv[bi][0]=(signed char)vec[0];
embs[_mbi].ref_mv[bi][1]=(signed char)vec[1];
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,128 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: ocintrin.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
/*Some common macros for potential platform-specific optimization.*/
#include <math.h>
#if !defined(_ocintrin_H)
# define _ocintrin_H (1)
/*Some specific platforms may have optimized intrinsic or inline assembly
versions of these functions which can substantially improve performance.
We define macros for them to allow easy incorporation of these non-ANSI
features.*/
/*Note that we do not provide a macro for abs(), because it is provided as a
library function, which we assume is translated into an intrinsic to avoid
the function call overhead and then implemented in the smartest way for the
target platform.
With modern gcc (4.x), this is true: it uses cmov instructions if the
architecture supports it and branchless bit-twiddling if it does not (the
speed difference between the two approaches is not measurable).
Interestingly, the bit-twiddling method was patented in 2000 (US 6,073,150)
by Sun Microsystems, despite prior art dating back to at least 1996:
http://web.archive.org/web/19961201174141/www.x86.org/ftp/articles/pentopt/PENTOPT.TXT
On gcc 3.x, however, our assumption is not true, as abs() is translated to a
conditional jump, which is horrible on deeply piplined architectures (e.g.,
all consumer architectures for the past decade or more).
Also be warned that -C*abs(x) where C is a constant is mis-optimized as
abs(C*x) on every gcc release before 4.2.3.
See bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34130 */
/*Modern gcc (4.x) can compile the naive versions of min and max with cmov if
given an appropriate architecture, but the branchless bit-twiddling versions
are just as fast, and do not require any special target architecture.
Earlier gcc versions (3.x) compiled both code to the same assembly
instructions, because of the way they represented ((_b)>(_a)) internally.*/
#define OC_MAXI(_a,_b) ((_a)-((_a)-(_b)&-((_b)>(_a))))
#define OC_MINI(_a,_b) ((_a)+((_b)-(_a)&-((_b)<(_a))))
/*Clamps an integer into the given range.
If _a>_c, then the lower bound _a is respected over the upper bound _c (this
behavior is required to meet our documented API behavior).
_a: The lower bound.
_b: The value to clamp.
_c: The upper boud.*/
#define OC_CLAMPI(_a,_b,_c) (OC_MAXI(_a,OC_MINI(_b,_c)))
#define OC_CLAMP255(_x) ((unsigned char)((((_x)<0)-1)&((_x)|-((_x)>255))))
/*This has a chance of compiling branchless, and is just as fast as the
bit-twiddling method, which is slightly less portable, since it relies on a
sign-extended rightshift, which is not guaranteed by ANSI (but present on
every relevant platform).*/
#define OC_SIGNI(_a) (((_a)>0)-((_a)<0))
/*Slightly more portable than relying on a sign-extended right-shift (which is
not guaranteed by ANSI), and just as fast, since gcc (3.x and 4.x both)
compile it into the right-shift anyway.*/
#define OC_SIGNMASK(_a) (-((_a)<0))
/*Divides an integer by a power of two, truncating towards 0.
_dividend: The integer to divide.
_shift: The non-negative power of two to divide by.
_rmask: (1<<_shift)-1*/
#define OC_DIV_POW2(_dividend,_shift,_rmask)\
((_dividend)+(OC_SIGNMASK(_dividend)&(_rmask))>>(_shift))
/*Divides _x by 65536, truncating towards 0.*/
#define OC_DIV2_16(_x) OC_DIV_POW2(_x,16,0xFFFF)
/*Divides _x by 2, truncating towards 0.*/
#define OC_DIV2(_x) OC_DIV_POW2(_x,1,0x1)
/*Divides _x by 8, truncating towards 0.*/
#define OC_DIV8(_x) OC_DIV_POW2(_x,3,0x7)
/*Divides _x by 16, truncating towards 0.*/
#define OC_DIV16(_x) OC_DIV_POW2(_x,4,0xF)
/*Right shifts _dividend by _shift, adding _rval, and subtracting one for
negative dividends first.
When _rval is (1<<_shift-1), this is equivalent to division with rounding
ties away from zero.*/
#define OC_DIV_ROUND_POW2(_dividend,_shift,_rval)\
((_dividend)+OC_SIGNMASK(_dividend)+(_rval)>>(_shift))
/*Divides a _x by 2, rounding towards even numbers.*/
#define OC_DIV2_RE(_x) ((_x)+((_x)>>1&1)>>1)
/*Divides a _x by (1<<(_shift)), rounding towards even numbers.*/
#define OC_DIV_POW2_RE(_x,_shift) \
((_x)+((_x)>>(_shift)&1)+((1<<(_shift))-1>>1)>>(_shift))
/*Swaps two integers _a and _b if _a>_b.*/
#define OC_SORT2I(_a,_b) \
do{ \
int t__; \
t__=((_a)^(_b))&-((_b)<(_a)); \
(_a)^=t__; \
(_b)^=t__; \
} \
while(0)
/*Accesses one of four (signed) bytes given an index.
This can be used to avoid small lookup tables.*/
#define OC_BYTE_TABLE32(_a,_b,_c,_d,_i) \
((signed char) \
(((_a)&0xFF|((_b)&0xFF)<<8|((_c)&0xFF)<<16|((_d)&0xFF)<<24)>>(_i)*8))
/*Accesses one of eight (unsigned) nibbles given an index.
This can be used to avoid small lookup tables.*/
#define OC_UNIBBLE_TABLE32(_a,_b,_c,_d,_e,_f,_g,_h,_i) \
((((_a)&0xF|((_b)&0xF)<<4|((_c)&0xF)<<8|((_d)&0xF)<<12| \
((_e)&0xF)<<16|((_f)&0xF)<<20|((_g)&0xF)<<24|((_h)&0xF)<<28)>>(_i)*4)&0xF)
/*All of these macros should expect floats as arguments.*/
#define OC_MAXF(_a,_b) ((_a)<(_b)?(_b):(_a))
#define OC_MINF(_a,_b) ((_a)>(_b)?(_b):(_a))
#define OC_CLAMPF(_a,_b,_c) (OC_MINF(_a,OC_MAXF(_b,_c)))
#define OC_FABSF(_f) ((float)fabs(_f))
#define OC_SQRTF(_f) ((float)sqrt(_f))
#define OC_POWF(_b,_e) ((float)pow(_b,_e))
#define OC_LOGF(_f) ((float)log(_f))
#define OC_IFLOORF(_f) ((int)floor(_f))
#define OC_ICEILF(_f) ((int)ceil(_f))
#endif

View File

@@ -0,0 +1,119 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: quant.c 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <ogg/ogg.h>
#include "quant.h"
#include "decint.h"
static const unsigned OC_DC_QUANT_MIN[2]={4<<2,8<<2};
static const unsigned OC_AC_QUANT_MIN[2]={2<<2,4<<2};
/*Initializes the dequantization tables from a set of quantizer info.
Currently the dequantizer (and elsewhere enquantizer) tables are expected to
be initialized as pointing to the storage reserved for them in the
oc_theora_state (resp. oc_enc_ctx) structure.
If some tables are duplicates of others, the pointers will be adjusted to
point to a single copy of the tables, but the storage for them will not be
freed.
If you're concerned about the memory footprint, the obvious thing to do is
to move the storage out of its fixed place in the structures and allocate
it on demand.
However, a much, much better option is to only store the quantization
matrices being used for the current frame, and to recalculate these as the
qi values change between frames (this is what VP3 did).*/
void oc_dequant_tables_init(ogg_uint16_t *_dequant[64][3][2],
int _pp_dc_scale[64],const th_quant_info *_qinfo){
/*Coding mode: intra or inter.*/
int qti;
/*Y', C_b, C_r*/
int pli;
for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
/*Quality index.*/
int qi;
/*Range iterator.*/
int qri;
for(qi=0,qri=0;qri<=_qinfo->qi_ranges[qti][pli].nranges;qri++){
th_quant_base base;
ogg_uint32_t q;
int qi_start;
int qi_end;
memcpy(base,_qinfo->qi_ranges[qti][pli].base_matrices[qri],
sizeof(base));
qi_start=qi;
if(qri==_qinfo->qi_ranges[qti][pli].nranges)qi_end=qi+1;
else qi_end=qi+_qinfo->qi_ranges[qti][pli].sizes[qri];
/*Iterate over quality indicies in this range.*/
for(;;){
ogg_uint32_t qfac;
int zzi;
int ci;
/*In the original VP3.2 code, the rounding offset and the size of the
dead zone around 0 were controlled by a "sharpness" parameter.
The size of our dead zone is now controlled by the per-coefficient
quality thresholds returned by our HVS module.
We round down from a more accurate value when the quality of the
reconstruction does not fall below our threshold and it saves bits.
Hence, all of that VP3.2 code is gone from here, and the remaining
floating point code has been implemented as equivalent integer code
with exact precision.*/
qfac=(ogg_uint32_t)_qinfo->dc_scale[qi]*base[0];
/*For postprocessing, not dequantization.*/
if(_pp_dc_scale!=NULL)_pp_dc_scale[qi]=(int)(qfac/160);
/*Scale DC the coefficient from the proper table.*/
q=(qfac/100)<<2;
q=OC_CLAMPI(OC_DC_QUANT_MIN[qti],q,OC_QUANT_MAX);
_dequant[qi][pli][qti][0]=(ogg_uint16_t)q;
/*Now scale AC coefficients from the proper table.*/
for(zzi=1;zzi<64;zzi++){
q=((ogg_uint32_t)_qinfo->ac_scale[qi]*base[OC_FZIG_ZAG[zzi]]/100)<<2;
q=OC_CLAMPI(OC_AC_QUANT_MIN[qti],q,OC_QUANT_MAX);
_dequant[qi][pli][qti][zzi]=(ogg_uint16_t)q;
}
/*If this is a duplicate of a previous matrix, use that instead.
This simple check helps us improve cache coherency later.*/
{
int dupe;
int qtj;
int plj;
dupe=0;
for(qtj=0;qtj<=qti;qtj++){
for(plj=0;plj<(qtj<qti?3:pli);plj++){
if(!memcmp(_dequant[qi][pli][qti],_dequant[qi][plj][qtj],
sizeof(oc_quant_table))){
dupe=1;
break;
}
}
if(dupe)break;
}
if(dupe)_dequant[qi][pli][qti]=_dequant[qi][plj][qtj];
}
if(++qi>=qi_end)break;
/*Interpolate the next base matrix.*/
for(ci=0;ci<64;ci++){
base[ci]=(unsigned char)(
(2*((qi_end-qi)*_qinfo->qi_ranges[qti][pli].base_matrices[qri][ci]+
(qi-qi_start)*_qinfo->qi_ranges[qti][pli].base_matrices[qri+1][ci])
+_qinfo->qi_ranges[qti][pli].sizes[qri])/
(2*_qinfo->qi_ranges[qti][pli].sizes[qri]));
}
}
}
}
}

View File

@@ -0,0 +1,33 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************
function:
last mod: $Id: quant.h 16503 2009-08-22 18:14:02Z giles $
********************************************************************/
#if !defined(_quant_H)
# define _quant_H (1)
# include "theora/codec.h"
# include "ocintrin.h"
typedef ogg_uint16_t oc_quant_table[64];
/*Maximum scaled quantizer value.*/
#define OC_QUANT_MAX (1024<<2)
void oc_dequant_tables_init(ogg_uint16_t *_dequant[64][3][2],
int _pp_dc_scale[64],const th_quant_info *_qinfo);
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff