void ss_saver() { PALETTE pal; get_palette(pal); acquire_screen(); save_pcx("ss.pcx", screen, pal); release_screen(); }
void save_img(std::string filename, const Matrix<Color>& img) { std::size_t n = filename.size(); std::string extension3 = filename.substr(n-3, n); std::string extension4 = filename.substr(n-4, n); if(!extension3.compare("bmp")) { save_bmp(filename, img); } else if(!extension3.compare("gif")) { save_gif(filename, img); } else if(!extension3.compare("ico")) { save_ico(filename, img); } /*else if(!extension3.compare("jpg")) { save_jpeg(filename, img); }*/ else if(!extension3.compare("pcx")) { save_pcx(filename, img); } else if(!extension3.compare("png")) { save_png(filename, img); } else if(!extension3.compare("pbm")) { save_pbm(filename, color2bwimage(img)); } else if(!extension3.compare("pgm")) { save_pgm(filename, color2grayimage(img)); } else if(!extension3.compare("ppm")) { save_ppm(filename, img); } else if(!extension3.compare("tga")) { save_tga(filename, img); } else if(!extension4.compare("tiff")) { save_tiff(filename, img); } }
void snap(BITMAP *bmp, RGB * pal) { DIR * dd; FILE * fp; char filename[80]; int counter = 0; int done = 0; // first check if the directory exists. dd = opendir(SNAPDIR); if (dd) closedir(dd); // yup else mkdir(SNAPDIR, S_IRUSR | S_IWUSR); while (!done && counter <= 9999) { #ifdef SNAP_JPEG sprintf(filename, "%s/%s%04d.jpg", SNAPDIR, SNAPBASE, counter); #else sprintf(filename, "%s/%s%04d.pcx", SNAPDIR, SNAPBASE, counter); #endif fp = fopen(filename, "rb"); if (fp) { fclose(fp); counter++; } else { done = 1; } } if (counter <= 9999) // just in case... { #ifdef SNAP_JPEG save_jpeg(filename, bmp, pal); #else done = // GN: returns -1 save_pcx(filename, bmp, pal); if (done != 0) return; #endif } }
/*----------------------------------------------------------------------------*/ void save( const claw::graphic::image& img, const std::string& filename ) { std::cout << "== Saving pcx files ==" << std::endl; save_pcx( img, filename ); std::cout << "== Saving jpg files ==" << std::endl; save_jpeg( img, filename ); std::cout << "== Saving png files ==" << std::endl; save_png( img, filename ); std::cout << "== Saving bitmap files ==" << std::endl; save_bitmap( img, filename ); std::cout << "== Saving targa files ==" << std::endl; save_targa( img, filename ); std::cout << "== Saving xbm files ==" << std::endl; save_xbm( img, filename ); }
/* Check user interface keys */ void check_ui_keys(void) { if(check_key(KEY_TILDE)) { static const char *msg[] = {"EMU2413", "YM2413"}; if(snd.fm_which == SND_EMU2413) snd.fm_which = SND_YM2413; else snd.fm_which = SND_EMU2413; add_msg("Using %s FM sound emulator.", msg[snd.fm_which]); sound_init(); } /* Frame skip keys */ if(check_key(KEY_F1)) { frame_skip = 1; add_msg("Frame skip disabled"); }; if(check_key(KEY_F2)) { frame_skip = 2; add_msg("Frame skip set to 1"); }; if(check_key(KEY_F3)) { frame_skip = 3; add_msg("Frame skip set to 2"); }; if(check_key(KEY_F4)) { frame_skip = 4; add_msg("Frame skip set to 3"); }; /* State save/load keys */ if(check_key(KEY_F5)) { if(save_state()) add_msg("State saved to slot %d", state_slot); }; if(check_key(KEY_F6)) { state_slot = (state_slot + 1) % 10; add_msg("Slot %d", state_slot); }; if(check_key(KEY_F7)) { if(load_state()) add_msg("State loaded from slot %d", state_slot); }; /* Screen snapshot */ if(check_key(KEY_F8)) { char name[PATH_MAX]; PALETTE snap_pal; BITMAP *snap_bmp = create_bitmap_ex(option.video_depth, bitmap.viewport.w, bitmap.viewport.h); if(snap_bmp) { int i; /* Get current palette */ get_palette(snap_pal); /* Remove unused palette entries */ for(i = 0x20; i < 0xFE; i++) snap_pal[i].r = snap_pal[i].g = snap_pal[i].b = 0x00; /* Clip image */ blit(sms_bmp, snap_bmp, bitmap.viewport.x, bitmap.viewport.y, 0, 0, bitmap.viewport.w, bitmap.viewport.h); /* Generate file name */ sprintf(name, "snap%04d.pcx", snap_count); /* Remove unused bits */ if(option.video_depth == 8) { int x, y; for(y = 0; y < bitmap.viewport.h; y++) for(x = 0; x < bitmap.viewport.w; x++) putpixel(snap_bmp, x, y, getpixel(snap_bmp, bitmap.viewport.x + x, bitmap.viewport.y + y) & PIXEL_MASK); } /* Save snapshot in PCX format */ save_pcx(name, snap_bmp, snap_pal); /* Deallocate temporary bitmap */ destroy_bitmap(snap_bmp); /* Bump snapshot counter */ snap_count = (snap_count + 1) & 0xFFFF; /* Display results */ add_msg("Saved screen to %s", name); } } /* FPS meter toggle */ if(check_key(KEY_F9)) { option.fps ^= 1; add_msg("FPS meter %s", option.fps ? "on" : "off"); } /* Speed throttling */ if(check_key(KEY_F10)) { if(!option.sound) { option.throttle ^= 1; add_msg("Speed throttling %s", option.throttle ? "on" : "off"); } } /* Speed throttling */ if(check_key(KEY_F11)) { option.vsync ^= 1; add_msg("VSync %s", option.vsync ? "on" : "off"); } /* Exit keys */ if(key[KEY_ESC] || key[KEY_END]) running = 0; }
// ========================================================================== int main(int argc, char * argv[]) { BLOCK_S * block_ptr=NULL; BITMAP * pcxbmp = NULL; FILE * in, * out; char strtmp[256], pcxfilename[256], * ptr; long b, t, w, h; enum {PT_FA, PT_FS, PT_WU, PT_WD, PT_MAX}; int pcx_idx, i; struct { char * name; long w; long h; int col; } pcx[PT_MAX]; // header & syntaxe printf("DT1EXTR v 0.97 beta, by Paul Siramy, Freeware\n" "=============================================\n"); if (argc == 1) { printf("syntaxe : dt1extr <file.dt1> [-pal <file.dat>]\n"); exit(0); } // palette & atexit() if (strcmp(argv[2], "-pal") == 0) load_palette(argv[3]); else { printf("opening default palette\n "); load_palette("d2pal\\act1.dat"); } // dt1 file in = fopen(argv[1], "rb"); if (in == NULL) { printf("can't open %s\n", argv[1]); exit(1); } else printf("opening %s\n", argv[1]); read_dt1_header(in); read_blocks_headers(in); for (t=0; t<glb_block_number; t++) read_tiles_of_block(in, t); fclose(in); allegro_init(); set_color_depth(8); atexit(dt1con_exit); memset(pcx, 0, sizeof(pcx)); pcx[PT_FA].name = "fa"; // floor animated pcx[PT_FS].name = "fs"; // floor static pcx[PT_WU].name = "wu"; // walls up pcx[PT_WD].name = "wd"; // walls down ptr = argv[1]; i=strlen(ptr) - 1; while ((i >= 0) && ( * (ptr+i) != '\\') && ( * (ptr+i) != ':')) i--; if (i != 0) i++; strcpy(strtmp, ptr+i); strtmp[strlen(strtmp) - 4] = 0; strcat(strtmp, ".ini"); out = fopen(strtmp, "wt"); printf("saving %s\n", strtmp); strtmp[strlen(strtmp) - 4] = 0; // start of ini fprintf(out, "nb_blocks = %li\n\n", glb_block_number); // check the size of each pcx for (b=0; b<glb_block_number; b++) { block_ptr = glb_block + b; // set some flags if ( ((block_ptr->direction == 3) && (block_ptr->orientation == 0)) || ((block_ptr->direction == 5) && (block_ptr->orientation == 15)) ) { // floor set_floor(block_ptr->f); if (block_ptr->animated) { set_animated(block_ptr->f); } else set_static(block_ptr->f); } else { // wall set_wall(block_ptr->f); if (block_ptr->orientation & 0xF0) set_wall_down(block_ptr->f); else set_wall_up(block_ptr->f); } // boxsize h = block_ptr->ysize; if (h < 0) h = - h; if (is_wall(block_ptr->f)) h += 32; // 1 worldstone down wall need more border w = block_ptr->xsize; // place the block in the pcx pcx_idx = -1; if (is_floor(block_ptr->f)) { h = 80; if (is_static(block_ptr->f)) pcx_idx = PT_FS; else if (is_animated(block_ptr->f)) pcx_idx = PT_FA; } else if (is_wall(block_ptr->f)) { if (is_wall_up(block_ptr->f)) pcx_idx = PT_WU; else if (is_wall_down(block_ptr->f)) pcx_idx = PT_WD; } if (pcx_idx != -1) { block_ptr->pcx_n = pcx_idx; block_ptr->pcx_x = pcx[pcx_idx].w; if ( (pcx_idx == PT_FA) || (pcx_idx == PT_FS) ) { block_ptr->pcx_y = 80 * (block_ptr->pcx_x / 800); block_ptr->pcx_x = block_ptr->pcx_x % 800; } pcx[pcx_idx].w += 160; if (pcx[pcx_idx].h < h) pcx[pcx_idx].h = h; pcx[pcx_idx].col++; // ini fprintf(out, "block = %li\n", b); fprintf(out, "pcx_file = %s\n", pcx[pcx_idx].name); fprintf(out, "pcx_x = %i\n", block_ptr->pcx_x); fprintf(out, "pcx_y = %i\n", block_ptr->pcx_y); fprintf(out, "direction = %08lX\n", block_ptr->direction); // fprintf(out, "flags = %08lX\n", block_ptr->flags); fprintf(out, "y_delta = %i\n", block_ptr->y_delta); fprintf(out, "tile_sound = %i\n", block_ptr->tile_sound); fprintf(out, "animated = %i\n", block_ptr->animated); fprintf(out, "orientation = %08lX\n", block_ptr->orientation); fprintf(out, "main_index = %08lX\n", block_ptr->main_index); fprintf(out, "sub_index = %08lX\n", block_ptr->sub_index); fprintf(out, "frame = %08lX\n", block_ptr->frame); fprintf(out, "unknown = %08lX\n", block_ptr->unknown); fprintf(out, "floor_flag1 = %02X %02X %02X %02X %02X\n", block_ptr->sub_tiles_flags[20], block_ptr->sub_tiles_flags[21], block_ptr->sub_tiles_flags[22], block_ptr->sub_tiles_flags[23], block_ptr->sub_tiles_flags[24] ); fprintf(out, "floor_flag2 = %02X %02X %02X %02X %02X\n", block_ptr->sub_tiles_flags[15], block_ptr->sub_tiles_flags[16], block_ptr->sub_tiles_flags[17], block_ptr->sub_tiles_flags[18], block_ptr->sub_tiles_flags[19] ); fprintf(out, "floor_flag3 = %02X %02X %02X %02X %02X\n", block_ptr->sub_tiles_flags[10], block_ptr->sub_tiles_flags[11], block_ptr->sub_tiles_flags[12], block_ptr->sub_tiles_flags[13], block_ptr->sub_tiles_flags[14] ); fprintf(out, "floor_flag4 = %02X %02X %02X %02X %02X\n", block_ptr->sub_tiles_flags[5], block_ptr->sub_tiles_flags[6], block_ptr->sub_tiles_flags[7], block_ptr->sub_tiles_flags[8], block_ptr->sub_tiles_flags[9] ); fprintf(out, "floor_flag5 = %02X %02X %02X %02X %02X\n", block_ptr->sub_tiles_flags[0], block_ptr->sub_tiles_flags[1], block_ptr->sub_tiles_flags[2], block_ptr->sub_tiles_flags[3], block_ptr->sub_tiles_flags[4] ); fprintf(out, "\n"); } } for (i=0; i<PT_MAX; i++) { if (pcx[i].w > 0) { if ((i == PT_FA) || (i == PT_FS)) { if (pcx[i].w > 800) { pcx[i].h = 80 * (1 + pcx[i].w / 800); pcx[i].w = 800; } } pcxbmp = create_bitmap(pcx[i].w, pcx[i].h); clear(pcxbmp); if (pcxbmp != NULL) { for (b=0; b<glb_block_number; b++) { block_ptr = glb_block + b; if (block_ptr->pcx_n == i) { if (is_floor(block_ptr->f)) draw_block(pcxbmp, block_ptr->pcx_x, block_ptr->pcx_y, b); else { if (is_wall_up(block_ptr->f)) draw_block(pcxbmp, block_ptr->pcx_x, pcx[i].h, b); else draw_block(pcxbmp, block_ptr->pcx_x, 96, b); } } } } sprintf(pcxfilename, "%s-%s.pcx", strtmp, pcx[i].name); printf("saving %s\n", pcxfilename); save_pcx(pcxfilename, pcxbmp, & the_pal); destroy_bitmap(pcxbmp); } } fclose(out); // end printf("done\n"); return 0; }
int main(void) { allegro_init(); install_keyboard(); install_mouse(); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); buffer = create_bitmap(640, 480); vpic[0] = load_pcx("antivirus.dat#virus_red.pcx", pal); vpic[1] = load_pcx("antivirus.dat#virus_yellow.pcx", NULL); vpic[2] = load_pcx("antivirus.dat#virus_blue.pcx", NULL); map = create_bitmap(8, 16); clear_bitmap(map); set_palette(pal); set_mouse_sprite(NULL); while(!done) { if(key[KEY_ESC]) { done = 1; } if(key[KEY_1]) { virus = 16; } else if(key[KEY_2]) { virus = 17; } else if(key[KEY_3]) { virus = 18; } if(key[KEY_F2]) { if(file_select_ex("Save:", filename, "pcx", 1024, 320, 240)) { save_pcx(filename, map, pal); } clear_keybuf(); } if(key[KEY_F3]) { if(file_select_ex("Load:", filename, "pcx", 1024, 320, 240)) { destroy_bitmap(map); map = load_pcx(filename, NULL); } clear_keybuf(); } mx = mouse_x; my = mouse_y; if(mouse_b & 1 && mx / 16 < 8 && my / 16 < 16) { map->line[my / 16][mx / 16] = virus; } else if(mouse_b & 2 && mx / 16 < 8 && my / 16 < 16) { map->line[my / 16][mx / 16] = 0; } clear_bitmap(buffer); for(int i = 0; i < 16; i++) { for(int j = 0; j < 8; j++) { if(map->line[i][j]) { draw_sprite(buffer, vpic[map->line[i][j] - 16], j * 16, i * 16); } } } draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h); } return 0; }
int main(int argc, char *argv[]) { /* default values for -f, -i, -r, -c, -b, -g */ char *fontname = "*"; char *filename = "font.pcx"; int start_char = 32, end_char = 255; int ccolor = 000000000; int bcolor = 255255255; int gcolor = 255000255; /* X11 variables */ Display *display; int screen_number; int default_depth; Window window; Font font; GC gc, gc2; Pixmap pixmap; XImage *image; XCharStruct overall; /* misc variables */ int bitmap_width, bitmap_height; int max_ascent, max_descent; int max_width, max_height; int i, opt, x, y, cx, cy, sx, sy, lines; unsigned long black, white; BITMAP *bitmap; RGB palette[256]; /* show usage if no options */ if (argc == 1) { usage(argv[0]); exit(EXIT_SUCCESS); } /* only to access bitmap operations */ install_allegro(SYSTEM_NONE, &errno, atexit); /* parse options */ opterr = 0; while ((opt = getopt(argc, argv, "f:o:z:c:b:g:r:h")) != EOF) { switch (opt) { case 'f': fontname = optarg; break; case 'o': filename = optarg; break; case 'c': ccolor = atol(optarg); break; case 'b': bcolor = atol(optarg); break; case 'g': gcolor = atol(optarg); break; case 'r': { char *str; start_char = strtol(optarg, &str, 0); end_char = strtol(str + 1, NULL, 0); break; } case 'h': usage(argv[0]); exit(EXIT_SUCCESS); default: fprintf(stderr, "%s: unrecognized option -- '%c'\n", argv[0], optopt); fprintf(stderr, "%s: try '%s -h' for more information\n", argv[0], argv[0]); exit(EXIT_FAILURE); } } /* open display */ display = XOpenDisplay(0); if (display == 0) { fprintf(stderr, "%s: XOpenDisplay failed\n", argv[0]); exit(EXIT_FAILURE); } /* default screen number and window */ screen_number = XDefaultScreen(display); default_depth = XDefaultDepth(display, screen_number); window = XDefaultRootWindow(display); /* load font */ font = XLoadFont(display, fontname); /* create gcs */ { unsigned long val_mask; XGCValues val_bits; val_mask = GCForeground | GCBackground | GCFont | GCFunction; val_bits.function = GXcopy; val_bits.foreground = white = WhitePixel(display, screen_number); val_bits.background = black = BlackPixel(display, screen_number); val_bits.font = font; gc = XCreateGC(display, window, val_mask, &val_bits); val_mask = GCForeground; val_bits.foreground = black; gc2 = XCreateGC(display, window, val_mask, &val_bits); } /* query font ascent and descent */ { XFontStruct *xfs; int min, max; xfs = XQueryFont(display, font); max_ascent = xfs->ascent; max_descent = xfs->descent; if (xfs->min_byte1 == 0 && xfs->max_byte1 == 0) { min = xfs->min_char_or_byte2; max = xfs->max_char_or_byte2; } else { min = (xfs->min_byte1 << 8) + xfs->min_char_or_byte2; max = (xfs->max_byte1 << 8) + xfs->max_char_or_byte2; } if (start_char < min || end_char > max) fprintf(stderr, "You specified characters %04x-%04x, but this font " "only has the range %04x-%04x\n", start_char, end_char, min, max); XFreeFontInfo(NULL, xfs, 0); } /* calculate bitmap width and maximum ascent and descent of characters * (can exceed the font ascent/descent queried above!) */ max_width = 0; lines = 1 + (end_char - start_char) / 16; for (cy = 0; cy < lines; cy++) { for (cx = 0; cx < 16 && start_char + cy * 16 + cx <= end_char; cx++) { int dir, ascent, descent; int width; XChar2b string[2] = { {0, 0}, {0, 0} }; /* query character size */ string[0].byte1 = (start_char + cy * 16 + cx) >> 8; string[0].byte2 = (start_char + cy * 16 + cx) & 255; XQueryTextExtents16(display, font, string, 1, &dir, &ascent, &descent, &overall); width = overall.width; if (width < 1) width = 1; if (width > max_width) max_width = width; if (max_ascent < overall.ascent) max_ascent = overall.ascent; if (max_descent < overall.descent) max_descent = overall.descent; } } max_height = max_ascent + max_descent; bitmap_width = (max_width + 1) * 16 + 1; bitmap_height = (max_height + 1) * lines + 1; /* create bitmap */ bitmap = create_bitmap(bitmap_width, bitmap_height); if (bitmap == 0) { fprintf(stderr, "%s: can not create bitmap\n", argv[0]); exit(EXIT_FAILURE); } /* fill with filler color */ clear_to_color(bitmap, 255); /* process all characters */ sy = 1; for (cy = 0; cy < lines; cy++) { sx = 1; for (cx = 0; cx < 16 && start_char + cy * 16 + cx <= end_char; cx++) { int dir, ascent, descent; XChar2b string[2] = { {0, 0}, {0, 0} }; /* query character size */ string[0].byte1 = (start_char + cy * 16 + cx) >> 8; string[0].byte2 = (start_char + cy * 16 + cx) & 255; XQueryTextExtents16(display, font, string, 1, &dir, &ascent, &descent, &overall); if (overall.width < 1) overall.width = 1; /* create pixmap and draw character there */ pixmap = XCreatePixmap(display, window, overall.width, max_height, default_depth); /* some fonts draw outside their ascent/descent, so we need to clear * the pixmap before drawing the glyph */ XFillRectangle(display, pixmap, gc2, 0, 0, overall.width, max_height); XDrawImageString16(display, pixmap, gc, 0, max_ascent, string, 1); /* create image with pixmap contents */ image = XGetImage(display, pixmap, 0, 0, overall.width, max_height, AllPlanes, ZPixmap); if (image == 0) { fprintf(stderr, "%s: can not get image\n", argv[0]); exit(EXIT_FAILURE); } /* copy image to bitmap */ for (y = 0; y < max_height; y++) for (x = 0; x < overall.width; x++) { if (XGetPixel(image, x, y) == white) putpixel(bitmap, sx + x, sy + y, 1); else putpixel(bitmap, sx + x, sy + y, 0); } XDestroyImage(image); XFreePixmap(display, pixmap); sx += max_width + 1; } sy += max_height + 1; } /* initialize palette */ for (i = 0; i < 256; i++) palette[i].r = palette[i].g = palette[i].b = 0; #define CLAMP_COL(v) (((v / 4) > 63) ? 63 : (v / 4)) palette[0].r = CLAMP_COL(bcolor / 1000000); palette[0].g = CLAMP_COL((bcolor % 1000000) / 1000); palette[0].b = CLAMP_COL(bcolor % 1000); palette[1].r = CLAMP_COL(ccolor / 1000000); palette[1].g = CLAMP_COL((ccolor % 1000000) / 1000); palette[1].b = CLAMP_COL(ccolor % 1000); palette[255].r = CLAMP_COL(gcolor / 1000000); palette[255].g = CLAMP_COL((gcolor % 1000000) / 1000); palette[255].b = CLAMP_COL(gcolor % 1000); #undef CLAMP_COL save_pcx(filename, bitmap, palette); /* clean up */ destroy_bitmap(bitmap); XFreeGC(display, gc); XFreeGC(display, gc2); XUnloadFont(display, font); XCloseDisplay(display); exit(EXIT_SUCCESS); }