void video_manager::create_snapshot_bitmap(device_t *screen) { // select the appropriate view in our dummy target if (m_snap_native && screen != NULL) { int view_index = machine().devicelist().indexof(SCREEN, screen->tag()); assert(view_index != -1); m_snap_target->set_view(view_index); } // get the minimum width/height and set it on the target INT32 width = m_snap_width; INT32 height = m_snap_height; if (width == 0 || height == 0) m_snap_target->compute_minimum_size(width, height); m_snap_target->set_bounds(width, height); // if we don't have a bitmap, or if it's not the right size, allocate a new one if (m_snap_bitmap == NULL || width != m_snap_bitmap->width || height != m_snap_bitmap->height) { if (m_snap_bitmap != NULL) auto_free(machine(), m_snap_bitmap); m_snap_bitmap = auto_alloc(machine(), bitmap_t(width, height, BITMAP_FORMAT_RGB32)); } // render the screen there render_primitive_list &primlist = m_snap_target->get_primitives(); primlist.acquire_lock(); rgb888_draw_primitives(primlist, m_snap_bitmap->base, width, height, m_snap_bitmap->rowpixels); primlist.release_lock(); }
static void create_bitmap(running_machine *machine, int player) { int x, y; char filename[20]; rgb_t color = crosshair_colors[player]; /* if we have a bitmap and texture for this player, kill it */ global_free(global.bitmap[player]); machine->render().texture_free(global.texture[player]); emu_file crossfile(machine->options(), OPTION_CROSSHAIRPATH, OPEN_FLAG_READ); if (global.name[player][0] != 0) { /* look for user specified file */ sprintf(filename, "%s.png", global.name[player]); global.bitmap[player] = render_load_png(crossfile, NULL, filename, NULL, NULL); } else { /* look for default cross?.png in crsshair\game dir */ sprintf(filename, "cross%d.png", player + 1); global.bitmap[player] = render_load_png(crossfile, machine->gamedrv->name, filename, NULL, NULL); /* look for default cross?.png in crsshair dir */ if (global.bitmap[player] == NULL) global.bitmap[player] = render_load_png(crossfile, NULL, filename, NULL, NULL); } /* if that didn't work, use the built-in one */ if (global.bitmap[player] == NULL) { /* allocate a blank bitmap to start with */ global.bitmap[player] = global_alloc(bitmap_t(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE, BITMAP_FORMAT_ARGB32)); bitmap_fill(global.bitmap[player], NULL, MAKE_ARGB(0x00,0xff,0xff,0xff)); /* extract the raw source data to it */ for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ UINT32 *dest0 = BITMAP_ADDR32(global.bitmap[player], y, 0); UINT32 *dest1 = BITMAP_ADDR32(global.bitmap[player], CROSSHAIR_RAW_SIZE - 1 - y, 0); /* extract to two rows simultaneously */ for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) if ((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) dest0[x] = dest1[x] = MAKE_ARGB(0xff,0x00,0x00,0x00) | color; } } /* create a texture to reference the bitmap */ global.texture[player] = machine->render().texture_alloc(render_texture::hq_scale); global.texture[player]->set_bitmap(global.bitmap[player], NULL, TEXFORMAT_ARGB32); }
bitmap_t *sdl_osd_interface::font_get_bitmap(osd_font font, unicode_char chnum, INT32 &width, INT32 &xoffs, INT32 &yoffs) { TTF_Font *ttffont; bitmap_t *bitmap = (bitmap_t *)NULL; SDL_Surface *drawsurf; SDL_Color fcol = { 0xff, 0xff, 0xff }; UINT16 ustr[16]; ttffont = (TTF_Font *)font; memset(ustr,0,sizeof(ustr)); ustr[0] = (UINT16)chnum; drawsurf = TTF_RenderUNICODE_Solid(ttffont, ustr, fcol); // was nothing returned? if (drawsurf) { // allocate a MAME destination bitmap bitmap = auto_alloc(machine(), bitmap_t(drawsurf->w, drawsurf->h, BITMAP_FORMAT_ARGB32)); // copy the rendered character image into it for (int y = 0; y < bitmap->height; y++) { UINT32 *dstrow = BITMAP_ADDR32(bitmap, y, 0); UINT8 *srcrow = (UINT8 *)drawsurf->pixels; srcrow += (y * drawsurf->pitch); for (int x = 0; x < drawsurf->w; x++) { dstrow[x] = srcrow[x] ? MAKE_ARGB(0xff,0xff,0xff,0xff) : MAKE_ARGB(0x00,0xff,0xff,0xff); } } // what are these? xoffs = yoffs = 0; width = drawsurf->w; SDL_FreeSurface(drawsurf); } return bitmap; }
bitmap_t *sdl_osd_interface::font_get_bitmap(osd_font font, unicode_char chnum, INT32 &width, INT32 &xoffs, INT32 &yoffs) { UniChar uni_char; CGGlyph glyph; bitmap_t *bitmap = (bitmap_t *)NULL; CTFontRef ct_font = (CTFontRef)font; const CFIndex count = 1; CGRect bounding_rect, success_rect; CGContextRef context_ref; if( chnum == ' ' ) { uni_char = 'n'; CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); uni_char = chnum; CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); } else { uni_char = chnum; CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); } if( CGRectEqualToRect( success_rect, CGRectNull ) == false ) { size_t bitmap_width; size_t bitmap_height; bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH); bitmap_width = bitmap_width == 0 ? 1 : bitmap_width; bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT); xoffs = yoffs = 0; width = bitmap_width; size_t bits_per_component; CGColorSpaceRef color_space; CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; color_space = CGColorSpaceCreateDeviceRGB(); bits_per_component = 8; bitmap = auto_alloc(machine(), bitmap_t(bitmap_width, bitmap_height, BITMAP_FORMAT_ARGB32)); context_ref = CGBitmapContextCreate( bitmap->base, bitmap_width, bitmap_height, bits_per_component, bitmap->rowpixels*4, color_space, bitmap_info ); if( context_ref != NULL ) { CGFontRef font_ref; font_ref = CTFontCopyGraphicsFont( ct_font, NULL ); CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) ); CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0); CGContextSetFont( context_ref, font_ref ); CGContextSetFontSize( context_ref, POINT_SIZE ); CGContextShowGlyphs( context_ref, &glyph, count ); CGFontRelease( font_ref ); CGContextRelease( context_ref ); } CGColorSpaceRelease( color_space ); } return bitmap; }
void execute(const std::string& line) { std::stringstream ls(line); char cmd; ls >> cmd; switch (cmd) { case 'I': { int w, h; ls >> w; ls >> h; m_bitmap = bitmap_t(w, h); } break; case 'C': { m_bitmap.clear(); } break; case 'S': { ls.get(); // skip whitespace std::string filename = read_line(ls); save(std::cout, filename); } break; case 'L': { int x, y; char c; ls >> x; ls >> y; ls >> c; //std::cout << "color:" << x << "," << y << "," << c << std::endl; m_bitmap.set_1(x, y, c); } break; case 'V': { int x, y1, y2; char c; ls >> x; ls >> y1; ls >> y2; ls >> c; sort_order(&y1, &y2); for (int i=y1; i<=y2; ++i) { m_bitmap.set_1(x, i, c); } } break; case 'H': { int x1, x2, y; char c; ls >> x1; ls >> x2; ls >> y; ls >> c; sort_order(&x1, &x2); for (int i=x1; i<=x2; ++i) { m_bitmap.set_1(i, y, c); } } break; case 'K': { int x1, x2, y1, y2; char c; ls >> x1; ls >> y1; ls >> x2; ls >> y2; ls >> c; for (int i=y1; i<=y2; ++i) { for (int j=x1; j<=x2; ++j) { //std::cout << "p:" << j << "," << i << std::endl; m_bitmap.set_1(j, i, c); } } } break; case 'F': { int x, y; char c; ls >> x; ls >> y; ls >> c; fill(x, y, c); } break; default: //std::cout << "unknown command:" << cmd << std::endl; break; } }