X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=vq%2Fhuffbuild.c;h=014c81c13d89b1207a8ac3a2c771328b6ded5cee;hb=018ca26dece618457dd13585cad52941193c4a25;hp=9aa819ec61806c70ad5057090f9d828246f83d78;hpb=b71261a0a63f1687e62a539c9da263bf73fdd14b;p=platform%2Fupstream%2Flibvorbis.git diff --git a/vq/huffbuild.c b/vq/huffbuild.c index 9aa819e..014c81c 100644 --- a/vq/huffbuild.c +++ b/vq/huffbuild.c @@ -1,17 +1,16 @@ /******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * - * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH * - * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * 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-2001 * - * by the XIPHOPHORUS Company http://www.xiph.org/ * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2014 * + * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: hufftree builder - last mod: $Id: huffbuild.c,v 1.7 2001/02/02 03:52:27 xiphmont Exp $ ********************************************************************/ @@ -49,13 +48,13 @@ static int getval(FILE *in,int begin,int n,int group,int max){ static void usage(){ fprintf(stderr, - "usage:\n" - "huffbuild .vqd [noguard]\n" - " where begin,n,group is first scalar, \n" - " number of scalars of each in line,\n" - " number of scalars in a group\n" - "eg: huffbuild reslongaux.vqd 0,1024,4\n" - "produces reslongaux.vqh\n\n"); + "usage:\n" + "huffbuild .vqd | [noguard]\n" + " where begin,n,group is first scalar, \n" + " number of scalars of each in line,\n" + " number of scalars in a group\n" + "eg: huffbuild reslongaux.vqd 0,1024,4\n" + "produces reslongaux.vqh\n\n"); exit(1); } @@ -65,6 +64,7 @@ int main(int argc, char *argv[]){ int i,j,k,begin,n,subn,guard=1; FILE *file; int maxval=0; + int loval=0; if(argc<3)usage(); if(argc==4)guard=0; @@ -76,19 +76,27 @@ int main(int argc, char *argv[]){ { char *pos=strchr(argv[2],','); - begin=atoi(argv[2]); - if(!pos) - usage(); - else - n=atoi(pos+1); - pos=strchr(pos+1,','); - if(!pos) - usage(); - else - subn=atoi(pos+1); - if(n/subn*subn != n){ - fprintf(stderr,"n must be divisible by group\n"); - exit(1); + char *dpos=strchr(argv[2],'-'); + if(dpos){ + loval=atoi(argv[2]); + maxval=atoi(dpos+1); + subn=1; + begin=0; + }else{ + begin=atoi(argv[2]); + if(!pos) + usage(); + else + n=atoi(pos+1); + pos=strchr(pos+1,','); + if(!pos) + usage(); + else + subn=atoi(pos+1); + if(n/subn*subn != n){ + fprintf(stderr,"n must be divisible by group\n"); + exit(1); + } } } @@ -96,36 +104,45 @@ int main(int argc, char *argv[]){ file=fopen(infile,"r"); if(!file){ fprintf(stderr,"Could not open file %s\n",infile); - exit(1); + if(!maxval) + exit(1); + else + fprintf(stderr," making untrained books.\n"); + } - i=0; - while(1){ - long v; - if(get_next_ivalue(file,&v))break; - if(v>maxval)maxval=v; - if(!(i++&0xff))spinnit("loading... ",i); + if(!maxval){ + i=0; + while(1){ + long v; + if(get_next_ivalue(file,&v))break; + if(v>maxval)maxval=v; + + if(!(i++&0xff))spinnit("loading... ",i); + } + rewind(file); + maxval++; } - rewind(file); - maxval++; { long vals=pow(maxval,subn); - long *hist=_ogg_malloc(vals*sizeof(long)); - long *lengths=_ogg_malloc(vals*sizeof(long)); - - for(j=0;j=vals)break; + hist[val]++; + if(!(i--&0xff))spinnit("loading... ",i*subn); + } + fclose(file); } - fclose(file); - + /* we have the probabilities, build the tree */ fprintf(stderr,"Building tree for %ld entries\n",vals); build_tree_from_lengths0(vals,hist,lengths); @@ -137,54 +154,31 @@ int main(int argc, char *argv[]){ strcat(buffer,".vqh"); file=fopen(buffer,"w"); if(!file){ - fprintf(stderr,"Could not open file %s\n",buffer); - exit(1); + fprintf(stderr,"Could not open file %s\n",buffer); + exit(1); } } - - fprintf(file, - "/********************************************************************\n" - " * *\n" - " * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *\n" - " * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *\n" - " * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *\n" - " * PLEASE READ THESE TERMS DISTRIBUTING. *\n" - " * *\n" - " * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999 *\n" - " * by 1999 Monty and The XIPHOPHORUS Company *\n" - " * http://www.xiph.org/ *\n" - " * *\n" - " ********************************************************************\n" - "\n" - " function: static codebook autogenerated by huff/huffbuld\n" - "\n" - " ********************************************************************/\n\n"); - - fprintf(file,"#ifndef _V_%s_VQH_\n#define _V_%s_VQH_\n",base,base); - fprintf(file,"#include \"codebook.h\"\n\n"); - + /* first, the static vectors, then the book structure to tie it together. */ /* lengthlist */ - fprintf(file,"static long _huff_lengthlist_%s[] = {\n",base); + fprintf(file,"static const char _huff_lengthlist_%s[] = {\n",base); for(j=0;j