def LoadFile(self, file):
		print "LoadFile", file
		#self.mng = MNG(file, output=MNG_CANVAS_RGB8_A8, read=False)
		self.mng = MNG(file, output=MNG_CANVAS_RGBA8, read=False)
		self.mng.read()

		#Animation starts paused
		self.mng.pause()

		self.SetSize(wx.Size(*self.mng.size))
	def processheader(self, width, height):
		self.initalized = True

		# Create a buffer which the library will output to
		self.image = pygame.surface.Surface((width, height)).convert(self.info.masks)
		if self.bytesperpixel*8 != self.image.get_bitsize():
			raise RuntimeError("Created surface (%s) does not have correct bitsize (%s)." % \
				(self.image.get_bitsize(), self.bytesperpixel*8))
		self.mnghelper.buffer = CPygameSurface(self.image).pixels

		OriginalMNG.processheader(self, width, height)
Esempio n. 3
0
    def processheader(self, width, height):
        self.initalized = True

        # Create a buffer which the library will output to
        self.image = pygame.surface.Surface(
            (width, height)).convert(self.info.masks)
        if self.bytesperpixel * 8 != self.image.get_bitsize():
            raise RuntimeError("Created surface (%s) does not have correct bitsize (%s)." % \
             (self.image.get_bitsize(), self.bytesperpixel*8))
        self.mnghelper.buffer = CPygameSurface(self.image).pixels

        OriginalMNG.processheader(self, width, height)
class MNGAnimationCtrl(ImagePanel):
	def __init__(self, parent, id=-1):
		ImagePanel.__init__(self, parent, id)

		self.timer = wx.Timer(self, -1)
		self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

	def Play(self):
		print "Starting Animation"
		self.mng.resume()
		wx.CallAfter(self.timer.Start, 50)

	def Stop(self):
		print "Stoping Animation"
		self.mng.pause()
		self.timer.Stop()

	def Reset(self):
		self.Stop()
		self.mng.reset()

	def LoadFile(self, file):
		print "LoadFile", file
		#self.mng = MNG(file, output=MNG_CANVAS_RGB8_A8, read=False)
		self.mng = MNG(file, output=MNG_CANVAS_RGBA8, read=False)
		self.mng.read()

		#Animation starts paused
		self.mng.pause()

		self.SetSize(wx.Size(*self.mng.size))

	def OnTimer(self, evt):
		#print "OnTimer", evt

		delay, frame = self.mng.nextframe()
		image = mng2wx(frame, self.mng.size, (self.mng.width*self.mng.height*self.mng.bitsperpixel_color/8))
		self.Display(image)
    if len(sys.argv) != 2 or sys.argv[1] in ("--help", "-h"):
        print __doc__

    fn = sys.argv[1]
    if not os.path.exists(fn):
        print "No such file found...."
        sys.exit(1)

    try:
        from mng import MNG
    except ImportError, e:
        print e
        print "The libmng library doesn't appear to work :/"
        sys.exit(1)

    a1 = MNG(sys.argv[1])
    print "filename\t\t", fn
    print "filesize\t\t", os.path.getsize(fn), "bytes"
    print "---------------------------------------"
    print "sigtype\t\t\t", a1.sigtype
    print "type\t\t\t", a1.type
    print "width\t\t\t", a1.width, "pixels"
    print "height\t\t\t", a1.height, "pixels"
    print "ticks\t\t\t", a1.ticks
    print "framecount\t\t", a1.framecount
    print "layercount\t\t", a1.layercount
    print "playtime\t\t", a1.playtime
    print "simplicity\t\t", a1.simplicity
    print "bitdepth\t\t", a1.bitdepth
    print "colortype\t\t", a1.colortype
    print "compression\t\t", a1.compression
	def __init__(self, file, surface=None):
		# Figure out the best fileformat for the library to output
		class info:
			def __str__(self):
				return "<Info b:%s m:%s s:%s l:%s>" % (self.bitsize, self.masks, self.shifts, self.losses)

		info = info()
		if surface is None:
			i = pygame.display.Info()
			info.masks = i.masks
			info.shifts = i.shifts
			info.losses = i.losses

			info.bitsize = i.bitsize
			# FIXME: Sometimes the screen info lies
			if info.masks[-1] == 0:
				info.bitsize -= 8
		else:
			info.bitsize = surface.get_bitsize()
			info.masks   = list(surface.get_masks())
			info.shifts  = surface.get_shifts()
			info.losses  = surface.get_losses()

		print info
		self.info = info

		if info.bitsize == 32:
			if info.masks[ALPHA] == 0:
				# No alpha (padding byte) 
				if info.shifts[BLUE] == 0:
					format = MNG_CANVAS_BGRX8
					sdlformat = "BGRX"
				else:
					# Red first
					print "No matching mng canvas for sdl pixel format. Colors may be wrong."
					format = MNG_CANVAS_BGRX8
					sdlformat = "BGRX"
			else:
				# Real alpha
				if info.shifts[BLUE] == 0:
					# Blue first
					format = MNG_CANVAS_BGRA8
					sdlformat = "BGRA"
				else:
					# Red first
					format = MNG_CANVAS_RGBA8
					sdlformat = "RGBA"
		elif info.bitsize == 24:
			if info.masks[ALPHA] == 0:
				# No alpha here should mean true rgb24bit
				if info.shifts[BLUE] == 0:
					# Blue first
					format = MNG_CANVAS_BGR8
					sdlformat = "BGR"
				else:
					# Red first
					format = MNG_CANVAS_RGB8
					sdlformat = "RGB"
			else:
				# If there is an alpha and we are in 24 bpp, this must mean rgb5658
				if info.shifts[BLUE] == 0:
					# Blue first
					format = MNG_CANVAS_BGRA565
					sdlformat = "BGRA"
				else:
					# Red first
					format = MNG_CANVAS_RGBA565
					sdlformat = "RGBA"
		elif info.bitsize == 16:
			if info.shifts[BLUE] == 0:
				# Blue first
				format = MNG_CANVAS_BGR565
				sdlformat = "RGB"
			else:
				# Red first
				format = MNG_CANVAS_RGB565
				sdlformat = "RGB"
		else:
			raise RuntimeError("Unable to figure out the best format for this video file.")

		print "Detected image format to be", NAMESPERPIXEL[format], sdlformat
		OriginalMNG.__init__(self, file, format)
