Changeset 1909


Ignore:
Timestamp:
11/06/07 15:09:07 (6 years ago)
Author:
jylam
Message:
  • Added brightness / contrast / gamma support
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/img2txt.c

    r1908 r1909  
    4444    fprintf(stderr, "Example : %s -w 80 -f ansi ./caca.png\n\n", argv[0]); 
    4545    fprintf(stderr, "Options:\n"); 
    46     fprintf(stderr, "  -h, --help\tThis help\n"); 
    47     fprintf(stderr, "  -W, --width=WIDTH\tWidth of resulting image\n"); 
    48     fprintf(stderr, "  -H, --height=HEIGHT\tHeight of resulting image\n"); 
    49     fprintf(stderr, "  -d, --dither=DITHER\tDithering algorithm to use :\n"); 
     46    fprintf(stderr, "  -h, --help\t\t\tThis help\n"); 
     47    fprintf(stderr, "  -W, --width=WIDTH\t\tWidth of resulting image\n"); 
     48    fprintf(stderr, "  -H, --height=HEIGHT\t\tHeight of resulting image\n"); 
     49    fprintf(stderr, "  -b, --brightness=BRIGHTNESS\tBrightness of resulting image\n"); 
     50    fprintf(stderr, "  -c, --contrast=CONTRAST\tContrast of resulting image\n"); 
     51    fprintf(stderr, "  -g, --gamma=GAMMA\t\tGamma of resulting image\n"); 
     52    fprintf(stderr, "  -d, --dither=DITHER\t\tDithering algorithm to use :\n"); 
    5053    fprintf(stderr, "\t\t\tnone     : Nearest color\n"); 
    5154    fprintf(stderr, "\t\t\tordered2 : Ordered 2x2\n"); 
     
    5457    fprintf(stderr, "\t\t\trandom   : Random\n"); 
    5558    fprintf(stderr, "\t\t\tfstein   : Floyd Steinberg (default)\n"); 
    56     fprintf(stderr, "  -f, --format=FORMAT\tFormat of the resulting image :\n"); 
     59    fprintf(stderr, "  -f, --format=FORMAT\t\tFormat of the resulting image :\n"); 
    5760    fprintf(stderr, "\t\t\tansi : coulored ANSI (default)\n"); 
    5861    fprintf(stderr, "\t\t\tcaca : internal libcaca format\n"); 
     
    7780    char *format = NULL; 
    7881    char *dither = NULL; 
    79  
     82    float gamma = -1, brightness = -1, contrast = -1; 
    8083 
    8184    if(argc < 2) 
     
    9194        static struct myoption long_options[] = 
    9295        { 
    93             { "width",  1, NULL, 'W' }, 
    94             { "height", 1, NULL, 'H' }, 
    95             { "format", 1, NULL, 'f' }, 
    96             { "dither", 1, NULL, 'd' }, 
    97             { "help",   0, NULL, 'h' }, 
     96            { "width",       1, NULL, 'W' }, 
     97            { "height",      1, NULL, 'H' }, 
     98            { "format",      1, NULL, 'f' }, 
     99            { "dither",      1, NULL, 'd' }, 
     100            { "gamma",       1, NULL, 'g' }, 
     101            { "brightness",  1, NULL, 'b' }, 
     102            { "contrast",    1, NULL, 'c' }, 
     103            { "help",        0, NULL, 'h' }, 
    98104        }; 
    99         int c = mygetopt(argc, argv, "W:H:f:d:h", long_options, &option_index); 
     105        int c = mygetopt(argc, argv, "W:H:f:d:g:b:c:h", long_options, &option_index); 
    100106        if(c == -1) 
    101107            break; 
     
    119125            return 0; 
    120126            break; 
     127        case 'g': /* --gamma */ 
     128            gamma = atof(myoptarg); 
     129            break; 
     130        case 'b': /* --brightness */ 
     131            brightness = atof(myoptarg); 
     132            break; 
     133        case 'c': /* --contrast */ 
     134            contrast = atof(myoptarg); 
     135            break; 
    121136        default: 
    122137            return 1; 
     
    167182        return -1; 
    168183    } 
     184 
     185    if(brightness!=-1) cucul_set_dither_brightness (i->dither, brightness); 
     186    if(contrast!=-1) cucul_set_dither_contrast (i->dither, contrast); 
     187    if(gamma!=-1) cucul_set_dither_gamma (i->dither, gamma); 
     188 
    169189    cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels); 
    170190 
Note: See TracChangeset for help on using the changeset viewer.