static void shift_btn(shifter_dd *dt, void **wdata, int what, void **where) { int i; if ((what == op_EVT_OK) || (what == op_EVT_CANCEL)) { shift_play_state = FALSE; // Stop mem_pal_copy(mem_pal, dt->old_pal); update_stuff(UPD_PAL); run_destroy(wdata); return; } if (what == op_EVT_CHANGE) // Play toggle { cmd_read(where, dt); if (shift_play_state && !shift_timer_state) // Start timer shift_timer_state = threads_timeout_add(100, shift_play_timer_call, dt); return; } where = origin_slot(where); if (where == dt->fix) // Button to fix palette pressed { i = dt->frame[0]; if (!i || (i > dt->frame[2])) return; // Nothing to do mem_pal_copy(mem_pal, dt->old_pal); spot_undo(UNDO_PAL); shifter_set_palette(dt, i); mem_pal_copy(dt->old_pal, mem_pal); cmd_set(dt->slider, 0); update_stuff(UPD_PAL); } else if (where == dt->clear) // Button to clear all of the values { for (i = 0; i < NSHIFT; i++) spins[i][0][0] = spins[i][1][0] = spins[i][2][0] = 0; cmd_reset(dt->spinpack, dt); shifter_moved(dt, wdata, op_EVT_CHANGE, dt->spinpack); } else if (where == dt->create) // Button to create a sequence of undo images { if (!dt->frame[2]) return; // Nothing to do for (i = 0; i <= dt->frame[2]; i++) { shifter_set_palette(dt, i); spot_undo(UNDO_PAL); } shifter_set_palette(dt, dt->frame[0]); update_stuff(UPD_PAL); } }
static void click_shift_fix() // Button to fix palette pressed { int i = mt_spinslide_get_value(shifter_slider); if ( i==0 || i>=shifter_max ) return; // Nothing to do mem_pal_copy( mem_pal, sh_old_pal ); spot_undo(UNDO_PAL); shifter_set_palette(i); mem_pal_copy( sh_old_pal, mem_pal ); mt_spinslide_set_value(shifter_slider, 0); update_stuff(UPD_PAL); }
static gboolean click_shift_close() // Palette Shifter window closed by user or WM { shift_play_stop(); mem_pal_copy( mem_pal, sh_old_pal ); update_stuff(UPD_PAL); destroy_dialog(shifter_window); return (FALSE); }
static void shifter_set_palette(int pos) // Set current palette to a given position in cycle { int i, pos2; if ( pos<0 || pos>=shifter_max ) return; // Ensure sanity mem_pal_copy( mem_pal, sh_old_pal ); if ( pos==0 ) return; // pos=0 => original state for ( i=0; i<8; i++ ) // Implement each of the shifts { pos2 = pos / (shifter_in[i][2]+1); // Normalize the position shift for delay pal_shift( shifter_in[i][0], shifter_in[i][1], pos2 ); } }
/* Set current palette to a given position in cycle */ static void shifter_set_palette(shifter_dd *dt, int pos) { int i, pos2; mem_pal_copy(mem_pal, dt->old_pal); if (!pos) return; // pos=0 => original state for (i = 0; i < NSHIFT; i++) // Implement each of the shifts { // Normalize the position shift for delay pos2 = pos / (spins[i][2][0] + 1); pal_shift(dt->old_pal, spins[i][0][0], spins[i][1][0], pos2); } }
void pressed_shifter() { shifter_dd tdata; int i; memset(&tdata, 0, sizeof(tdata)); mem_pal_copy(tdata.old_pal, mem_pal); for (i = 0; i < NSHIFT; i++) { spins[i][0][2] = spins[i][1][2] = mem_cols - 1; spins[i][2][2] = 255; } shift_play_state = FALSE; // Stopped run_create_(shifter_code, &tdata, sizeof(tdata), script_cmds); }
int load_png( char *file_name, int stype ) { char buf[PNG_BYTES_TO_CHECK], *mess; unsigned char *rgb, *rgb2, *rgb3; int i, row, do_prog, bit_depth, color_type, interlace_type, width, height; unsigned int sig_read = 0; FILE *fp; png_bytep *row_pointers, trans; png_color_16p trans_rgb; png_structp png_ptr; png_infop info_ptr; png_uint_32 pwidth, pheight; png_colorp png_palette; if ((fp = fopen(file_name, "rb")) == NULL) return -1; i = fread(buf, 1, PNG_BYTES_TO_CHECK, fp); if ( i != PNG_BYTES_TO_CHECK ) goto fail; i = !png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK); if ( i<=0 ) goto fail; rewind( fp ); png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) goto fail; info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { png_destroy_read_struct(&png_ptr, NULL, NULL); goto fail; } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, NULL, NULL); fclose(fp); return -1; } png_init_io(png_ptr, fp); png_set_sig_bytes(png_ptr, sig_read); png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &pwidth, &pheight, &bit_depth, &color_type, &interlace_type, NULL, NULL); width = (int) pwidth; height = (int) pheight; if ( width > MAX_WIDTH || height > MAX_HEIGHT ) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(fp); return TOO_BIG; } row_pointers = malloc( sizeof(png_bytep) * height ); if (setjmp(png_jmpbuf(png_ptr))) // If libpng generates an error now, clean up { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(fp); free(row_pointers); return FILE_LIB_ERROR; } rgb = NULL; mess = NULL; if ( width*height > FILE_PROGRESS ) do_prog = 1; else do_prog = 0; if ( stype == 0 ) { mess = _("Loading PNG image"); rgb = mem_image; } if ( stype == 1 ) { mess = _("Loading clipboard image"); rgb = mem_clipboard; if ( rgb != NULL ) free( rgb ); // Lose old clipboard mem_clip_mask_clear(); // Lose old clipboard mask } if ( color_type != PNG_COLOR_TYPE_PALETTE || bit_depth>8 ) // RGB PNG file { png_set_strip_16(png_ptr); png_set_gray_1_2_4_to_8(png_ptr); png_set_palette_to_rgb(png_ptr); png_set_gray_to_rgb(png_ptr); if ( stype == 0 ) { mem_pal_copy( mem_pal, mem_pal_def ); mem_cols = 256; if ( mem_new( width, height, 3 ) != 0 ) goto file_too_huge; rgb = mem_image; if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { // Image has a transparent index png_get_tRNS(png_ptr, info_ptr, 0, 0, &trans_rgb); mem_pal[255].red = trans_rgb->red; mem_pal[255].green = trans_rgb->green; mem_pal[255].blue = trans_rgb->blue; if (color_type == PNG_COLOR_TYPE_GRAY) { if ( bit_depth==4 ) i = trans_rgb->gray * 17; if ( bit_depth==8 ) i = trans_rgb->gray; if ( bit_depth==16 ) i = trans_rgb->gray >> (bit_depth-8); mem_pal[255].red = i; mem_pal[255].green = i; mem_pal[255].blue = i; } mem_xpm_trans = 255; } }
void pressed_shifter() { GtkWidget *vbox, *hbox, *table, *button, *label; GtkAccelGroup* ag = gtk_accel_group_new(); int i, j, max; char txt[32]; shifter_window = add_a_window(GTK_WINDOW_TOPLEVEL, _("Palette Shifter"), GTK_WIN_POS_CENTER, TRUE); vbox = add_vbox(shifter_window); gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); table = add_a_table(9, 4, 5, vbox); label = add_to_table( _("Start"), table, 0, 1, 1 ); gtk_misc_set_alignment( GTK_MISC(label), 0.5, 0.5 ); label = add_to_table( _("Finish"), table, 0, 2, 1 ); gtk_misc_set_alignment( GTK_MISC(label), 0.5, 0.5 ); label = add_to_table( _("Delay"), table, 0, 3, 1 ); gtk_misc_set_alignment( GTK_MISC(label), 0.5, 0.5 ); for ( i=0; i<8; i++ ) { sprintf(txt, "%i", i); add_to_table( txt, table, i+1, 0, 5 ); for ( j=0; j<3; j++ ) { if ( j==2 ) max=255; else max=mem_cols-1; shifter_spin[i][j] = spin_to_table( table, i+1, j+1, 2, shifter_in[i][j], 0, max ); spin_connect(shifter_spin[i][j], GTK_SIGNAL_FUNC(shifter_moved), NULL); } } hbox = pack(vbox, gtk_hbox_new(FALSE, 0)); gtk_widget_show (hbox); button = pack(hbox, sig_toggle_button(_("Play"), FALSE, NULL, GTK_SIGNAL_FUNC(shift_but_playstop))); shift_play_state = FALSE; // Stopped shifter_label = xpack(hbox, gtk_label_new("")); gtk_widget_show( shifter_label ); gtk_misc_set_alignment( GTK_MISC(shifter_label), 0.5, 0.5 ); shifter_slider = xpack5(vbox, mt_spinslide_new(-1, -1)); mt_spinslide_set_range(shifter_slider, 0, 0); mt_spinslide_set_value(shifter_slider, 0); mt_spinslide_connect(shifter_slider, GTK_SIGNAL_FUNC(shifter_slider_moved), NULL); add_hseparator( vbox, -2, 10 ); hbox = pack(vbox, gtk_hbox_new(FALSE, 0)); gtk_widget_show (hbox); button = xpack5(hbox, gtk_button_new_with_label(_("Clear"))); gtk_widget_show(button); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(click_shift_clear), NULL); button = xpack5(hbox, gtk_button_new_with_label(_("Fix Palette"))); gtk_widget_show(button); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(click_shift_fix), NULL); button = xpack5(hbox, gtk_button_new_with_label(_("Create Frames"))); gtk_widget_show(button); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(click_shift_create), NULL); button = xpack5(hbox, gtk_button_new_with_label(_("Close"))); gtk_widget_show(button); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(click_shift_close), NULL ); gtk_widget_add_accelerator (button, "clicked", ag, GDK_Escape, 0, (GtkAccelFlags) 0); delete_to_click(shifter_window, button); gtk_window_add_accel_group(GTK_WINDOW (shifter_window), ag); // !!! Transient windows cannot be minimized; don't know if that's desirable here // gtk_window_set_transient_for(GTK_WINDOW(shifter_window), GTK_WINDOW(main_window)); gtk_widget_show(shifter_window); #if GTK_MAJOR_VERSION == 1 gtk_widget_queue_resize(shifter_window); /* Re-render sliders */ #endif mem_pal_copy( sh_old_pal, mem_pal ); // Backup the current palette shifter_pos = 0; shifter_max = 0; shifter_moved(); // Initialize the input array }