author | ecalot
<ecalot> 2006-02-26 07:55:19 UTC |
committer | ecalot
<ecalot> 2006-02-26 07:55:19 UTC |
parent | a101227846077662f72124164ec531bdaaf57c08 |
PR/src/include/image.h | +2 | -1 |
PR/src/lib/actions/import.c | +6 | -3 |
PR/src/lib/formats/bmp.c | +1 | -1 |
PR/src/lib/object/image/image16.c | +54 | -46 |
PR/src/lib/object/image/image2.c | +54 | -46 |
PR/src/lib/object/image/image256.c | +54 | -46 |
PR/src/lib/object/image/image_common.c | +54 | -46 |
PR/src/lib/object/object.c | +1 | -1 |
diff --git a/PR/src/include/image.h b/PR/src/include/image.h index 2a57528..20745b6 100644 --- a/PR/src/include/image.h +++ b/PR/src/include/image.h @@ -63,11 +63,12 @@ typedef struct { /* Prototypes */ -int mCompressGraphic(unsigned char** a,tImage* i, int* size); /* make it private */ +/*int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes) */ void* objImageCreate(tBinary c, tObject palette, int *error); int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension); void* objImageRead(const char* file,tObject palette, int *result); +int objImageSet(void* o,tResource* res); #define getCarry(a) ((((a)>>4)&7)+1) #define getAlgor(a) a&0x4F diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index fade75e..b6c5b61 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -86,13 +86,15 @@ int import_full(const char* vFiledat, const char* vDirExt, tResourceList* r, int if (hasFlag(raw_flag)) newRes.type=0; /* compile from raw */ getFileName(vFileext,vDirExt,res,vFiledat,vDatFileName,optionflag,backupExtension,NULL); + /* TODO: if image read the palette */ /* the file is in the archive, so I'll add it to the main DAT body */ /* newRes.content=mLoadFileArray(vFileext);*/ /* if (newRes.content.size>0) {*/ /* TODO: let each format handle the files */ o=readObject(vFileext,&newRes,&result); -/* if (!fatal(ok)) */ - setObject(o,&result,&newRes); +/* if (!fatal(result)) */ + if (!result) + setObject(o,&result,&newRes); /* if (!fatal(ok)) { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); @@ -159,7 +161,8 @@ int import_partial(const char* vFiledat, const char* vDirExt, tResourceList* r, o=readObject(repairFolders(vFileext),&newRes,&result); /* if (!fatal(ok)) */ - setObject(o,&result,&newRes); + if (!ok) + setObject(o,&result,&newRes); /* the file is in the partial matching list, so I'll import */ /* newRes.content=mLoadFileArray(vFileext); diff --git a/PR/src/lib/formats/bmp.c b/PR/src/lib/formats/bmp.c index 7dcfee9..f6f388b 100644 --- a/PR/src/lib/formats/bmp.c +++ b/PR/src/lib/formats/bmp.c @@ -156,7 +156,7 @@ int readBmp(const char* file, unsigned char** data, int *ph, int *pw, int *pbit ok=ok&&freadlong(&aux ,bitmap); /* Important colours (junk) */ /* Verify */ - *plineWidth=width*(8/bits); /* Note: only works in bits=1,2,4,8 */ + *plineWidth=width*bits/8; /* Note: only works in bits=1,2,4,8 */ lineSerialization=(-*plineWidth)&3; /* offset=54+(colors<<2); lineSerialization=(-lineWidth)&3; diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index 351bb31..d0ec297 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -126,14 +126,14 @@ void cmp_transposeImage(tImage* image,int size) { image->pix=outputaux; } -void cmp_antiTransposeImage(tImage* image,int size) { - unsigned char* outputaux=getMemory(size); +void cmp_antiTransposeImage(tBinary* b, int widthInBytes, int height) { + unsigned char* outputaux=getMemory(b->size); int cursor; - for (cursor=0;cursor<size;cursor++) - outputaux[cursor]=image->pix[cmp_transpose(cursor,image->widthInBytes,image->height)]; - free(image->pix); - image->pix=outputaux; + for (cursor=0;cursor<b->size;cursor++) + outputaux[cursor]=b->data[cmp_transpose(cursor,widthInBytes,height)]; + free(b->data); + b->data=outputaux; } /***************************************************************\ @@ -225,7 +225,8 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) { +/* unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/ /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -235,7 +236,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { int max_alg=1; /* Initialize variables */ - imageSizeInBytes=image->widthInBytes*image->height; + imageSizeInBytes=input->size; /*=image->widthInBytes*image->height;*/ /* * Perform all compressions @@ -251,7 +252,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); compressedSize[COMPRESS_RAW]=imageSizeInBytes; - memcpy(compressed[COMPRESS_RAW],image->pix,imageSizeInBytes); + memcpy(compressed[COMPRESS_RAW],input->data,imageSizeInBytes); /* COMPRESS_RLE_LR * If all the uncompressed data has a big entropy, there @@ -263,7 +264,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { cLevel(2) { compressed[COMPRESS_RLE_LR]=getMemory((2*imageSizeInBytes+50)); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_LR],&(compressedSize[COMPRESS_RLE_LR]) ); max_alg++; @@ -284,7 +285,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_LR]=getMemory((2*imageSizeInBytes+1050)); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_LR],&(compressedSize[COMPRESS_LZG_LR]) ); max_alg++; @@ -298,13 +299,13 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { * using the image matrix transposed. */ cLevel(3) - cmp_antiTransposeImage(image,imageSizeInBytes); + cmp_antiTransposeImage(input,w,h); /* COMPRESS_RLE_UD */ cLevel(3) { compressed[COMPRESS_RLE_UD]=getMemory(2*imageSizeInBytes+50); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_UD],&(compressedSize[COMPRESS_RLE_UD]) ); max_alg++; @@ -318,7 +319,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_UD]=getMemory(2*imageSizeInBytes+1050); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_UD],&(compressedSize[COMPRESS_LZG_UD]) ); max_alg++; @@ -328,37 +329,23 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ /* Select the best compression (find minimum) */ - *dataSizeInBytes=compressedSize[COMPRESS_RAW]; + output->size=compressedSize[COMPRESS_RAW]; algorithm=COMPRESS_RAW; for (i=COMPRESS_RLE_LR;i<max_alg;i++) { - if ((*dataSizeInBytes)>compressedSize[i]) { - (*dataSizeInBytes)=compressedSize[i]; + if (output->size>compressedSize[i]) { + output->size=compressedSize[i]; algorithm=i; } } /* Copy the best algorithm in the compressed data */ - *data=getMemory(*dataSizeInBytes+6); - memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); - (*dataSizeInBytes)+=6; - - /* - * Write header - */ - - /* (16 bits)height (Intel short int format) */ - (*data)[0]=image->height; - (*data)[1]=image->height>>8; - /* (16 bits)width (Intel short int format) */ - (*data)[2]=image->width; - (*data)[3]=image->width>>8; - /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - (*data)[4]=0; - (*data)[5]=image->type|algorithm; + output->data=getMemory(output->size+ignoreFirstBytes); + memcpy(output->data+ignoreFirstBytes,compressed[algorithm],output->size); + output->size+=ignoreFirstBytes; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); - return 1; /* true */ + return algorithm; } int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { @@ -457,9 +444,8 @@ void* objImageRead(const char* file,tObject palette, int *result) { *result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes)); /* check if image was succesfully read loaded */ +printf("result=%d\n",*result); if (*result!=PR_RESULT_SUCCESS) { - free(image->pix); - free(colorArray); free(image); return NULL; } @@ -468,26 +454,48 @@ void* objImageRead(const char* file,tObject palette, int *result) { image->pal=palette; bits=paletteGetBits(image->pal); - if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */ + if (bits && bits!=image->bits) { /* bits=0 means all palettes allowed or ignore palette check */ *result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS; free(image->pix); free(colorArray); free(image); return NULL; } - + /* TODO: palette content checks */ - + free(colorArray); return (void*)image; } + /* TODO: generate image->type in objImageSet */ /*int mFormatImportBmp(tResource *res) { --> objImageSet */ - /*tImage img;*/ +int objImageSet(void* o,tResource* res) { + tImage* img=o; + tBinary decompressed,compressed; + int algorithm; + + decompressed.data=img->pix; + decompressed.size=img->widthInBytes*img->height; + + algorithm=mCompressGraphic(&decompressed,&compressed,6,img->widthInBytes,img->height); + + /* + * Write header + */ -/* if (!mReadBitMap(&img,)) return 0; * false * - free(res->content.data); - mCompressGraphic(&(res->content.data),&img,(int*)&(res->content.size)); + /* (16 bits)height (Intel short int format) */ + compressed.data[0]=img->height; /* TODO: use shorttoarray */ + compressed.data[1]=img->height>>8; + /* (16 bits)width (Intel short int format) */ + compressed.data[2]=img->width; + compressed.data[3]=img->width>>8; + /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ + compressed.data[4]=0; + compressed.data[5]=(img->bits==4?0xb0:0x00)|algorithm; + + res->content=compressed; mWriteFileInDatFile(res); - free(img.pix); -*/ + return PR_RESULT_SUCCESS; +} + diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index 351bb31..d0ec297 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -126,14 +126,14 @@ void cmp_transposeImage(tImage* image,int size) { image->pix=outputaux; } -void cmp_antiTransposeImage(tImage* image,int size) { - unsigned char* outputaux=getMemory(size); +void cmp_antiTransposeImage(tBinary* b, int widthInBytes, int height) { + unsigned char* outputaux=getMemory(b->size); int cursor; - for (cursor=0;cursor<size;cursor++) - outputaux[cursor]=image->pix[cmp_transpose(cursor,image->widthInBytes,image->height)]; - free(image->pix); - image->pix=outputaux; + for (cursor=0;cursor<b->size;cursor++) + outputaux[cursor]=b->data[cmp_transpose(cursor,widthInBytes,height)]; + free(b->data); + b->data=outputaux; } /***************************************************************\ @@ -225,7 +225,8 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) { +/* unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/ /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -235,7 +236,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { int max_alg=1; /* Initialize variables */ - imageSizeInBytes=image->widthInBytes*image->height; + imageSizeInBytes=input->size; /*=image->widthInBytes*image->height;*/ /* * Perform all compressions @@ -251,7 +252,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); compressedSize[COMPRESS_RAW]=imageSizeInBytes; - memcpy(compressed[COMPRESS_RAW],image->pix,imageSizeInBytes); + memcpy(compressed[COMPRESS_RAW],input->data,imageSizeInBytes); /* COMPRESS_RLE_LR * If all the uncompressed data has a big entropy, there @@ -263,7 +264,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { cLevel(2) { compressed[COMPRESS_RLE_LR]=getMemory((2*imageSizeInBytes+50)); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_LR],&(compressedSize[COMPRESS_RLE_LR]) ); max_alg++; @@ -284,7 +285,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_LR]=getMemory((2*imageSizeInBytes+1050)); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_LR],&(compressedSize[COMPRESS_LZG_LR]) ); max_alg++; @@ -298,13 +299,13 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { * using the image matrix transposed. */ cLevel(3) - cmp_antiTransposeImage(image,imageSizeInBytes); + cmp_antiTransposeImage(input,w,h); /* COMPRESS_RLE_UD */ cLevel(3) { compressed[COMPRESS_RLE_UD]=getMemory(2*imageSizeInBytes+50); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_UD],&(compressedSize[COMPRESS_RLE_UD]) ); max_alg++; @@ -318,7 +319,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_UD]=getMemory(2*imageSizeInBytes+1050); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_UD],&(compressedSize[COMPRESS_LZG_UD]) ); max_alg++; @@ -328,37 +329,23 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ /* Select the best compression (find minimum) */ - *dataSizeInBytes=compressedSize[COMPRESS_RAW]; + output->size=compressedSize[COMPRESS_RAW]; algorithm=COMPRESS_RAW; for (i=COMPRESS_RLE_LR;i<max_alg;i++) { - if ((*dataSizeInBytes)>compressedSize[i]) { - (*dataSizeInBytes)=compressedSize[i]; + if (output->size>compressedSize[i]) { + output->size=compressedSize[i]; algorithm=i; } } /* Copy the best algorithm in the compressed data */ - *data=getMemory(*dataSizeInBytes+6); - memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); - (*dataSizeInBytes)+=6; - - /* - * Write header - */ - - /* (16 bits)height (Intel short int format) */ - (*data)[0]=image->height; - (*data)[1]=image->height>>8; - /* (16 bits)width (Intel short int format) */ - (*data)[2]=image->width; - (*data)[3]=image->width>>8; - /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - (*data)[4]=0; - (*data)[5]=image->type|algorithm; + output->data=getMemory(output->size+ignoreFirstBytes); + memcpy(output->data+ignoreFirstBytes,compressed[algorithm],output->size); + output->size+=ignoreFirstBytes; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); - return 1; /* true */ + return algorithm; } int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { @@ -457,9 +444,8 @@ void* objImageRead(const char* file,tObject palette, int *result) { *result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes)); /* check if image was succesfully read loaded */ +printf("result=%d\n",*result); if (*result!=PR_RESULT_SUCCESS) { - free(image->pix); - free(colorArray); free(image); return NULL; } @@ -468,26 +454,48 @@ void* objImageRead(const char* file,tObject palette, int *result) { image->pal=palette; bits=paletteGetBits(image->pal); - if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */ + if (bits && bits!=image->bits) { /* bits=0 means all palettes allowed or ignore palette check */ *result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS; free(image->pix); free(colorArray); free(image); return NULL; } - + /* TODO: palette content checks */ - + free(colorArray); return (void*)image; } + /* TODO: generate image->type in objImageSet */ /*int mFormatImportBmp(tResource *res) { --> objImageSet */ - /*tImage img;*/ +int objImageSet(void* o,tResource* res) { + tImage* img=o; + tBinary decompressed,compressed; + int algorithm; + + decompressed.data=img->pix; + decompressed.size=img->widthInBytes*img->height; + + algorithm=mCompressGraphic(&decompressed,&compressed,6,img->widthInBytes,img->height); + + /* + * Write header + */ -/* if (!mReadBitMap(&img,)) return 0; * false * - free(res->content.data); - mCompressGraphic(&(res->content.data),&img,(int*)&(res->content.size)); + /* (16 bits)height (Intel short int format) */ + compressed.data[0]=img->height; /* TODO: use shorttoarray */ + compressed.data[1]=img->height>>8; + /* (16 bits)width (Intel short int format) */ + compressed.data[2]=img->width; + compressed.data[3]=img->width>>8; + /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ + compressed.data[4]=0; + compressed.data[5]=(img->bits==4?0xb0:0x00)|algorithm; + + res->content=compressed; mWriteFileInDatFile(res); - free(img.pix); -*/ + return PR_RESULT_SUCCESS; +} + diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 351bb31..d0ec297 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -126,14 +126,14 @@ void cmp_transposeImage(tImage* image,int size) { image->pix=outputaux; } -void cmp_antiTransposeImage(tImage* image,int size) { - unsigned char* outputaux=getMemory(size); +void cmp_antiTransposeImage(tBinary* b, int widthInBytes, int height) { + unsigned char* outputaux=getMemory(b->size); int cursor; - for (cursor=0;cursor<size;cursor++) - outputaux[cursor]=image->pix[cmp_transpose(cursor,image->widthInBytes,image->height)]; - free(image->pix); - image->pix=outputaux; + for (cursor=0;cursor<b->size;cursor++) + outputaux[cursor]=b->data[cmp_transpose(cursor,widthInBytes,height)]; + free(b->data); + b->data=outputaux; } /***************************************************************\ @@ -225,7 +225,8 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) { +/* unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/ /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -235,7 +236,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { int max_alg=1; /* Initialize variables */ - imageSizeInBytes=image->widthInBytes*image->height; + imageSizeInBytes=input->size; /*=image->widthInBytes*image->height;*/ /* * Perform all compressions @@ -251,7 +252,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); compressedSize[COMPRESS_RAW]=imageSizeInBytes; - memcpy(compressed[COMPRESS_RAW],image->pix,imageSizeInBytes); + memcpy(compressed[COMPRESS_RAW],input->data,imageSizeInBytes); /* COMPRESS_RLE_LR * If all the uncompressed data has a big entropy, there @@ -263,7 +264,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { cLevel(2) { compressed[COMPRESS_RLE_LR]=getMemory((2*imageSizeInBytes+50)); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_LR],&(compressedSize[COMPRESS_RLE_LR]) ); max_alg++; @@ -284,7 +285,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_LR]=getMemory((2*imageSizeInBytes+1050)); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_LR],&(compressedSize[COMPRESS_LZG_LR]) ); max_alg++; @@ -298,13 +299,13 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { * using the image matrix transposed. */ cLevel(3) - cmp_antiTransposeImage(image,imageSizeInBytes); + cmp_antiTransposeImage(input,w,h); /* COMPRESS_RLE_UD */ cLevel(3) { compressed[COMPRESS_RLE_UD]=getMemory(2*imageSizeInBytes+50); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_UD],&(compressedSize[COMPRESS_RLE_UD]) ); max_alg++; @@ -318,7 +319,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_UD]=getMemory(2*imageSizeInBytes+1050); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_UD],&(compressedSize[COMPRESS_LZG_UD]) ); max_alg++; @@ -328,37 +329,23 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ /* Select the best compression (find minimum) */ - *dataSizeInBytes=compressedSize[COMPRESS_RAW]; + output->size=compressedSize[COMPRESS_RAW]; algorithm=COMPRESS_RAW; for (i=COMPRESS_RLE_LR;i<max_alg;i++) { - if ((*dataSizeInBytes)>compressedSize[i]) { - (*dataSizeInBytes)=compressedSize[i]; + if (output->size>compressedSize[i]) { + output->size=compressedSize[i]; algorithm=i; } } /* Copy the best algorithm in the compressed data */ - *data=getMemory(*dataSizeInBytes+6); - memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); - (*dataSizeInBytes)+=6; - - /* - * Write header - */ - - /* (16 bits)height (Intel short int format) */ - (*data)[0]=image->height; - (*data)[1]=image->height>>8; - /* (16 bits)width (Intel short int format) */ - (*data)[2]=image->width; - (*data)[3]=image->width>>8; - /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - (*data)[4]=0; - (*data)[5]=image->type|algorithm; + output->data=getMemory(output->size+ignoreFirstBytes); + memcpy(output->data+ignoreFirstBytes,compressed[algorithm],output->size); + output->size+=ignoreFirstBytes; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); - return 1; /* true */ + return algorithm; } int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { @@ -457,9 +444,8 @@ void* objImageRead(const char* file,tObject palette, int *result) { *result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes)); /* check if image was succesfully read loaded */ +printf("result=%d\n",*result); if (*result!=PR_RESULT_SUCCESS) { - free(image->pix); - free(colorArray); free(image); return NULL; } @@ -468,26 +454,48 @@ void* objImageRead(const char* file,tObject palette, int *result) { image->pal=palette; bits=paletteGetBits(image->pal); - if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */ + if (bits && bits!=image->bits) { /* bits=0 means all palettes allowed or ignore palette check */ *result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS; free(image->pix); free(colorArray); free(image); return NULL; } - + /* TODO: palette content checks */ - + free(colorArray); return (void*)image; } + /* TODO: generate image->type in objImageSet */ /*int mFormatImportBmp(tResource *res) { --> objImageSet */ - /*tImage img;*/ +int objImageSet(void* o,tResource* res) { + tImage* img=o; + tBinary decompressed,compressed; + int algorithm; + + decompressed.data=img->pix; + decompressed.size=img->widthInBytes*img->height; + + algorithm=mCompressGraphic(&decompressed,&compressed,6,img->widthInBytes,img->height); + + /* + * Write header + */ -/* if (!mReadBitMap(&img,)) return 0; * false * - free(res->content.data); - mCompressGraphic(&(res->content.data),&img,(int*)&(res->content.size)); + /* (16 bits)height (Intel short int format) */ + compressed.data[0]=img->height; /* TODO: use shorttoarray */ + compressed.data[1]=img->height>>8; + /* (16 bits)width (Intel short int format) */ + compressed.data[2]=img->width; + compressed.data[3]=img->width>>8; + /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ + compressed.data[4]=0; + compressed.data[5]=(img->bits==4?0xb0:0x00)|algorithm; + + res->content=compressed; mWriteFileInDatFile(res); - free(img.pix); -*/ + return PR_RESULT_SUCCESS; +} + diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index 351bb31..d0ec297 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -126,14 +126,14 @@ void cmp_transposeImage(tImage* image,int size) { image->pix=outputaux; } -void cmp_antiTransposeImage(tImage* image,int size) { - unsigned char* outputaux=getMemory(size); +void cmp_antiTransposeImage(tBinary* b, int widthInBytes, int height) { + unsigned char* outputaux=getMemory(b->size); int cursor; - for (cursor=0;cursor<size;cursor++) - outputaux[cursor]=image->pix[cmp_transpose(cursor,image->widthInBytes,image->height)]; - free(image->pix); - image->pix=outputaux; + for (cursor=0;cursor<b->size;cursor++) + outputaux[cursor]=b->data[cmp_transpose(cursor,widthInBytes,height)]; + free(b->data); + b->data=outputaux; } /***************************************************************\ @@ -225,7 +225,8 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) { +/* unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/ /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -235,7 +236,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { int max_alg=1; /* Initialize variables */ - imageSizeInBytes=image->widthInBytes*image->height; + imageSizeInBytes=input->size; /*=image->widthInBytes*image->height;*/ /* * Perform all compressions @@ -251,7 +252,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); compressedSize[COMPRESS_RAW]=imageSizeInBytes; - memcpy(compressed[COMPRESS_RAW],image->pix,imageSizeInBytes); + memcpy(compressed[COMPRESS_RAW],input->data,imageSizeInBytes); /* COMPRESS_RLE_LR * If all the uncompressed data has a big entropy, there @@ -263,7 +264,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { cLevel(2) { compressed[COMPRESS_RLE_LR]=getMemory((2*imageSizeInBytes+50)); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_LR],&(compressedSize[COMPRESS_RLE_LR]) ); max_alg++; @@ -284,7 +285,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_LR]=getMemory((2*imageSizeInBytes+1050)); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_LR],&(compressedSize[COMPRESS_LZG_LR]) ); max_alg++; @@ -298,13 +299,13 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { * using the image matrix transposed. */ cLevel(3) - cmp_antiTransposeImage(image,imageSizeInBytes); + cmp_antiTransposeImage(input,w,h); /* COMPRESS_RLE_UD */ cLevel(3) { compressed[COMPRESS_RLE_UD]=getMemory(2*imageSizeInBytes+50); compressRle( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_RLE_UD],&(compressedSize[COMPRESS_RLE_UD]) ); max_alg++; @@ -318,7 +319,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { unsetHigh; compressed[COMPRESS_LZG_UD]=getMemory(2*imageSizeInBytes+1050); compressLzg( - image->pix,imageSizeInBytes, + input->data,imageSizeInBytes, compressed[COMPRESS_LZG_UD],&(compressedSize[COMPRESS_LZG_UD]) ); max_alg++; @@ -328,37 +329,23 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { */ /* Select the best compression (find minimum) */ - *dataSizeInBytes=compressedSize[COMPRESS_RAW]; + output->size=compressedSize[COMPRESS_RAW]; algorithm=COMPRESS_RAW; for (i=COMPRESS_RLE_LR;i<max_alg;i++) { - if ((*dataSizeInBytes)>compressedSize[i]) { - (*dataSizeInBytes)=compressedSize[i]; + if (output->size>compressedSize[i]) { + output->size=compressedSize[i]; algorithm=i; } } /* Copy the best algorithm in the compressed data */ - *data=getMemory(*dataSizeInBytes+6); - memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); - (*dataSizeInBytes)+=6; - - /* - * Write header - */ - - /* (16 bits)height (Intel short int format) */ - (*data)[0]=image->height; - (*data)[1]=image->height>>8; - /* (16 bits)width (Intel short int format) */ - (*data)[2]=image->width; - (*data)[3]=image->width>>8; - /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - (*data)[4]=0; - (*data)[5]=image->type|algorithm; + output->data=getMemory(output->size+ignoreFirstBytes); + memcpy(output->data+ignoreFirstBytes,compressed[algorithm],output->size); + output->size+=ignoreFirstBytes; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); - return 1; /* true */ + return algorithm; } int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { @@ -457,9 +444,8 @@ void* objImageRead(const char* file,tObject palette, int *result) { *result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes)); /* check if image was succesfully read loaded */ +printf("result=%d\n",*result); if (*result!=PR_RESULT_SUCCESS) { - free(image->pix); - free(colorArray); free(image); return NULL; } @@ -468,26 +454,48 @@ void* objImageRead(const char* file,tObject palette, int *result) { image->pal=palette; bits=paletteGetBits(image->pal); - if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */ + if (bits && bits!=image->bits) { /* bits=0 means all palettes allowed or ignore palette check */ *result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS; free(image->pix); free(colorArray); free(image); return NULL; } - + /* TODO: palette content checks */ - + free(colorArray); return (void*)image; } + /* TODO: generate image->type in objImageSet */ /*int mFormatImportBmp(tResource *res) { --> objImageSet */ - /*tImage img;*/ +int objImageSet(void* o,tResource* res) { + tImage* img=o; + tBinary decompressed,compressed; + int algorithm; + + decompressed.data=img->pix; + decompressed.size=img->widthInBytes*img->height; + + algorithm=mCompressGraphic(&decompressed,&compressed,6,img->widthInBytes,img->height); + + /* + * Write header + */ -/* if (!mReadBitMap(&img,)) return 0; * false * - free(res->content.data); - mCompressGraphic(&(res->content.data),&img,(int*)&(res->content.size)); + /* (16 bits)height (Intel short int format) */ + compressed.data[0]=img->height; /* TODO: use shorttoarray */ + compressed.data[1]=img->height>>8; + /* (16 bits)width (Intel short int format) */ + compressed.data[2]=img->width; + compressed.data[3]=img->width>>8; + /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ + compressed.data[4]=0; + compressed.data[5]=(img->bits==4?0xb0:0x00)|algorithm; + + res->content=compressed; mWriteFileInDatFile(res); - free(img.pix); -*/ + return PR_RESULT_SUCCESS; +} + diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c index c3edb8b..fe41d9f 100644 --- a/PR/src/lib/object/object.c +++ b/PR/src/lib/object/object.c @@ -137,7 +137,7 @@ void setObject(tObject o,int *result,tResource* res) { /*o.obj=objLevelRead(file,res.content,result);*/ break; case eResTypeImage: - /*o.obj=objImageRead(file,res.content,res.palette,result);*/ + *result=objImageSet(o.obj,res); break; case eResTypeWave: *result=objWaveSet(o.obj,res);