예제 #1
0
int main(int argc, char *argv[])
{
    int opt;

    scale_fnctn = sq_linear_scale;

    while ((opt = getopt(argc, argv, "hr:c:a:px")) != -1)
    {
        switch (opt)
        {
            case 'h':
                print_usage(usage_text);
                exit(EXIT_FAILURE);
            case 'r':
                sscanf(optarg, "%u", &rows);
                break;
            case 'c':
                sscanf(optarg, "%u", &cols);
                break;
            case 'a':
                sscanf(optarg, "%u", &averagelines);
                break;
            case 'p':
                scale_fnctn = sq_power_scale;
                break;
            case 'x':
                scale_fnctn = sq_no_scale;
                break;
            default:
                print_usage(usage_text);
                exit(EXIT_FAILURE);
        }
    }

    //fprintf(stderr, "Allocating image\n");
    
    imgbfr = malloc(sizeof(float) * rows * cols);

    //fprintf(stderr, "Allocated image\n");
    if(imgbfr == NULL)
    {
        sq_error_handle(ERR_MALLOC);
        exit(EXIT_FAILURE);
    }
    
    //fprintf(stderr, "reading image\n");
    int read_status = sq_read_img(stdin, imgbfr, rows, cols);
    
    //fprintf(stderr, "read image\n");
    if(read_status < 0)
    {
        free(imgbfr);
        sq_error_handle(read_status);
        exit(EXIT_FAILURE);
    }
    //fprintf(stderr, "Scaling image\n");

    scale_fnctn(imgbfr, rows, cols);
    
    //fprintf(stderr, "Scaled image\n");
    // Now optionally average the lines as desired
    if(averagelines > 0)
    {
        imgbfr_avg = malloc(sizeof(float) * rows/averagelines * cols);
        sq_average_lines(imgbfr, rows, cols, imgbfr_avg, averagelines);
        sq_write_pnm(stdout, imgbfr_avg, rows/averagelines, cols);
        scale_fnctn(imgbfr_avg, rows/averagelines, cols);
        free(imgbfr_avg);
    }
    else
    {
        sq_write_pnm(stdout, imgbfr, rows, cols);
        free(imgbfr);
    }

    //fprintf(stderr, "Exiting image\n");
    exit(EXIT_SUCCESS);
}
예제 #2
0
int main(int argc, char *argv[])
{
    int opt;
    
    while ((opt = getopt(argc, argv, "hr:c:x:y:")) != -1)
    {
        switch (opt)
        {
            case 'h':
                print_usage(usage_text, arrlen);
                exit(EXIT_SUCCESS);
            case 'r':
                sscanf(optarg, "%u", &rows);
                break;
            case 'c':
                sscanf(optarg, "%u", &cols);
                break;
            case 'x':
                sscanf(optarg, "%f", &width_chop_fraction);
                break;
            case 'y':
                sscanf(optarg, "%f", &height_chop_fraction);
                break;
            default:
                print_usage(usage_text, arrlen);
                exit(EXIT_SUCCESS);
        }
    }
    
    unsigned int col_first = cols * width_chop_fraction;
    unsigned int col_last = cols * (1 - width_chop_fraction);
    unsigned int col_count = col_last - col_first;
    
    unsigned int row_first = rows * height_chop_fraction;
    unsigned int row_last = rows * (1 - height_chop_fraction);
    unsigned int row_count = row_last - row_first;
    
    imgbfr = malloc(sizeof(float) * rows * cols);
    if(imgbfr == NULL)
    {
        sq_error_handle(ERR_MALLOC);
        exit(EXIT_FAILURE);
    }
    
    int read_status = sq_read_img(stdin, imgbfr, rows, cols);
    if(read_status < 0)
    {
        free(imgbfr);
        sq_error_handle(read_status);
        exit(EXIT_FAILURE);
    }
    
    imgbfr_chopped = malloc(sizeof(float) * row_count * col_count);
    if(imgbfr_chopped == NULL)
    {
        sq_error_handle(ERR_MALLOC);
        exit(EXIT_FAILURE);
    }
    
    int chop_status = sq_imchop(imgbfr, imgbfr_chopped, rows, cols, width_chop_fraction, 0);
    if(chop_status < 0)
    {
        free(imgbfr);
        sq_error_handle(chop_status);
        exit(EXIT_FAILURE);
    }
    
    fprintf(stderr, "Image chopped by %s - number of columns: %d, number of rows: %d\n", argv[0], col_count, row_count);
    
    sq_write_img(stdout, imgbfr_chopped, row_count, col_count);
    free(imgbfr);
    free(imgbfr_chopped);
    
    exit(EXIT_SUCCESS);
}