예제 #1
0
/* This function takes in the file, reads the header, utilizes
 * functions in compute40 module to perform the decompress, completes the
 * decompressed ppm, and calls ppmwrite() to write the image to the 
 * stdout */
void decompress40(FILE *input)
{
        unsigned height, width;
        int read = fscanf(input, "COMP40 Compressed image format 2\n%u %u", 
                          &width, &height);
        assert(read == 2);
        int c = getc(input);
        assert(c == '\n');

        A2Methods_T methods = uarray2_methods_blocked;
        A2 array = methods->new_with_blocksize(width / 2, height / 2, 
                                               sizeof(uint64_t), 1);
        assert(array);
        A2 result = methods->new_with_blocksize(width, height,
                                                sizeof(struct Pnm_rgb), 2);
        assert(result);
        
        methods->map_block_major(array, read_compressed, input);
 
        methods->map_block_major(array, decompress, result);

        assert(result);

        struct Pnm_ppm pixmap = { .width = width, .height = height,
                                  .denominator = DENOMINATOR, .pixels = result,
                                  .methods = uarray2_methods_blocked}; 

        Pnm_ppmwrite(stdout, &pixmap);

        methods->free(&result);
        methods->free(&array);
}
예제 #2
0
/* This function takes in the file and utilizes functions in compute40
 * module to perform the compression and outputing, and frees the memory
 */
void compress40(FILE *input)
{
        A2Methods_T methods = uarray2_methods_blocked;
        Pnm_ppm image = Pnm_ppmread(input, methods);

        assert(image);
        assert(image->width > 1 && image->height > 1);
        
        image->pixels = image_trimmer(image);
 

        A2 result = methods->new_with_blocksize(image->width / BLOCKSIZE,
                                                image->height / BLOCKSIZE, 
                                                sizeof(uint64_t), 1);
 
        methods->map_block_major(result, compress, image);
        
        assert(result);
        print_result(result, methods);

        methods->free(&result);
        FREE(result);
        Pnm_ppmfree(&image);
        
}