Ignore:
Timestamp:
Sep 22, 2006, 2:27:13 AM (17 years ago)
Author:
Sam Hocevar
Message:
  • Autocrop toilet output.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/test/toilet.c

    r1077 r1080  
    3535
    3636/* Canvas special effects */
    37 static void make_gay(cucul_canvas_t *);
     37static void filter_autocrop(cucul_canvas_t *);
     38static void filter_gay(cucul_canvas_t *);
    3839
    3940int main(int argc, char *argv[])
     
    149150    /* Do gay stuff with our string (léopard) */
    150151    cv = cuculize_big(string, length);
     152    filter_autocrop(cv);
    151153    if(flag_gay)
    152         make_gay(cv);
     154        filter_gay(cv);
    153155
    154156    /* Output char */
     
    230232}
    231233
    232 static void make_gay(cucul_canvas_t *cv)
     234static void filter_autocrop(cucul_canvas_t *cv)
     235{
     236    unsigned int x, y, w, h;
     237    unsigned int xmin, xmax, ymin, ymax;
     238
     239    xmin = w = cucul_get_canvas_width(cv);
     240    xmax = 0;
     241    ymin = h = cucul_get_canvas_height(cv);
     242    ymax = 0;
     243
     244    for(y = 0; y < h; y++)
     245        for(x = 0; x < w; x++)
     246    {
     247        unsigned long int ch = cucul_getchar(cv, x, y);
     248        if(ch != (unsigned char)' ')
     249        {
     250            if(x < xmin)
     251                xmin = x;
     252            if(x > xmax)
     253                xmax = x;
     254            if(y < ymin)
     255                ymin = y;
     256            if(y > ymax)
     257                ymax = y;
     258        }
     259    }
     260
     261    cucul_set_canvas_boundaries(cv, xmin, ymin,
     262                                xmax - xmin + 1, ymax - ymin + 1);
     263}
     264
     265static void filter_gay(cucul_canvas_t *cv)
    233266{
    234267    static unsigned char const rainbow[] =
Note: See TracChangeset for help on using the changeset viewer.