#include #include #include "pnginput.h" #include "colourspace.h" #include "triangulation.h" #define USE_LUV void read_image( double *data, double *pixeldata, pnginput_t *pnginput, int width, int height ) { int i, j; for( i = 0; i < height; i++ ) { unsigned char *curscanline = pnginput_get_scanline( pnginput, i ); for( j = 0; j < width; j++ ) { double bp = ( (double) curscanline[ 0 ] ) / 255.0; double gp = ( (double) curscanline[ 1 ] ) / 255.0; double rp = ( (double) curscanline[ 2 ] ) / 255.0; double r, g, b, x, y, z, lstar, ustar, vstar; nonlinear_to_linear_srgb( rp, gp, bp, &r, &g, &b ); srgb_to_xyz( r, g, b, &x, &y, &z ); xyz_to_lupvp( x, y, z, &lstar, &ustar, &vstar ); *data++ = lstar; #ifdef USE_LUV *pixeldata++ = lstar; *pixeldata++ = ustar; *pixeldata++ = vstar; #else *pixeldata++ = x; *pixeldata++ = y; *pixeldata++ = z; #endif curscanline += 3; } } } int main( int argc, char **argv ) { pnginput_t *pnginput; int width, height; double *data; double *pixeldata; triangulation_t *image; int alg, passes; pnginput = pnginput_new( argv[ 1 ] ); if( !pnginput ) { fprintf( stderr, "scale: can't open input %s\n", argv[ 1 ] ); return 1; } width = pnginput_get_width( pnginput ); height = pnginput_get_height( pnginput ); data = (double *) malloc( width * height * sizeof( double ) ); if( !data ) { fprintf( stderr, "scale: can't allocate input data\n" ); return 1; } pixeldata = (double *) malloc( 3 * width * height * sizeof( double ) ); if( !pixeldata ) { fprintf( stderr, "scale: can't allocate pixel data\n" ); return 1; } read_image( data, pixeldata, pnginput, width, height ); pnginput_delete( pnginput ); alg = atoi( argv[ 3 ] ); passes = atoi( argv[ 4 ] ); fprintf( stderr, "tri: Input is %dx%d\n", width, height ); image = initialize_image( data, pixeldata, width, height ); run_alg( image, alg, passes ); // print_edges( image ); save_triangulation( image, argv[ 2 ] ); return 0; }