static int pcxdrv_open(screenshot_t *screenshot, const char *filename) { gfxoutputdrv_data_t *sdata; if (screenshot->palette->num_entries > 256) { log_error(LOG_DEFAULT, "Max 256 colors supported."); return -1; } sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; sdata->line = 0; sdata->ext_filename = util_add_extension_const(filename, pcx_drv.default_extension); sdata->fd = fopen(sdata->ext_filename, "wb"); if (sdata->fd == NULL) { lib_free(sdata->ext_filename); lib_free(sdata); return -1; } if (pcxdrv_write_file_header(screenshot) < 0) { fclose(sdata->fd); lib_free(sdata->ext_filename); lib_free(sdata); return -1; } sdata->data = lib_malloc(screenshot->width); sdata->pcx_data = lib_malloc(screenshot->width * 2); return 0; }
static int bmpdrv_open_memmap(const char *filename, int x_size, int y_size, BYTE *palette) { bmpdrv_memmap_ext_filename = util_add_extension_const(filename, bmp_drv.default_extension); bmpdrv_memmap_fd = fopen(bmpdrv_memmap_ext_filename, MODE_WRITE); if (bmpdrv_memmap_fd == NULL) { lib_free(bmpdrv_memmap_ext_filename); return -1; } if (bmpdrv_memmap_write_file_header(x_size, y_size) < 0) { fclose(bmpdrv_memmap_fd); lib_free(bmpdrv_memmap_ext_filename); return -1; } if (bmpdrv_memmap_write_bitmap_info(x_size, y_size, palette) < 0) { fclose(bmpdrv_memmap_fd); lib_free(bmpdrv_memmap_ext_filename); return -1; } bmpdrv_memmap_bmp_data = lib_malloc(bmpdrv_memmap_bytes_per_row(x_size)*y_size); return 0; }
static int jpegdrv_open(screenshot_t *screenshot, const char *filename) { gfxoutputdrv_data_t *sdata; cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; sdata->line = 0; sdata->ext_filename=util_add_extension_const(filename, jpeg_drv.default_extension); sdata->fd = fopen(sdata->ext_filename, "wb"); if (sdata->fd==NULL) { jpeg_destroy_compress(&cinfo); lib_free(sdata->ext_filename); lib_free(sdata); return -1; } jpeg_stdio_dest(&cinfo, sdata->fd); sdata->data = lib_malloc(screenshot->width*3); cinfo.image_width = screenshot->width; cinfo.image_height = screenshot->height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); return 0; }
int romset_file_save(const char *filename, const char **resource_list) { FILE *fp; char *newname; const char *s; newname = util_add_extension_const(filename, "vrs"); fp = fopen(newname, MODE_WRITE_TEXT); if (fp == NULL) { log_warning(romset_log, "Could not open file '%s' for writing (%s)!", newname, strerror(errno)); lib_free(newname); return -1; } log_message(romset_log, "Saving ROM set to file '%s'", newname); s = *resource_list++; while (s != NULL) { resources_write_item_to_file(fp, s); s = *resource_list++; } fclose(fp); lib_free(newname); return 0; }
static int ppmdrv_open(screenshot_t *screenshot, const char *filename) { gfxoutputdrv_data_t *sdata; sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; sdata->line = 0; sdata->ext_filename=util_add_extension_const(filename, ppm_drv.default_extension); sdata->fd = fopen(sdata->ext_filename, "wb"); if (sdata->fd==NULL) { lib_free(sdata->ext_filename); lib_free(sdata); return -1; } if (ppmdrv_write_file_header(screenshot)<0) { fclose(sdata->fd); lib_free(sdata->ext_filename); lib_free(sdata); return -1; } sdata->data = lib_malloc(screenshot->width*3); return 0; }
static int pngdrv_open_memmap(const char *filename, int x_size, int y_size, BYTE *palette) { pngdrv_memmap_png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)NULL, NULL, NULL); if (pngdrv_memmap_png_ptr == NULL) { return -1; } pngdrv_memmap_info_ptr = png_create_info_struct(pngdrv_memmap_png_ptr); if (pngdrv_memmap_info_ptr == NULL) { png_destroy_write_struct(&(pngdrv_memmap_png_ptr), (png_infopp)NULL); return -1; } /* pngdrv.c:232: warning: ‘jmpbuf‘ is deprecated (declared at /usr/include/libpng14/png.h:1096) */ /* if (setjmp(pngdrv_memmap_png_ptr->jmpbuf)) { */ if (setjmp(png_jmpbuf(pngdrv_memmap_png_ptr))) { png_destroy_write_struct(&(pngdrv_memmap_png_ptr), &(pngdrv_memmap_info_ptr)); return -1; } pngdrv_memmap_ext_filename = util_add_extension_const(filename, png_drv.default_extension); pngdrv_memmap_fd = fopen(pngdrv_memmap_ext_filename, MODE_WRITE); if (pngdrv_memmap_fd == NULL) { lib_free(pngdrv_memmap_ext_filename); return -1; } pngdrv_memmap_png_data = lib_malloc(x_size * 4); png_init_io(pngdrv_memmap_png_ptr, pngdrv_memmap_fd); png_set_compression_level(pngdrv_memmap_png_ptr, Z_BEST_COMPRESSION); /* pngdrv.c:251: warning: ‘width‘ is deprecated (declared at /usr/include/libpng14/png.h:639) pngdrv.c:252: warning: ‘height‘ is deprecated (declared at /usr/include/libpng14/png.h:640) pngdrv.c:253: warning: ‘bit_depth‘ is deprecated (declared at /usr/include/libpng14/png.h:651) pngdrv.c:254: warning: ‘color_type‘ is deprecated (declared at /usr/include/libpng14/png.h:653) */ /* pngdrv_memmap_info_ptr->width = x_size; pngdrv_memmap_info_ptr->height= y_size; pngdrv_memmap_info_ptr->bit_depth = 8; pngdrv_memmap_info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; */ png_set_IHDR(pngdrv_memmap_png_ptr, pngdrv_memmap_info_ptr, x_size, y_size, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(pngdrv_memmap_png_ptr, pngdrv_memmap_info_ptr); #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED png_set_invert_alpha(pngdrv_memmap_png_ptr); #endif return 0; }
static int gifdrv_open(screenshot_t *screenshot, const char *filename) { unsigned int i; gfxoutputdrv_data_t *sdata; GifColorType ColorMap256[256]; #if GIFLIB_MAJOR >= 5 int ec; #endif if (screenshot->palette->num_entries > 256) { log_error(LOG_DEFAULT, "Max 256 colors supported."); return -1; } sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; sdata->line = 0; sdata->ext_filename = util_add_extension_const(filename, gif_drv.default_extension); sdata->fd = VICE_EGifOpenFileName(sdata->ext_filename, 0, &ec); if (sdata->fd == NULL) { lib_free(sdata->ext_filename); lib_free(sdata); return -1; } sdata->data = lib_malloc(screenshot->width); gif_colors = VICE_MakeMapObject(screenshot->palette->num_entries, ColorMap256); for (i = 0; i < screenshot->palette->num_entries; i++) { gif_colors->Colors[i].Blue = screenshot->palette->entries[i].blue; gif_colors->Colors[i].Green = screenshot->palette->entries[i].green; gif_colors->Colors[i].Red = screenshot->palette->entries[i].red; } #if GIFLIB_MAJOR < 5 EGifSetGifVersion("87a"); #endif if (EGifPutScreenDesc(sdata->fd, screenshot->width, screenshot->height, 8, 0, gif_colors) == GIF_ERROR || EGifPutImageDesc(sdata->fd, 0, 0, screenshot->width, screenshot->height, 0, NULL) == GIF_ERROR) { VICE_EGifCloseFile(sdata->fd); VICE_FreeMapObject(gif_colors); lib_free(sdata->data); lib_free(sdata->ext_filename); lib_free(sdata); return -1; } return 0; }
static int bmpdrv_open(screenshot_t *screenshot, const char *filename) { gfxoutputdrv_data_t *sdata; sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; if (screenshot->palette->num_entries <= 2) { sdata->bpp = 1; } else if (screenshot->palette->num_entries <= 16) { sdata->bpp = 4; } else if (screenshot->palette->num_entries <= 256) { sdata->bpp = 8; } else { sdata->bpp = 24; } sdata->line = 0; sdata->ext_filename = util_add_extension_const(filename, bmp_drv.default_extension); sdata->fd = fopen(sdata->ext_filename, MODE_WRITE); if (sdata->fd == NULL) { lib_free(sdata->ext_filename); lib_free(sdata); return -1; } if (bmpdrv_write_file_header(screenshot) < 0) { fclose(screenshot->gfxoutputdrv_data->fd); lib_free(screenshot->gfxoutputdrv_data->ext_filename); lib_free(screenshot->gfxoutputdrv_data); return -1; } if (bmpdrv_write_bitmap_info(screenshot) < 0) { fclose(sdata->fd); lib_free(sdata->ext_filename); lib_free(sdata); return -1; } if (sdata->bpp == 24) { sdata->data = lib_malloc(screenshot->width * 3); } else { sdata->data = lib_malloc(screenshot->width); } sdata->bmp_data = lib_malloc(bmpdrv_bytes_per_row(screenshot)*screenshot->height); return 0; }
static int pcxdrv_open_memmap(const char *filename, int x_size, int y_size) { pcxdrv_memmap_ext_filename = util_add_extension_const(filename, pcx_drv.default_extension); pcxdrv_memmap_fd = fopen(pcxdrv_memmap_ext_filename, "wb"); if (pcxdrv_memmap_fd == NULL) { lib_free(pcxdrv_memmap_ext_filename); return -1; } if (pcxdrv_write_file_header_memmap(x_size, y_size) < 0) { fclose(pcxdrv_memmap_fd); lib_free(pcxdrv_memmap_ext_filename); return -1; } pcxdrv_memmap_pcx_data = lib_malloc(x_size * 2); return 0; }
static int gifdrv_open_memmap(const char *filename, int x_size, int y_size, uint8_t *palette) { unsigned int i; GifColorType ColorMap256[256]; #if GIFLIB_MAJOR >= 5 int ec; #endif gifdrv_memmap_ext_filename = util_add_extension_const(filename, gif_drv.default_extension); gifdrv_memmap_fd = VICE_EGifOpenFileName(gifdrv_memmap_ext_filename, 0, &ec); if (gifdrv_memmap_fd == NULL) { lib_free(gifdrv_memmap_ext_filename); return -1; } gif_colors = VICE_MakeMapObject(256, ColorMap256); for (i = 0; i < 256; i++) { gif_colors->Colors[i].Blue = palette[(i * 3) + 2]; gif_colors->Colors[i].Green = palette[(i * 3) + 1]; gif_colors->Colors[i].Red = palette[i * 3]; } #if GIFLIB_MAJOR < 5 EGifSetGifVersion("87a"); #endif if (EGifPutScreenDesc(gifdrv_memmap_fd, x_size, y_size, 8, 0, gif_colors) == GIF_ERROR || EGifPutImageDesc(gifdrv_memmap_fd, 0, 0, x_size, y_size, 0, NULL) == GIF_ERROR) { VICE_EGifCloseFile(gifdrv_memmap_fd); VICE_FreeMapObject(gif_colors); lib_free(gifdrv_memmap_ext_filename); return -1; } return 0; }
static int iffdrv_open_memmap(const char *filename, int x_size, int y_size, BYTE *palette) { iffdrv_memmap_ext_filename=util_add_extension_const(filename, iff_drv.default_extension); iffdrv_memmap_fd = fopen(iffdrv_memmap_ext_filename, "wb"); if (iffdrv_memmap_fd==NULL) { lib_free(iffdrv_memmap_ext_filename); return -1; } if (iffdrv_write_file_header_memmap(x_size, y_size, palette)<0) { fclose(iffdrv_memmap_fd); lib_free(iffdrv_memmap_ext_filename); return -1; } iffdrv_memmap_iff_data = lib_malloc(iffdrv_memmap_iff_rowbytes); return 0; }
static int iffdrv_open(screenshot_t *screenshot, const char *filename) { gfxoutputdrv_data_t *sdata; if (screenshot->palette->num_entries > 256) { #ifdef CELL_DEBUG printf("ERROR: Max 256 colors supported."); #endif return -1; } sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; sdata->line = 0; sdata->ext_filename=util_add_extension_const(filename, iff_drv.default_extension); sdata->fd = fopen(sdata->ext_filename, "wb"); if (sdata->fd==NULL) { lib_free(sdata->ext_filename); lib_free(sdata); return -1; } if (iffdrv_write_file_header(screenshot)<0) { fclose(sdata->fd); lib_free(sdata->ext_filename); lib_free(sdata); return -1; } sdata->data = lib_malloc(sdata->iff_rowbytes*8); sdata->iff_data = lib_malloc(sdata->iff_rowbytes); return 0; }
static int jpegdrv_open_memmap(const char *filename, int x_size, int y_size) { cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); jpegdrv_memmap_ext_filename=util_add_extension_const(filename, jpeg_drv.default_extension); jpegdrv_memmap_fd = fopen(jpegdrv_memmap_ext_filename, "wb"); if (jpegdrv_memmap_fd==NULL) { jpeg_destroy_compress(&cinfo); lib_free(jpegdrv_memmap_ext_filename); return -1; } jpeg_stdio_dest(&cinfo, jpegdrv_memmap_fd); jpegdrv_memmap_data = lib_malloc(x_size*3); cinfo.image_width = x_size; cinfo.image_height = y_size; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); return 0; }
static int pngdrv_open(screenshot_t *screenshot, const char *filename) { gfxoutputdrv_data_t *sdata; sdata = lib_malloc(sizeof(gfxoutputdrv_data_t)); screenshot->gfxoutputdrv_data = sdata; sdata->png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)NULL, NULL, NULL); if (sdata->png_ptr == NULL) { lib_free(sdata); return -1; } sdata->info_ptr = png_create_info_struct(sdata->png_ptr); if (sdata->info_ptr == NULL) { png_destroy_write_struct(&(sdata->png_ptr), (png_infopp)NULL); lib_free(sdata); return -1; } /* pngdrv.c:79: warning: ‘jmpbuf’ is deprecated (declared at /usr/include/libpng14/png.h:1096) */ /* if (setjmp(screenshot->gfxoutputdrv_data->png_ptr->jmpbuf)) { */ if (setjmp(png_jmpbuf(screenshot->gfxoutputdrv_data->png_ptr))) { png_destroy_write_struct(&(screenshot->gfxoutputdrv_data->png_ptr), &(screenshot->gfxoutputdrv_data->info_ptr)); lib_free(sdata); return -1; } sdata->ext_filename = util_add_extension_const(filename, png_drv.default_extension); sdata->fd = fopen(sdata->ext_filename, MODE_WRITE); if (sdata->fd == NULL) { lib_free(sdata->ext_filename); lib_free(sdata); return -1; } sdata->data = lib_malloc(screenshot->width * 4); png_init_io(sdata->png_ptr, sdata->fd); png_set_compression_level(sdata->png_ptr, Z_BEST_COMPRESSION); /* pngdrv.c:102: warning: ‘width’ is deprecated (declared at /usr/include/libpng14/png.h:639) pngdrv.c:103: warning: ‘height’ is deprecated (declared at /usr/include/libpng14/png.h:640) pngdrv.c:104: warning: ‘bit_depth’ is deprecated (declared at /usr/include/libpng14/png.h:651) pngdrv.c:105: warning: ‘color_type’ is deprecated (declared at /usr/include/libpng14/png.h:653) */ /* sdata->info_ptr->width = screenshot->width; sdata->info_ptr->height= screenshot->height; sdata->info_ptr->bit_depth = 8; sdata->info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; */ png_set_IHDR(sdata->png_ptr, sdata->info_ptr, screenshot->width, screenshot->height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(sdata->png_ptr, sdata->info_ptr); #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED png_set_invert_alpha(sdata->png_ptr); #endif return 0; }
/** \brief Show dialog to save a snapshot */ static void save_snapshot_dialog(void) { GtkWidget *dialog; GtkWidget *extra; GtkWidget *roms_widget; GtkWidget *disks_widget; gint response_id; int save_roms; int save_disks; dialog = gtk_file_chooser_dialog_new("Save snapshot file", ui_get_active_window(), GTK_FILE_CHOOSER_ACTION_SAVE, "Save", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_CANCEL, NULL); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), create_file_chooser_filter(file_chooser_filter_snapshot, FALSE)); /* create extras widget */ extra = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(extra), 16); disks_widget = gtk_check_button_new_with_label("Save attached disks"); roms_widget = gtk_check_button_new_with_label("Save attached ROMs"); gtk_grid_attach(GTK_GRID(extra), disks_widget, 0, 0, 1, 1); gtk_grid_attach(GTK_GRID(extra), roms_widget, 1, 0, 1, 1); gtk_widget_show_all(extra); gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), extra); response_id = gtk_dialog_run(GTK_DIALOG(dialog)); save_roms = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(roms_widget)); save_disks = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(disks_widget)); debug_gtk3("response_id = %d.", response_id); debug_gtk3("save disks = %s.", save_disks ? "YES" : "NO"); debug_gtk3("save ROMs = %s.", save_roms ? "YES" : "NO"); if (response_id == GTK_RESPONSE_ACCEPT) { gchar *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); if (filename != NULL) { char *fname_copy; char buffer[1024]; fname_copy = util_add_extension_const(filename, "vsf"); if (machine_write_snapshot(fname_copy, save_roms, save_disks, 0) < 0) { snapshot_display_error(); g_snprintf(buffer, 1024, "Failed to save snapshot '%s'", fname_copy); } else { debug_gtk3("Wrote snapshot file '%s'.", fname_copy); g_snprintf(buffer, 1024, "Saved snapshot '%s'", fname_copy); } lib_free(fname_copy); g_free(filename); } } gtk_widget_destroy(dialog); }
static int doodle_render_and_save(native_data_t *source, int compress) { FILE *fd; char *filename_ext = NULL; BYTE *filebuffer = NULL; BYTE *result = NULL; int i, j, k, l; int m = 0; int n = 0; int retval = 0; BYTE fgcolor = 0; BYTE bgcolor; BYTE colorbyte; /* allocate file buffer */ filebuffer = lib_malloc(9218); /* clear filebuffer */ memset(filebuffer, 0, 9218); /* set load addy */ filebuffer[0] = 0x00; filebuffer[1] = 0x5C; for (i = 0; i < DOODLE_SCREEN_BYTE_HEIGHT; i++) { for (j = 0; j < DOODLE_SCREEN_BYTE_WIDTH; j++) { bgcolor = 255; for (k = 0; k < 8; k++) { filebuffer[BITMAP_OFFSET + m] = 0; for (l = 0; l < 8; l++) { colorbyte = source->colormap[(i * DOODLE_SCREEN_PIXEL_WIDTH * 8) + (j * 8) + (k * DOODLE_SCREEN_PIXEL_WIDTH) + l]; if (k == 0 && l == 0) { fgcolor = colorbyte; } if (colorbyte == fgcolor) { filebuffer[BITMAP_OFFSET + m] |= (1 << (7 - l)); } else { if (colorbyte != bgcolor) { bgcolor = colorbyte; } } } m++; } filebuffer[VIDEORAM_OFFSET + n++] = ((fgcolor & 0xf) << 4) | (bgcolor & 0xf); } } if (compress) { filename_ext = util_add_extension_const(source->filename, doodle_compressed_drv.default_extension); } else { filename_ext = util_add_extension_const(source->filename, doodle_drv.default_extension); } fd = fopen(filename_ext, MODE_WRITE); if (fd == NULL) { retval = -1; } if (retval != -1) { if (compress) { result = lib_malloc(9218); j = 0; i = 2; result[j++] = 0; result[j++] = 0x5C; while (i < 9214) { if (filebuffer[i] == filebuffer[i + 1] && filebuffer[i] == filebuffer[i + 2] && filebuffer[i] == filebuffer[i + 3]) { result[j++] = 0xFE; result[j] = filebuffer[i]; k = 4; i += 4; while (k != 0xFF && i < 9218 && result[j] == filebuffer[i]) { i++; k++; } j++; result[j++] = k; } else { if (filebuffer[i] == 0xFE) { result[j++] = 0xFE; result[j++] = 0xFE; result[j++] = 0x01; } else { result[j++] = filebuffer[i++]; } } } while (i < 9218) { result[j++] = filebuffer[i++]; } if (fwrite(result, j, 1, fd) < 1) { retval = -1; } } else { if (fwrite(filebuffer, 9218, 1, fd) < 1) { retval = -1; } } } if (fd != NULL) { fclose(fd); } lib_free(source->colormap); lib_free(source); lib_free(filename_ext); lib_free(filebuffer); lib_free(result); return retval; }