Esempio n. 7
0
    def __init__(self, file, surface=None):
        # Figure out the best fileformat for the library to output
        class info:
            def __str__(self):
                return "<Info b:%s m:%s s:%s l:%s>" % (
                    self.bitsize, self.masks, self.shifts, self.losses)

        info = info()
        if surface is None:
            i = pygame.display.Info()
            info.masks = i.masks
            info.shifts = i.shifts
            info.losses = i.losses

            info.bitsize = i.bitsize
            # FIXME: Sometimes the screen info lies
            if info.masks[-1] == 0:
                info.bitsize -= 8
        else:
            info.bitsize = surface.get_bitsize()
            info.masks = list(surface.get_masks())
            info.shifts = surface.get_shifts()
            info.losses = surface.get_losses()

        print info
        self.info = info

        if info.bitsize == 32:
            if info.masks[ALPHA] == 0:
                # No alpha (padding byte)
                if info.shifts[BLUE] == 0:
                    format = MNG_CANVAS_BGRX8
                    sdlformat = "BGRX"
                else:
                    # Red first
                    print "No matching mng canvas for sdl pixel format. Colors may be wrong."
                    format = MNG_CANVAS_BGRX8
                    sdlformat = "BGRX"
            else:
                # Real alpha
                if info.shifts[BLUE] == 0:
                    # Blue first
                    format = MNG_CANVAS_BGRA8
                    sdlformat = "BGRA"
                else:
                    # Red first
                    format = MNG_CANVAS_RGBA8
                    sdlformat = "RGBA"
        elif info.bitsize == 24:
            if info.masks[ALPHA] == 0:
                # No alpha here should mean true rgb24bit
                if info.shifts[BLUE] == 0:
                    # Blue first
                    format = MNG_CANVAS_BGR8
                    sdlformat = "BGR"
                else:
                    # Red first
                    format = MNG_CANVAS_RGB8
                    sdlformat = "RGB"
            else:
                # If there is an alpha and we are in 24 bpp, this must mean rgb5658
                if info.shifts[BLUE] == 0:
                    # Blue first
                    format = MNG_CANVAS_BGRA565
                    sdlformat = "BGRA"
                else:
                    # Red first
                    format = MNG_CANVAS_RGBA565
                    sdlformat = "RGBA"
        elif info.bitsize == 16:
            if info.shifts[BLUE] == 0:
                # Blue first
                format = MNG_CANVAS_BGR565
                sdlformat = "RGB"
            else:
                # Red first
                format = MNG_CANVAS_RGB565
                sdlformat = "RGB"
        else:
            raise RuntimeError(
                "Unable to figure out the best format for this video file.")

        print "Detected image format to be", NAMESPERPIXEL[format], sdlformat
        OriginalMNG.__init__(self, file, format)