void VM_fclose (int fnum, int owner) { fnum--; if (fnum < 0 || fnum >= MAX_VM_FILES) return; //out of range if (vm_fopen_files[fnum].owner != owner) return; //cgs? if (!vm_fopen_files[fnum].data) return; //not open switch(vm_fopen_files[fnum].accessmode) { case VM_FS_READ: BZ_Free(vm_fopen_files[fnum].data); break; case VM_FS_WRITE: case VM_FS_APPEND: case VM_FS_APPEND2: COM_WriteFile(vm_fopen_files[fnum].name, FS_GAMEONLY, vm_fopen_files[fnum].data, vm_fopen_files[fnum].len); BZ_Free(vm_fopen_files[fnum].data); break; } vm_fopen_files[fnum].data = NULL; }
/* ============== WritePCXfile ============== */ void WritePCXfile (char *filename, byte *data, int width, int height, int rowbytes, byte *palette) { int i, j, length; pcx_t *pcx; byte *pack; pcx = Hunk_TempAlloc (width*height*2+1000); if (pcx == NULL) { Con_Printf("SCR_ScreenShot_f: not enough memory\n"); return; } pcx->manufacturer = 0x0a; // PCX id pcx->version = 5; // 256 color pcx->encoding = 1; // uncompressed pcx->bits_per_pixel = 8; // 256 color pcx->xmin = 0; pcx->ymin = 0; pcx->xmax = LittleShort((short)(width-1)); pcx->ymax = LittleShort((short)(height-1)); pcx->hres = LittleShort((short)width); pcx->vres = LittleShort((short)height); memset (pcx->palette,0,sizeof(pcx->palette)); pcx->color_planes = 1; // chunky image pcx->bytes_per_line = LittleShort((short)width); pcx->palette_type = LittleShort(2); // not a grey scale memset (pcx->filler,0,sizeof(pcx->filler)); // pack the image pack = &pcx->data; for (i=0 ; i<height ; i++) { for (j=0 ; j<width ; j++) { if ( (*data & 0xc0) != 0xc0) *pack++ = *data++; else { *pack++ = 0xc1; *pack++ = *data++; } } data += rowbytes - width; } // write the palette *pack++ = 0x0c; // palette ID byte for (i=0 ; i<768 ; i++) *pack++ = *palette++; // write output file length = pack - (byte *)pcx; COM_WriteFile (filename, pcx, length); }
/* EDITOR: GENERATE COLORMAP * =============== * Generate a colormap for the current palette... * makes use of our builtin function for generating them */ gint VID_EditorGenerateColormap(gpointer data) { GtkWidget *dialog; GtkFileChooser *chooser; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; gint res; byte *pic; dialog = gtk_file_chooser_dialog_new ("NGUNIXEd - Save Generated Colormap (.lmp) File", NULL, action, ("_Cancel"), GTK_RESPONSE_CANCEL, ("_Save"), GTK_RESPONSE_ACCEPT, NULL); chooser = GTK_FILE_CHOOSER (dialog); gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE); // Set the default path (current directory) char path[MAX_OSPATH]; sprintf(path, "file://%s", get_current_dir_name()); gtk_file_chooser_set_current_folder_uri(chooser, path); // Add the filter for .lmp files GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*.lmp"); gtk_file_chooser_set_filter (chooser, filter); res = gtk_dialog_run (GTK_DIALOG (dialog)); if (res == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename (chooser); byte out_colormap[16384]; Con_Printf("[EDITOR] Generating colormap based on current palette...\n"); Colormap_Generate(ed_palette, out_colormap); COM_WriteFile (filename, out_colormap, 16384); g_free (filename); } gtk_widget_destroy (dialog); return 0; }
void VLight_DumpLightTable_f(void) { COM_WriteFile ("lighttable.raw", vlighttable, 256*256); }
/* EDITOR: SAVE LUMP * ================= * Saves the pic currently displayed as a lump... * This means that you can save special files, such as colormaps as regular piclumps, too! */ gint VID_EditorSaveFile(gpointer data) { GtkWidget *dialog; GtkFileChooser *chooser; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; gint res; if(!ed_file) return; dialog = gtk_file_chooser_dialog_new ("NGUNIXEd - Save LUMP (.lmp) File", NULL, action, ("_Cancel"), GTK_RESPONSE_CANCEL, ("_Save"), GTK_RESPONSE_ACCEPT, NULL); chooser = GTK_FILE_CHOOSER (dialog); gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE); // Set the default path (current directory) char path[MAX_OSPATH]; sprintf(path, "file://%s", get_current_dir_name()); gtk_file_chooser_set_current_folder_uri(chooser, path); // Add the filter for .lmp files GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*.lmp"); gtk_file_chooser_set_filter (chooser, filter); //if (user_edited_a_new_document) gtk_file_chooser_set_current_name (chooser, ("untitled.lmp")); //else // gtk_file_chooser_set_filename (chooser, // existing_filename); res = gtk_dialog_run (GTK_DIALOG (dialog)); if (res == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename (chooser); Con_Printf("[EDITOR] Saving LUMP as %s...\n", filename); #if 0 printf("Saving IMAGE: %i, %i\n", pic[0], pic[1]); for(i = 2; i < pic[0] * pic[1]+2; i++) printf("%i,", pic[i]); printf("\n...DONE\n"); #endif COM_WriteFile (filename, ed_file, ed_file->width * ed_file->height + 2); g_free (filename); // free(pic); } gtk_widget_destroy (dialog); return 0; }