예제 #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
파일: a2test.c 프로젝트: limz10/locality
static void double_row_major_plus()
{
        /* store increasing integers in row-major order */
        A2 array = methods->new_with_blocksize(W, H, sizeof(int), BS);
        int counter = 1;
        for (int j = 0; j < H; j++) { 
                for (int i = 0; i < W; i++) { /* col index varies faster */
                        int *p = methods->at(array, i, j);
                        *p = counter++;
                }
        }
        counter = 1;
        for (int j = 0; j < H; j++) {
                for (int i = 0; i < W; i++) {
                        int *p = methods->at(array, i, j);
                        assert(*p == counter);
                        counter++;
                }
        }
        if (methods->map_row_major) {
                counter = 1;
                methods->map_row_major(array, check_and_increment, &counter);
        }
        if (methods->small_map_row_major) {
                counter = 1;
                methods->small_map_row_major(array,
                                             small_check_and_increment,
                                             &counter);
        }
        methods->free(&array);
}
예제 #3
0
static void test_methods(A2Methods_T methods_under_test) {
  methods = methods_under_test;
  assert(methods);
  assert(has_minimum_methods(methods));
  assert(has_small_plain_methods(methods) || has_small_blocked_methods(methods));
  assert(!(has_small_plain_methods(methods) && has_small_blocked_methods(methods)));
  assert(!(has_plain_methods(methods) && has_blocked_methods(methods)));
  if (!(has_plain_methods(methods) || has_blocked_methods(methods)))
    fprintf(stderr, "Some full mapping methods are missing\n");

  A2 array = methods->new_with_blocksize(W, H, sizeof(unsigned), BS);
  copy_unsigned(methods, array,  2,  1, 99);
  copy_unsigned(methods, array,  3,  3, 88);
  copy_unsigned(methods, array, 10, 10, 77);
  check(array,  2,  1, 99);
  check(array,  3,  3, 88);
  check(array, 10, 10, 77);
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      unsigned n = 1000 * i + j; 
      copy_unsigned(methods, array, i, j, n);
      unsigned *p = methods->at(array, i, j);
      assert(*p == n);
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      unsigned n = 1000 * i + j;
      unsigned *p = methods->at(array, i, j);
      assert(*p == n);
    }
  }
  double_row_major_plus();
  methods->free(&array);
}
예제 #4
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);
        
}
예제 #5
0
파일: a2test.c 프로젝트: limz10/locality
static void test_methods(A2Methods_T methods_under_test) 
{
        methods = methods_under_test;
        assert(methods);
        assert(has_minimum_methods(methods));
        assert(has_small_plain_methods(methods)
               || has_small_blocked_methods(methods));
        assert(!(has_small_plain_methods(methods)
                 && has_small_blocked_methods(methods)));
        assert(!(has_plain_methods(methods)
                 && has_blocked_methods(methods)));

        if (!(has_plain_methods(methods) || has_blocked_methods(methods)))
                fprintf(stderr, "Some full mapping methods are missing\n");

        A2 array = methods->new_with_blocksize(W, H, sizeof(unsigned), BS);
<<<<<<< HEAD