示例#1
0
文件: prog08.c 项目: CARLEYBR/Classes
/*------------------------------------------------- main -----
  |  Function main
  |
  |  Purpose:  Reads input from STDIN using getchar(), iterates over 
  |            each character and determines whether the character
  |            denotes the end of a sentence or word. After reaching
  |            EOF, prints output of flesch kincaid algorithm results
  |            and exits.
  |       
  |
  |  Parameters: argc (IN) -- number of arguments
  |              argv (IN) -- Expects the program name, image file, and triples
  |                
  |
  |  Returns:  Only success
  *-------------------------------------------------------------------*/
int main(int argc, char ** argv) {
    context = logging_init("prog08");
    
    if (argc < 5) {
        error("Incorrect number of arguments. Need a file name and at least one triple");
        usage(*argv);
        exit(EXIT_FAILURE);
    }

    if ((argc - 2) % 3) {
        error("Incorrect number of arguments. Triples have 3 values hence the name");
        usage(*argv);
        exit(EXIT_FAILURE);
    }
    
    char * image_file_name = chararr_get(argv, 1);
    FILE * image_file = fopen(image_file_name, "r");
    Image * image = image_file_init(image_file);

    printf("Original Image:\n\n");
    image_print(image);

    int changed = each_triple(argc, argv, image, image_fill);

    printf("A total of %d pixels were changed\n", changed);

    fclose(image_file);
    free(image_file_name);
    image_free(image);
    logging_dest(context);
    return EXIT_SUCCESS;
}
示例#2
0
char *ascii_read() {
    FILE *jpeg = webcam_read();

    image_t *original = image_read(jpeg),
            *resized  = image_new(opt_width, opt_height);

    fclose(jpeg);

    image_clear(resized);
    image_resize(original, resized);

    char *ascii = image_print(resized);

    image_destroy(original);
    image_destroy(resized);

    return ascii;
}
示例#3
0
文件: prog08.c 项目: CARLEYBR/Classes
/*------------------------------------------------- each_triple -----
  |  Function each_triple
  |
  |  Purpose:  Iterates through triples passed on the command line and
  |            executes the given callback for each triple.
  |       
  |
  |  Parameters: argc (IN) -- Number of arguments
  |              argv (IN) -- arguments
  |              image (IN) -- Image instance parsed from the image file
  |              callback (IN) -- call back to call for each triple
  |                
  |
  |  Returns:  Number of images effected
  *-------------------------------------------------------------------*/
int each_triple(int argc, char ** argv, Image * image, Image * (*callback)(Image *, int, int, char, int *)) {
    int retval = 0;
    int i;
    char * arg = *argv;
    int arg_offset = 2;
    int triple_cnt = (argc - 2) / 3;

    for (i = 0; i < triple_cnt; i++) {
        int rows = atoi(chararr_get(argv, (i * 3) + arg_offset));
        int cols = atoi(chararr_get(argv, (i * 3) + arg_offset + 1));
        char color = *chararr_get(argv, (i * 3) + arg_offset + 2);

        if (rows < 0 || rows >= image->height || cols < 0 || cols >= image->width) {
            error("Supplied triple is outside the image range");
        }
        
        image = callback(image, rows, cols, color, &retval);
        image_print(image);
        debug("Got color %c", color);
        debug("%d changed ", retval);
    }

    return retval;
}
示例#4
0
文件: aomcopy.c 项目: jleffler/soq
static void aomc_applicator_ctxt(const AoM_Block *ptr, void *ctxt)
{
    int *ip = ctxt;
    printf("%d\n", ++*ip);
    image_print(stdout, 0, ptr->blk_data, ptr->blk_size);
}
示例#5
0
文件: aomcopy.c 项目: jleffler/soq
static void aomc_applicator(const AoM_Block *ptr)
{
    image_print(stdout, 0, ptr->blk_data, ptr->blk_size);
}