def get_image(image, hotspot=None, mode=None, border=None): """Load an image from the given path The image is cached and the same Image instance is returned on subsequent calls. """ self = Opioid2D.ResourceManager if isinstance(image, type) and issubclass(image, Image): image = image() # begin PIG hack! elif isinstance(image, tuple): gridkey = image # (filename, height, width, frame#) image = Image() image.filename = gridkey # str(gridkey) try: return self.images[image] except KeyError: frames = self.get_grid( *gridkey[0:3]) framenum = 0 for img in frames: # cache all frames key = gridkey[0:3] + (framenum,) img.filename = key #str(key) self._set_image( key, img) framenum += 1 elif not isinstance(image, Image): filename = image image = Image() image.filename = filename if mode or hotspot or border: image = image.copy() if hotspot is not None: image.hotspot = hotspot if mode is not None: image.mode = mode if border is not None: image.border = border if isinstance(image.mode, basestring): image.mode = [image.mode] try: return self.images[image] except KeyError: if not image.filename: raise ValueError("no filename specified in Image definition for %s" % image.__class__.__name__) bmp = self._load_bitmap(image.filename) for mod in image.mode: try: func = getattr(transform, "make_"+mod) except AttributeError: raise ValueError("invalid Image mode: %r" % mod) bmp = bmp.transform(func) img = self._set_image(image, bmp, hotspot=image.hotspot, border=image.border) img._cObj.hotspot.set(*image.hotspot) for c in image.collision: img.add_collision_node(*c) return img
def get_image(self, image, hotspot=None, mode=None, border=None): """Load an image from the given path The image is cached and the same Image instance is returned on subsequent calls. """ if isinstance(image, type) and issubclass(image, Image): image = image() elif not isinstance(image, Image): filename = image image = Image() image.filename = filename if mode or hotspot or border: image = image.copy() if hotspot is not None: image.hotspot = hotspot if mode is not None: image.mode = mode if border is not None: image.border = border if isinstance(image.mode, basestring): image.mode = [image.mode] try: return self.images[image] except KeyError: if not image.filename: raise ValueError( "no filename specified in Image definition for %s" % image.__class__.__name__) bmp = self._load_bitmap(image.filename) for mod in image.mode: try: func = getattr(transform, "make_" + mod) except AttributeError: raise ValueError("invalid Image mode: %r" % mod) bmp = bmp.transform(func) img = self._set_image(image, bmp, hotspot=image.hotspot, border=image.border) img._cObj.hotspot.set(*image.hotspot) for c in image.collision: img.add_collision_node(*c) return img
def get_image(self, image, hotspot=None, mode=None, border=None): """Load an image from the given path The image is cached and the same Image instance is returned on subsequent calls. """ if isinstance(image, type) and issubclass(image, Image): image = image() elif not isinstance(image, Image): filename = image image = Image() image.filename = filename if mode or hotspot or border: image = image.copy() if hotspot is not None: image.hotspot = hotspot if mode is not None: image.mode = mode if border is not None: image.border = border if isinstance(image.mode, basestring): image.mode = [image.mode] try: return self.images[image] except KeyError: if not image.filename: raise ValueError("no filename specified in Image definition for %s" % image.__class__.__name__) bmp = self._load_bitmap(image.filename) for mod in image.mode: try: func = getattr(transform, "make_"+mod) except AttributeError: raise ValueError("invalid Image mode: %r" % mod) bmp = bmp.transform(func) img = self._set_image(image, bmp, hotspot=image.hotspot, border=image.border) img._cObj.hotspot.set(*image.hotspot) for c in image.collision: img.add_collision_node(*c) return img