author | ecalot
<ecalot> 2006-06-05 23:47:13 UTC |
committer | ecalot
<ecalot> 2006-06-05 23:47:13 UTC |
parent | d9b7f10cf1265697dbe42a580c340b73e6b9fe34 |
PR/src/lib/compression/lzg_decompress.c | +5 | -2 |
PR/src/lib/compression/rlev_decompress.c | +8 | -8 |
PR/src/lib/object/image/image256.c | +57 | -14 |
PR/src/xml/resources.xml | +1 | -1 |
diff --git a/PR/src/lib/compression/lzg_decompress.c b/PR/src/lib/compression/lzg_decompress.c index 976b6cf..f377bfd 100644 --- a/PR/src/lib/compression/lzg_decompress.c +++ b/PR/src/lib/compression/lzg_decompress.c @@ -55,6 +55,8 @@ int expandLzg(const unsigned char* input, int inputSize, if (*outputSize) (*outputSize)+=LZG_WINDOW_SIZE; else *outputSize=65000; +printf("Entering LZG layer:\n Init:\n input: size=%d\n output: allocated size=%d\n",inputSize,(*outputSize)); + /* initialize the first 1024 bytes of the window with zeros */ for(oCursor=0;oCursor<LZG_WINDOW_SIZE;output[oCursor++]=0); @@ -94,12 +96,13 @@ int expandLzg(const unsigned char* input, int inputSize, /* ignore the first 1024 bytes */ *outputSize=oCursor-LZG_WINDOW_SIZE; *output2=(unsigned char*)malloc(*outputSize); +printf(" results:\n input: read cursor=%d input size resulted=%d\n",iCursor,inputSize); for(iCursor=LZG_WINDOW_SIZE;iCursor<oCursor;iCursor++) (*output2)[iCursor-LZG_WINDOW_SIZE]=output[iCursor]; -/*printf("oc=%d os=%d ic=%d is=%d\n",oCursor,(*outputSize),iCursor,inputSize);*/ +printf(" output: size=%d (without window=%d)\n error control: maskbyte=%01x\n",oCursor,(*outputSize),maskbyte); - if (oCursor>=(*outputSize)) return inputSize; + if (oCursor>=(*outputSize)) return inputSize; /* TODO: this case never happens !!! */ return (!maskbyte)-1; /*return rep?COMPRESS_RESULT_WARNING:COMPRESS_RESULT_SUCCESS;*/ diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c index 27d8f11..6749a4c 100644 --- a/PR/src/lib/compression/rlev_decompress.c +++ b/PR/src/lib/compression/rlev_decompress.c @@ -44,8 +44,8 @@ int expandRleC(const unsigned char* input, int inputSize, int oCursor=0; int iCursor=0; int done=0; - int aux=0; - int lineSize; + /*int aux=0;*/ + /*int lineSize;*/ /* reserve memory */ /* if ((*output=(unsigned char*)malloc(40000))==NULL) return COMPRESS_RESULT_FATAL;*/ @@ -54,7 +54,7 @@ int expandRleC(const unsigned char* input, int inputSize, while (iCursor<inputSize) { rep=(input[iCursor++]); /*printf("o=%d i=%d\n",oCursor,iCursor);*/ - if (1||(done)||(oCursor%verif)) { +/* if (1||(done)||(oCursor%verif)) {*/ done=0; if (rep&0x80) { /* repeat */ /*rep&=~0x80;*/ @@ -68,7 +68,7 @@ int expandRleC(const unsigned char* input, int inputSize, (output)[oCursor++]=input[iCursor++]; } } - } else { +/* } else { if (aux) if (lineSize!=(iCursor-aux)) printf("Error, line size is wrong: lineSize=%d got=%d\n",lineSize,(iCursor-aux)); @@ -77,7 +77,7 @@ int expandRleC(const unsigned char* input, int inputSize, iCursor++; done=1; aux=iCursor; -/* if (oCursor==28800) { +* if (oCursor==28800) { int g; printf("error time: (ls=%d)",lineSize); for (g=-20;g<100;g++) @@ -85,14 +85,14 @@ int expandRleC(const unsigned char* input, int inputSize, printf("\n"); iCursor-=4; }*/ - } + /* }*/ } /*printf("done=%d i=%d but=%d\n",done,iCursor,inputSize);*/ *outputSize=oCursor; - printf("rep=%d\n",rep); - return (rep==1)?COMPRESS_RESULT_SUCCESS:COMPRESS_RESULT_WARNING; +/* printf("rep=%d\n",rep);*/ + return (rep==255)?COMPRESS_RESULT_SUCCESS:COMPRESS_RESULT_WARNING; } diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 67be9ed..eb5df43 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -141,7 +141,7 @@ int mExpandGraphic256(const unsigned char* data,tImage *image, int dataSizeInByt } /* special format has a special function */ - return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes); + return pop2decompress(data,dataSizeInBytes,image->width,&(image->pix),&imageSizeInBytes); } /* Compress an image into binary data */ @@ -203,10 +203,11 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign unsigned char* lineI; /* chunk */ unsigned char* lineO; /* chunk */ int lineSize; - int aux; + int aux,aux2,remaining; + int tempOutputSize; + int osCheck; - int tempOutputSize; - int osCheck; + printf("\n\nNew image!\n"); *output=malloc(40000); lineO=*output; @@ -215,29 +216,69 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign osCheck=array2short(input)-6; input+=2; - /*os=osCheck;*/ /* First layer: expand the lgz */ - /*tempOutputSize=0;*/ - tempOutputSize=osCheck; - printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck); + tempOutputSize=osCheck+6; + + remaining=expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize); + printf("Call:\n return=%d function input size=%d\n internal output size=%d result output size=%d\n", + remaining,inputSize,osCheck,tempOutputSize); + if ((osCheck+6)!=tempOutputSize) + printf(" Special case: more is coming\n"); /* Second layer expand each rle line */ lineI=tempOutput; + printf("RLE loop layer:\n"); do { aux=array2short(lineI); lineI+=2; - printf("rle=%d\n", expandRleC(lineI,aux,lineO,&lineSize,1000)); - printf("linesize=%d of %d. size=%d r=%d.\n",lineSize,verify,tempOutputSize,tempOutputSize-aux-2); + if (aux>tempOutputSize) { + printf(" error: aux=%d tempOutputSize=%d\n",aux,tempOutputSize); + return COMPRESS_RESULT_WARNING; + } + aux2= expandRleC(lineI,aux,lineO,&lineSize,1000); + if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-aux-2); lineO+=lineSize; - outputSize+=lineSize; + *outputSize+=lineSize; tempOutputSize-=aux; tempOutputSize-=2; lineI+=aux; } while (lineSize==verify && tempOutputSize>0); - + printf(" return: linesize=%d verify=%d tempOutputSize=%d\n", lineSize, verify, tempOutputSize); + if (remaining) { + const unsigned char* start=input+(inputSize-0)-remaining; + printf("Remaining tailing data: size=%d first=%02x %02x\n", remaining,start[0],start[1]); + tempOutputSize=0; + remaining=expandLzg(start,remaining,&tempOutput,&tempOutputSize); + + lineI=tempOutput; + + do { + aux=array2short(lineI); + lineI+=2; + if (aux>tempOutputSize) { + printf(" error: aux=%d tempOutputSize=%d\n",aux,tempOutputSize); + return COMPRESS_RESULT_WARNING; + } + aux2= expandRleC(lineI,aux,lineO,&lineSize,1000); + if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-aux-2); + lineO+=lineSize; + *outputSize+=lineSize; + tempOutputSize-=aux; + tempOutputSize-=2; + lineI+=aux; + } while (lineSize==verify && tempOutputSize>0); +/* + aux=array2short(lineI); + lineI+=2; + if (aux>tempOutputSize) printf(" error: aux=%d tempOutputSize=%d\n",aux,tempOutputSize); + aux2= expandRleC(lineI,tempOutputSize,lineO,&lineSize,1000); + if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-aux-2); +*/ + } -/* printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));*/ /* + printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify)); + printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os)); osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2]; @@ -246,7 +287,9 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign fclose(out); - printf("os=%d oscheck=%d\n",os,osCheck);*/ + printf("os=%d oscheck=%d\n",os,osCheck); +*/ + return COMPRESS_RESULT_SUCCESS; } diff --git a/PR/src/xml/resources.xml b/PR/src/xml/resources.xml index 2a67055..ec44892 100644 --- a/PR/src/xml/resources.xml +++ b/PR/src/xml/resources.xml @@ -807,7 +807,7 @@ resources.xml: Princed Resources : Resource tree </folder> - <folder index="pop1" name="binary" file="kid.dat" path="kid" palette="400" type="image"> + <folder index="pop1" name="binary" file="ikid.dat" path="kid" palette="400" type="image"> <item value="400" path="kid.pal" type="palette-pop1-4bits">Resource number 400</item> <folder path="running"> <item value="401" path="frame01.bmp">Image frame01 (401)</item>