Image filtering and transformation in Perl and C