author | ecalot
<ecalot> 2006-08-04 06:23:14 UTC |
committer | ecalot
<ecalot> 2006-08-04 06:23:14 UTC |
parent | dcfa21e61eb7480938db47f9575f88bd9e0def04 |
PR/src/lib/actions/export.c | +12 | -1 |
PR/src/lib/layers/pallist.c | +16 | -2 |
PR/src/lib/object/image/image256.c | +48 | -16 |
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index 286c56c..6910df6 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -63,7 +63,9 @@ extern FILE* outputStream; Extracts a DAT file For parameter documentation, see pr.c */ +#ifdef DEBUG_TEST_PALLST void showobj(tObject o); /* TODO: only for debug purposes, delete this line */ +#endif int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension,const char* format) { char file[MAX_FILENAME_SIZE]; @@ -113,7 +115,9 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti case eResTypePalettePop2_NColors: case eResTypePalettePop1_16: { /* save and remember palette file */ o=objectCreate(&res,&ok); +#ifdef DEBUG_TEST_PALLST printf("new palette object: o=%p type=%d\n",o.obj,o.type); +#endif if (!ok) { /* if SUCCESS remember the palette, otherwise keep using the default one */ pl_add(&palettes,o,res.id,lowPriority); } @@ -131,19 +135,25 @@ printf("new palette object: o=%p type=%d\n",o.obj,o.type); resourceListAddInfo(r,&otherPalette); /* this is nessesary to get the palette type */ if (!otherPalette.type) otherPalette.type=verifyHeader(otherPalette.content); /* in case of error, an autodetection will be performed */ o=objectCreate(&otherPalette,&ok); +#ifdef DEBUG_TEST_PALLST printf("adding "); showobj(o); +#endif pl_add(&palettes,o,res.paletteId,highPriority); } else { /*, that's bad, I'll have to use the previous palette, even if it is the default */ printf("Warning: the selected palette doesn't exist in the file, the extracted image could result in a wrong palette\n"); } } o=objectCreate(&res,&ok); +#ifdef DEBUG_TEST_PALLST printf("getting the palette for the %d colours object ",objectGetColorCount(o)); showobj(o); +#endif pal=pl_get(&palettes,&priorityRight,objectGetColorCount(o)); +#ifdef DEBUG_TEST_PALLST printf("palette "); showobj(pal); +#endif applyPalette(o,pal); if (!priorityRight) { printf("Warning: the selected palette can't be applied to the image\n"); @@ -156,7 +166,8 @@ showobj(pal); } /* TODO: warning counting here */ /* if (!fatal(ok)) */ - if (ok==PR_RESULT_SUCCESS) +if (ok < -70) printf("debug error: code=%d\n",ok); + if (ok==PR_RESULT_SUCCESS || ok < -70 /* debug codes are below 70*/) ok=objectWrite(o,file,optionflag,backupExtension); else /* printf("not ok. result=%d for %s\n",ok,file);*/ diff --git a/PR/src/lib/layers/pallist.c b/PR/src/lib/layers/pallist.c index 70d8282..0ca12c7 100644 --- a/PR/src/lib/layers/pallist.c +++ b/PR/src/lib/layers/pallist.c @@ -39,7 +39,7 @@ pallist.c: Princed Resources : Palette list layer implementation #include <stdlib.h> #include "object.h" -#ifndef DEBUG_TEST_PALLST +#ifdef DEBUG_TEST_PALLST void showobj(tObject o) { printf("object type=%d colors=%d\n",o.type,objectGetColorCount(o)); } @@ -66,8 +66,10 @@ int pl_tryAdd(tPL* pl, tResourceId resid, tPriority p) { void pl_add(tPL* pl, tObject o, tResourceId resid, tPriority p) { if (p==highPriority) { +#ifdef DEBUG_TEST_PALLST printf("adding with high priority:\n"); showobj(o); +#endif /* high priority insertion */ if (pl->priority_field.enabled) { /* if there was another object proprized, move it to the list */ tObject obj_old_priority=pl->priority_field.object; @@ -84,20 +86,26 @@ showobj(o); /* low priority insertion */ tPL_Node* insertNode=malloc(sizeof(tPL_Node)); int colors=objectGetColorCount(o); +#ifdef DEBUG_TEST_PALLST printf("adding with low priority:\n"); showobj(o); +#endif while (pl->list_first && colors>=objectGetColorCount(pl->list_first->object)) { +#ifdef DEBUG_TEST_PALLST printf("deleting: "); showobj(pl->list_first->object); +#endif pl->list_first=pl->list_first->next; /* Delete */ } insertNode->next=pl->list_first; insertNode->object=o; insertNode->resid=resid; pl->list_first=insertNode; +#ifdef DEBUG_TEST_PALLST printf("inserting "); showobj(pl->list_first->object); +#endif } return; } @@ -105,12 +113,16 @@ showobj(pl->list_first->object); tObject pl_get(tPL* pl, int* priorityRight, int colors) { tPL_Node* node; int junk; +#ifdef DEBUG_TEST_PALLST printf("getting PL\n"); +#endif *priorityRight=1; if (pl->priority_field.enabled) { if (colors<=objectGetColorCount(pl->priority_field.object)) { +#ifdef DEBUG_TEST_PALLST showobj(pl->priority_field.object); +#endif return pl->priority_field.object; } else { *priorityRight=0; @@ -118,11 +130,13 @@ showobj(pl->priority_field.object); } node=pl->list_first; +#ifdef DEBUG_TEST_PALLST printf("first=%p with ",(void*)pl->list_first); showobj(pl->list_first->object); +#endif while (node && colors>objectGetColorCount(node->object)) - { node=node->next; printf("next %p\n",(void*)node); } + { node=node->next;/* printf("next %p\n",(void*)node);*/ } return node?node->object:objectCreate(NULL,&junk); } diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index f52d0bb..195ce6c 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -150,10 +150,11 @@ int pop2decompress(tBinary input, int verify, unsigned char** output,int* output int aux,aux2,remaining; int tempOutputSize; int osCheck; + int scase=1; *output=malloc(*outputSize); lineO=*output; - for (aux=0;aux<*outputSize;aux++) (*output)[aux]=0; /* initialise the array (TODO: only for debug, in fixed images it won't be necessary) */ + for (aux=0;aux<*outputSize;aux++) (*output)[aux]=99; /* initialise the array (TODO: only for debug, in fixed images it won't be necessary) */ *outputSize=0; osCheck=array2short(input.data)-6; @@ -163,40 +164,69 @@ int pop2decompress(tBinary input, int verify, unsigned char** output,int* output tempOutputSize=osCheck+6; remaining=expandLzg(input,&tempOutput,&tempOutputSize); - /*printf("Call:\n return=%d function input.data size=%d\n internal output size=%d result output size=%d\n", - remaining,input.size,osCheck,tempOutputSize);*/ - /*if ((osCheck+6)!=tempOutputSize) - printf(" Special case: more is coming\n");*/ + printf("Call:\n return=%d function input.data size=%d\n internal output size=%d result output size=%d\n", + remaining,input.size,osCheck,tempOutputSize); + if ((osCheck+6)!=tempOutputSize) + printf(" Special case: more is coming\n"); /* Second layer expand each rle line */ lineI.data=tempOutput; - /*printf("RLE loop layer:\n");*/ + printf("RLE loop layer:\n"); do { lineI.size=array2short(lineI.data); lineI.data+=2; if (lineI.size>tempOutputSize) { - /*printf(" error: lineI.size=%d tempOutputSize=%d\n",lineI.size,tempOutputSize);*/ - return PR_RESULT_W_COMPRESS_RESULT_WARNING; - } + printf(" fatal error: lineI.size=%d tempOutputSize=%d\n",lineI.size,tempOutputSize); + /*return -81; *PR_RESULT_W_COMPRESS_RESULT_WARNING;*/ + /*lineSize=-1;*/ +/* lineI.data+=2; + expandRleV(lineI,lineO,&lineSize); + lineO+=lineSize; + *outputSize+=lineSize;*/ + /* memcpy(lineO,lineI.data,tempOutputSize); + *outputSize+=tempOutputSize;*/ + scase=0; + } else { aux2=expandRleV(lineI,lineO,&lineSize); - /*if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-lineI.size-2);*/ + if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-lineI.size-2); lineO+=lineSize; *outputSize+=lineSize; tempOutputSize-=lineI.size; tempOutputSize-=2; lineI.data+=lineI.size; - } while (lineSize==verify && tempOutputSize>0); + } + } while (scase && lineSize==verify && tempOutputSize>0); /*printf(" return: linesize=%d verify=%d tempOutputSize=%d\n", lineSize, verify, tempOutputSize);*/ if (remaining) { - /*const unsigned char* start=input.data+(input.size+2)-remaining;*/ + const unsigned char* start=input.data+(input.size+2)-remaining; tBinary tail; tail.data=input.data+(input.size+2-remaining); tail.size=remaining; - /*printf("Remaining tailing data: size=%d first=%02x %02x\n", remaining,start[0],start[1]);*/ + printf("Remaining tailing data: size=%d first=%02x %02x\n", remaining,start[0],start[1]); + if (scase) { tempOutputSize=0; - expandLzg(tail,&tempOutput,&tempOutputSize); /* TODO: check error output */ + printf("lzg=%d\n",expandLzg(tail,&tempOutput,&tempOutputSize)); /* TODO: check error output */ + } else { + /* this is the fatal error, I'll try not to compress */ + /*tail=binaryCrop(tail,-2,0); + printf("lzgi=%d\n",expandLzg(tail,&tempOutput,&tempOutputSize)); * TODO: check error output */ + /* case 1: memcpy*/ + tail.data=lineI.data; + tail.size=remaining+tempOutputSize; + printf("tail.size=%d remaining=%d tempOutputSize=%d\n",tail.size,remaining,tempOutputSize); + /*memcpy(lineO,tail.data,tail.size); + *outputSize+=tail.size;*/ + + /* case 2: lzg */ + /*tail=binaryCrop(tail,6,0); + printf("lzgi=%d\n",expandLzg(tail,&tempOutput,&tempOutputSize)); + memcpy(lineO,tempOutput,tempOutputSize); + *outputSize+=tempOutputSize;*/ + + return -81; + } lineI.data=tempOutput; @@ -204,8 +234,10 @@ int pop2decompress(tBinary input, int verify, unsigned char** output,int* output lineI.size=array2short(lineI.data); lineI.data+=2; if (lineI.size>tempOutputSize) { - /*printf(" error: lineI.size=%d tempOutputSize=%d\n",lineI.size,tempOutputSize);*/ - return PR_RESULT_W_COMPRESS_RESULT_WARNING; + printf(" particular error: lineI.size=%d tempOutputSize=%d\n",lineI.size,tempOutputSize); +printf("worked in particular case: %d\n",lineI.size-tempOutputSize); +/* TODO: learn what is lineI.size */ + return PR_RESULT_SUCCESS; /*-80; *PR_RESULT_W_COMPRESS_RESULT_WARNING;*/ } aux2=expandRleV(lineI,lineO,&lineSize); /*if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-lineI.size-2);*/