X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/76ff75b8c05625d532518113a5baddb2fc0a1196..84e51293e6a1c380f80f5579fcf521bb655c2652:/io.c diff --git a/io.c b/io.c index 9b2aedb6..1fdbed52 100644 --- a/io.c +++ b/io.c @@ -37,7 +37,7 @@ malloc_entry malloc_pointers[MAXMAL]; static void -malloc_init() { +malloc_init(void) { int i; for(i=0; ialloc = 10; + mp->used = 0; + mp->p = mymalloc(sizeof(void*)*mp->alloc); +} +void +i_mempool_extend(i_mempool *mp) { + mp->p = myrealloc(mp->p, mp->alloc * 2); + mp->alloc *=2; +} + +void * +i_mempool_alloc(i_mempool *mp, size_t size) { + if (mp->used == mp->alloc) i_mempool_extend(mp); + mp->p[mp->used] = mymalloc(size); + mp->used++; + return mp->p[mp->used-1]; +} +void +i_mempool_destroy(i_mempool *mp) { + unsigned int i; + for(i=0; iused; i++) myfree(mp->p[i]); + myfree(mp->p); +} + + + +/* Should these really be here? */ + #undef min #undef max int -min(int a,int b) { +i_min(int a,int b) { if (ab) return a; else return b; } -int -myread(int fd,void *buf,int len) { - unsigned char* bufc; - int bc,rc; - bufc = (unsigned char*)buf; - bc=0; - while( ((rc=read(fd,bufc+bc,len-bc))>0 ) && (bc!=len) ) bc+=rc; - if ( rc < 0 ) return rc; - else return bc; -} -int -mywrite(int fd,void *buf,int len) { - unsigned char* bufc; - int bc,rc; - bufc=(unsigned char*)buf; - bc=0; - while(((rc=write(fd,bufc+bc,len-bc))>0) && (bc!=len)) bc+=rc; - if (rc<0) return rc; - else return bc; -} +struct utf8_size { + int mask, expect; + int size; +}; -void -interleave(unsigned char *inbuffer,unsigned char *outbuffer,int rowsize,int channels) { - int ch,ind,i; - i=0; - if ( inbuffer==outbuffer ) return; /* Check if data is already in interleaved format */ - for( ind=0; ind