src/platform/python/mgba/image.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 png
8
9class Image:
10 def __init__(self, width, height, stride=0):
11 self.width = width
12 self.height = height
13 self.stride = stride
14 self.constitute()
15
16 def constitute(self):
17 if self.stride <= 0:
18 self.stride = self.width
19 self.buffer = ffi.new("color_t[{}]".format(self.stride * self.height))
20
21 def savePNG(self, f):
22 p = png.PNG(f)
23 success = p.writeHeader(self)
24 success = success and p.writePixels(self)
25 p.writeClose()
26 return success