void save_screen_snapshot_as(void *fp,struct osd_bitmap *bitmap) { if (Machine->drv->video_attributes & VIDEO_TYPE_VECTOR) png_write_bitmap(fp,bitmap); else { struct osd_bitmap *copy; int sizex, sizey, scalex, scaley; sizex = Machine->visible_area.max_x - Machine->visible_area.min_x + 1; sizey = Machine->visible_area.max_y - Machine->visible_area.min_y + 1; scalex = 1; scaley = (Machine->drv->video_attributes & VIDEO_PIXEL_ASPECT_RATIO_1_2) ? 2 : 1; copy = bitmap_alloc_depth(sizex * scalex,sizey * scaley,bitmap->depth); if (copy) { copyrozbitmap(copy,bitmap, Machine->visible_area.min_x << 16,Machine->visible_area.min_y << 16, 0x10000 / scalex,0,0,0x10000 / scaley, /* zoom, no rotation */ 0, /* no wraparound */ 0,TRANSPARENCY_NONE,0,0); png_write_bitmap(fp,copy); bitmap_free(copy); } } }
void video_manager::save_snapshot(screen_device *screen, emu_file &file) { // validate assert(!m_snap_native || screen != nullptr); // create the bitmap to pass in create_snapshot_bitmap(screen); // add two text entries describing the image std::string text1 = std::string(emulator_info::get_appname()).append(" ").append(build_version); std::string text2 = std::string(machine().system().manufacturer).append(" ").append(machine().system().description); png_info pnginfo = { nullptr }; png_add_text(&pnginfo, "Software", text1.c_str()); png_add_text(&pnginfo, "System", text2.c_str()); // now do the actual work const rgb_t *palette = (screen != nullptr && screen->has_palette()) ? screen->palette().palette()->entry_list_adjusted() : nullptr; int entries = (screen != nullptr && screen->has_palette()) ? screen->palette().entries() : 0; png_error error = png_write_bitmap(file, &pnginfo, m_snap_bitmap, entries, palette); if (error != PNGERR_NONE) osd_printf_error("Error generating PNG for snapshot: png_error = %d\n", error); // free any data allocated png_free(&pnginfo); }
void gr_opengl_print_screen(const char *filename) { char tmp[MAX_PATH_LEN]; GLubyte *pixels = NULL; GLuint pbo = 0; // save to a "screenshots" directory and tack on the filename snprintf(tmp, MAX_PATH_LEN-1, "screenshots/%s.png", filename); _mkdir(os_get_config_path("screenshots").c_str()); // glReadBuffer(GL_FRONT); // now for the data if (Use_PBOs) { Assert( !pbo ); glGenBuffers(1, &pbo); if ( !pbo ) { return; } glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, (gr_screen.max_w * gr_screen.max_h * 4), NULL, GL_STATIC_READ); glReadBuffer(GL_FRONT); glReadPixels(0, 0, gr_screen.max_w, gr_screen.max_h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); // map the image data so that we can save it to file pixels = (GLubyte*) glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); } else { pixels = (GLubyte*) vm_malloc(gr_screen.max_w * gr_screen.max_h * 4, memory::quiet_alloc); if (pixels == NULL) { return; } glReadPixels(0, 0, gr_screen.max_w, gr_screen.max_h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); glFlush(); } if (!png_write_bitmap(os_get_config_path(tmp).c_str(), gr_screen.max_w, gr_screen.max_h, true, pixels)) { ReleaseWarning(LOCATION, "Failed to write screenshot to \"%s\".", os_get_config_path(tmp).c_str()); } if (pbo) { glUnmapBuffer(GL_PIXEL_PACK_BUFFER); pixels = NULL; glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glDeleteBuffers(1, &pbo); } if (pixels != NULL) { vm_free(pixels); } }
void iq151_minigraf_device::device_stop() { #if DUMP_PAPER_INTO_PNG emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); file_error filerr = file.open("iq151_minigraf.png"); if (filerr == FILERR_NONE) { static const rgb_t png_palette[] = { RGB_WHITE, RGB_BLACK }; // save the paper into a png png_write_bitmap(file, NULL, *m_paper, 2, png_palette); } #endif }
void iq151_ms151a_device::device_stop() { #if DUMP_PAPER_INTO_PNG emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); osd_file::error filerr = file.open("iq151_ms151a.png"); if (filerr == osd_file::error::NONE) { static const rgb_t png_palette[] = { rgb_t::white, rgb_t::black }; // save the paper into a png png_write_bitmap(file, NULL, *m_paper, 2, png_palette); } #endif }
void video_manager::save_snapshot(screen_device *screen, emu_file &file) { // validate assert(!m_snap_native || screen != NULL); // create the bitmap to pass in create_snapshot_bitmap(screen); // add two text entries describing the image astring text1(emulator_info::get_appname(), " ", build_version); astring text2(machine().system().manufacturer, " ", machine().system().description); png_info pnginfo = { 0 }; png_add_text(&pnginfo, "Software", text1); png_add_text(&pnginfo, "System", text2); // now do the actual work const rgb_t *palette = (machine().palette != NULL) ? palette_entry_list_adjusted(machine().palette) : NULL; png_error error = png_write_bitmap(file, &pnginfo, m_snap_bitmap, machine().total_colors(), palette); if (error != PNGERR_NONE) mame_printf_error("Error generating PNG for snapshot: png_error = %d\n", error); // free any data allocated png_free(&pnginfo); }
static int generate_png_diff(const summary_file *curfile, std::string &destdir, const char *destname) { bitmap_argb32 bitmaps[MAX_COMPARES]; std::string srcimgname; std::string dstfilename; std::string tempname; bitmap_argb32 finalbitmap; int width, height, maxwidth; int bitmapcount = 0; int listnum, bmnum; util::core_file::ptr file; osd_file::error filerr; png_error pngerr; int error = -1; int starty; /* generate the common source filename */ dstfilename = string_format("%s" PATH_SEPARATOR "%s", destdir.c_str(), destname); srcimgname = string_format("snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name); /* open and load all unique bitmaps */ for (listnum = 0; listnum < list_count; listnum++) if (curfile->matchbitmap[listnum] == listnum) { tempname = string_format("%s" PATH_SEPARATOR "%s", lists[listnum].dir, srcimgname.c_str()); /* open the source image */ filerr = util::core_file::open(tempname, OPEN_FLAG_READ, file); if (filerr != osd_file::error::NONE) goto error; /* load the source image */ pngerr = png_read_bitmap(*file, bitmaps[bitmapcount++]); file.reset(); if (pngerr != PNGERR_NONE) goto error; } /* if there's only one unique bitmap, skip it */ if (bitmapcount <= 1) goto error; /* determine the size of the final bitmap */ height = width = 0; maxwidth = bitmaps[0].width(); for (bmnum = 1; bmnum < bitmapcount; bmnum++) { int curwidth; /* determine the maximal width */ maxwidth = std::max(maxwidth, bitmaps[bmnum].width()); curwidth = bitmaps[0].width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth; width = std::max(width, curwidth); /* add to the height */ height += std::max(bitmaps[0].height(), bitmaps[bmnum].height()); if (bmnum != 1) height += BITMAP_SPACE; } /* allocate the final bitmap */ finalbitmap.allocate(width, height); /* now copy and compare each set of bitmaps */ starty = 0; for (bmnum = 1; bmnum < bitmapcount; bmnum++) { bitmap_argb32 &bitmap1 = bitmaps[0]; bitmap_argb32 &bitmap2 = bitmaps[bmnum]; int curheight = std::max(bitmap1.height(), bitmap2.height()); int x, y; /* iterate over rows in these bitmaps */ for (y = 0; y < curheight; y++) { UINT32 *src1 = (y < bitmap1.height()) ? &bitmap1.pix32(y) : nullptr; UINT32 *src2 = (y < bitmap2.height()) ? &bitmap2.pix32(y) : nullptr; UINT32 *dst1 = &finalbitmap.pix32(starty + y, 0); UINT32 *dst2 = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE); UINT32 *dstdiff = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE); /* now iterate over columns */ for (x = 0; x < maxwidth; x++) { int pix1 = -1, pix2 = -2; if (src1 != nullptr && x < bitmap1.width()) pix1 = dst1[x] = src1[x]; if (src2 != nullptr && x < bitmap2.width()) pix2 = dst2[x] = src2[x]; dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000; } } /* update the starting Y position */ starty += BITMAP_SPACE + std::max(bitmap1.height(), bitmap2.height()); } /* write the final PNG */ filerr = util::core_file::open(dstfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file); if (filerr != osd_file::error::NONE) goto error; pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr); file.reset(); if (pngerr != PNGERR_NONE) goto error; /* if we get here, we are error free */ error = 0; error: if (error) osd_file::remove(dstfilename); return error; }
static int generate_png_diff(const summary_file *curfile, const astring *destdir, const char *destname) { bitmap_t *bitmaps[MAX_COMPARES] = { NULL }; astring *srcimgname = astring_alloc(); astring *dstfilename = astring_alloc(); astring *tempname = astring_alloc(); bitmap_t *finalbitmap = NULL; int width, height, maxwidth; int bitmapcount = 0; int listnum, bmnum; core_file *file = NULL; file_error filerr; png_error pngerr; int error = -1; int starty; /* generate the common source filename */ astring_printf(dstfilename, "%s" PATH_SEPARATOR "%s", astring_c(destdir), destname); astring_printf(srcimgname, "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name); /* open and load all unique bitmaps */ for (listnum = 0; listnum < list_count; listnum++) if (curfile->matchbitmap[listnum] == listnum) { astring_printf(tempname, "%s" PATH_SEPARATOR "%s", lists[listnum].dir, astring_c(srcimgname)); /* open the source image */ filerr = core_fopen(astring_c(tempname), OPEN_FLAG_READ, &file); if (filerr != FILERR_NONE) goto error; /* load the source image */ pngerr = png_read_bitmap(file, &bitmaps[bitmapcount++]); core_fclose(file); if (pngerr != PNGERR_NONE) goto error; } /* if there's only one unique bitmap, skip it */ if (bitmapcount <= 1) goto error; /* determine the size of the final bitmap */ height = width = 0; maxwidth = bitmaps[0]->width; for (bmnum = 1; bmnum < bitmapcount; bmnum++) { int curwidth; /* determine the maximal width */ maxwidth = MAX(maxwidth, bitmaps[bmnum]->width); curwidth = bitmaps[0]->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth; width = MAX(width, curwidth); /* add to the height */ height += MAX(bitmaps[0]->height, bitmaps[bmnum]->height); if (bmnum != 1) height += BITMAP_SPACE; } /* allocate the final bitmap */ finalbitmap = bitmap_alloc(width, height, BITMAP_FORMAT_ARGB32); if (finalbitmap == NULL) goto error; /* now copy and compare each set of bitmaps */ starty = 0; for (bmnum = 1; bmnum < bitmapcount; bmnum++) { bitmap_t *bitmap1 = bitmaps[0]; bitmap_t *bitmap2 = bitmaps[bmnum]; int curheight = MAX(bitmap1->height, bitmap2->height); int x, y; /* iterate over rows in these bitmaps */ for (y = 0; y < curheight; y++) { UINT32 *src1 = (y < bitmap1->height) ? BITMAP_ADDR32(bitmap1, y, 0) : NULL; UINT32 *src2 = (y < bitmap2->height) ? BITMAP_ADDR32(bitmap2, y, 0) : NULL; UINT32 *dst1 = BITMAP_ADDR32(finalbitmap, starty + y, 0); UINT32 *dst2 = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE); UINT32 *dstdiff = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE); /* now iterate over columns */ for (x = 0; x < maxwidth; x++) { int pix1 = -1, pix2 = -2; if (src1 != NULL && x < bitmap1->width) pix1 = dst1[x] = src1[x]; if (src2 != NULL && x < bitmap2->width) pix2 = dst2[x] = src2[x]; dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000; } } /* update the starting Y position */ starty += BITMAP_SPACE + MAX(bitmap1->height, bitmap2->height); } /* write the final PNG */ filerr = core_fopen(astring_c(dstfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); if (filerr != FILERR_NONE) goto error; pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL); core_fclose(file); if (pngerr != PNGERR_NONE) goto error; /* if we get here, we are error free */ error = 0; error: if (finalbitmap != NULL) bitmap_free(finalbitmap); for (bmnum = 0; bmnum < bitmapcount; bmnum++) if (bitmaps[bmnum] != NULL) bitmap_free(bitmaps[bmnum]); if (error) osd_rmfile(astring_c(dstfilename)); astring_free(dstfilename); astring_free(srcimgname); astring_free(tempname); return error; }
static int generate_png_diff(const astring& imgfile1, const astring& imgfile2, const astring& outfilename) { bitmap_argb32 bitmap1; bitmap_argb32 bitmap2; bitmap_argb32 finalbitmap; int width, height, maxwidth; core_file *file = NULL; file_error filerr; png_error pngerr; int error = 100; bool bitmaps_differ; int x, y; /* open the source image */ filerr = core_fopen(imgfile1, OPEN_FLAG_READ, &file); if (filerr != FILERR_NONE) { printf("Could not open %s (%d)\n", imgfile1.cstr(), filerr); goto error; } /* load the source image */ pngerr = png_read_bitmap(file, bitmap1); core_fclose(file); if (pngerr != PNGERR_NONE) { printf("Could not read %s (%d)\n", imgfile1.cstr(), pngerr); goto error; } /* open the source image */ filerr = core_fopen(imgfile2, OPEN_FLAG_READ, &file); if (filerr != FILERR_NONE) { printf("Could not open %s (%d)\n", imgfile2.cstr(), filerr); goto error; } /* load the source image */ pngerr = png_read_bitmap(file, bitmap2); core_fclose(file); if (pngerr != PNGERR_NONE) { printf("Could not read %s (%d)\n", imgfile2.cstr(), pngerr); goto error; } /* if the sizes are different, we differ; otherwise start off assuming we are the same */ bitmaps_differ = (bitmap2.width() != bitmap1.width() || bitmap2.height() != bitmap1.height()); /* compare scanline by scanline */ for (y = 0; y < bitmap2.height() && !bitmaps_differ; y++) { UINT32 *base = &bitmap1.pix32(y); UINT32 *curr = &bitmap2.pix32(y); /* scan the scanline */ for (x = 0; x < bitmap2.width(); x++) if (*base++ != *curr++) break; bitmaps_differ = (x != bitmap2.width()); } if (bitmaps_differ) { /* determine the size of the final bitmap */ height = width = 0; { /* determine the maximal width */ maxwidth = MAX(bitmap1.width(), bitmap2.width()); width = bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth; /* add to the height */ height += MAX(bitmap1.height(), bitmap2.height()); } /* allocate the final bitmap */ finalbitmap.allocate(width, height); /* now copy and compare each set of bitmaps */ int curheight = MAX(bitmap1.height(), bitmap2.height()); /* iterate over rows in these bitmaps */ for (y = 0; y < curheight; y++) { UINT32 *src1 = (y < bitmap1.height()) ? &bitmap1.pix32(y) : NULL; UINT32 *src2 = (y < bitmap2.height()) ? &bitmap2.pix32(y) : NULL; UINT32 *dst1 = &finalbitmap.pix32(y); UINT32 *dst2 = &finalbitmap.pix32(y, bitmap1.width() + BITMAP_SPACE); UINT32 *dstdiff = &finalbitmap.pix32(y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE); /* now iterate over columns */ for (x = 0; x < maxwidth; x++) { int pix1 = -1, pix2 = -2; if (src1 != NULL && x < bitmap1.width()) pix1 = dst1[x] = src1[x]; if (src2 != NULL && x < bitmap2.width()) pix2 = dst2[x] = src2[x]; dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000; } } /* write the final PNG */ filerr = core_fopen(outfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); if (filerr != FILERR_NONE) { printf("Could not open %s (%d)\n", outfilename.cstr(), filerr); goto error; } pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL); core_fclose(file); if (pngerr != PNGERR_NONE) { printf("Could not write %s (%d)\n", outfilename.cstr(), pngerr); goto error; } } /* if we get here, we are error free */ if (bitmaps_differ) error = 1; else error = 0; error: if (error == -1) osd_rmfile(outfilename); return error; }