X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/cb53166758c12a09e9911769ce89c94cee4cc0f0..2ee6f95a8db79ede018e0f15124dd486451c4170:/src/jacu.c diff --git a/src/jacu.c b/src/jacu.c index ab4c79d..599d636 100644 --- a/src/jacu.c +++ b/src/jacu.c @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) } if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) || (mflag & sflag)) { - fprintf(stderr, "Usage: %s [-cdzs][-q blksize][-t volsize][-m modeldumpfile] source target\n", argv[0]); + fprintf(stderr, "Usage: %s [-cdzs][-q compressionquality][-t volsize][-m modeldumpfile] source target\n", argv[0]); return (3); } if ((tflag) && (volumesize <= 0l)) { @@ -120,6 +120,10 @@ int main(int argc, char* argv[]) /* Guardamos el pagesize como header (huffencoded) */ shuff_scanfreq_chunk(shuff,(char*)&pagesize,sizeof(size_t)); + /* Guardamos cabecera para indicar si usamos ZG (huffencoded) */ + if (zflag) shuff_scanfreq_chunk(shuff, "\001", 1); + else shuff_scanfreq_chunk(shuff, "\000", 1); + total = 0; while (!feof(fp)) { i = 0; @@ -136,23 +140,25 @@ int main(int argc, char* argv[]) /* Le aplico el MTF a salida */ mtf = jacu_mtf(salida, i+sizeof(Uint32), &z, &z_len); + + /* Guardo el z_len y el Z */ + shuff_scanfreq_chunk(shuff,(char*)&z_len,sizeof(int)); + shuff_scanfreq_chunk(shuff,z,z_len); /* Si me lo piden, aplico ZG. */ if (zflag) { size_t len; char buff[2]; + Uint32 total_size = i + sizeof(Uint32); ZG zg; zg_init(&zg); - /* TODO HACER LO MISMO QUE EN EL ELSE XXX */ - for (j = 0; j < i; ++j) - if ((len = zg_group(&zg, buff, mtf[j]))) shuff_scanfreq_chunk(shuff,buff,len); - } else { - /* Comprimo el Z len y el Z */ - shuff_scanfreq_chunk(shuff,(char*)&z_len,sizeof(int)); - shuff_scanfreq_chunk(shuff,z,z_len); - + /* Guardo la salida del MTF con ceros agrupados (ZG) */ + for (j = 0; j < total_size; ++j) + if ((len = zg_group(&zg, buff, mtf[j]))) + shuff_scanfreq_chunk(shuff, buff, len); + } else { /* Comprimo la salida del MTF */ - shuff_scanfreq_chunk(shuff,mtf,i+sizeof(Uint32)); + shuff_scanfreq_chunk(shuff,mtf,i+sizeof(Uint32)); } free(mtf); free(z); @@ -182,6 +188,7 @@ int main(int argc, char* argv[]) unsigned char *block, *mtf, *orig; unsigned char *z; int z_len,moredata = 0,decoded = 0; + char use_zg; /* Inicializo el descompresor */ if ((shuff = shuff_init_decoder(argv[optind],NULL)) == NULL) return 1; @@ -191,6 +198,11 @@ int main(int argc, char* argv[]) /* Descomprimo primero que nada el pagesize utilizado para comprimir */ if (!(moredata = shuff_decode_chunk(shuff,(char*)&block_size,sizeof(Uint32),&decoded))) return 1; + + /* Descomprimo byte que indica si se usa ZG */ + if (!(moredata = shuff_decode_chunk(shuff, &use_zg, 1, &decoded))) return 1; + + /* Creo buffers */ block = malloc(block_size*sizeof(unsigned char)+sizeof(Uint32)); orig = malloc(block_size*sizeof(unsigned char));