all repos — mgba @ 6d898542c765f4efc4a094c5ebd3f3465c36f417

mGBA Game Boy Advance Emulator

src/platform/python/mgba/png.py (view raw)

 1# Copyright (c) 2013-2016 Jeffrey Pfau
 2#
 3# This Source Code Form is subject to the terms of the Mozilla Public
 4# License, v. 2.0. If a copy of the MPL was not distributed with this
 5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6from ._pylib import ffi, lib
 7from . import vfs
 8
 9class PNG:
10	def __init__(self, f):
11		self.vf = vfs.open(f)
12
13	def writeHeader(self, image):
14		self._png = lib.PNGWriteOpen(self.vf.handle)
15		self._info = lib.PNGWriteHeader(self._png, image.width, image.height)
16		return self._info != ffi.NULL
17
18	def writePixels(self, image):
19		return lib.PNGWritePixels(self._png, image.width, image.height, image.stride, image.buffer)
20
21	def writeClose(self):
22		lib.PNGWriteClose(self._png, self._info)
23		del self._png
24		del self._info