]> git.llucax.com Git - z.facultad/75.06/jacu.git/commitdiff
Ahora si, me habia olvidado de hacer el Decoder de Jacu chunkeable y sin archivo...
authorAlan Kennedy <kennedya@3dgames.com.ar>
Thu, 24 Jun 2004 06:49:45 +0000 (06:49 +0000)
committerAlan Kennedy <kennedya@3dgames.com.ar>
Thu, 24 Jun 2004 06:49:45 +0000 (06:49 +0000)
src/jacu.c

index f0c3444d55525813611fc874529a6b2eb607a932..5add536bdca619bef27d773bc85a548264341a05 100644 (file)
@@ -199,23 +199,22 @@ int main(int argc, char* argv[])
                Uint32 block_size, k;
                char *block, *mtf, *orig;
                char *z;
-               int z_len;
+               int z_len,moredata = 0,decoded = 0;
 
-               if ((shuff = shuff_init_decoder(argv[optind],"tmp.comp")) == NULL) return 1;
-               shuff_decode_file(shuff);
-               shuff_deinit_decoder(shuff);
-               free(shuff);
-               
-               fp_in = fopen("tmp.comp", "rb");
+               /* Inicializo el descompresor */
+               if ((shuff = shuff_init_decoder(argv[optind],NULL)) == NULL) return 1;
+                               
+               /* Abrimos el archivo de salida */
                fp_out = fopen(argv[optind+1], "wb");
 
-               while (!feof(fp_in)) {
-                       block_size = 0;
-                       fread(&block_size, sizeof(Uint32), 1, fp_in);
+               /* Descomprimimos de a chunks segun convenga */
+               do {
+                       block_size = 0;                                         
+                       moredata = shuff_decode_chunk(shuff,(char*)&block_size,sizeof(Uint32),&decoded);
                        if (block_size > 0) {
-                               fread(&z_len, sizeof(int), 1, fp_in);
+                               moredata = shuff_decode_chunk(shuff,(char*)&z_len,sizeof(int),&decoded);                                
                                z = malloc(sizeof(char)*z_len);
-                               fread(z, z_len, sizeof(char), fp_in);
+                               moredata = shuff_decode_chunk(shuff,z,z_len,&decoded);                          
 
                                /*printf("MTF Z (len=%d) = [", z_len);
                                {
@@ -228,7 +227,7 @@ int main(int argc, char* argv[])
                                
                                block = malloc(block_size*sizeof(char)+sizeof(Uint32));
                                orig = malloc(block_size*sizeof(char));
-                               fread(block, block_size+sizeof(Uint32), sizeof(char), fp_in);
+                               moredata = shuff_decode_chunk(shuff,block,block_size+sizeof(Uint32),&decoded);                          
 
                                /*printf("Antes MTF_inv = [");
                                {
@@ -260,9 +259,14 @@ int main(int argc, char* argv[])
                                free(mtf);
                                free(z);
                        }
-               }
-               fclose(fp_in);
+               } while (moredata);             
+               
+               /* Close up files */
                fclose(fp_out);
+               
+               /* Shutdown Huffman */
+               shuff_deinit_decoder(shuff);
+               free(shuff);
        }
 
        return 0;