diff --git a/code/thirdparty/libvorbis-1.3.7/lib/vorbisenc.c b/code/thirdparty/libvorbis-1.3.7/lib/vorbisenc.c deleted file mode 100644 index cf3806a6..00000000 --- a/code/thirdparty/libvorbis-1.3.7/lib/vorbisenc.c +++ /dev/null @@ -1,1224 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 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 OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 * - * by the Xiph.Org Foundation https://xiph.org/ * - * * - ******************************************************************** - - function: simple programmatic interface for encoder mode setup - - ********************************************************************/ - -#include -#include -#include - -#include "vorbis/codec.h" -#include "vorbis/vorbisenc.h" - -#include "codec_internal.h" - -#include "os.h" -#include "misc.h" - -/* careful with this; it's using static array sizing to make managing - all the modes a little less annoying. If we use a residue backend - with > 12 partition types, or a different division of iteration, - this needs to be updated. */ -typedef struct { - const static_codebook *books[12][4]; -} static_bookblock; - -typedef struct { - int res_type; - int limit_type; /* 0 lowpass limited, 1 point stereo limited */ - int grouping; - const vorbis_info_residue0 *res; - const static_codebook *book_aux; - const static_codebook *book_aux_managed; - const static_bookblock *books_base; - const static_bookblock *books_base_managed; -} vorbis_residue_template; - -typedef struct { - const vorbis_info_mapping0 *map; - const vorbis_residue_template *res; -} vorbis_mapping_template; - -typedef struct vp_adjblock{ - int block[P_BANDS]; -} vp_adjblock; - -typedef struct { - int data[NOISE_COMPAND_LEVELS]; -} compandblock; - -/* high level configuration information for setting things up - step-by-step with the detailed vorbis_encode_ctl interface. - There's a fair amount of redundancy such that interactive setup - does not directly deal with any vorbis_info or codec_setup_info - initialization; it's all stored (until full init) in this highlevel - setup, then flushed out to the real codec setup structs later. */ - -typedef struct { - int att[P_NOISECURVES]; - float boost; - float decay; -} att3; -typedef struct { int data[P_NOISECURVES]; } adj3; - -typedef struct { - int pre[PACKETBLOBS]; - int post[PACKETBLOBS]; - float kHz[PACKETBLOBS]; - float lowpasskHz[PACKETBLOBS]; -} adj_stereo; - -typedef struct { - int lo; - int hi; - int fixed; -} noiseguard; -typedef struct { - int data[P_NOISECURVES][17]; -} noise3; - -typedef struct { - int mappings; - const double *rate_mapping; - const double *quality_mapping; - int coupling_restriction; - long samplerate_min_restriction; - long samplerate_max_restriction; - - - const int *blocksize_short; - const int *blocksize_long; - - const att3 *psy_tone_masteratt; - const int *psy_tone_0dB; - const int *psy_tone_dBsuppress; - - const vp_adjblock *psy_tone_adj_impulse; - const vp_adjblock *psy_tone_adj_long; - const vp_adjblock *psy_tone_adj_other; - - const noiseguard *psy_noiseguards; - const noise3 *psy_noise_bias_impulse; - const noise3 *psy_noise_bias_padding; - const noise3 *psy_noise_bias_trans; - const noise3 *psy_noise_bias_long; - const int *psy_noise_dBsuppress; - - const compandblock *psy_noise_compand; - const double *psy_noise_compand_short_mapping; - const double *psy_noise_compand_long_mapping; - - const int *psy_noise_normal_start[2]; - const int *psy_noise_normal_partition[2]; - const double *psy_noise_normal_thresh; - - const int *psy_ath_float; - const int *psy_ath_abs; - - const double *psy_lowpass; - - const vorbis_info_psy_global *global_params; - const double *global_mapping; - const adj_stereo *stereo_modes; - - const static_codebook *const *const *const floor_books; - const vorbis_info_floor1 *floor_params; - const int floor_mappings; - const int **floor_mapping_list; - - const vorbis_mapping_template *maps; -} ve_setup_data_template; - -/* a few static coder conventions */ -static const vorbis_info_mode _mode_template[2]={ - {0,0,0,0}, - {1,0,0,1} -}; - -static const vorbis_info_mapping0 _map_nominal[2]={ - {1, {0,0}, {0}, {0}, 1,{0},{1}}, - {1, {0,0}, {1}, {1}, 1,{0},{1}} -}; - -#include "modes/setup_44.h" -#include "modes/setup_44u.h" -#include "modes/setup_44p51.h" -#include "modes/setup_32.h" -#include "modes/setup_8.h" -#include "modes/setup_11.h" -#include "modes/setup_16.h" -#include "modes/setup_22.h" -#include "modes/setup_X.h" - -static const ve_setup_data_template *const setup_list[]={ - &ve_setup_44_stereo, - &ve_setup_44_51, - &ve_setup_44_uncoupled, - - &ve_setup_32_stereo, - &ve_setup_32_uncoupled, - - &ve_setup_22_stereo, - &ve_setup_22_uncoupled, - &ve_setup_16_stereo, - &ve_setup_16_uncoupled, - - &ve_setup_11_stereo, - &ve_setup_11_uncoupled, - &ve_setup_8_stereo, - &ve_setup_8_uncoupled, - - &ve_setup_X_stereo, - &ve_setup_X_uncoupled, - &ve_setup_XX_stereo, - &ve_setup_XX_uncoupled, - 0 -}; - -static void vorbis_encode_floor_setup(vorbis_info *vi,int s, - const static_codebook *const *const *const books, - const vorbis_info_floor1 *in, - const int *x){ - int i,k,is=s; - vorbis_info_floor1 *f=_ogg_calloc(1,sizeof(*f)); - codec_setup_info *ci=vi->codec_setup; - - memcpy(f,in+x[is],sizeof(*f)); - - /* books */ - { - int partitions=f->partitions; - int maxclass=-1; - int maxbook=-1; - for(i=0;ipartitionclass[i]>maxclass)maxclass=f->partitionclass[i]; - for(i=0;i<=maxclass;i++){ - if(f->class_book[i]>maxbook)maxbook=f->class_book[i]; - f->class_book[i]+=ci->books; - for(k=0;k<(1<class_subs[i]);k++){ - if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k]; - if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books; - } - } - - for(i=0;i<=maxbook;i++) - ci->book_param[ci->books++]=(static_codebook *)books[x[is]][i]; - } - - /* for now, we're only using floor 1 */ - ci->floor_type[ci->floors]=1; - ci->floor_param[ci->floors]=f; - ci->floors++; - - return; -} - -static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s, - const vorbis_info_psy_global *in, - const double *x){ - int i,is=s; - double ds=s-is; - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy_global *g=&ci->psy_g_param; - - memcpy(g,in+(int)x[is],sizeof(*g)); - - ds=x[is]*(1.-ds)+x[is+1]*ds; - is=(int)ds; - ds-=is; - if(ds==0 && is>0){ - is--; - ds=1.; - } - - /* interpolate the trigger threshholds */ - for(i=0;i<4;i++){ - g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds; - g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds; - } - g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec; - return; -} - -static void vorbis_encode_global_stereo(vorbis_info *vi, - const highlevel_encode_setup *const hi, - const adj_stereo *p){ - float s=hi->stereo_point_setting; - int i,is=s; - double ds=s-is; - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy_global *g=&ci->psy_g_param; - - if(p){ - memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS); - memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS); - - if(hi->managed){ - /* interpolate the kHz threshholds */ - for(i=0;icoupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; - g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; - g->coupling_pkHz[i]=kHz; - - kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds; - g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; - g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; - - } - }else{ - float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds; - for(i=0;icoupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; - g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; - g->coupling_pkHz[i]=kHz; - } - - kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds; - for(i=0;isliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; - g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; - } - } - }else{ - for(i=0;isliding_lowpass[0][i]=ci->blocksizes[0]; - g->sliding_lowpass[1][i]=ci->blocksizes[1]; - } - } - return; -} - -static void vorbis_encode_psyset_setup(vorbis_info *vi,double s, - const int *nn_start, - const int *nn_partition, - const double *nn_thresh, - int block){ - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy *p=ci->psy_param[block]; - highlevel_encode_setup *hi=&ci->hi; - int is=s; - - if(block>=ci->psys) - ci->psys=block+1; - if(!p){ - p=_ogg_calloc(1,sizeof(*p)); - ci->psy_param[block]=p; - } - - memcpy(p,&_psy_info_template,sizeof(*p)); - p->blockflag=block>>1; - - if(hi->noise_normalize_p){ - p->normal_p=1; - p->normal_start=nn_start[is]; - p->normal_partition=nn_partition[is]; - p->normal_thresh=nn_thresh[is]; - } - - return; -} - -static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block, - const att3 *att, - const int *max, - const vp_adjblock *in){ - int i,is=s; - double ds=s-is; - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy *p=ci->psy_param[block]; - - /* 0 and 2 are only used by bitmanagement, but there's no harm to always - filling the values in here */ - p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds; - p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds; - p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds; - p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds; - p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds; - - p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds; - - for(i=0;itoneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds; - return; -} - - -static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block, - const compandblock *in, - const double *x){ - int i,is=s; - double ds=s-is; - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy *p=ci->psy_param[block]; - - ds=x[is]*(1.-ds)+x[is+1]*ds; - is=(int)ds; - ds-=is; - if(ds==0 && is>0){ - is--; - ds=1.; - } - - /* interpolate the compander settings */ - for(i=0;inoisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds; - return; -} - -static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block, - const int *suppress){ - int is=s; - double ds=s-is; - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy *p=ci->psy_param[block]; - - p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds; - - return; -} - -static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block, - const int *suppress, - const noise3 *in, - const noiseguard *guard, - double userbias){ - int i,is=s,j; - double ds=s-is; - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy *p=ci->psy_param[block]; - - p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds; - p->noisewindowlomin=guard[block].lo; - p->noisewindowhimin=guard[block].hi; - p->noisewindowfixed=guard[block].fixed; - - for(j=0;jnoiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds; - - /* impulse blocks may take a user specified bias to boost the - nominal/high noise encoding depth */ - for(j=0;jnoiseoff[j][0]+6; /* the lowest it can go */ - for(i=0;inoiseoff[j][i]+=userbias; - if(p->noiseoff[j][i]noiseoff[j][i]=min; - } - } - - return; -} - -static void vorbis_encode_ath_setup(vorbis_info *vi,int block){ - codec_setup_info *ci=vi->codec_setup; - vorbis_info_psy *p=ci->psy_param[block]; - - p->ath_adjatt=ci->hi.ath_floating_dB; - p->ath_maxatt=ci->hi.ath_absolute_dB; - return; -} - - -static int book_dup_or_new(codec_setup_info *ci,const static_codebook *book){ - int i; - for(i=0;ibooks;i++) - if(ci->book_param[i]==book)return(i); - - return(ci->books++); -} - -static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s, - const int *shortb,const int *longb){ - - codec_setup_info *ci=vi->codec_setup; - int is=s; - - int blockshort=shortb[is]; - int blocklong=longb[is]; - ci->blocksizes[0]=blockshort; - ci->blocksizes[1]=blocklong; - -} - -static void vorbis_encode_residue_setup(vorbis_info *vi, - int number, int block, - const vorbis_residue_template *res){ - - codec_setup_info *ci=vi->codec_setup; - int i; - - vorbis_info_residue0 *r=ci->residue_param[number]= - _ogg_malloc(sizeof(*r)); - - memcpy(r,res->res,sizeof(*r)); - if(ci->residues<=number)ci->residues=number+1; - - r->grouping=res->grouping; - ci->residue_type[number]=res->res_type; - - /* fill in all the books */ - { - int booklist=0,k; - - if(ci->hi.managed){ - for(i=0;ipartitions;i++) - for(k=0;k<4;k++) - if(res->books_base_managed->books[i][k]) - r->secondstages[i]|=(1<groupbook=book_dup_or_new(ci,res->book_aux_managed); - ci->book_param[r->groupbook]=(static_codebook *)res->book_aux_managed; - - for(i=0;ipartitions;i++){ - for(k=0;k<4;k++){ - if(res->books_base_managed->books[i][k]){ - int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]); - r->booklist[booklist++]=bookid; - ci->book_param[bookid]=(static_codebook *)res->books_base_managed->books[i][k]; - } - } - } - - }else{ - - for(i=0;ipartitions;i++) - for(k=0;k<4;k++) - if(res->books_base->books[i][k]) - r->secondstages[i]|=(1<groupbook=book_dup_or_new(ci,res->book_aux); - ci->book_param[r->groupbook]=(static_codebook *)res->book_aux; - - for(i=0;ipartitions;i++){ - for(k=0;k<4;k++){ - if(res->books_base->books[i][k]){ - int bookid=book_dup_or_new(ci,res->books_base->books[i][k]); - r->booklist[booklist++]=bookid; - ci->book_param[bookid]=(static_codebook *)res->books_base->books[i][k]; - } - } - } - } - } - - /* lowpass setup/pointlimit */ - { - double freq=ci->hi.lowpass_kHz*1000.; - vorbis_info_floor1 *f=ci->floor_param[block]; /* by convention */ - double nyq=vi->rate/2.; - long blocksize=ci->blocksizes[block]>>1; - - /* lowpass needs to be set in the floor and the residue. */ - if(freq>nyq)freq=nyq; - /* in the floor, the granularity can be very fine; it doesn't alter - the encoding structure, only the samples used to fit the floor - approximation */ - f->n=freq/nyq*blocksize; - - /* this res may by limited by the maximum pointlimit of the mode, - not the lowpass. the floor is always lowpass limited. */ - switch(res->limit_type){ - case 1: /* point stereo limited */ - if(ci->hi.managed) - freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.; - else - freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.; - if(freq>nyq)freq=nyq; - break; - case 2: /* LFE channel; lowpass at ~ 250Hz */ - freq=250; - break; - default: - /* already set */ - break; - } - - /* in the residue, we're constrained, physically, by partition - boundaries. We still lowpass 'wherever', but we have to round up - here to next boundary, or the vorbis spec will round it *down* to - previous boundary in encode/decode */ - if(ci->residue_type[number]==2){ - /* residue 2 bundles together multiple channels; used by stereo - and surround. Count the channels in use */ - /* Multiple maps/submaps can point to the same residue. In the case - of residue 2, they all better have the same number of - channels/samples. */ - int j,k,ch=0; - for(i=0;imaps&&ch==0;i++){ - vorbis_info_mapping0 *mi=(vorbis_info_mapping0 *)ci->map_param[i]; - for(j=0;jsubmaps && ch==0;j++) - if(mi->residuesubmap[j]==number) /* we found a submap referencing theis residue backend */ - for(k=0;kchannels;k++) - if(mi->chmuxlist[k]==j) /* this channel belongs to the submap */ - ch++; - } - - r->end=(int)((freq/nyq*blocksize*ch)/r->grouping+.9)* /* round up only if we're well past */ - r->grouping; - /* the blocksize and grouping may disagree at the end */ - if(r->end>blocksize*ch)r->end=blocksize*ch/r->grouping*r->grouping; - - }else{ - - r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */ - r->grouping; - /* the blocksize and grouping may disagree at the end */ - if(r->end>blocksize)r->end=blocksize/r->grouping*r->grouping; - - } - - if(r->end==0)r->end=r->grouping; /* LFE channel */ - - } -} - -/* we assume two maps in this encoder */ -static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s, - const vorbis_mapping_template *maps){ - - codec_setup_info *ci=vi->codec_setup; - int i,j,is=s,modes=2; - const vorbis_info_mapping0 *map=maps[is].map; - const vorbis_info_mode *mode=_mode_template; - const vorbis_residue_template *res=maps[is].res; - - if(ci->blocksizes[0]==ci->blocksizes[1])modes=1; - - for(i=0;imap_param[i]=_ogg_calloc(1,sizeof(*map)); - ci->mode_param[i]=_ogg_calloc(1,sizeof(*mode)); - - memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template)); - if(i>=ci->modes)ci->modes=i+1; - - ci->map_type[i]=0; - memcpy(ci->map_param[i],map+i,sizeof(*map)); - if(i>=ci->maps)ci->maps=i+1; - - for(j=0;jcodec_setup; - highlevel_encode_setup *hi=&ci->hi; - ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup; - int is=hi->base_setting; - double ds=hi->base_setting-is; - int ch=vi->channels; - const double *r=setup->rate_mapping; - - if(r==NULL) - return(-1); - - return((r[is]*(1.-ds)+r[is+1]*ds)*ch); -} - -static const void *get_setup_template(long ch,long srate, - double req,int q_or_bitrate, - double *base_setting){ - int i=0,j; - if(q_or_bitrate)req/=ch; - - while(setup_list[i]){ - if(setup_list[i]->coupling_restriction==-1 || - setup_list[i]->coupling_restriction==ch){ - if(srate>=setup_list[i]->samplerate_min_restriction && - srate<=setup_list[i]->samplerate_max_restriction){ - int mappings=setup_list[i]->mappings; - const double *map=(q_or_bitrate? - setup_list[i]->rate_mapping: - setup_list[i]->quality_mapping); - - /* the template matches. Does the requested quality mode - fall within this template's modes? */ - if(reqmap[setup_list[i]->mappings]){++i;continue;} - for(j=0;j=map[j] && reqcodec_setup; - ve_setup_data_template *setup=NULL; - highlevel_encode_setup *hi=&ci->hi; - - if(ci==NULL)return(OV_EINVAL); - if(vi->channels<1||vi->channels>255)return(OV_EINVAL); - if(!hi->impulse_block_p)i0=1; - - /* too low/high an ATH floater is nonsensical, but doesn't break anything */ - if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80; - if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200; - - /* again, bound this to avoid the app shooting itself int he foot - too badly */ - if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.; - if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.; - - /* get the appropriate setup template; matches the fetch in previous - stages */ - setup=(ve_setup_data_template *)hi->setup; - if(setup==NULL)return(OV_EINVAL); - - hi->set_in_stone=1; - /* choose block sizes from configured sizes as well as paying - attention to long_block_p and short_block_p. If the configured - short and long blocks are the same length, we set long_block_p - and unset short_block_p */ - vorbis_encode_blocksize_setup(vi,hi->base_setting, - setup->blocksize_short, - setup->blocksize_long); - if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1; - - /* floor setup; choose proper floor params. Allocated on the floor - stack in order; if we alloc only a single long floor, it's 0 */ - for(i=0;ifloor_mappings;i++) - vorbis_encode_floor_setup(vi,hi->base_setting, - setup->floor_books, - setup->floor_params, - setup->floor_mapping_list[i]); - - /* setup of [mostly] short block detection and stereo*/ - vorbis_encode_global_psych_setup(vi,hi->trigger_setting, - setup->global_params, - setup->global_mapping); - vorbis_encode_global_stereo(vi,hi,setup->stereo_modes); - - /* basic psych setup and noise normalization */ - vorbis_encode_psyset_setup(vi,hi->base_setting, - setup->psy_noise_normal_start[0], - setup->psy_noise_normal_partition[0], - setup->psy_noise_normal_thresh, - 0); - vorbis_encode_psyset_setup(vi,hi->base_setting, - setup->psy_noise_normal_start[0], - setup->psy_noise_normal_partition[0], - setup->psy_noise_normal_thresh, - 1); - if(!singleblock){ - vorbis_encode_psyset_setup(vi,hi->base_setting, - setup->psy_noise_normal_start[1], - setup->psy_noise_normal_partition[1], - setup->psy_noise_normal_thresh, - 2); - vorbis_encode_psyset_setup(vi,hi->base_setting, - setup->psy_noise_normal_start[1], - setup->psy_noise_normal_partition[1], - setup->psy_noise_normal_thresh, - 3); - } - - /* tone masking setup */ - vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0, - setup->psy_tone_masteratt, - setup->psy_tone_0dB, - setup->psy_tone_adj_impulse); - vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1, - setup->psy_tone_masteratt, - setup->psy_tone_0dB, - setup->psy_tone_adj_other); - if(!singleblock){ - vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2, - setup->psy_tone_masteratt, - setup->psy_tone_0dB, - setup->psy_tone_adj_other); - vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3, - setup->psy_tone_masteratt, - setup->psy_tone_0dB, - setup->psy_tone_adj_long); - } - - /* noise companding setup */ - vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0, - setup->psy_noise_compand, - setup->psy_noise_compand_short_mapping); - vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1, - setup->psy_noise_compand, - setup->psy_noise_compand_short_mapping); - if(!singleblock){ - vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2, - setup->psy_noise_compand, - setup->psy_noise_compand_long_mapping); - vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3, - setup->psy_noise_compand, - setup->psy_noise_compand_long_mapping); - } - - /* peak guarding setup */ - vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0, - setup->psy_tone_dBsuppress); - vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1, - setup->psy_tone_dBsuppress); - if(!singleblock){ - vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2, - setup->psy_tone_dBsuppress); - vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3, - setup->psy_tone_dBsuppress); - } - - /* noise bias setup */ - vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0, - setup->psy_noise_dBsuppress, - setup->psy_noise_bias_impulse, - setup->psy_noiseguards, - (i0==0?hi->impulse_noisetune:0.)); - vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1, - setup->psy_noise_dBsuppress, - setup->psy_noise_bias_padding, - setup->psy_noiseguards,0.); - if(!singleblock){ - vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2, - setup->psy_noise_dBsuppress, - setup->psy_noise_bias_trans, - setup->psy_noiseguards,0.); - vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3, - setup->psy_noise_dBsuppress, - setup->psy_noise_bias_long, - setup->psy_noiseguards,0.); - } - - vorbis_encode_ath_setup(vi,0); - vorbis_encode_ath_setup(vi,1); - if(!singleblock){ - vorbis_encode_ath_setup(vi,2); - vorbis_encode_ath_setup(vi,3); - } - - vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps); - - /* set bitrate readonlies and management */ - if(hi->bitrate_av>0) - vi->bitrate_nominal=hi->bitrate_av; - else{ - vi->bitrate_nominal=setting_to_approx_bitrate(vi); - } - - vi->bitrate_lower=hi->bitrate_min; - vi->bitrate_upper=hi->bitrate_max; - if(hi->bitrate_av) - vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av; - else - vi->bitrate_window=0.; - - if(hi->managed){ - ci->bi.avg_rate=hi->bitrate_av; - ci->bi.min_rate=hi->bitrate_min; - ci->bi.max_rate=hi->bitrate_max; - - ci->bi.reservoir_bits=hi->bitrate_reservoir; - ci->bi.reservoir_bias= - hi->bitrate_reservoir_bias; - - ci->bi.slew_damp=hi->bitrate_av_damp; - - } - - return(0); - -} - -static void vorbis_encode_setup_setting(vorbis_info *vi, - long channels, - long rate){ - int i,is; - codec_setup_info *ci=vi->codec_setup; - highlevel_encode_setup *hi=&ci->hi; - const ve_setup_data_template *setup=hi->setup; - double ds; - - vi->version=0; - vi->channels=channels; - vi->rate=rate; - - hi->impulse_block_p=1; - hi->noise_normalize_p=1; - - is=hi->base_setting; - ds=hi->base_setting-is; - - hi->stereo_point_setting=hi->base_setting; - - if(!hi->lowpass_altered) - hi->lowpass_kHz= - setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds; - - hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+ - setup->psy_ath_float[is+1]*ds; - hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+ - setup->psy_ath_abs[is+1]*ds; - - hi->amplitude_track_dBpersec=-6.; - hi->trigger_setting=hi->base_setting; - - for(i=0;i<4;i++){ - hi->block[i].tone_mask_setting=hi->base_setting; - hi->block[i].tone_peaklimit_setting=hi->base_setting; - hi->block[i].noise_bias_setting=hi->base_setting; - hi->block[i].noise_compand_setting=hi->base_setting; - } -} - -int vorbis_encode_setup_vbr(vorbis_info *vi, - long channels, - long rate, - float quality){ - codec_setup_info *ci; - highlevel_encode_setup *hi; - if(rate<=0) return OV_EINVAL; - - ci=vi->codec_setup; - hi=&ci->hi; - - quality+=.0000001; - if(quality>=1.)quality=.9999; - - hi->req=quality; - hi->setup=get_setup_template(channels,rate,quality,0,&hi->base_setting); - if(!hi->setup)return OV_EIMPL; - - vorbis_encode_setup_setting(vi,channels,rate); - hi->managed=0; - hi->coupling_p=1; - - return 0; -} - -int vorbis_encode_init_vbr(vorbis_info *vi, - long channels, - long rate, - - float base_quality /* 0. to 1. */ - ){ - int ret=0; - - ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality); - - if(ret){ - vorbis_info_clear(vi); - return ret; - } - ret=vorbis_encode_setup_init(vi); - if(ret) - vorbis_info_clear(vi); - return(ret); -} - -int vorbis_encode_setup_managed(vorbis_info *vi, - long channels, - long rate, - - long max_bitrate, - long nominal_bitrate, - long min_bitrate){ - - codec_setup_info *ci; - highlevel_encode_setup *hi; - double tnominal; - if(rate<=0) return OV_EINVAL; - - ci=vi->codec_setup; - hi=&ci->hi; - tnominal=nominal_bitrate; - - if(nominal_bitrate<=0.){ - if(max_bitrate>0.){ - if(min_bitrate>0.) - nominal_bitrate=(max_bitrate+min_bitrate)*.5; - else - nominal_bitrate=max_bitrate*.875; - }else{ - if(min_bitrate>0.){ - nominal_bitrate=min_bitrate; - }else{ - return(OV_EINVAL); - } - } - } - - hi->req=nominal_bitrate; - hi->setup=get_setup_template(channels,rate,nominal_bitrate,1,&hi->base_setting); - if(!hi->setup)return OV_EIMPL; - - vorbis_encode_setup_setting(vi,channels,rate); - - /* initialize management with sane defaults */ - hi->coupling_p=1; - hi->managed=1; - hi->bitrate_min=min_bitrate; - hi->bitrate_max=max_bitrate; - hi->bitrate_av=tnominal; - hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */ - hi->bitrate_reservoir=nominal_bitrate*2; - hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */ - - return(0); - -} - -int vorbis_encode_init(vorbis_info *vi, - long channels, - long rate, - - long max_bitrate, - long nominal_bitrate, - long min_bitrate){ - - int ret=vorbis_encode_setup_managed(vi,channels,rate, - max_bitrate, - nominal_bitrate, - min_bitrate); - if(ret){ - vorbis_info_clear(vi); - return(ret); - } - - ret=vorbis_encode_setup_init(vi); - if(ret) - vorbis_info_clear(vi); - return(ret); -} - -int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){ - if(vi){ - codec_setup_info *ci=vi->codec_setup; - highlevel_encode_setup *hi=&ci->hi; - int setp=(number&0xf); /* a read request has a low nibble of 0 */ - - if(setp && hi->set_in_stone)return(OV_EINVAL); - - switch(number){ - - /* now deprecated *****************/ - case OV_ECTL_RATEMANAGE_GET: - { - - struct ovectl_ratemanage_arg *ai= - (struct ovectl_ratemanage_arg *)arg; - - ai->management_active=hi->managed; - ai->bitrate_hard_window=ai->bitrate_av_window= - (double)hi->bitrate_reservoir/vi->rate; - ai->bitrate_av_window_center=1.; - ai->bitrate_hard_min=hi->bitrate_min; - ai->bitrate_hard_max=hi->bitrate_max; - ai->bitrate_av_lo=hi->bitrate_av; - ai->bitrate_av_hi=hi->bitrate_av; - - } - return(0); - - /* now deprecated *****************/ - case OV_ECTL_RATEMANAGE_SET: - { - struct ovectl_ratemanage_arg *ai= - (struct ovectl_ratemanage_arg *)arg; - if(ai==NULL){ - hi->managed=0; - }else{ - hi->managed=ai->management_active; - vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg); - vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg); - } - } - return 0; - - /* now deprecated *****************/ - case OV_ECTL_RATEMANAGE_AVG: - { - struct ovectl_ratemanage_arg *ai= - (struct ovectl_ratemanage_arg *)arg; - if(ai==NULL){ - hi->bitrate_av=0; - }else{ - hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5; - } - } - return(0); - /* now deprecated *****************/ - case OV_ECTL_RATEMANAGE_HARD: - { - struct ovectl_ratemanage_arg *ai= - (struct ovectl_ratemanage_arg *)arg; - if(ai==NULL){ - hi->bitrate_min=0; - hi->bitrate_max=0; - }else{ - hi->bitrate_min=ai->bitrate_hard_min; - hi->bitrate_max=ai->bitrate_hard_max; - hi->bitrate_reservoir=ai->bitrate_hard_window* - (hi->bitrate_max+hi->bitrate_min)*.5; - } - if(hi->bitrate_reservoir<128.) - hi->bitrate_reservoir=128.; - } - return(0); - - /* replacement ratemanage interface */ - case OV_ECTL_RATEMANAGE2_GET: - { - struct ovectl_ratemanage2_arg *ai= - (struct ovectl_ratemanage2_arg *)arg; - if(ai==NULL)return OV_EINVAL; - - ai->management_active=hi->managed; - ai->bitrate_limit_min_kbps=hi->bitrate_min/1000; - ai->bitrate_limit_max_kbps=hi->bitrate_max/1000; - ai->bitrate_average_kbps=hi->bitrate_av/1000; - ai->bitrate_average_damping=hi->bitrate_av_damp; - ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir; - ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias; - } - return (0); - case OV_ECTL_RATEMANAGE2_SET: - { - struct ovectl_ratemanage2_arg *ai= - (struct ovectl_ratemanage2_arg *)arg; - if(ai==NULL){ - hi->managed=0; - }else{ - /* sanity check; only catch invariant violations */ - if(ai->bitrate_limit_min_kbps>0 && - ai->bitrate_average_kbps>0 && - ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps) - return OV_EINVAL; - - if(ai->bitrate_limit_max_kbps>0 && - ai->bitrate_average_kbps>0 && - ai->bitrate_limit_max_kbpsbitrate_average_kbps) - return OV_EINVAL; - - if(ai->bitrate_limit_min_kbps>0 && - ai->bitrate_limit_max_kbps>0 && - ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps) - return OV_EINVAL; - - if(ai->bitrate_average_damping <= 0.) - return OV_EINVAL; - - if(ai->bitrate_limit_reservoir_bits < 0) - return OV_EINVAL; - - if(ai->bitrate_limit_reservoir_bias < 0.) - return OV_EINVAL; - - if(ai->bitrate_limit_reservoir_bias > 1.) - return OV_EINVAL; - - hi->managed=ai->management_active; - hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000; - hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000; - hi->bitrate_av=ai->bitrate_average_kbps * 1000; - hi->bitrate_av_damp=ai->bitrate_average_damping; - hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits; - hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias; - } - } - return 0; - - case OV_ECTL_LOWPASS_GET: - { - double *farg=(double *)arg; - *farg=hi->lowpass_kHz; - } - return(0); - case OV_ECTL_LOWPASS_SET: - { - double *farg=(double *)arg; - hi->lowpass_kHz=*farg; - - if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.; - if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.; - hi->lowpass_altered=1; - } - return(0); - case OV_ECTL_IBLOCK_GET: - { - double *farg=(double *)arg; - *farg=hi->impulse_noisetune; - } - return(0); - case OV_ECTL_IBLOCK_SET: - { - double *farg=(double *)arg; - hi->impulse_noisetune=*farg; - - if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.; - if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.; - } - return(0); - case OV_ECTL_COUPLING_GET: - { - int *iarg=(int *)arg; - *iarg=hi->coupling_p; - } - return(0); - case OV_ECTL_COUPLING_SET: - { - const void *new_template; - double new_base=0.; - int *iarg=(int *)arg; - hi->coupling_p=((*iarg)!=0); - - /* Fetching a new template can alter the base_setting, which - many other parameters are based on. Right now, the only - parameter drawn from the base_setting that can be altered - by an encctl is the lowpass, so that is explictly flagged - to not be overwritten when we fetch a new template and - recompute the dependant settings */ - new_template = get_setup_template(hi->coupling_p?vi->channels:-1, - vi->rate, - hi->req, - hi->managed, - &new_base); - if(!new_template)return OV_EIMPL; - hi->setup=new_template; - hi->base_setting=new_base; - vorbis_encode_setup_setting(vi,vi->channels,vi->rate); - } - return(0); - } - return(OV_EIMPL); - } - return(OV_EINVAL); -} diff --git a/code/thirdparty/opus-1.5.2/src/mapping_matrix.c b/code/thirdparty/opus-1.5.2/src/mapping_matrix.c deleted file mode 100644 index 3f78ab59..00000000 --- a/code/thirdparty/opus-1.5.2/src/mapping_matrix.c +++ /dev/null @@ -1,939 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "arch.h" -#include "float_cast.h" -#include "opus_private.h" -#include "opus_defines.h" -#include "mapping_matrix.h" - -#define MATRIX_INDEX(nb_rows, row, col) (nb_rows * col + row) - -opus_int32 mapping_matrix_get_size(int rows, int cols) -{ - opus_int32 size; - - /* Mapping Matrix must only support up to 255 channels in or out. - * Additionally, the total cell count must be <= 65004 octets in order - * for the matrix to be stored in an OGG header. - */ - if (rows > 255 || cols > 255) - return 0; - size = rows * (opus_int32)cols * sizeof(opus_int16); - if (size > 65004) - return 0; - - return align(sizeof(MappingMatrix)) + align(size); -} - -opus_int16 *mapping_matrix_get_data(const MappingMatrix *matrix) -{ - /* void* cast avoids clang -Wcast-align warning */ - return (opus_int16*)(void*)((char*)matrix + align(sizeof(MappingMatrix))); -} - -void mapping_matrix_init(MappingMatrix * const matrix, - int rows, int cols, int gain, const opus_int16 *data, opus_int32 data_size) -{ - int i; - opus_int16 *ptr; - -#if !defined(ENABLE_ASSERTIONS) - (void)data_size; -#endif - celt_assert(align(data_size) == align(rows * cols * sizeof(opus_int16))); - - matrix->rows = rows; - matrix->cols = cols; - matrix->gain = gain; - ptr = mapping_matrix_get_data(matrix); - for (i = 0; i < rows * cols; i++) - { - ptr[i] = data[i]; - } -} - -#ifndef DISABLE_FLOAT_API -void mapping_matrix_multiply_channel_in_float( - const MappingMatrix *matrix, - const float *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size) -{ - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, col; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) - { - float tmp = 0; - for (col = 0; col < input_rows; col++) - { - tmp += - matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * - input[MATRIX_INDEX(input_rows, col, i)]; - } -#if defined(FIXED_POINT) - output[output_rows * i] = FLOAT2INT16((1/32768.f)*tmp); -#else - output[output_rows * i] = (1/32768.f)*tmp; -#endif - } -} - -void mapping_matrix_multiply_channel_out_float( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - float *output, - int output_rows, - int frame_size -) -{ - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, row; - float input_sample; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) - { -#if defined(FIXED_POINT) - input_sample = (1/32768.f)*input[input_rows * i]; -#else - input_sample = input[input_rows * i]; -#endif - for (row = 0; row < output_rows; row++) - { - float tmp = - (1/32768.f)*matrix_data[MATRIX_INDEX(matrix->rows, row, input_row)] * - input_sample; - output[MATRIX_INDEX(output_rows, row, i)] += tmp; - } - } -} -#endif /* DISABLE_FLOAT_API */ - -void mapping_matrix_multiply_channel_in_short( - const MappingMatrix *matrix, - const opus_int16 *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size) -{ - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, col; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) - { - opus_val32 tmp = 0; - for (col = 0; col < input_rows; col++) - { -#if defined(FIXED_POINT) - tmp += - ((opus_int32)matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * - (opus_int32)input[MATRIX_INDEX(input_rows, col, i)]) >> 8; -#else - tmp += - matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * - input[MATRIX_INDEX(input_rows, col, i)]; -#endif - } -#if defined(FIXED_POINT) - output[output_rows * i] = (opus_int16)((tmp + 64) >> 7); -#else - output[output_rows * i] = (1/(32768.f*32768.f))*tmp; -#endif - } -} - -void mapping_matrix_multiply_channel_out_short( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - opus_int16 *output, - int output_rows, - int frame_size) -{ - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, row; - opus_int32 input_sample; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) - { -#if defined(FIXED_POINT) - input_sample = (opus_int32)input[input_rows * i]; -#else - input_sample = (opus_int32)FLOAT2INT16(input[input_rows * i]); -#endif - for (row = 0; row < output_rows; row++) - { - opus_int32 tmp = - (opus_int32)matrix_data[MATRIX_INDEX(matrix->rows, row, input_row)] * - input_sample; - output[MATRIX_INDEX(output_rows, row, i)] += (tmp + 16384) >> 15; - } - } -} - -const MappingMatrix mapping_matrix_foa_mixing = { 6, 6, 0 }; -const opus_int16 mapping_matrix_foa_mixing_data[36] = { - 16384, 0, -16384, 23170, 0, 0, 16384, 23170, - 16384, 0, 0, 0, 16384, 0, -16384, -23170, - 0, 0, 16384, -23170, 16384, 0, 0, 0, - 0, 0, 0, 0, 32767, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_soa_mixing = { 11, 11, 0 }; -const opus_int16 mapping_matrix_soa_mixing_data[121] = { - 10923, 7723, 13377, -13377, 11585, 9459, 7723, -16384, - -6689, 0, 0, 10923, 7723, 13377, 13377, -11585, - 9459, 7723, 16384, -6689, 0, 0, 10923, -15447, - 13377, 0, 0, -18919, 7723, 0, 13377, 0, - 0, 10923, 7723, -13377, -13377, 11585, -9459, 7723, - 16384, -6689, 0, 0, 10923, -7723, 0, 13377, - -16384, 0, -15447, 0, 9459, 0, 0, 10923, - -7723, 0, -13377, 16384, 0, -15447, 0, 9459, - 0, 0, 10923, 15447, 0, 0, 0, 0, - -15447, 0, -18919, 0, 0, 10923, 7723, -13377, - 13377, -11585, -9459, 7723, -16384, -6689, 0, 0, - 10923, -15447, -13377, 0, 0, 18919, 7723, 0, - 13377, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 32767, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32767 -}; - -const MappingMatrix mapping_matrix_toa_mixing = { 18, 18, 0 }; -const opus_int16 mapping_matrix_toa_mixing_data[324] = { - 8208, 0, -881, 14369, 0, 0, -8192, -4163, - 13218, 0, 0, 0, 11095, -8836, -6218, 14833, - 0, 0, 8208, -10161, 881, 10161, -13218, -2944, - -8192, 2944, 0, -10488, -6218, 6248, -11095, -6248, - 0, -10488, 0, 0, 8208, 10161, 881, -10161, - -13218, 2944, -8192, -2944, 0, 10488, -6218, -6248, - -11095, 6248, 0, 10488, 0, 0, 8176, 5566, - -11552, 5566, 9681, -11205, 8192, -11205, 0, 4920, - -15158, 9756, -3334, 9756, 0, -4920, 0, 0, - 8176, 7871, 11552, 0, 0, 15846, 8192, 0, - -9681, -6958, 0, 13797, 3334, 0, -15158, 0, - 0, 0, 8176, 0, 11552, 7871, 0, 0, - 8192, 15846, 9681, 0, 0, 0, 3334, 13797, - 15158, 6958, 0, 0, 8176, 5566, -11552, -5566, - -9681, -11205, 8192, 11205, 0, 4920, 15158, 9756, - -3334, -9756, 0, 4920, 0, 0, 8208, 14369, - -881, 0, 0, -4163, -8192, 0, -13218, -14833, - 0, -8836, 11095, 0, 6218, 0, 0, 0, - 8208, 10161, 881, 10161, 13218, 2944, -8192, 2944, - 0, 10488, 6218, -6248, -11095, -6248, 0, -10488, - 0, 0, 8208, -14369, -881, 0, 0, 4163, - -8192, 0, -13218, 14833, 0, 8836, 11095, 0, - 6218, 0, 0, 0, 8208, 0, -881, -14369, - 0, 0, -8192, 4163, 13218, 0, 0, 0, - 11095, 8836, -6218, -14833, 0, 0, 8176, -5566, - -11552, 5566, -9681, 11205, 8192, -11205, 0, -4920, - 15158, -9756, -3334, 9756, 0, -4920, 0, 0, - 8176, 0, 11552, -7871, 0, 0, 8192, -15846, - 9681, 0, 0, 0, 3334, -13797, 15158, -6958, - 0, 0, 8176, -7871, 11552, 0, 0, -15846, - 8192, 0, -9681, 6958, 0, -13797, 3334, 0, - -15158, 0, 0, 0, 8176, -5566, -11552, -5566, - 9681, 11205, 8192, 11205, 0, -4920, -15158, -9756, - -3334, -9756, 0, 4920, 0, 0, 8208, -10161, - 881, -10161, 13218, -2944, -8192, -2944, 0, -10488, - 6218, 6248, -11095, 6248, 0, 10488, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32767, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_fourthoa_mixing = { 27, 27, 0 }; -const opus_int16 mapping_matrix_fourthoa_mixing_data[729] = { - 9243, 0, 16010, 0, 0, 0, 20669, 0, - 0, 0, 0, 0, 24456, 0, 0, 0, - 0, 0, 0, 0, 27731, 0, 0, 0, - 0, 0, 0, 9243, 0, 10884, 11741, 0, - 0, 3995, 17849, 9626, 0, 0, 0, -5727, - 14399, 17315, 7625, 0, 0, 0, 0, -11747, - 2574, 18637, 15552, 5930, 0, 0, 9243, -14302, - -2682, -6677, 13337, 5357, -9464, 2501, -11170, 4770, - -5911, 11501, 5858, 5369, 4951, 17901, -19071, -2397, - -9281, -9198, 7576, -4294, 7773, -8997, -3399, 0, - 0, 9243, 9940, 11991, -3705, -5144, 16647, 7057, - -6206, -5941, -2698, -10194, 16781, -1788, -6256, -11772, - 4935, 3912, -6062, -13039, 9446, -9758, -3521, -15058, - 11089, 565, 0, 0, 9243, -15376, 3720, 2461, - -5285, -7989, -8660, 1278, -16087, 15811, -3249, 10500, - -7757, -1680, -9890, -8153, 10884, 11022, 2847, 12828, - 5137, -2053, 8666, -5684, 14776, 0, 0, 9243, - -10577, 10304, -6186, 9139, -15222, 2507, -8902, -5140, - -145, 15562, -10596, -7311, -6197, -8753, 8667, -6014, - -281, 15033, 938, -11859, 548, -8456, 16735, -3654, - 0, 0, 9243, 8974, 4839, -12343, -15472, 6066, - -7501, -8343, 5015, 15920, -12374, -4559, -9400, 6271, - 4011, 5191, -9932, 14438, 4828, -8768, 1909, 12059, - -1565, 4707, -13711, 0, 0, 9243, 15799, 2085, - -1534, -3386, 4602, -9808, -447, -17267, -18054, -1167, - -13525, -4644, 1313, -5951, 5397, 7485, -7056, 2584, - -8120, 8669, 788, 13177, 2109, 18349, 0, 0, - 9243, 12371, -10036, 1597, 2760, -17341, 1848, -2239, - -10509, -8474, -4577, 11164, 7935, 1441, 17430, -3436, - -3713, 15936, 4184, 2647, -11730, 341, -15934, 6462, - 6581, 0, 0, 9243, -8963, 2184, 13084, -16381, - -2734, -9757, 3991, 6345, -18297, -5912, 7604, -4849, - -11100, 2290, -4304, -13305, -7488, 12338, 4805, 8505, - -7014, -4779, -1761, -14597, 0, 0, 9243, 1301, - -15498, 3799, 690, -2816, 18718, -8223, 889, 255, - -1768, 4485, -19951, 13097, -2278, 167, 78, -740, - 3324, -6139, 19488, -17925, 4283, -486, 20, 0, - 0, 9243, -13470, -6719, 5452, -10257, 12641, -4873, - -5116, -10595, 5856, 11389, 1502, 10876, -608, 11765, - -13218, 13911, -7373, -2070, -13679, -4154, 5536, -2138, - 16643, 451, 0, 0, 9243, 2455, -3679, -15387, - -5277, -1261, -8697, 7906, 16112, 8147, 3208, -1690, - 7687, 10593, -9796, -15852, -10884, -5616, 2881, 2032, - 5246, -12735, -8796, 10928, 14833, 0, 0, 9243, - -6849, 2775, -14202, 13586, -2655, -9402, -5505, 10809, - -18013, 6231, 5444, -6041, 11288, 4958, -4078, 18799, - -9368, -9291, 4535, 7383, 9405, -7391, -2121, -4336, - 0, 0, 9243, 6423, -9040, 11548, 10359, -8109, - -450, -14580, 6431, 10857, -15475, 3569, 9707, 6416, - -9607, 521, 8528, -18391, 11049, 3815, -10423, 6860, - 6860, -883, -4221, 0, 0, 9243, 11932, -5968, - -8850, -14749, -9946, -6026, 7377, -4472, 5206, 14547, - -3406, 10508, 2526, 4411, 14543, 8444, -5822, 347, - 12347, -1709, -9158, 105, -16265, -12642, 0, 0, - 9243, 13044, -150, 9282, 16910, -274, -10332, -194, - -5864, 5428, -420, -12196, 344, -8679, 145, -18554, - -12695, -152, -14635, 503, 10389, 358, 5076, 522, - -16100, 0, 0, 9243, -8374, -13590, -1221, 1428, - 15896, 12005, 2318, -4793, 2590, -3209, -20390, -6256, - -2974, 10766, 1202, -876, -6597, 5004, 19896, -1541, - 2902, -16788, -3062, 1340, 0, 0, 9243, 9879, - 10267, 7300, 10073, 14167, 2416, 10469, -3094, 2899, - 17092, 9762, -7400, 7214, -5250, -8238, -3989, 5578, - 16392, -1050, -11848, -776, -5034, -15850, -5882, 0, - 0, 9243, -4974, -9068, 12221, -8490, 6299, -388, - -15478, 8702, -9920, 12723, -2810, 9668, 6905, -13040, - 4325, -9456, 16856, -9159, -2909, -10476, 7149, 9387, - -7350, 233, 0, 0, 9243, 3627, -13823, -7218, - -3656, -7002, 12776, 13935, 2719, 2446, 8352, 9252, - -7676, -18413, -6212, -429, -1272, -6335, -13356, -9510, - 295, 18926, 9934, 1112, -382, 0, 0, 9243, - -6383, -9343, -11326, 10097, 8329, 223, 14780, 6114, - -10348, -15590, -4195, 9257, -7445, -9439, -323, 7902, - 18117, 12101, -3142, -10944, -5577, 7327, 566, -4133, - 0, 0, 9243, 2626, 865, 15769, 5783, 317, - -10244, 1905, 16884, 9144, 826, -2420, -1972, -14536, - 2413, 16939, 12500, 1482, -4906, -578, 10096, -3476, - -14323, 2745, 16105, 0, 0, 9243, -8975, 12086, - 5450, -6832, -15149, 7333, 9200, -3550, -362, -13645, - -15525, -1391, 9428, -7091, -5442, 3105, -820, -17685, - -9175, -9462, 5572, -9191, -12325, -2180, 0, 0, - 9243, -114, 11576, -11058, 177, -185, 5875, -17880, - 8539, -198, 339, -173, -3411, -16698, 16336, -6369, - 193, -430, 408, -75, -10806, -7225, 19670, -13817, - 4665, 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, 32767, 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, - 32767 -}; - -const MappingMatrix mapping_matrix_fifthoa_mixing = { 38, 38, 0 }; -const opus_int16 mapping_matrix_fifthoa_mixing_data[1444] = { - 9243, 0, 16010, 0, 0, 0, 20669, 0, - 0, 0, 0, 0, 24456, 0, 0, 0, - 0, 0, 0, 0, 27731, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 30657, 0, - 0, 0, 0, 0, 0, 0, 9243, 0, - -7023, 14387, 0, 0, -4369, -14112, 14455, 0, - 0, 0, 10931, -510, -16777, 14031, 0, 0, - 0, 0, -5118, 14286, 4343, -18465, 13374, 0, - 0, 0, 0, 0, -6494, -12221, 11761, 8513, - -19458, 12605, 0, 0, 9243, -14128, 5093, 5547, - -10946, -10050, -7197, 3945, -11790, 7142, -9213, 6529, - -9701, -2563, -9923, -14846, 16521, 6816, 2764, 14103, - 1118, -5537, 2977, -14168, 1228, 4866, 17430, -528, - 10639, 2641, 10437, -1037, 11460, 1098, 1296, 15737, - 0, 0, 9243, 1128, -14775, 6062, 955, -2329, - 16069, -12511, 2477, 579, -2333, 3440, -14197, 18478, - -6050, 940, 303, -1604, 4106, -4223, 9829, -22688, - 10647, -2604, 334, 145, -927, 3203, -6017, 4507, - -3812, 24212, -15600, 5198, -1023, 110, 0, 0, - 9243, 1158, 12997, 9277, 1501, 2103, 10097, 16840, - 5916, 1402, 3225, 2488, 2929, 19916, 12706, 3585, - 1137, 3415, 4698, 2078, -5442, 16634, 18511, 8731, - 2095, 850, 3061, 5733, 5225, 960, -11728, 7689, - 20588, 14659, 5642, 1187, 0, 0, 9243, -4663, - -3081, -15003, 9771, 2007, -9185, 6457, 14199, -14357, - -4976, 3554, 6625, 11434, -7231, -11297, 17760, 8291, - -6267, -3368, 6712, -10837, -9107, 6524, 6793, -19531, - -11338, 7934, 7335, -2205, -9215, -7094, 10659, 6243, - -4337, -1250, 0, 0, 9243, -13515, 7679, -3831, - 7232, -14496, -3201, -4109, -11731, 8828, 9178, -1901, - -10848, -539, -14888, 9626, -10860, 12703, 3824, 12334, - -7104, 3496, -6203, 13852, 5461, -2109, -17277, 7837, - -4714, 13901, 4097, 3940, 7647, 8546, 8688, -10986, - 0, 0, 9243, 8113, -9860, 9657, 10943, -11174, - 1426, -13300, 1915, 8178, -17833, 6805, 8309, 8100, - -3121, -4742, 2683, -15111, 15688, 2358, -11590, 2807, - 2746, 8762, -7430, -2251, -5481, 16370, -4081, -9694, - 5872, -11539, -714, -9492, 15177, -6126, 0, 0, - 9243, 9933, -9215, -8528, -11831, -12785, -62, 10976, - -1811, 5593, 18018, 6100, 9455, -5237, 2758, 8971, - 2743, -9659, -13517, 5330, -10737, -4576, -2069, -15491, - -8749, -7226, -5237, 9191, -181, -12277, 2815, 10540, - -27, 14741, 16703, 3103, 0, 0, 9243, -10067, - -8881, -8723, 12265, 12487, -793, 10821, -1762, -6021, - -18002, -5072, 9912, -4395, 2587, 9368, -2767, 10021, - 12259, -6468, -10113, -5605, -1761, -15590, -9430, 7800, - 5092, -8835, 2293, 12314, 1222, 10671, -329, 13745, - 17349, 3563, 0, 0, 9243, -6485, 12991, -6743, - 6108, -11768, 10080, -12236, 238, -2883, 13115, -13907, - 2900, -14460, 511, 2564, 186, -7019, 19094, -11597, - -5472, -12058, 744, 6243, -2384, 930, 501, -11778, - 21214, -5330, -11746, -5542, 827, 10475, -6418, 1132, - 0, 0, 9243, 3862, 5238, -14627, -7891, 2826, - -7015, -10701, 13900, 11410, -6831, -1679, -9861, 6359, - 12032, -11660, -14041, 11199, 1713, -3895, 657, 14749, - -3017, -11445, 8380, 15575, -15236, -346, 7690, -923, - 10317, 3498, -13545, 354, 9093, -4476, 0, 0, - 9243, -8417, 13183, 3418, -4018, -15498, 10685, 6294, - -4132, 1419, -8755, -18818, 3926, 7642, -9001, -3235, - 2125, 3506, -13037, -16570, -4337, 6729, -13404, -7991, - 59, 443, 5804, 6005, -15011, -9060, -11044, 3679, - -15434, -13685, 161, 1185, 0, 0, 9243, -5288, - 6773, -13508, 9977, -5002, -4784, -12780, 10790, -12942, - 11168, 519, -10890, 1326, 12078, -6274, 13780, -16427, - 2186, 5352, -4328, 13671, 2364, -7963, 1080, -12568, - 19336, -6557, -8574, 4084, 7277, 10433, -9273, -3178, - 1516, 3817, 0, 0, 9243, 9660, 7817, 10093, - 13619, 10548, -2942, 11021, 597, 9663, 17594, 1736, - -10794, 1814, 771, -8469, 1041, 14155, 7891, -8597, - -7498, -8982, 346, -12407, -11848, -6809, 1686, 9181, - -8306, -10247, 3538, -10706, -364, -8047, -19188, -8493, - 0, 0, 9243, -7163, -1020, 14282, -14289, 1021, - -10208, -2036, 10660, -18919, 2410, 6564, 2323, -13088, - -1798, 3365, -19498, 3619, 12022, -1858, 9978, 3705, - -8969, -643, -5794, -15523, 4123, 15113, -3949, -6265, - -3596, 12490, 2946, -2688, 1225, -14570, 0, 0, - 9243, -12187, 772, -10354, 17623, -1314, -10262, -1117, - -2885, -9937, 2249, 11267, -1763, 9572, -368, 16506, - -6510, -1438, -15014, 2402, 10157, 2041, 2458, 2389, - -19346, 19860, -1041, 8067, -3704, -10931, 2743, -9286, - 606, -13399, -3095, 7924, 0, 0, 9243, 15545, - -2367, -3011, -6538, -5139, -9657, 995, -16242, -15706, - 2557, -12952, 5226, 2508, 6353, 10156, 13593, 6966, - 4795, 8960, 8183, -1735, 11914, -4504, 14149, 11727, - -6665, 10460, -3962, 10145, -7648, -1965, -9845, -6764, - -6938, -16633, 0, 0, 9243, 3098, 12983, -8841, - -3826, 5618, 10053, -16031, 4787, 3283, -8209, 6632, - 2856, -18922, 10272, -2055, -2344, 7987, -11939, 5516, - -5520, -15739, 14940, -5001, 530, 1465, -6306, 13388, - -13243, 2513, -11772, -7170, 16572, -8384, 1426, 168, - 0, 0, 9243, -15767, -2008, -1916, 4220, 4422, - -9846, 537, -17105, 17650, -1400, 13589, 4481, 1651, - 5677, 6701, -9241, -6642, -3252, -7827, 8792, -951, - 13182, -2522, 17586, -17005, 3845, -12562, 2213, -11472, - -6688, -1394, -8970, -4769, -7316, -11753, 0, 0, - 9243, -13344, -3829, 7975, -14863, 7136, -8561, -4265, - -7992, -801, 9405, 8912, 7937, -5326, 5057, -17681, - 15207, 575, 7717, -11360, 4847, 6789, 4150, 12686, - -10050, 16730, -12063, 322, -12920, -3313, -10267, 1980, - -6948, 7112, 7972, 8042, 0, 0, 9243, 7791, - -1021, 13949, 15180, -1111, -10208, -1989, 9348, 19199, - -2561, -7140, 2323, -12782, -1577, 817, 18164, -3673, - -12771, 2022, 9978, 3620, -7865, -156, -9155, 11924, - -3842, -15336, 4196, 6814, -3596, 12199, 2583, -652, - 1936, -17637, 0, 0, 9243, -4810, -15144, -1958, - 1315, 10175, 17406, 4142, -1348, 263, -3292, -15632, - -17046, -6363, 3374, 605, -227, -748, 5997, 20334, - 14481, 8277, -6146, -1717, 5, 27, 712, 1542, - -9197, -23572, -10163, -9595, 9425, 3539, -17, -72, - 0, 0, 9243, -7366, 8261, 11568, -11901, -8499, - -2079, 13347, 5556, -12049, -16247, -2282, -10529, 3584, - 7585, -1577, -8464, -18652, -8902, 5913, -8688, -9287, - 4156, -2442, -7089, -2993, -14485, -13949, 5422, 8459, - 1638, -13285, -2531, -1826, -12132, -9456, 0, 0, - 9243, 11716, 698, -10889, -17818, 1143, -10275, -1062, - -1305, 12057, -2057, -10855, -1595, 10088, -150, 15043, - 2978, 1578, 15225, -2090, 10201, 1943, 1115, 1969, - -20211, -17636, 430, -9826, 3391, 10572, 2485, -9826, - 248, -12259, -2924, 12131, 0, 0, 9243, 4361, - -4594, -14703, -8956, -2798, -7781, 9434, 13769, 12936, - 6800, -2400, 9082, 8091, -10453, -11023, -15786, -11136, - 3285, 4153, 2658, -14002, -5051, 9489, 7000, 17206, - 15024, -2777, -8491, -42, -10626, 141, 13053, 2366, - -6662, -2231, 0, 0, 9243, -752, -11933, -10646, - 1119, 1254, 6890, 17745, 7875, -1203, -2207, -1251, - 2024, -17706, -15532, -5600, 1128, 2691, 2800, 683, - -9927, 9661, 19706, 12522, 3889, -978, -2789, -3992, - -2440, 206, 12695, 2921, -17173, -18575, -9616, -2657, - 0, 0, 9243, 4791, -15001, -2887, -1931, -10037, - 16885, 6048, -1020, 46, 4789, 15191, -15922, -9154, - 2530, 823, 252, -130, -8608, -19335, 12613, 11651, - -4549, -2314, -172, -101, -784, 265, 12975, 21741, - -7551, -13101, 6856, 4710, 535, -46, 0, 0, - 9243, -12153, -10395, 754, -1281, 17644, 2735, -1095, - -10274, 8359, 2200, -12593, 7083, 782, 17650, -1573, - 1685, -16282, -2164, -530, -11878, 32, -17359, 3065, - 6651, -5212, -3628, 19365, 965, 13180, 8243, -818, - 7746, -3645, -14323, 1670, 0, 0, 9243, -6961, - -11198, 9081, -8829, 10887, 4833, -14202, 2374, -6524, - 16339, -9417, 4737, 12284, -4394, -2691, -2683, 13690, - -18539, 2830, -11438, -3692, 4985, 5648, -4628, 514, - 6225, -18409, 12672, 5311, 11170, -6928, -3407, -7595, - 10737, -3977, 0, 0, 9243, 12099, -10405, 1294, - 2187, -17582, 2760, -1880, -10105, -8058, -3760, 12583, - 7058, 1346, 17376, -2667, -2829, 15710, 3705, 468, - -11880, 50, -17123, 5201, 6230, 4698, 6098, -18716, - -1665, -13088, 8285, -1400, 7696, -6196, -13429, 2770, - 0, 0, 9243, 8602, 13392, 1722, 2070, 16090, - 11359, 3222, -4960, -2638, 4581, 20106, 5099, 4026, - -10978, -1778, -1314, -6620, 6988, 18701, -2965, 3745, - -16745, -4461, 1300, 584, -3646, -11588, 8350, 11847, - -10050, 2372, -20010, -7809, 3608, 887, 0, 0, - 9243, 14252, -1958, 7026, 13986, -3899, -9870, -1922, - -10736, -3693, -4527, -12333, 4376, -6080, 3475, -18537, - -19222, 1355, -10843, 6913, 8869, 3408, 8323, 6804, - -5141, -13648, 7800, 2649, 7171, 10505, -6548, 5179, - -5505, 13299, 2086, 15579, 0, 0, 9243, 11323, - 9021, -6835, -10810, 14267, -489, -8613, -5689, 639, - -16117, 6224, -9731, -3757, -8482, 10882, 7873, 1080, - -11447, -6791, -10388, 4099, -6025, 18396, -5407, -7536, - 14714, 984, 1267, -13940, -1889, 8416, 666, 16762, - -10106, -3418, 0, 0, 9243, 871, 4833, 15238, - 1855, 588, -7508, 10287, 16162, 2857, 1481, -443, - -9392, -7758, 12910, 16506, 3837, 2588, -581, -851, - 1928, -14879, -5066, 14950, 16498, 4773, 3842, -425, - -1785, -82, 10578, -1435, -15554, -2459, 16520, 16250, - 0, 0, 9243, 14762, 5967, 1673, 3450, 12303, - -6027, 1394, -15022, -14571, 3402, -4217, -10507, -478, - -14813, -5131, -6634, -16293, -82, -15276, -1705, -1731, - 358, -5738, 13681, 12503, -8200, -3023, -3290, -7384, - 9272, -837, 14328, -1064, 16913, 7915, 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, 32767, 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, 32767 -}; - -const MappingMatrix mapping_matrix_foa_demixing = { 6, 6, 0 }; -const opus_int16 mapping_matrix_foa_demixing_data[36] = { - 16384, 16384, 16384, 16384, 0, 0, 0, 23170, - 0, -23170, 0, 0, -16384, 16384, -16384, 16384, - 0, 0, 23170, 0, -23170, 0, 0, 0, - 0, 0, 0, 0, 32767, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_soa_demixing = { 11, 11, 3050 }; -const opus_int16 mapping_matrix_soa_demixing_data[121] = { - 2771, 2771, 2771, 2771, 2771, 2771, 2771, 2771, - 2771, 0, 0, 10033, 10033, -20066, 10033, 14189, - 14189, -28378, 10033, -20066, 0, 0, 3393, 3393, - 3393, -3393, 0, 0, 0, -3393, -3393, 0, - 0, -17378, 17378, 0, -17378, -24576, 24576, 0, - 17378, 0, 0, 0, -14189, 14189, 0, -14189, - -28378, 28378, 0, 14189, 0, 0, 0, 2399, - 2399, -4799, -2399, 0, 0, 0, -2399, 4799, - 0, 0, 1959, 1959, 1959, 1959, -3918, -3918, - -3918, 1959, 1959, 0, 0, -4156, 4156, 0, - 4156, 0, 0, 0, -4156, 0, 0, 0, - 8192, 8192, -16384, 8192, 16384, 16384, -32768, 8192, - -16384, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 8312, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 8312 -}; - -const MappingMatrix mapping_matrix_toa_demixing = { 18, 18, 0 }; -const opus_int16 mapping_matrix_toa_demixing_data[324] = { - 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, - 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, - 0, 0, 0, -9779, 9779, 6263, 8857, 0, - 6263, 13829, 9779, -13829, 0, -6263, 0, -8857, - -6263, -9779, 0, 0, -3413, 3413, 3413, -11359, - 11359, 11359, -11359, -3413, 3413, -3413, -3413, -11359, - 11359, 11359, -11359, 3413, 0, 0, 13829, 9779, - -9779, 6263, 0, 8857, -6263, 0, 9779, 0, - -13829, 6263, -8857, 0, -6263, -9779, 0, 0, - 0, -15617, -15617, 6406, 0, 0, -6406, 0, - 15617, 0, 0, -6406, 0, 0, 6406, 15617, - 0, 0, 0, -5003, 5003, -10664, 15081, 0, - -10664, -7075, 5003, 7075, 0, 10664, 0, -15081, - 10664, -5003, 0, 0, -8176, -8176, -8176, 8208, - 8208, 8208, 8208, -8176, -8176, -8176, -8176, 8208, - 8208, 8208, 8208, -8176, 0, 0, -7075, 5003, - -5003, -10664, 0, 15081, 10664, 0, 5003, 0, - 7075, -10664, -15081, 0, 10664, -5003, 0, 0, - 15617, 0, 0, 0, -6406, 6406, 0, -15617, - 0, -15617, 15617, 0, 6406, -6406, 0, 0, - 0, 0, 0, -11393, 11393, 2993, -4233, 0, - 2993, -16112, 11393, 16112, 0, -2993, 0, 4233, - -2993, -11393, 0, 0, 0, -9974, -9974, -13617, - 0, 0, 13617, 0, 9974, 0, 0, 13617, - 0, 0, -13617, 9974, 0, 0, 0, 5579, - -5579, 10185, 14403, 0, 10185, -7890, -5579, 7890, - 0, -10185, 0, -14403, -10185, 5579, 0, 0, - 11826, -11826, -11826, -901, 901, 901, -901, 11826, - -11826, 11826, 11826, -901, 901, 901, -901, -11826, - 0, 0, -7890, -5579, 5579, 10185, 0, 14403, - -10185, 0, -5579, 0, 7890, 10185, -14403, 0, - -10185, 5579, 0, 0, -9974, 0, 0, 0, - -13617, 13617, 0, 9974, 0, 9974, -9974, 0, - 13617, -13617, 0, 0, 0, 0, 16112, -11393, - 11393, -2993, 0, 4233, 2993, 0, -11393, 0, - -16112, -2993, -4233, 0, 2993, 11393, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32767, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_fourthoa_demixing = { 27, 27, 0 }; -const opus_int16 mapping_matrix_fourthoa_demixing_data[729] = { - 4870, 4484, 4870, 4347, 4440, 4726, 4683, 4821, - 4883, 4842, 4603, 4484, 4683, 4698, 4234, 4368, - 4603, 4783, 4783, 4820, 4821, 4347, 4820, 4440, - 4698, 0, 0, 101, 84, -7818, 4640, -7178, - -5492, 4629, 8384, 6547, -4966, 617, -6345, 1061, - -3241, 2939, 5549, 6390, -4434, 4994, -2610, 1993, - -2873, 1547, -4356, -164, 0, 0, 8797, 5074, - -1553, 5383, 1906, 5297, 2722, 1158, -5226, 1311, - -7760, -3327, -1940, 1586, -4093, -2951, -214, -6873, - 5450, -4875, -7193, -4438, 558, 5593, 5607, 0, - 0, -26, 5761, -3723, -1460, 1195, -3065, -6357, - -1175, 608, 6965, 2310, 2759, -8023, -7138, 5162, - -3624, 5006, -809, 3592, 6209, -4159, -4968, 8150, - 2513, -5702, 0, 0, 301, 109, 7161, -2462, - -2443, 5044, -7125, -2256, 1967, -9107, 259, -4928, - -2592, 6514, 4111, -7236, 8695, 635, 5009, -4025, - -1937, 4794, 3420, -3507, -400, 0, 0, -134, - 85, 2771, 7842, -3649, -8225, 2866, 2586, -9200, - -1945, -1563, 6155, -720, -1061, -3494, -4513, -487, - 8389, 7317, 3348, -3721, 3806, 371, -6896, 70, - 0, 0, 10919, 2072, -4867, 3472, -4429, 1721, - -4066, -5193, 1032, -5253, 9501, -2017, -3971, -5261, - -306, -2737, -5137, 5713, 1237, -8, 6387, 364, - -5423, 3364, 2888, 0, 0, -48, 8946, 1048, - -2691, 602, -4332, -4302, -514, -1730, 2459, -4328, - -2156, 3335, -2748, -6029, 4023, 155, 897, 5268, - -8380, 7625, 7395, 508, 3945, -8951, 0, 0, - 39, 4151, -5965, -3398, -7006, -3534, 2697, -8989, - -5237, 2913, 46, -5540, 8196, 5766, 2711, -2520, - -3043, -2146, -948, 4965, 1806, 2472, 8988, -1266, - 4840, 0, 0, -407, -189, 2179, -1627, 6516, - 259, 7196, -9449, -4905, -9766, 561, 4021, 3371, - -8650, 5032, 3329, 2534, 641, 2224, -5747, 1047, - -4074, 5252, -24, 674, 0, 0, 664, 237, - -2837, -4072, -1205, 8252, -5875, -1670, -2743, -3984, - 381, 5059, 1765, 2666, -8295, 7403, 1154, -2086, - 7622, 7105, 3677, -6943, 1050, -6632, -694, 0, - 0, 382, -133, 5699, 7650, 5154, -5713, -1645, - -6902, 6181, 4450, 1151, 410, -993, 3829, 2444, - -2405, -6618, -9514, 5366, -1896, 5844, -2886, -1524, - -7321, -1007, 0, 0, 12767, -2530, 3183, -1409, - -4015, -2894, -5155, -1710, 3841, -2107, -10274, 5119, - 3979, -4010, 5550, 4822, -746, -2507, -3080, 4289, - -3675, 4333, -1416, -1230, -1122, 0, 0, 17, - 8048, 2398, -2167, -73, -3606, 3125, 398, 731, - -5973, 5705, -1032, 4679, 7305, 3134, 1301, -3858, - -89, 2938, 4359, -9155, -4805, -8407, 3673, -8645, - 0, 0, 187, 7355, 3145, -6719, -4432, -5939, - 2541, -2810, 9723, 778, -1105, 5687, -4174, 2534, - -4461, 1017, -244, 5481, -1655, -6765, -3350, -4894, - 1592, -2318, 8827, 0, 0, 196, 3588, 9631, - 3063, -4564, 6043, 2683, 2595, -2488, -2186, 173, - -6059, -8270, -2386, 409, 7441, -8608, 376, -4364, - 2321, -280, 97, 8331, -3022, -4721, 0, 0, - 117, -748, -10833, 1533, 4200, -2875, -997, -109, - -3661, -6119, 4454, 8808, -9189, 8294, 1521, 7265, - -2348, -5094, -948, -5400, -3193, 8914, 5763, 1716, - -1070, 0, 0, 2497, 399, -5201, -2038, 7843, - -376, 7567, -5073, 7616, -5537, 2086, -3453, -5544, - -56, -11648, -1314, 3546, -3432, -117, 8694, -4245, - 9621, 3098, -2582, -2351, 0, 0, 4386, -3104, - -3132, -10512, 566, 5217, 5128, 4967, 1348, 7035, - -1470, 91, -125, -3548, 8244, -3029, -10033, 2186, - 9745, -6440, -2074, 3638, -1477, -7045, -562, 0, - 0, 2154, 8116, -6102, 6570, 12998, -712, -4126, - -4996, 30, 1571, -6393, -12794, 425, 5036, 1190, - 5763, 5653, 12933, -6671, 5197, -2964, -3316, -6354, - -10554, -2652, 0, 0, 12618, -3737, 93, -5901, - 4262, -3364, 4444, 3103, -2767, 3403, 4925, -2584, - -989, 4977, -3714, -1965, 3076, 326, -2946, -2568, - 1026, -2980, 3362, -6132, -5966, 0, 0, 6001, - 48, -1979, -7275, 3476, -2096, 10591, 3793, 2629, - -447, -14747, -3689, -5525, 8358, 6883, -9703, -4556, - 7471, 2965, 4056, 13221, -7327, -3073, -2353, -6720, - 0, 0, 621, 11034, -44, -2828, 5978, -1850, - -1772, 3894, -7471, -1397, 945, -2028, -2928, -2240, - 3172, 2222, 4544, -4243, -5645, 3745, 2573, 3511, - -8206, -7286, 5700, 0, 0, 321, 10818, -4982, - 7813, -749, 9907, 1360, -1443, 568, -1103, 2305, - 6045, 2270, -1063, -1920, -3073, 5893, -3476, -11346, - -1657, -588, 2957, -2287, -8527, -8041, 0, 0, - 119, -268, 2372, -3040, 4979, -3789, -5630, 10619, - 5900, -5109, -4585, -3862, 10467, -3527, -385, -10034, - -9991, 4860, 984, 2362, 2311, -6804, 6324, 433, - 5291, 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, 32767, 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, - 32767 -}; - -const MappingMatrix mapping_matrix_fifthoa_demixing = { 38, 38, 0 }; -const opus_int16 mapping_matrix_fifthoa_demixing_data[1444] = { - 3188, 3247, 3268, 3368, 3368, 3138, 3268, 3099, - 3211, 3368, 3099, 3247, 3211, 3368, 3368, 3368, - 3149, 3268, 3247, 3211, 3099, 3188, 3138, 3149, - 3099, 3188, 3368, 3149, 3188, 3247, 3268, 3138, - 3211, 3368, 3138, 3149, 0, 0, 118, -47, - -5011, 282, 333, -1497, -4584, 2908, 3388, -3647, - -2493, 1139, -2882, -1719, 3604, -2543, -4328, 5443, - 1286, -5498, -4583, 2510, -1743, -2556, 4168, 1446, - -290, 1812, -4074, -2377, 4152, 2847, 4991, 3980, - 393, 5072, 0, 0, 5489, -2235, 1507, -5326, - 4609, -1096, 2926, -3427, -3301, -3078, 4226, 1730, - 4627, 2561, 2966, -592, 143, -677, 4617, -755, - -956, -433, -5138, 3037, 157, -1394, -4498, -4984, - -3661, -4112, -3756, 4628, -570, 3356, 1605, 1803, - 0, 0, -162, 5162, 2132, 2392, 3556, -5141, - -1536, 2975, -3001, -3350, -2231, -5230, 1294, -4965, - 3494, 5230, -3292, -1359, -2945, -773, 2670, 4867, - -660, 3720, -3415, -5112, -3700, -1211, 407, 3013, - 763, 591, 2481, -2657, 5210, 784, 0, 0, - -156, 338, -4246, 510, 462, 3296, 2846, 3333, - -4292, 4574, 1940, -2986, -1275, 3701, 5022, -5250, - 5780, -2676, -1180, 1516, -4852, 4877, 342, -3923, - -5703, -2920, 379, -657, -361, -3346, 1044, 795, - 5257, -4004, 698, 1115, 0, 0, 47, -140, - -3292, -1097, 652, 855, -5260, -3691, -4470, 4521, - -3863, 1093, -5552, -2016, 3831, 334, -456, -1532, - 2068, 1788, 2054, -295, 3668, -2820, 328, -994, - 295, -3301, 5770, 4282, -6353, 5632, -1371, 5005, - 238, 4041, 0, 0, 6764, -1659, -2730, 5726, - 3715, -3216, -933, 531, -52, -345, 3022, -2818, - 4005, -1617, -1189, -3748, -3403, -3592, 4040, -3553, - -2806, -3444, 6023, -711, -3298, -2503, 2548, 5564, - 940, 1848, 1207, 4010, -3488, -358, -2511, -1966, - 0, 0, -64, -5039, 1403, -4455, 6240, 2189, - -1716, -4348, 4183, 3951, -4042, -3606, 2399, -4563, - 4050, -612, -395, 348, -5791, 391, -1440, -735, - 1398, 4359, -518, 2969, 6556, 1951, -518, -4993, - -925, 998, -569, -2934, 3460, 420, 0, 0, - 16, 5482, -4122, 770, 2082, 5020, -3961, 485, - -584, -793, 3, 5222, -1416, 3673, 78, 3549, - -937, -5723, 1673, -6162, -2540, 3082, -355, 1838, - -615, 4601, 2832, -359, -3346, 668, -3393, -1583, - -3774, -2206, 5754, -4961, 0, 0, -328, 299, - 2470, 317, 525, -4494, 2805, 2617, 2383, -2363, - -1037, 4085, 895, -4622, 3218, -6607, -3381, -5933, - 1397, 6394, -446, 5694, 14, -4510, 4329, 3690, - -334, 0, 2932, -2478, -2944, -577, -599, -230, - 1553, -4736, 0, 0, -324, 142, -3252, -867, - 1111, -1882, 3378, -6055, 6502, -6840, 4280, -2694, - -2876, 4190, 6454, 655, 1061, 626, -2669, -798, - 3192, -985, -898, -5482, -548, 2315, -558, 1302, - 900, 5747, -1325, 1599, -1384, -5749, 624, 1110, - 0, 0, 321, 312, 2188, 1322, 237, 708, - -304, 2463, 1500, -1094, -5112, -1010, -6799, 646, - 992, 1969, 3423, -3996, 2628, 4451, 3432, -2833, - -6101, -330, -3768, -3, -707, 5961, -4037, -3736, - 4080, 7254, -4113, 2151, 54, -2150, 0, 0, - 7735, 4064, -3884, -5240, 577, 2229, -3947, 2914, - 3555, 4011, 774, -3519, 1985, -3701, -3824, 330, - -905, 2085, 1155, 2176, 3006, 340, -5533, -3264, - -902, 3114, 344, -5060, 1524, 1805, 1926, 2350, - 1905, -3203, -2762, -4162, 0, 0, 193, -151, - -1434, 6289, 7354, 4234, 169, 2868, -1977, -1375, - -4987, 2345, 2742, 599, 939, -4837, 2688, 991, - -6907, 716, -1542, -4346, -1833, 1493, 3134, 2903, - -7019, -2835, 93, 4395, 621, 870, -2357, -975, - -2933, -127, 0, 0, -616, -5968, -3479, -1651, - 4932, -2445, -5512, -1451, 691, 739, 479, 4227, - -2886, 3853, 8, -501, 188, 1990, 3842, 2270, - 1662, -174, 1290, 2456, 67, -3267, -5535, 483, - 5721, -1642, 6501, -3432, 1184, -3246, 4101, -4880, - 0, 0, -465, 5264, -4812, 682, 1683, -4539, - 2916, -1985, 2899, 3324, 1060, -4398, -745, -2137, - -3827, 1044, 6225, 3609, -532, 1980, -6001, 564, - -209, -1299, 5336, -3605, -1484, 37, 19, -1295, - -665, -385, -6773, 3651, 6153, -1291, 0, 0, - 193, -415, 5166, -110, 626, 6743, -2860, 1425, - 1101, -1341, 80, -4533, 249, 4231, -119, -6009, - -2970, 5170, -822, -2610, 4527, 5948, 182, -2589, - 837, -5471, 371, -43, 373, -665, -1233, -626, - -7353, 2606, 1339, -1398, 0, 0, -533, 147, - 2075, -672, 1043, 3503, 4402, -4971, -3287, 3731, - -2606, 3817, 1972, -5603, 5114, 1185, -1318, 1906, - 3018, -1999, 343, -1943, 207, -6744, 913, -4060, - 645, -349, -5667, 4766, 5575, -1733, 1116, 160, - 1534, -5690, 0, 0, -137, -36, 1556, 1325, - 1553, -2230, 1188, 5296, -5104, 4673, 6295, 498, - -4723, 933, 2994, 4067, -4700, 1758, -4116, -1252, - 2444, -4092, 1653, -2802, 5069, 1133, 790, -2355, - -934, -6304, 1642, 2045, -4259, -3873, -213, 215, - 0, 0, -364, 423, 4888, -1316, 118, -950, - 4027, 114, 2961, -3136, -3012, -883, -6192, 1340, - -3210, -1193, 1376, 3128, 1596, -2994, -3194, 533, - 8502, 2487, -1485, 1032, 301, -8007, -577, 887, - 297, 7778, 3121, -1901, -94, -6401, 0, 0, - 9260, -1845, 668, 2787, -2255, 2699, -2512, -3737, - -3675, -3601, -1803, 210, -1701, -1442, -2700, 3457, - 2868, 2079, -2113, 3178, 1277, 3578, 5240, -2482, - 3324, 1020, -4027, 3835, -3758, -3633, -3170, -1310, - 2509, -3110, 713, 174, 0, 0, -399, 4969, - -2321, -7744, 6494, -3776, 1478, 758, -1794, -2233, - -4059, 4932, 2770, 4761, -3475, 1243, 829, -651, - -5358, -436, 2381, 1360, 2561, -3118, 858, -4366, - 3933, 3646, -43, -1310, -16, 924, 1197, 1415, - -5036, -376, 0, 0, 100, 1410, 1290, 3199, - 7091, -3638, -2641, 1118, 45, -441, 794, -974, - -5033, 889, 438, -3102, 895, 3555, 4672, 4795, - 1129, -2408, -2153, 1742, 159, -2040, 7578, -2006, - -5737, 1986, -5568, -6413, 2428, -1387, -2441, 667, - 0, 0, -37, -6031, -4434, -904, 3290, 1806, - 4736, 2516, -5905, -5927, 1754, -4300, -2468, -2203, - -4836, -672, 1444, -1591, -1631, -1789, 4311, -153, - -688, -1222, 1058, 3139, 4659, -353, 1543, 1838, - 2180, -1448, 2432, 6277, 5304, -1692, 0, 0, - -280, 4506, 807, -477, 823, 3550, 1427, -1856, - -3003, -3501, -1203, 2679, 933, 778, -4954, -1977, - -7458, 4687, 435, 7045, -4053, -3130, 257, -3917, - -6165, 1889, 927, 235, 1889, -1097, 1985, 630, - -2172, -2130, 7080, 4810, 0, 0, -300, 496, - 2808, 279, 667, -7179, -2661, -526, -2832, 1751, - 2849, 4829, -906, -4151, -1124, -3062, 8166, 5361, - -1656, -6017, 3265, 2551, -864, -432, -6966, 6295, - -168, 901, 442, -582, 269, 236, -3574, 799, - 472, 565, 0, 0, 805, -2466, 6208, -4592, - -170, -6701, -5610, 3678, -4242, 4561, -724, -5534, - 2415, 7354, 2761, 2699, -349, 3822, -2372, 1756, - -5523, -3445, -588, -5749, -3986, 9804, -3871, 5375, - -2308, 5504, -2766, -1651, 1472, 6832, 2705, -5104, - 0, 0, -700, -1179, 4402, 400, 1383, 939, - -1342, 6013, 2577, -3472, 472, 2883, 1450, -3917, - 2849, 5084, 4990, 5392, 342, -4925, -3329, -5372, - -2674, -6035, -5072, -836, 179, 2506, 7987, -3647, - -8202, -1437, 1891, 2400, 1607, -3611, 0, 0, - -4706, -4003, 9928, -379, 5557, 3738, -8789, 685, - 1937, -5157, 13388, 7995, -4119, -9909, -5079, 4804, - 5586, 774, -5430, 299, -9943, 3264, -3690, -3901, - -1133, -6199, 3182, 1544, 5467, 3686, -2639, 4068, - 1163, -185, -1299, -506, 0, 0, 843, 1005, - -1059, 467, -1279, -2259, 6057, -1694, -5885, 5342, - -5160, -3748, -1382, 4420, -697, -2000, -3808, 3100, - 2685, -4073, 531, 318, -7822, 2414, 2901, 3399, - -1340, 8449, 3685, 463, -3341, 2423, 2304, -2723, - 84, -2622, 0, 0, 12088, -265, 2562, -435, - -4348, -2426, 3538, 1552, 1279, 883, -4166, 2634, - -6130, 2994, 3729, -1570, -601, -1753, -5124, -2788, - -2096, -1920, -2649, 2793, -1079, -1952, 2983, -1530, - 2499, 1769, 1492, -6757, -2108, 2841, 1466, 2597, - 0, 0, -3830, -4093, 2448, 12720, 7737, -665, - -832, -9257, 2971, -2400, 791, 1873, 1072, -587, - -7440, 8055, 1531, -4736, 616, -1782, -2982, 9663, - -5057, -5926, 1610, -4489, 7033, -8658, 6010, -5673, - 5648, 812, -271, -1802, -4500, 4392, 0, 0, - -888, -327, 3373, -1084, 7959, 2430, 1898, -2360, - -1820, -1377, -1090, -4436, -3422, -1106, -3230, 3876, - -41, -5128, 6375, -1848, -3824, 5844, 617, -1957, - 4232, 1345, -1439, -83, 3046, -214, 5458, -5566, - -4387, -3738, -5740, 8657, 0, 0, 6978, 6239, - -3686, -981, -2854, 78, 5859, -357, 4618, 7391, - -138, 971, -5799, 2135, 4478, -7004, -5949, 1668, - -6933, -1163, 7010, -5624, 2990, 6192, -8075, 3567, - -8308, 2236, -5098, -2120, -4355, -4238, 4955, 10230, - 692, -5606, 0, 0, -1348, -7069, -12, -4927, - 1211, 651, 1360, 7744, 3404, 5069, -2438, -105, - 2332, 1494, -4686, 1336, -3628, -881, 2474, 1736, - -26, -257, 2135, -4452, 446, -641, -4704, 2605, - -6436, 6662, -4939, 990, -1100, -3782, 5028, 4753, - 0, 0, -2875, 6410, 3518, 3950, 1271, 869, - -2842, -5837, 1532, -2899, 1140, -597, 1712, -1988, - -4819, -4783, 4773, -8796, 2240, -4596, 3565, -4853, - -556, -3974, 7366, -4370, 3113, -3548, 3552, -5450, - 3869, 2514, 6736, -4570, 6074, 3151, 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, 32767, 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, 32767 -}; diff --git a/code/thirdparty/opus-1.5.2/src/mapping_matrix.h b/code/thirdparty/opus-1.5.2/src/mapping_matrix.h deleted file mode 100644 index 53646cb1..00000000 --- a/code/thirdparty/opus-1.5.2/src/mapping_matrix.h +++ /dev/null @@ -1,145 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @file mapping_matrix.h - * @brief Opus reference implementation mapping matrix API - */ - -#ifndef MAPPING_MATRIX_H -#define MAPPING_MATRIX_H - -#include "opus_types.h" -#include "opus_projection.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct MappingMatrix -{ - int rows; /* number of channels outputted from matrix. */ - int cols; /* number of channels inputted to matrix. */ - int gain; /* in dB. S7.8-format. */ - /* Matrix cell data goes here using col-wise ordering. */ -} MappingMatrix; - -opus_int32 mapping_matrix_get_size(int rows, int cols); - -opus_int16 *mapping_matrix_get_data(const MappingMatrix *matrix); - -void mapping_matrix_init( - MappingMatrix * const matrix, - int rows, - int cols, - int gain, - const opus_int16 *data, - opus_int32 data_size -); - -#ifndef DISABLE_FLOAT_API -void mapping_matrix_multiply_channel_in_float( - const MappingMatrix *matrix, - const float *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size -); - -void mapping_matrix_multiply_channel_out_float( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - float *output, - int output_rows, - int frame_size -); -#endif /* DISABLE_FLOAT_API */ - -void mapping_matrix_multiply_channel_in_short( - const MappingMatrix *matrix, - const opus_int16 *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size -); - -void mapping_matrix_multiply_channel_out_short( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - opus_int16 *output, - int output_rows, - int frame_size -); - -/* Pre-computed mixing and demixing matrices for 1st to 3rd-order ambisonics. - * foa: first-order ambisonics - * soa: second-order ambisonics - * toa: third-order ambisonics - */ -extern const MappingMatrix mapping_matrix_foa_mixing; -extern const opus_int16 mapping_matrix_foa_mixing_data[36]; - -extern const MappingMatrix mapping_matrix_soa_mixing; -extern const opus_int16 mapping_matrix_soa_mixing_data[121]; - -extern const MappingMatrix mapping_matrix_toa_mixing; -extern const opus_int16 mapping_matrix_toa_mixing_data[324]; - -extern const MappingMatrix mapping_matrix_fourthoa_mixing; -extern const opus_int16 mapping_matrix_fourthoa_mixing_data[729]; - -extern const MappingMatrix mapping_matrix_fifthoa_mixing; -extern const opus_int16 mapping_matrix_fifthoa_mixing_data[1444]; - -extern const MappingMatrix mapping_matrix_foa_demixing; -extern const opus_int16 mapping_matrix_foa_demixing_data[36]; - -extern const MappingMatrix mapping_matrix_soa_demixing; -extern const opus_int16 mapping_matrix_soa_demixing_data[121]; - -extern const MappingMatrix mapping_matrix_toa_demixing; -extern const opus_int16 mapping_matrix_toa_demixing_data[324]; - -extern const MappingMatrix mapping_matrix_fourthoa_demixing; -extern const opus_int16 mapping_matrix_fourthoa_demixing_data[729]; - -extern const MappingMatrix mapping_matrix_fifthoa_demixing; -extern const opus_int16 mapping_matrix_fifthoa_demixing_data[1444]; - -#ifdef __cplusplus -} -#endif - -#endif /* MAPPING_MATRIX_H */ diff --git a/code/thirdparty/opus-1.5.2/src/opus_projection_decoder.c b/code/thirdparty/opus-1.5.2/src/opus_projection_decoder.c deleted file mode 100644 index c2e07d5b..00000000 --- a/code/thirdparty/opus-1.5.2/src/opus_projection_decoder.c +++ /dev/null @@ -1,258 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "mathops.h" -#include "os_support.h" -#include "opus_private.h" -#include "opus_defines.h" -#include "opus_projection.h" -#include "opus_multistream.h" -#include "mapping_matrix.h" -#include "stack_alloc.h" - -struct OpusProjectionDecoder -{ - opus_int32 demixing_matrix_size_in_bytes; - /* Encoder states go here */ -}; - -#if !defined(DISABLE_FLOAT_API) -static void opus_projection_copy_channel_out_float( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data) -{ - float *float_dst; - const MappingMatrix *matrix; - float_dst = (float *)dst; - matrix = (const MappingMatrix *)user_data; - - if (dst_channel == 0) - OPUS_CLEAR(float_dst, frame_size * dst_stride); - - if (src != NULL) - mapping_matrix_multiply_channel_out_float(matrix, src, dst_channel, - src_stride, float_dst, dst_stride, frame_size); -} -#endif - -static void opus_projection_copy_channel_out_short( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data) -{ - opus_int16 *short_dst; - const MappingMatrix *matrix; - short_dst = (opus_int16 *)dst; - matrix = (const MappingMatrix *)user_data; - if (dst_channel == 0) - OPUS_CLEAR(short_dst, frame_size * dst_stride); - - if (src != NULL) - mapping_matrix_multiply_channel_out_short(matrix, src, dst_channel, - src_stride, short_dst, dst_stride, frame_size); -} - -static MappingMatrix *get_dec_demixing_matrix(OpusProjectionDecoder *st) -{ - /* void* cast avoids clang -Wcast-align warning */ - return (MappingMatrix*)(void*)((char*)st + - align(sizeof(OpusProjectionDecoder))); -} - -static OpusMSDecoder *get_multistream_decoder(OpusProjectionDecoder *st) -{ - /* void* cast avoids clang -Wcast-align warning */ - return (OpusMSDecoder*)(void*)((char*)st + - align(sizeof(OpusProjectionDecoder) + - st->demixing_matrix_size_in_bytes)); -} - -opus_int32 opus_projection_decoder_get_size(int channels, int streams, - int coupled_streams) -{ - opus_int32 matrix_size; - opus_int32 decoder_size; - - matrix_size = - mapping_matrix_get_size(streams + coupled_streams, channels); - if (!matrix_size) - return 0; - - decoder_size = opus_multistream_decoder_get_size(streams, coupled_streams); - if (!decoder_size) - return 0; - - return align(sizeof(OpusProjectionDecoder)) + matrix_size + decoder_size; -} - -int opus_projection_decoder_init(OpusProjectionDecoder *st, opus_int32 Fs, - int channels, int streams, int coupled_streams, - unsigned char *demixing_matrix, opus_int32 demixing_matrix_size) -{ - int nb_input_streams; - opus_int32 expected_matrix_size; - int i, ret; - unsigned char mapping[255]; - VARDECL(opus_int16, buf); - ALLOC_STACK; - - /* Verify supplied matrix size. */ - nb_input_streams = streams + coupled_streams; - expected_matrix_size = nb_input_streams * channels * sizeof(opus_int16); - if (expected_matrix_size != demixing_matrix_size) - { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - /* Convert demixing matrix input into internal format. */ - ALLOC(buf, nb_input_streams * channels, opus_int16); - for (i = 0; i < nb_input_streams * channels; i++) - { - int s = demixing_matrix[2*i + 1] << 8 | demixing_matrix[2*i]; - s = ((s & 0xFFFF) ^ 0x8000) - 0x8000; - buf[i] = (opus_int16)s; - } - - /* Assign demixing matrix. */ - st->demixing_matrix_size_in_bytes = - mapping_matrix_get_size(channels, nb_input_streams); - if (!st->demixing_matrix_size_in_bytes) - { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - mapping_matrix_init(get_dec_demixing_matrix(st), channels, nb_input_streams, 0, - buf, demixing_matrix_size); - - /* Set trivial mapping so each input channel pairs with a matrix column. */ - for (i = 0; i < channels; i++) - mapping[i] = i; - - ret = opus_multistream_decoder_init( - get_multistream_decoder(st), Fs, channels, streams, coupled_streams, mapping); - RESTORE_STACK; - return ret; -} - -OpusProjectionDecoder *opus_projection_decoder_create( - opus_int32 Fs, int channels, int streams, int coupled_streams, - unsigned char *demixing_matrix, opus_int32 demixing_matrix_size, int *error) -{ - int size; - int ret; - OpusProjectionDecoder *st; - - /* Allocate space for the projection decoder. */ - size = opus_projection_decoder_get_size(channels, streams, coupled_streams); - if (!size) { - if (error) - *error = OPUS_ALLOC_FAIL; - return NULL; - } - st = (OpusProjectionDecoder *)opus_alloc(size); - if (!st) - { - if (error) - *error = OPUS_ALLOC_FAIL; - return NULL; - } - - /* Initialize projection decoder with provided settings. */ - ret = opus_projection_decoder_init(st, Fs, channels, streams, coupled_streams, - demixing_matrix, demixing_matrix_size); - if (ret != OPUS_OK) - { - opus_free(st); - st = NULL; - } - if (error) - *error = ret; - return st; -} - -#ifdef FIXED_POINT -int opus_projection_decode(OpusProjectionDecoder *st, const unsigned char *data, - opus_int32 len, opus_int16 *pcm, int frame_size, - int decode_fec) -{ - return opus_multistream_decode_native(get_multistream_decoder(st), data, len, - pcm, opus_projection_copy_channel_out_short, frame_size, decode_fec, 0, - get_dec_demixing_matrix(st)); -} -#else -int opus_projection_decode(OpusProjectionDecoder *st, const unsigned char *data, - opus_int32 len, opus_int16 *pcm, int frame_size, - int decode_fec) -{ - return opus_multistream_decode_native(get_multistream_decoder(st), data, len, - pcm, opus_projection_copy_channel_out_short, frame_size, decode_fec, 1, - get_dec_demixing_matrix(st)); -} -#endif - -#ifndef DISABLE_FLOAT_API -int opus_projection_decode_float(OpusProjectionDecoder *st, const unsigned char *data, - opus_int32 len, float *pcm, int frame_size, int decode_fec) -{ - return opus_multistream_decode_native(get_multistream_decoder(st), data, len, - pcm, opus_projection_copy_channel_out_float, frame_size, decode_fec, 0, - get_dec_demixing_matrix(st)); -} -#endif - -int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) -{ - va_list ap; - int ret = OPUS_OK; - - va_start(ap, request); - ret = opus_multistream_decoder_ctl_va_list(get_multistream_decoder(st), - request, ap); - va_end(ap); - return ret; -} - -void opus_projection_decoder_destroy(OpusProjectionDecoder *st) -{ - opus_free(st); -} - diff --git a/code/thirdparty/opus-1.5.2/src/opus_projection_encoder.c b/code/thirdparty/opus-1.5.2/src/opus_projection_encoder.c deleted file mode 100644 index 92813ad0..00000000 --- a/code/thirdparty/opus-1.5.2/src/opus_projection_encoder.c +++ /dev/null @@ -1,510 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "mathops.h" -#include "os_support.h" -#include "opus_private.h" -#include "opus_defines.h" -#include "opus_projection.h" -#include "opus_multistream.h" -#include "stack_alloc.h" -#include "mapping_matrix.h" - -struct OpusProjectionEncoder -{ - opus_int32 mixing_matrix_size_in_bytes; - opus_int32 demixing_matrix_size_in_bytes; - /* Encoder states go here */ -}; - -#if !defined(DISABLE_FLOAT_API) -static void opus_projection_copy_channel_in_float( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -) -{ - mapping_matrix_multiply_channel_in_float((const MappingMatrix*)user_data, - (const float*)src, src_stride, dst, src_channel, dst_stride, frame_size); -} -#endif - -static void opus_projection_copy_channel_in_short( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -) -{ - mapping_matrix_multiply_channel_in_short((const MappingMatrix*)user_data, - (const opus_int16*)src, src_stride, dst, src_channel, dst_stride, frame_size); -} - -static int get_order_plus_one_from_channels(int channels, int *order_plus_one) -{ - int order_plus_one_; - int acn_channels; - int nondiegetic_channels; - - /* Allowed numbers of channels: - * (1 + n)^2 + 2j, for n = 0...14 and j = 0 or 1. - */ - if (channels < 1 || channels > 227) - return OPUS_BAD_ARG; - - order_plus_one_ = isqrt32(channels); - acn_channels = order_plus_one_ * order_plus_one_; - nondiegetic_channels = channels - acn_channels; - if (nondiegetic_channels != 0 && nondiegetic_channels != 2) - return OPUS_BAD_ARG; - - if (order_plus_one) - *order_plus_one = order_plus_one_; - return OPUS_OK; -} - -static int get_streams_from_channels(int channels, int mapping_family, - int *streams, int *coupled_streams, - int *order_plus_one) -{ - if (mapping_family == 3) - { - if (get_order_plus_one_from_channels(channels, order_plus_one) != OPUS_OK) - return OPUS_BAD_ARG; - if (streams) - *streams = (channels + 1) / 2; - if (coupled_streams) - *coupled_streams = channels / 2; - return OPUS_OK; - } - return OPUS_BAD_ARG; -} - -static MappingMatrix *get_mixing_matrix(OpusProjectionEncoder *st) -{ - /* void* cast avoids clang -Wcast-align warning */ - return (MappingMatrix *)(void*)((char*)st + - align(sizeof(OpusProjectionEncoder))); -} - -static MappingMatrix *get_enc_demixing_matrix(OpusProjectionEncoder *st) -{ - /* void* cast avoids clang -Wcast-align warning */ - return (MappingMatrix *)(void*)((char*)st + - align(sizeof(OpusProjectionEncoder) + - st->mixing_matrix_size_in_bytes)); -} - -static OpusMSEncoder *get_multistream_encoder(OpusProjectionEncoder *st) -{ - /* void* cast avoids clang -Wcast-align warning */ - return (OpusMSEncoder *)(void*)((char*)st + - align(sizeof(OpusProjectionEncoder) + - st->mixing_matrix_size_in_bytes + - st->demixing_matrix_size_in_bytes)); -} - -opus_int32 opus_projection_ambisonics_encoder_get_size(int channels, - int mapping_family) -{ - int nb_streams; - int nb_coupled_streams; - int order_plus_one; - int mixing_matrix_rows, mixing_matrix_cols; - int demixing_matrix_rows, demixing_matrix_cols; - opus_int32 mixing_matrix_size, demixing_matrix_size; - opus_int32 encoder_size; - int ret; - - ret = get_streams_from_channels(channels, mapping_family, &nb_streams, - &nb_coupled_streams, &order_plus_one); - if (ret != OPUS_OK) - return 0; - - if (order_plus_one == 2) - { - mixing_matrix_rows = mapping_matrix_foa_mixing.rows; - mixing_matrix_cols = mapping_matrix_foa_mixing.cols; - demixing_matrix_rows = mapping_matrix_foa_demixing.rows; - demixing_matrix_cols = mapping_matrix_foa_demixing.cols; - } - else if (order_plus_one == 3) - { - mixing_matrix_rows = mapping_matrix_soa_mixing.rows; - mixing_matrix_cols = mapping_matrix_soa_mixing.cols; - demixing_matrix_rows = mapping_matrix_soa_demixing.rows; - demixing_matrix_cols = mapping_matrix_soa_demixing.cols; - } - else if (order_plus_one == 4) - { - mixing_matrix_rows = mapping_matrix_toa_mixing.rows; - mixing_matrix_cols = mapping_matrix_toa_mixing.cols; - demixing_matrix_rows = mapping_matrix_toa_demixing.rows; - demixing_matrix_cols = mapping_matrix_toa_demixing.cols; - } - else if (order_plus_one == 5) - { - mixing_matrix_rows = mapping_matrix_fourthoa_mixing.rows; - mixing_matrix_cols = mapping_matrix_fourthoa_mixing.cols; - demixing_matrix_rows = mapping_matrix_fourthoa_demixing.rows; - demixing_matrix_cols = mapping_matrix_fourthoa_demixing.cols; - } - else if (order_plus_one == 6) - { - mixing_matrix_rows = mapping_matrix_fifthoa_mixing.rows; - mixing_matrix_cols = mapping_matrix_fifthoa_mixing.cols; - demixing_matrix_rows = mapping_matrix_fifthoa_demixing.rows; - demixing_matrix_cols = mapping_matrix_fifthoa_demixing.cols; - } - else - return 0; - - mixing_matrix_size = - mapping_matrix_get_size(mixing_matrix_rows, mixing_matrix_cols); - if (!mixing_matrix_size) - return 0; - - demixing_matrix_size = - mapping_matrix_get_size(demixing_matrix_rows, demixing_matrix_cols); - if (!demixing_matrix_size) - return 0; - - encoder_size = - opus_multistream_encoder_get_size(nb_streams, nb_coupled_streams); - if (!encoder_size) - return 0; - - return align(sizeof(OpusProjectionEncoder)) + - mixing_matrix_size + demixing_matrix_size + encoder_size; -} - -int opus_projection_ambisonics_encoder_init(OpusProjectionEncoder *st, opus_int32 Fs, - int channels, int mapping_family, - int *streams, int *coupled_streams, - int application) -{ - MappingMatrix *mixing_matrix; - MappingMatrix *demixing_matrix; - OpusMSEncoder *ms_encoder; - int i; - int ret; - int order_plus_one; - unsigned char mapping[255]; - - if (streams == NULL || coupled_streams == NULL) { - return OPUS_BAD_ARG; - } - - if (get_streams_from_channels(channels, mapping_family, streams, - coupled_streams, &order_plus_one) != OPUS_OK) - return OPUS_BAD_ARG; - - if (mapping_family == 3) - { - /* Assign mixing matrix based on available pre-computed matrices. */ - mixing_matrix = get_mixing_matrix(st); - if (order_plus_one == 2) - { - mapping_matrix_init(mixing_matrix, mapping_matrix_foa_mixing.rows, - mapping_matrix_foa_mixing.cols, mapping_matrix_foa_mixing.gain, - mapping_matrix_foa_mixing_data, - sizeof(mapping_matrix_foa_mixing_data)); - } - else if (order_plus_one == 3) - { - mapping_matrix_init(mixing_matrix, mapping_matrix_soa_mixing.rows, - mapping_matrix_soa_mixing.cols, mapping_matrix_soa_mixing.gain, - mapping_matrix_soa_mixing_data, - sizeof(mapping_matrix_soa_mixing_data)); - } - else if (order_plus_one == 4) - { - mapping_matrix_init(mixing_matrix, mapping_matrix_toa_mixing.rows, - mapping_matrix_toa_mixing.cols, mapping_matrix_toa_mixing.gain, - mapping_matrix_toa_mixing_data, - sizeof(mapping_matrix_toa_mixing_data)); - } - else if (order_plus_one == 5) - { - mapping_matrix_init(mixing_matrix, mapping_matrix_fourthoa_mixing.rows, - mapping_matrix_fourthoa_mixing.cols, mapping_matrix_fourthoa_mixing.gain, - mapping_matrix_fourthoa_mixing_data, - sizeof(mapping_matrix_fourthoa_mixing_data)); - } - else if (order_plus_one == 6) - { - mapping_matrix_init(mixing_matrix, mapping_matrix_fifthoa_mixing.rows, - mapping_matrix_fifthoa_mixing.cols, mapping_matrix_fifthoa_mixing.gain, - mapping_matrix_fifthoa_mixing_data, - sizeof(mapping_matrix_fifthoa_mixing_data)); - } - else - return OPUS_BAD_ARG; - - st->mixing_matrix_size_in_bytes = mapping_matrix_get_size( - mixing_matrix->rows, mixing_matrix->cols); - if (!st->mixing_matrix_size_in_bytes) - return OPUS_BAD_ARG; - - /* Assign demixing matrix based on available pre-computed matrices. */ - demixing_matrix = get_enc_demixing_matrix(st); - if (order_plus_one == 2) - { - mapping_matrix_init(demixing_matrix, mapping_matrix_foa_demixing.rows, - mapping_matrix_foa_demixing.cols, mapping_matrix_foa_demixing.gain, - mapping_matrix_foa_demixing_data, - sizeof(mapping_matrix_foa_demixing_data)); - } - else if (order_plus_one == 3) - { - mapping_matrix_init(demixing_matrix, mapping_matrix_soa_demixing.rows, - mapping_matrix_soa_demixing.cols, mapping_matrix_soa_demixing.gain, - mapping_matrix_soa_demixing_data, - sizeof(mapping_matrix_soa_demixing_data)); - } - else if (order_plus_one == 4) - { - mapping_matrix_init(demixing_matrix, mapping_matrix_toa_demixing.rows, - mapping_matrix_toa_demixing.cols, mapping_matrix_toa_demixing.gain, - mapping_matrix_toa_demixing_data, - sizeof(mapping_matrix_toa_demixing_data)); - } - else if (order_plus_one == 5) - { - mapping_matrix_init(demixing_matrix, mapping_matrix_fourthoa_demixing.rows, - mapping_matrix_fourthoa_demixing.cols, mapping_matrix_fourthoa_demixing.gain, - mapping_matrix_fourthoa_demixing_data, - sizeof(mapping_matrix_fourthoa_demixing_data)); - } - else if (order_plus_one == 6) - { - mapping_matrix_init(demixing_matrix, mapping_matrix_fifthoa_demixing.rows, - mapping_matrix_fifthoa_demixing.cols, mapping_matrix_fifthoa_demixing.gain, - mapping_matrix_fifthoa_demixing_data, - sizeof(mapping_matrix_fifthoa_demixing_data)); - } - else - return OPUS_BAD_ARG; - - st->demixing_matrix_size_in_bytes = mapping_matrix_get_size( - demixing_matrix->rows, demixing_matrix->cols); - if (!st->demixing_matrix_size_in_bytes) - return OPUS_BAD_ARG; - } - else - return OPUS_UNIMPLEMENTED; - - /* Ensure matrices are large enough for desired coding scheme. */ - if (*streams + *coupled_streams > mixing_matrix->rows || - channels > mixing_matrix->cols || - channels > demixing_matrix->rows || - *streams + *coupled_streams > demixing_matrix->cols) - return OPUS_BAD_ARG; - - /* Set trivial mapping so each input channel pairs with a matrix column. */ - for (i = 0; i < channels; i++) - mapping[i] = i; - - /* Initialize multistream encoder with provided settings. */ - ms_encoder = get_multistream_encoder(st); - ret = opus_multistream_encoder_init(ms_encoder, Fs, channels, *streams, - *coupled_streams, mapping, application); - return ret; -} - -OpusProjectionEncoder *opus_projection_ambisonics_encoder_create( - opus_int32 Fs, int channels, int mapping_family, int *streams, - int *coupled_streams, int application, int *error) -{ - int size; - int ret; - OpusProjectionEncoder *st; - - /* Allocate space for the projection encoder. */ - size = opus_projection_ambisonics_encoder_get_size(channels, mapping_family); - if (!size) { - if (error) - *error = OPUS_ALLOC_FAIL; - return NULL; - } - st = (OpusProjectionEncoder *)opus_alloc(size); - if (!st) - { - if (error) - *error = OPUS_ALLOC_FAIL; - return NULL; - } - - /* Initialize projection encoder with provided settings. */ - ret = opus_projection_ambisonics_encoder_init(st, Fs, channels, - mapping_family, streams, coupled_streams, application); - if (ret != OPUS_OK) - { - opus_free(st); - st = NULL; - } - if (error) - *error = ret; - return st; -} - -int opus_projection_encode(OpusProjectionEncoder *st, const opus_int16 *pcm, - int frame_size, unsigned char *data, - opus_int32 max_data_bytes) -{ - return opus_multistream_encode_native(get_multistream_encoder(st), - opus_projection_copy_channel_in_short, pcm, frame_size, data, - max_data_bytes, 16, downmix_int, 0, get_mixing_matrix(st)); -} - -#ifndef DISABLE_FLOAT_API -#ifdef FIXED_POINT -int opus_projection_encode_float(OpusProjectionEncoder *st, const float *pcm, - int frame_size, unsigned char *data, - opus_int32 max_data_bytes) -{ - return opus_multistream_encode_native(get_multistream_encoder(st), - opus_projection_copy_channel_in_float, pcm, frame_size, data, - max_data_bytes, 16, downmix_float, 1, get_mixing_matrix(st)); -} -#else -int opus_projection_encode_float(OpusProjectionEncoder *st, const float *pcm, - int frame_size, unsigned char *data, - opus_int32 max_data_bytes) -{ - return opus_multistream_encode_native(get_multistream_encoder(st), - opus_projection_copy_channel_in_float, pcm, frame_size, data, - max_data_bytes, 24, downmix_float, 1, get_mixing_matrix(st)); -} -#endif -#endif - -void opus_projection_encoder_destroy(OpusProjectionEncoder *st) -{ - opus_free(st); -} - -int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) -{ - va_list ap; - MappingMatrix *demixing_matrix; - OpusMSEncoder *ms_encoder; - int ret = OPUS_OK; - - ms_encoder = get_multistream_encoder(st); - demixing_matrix = get_enc_demixing_matrix(st); - - va_start(ap, request); - switch(request) - { - case OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST: - { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) - { - goto bad_arg; - } - *value = - ms_encoder->layout.nb_channels * (ms_encoder->layout.nb_streams - + ms_encoder->layout.nb_coupled_streams) * sizeof(opus_int16); - } - break; - case OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST: - { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) - { - goto bad_arg; - } - *value = demixing_matrix->gain; - } - break; - case OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST: - { - int i, j, k, l; - int nb_input_streams; - int nb_output_streams; - unsigned char *external_char; - opus_int16 *internal_short; - opus_int32 external_size; - opus_int32 internal_size; - - /* (I/O is in relation to the decoder's perspective). */ - nb_input_streams = ms_encoder->layout.nb_streams + - ms_encoder->layout.nb_coupled_streams; - nb_output_streams = ms_encoder->layout.nb_channels; - - external_char = va_arg(ap, unsigned char *); - external_size = va_arg(ap, opus_int32); - if (!external_char) - { - goto bad_arg; - } - internal_short = mapping_matrix_get_data(demixing_matrix); - internal_size = nb_input_streams * nb_output_streams * sizeof(opus_int16); - if (external_size != internal_size) - { - goto bad_arg; - } - - /* Copy demixing matrix subset to output destination. */ - l = 0; - for (i = 0; i < nb_input_streams; i++) { - for (j = 0; j < nb_output_streams; j++) { - k = demixing_matrix->rows * i + j; - external_char[2*l] = (unsigned char)internal_short[k]; - external_char[2*l+1] = (unsigned char)(internal_short[k] >> 8); - l++; - } - } - } - break; - default: - { - ret = opus_multistream_encoder_ctl_va_list(ms_encoder, request, ap); - } - break; - } - va_end(ap); - return ret; - -bad_arg: - va_end(ap); - return OPUS_BAD_ARG; -} - diff --git a/code/thirdparty/zlib-1.3.1/compress.c b/code/thirdparty/zlib-1.3.1/compress.c deleted file mode 100644 index f43bacf7..00000000 --- a/code/thirdparty/zlib-1.3.1/compress.c +++ /dev/null @@ -1,75 +0,0 @@ -/* compress.c -- compress a memory buffer - * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ -int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong sourceLen, int level) { - z_stream stream; - int err; - const uInt max = (uInt)-1; - uLong left; - - left = *destLen; - *destLen = 0; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - stream.opaque = (voidpf)0; - - err = deflateInit(&stream, level); - if (err != Z_OK) return err; - - stream.next_out = dest; - stream.avail_out = 0; - stream.next_in = (z_const Bytef *)source; - stream.avail_in = 0; - - do { - if (stream.avail_out == 0) { - stream.avail_out = left > (uLong)max ? max : (uInt)left; - left -= stream.avail_out; - } - if (stream.avail_in == 0) { - stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen; - sourceLen -= stream.avail_in; - } - err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH); - } while (err == Z_OK); - - *destLen = stream.total_out; - deflateEnd(&stream); - return err == Z_STREAM_END ? Z_OK : err; -} - -/* =========================================================================== - */ -int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong sourceLen) { - return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); -} - -/* =========================================================================== - If the default memLevel or windowBits for deflateInit() is changed, then - this function needs to be updated. - */ -uLong ZEXPORT compressBound(uLong sourceLen) { - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13; -} diff --git a/code/thirdparty/zlib-1.3.1/deflate.c b/code/thirdparty/zlib-1.3.1/deflate.c deleted file mode 100644 index 012ea814..00000000 --- a/code/thirdparty/zlib-1.3.1/deflate.c +++ /dev/null @@ -1,2139 +0,0 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://tools.ietf.org/html/rfc1951 - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id$ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func)(deflate_state *s, int flush); -/* Compression function. Returns the block state after the call. */ - -local block_state deflate_stored(deflate_state *s, int flush); -local block_state deflate_fast(deflate_state *s, int flush); -#ifndef FASTEST -local block_state deflate_slow(deflate_state *s, int flush); -#endif -local block_state deflate_rle(deflate_state *s, int flush); -local block_state deflate_huff(deflate_state *s, int flush); - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ -#define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0)) - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to UPDATE_HASH are made with consecutive input - * characters, so that a running hash key can be computed from the previous - * key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to INSERT_STRING are made with consecutive input - * characters and the first MIN_MATCH bytes of str are valid (except for - * the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - do { \ - s->head[s->hash_size - 1] = NIL; \ - zmemzero((Bytef *)s->head, \ - (unsigned)(s->hash_size - 1)*sizeof(*s->head)); \ - } while (0) - -/* =========================================================================== - * Slide the hash table when sliding the window down (could be avoided with 32 - * bit values at the expense of memory usage). We slide even when level == 0 to - * keep the hash table consistent if we switch back to level > 0 later. - */ -#if defined(__has_feature) -# if __has_feature(memory_sanitizer) - __attribute__((no_sanitize("memory"))) -# endif -#endif -local void slide_hash(deflate_state *s) { - unsigned n, m; - Posf *p; - uInt wsize = s->w_size; - - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m - wsize : NIL); - } while (--n); - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m - wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(deflate_state *s) { - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize + MAX_DIST(s)) { - - zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* ========================================================================= */ -int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, - int stream_size) { - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, - int windowBits, int memLevel, int strategy, - const char *version, int stream_size) { - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - if (windowBits < -15) - return Z_STREAM_ERROR; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - s->status = INIT_STATE; /* to pass state test in deflateReset() */ - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = (uInt)windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = (uInt)memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - /* We overlay pending_buf and sym_buf. This works since the average size - * for length/distance pairs over any compressed block is assured to be 31 - * bits or less. - * - * Analysis: The longest fixed codes are a length code of 8 bits plus 5 - * extra bits, for lengths 131 to 257. The longest fixed distance codes are - * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest - * possible fixed-codes length/distance pair is then 31 bits total. - * - * sym_buf starts one-fourth of the way into pending_buf. So there are - * three bytes in sym_buf for every four bytes in pending_buf. Each symbol - * in sym_buf is three bytes -- two for the distance and one for the - * literal/length. As each symbol is consumed, the pointer to the next - * sym_buf value to read moves forward three bytes. From that symbol, up to - * 31 bits are written to pending_buf. The closest the written pending_buf - * bits gets to the next sym_buf symbol to read is just before the last - * code is written. At that time, 31*(n - 2) bits have been written, just - * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at - * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1 - * symbols are written.) The closest the writing gets to what is unread is - * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and - * can range from 128 to 32768. - * - * Therefore, at a minimum, there are 142 bits of space between what is - * written and what is read in the overlain buffers, so the symbols cannot - * be overwritten by the compressed data. That space is actually 139 bits, - * due to the three-bit fixed-code block header. - * - * That covers the case where either Z_FIXED is specified, forcing fixed - * codes, or when the use of fixed codes is chosen, because that choice - * results in a smaller compressed block than dynamic codes. That latter - * condition then assures that the above analysis also covers all dynamic - * blocks. A dynamic-code block will only be chosen to be emitted if it has - * fewer bits than a fixed-code block would for the same set of symbols. - * Therefore its average symbol length is assured to be less than 31. So - * the compressed data for a dynamic block also cannot overwrite the - * symbols from which it is being constructed. - */ - - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); - s->pending_buf_size = (ulg)s->lit_bufsize * 4; - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } -#ifdef LIT_MEM - s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); - s->l_buf = s->pending_buf + (s->lit_bufsize << 2); - s->sym_end = s->lit_bufsize - 1; -#else - s->sym_buf = s->pending_buf + s->lit_bufsize; - s->sym_end = (s->lit_bufsize - 1) * 3; -#endif - /* We avoid equality with lit_bufsize*3 because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= - * Check for a valid deflate stream state. Return 0 if ok, 1 if not. - */ -local int deflateStateCheck(z_streamp strm) { - deflate_state *s; - if (strm == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) - return 1; - s = strm->state; - if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE && -#ifdef GZIP - s->status != GZIP_STATE && -#endif - s->status != EXTRA_STATE && - s->status != NAME_STATE && - s->status != COMMENT_STATE && - s->status != HCRC_STATE && - s->status != BUSY_STATE && - s->status != FINISH_STATE)) - return 1; - return 0; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength) { - deflate_state *s; - uInt str, n; - int wrap; - unsigned avail; - z_const unsigned char *next; - - if (deflateStateCheck(strm) || dictionary == Z_NULL) - return Z_STREAM_ERROR; - s = strm->state; - wrap = s->wrap; - if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) - return Z_STREAM_ERROR; - - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ - if (dictLength >= s->w_size) { - if (wrap == 0) { /* already empty otherwise */ - CLEAR_HASH(s); - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - dictionary += dictLength - s->w_size; /* use the tail */ - dictLength = s->w_size; - } - - /* insert dictionary into window and hash */ - avail = strm->avail_in; - next = strm->next_in; - strm->avail_in = dictLength; - strm->next_in = (z_const Bytef *)dictionary; - fill_window(s); - while (s->lookahead >= MIN_MATCH) { - str = s->strstart; - n = s->lookahead - (MIN_MATCH-1); - do { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - } while (--n); - s->strstart = str; - s->lookahead = MIN_MATCH-1; - fill_window(s); - } - s->strstart += s->lookahead; - s->block_start = (long)s->strstart; - s->insert = s->lookahead; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - strm->next_in = next; - strm->avail_in = avail; - s->wrap = wrap; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, - uInt *dictLength) { - deflate_state *s; - uInt len; - - if (deflateStateCheck(strm)) - return Z_STREAM_ERROR; - s = strm->state; - len = s->strstart + s->lookahead; - if (len > s->w_size) - len = s->w_size; - if (dictionary != Z_NULL && len) - zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len); - if (dictLength != Z_NULL) - *dictLength = len; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateResetKeep(z_streamp strm) { - deflate_state *s; - - if (deflateStateCheck(strm)) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = -#ifdef GZIP - s->wrap == 2 ? GZIP_STATE : -#endif - INIT_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = -2; - - _tr_init(s); - - return Z_OK; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init(deflate_state *s) { - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset(z_streamp strm) { - int ret; - - ret = deflateResetKeep(strm); - if (ret == Z_OK) - lm_init(strm->state); - return ret; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { - if (deflateStateCheck(strm) || strm->state->wrap != 2) - return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - if (pending != Z_NULL) - *pending = strm->state->pending; - if (bits != Z_NULL) - *bits = strm->state->bi_valid; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { - deflate_state *s; - int put; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; -#ifdef LIT_MEM - if (bits < 0 || bits > 16 || - (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; -#else - if (bits < 0 || bits > 16 || - s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; -#endif - do { - put = Buf_size - s->bi_valid; - if (put > bits) - put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); - s->bi_valid += put; - _tr_flush_bits(s); - value >>= put; - bits -= put; - } while (bits); - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { - deflate_state *s; - compress_func func; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - s->last_flush != -2) { - /* Flush the last buffer: */ - int err = deflate(strm, Z_BLOCK); - if (err == Z_STREAM_ERROR) - return err; - if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead) - return Z_BUF_ERROR; - } - if (s->level != level) { - if (s->level == 0 && s->matches != 0) { - if (s->matches == 1) - slide_hash(s); - else - CLEAR_HASH(s); - s->matches = 0; - } - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, - int nice_length, int max_chain) { - deflate_state *s; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = (uInt)good_length; - s->max_lazy_match = (uInt)max_lazy; - s->nice_match = nice_length; - s->max_chain_length = (uInt)max_chain; - return Z_OK; -} - -/* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns a - * close to exact, as well as small, upper bound on the compressed size. This - * is an expansion of ~0.03%, plus a small constant. - * - * For any setting other than those defaults for windowBits and memLevel, one - * of two worst case bounds is returned. This is at most an expansion of ~4% or - * ~13%, plus a small constant. - * - * Both the 0.03% and 4% derive from the overhead of stored blocks. The first - * one is for stored blocks of 16383 bytes (memLevel == 8), whereas the second - * is for stored blocks of 127 bytes (the worst case memLevel == 1). The - * expansion results from five bytes of header for each stored block. - * - * The larger expansion of 13% results from a window size less than or equal to - * the symbols buffer size (windowBits <= memLevel + 7). In that case some of - * the data being compressed may have slid out of the sliding window, impeding - * a stored block from being emitted. Then the only choice is a fixed or - * dynamic block, where a fixed block limits the maximum expansion to 9 bits - * per 8-bit byte, plus 10 bits for every block. The smallest block size for - * which this can occur is 255 (memLevel == 2). - * - * Shifts are used to approximate divisions, for speed. - */ -uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { - deflate_state *s; - uLong fixedlen, storelen, wraplen; - - /* upper bound for fixed blocks with 9-bit literals and length 255 - (memLevel == 2, which is the lowest that may not use stored blocks) -- - ~13% overhead plus a small constant */ - fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) + - (sourceLen >> 9) + 4; - - /* upper bound for stored blocks with length 127 (memLevel == 1) -- - ~4% overhead plus a small constant */ - storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + - (sourceLen >> 11) + 7; - - /* if can't get parameters, return larger bound plus a zlib wrapper */ - if (deflateStateCheck(strm)) - return (fixedlen > storelen ? fixedlen : storelen) + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; -#ifdef GZIP - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - Bytef *str; - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; -#endif - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return one of the conservative bounds */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + - wraplen; - - /* default settings: return tight bound for that case -- ~0.03% overhead - plus a small constant */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB(deflate_state *s, uInt b) { - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output, except for - * some deflate_stored() output, goes through this function so some - * applications may wish to modify it to avoid allocating a large - * strm->next_out buffer and copying into it. (See also read_buf()). - */ -local void flush_pending(z_streamp strm) { - unsigned len; - deflate_state *s = strm->state; - - _tr_flush_bits(s); - len = s->pending; - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, s->pending_out, len); - strm->next_out += len; - s->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - s->pending -= len; - if (s->pending == 0) { - s->pending_out = s->pending_buf; - } -} - -/* =========================================================================== - * Update the header CRC with the bytes s->pending_buf[beg..s->pending - 1]. - */ -#define HCRC_UPDATE(beg) \ - do { \ - if (s->gzhead->hcrc && s->pending > (beg)) \ - strm->adler = crc32(strm->adler, s->pending_buf + (beg), \ - s->pending - (beg)); \ - } while (0) - -/* ========================================================================= */ -int ZEXPORT deflate(z_streamp strm, int flush) { - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->avail_in != 0 && strm->next_in == Z_NULL) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - old_flush = s->last_flush; - s->last_flush = flush; - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Write the header */ - if (s->status == INIT_STATE && s->wrap == 0) - s->status = BUSY_STATE; - if (s->status == INIT_STATE) { - /* zlib header */ - uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8; - uInt level_flags; - - if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) - level_flags = 0; - else if (s->level < 6) - level_flags = 1; - else if (s->level == 6) - level_flags = 2; - else - level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = adler32(0L, Z_NULL, 0); - s->status = BUSY_STATE; - - /* Compression must start with an empty pending buffer */ - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } -#ifdef GZIP - if (s->status == GZIP_STATE) { - /* gzip header */ - strm->adler = crc32(0L, Z_NULL, 0); - put_byte(s, 31); - put_byte(s, 139); - put_byte(s, 8); - if (s->gzhead == Z_NULL) { - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, OS_CODE); - s->status = BUSY_STATE; - - /* Compression must start with an empty pending buffer */ - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } - else { - put_byte(s, (s->gzhead->text ? 1 : 0) + - (s->gzhead->hcrc ? 2 : 0) + - (s->gzhead->extra == Z_NULL ? 0 : 4) + - (s->gzhead->name == Z_NULL ? 0 : 8) + - (s->gzhead->comment == Z_NULL ? 0 : 16) - ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != Z_NULL) { - put_byte(s, s->gzhead->extra_len & 0xff); - put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); - } - if (s->gzhead->hcrc) - strm->adler = crc32(strm->adler, s->pending_buf, - s->pending); - s->gzindex = 0; - s->status = EXTRA_STATE; - } - } - if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != Z_NULL) { - ulg beg = s->pending; /* start of bytes to update crc */ - uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex; - while (s->pending + left > s->pending_buf_size) { - uInt copy = s->pending_buf_size - s->pending; - zmemcpy(s->pending_buf + s->pending, - s->gzhead->extra + s->gzindex, copy); - s->pending = s->pending_buf_size; - HCRC_UPDATE(beg); - s->gzindex += copy; - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - beg = 0; - left -= copy; - } - zmemcpy(s->pending_buf + s->pending, - s->gzhead->extra + s->gzindex, left); - s->pending += left; - HCRC_UPDATE(beg); - s->gzindex = 0; - } - s->status = NAME_STATE; - } - if (s->status == NAME_STATE) { - if (s->gzhead->name != Z_NULL) { - ulg beg = s->pending; /* start of bytes to update crc */ - int val; - do { - if (s->pending == s->pending_buf_size) { - HCRC_UPDATE(beg); - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - beg = 0; - } - val = s->gzhead->name[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - HCRC_UPDATE(beg); - s->gzindex = 0; - } - s->status = COMMENT_STATE; - } - if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != Z_NULL) { - ulg beg = s->pending; /* start of bytes to update crc */ - int val; - do { - if (s->pending == s->pending_buf_size) { - HCRC_UPDATE(beg); - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - beg = 0; - } - val = s->gzhead->comment[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - HCRC_UPDATE(beg); - } - s->status = HCRC_STATE; - } - if (s->status == HCRC_STATE) { - if (s->gzhead->hcrc) { - if (s->pending + 2 > s->pending_buf_size) { - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - strm->adler = crc32(0L, Z_NULL, 0); - } - s->status = BUSY_STATE; - - /* Compression must start with an empty pending buffer */ - flush_pending(strm); - if (s->pending != 0) { - s->last_flush = -1; - return Z_OK; - } - } -#endif - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = s->level == 0 ? deflate_stored(s, flush) : - s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - if (s->lookahead == 0) { - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - - if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ -#ifdef GZIP - if (s->wrap == 2) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); - put_byte(s, (Byte)(strm->total_in & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); - } - else -#endif - { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd(z_streamp strm) { - int status; - - if (deflateStateCheck(strm)) return Z_STREAM_ERROR; - - status = strm->state->status; - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { -#ifdef MAXSEG_64K - (void)dest; - (void)source; - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - - - if (deflateStateCheck(source) || dest == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); -#ifdef LIT_MEM - ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); - ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); -#else - ds->sym_buf = ds->pending_buf + ds->lit_bufsize; -#endif - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif /* MAXSEG_64K */ -} - -#ifndef FASTEST -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -local uInt longest_match(deflate_state *s, IPos cur_match) { - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = (int)s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan + best_len - 1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len - 1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match + best_len - 1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart + 3, + 5, up to strstart + 257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart + 257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan += 2) == *(ushf*)(match += 2) && - *(ushf*)(scan += 2) == *(ushf*)(match += 2) && - *(ushf*)(scan += 2) == *(ushf*)(match += 2) && - *(ushf*)(scan += 2) == *(ushf*)(match += 2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window + strstart + 257 */ - Assert(scan <= s->window + (unsigned)(s->window_size - 1), - "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend - scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len - 1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len - 1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart + 258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window + (unsigned)(s->window_size - 1), - "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan + best_len - 1); -#else - scan_end1 = scan[best_len - 1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} - -#else /* FASTEST */ - -/* --------------------------------------------------------------------------- - * Optimized version for FASTEST only - */ -local uInt longest_match(deflate_state *s, IPos cur_match) { - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len - 1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart + 258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; -} - -#endif /* FASTEST */ - -#ifdef ZLIB_DEBUG - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(deflate_state *s, IPos start, IPos match, int length) { - /* check that the match is indeed a match */ - Bytef *back = s->window + (int)match, *here = s->window + start; - IPos len = length; - if (match == (IPos)-1) { - /* match starts one byte before the current window -- just compare the - subsequent length-1 bytes */ - back++; - here++; - len--; - } - if (zmemcmp(back, here, len) != EQUAL) { - fprintf(stderr, " start %u, match %d, length %d\n", - start, (int)match, length); - do { - fprintf(stderr, "(%02x %02x)", *back++, *here++); - } while (--len != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start - match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif /* ZLIB_DEBUG */ - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ -} - -/* Maximum stored block length in deflate format (not including header). */ -#define MAX_STORED 65535 - -/* Minimum of a and b. */ -#define MIN(a, b) ((a) > (b) ? (b) : (a)) - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * - * In case deflateParams() is used to later switch to a non-zero compression - * level, s->matches (otherwise unused when storing) keeps track of the number - * of hash table slides to perform. If s->matches is 1, then one hash table - * slide will be done when switching. If s->matches is 2, the maximum value - * allowed here, then the hash table will be cleared, since two or more slides - * is the same as a clear. - * - * deflate_stored() is written to minimize the number of times an input byte is - * copied. It is most efficient with large input and output buffers, which - * maximizes the opportunities to have a single copy from next_in to next_out. - */ -local block_state deflate_stored(deflate_state *s, int flush) { - /* Smallest worthy block size when not flushing or finishing. By default - * this is 32K. This can be as small as 507 bytes for memLevel == 1. For - * large input and output buffers, the stored block size will be larger. - */ - unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size); - - /* Copy as many min_block or larger stored blocks directly to next_out as - * possible. If flushing, copy the remaining available input to next_out as - * stored blocks, if there is enough space. - */ - unsigned len, left, have, last = 0; - unsigned used = s->strm->avail_in; - do { - /* Set len to the maximum size block that we can copy directly with the - * available input data and output space. Set left to how much of that - * would be copied from what's left in the window. - */ - len = MAX_STORED; /* maximum deflate stored block length */ - have = (s->bi_valid + 42) >> 3; /* number of header bytes */ - if (s->strm->avail_out < have) /* need room for header */ - break; - /* maximum stored block length that will fit in avail_out: */ - have = s->strm->avail_out - have; - left = s->strstart - s->block_start; /* bytes left in window */ - if (len > (ulg)left + s->strm->avail_in) - len = left + s->strm->avail_in; /* limit len to the input */ - if (len > have) - len = have; /* limit len to the output */ - - /* If the stored block would be less than min_block in length, or if - * unable to copy all of the available input when flushing, then try - * copying to the window and the pending buffer instead. Also don't - * write an empty block when flushing -- deflate() does that. - */ - if (len < min_block && ((len == 0 && flush != Z_FINISH) || - flush == Z_NO_FLUSH || - len != left + s->strm->avail_in)) - break; - - /* Make a dummy stored block in pending to get the header bytes, - * including any pending bits. This also updates the debugging counts. - */ - last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0; - _tr_stored_block(s, (char *)0, 0L, last); - - /* Replace the lengths in the dummy stored block with len. */ - s->pending_buf[s->pending - 4] = len; - s->pending_buf[s->pending - 3] = len >> 8; - s->pending_buf[s->pending - 2] = ~len; - s->pending_buf[s->pending - 1] = ~len >> 8; - - /* Write the stored block header bytes. */ - flush_pending(s->strm); - -#ifdef ZLIB_DEBUG - /* Update debugging counts for the data about to be copied. */ - s->compressed_len += len << 3; - s->bits_sent += len << 3; -#endif - - /* Copy uncompressed bytes from the window to next_out. */ - if (left) { - if (left > len) - left = len; - zmemcpy(s->strm->next_out, s->window + s->block_start, left); - s->strm->next_out += left; - s->strm->avail_out -= left; - s->strm->total_out += left; - s->block_start += left; - len -= left; - } - - /* Copy uncompressed bytes directly from next_in to next_out, updating - * the check value. - */ - if (len) { - read_buf(s->strm, s->strm->next_out, len); - s->strm->next_out += len; - s->strm->avail_out -= len; - s->strm->total_out += len; - } - } while (last == 0); - - /* Update the sliding window with the last s->w_size bytes of the copied - * data, or append all of the copied data to the existing window if less - * than s->w_size bytes were copied. Also update the number of bytes to - * insert in the hash tables, in the event that deflateParams() switches to - * a non-zero compression level. - */ - used -= s->strm->avail_in; /* number of input bytes directly copied */ - if (used) { - /* If any input was used, then no unused input remains in the window, - * therefore s->block_start == s->strstart. - */ - if (used >= s->w_size) { /* supplant the previous history */ - s->matches = 2; /* clear hash */ - zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size); - s->strstart = s->w_size; - s->insert = s->strstart; - } - else { - if (s->window_size - s->strstart <= used) { - /* Slide the window down. */ - s->strstart -= s->w_size; - zmemcpy(s->window, s->window + s->w_size, s->strstart); - if (s->matches < 2) - s->matches++; /* add a pending slide_hash() */ - if (s->insert > s->strstart) - s->insert = s->strstart; - } - zmemcpy(s->window + s->strstart, s->strm->next_in - used, used); - s->strstart += used; - s->insert += MIN(used, s->w_size - s->insert); - } - s->block_start = s->strstart; - } - if (s->high_water < s->strstart) - s->high_water = s->strstart; - - /* If the last block was written to next_out, then done. */ - if (last) - return finish_done; - - /* If flushing and all input has been consumed, then done. */ - if (flush != Z_NO_FLUSH && flush != Z_FINISH && - s->strm->avail_in == 0 && (long)s->strstart == s->block_start) - return block_done; - - /* Fill the window with any remaining input. */ - have = s->window_size - s->strstart; - if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) { - /* Slide the window down. */ - s->block_start -= s->w_size; - s->strstart -= s->w_size; - zmemcpy(s->window, s->window + s->w_size, s->strstart); - if (s->matches < 2) - s->matches++; /* add a pending slide_hash() */ - have += s->w_size; /* more space now */ - if (s->insert > s->strstart) - s->insert = s->strstart; - } - if (have > s->strm->avail_in) - have = s->strm->avail_in; - if (have) { - read_buf(s->strm, s->window + s->strstart, have); - s->strstart += have; - s->insert += MIN(have, s->w_size - s->insert); - } - if (s->high_water < s->strstart) - s->high_water = s->strstart; - - /* There was not enough avail_out to write a complete worthy or flushed - * stored block to next_out. Write a stored block to pending instead, if we - * have enough input for a worthy block, or if flushing and there is enough - * room for the remaining input as a stored block in the pending buffer. - */ - have = (s->bi_valid + 42) >> 3; /* number of header bytes */ - /* maximum stored block length that will fit in pending: */ - have = MIN(s->pending_buf_size - have, MAX_STORED); - min_block = MIN(have, s->w_size); - left = s->strstart - s->block_start; - if (left >= min_block || - ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && - s->strm->avail_in == 0 && left <= have)) { - len = MIN(left, have); - last = flush == Z_FINISH && s->strm->avail_in == 0 && - len == left ? 1 : 0; - _tr_stored_block(s, (charf *)s->window + s->block_start, len, last); - s->block_start += len; - flush_pending(s->strm); - } - - /* We've done all we can with the available input and output. */ - return last ? finish_started : need_more; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(deflate_state *s, int flush) { - IPos hash_head; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart + 2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit(s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} - -#ifndef FASTEST -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(deflate_state *s, int flush) { - IPos hash_head; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart + 2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED -#if TOO_FAR <= 32767 - || (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR) -#endif - )) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart - 1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart - 1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart - 1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length - 1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart - 1])); - _tr_tally_lit(s, s->window[s->strstart - 1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart - 1])); - _tr_tally_lit(s, s->window[s->strstart - 1], bflush); - s->match_available = 0; - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} -#endif /* FASTEST */ - -/* =========================================================================== - * For Z_RLE, simply look for runs of bytes, generate matches only of distance - * one. Do not maintain a hash table. (It will be regenerated if this run of - * deflate switches away from Z_RLE.) - */ -local block_state deflate_rle(deflate_state *s, int flush) { - int bflush; /* set if current block must be flushed */ - uInt prev; /* byte at distance one to match */ - Bytef *scan, *strend; /* scan goes up to strend for length of run */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the longest run, plus one for the unrolled loop. - */ - if (s->lookahead <= MAX_MATCH) { - fill_window(s); - if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - s->match_length = 0; - if (s->lookahead >= MIN_MATCH && s->strstart > 0) { - scan = s->window + s->strstart - 1; - prev = *scan; - if (prev == *++scan && prev == *++scan && prev == *++scan) { - strend = s->window + s->strstart + MAX_MATCH; - do { - } while (prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - s->match_length = MAX_MATCH - (uInt)(strend - scan); - if (s->match_length > s->lookahead) - s->match_length = s->lookahead; - } - Assert(scan <= s->window + (uInt)(s->window_size - 1), - "wild scan"); - } - - /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, s->match_length); - - _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - s->strstart += s->match_length; - s->match_length = 0; - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit(s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -local block_state deflate_huff(deflate_state *s, int flush) { - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we have a literal to write. */ - if (s->lookahead == 0) { - fill_window(s); - if (s->lookahead == 0) { - if (flush == Z_NO_FLUSH) - return need_more; - break; /* flush the current block */ - } - } - - /* Output a literal byte */ - s->match_length = 0; - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit(s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->sym_next) - FLUSH_BLOCK(s, 0); - return block_done; -} diff --git a/code/thirdparty/zlib-1.3.1/infback.c b/code/thirdparty/zlib-1.3.1/infback.c deleted file mode 100644 index e7b25b30..00000000 --- a/code/thirdparty/zlib-1.3.1/infback.c +++ /dev/null @@ -1,628 +0,0 @@ -/* infback.c -- inflate using a call-back interface - * Copyright (C) 1995-2022 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - This code is largely copied from inflate.c. Normally either infback.o or - inflate.o would be linked into an application--not both. The interface - with inffast.c is retained so that optimized assembler-coded versions of - inflate_fast() can be used with either inflate.c or infback.c. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* - strm provides memory allocation functions in zalloc and zfree, or - Z_NULL to use the library memory allocation functions. - - windowBits is in the range 8..15, and window is a user-supplied - window and output buffer that is 2**windowBits bytes. - */ -int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, - unsigned char FAR *window, const char *version, - int stream_size) { - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL || window == Z_NULL || - windowBits < 8 || windowBits > 15) - return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *)ZALLOC(strm, 1, - sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->dmax = 32768U; - state->wbits = (uInt)windowBits; - state->wsize = 1U << windowBits; - state->window = window; - state->wnext = 0; - state->whave = 0; - state->sane = 1; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(struct inflate_state FAR *state) { -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -/* Macros for inflateBack(): */ - -/* Load returned state from inflate_fast() */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Set state from registers for inflate_fast() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Assure that some input is available. If input is requested, but denied, - then return a Z_BUF_ERROR from inflateBack(). */ -#define PULL() \ - do { \ - if (have == 0) { \ - have = in(in_desc, &next); \ - if (have == 0) { \ - next = Z_NULL; \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflateBack() - with an error if there is no input available. */ -#define PULLBYTE() \ - do { \ - PULL(); \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflateBack() with - an error. */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* Assure that some output space is available, by writing out the window - if it's full. If the write fails, return from inflateBack() with a - Z_BUF_ERROR. */ -#define ROOM() \ - do { \ - if (left == 0) { \ - put = state->window; \ - left = state->wsize; \ - state->whave = left; \ - if (out(out_desc, put, left)) { \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* - strm provides the memory allocation functions and window buffer on input, - and provides information on the unused input on return. For Z_DATA_ERROR - returns, strm will also provide an error message. - - in() and out() are the call-back input and output functions. When - inflateBack() needs more input, it calls in(). When inflateBack() has - filled the window with output, or when it completes with data in the - window, it calls out() to write out the data. The application must not - change the provided input until in() is called again or inflateBack() - returns. The application must not change the window/output buffer until - inflateBack() returns. - - in() and out() are called with a descriptor parameter provided in the - inflateBack() call. This parameter can be a structure that provides the - information required to do the read or write, as well as accumulated - information on the input and output such as totals and check values. - - in() should return zero on failure. out() should return non-zero on - failure. If either in() or out() fails, than inflateBack() returns a - Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it - was in() or out() that caused in the error. Otherwise, inflateBack() - returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format - error, or Z_MEM_ERROR if it could not allocate memory for the state. - inflateBack() can also return Z_STREAM_ERROR if the input parameters - are not correct, i.e. strm is Z_NULL or the state was not initialized. - */ -int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc) { - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - /* Check that the strm exists and that the state was initialized */ - if (strm == Z_NULL || strm->state == Z_NULL) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* Reset the state */ - strm->msg = Z_NULL; - state->mode = TYPE; - state->last = 0; - state->whave = 0; - next = strm->next_in; - have = next != Z_NULL ? strm->avail_in : 0; - hold = 0; - bits = 0; - put = state->window; - left = state->wsize; - - /* Inflate until end of block marked as last */ - for (;;) - switch (state->mode) { - case TYPE: - /* determine and dispatch block type */ - if (state->last) { - BYTEBITS(); - state->mode = DONE; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN; /* decode codes */ - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - - case STORED: - /* get and verify stored block length */ - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - - /* copy stored block from input to output */ - while (state->length != 0) { - copy = state->length; - PULL(); - ROOM(); - if (copy > have) copy = have; - if (copy > left) copy = left; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - - case TABLE: - /* get dynamic table entries descriptor */ - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - - /* get code length code lengths (not a typo) */ - state->have = 0; - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - - /* get length and distance code code lengths */ - state->have = 0; - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = (unsigned)(state->lens[state->have - 1]); - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (code const FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN; - /* fallthrough */ - - case LEN: - /* use inflate_fast() if we have enough input and output */ - if (have >= 6 && left >= 258) { - RESTORE(); - if (state->whave < state->wsize) - state->whave = state->wsize - left; - inflate_fast(strm, state->wsize); - LOAD(); - break; - } - - /* get a literal, length, or end-of-block code */ - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - state->length = (unsigned)here.val; - - /* process literal */ - if (here.op == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - ROOM(); - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - } - - /* process end of block */ - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - - /* invalid code */ - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - - /* length code -- get extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - - /* get distance code */ - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - - /* get distance extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - } - if (state->offset > state->wsize - (state->whave < state->wsize ? - left : 0)) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - - /* copy match from window to output */ - do { - ROOM(); - copy = state->wsize - state->offset; - if (copy < left) { - from = put + copy; - copy = left - copy; - } - else { - from = put - state->offset; - copy = left; - } - if (copy > state->length) copy = state->length; - state->length -= copy; - left -= copy; - do { - *put++ = *from++; - } while (--copy); - } while (state->length != 0); - break; - - case DONE: - /* inflate stream terminated properly */ - ret = Z_STREAM_END; - goto inf_leave; - - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - - default: - /* can't happen, but makes compilers happy */ - ret = Z_STREAM_ERROR; - goto inf_leave; - } - - /* Write leftover output and return unused input */ - inf_leave: - if (left < state->wsize) { - if (out(out_desc, state->window, state->wsize - left) && - ret == Z_STREAM_END) - ret = Z_BUF_ERROR; - } - strm->next_in = next; - strm->avail_in = have; - return ret; -} - -int ZEXPORT inflateBackEnd(z_streamp strm) { - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} diff --git a/code/thirdparty/zlib-1.3.1/trees.c b/code/thirdparty/zlib-1.3.1/trees.c deleted file mode 100644 index 6a523ef3..00000000 --- a/code/thirdparty/zlib-1.3.1/trees.c +++ /dev/null @@ -1,1117 +0,0 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2024 Jean-loup Gailly - * detect_data_type() function provided freely by Cosmin Truta, 2006 - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id$ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef ZLIB_DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -#ifdef NO_INIT_GLOBAL_POINTERS -# define TCONST -#else -# define TCONST const -#endif - -local TCONST static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local TCONST static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local TCONST static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(unsigned code, int len) { - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(deflate_state *s) { - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(deflate_state *s) { - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent + 7) & ~7; -#endif -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits - 1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, - "inconsistent bit counts"); - Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); - - for (n = 0; n <= max_code; n++) { - int len = tree[n].Len; - if (len == 0) continue; - /* Now reverse the bits */ - tree[n].Code = (ush)bi_reverse(next_code[len]++, len); - - Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", - n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); - } -} - -#ifdef GEN_TREES_H -local void gen_trees_header(void); -#endif - -#ifndef ZLIB_DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* !ZLIB_DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef ZLIB_DEBUG -local void send_bits(deflate_state *s, int value, int length) { - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16 - bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= (ush)value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !ZLIB_DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = (int)value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* ZLIB_DEBUG */ - - -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init(void) { -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ -#ifdef NO_INIT_GLOBAL_POINTERS - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; -#endif - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1 << extra_lbits[code]); n++) { - _length_code[length++] = (uch)code; - } - } - Assert (length == 256, "tr_static_init: length != 256"); - /* Note that the length 255 (match length 258) can be represented - * in two different ways: code 284 + 5 bits or code 285, so we - * overwrite length_code[255] to use the best encoding: - */ - _length_code[length - 1] = (uch)code; - - /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1 << extra_dbits[code]); n++) { - _dist_code[dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: dist != 256"); - dist >>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256 + dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Generate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef ZLIB_DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width) - 1 ? ",\n" : ", ")) - -void gen_trees_header(void) { - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, - "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(deflate_state *s) { - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void ZLIB_INTERNAL _tr_init(deflate_state *s) { - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(deflate_state *s, ct_data *tree, int k) { - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j + 1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(deflate_state *s, tree_desc *desc) { - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max + 1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n - base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (unsigned)(bits + xbits); - if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits); - } - if (overflow == 0) return; - - Tracev((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length - 1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits + 1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if ((unsigned) tree[m].Len != (unsigned) bits) { - Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -#ifdef DUMP_BL_TREE -# include -#endif - -/* =========================================================================== - * Construct one Huffman tree and assigns the code bit strings and lengths. - * Update the total bit length for the current block. - * IN assertion: the field freq is set for all tree elements. - * OUT assertions: the fields len and code are set to the optimal bit length - * and corresponding code. The length opt_len is updated; static_len is - * also updated if stree is not null. The field max_code is set. - */ -local void build_tree(deflate_state *s, tree_desc *desc) { - ct_data *tree = desc->dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n + 1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2 + 1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? - s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code + 1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n + 1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree(deflate_state *s, ct_data *tree, int max_code) { - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code + 1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n + 1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count - 3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count - 3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count - 11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(deflate_state *s) { - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except the - * lengths of the bit lengths codes and the 5 + 5 + 4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*((ulg)max_blindex + 1) + 5 + 5 + 4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(deflate_state *s, int lcodes, int dcodes, - int blcodes) { - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes - 1, 5); - send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes - 1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes - 1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, - ulg stored_len, int last) { - send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */ - bi_windup(s); /* align on byte boundary */ - put_short(s, (ush)stored_len); - put_short(s, (ush)~stored_len); - if (stored_len) - zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len); - s->pending += stored_len; -#ifdef ZLIB_DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; - s->bits_sent += 2*16; - s->bits_sent += stored_len << 3; -#endif -} - -/* =========================================================================== - * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) - */ -void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { - bi_flush(s); -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - */ -void ZLIB_INTERNAL _tr_align(deflate_state *s) { - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef ZLIB_DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(deflate_state *s, const ct_data *ltree, - const ct_data *dtree) { - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in symbol buffers */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { -#ifdef LIT_MEM - dist = s->d_buf[sx]; - lc = s->l_buf[sx++]; -#else - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; -#endif - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check for no overlay of pending_buf on needed symbols */ -#ifdef LIT_MEM - Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); -#else - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); -#endif - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(deflate_state *s) { - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and write out the encoded block. - */ -void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, - ulg stored_len, int last) { - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is binary or text */ - if (s->strm->data_type == Z_UNKNOWN) - s->strm->data_type = detect_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (s->opt_len + 3 + 7) >> 3; - static_lenb = (s->static_len + 3 + 7) >> 3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->sym_next / 3)); - -#ifndef FORCE_STATIC - if (static_lenb <= opt_lenb || s->strategy == Z_FIXED) -#endif - opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len + 4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, last); - - } else if (static_lenb == opt_lenb) { - send_bits(s, (STATIC_TREES<<1) + last, 3); - compress_block(s, (const ct_data *)static_ltree, - (const ct_data *)static_dtree); -#ifdef ZLIB_DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1) + last, 3); - send_all_trees(s, s->l_desc.max_code + 1, s->d_desc.max_code + 1, - max_blindex + 1); - compress_block(s, (const ct_data *)s->dyn_ltree, - (const ct_data *)s->dyn_dtree); -#ifdef ZLIB_DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (last) { - bi_windup(s); -#ifdef ZLIB_DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len >> 3, - s->compressed_len - 7*last)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { -#ifdef LIT_MEM - s->d_buf[s->sym_next] = (ush)dist; - s->l_buf[s->sym_next++] = (uch)lc; -#else - s->sym_buf[s->sym_next++] = (uch)dist; - s->sym_buf[s->sym_next++] = (uch)(dist >> 8); - s->sym_buf[s->sym_next++] = (uch)lc; -#endif - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc] + LITERALS + 1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - return (s->sym_next == s->sym_end); -} diff --git a/code/thirdparty/zlib-1.3.1/uncompr.c b/code/thirdparty/zlib-1.3.1/uncompr.c deleted file mode 100644 index 5e256663..00000000 --- a/code/thirdparty/zlib-1.3.1/uncompr.c +++ /dev/null @@ -1,85 +0,0 @@ -/* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Decompresses the source buffer into the destination buffer. *sourceLen is - the byte length of the source buffer. Upon entry, *destLen is the total size - of the destination buffer, which must be large enough to hold the entire - uncompressed data. (The size of the uncompressed data must have been saved - previously by the compressor and transmitted to the decompressor by some - mechanism outside the scope of this compression library.) Upon exit, - *destLen is the size of the decompressed data and *sourceLen is the number - of source bytes consumed. Upon return, source + *sourceLen points to the - first unused input byte. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, or - Z_DATA_ERROR if the input data was corrupted, including if the input data is - an incomplete zlib stream. -*/ -int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong *sourceLen) { - z_stream stream; - int err; - const uInt max = (uInt)-1; - uLong len, left; - Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ - - len = *sourceLen; - if (*destLen) { - left = *destLen; - *destLen = 0; - } - else { - left = 1; - dest = buf; - } - - stream.next_in = (z_const Bytef *)source; - stream.avail_in = 0; - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - stream.opaque = (voidpf)0; - - err = inflateInit(&stream); - if (err != Z_OK) return err; - - stream.next_out = dest; - stream.avail_out = 0; - - do { - if (stream.avail_out == 0) { - stream.avail_out = left > (uLong)max ? max : (uInt)left; - left -= stream.avail_out; - } - if (stream.avail_in == 0) { - stream.avail_in = len > (uLong)max ? max : (uInt)len; - len -= stream.avail_in; - } - err = inflate(&stream, Z_NO_FLUSH); - } while (err == Z_OK); - - *sourceLen -= len + stream.avail_in; - if (dest != buf) - *destLen = stream.total_out; - else if (stream.total_out && err == Z_BUF_ERROR) - left = 1; - - inflateEnd(&stream); - return err == Z_STREAM_END ? Z_OK : - err == Z_NEED_DICT ? Z_DATA_ERROR : - err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : - err; -} - -int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, - uLong sourceLen) { - return uncompress2(dest, destLen, source, &sourceLen); -} diff --git a/misc/update-libs.sh b/misc/update-libs.sh index 6519bfa2..8dd22484 100755 --- a/misc/update-libs.sh +++ b/misc/update-libs.sh @@ -47,12 +47,12 @@ prepare "https://downloads.xiph.org/releases/ogg/libogg-${OGG_VERSION}.tar.gz" \ prepare "https://downloads.xiph.org/releases/vorbis/libvorbis-${VORBIS_VERSION}.tar.gz" \ "./configure" \ "\./\(include\|lib\)/.*\.[ch]" \ - "\./lib/\(barkmel\|psytune\|tone\)\.c" + "\./lib/\(barkmel\|psytune\|tone\|vorbisenc\)\.c" prepare "https://downloads.xiph.org/releases/opus/opus-${OPUS_VERSION}.tar.gz" \ "./configure" \ "\./\(celt\|include\|silk\|src\)/.*\.[ch]" \ - "\./.*\(arm\|_compare\|_demo\|fixed\|mips\|tests\|x86\).*" + "\./.*\(arm\|_compare\|_demo\|fixed\|mapping_matrix\|mips\|opus_projection_\|tests\|x86\).*" prepare "https://downloads.xiph.org/releases/opus/opusfile-${OPUSFILE_VERSION}.tar.gz" \ "./configure" \ @@ -61,7 +61,7 @@ prepare "https://downloads.xiph.org/releases/opus/opusfile-${OPUSFILE_VERSION}.t prepare "https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz" \ "" \ "\./[^/]*\.[ch]" \ - "\./gz.*\.[c]" + "\./\(compress\|deflate\|infback\|trees\|uncompr\|gz.*\)\.[c]" prepare "https://www.ijg.org/files/jpegsrc.v${JPEG_VERSION}.tar.gz" \ "./configure" \