Ignore:
Timestamp:
Oct 25, 2006, 6:06:19 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Added filter_flip, filter_flop and filter_rotate.
  • Add a -F flag to specify filters to apply. Can be specified more than once, and filters can be chained using ":", eg. "-F flip:gay".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/filter.c

    r1227 r1228  
    2121#   include <inttypes.h>
    2222#endif
     23#include <string.h>
     24#include <stdio.h>
     25#include <stdlib.h>
    2326#include <cucul.h>
    2427
     28#include "toilet.h"
    2529#include "filter.h"
    2630
    27 void filter_autocrop(cucul_canvas_t *cv)
     31static void filter_crop(cucul_canvas_t *);
     32static void filter_gay(cucul_canvas_t *);
     33static void filter_metal(cucul_canvas_t *);
     34static void filter_flip(cucul_canvas_t *);
     35static void filter_flop(cucul_canvas_t *);
     36static void filter_rotate(cucul_canvas_t *);
     37
     38struct
     39{
     40    char const *name;
     41    void (*function)(cucul_canvas_t *);
     42}
     43const lookup[] =
     44{
     45    { "crop", filter_crop },
     46    { "gay", filter_gay },
     47    { "metal", filter_metal },
     48    { "flip", filter_flip },
     49    { "flop", filter_flop },
     50    { "rotate", filter_rotate },
     51};
     52
     53int filter_add(context_t *cx, char const *filter)
     54{
     55    unsigned int n;
     56    int i;
     57
     58    for(;;)
     59    {
     60        while(*filter == ':')
     61            filter++;
     62
     63        if(*filter == '\0')
     64            break;
     65
     66        for(i = sizeof(lookup) / sizeof(lookup[0]); i--; )
     67            if(!strncmp(filter, lookup[i].name, strlen(lookup[i].name)))
     68                break;
     69
     70        n = strlen(lookup[i].name);
     71
     72        if(i == -1 || (filter[n] != ':' && filter[n] != '\0'))
     73        {
     74            fprintf(stderr, "unknown filter near `%s'\n", filter);
     75            return -1;
     76        }
     77
     78        if((cx->nfilters % 16) == 0)
     79            cx->filters = realloc(cx->filters, (cx->nfilters + 16)
     80                                                 * sizeof(lookup[0].function));
     81        cx->filters[cx->nfilters] = lookup[i].function;
     82        cx->nfilters++;
     83
     84        filter += n;
     85    }
     86
     87    return 0;
     88}
     89
     90int filter_do(context_t *cx)
     91{
     92    unsigned int i;
     93
     94    for(i = 0; i < cx->nfilters; i++)
     95        cx->filters[i](cx->cv);
     96
     97    return 0;
     98}
     99
     100static void filter_crop(cucul_canvas_t *cv)
    28101{
    29102    unsigned int x, y, w, h;
     
    59132}
    60133
    61 void filter_metal(cucul_canvas_t *cv)
     134static void filter_metal(cucul_canvas_t *cv)
    62135{
    63136    static unsigned char const palette[] =
     
    89162}
    90163
    91 void filter_gay(cucul_canvas_t *cv)
     164static void filter_gay(cucul_canvas_t *cv)
    92165{
    93166    static unsigned char const rainbow[] =
     
    118191}
    119192
     193static void filter_flip(cucul_canvas_t *cv)
     194{
     195    cucul_flip(cv);
     196}
     197
     198static void filter_flop(cucul_canvas_t *cv)
     199{
     200    cucul_flop(cv);
     201}
     202
     203static void filter_rotate(cucul_canvas_t *cv)
     204{
     205    cucul_rotate(cv);
     206}
     207
Note: See TracChangeset for help on using the changeset viewer.