def convert_raw_image (img, name): """ convert v0.3.x raw image to png image """ # -- get length and height length = img.get_uint16 () height = img.get_uint16 () print "Length = %i, Height = %i" % (length, height) png = gfx.create_surface () png.set_alpha (255, 1) png.resize (length, height) png.lock () for y in range (height): for x in range (length): a = 255 r = img.get_uint8 () g = img.get_uint8 () b = img.get_uint8 () if r == 255 and g == 0 and b == 255: a = 0 col = png.map_color (r, g, b, a) png.put_pix (x, y, col) png.unlock () # -- for debugging png.draw (320 - length/2, 240 - height/2) gfx.screen.update() base.Timer.sleep (500) # -- save image png.save_png (name + ".png") print "Saved %s.png" % name
def convert_raw_image(img, name): """ convert v0.3.x raw image to png image """ # -- get length and height length = img.get_uint16() height = img.get_uint16() print "Length = %i, Height = %i" % (length, height) png = gfx.create_surface() png.set_alpha(255, 1) png.resize(length, height) png.lock() for y in range(height): for x in range(length): a = 255 r = img.get_uint8() g = img.get_uint8() b = img.get_uint8() if r == 255 and g == 0 and b == 255: a = 0 col = png.map_color(b, g, r, a) png.put_pix(x, y, col) png.unlock() # -- for debugging png.draw(320 - length / 2, 240 - height / 2) gfx.screen.update() base.Timer.sleep(500) # -- save image png.save_png(name + ".png") print "Saved %s.png" % name
def save_screenshot (self, directory): # -- create a standard-sized view to capture a screenshot mv = mapview (640, 480) # -- get the real map view to obtain the location for our view actual_view = area_manager.get_mapview() # -- this makes sure that the view is at proper Z coordinate mv.set_position (actual_view.get_x(), actual_view.get_y(), actual_view.get_z()) # -- now actually ensure that the x and y are in the center of the view mv.center_on (actual_view.get_x(), actual_view.get_y()) # -- create a surface onto which to render the map surf = gfx.create_surface() surf.resize (640, 480) # -- render the view onto the surface mv.draw (0, 0, None, surf) # -- save the surface to disk surf.save_png(directory + "/screenshot.png") # -- cleanup surf = None mv = None
def gfxtest (): global screenshot, walkdir #setup key handler def key_callback(ev): global letsexit, walkdir, screenshot if ev.type() == input.keyboard_event.KEY_PUSHED: if ev.key() == input.keyboard_event.ESCAPE_KEY: letsexit = 1 elif ev.key() == input.keyboard_event.LEFT_KEY: walkdir = 'walk_west' elif ev.key() == input.keyboard_event.RIGHT_KEY: walkdir = 'walk_east' elif ev.key() == input.keyboard_event.UP_KEY: walkdir = 'walk_north' elif ev.key() == input.keyboard_event.DOWN_KEY: walkdir = 'walk_south' elif ev.key() == input.keyboard_event.F8_KEY: screenshot = True elif ev.type() == input.keyboard_event.KEY_RELEASED: if ev.key() == input.keyboard_event.LEFT_KEY and walkdir == 'walk_west': walkdir = "stand" + walkdir[4:] elif ev.key() == input.keyboard_event.RIGHT_KEY and walkdir == 'walk_east': walkdir = "stand" + walkdir[4:] elif ev.key() == input.keyboard_event.UP_KEY and walkdir == 'walk_north': walkdir = "stand" + walkdir[4:] elif ev.key() == input.keyboard_event.DOWN_KEY and walkdir == 'walk_south': walkdir = "stand" + walkdir[4:] return 1 if not gfx.init("sdl"): raise "Can't load gfx backend!" if not input.init("sdl"): raise "Can't load input backend!" gfx.screen.set_video_mode(640, 480) li = input.listener() li.connect_keyboard_function(key_callback) input.manager.add(li) xloc = 10 yloc = 10 #setup a 'fake' background background = gfx.create_surface() background.thisown = 0 background.resize(640,480) backgroundcolor = [ 0x000000,0xFF0000,0x00FF00,0x0000FF, 0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF, 0x7FFF00,0x007FFF,0xFF007F,0xFF7FFF] for x in xrange(4): for y in xrange(3): background.fillrect(160*x,160*y,160,160,backgroundcolor[0]) backgroundcolor = backgroundcolor[1:] #load an image... gfx must be checked out and linked image = gfx.animation() image.load_animation("gfx/character/npc/naked_guy/naked_guy.xml") count = 0 oldwalkdir = None while not letsexit: count += 1 input.manager.update() if(walkdir != oldwalkdir): oldwalkdir = walkdir image.change_animation(walkdir) background.draw(0,0) image.draw(xloc,yloc) if count == 10: image.update(); count = 0 if screenshot: print "saving screenshot to 'screenshot.png'" screenshot = False ssurface = gfx.screen.get_surface() ssurface.save_png("screenshot.png") gfx.screen.update() input.cleanup() gfx.cleanup() return 0
def gfxtest(): global screenshot, walkdir #setup key handler def key_callback(ev): global letsexit, walkdir, screenshot if ev.type() == input.keyboard_event.KEY_PUSHED: if ev.key() == input.keyboard_event.ESCAPE_KEY: letsexit = 1 elif ev.key() == input.keyboard_event.LEFT_KEY: walkdir = 'walk_west' elif ev.key() == input.keyboard_event.RIGHT_KEY: walkdir = 'walk_east' elif ev.key() == input.keyboard_event.UP_KEY: walkdir = 'walk_north' elif ev.key() == input.keyboard_event.DOWN_KEY: walkdir = 'walk_south' elif ev.key() == input.keyboard_event.F8_KEY: screenshot = True elif ev.type() == input.keyboard_event.KEY_RELEASED: if ev.key( ) == input.keyboard_event.LEFT_KEY and walkdir == 'walk_west': walkdir = "stand" + walkdir[4:] elif ev.key( ) == input.keyboard_event.RIGHT_KEY and walkdir == 'walk_east': walkdir = "stand" + walkdir[4:] elif ev.key( ) == input.keyboard_event.UP_KEY and walkdir == 'walk_north': walkdir = "stand" + walkdir[4:] elif ev.key( ) == input.keyboard_event.DOWN_KEY and walkdir == 'walk_south': walkdir = "stand" + walkdir[4:] return 1 if not gfx.init("sdl"): raise "Can't load gfx backend!" if not input.init("sdl"): raise "Can't load input backend!" gfx.screen.set_video_mode(640, 480) li = input.listener() li.connect_keyboard_function(key_callback) input.manager.add(li) xloc = 10 yloc = 10 #setup a 'fake' background background = gfx.create_surface() background.thisown = 0 background.resize(640, 480) backgroundcolor = [ 0x000000, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF, 0x7FFF00, 0x007FFF, 0xFF007F, 0xFF7FFF ] for x in xrange(4): for y in xrange(3): background.fillrect(160 * x, 160 * y, 160, 160, backgroundcolor[0]) backgroundcolor = backgroundcolor[1:] #load an image... gfx must be checked out and linked image = gfx.animation() image.load_animation("gfx/character/npc/naked_guy/naked_guy.xml") count = 0 oldwalkdir = None while not letsexit: count += 1 input.manager.update() if (walkdir != oldwalkdir): oldwalkdir = walkdir image.change_animation(walkdir) background.draw(0, 0) image.draw(xloc, yloc) if count == 10: image.update() count = 0 if screenshot: print "saving screenshot to 'screenshot.png'" screenshot = False ssurface = gfx.screen.get_surface() ssurface.save_png("screenshot.png") gfx.screen.update() input.cleanup() gfx.cleanup() return 0