static void morph_buffer( float *in, float *out, int width, Params *parm ) { int x; for( x = 0; x < width; x++ ) { double L = in[0]; double a = in[1]; double b = in[2]; L = IM_CLIP( 0, L, 100 ); a -= parm->a_offset[(int) L]; b -= parm->b_offset[(int) L]; L = (L + parm->L_offset) * parm->L_scale; L = IM_CLIP( 0, L, 100 ); a *= parm->a_scale; b *= parm->b_scale; out[0] = L; out[1] = a; out[2] = b; in += 3; out += 3; } }
/* Fill a scanline between points x1 and x2 inclusive. x1 < x2. */ void im__draw_scanline( Draw *draw, int y, int x1, int x2 ) { PEL *mp; int i; int len; g_assert( x1 <= x2 ); if( y < 0 || y >= draw->im->Ysize ) return; if( x1 < 0 && x2 < 0 ) return; if( x1 >= draw->im->Xsize && x2 >= draw->im->Xsize ) return; x1 = IM_CLIP( 0, x1, draw->im->Xsize - 1 ); x2 = IM_CLIP( 0, x2, draw->im->Xsize - 1 ); mp = (PEL *) IM_IMAGE_ADDR( draw->im, x1, y ); len = x2 - x1 + 1; for( i = 0; i < len; i++ ) { im__draw_pel( draw, mp ); mp += draw->psize; } }
static void workspaceview_scroll_to( Workspaceview *wview, int x, int y ) { GtkAdjustment *hadj = gtk_scrolled_window_get_hadjustment( GTK_SCROLLED_WINDOW( wview->window ) ); GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW( wview->window ) ); int nx, ny; nx = IM_CLIP( 0, x, wview->width - wview->vp.width ); ny = IM_CLIP( 0, y, wview->height - wview->vp.height ); adjustments_set_value( hadj, vadj, nx, ny ); }
static int lgrab_set_ngrabs( LGrab *lg, int ngrabs ) { lg->c_ngrabs = IM_CLIP( 1, ngrabs, 1000 ); return( 0 ); }
static int lgrab_set_hue( LGrab *lg, int hue ) { lg->picture.hue = IM_CLIP( 0, hue, 65535 ); if( lgrab_ioctl( lg, VIDIOCSPICT, &lg->picture ) ) return( -1 ); return( 0 ); }
static int lgrab_set_contrast( LGrab *lg, int contrast ) { lg->picture.contrast = IM_CLIP( 0, contrast, 65535 ); if( lgrab_ioctl( lg, VIDIOCSPICT, &lg->picture ) ) return( -1 ); return( 0 ); }
static int lgrab_set_brightness( LGrab *lg, int brightness ) { lg->picture.brightness = IM_CLIP( 0, brightness, 65535 ); if( lgrab_ioctl( lg, VIDIOCSPICT, &lg->picture ) ) return( -1 ); return( 0 ); }
/* Make up a new definition. */ Symbol * workspace_add_def( Workspace *ws, const char *str ) { Column *col = workspace_column_pick( ws ); Symbol *sym; char *name; #ifdef DEBUG printf( "workspace_add_def: %s\n", str ); #endif /*DEBUG*/ if( !str || strspn( str, WHITESPACE ) == strlen( str ) ) return( NULL ); /* Try parsing as a "fred = 12" style def. */ attach_input_string( str ); if( (name = parse_test_define()) ) { sym = symbol_new( ws->sym->expr->compile, name ); IM_FREE( name ); attach_input_string( str + IM_CLIP( 0, input_state.charpos - 1, strlen( str ) ) ); } else { /* That didn't work. Make a sym from the col name. */ sym = workspace_add_symbol( ws ); attach_input_string( str ); } if( !symbol_user_init( sym ) || !parse_rhs( sym->expr, PARSE_RHS ) ) { /* Another parse error. */ expr_error_get( sym->expr ); /* Block changes to error_string ... symbol_destroy() * can set this for compound objects. */ error_block(); IDESTROY( sym ); error_unblock(); return( NULL ); } /* If we're redefining a sym, it might have a row already. */ if( !sym->expr->row ) (void) row_new( col->scol, sym, &sym->expr->root ); symbol_made( sym ); workspace_set_modified( ws, TRUE ); return( sym ); }
/* Read an ascii ppm/pgm file. */ static int read_ascii( FILE *fp, IMAGE *out ) { int x, y; PEL *buf; if( im_outcheck( out ) || im_setupout( out ) || !(buf = IM_ARRAY( out, IM_IMAGE_SIZEOF_LINE( out ), PEL )) ) return( -1 ); for( y = 0; y < out->Ysize; y++ ) { for( x = 0; x < out->Xsize * out->Bands; x++ ) { int val; if( read_int( fp, &val ) ) return( -1 ); switch( out->BandFmt ) { case IM_BANDFMT_UCHAR: buf[x] = IM_CLIP( 0, val, 255 ); break; case IM_BANDFMT_USHORT: ((unsigned short *) buf)[x] = IM_CLIP( 0, val, 65535 ); break; case IM_BANDFMT_UINT: ((unsigned int *) buf)[x] = val; break; default: g_assert( 0 ); } } if( im_writeline( y, out, buf ) ) return( -1 ); } return( 0 ); }
/* from/to/value have changed ... update the widgets. */ static void tslider_real_changed( Tslider *tslider ) { GtkAdjustment *adj = tslider->adj; GtkWidget *entry = tslider->entry; #ifdef DEBUG printf( "tslider_real_changed: %p, val = %g\n", tslider, tslider->value ); #endif /*DEBUG*/ if( tslider->auto_link ) tslider->svalue = tslider_value_to_slider( tslider, tslider->value ); gtk_signal_handler_block_by_data( GTK_OBJECT( adj ), tslider ); gtk_signal_handler_block_by_data( GTK_OBJECT( entry ), tslider ); /* Some libc's hate out-of-bounds precision, so clip, just in case. */ set_gentry( tslider->entry, "%.*f", IM_CLIP( 0, tslider->digits, 100 ), tslider->value ); gtk_scale_set_digits( GTK_SCALE( tslider->slider ), tslider->digits ); if( !DEQ( tslider->from, tslider->last_from ) || !DEQ( tslider->to, tslider->last_to ) ) { double range = tslider->to - tslider->from; adj->step_increment = range / 100; adj->page_increment = range / 10; adj->page_size = range / 10; adj->lower = tslider->from; adj->upper = tslider->to + adj->page_size; tslider->last_to = tslider->to; tslider->last_from = tslider->from; gtk_adjustment_changed( adj ); } if( !DEQ( tslider->svalue, tslider->last_svalue ) ) { adj->value = tslider->svalue; tslider->last_svalue = tslider->svalue; gtk_adjustment_value_changed( adj ); } gtk_signal_handler_unblock_by_data( GTK_OBJECT( adj ), tslider ); gtk_signal_handler_unblock_by_data( GTK_OBJECT( entry ), tslider ); }
/* Grab and average many frames. */ static int lgrab_capturen( LGrab *lg ) { if( lg->c_ngrabs == 1 ) { if( lgrab_capture1( lg ) ) return( -1 ); } else { int i, j; int npx = lg->c_width * lg->c_height * 3; unsigned int *acc; if( !(acc = IM_ARRAY( NULL, npx, unsigned int )) ) return( -1 ); memset( acc, 0, npx * sizeof( unsigned int ) ); for( i = 0; i < lg->c_ngrabs; i++ ) { if( lgrab_capture1( lg ) ) { FREE( acc ); return( -1 ); } for( j = 0; j < npx; j++ ) acc[j] += (unsigned char) lg->capture_buffer[j]; } for( j = 0; j < npx; j++ ) { int avg = (acc[j] + lg->c_ngrabs / 2) / lg->c_ngrabs; lg->capture_buffer[j] = IM_CLIP( 0, avg, 255 ); } FREE( acc ); } return( 0 ); }