Merge pull request #57 from jedediah/master

Use pure Python PNG loader instead of pygame.load
This commit is contained in:
David Vierra 2012-03-11 18:33:57 -07:00
commit 6b11355182
2 changed files with 13 additions and 42 deletions

View File

@ -29,7 +29,7 @@ import zipfile
from cStringIO import StringIO from cStringIO import StringIO
from datetime import datetime from datetime import datetime
from pygame import image, display from pygame import image, display, Surface
import png import png
import config import config
import release import release
@ -382,46 +382,18 @@ def loadAlphaTerrainTexture():
def loadPNGData(filename_or_data): def loadPNGData(filename_or_data):
# if filename[1:4] != "PNG": reader = png.Reader(filename_or_data)
if isinstance(filename_or_data, basestring): (w, h, data, metadata) = reader.read_flat()
filename_or_data = os.path.join(mcplatform.dataDir, filename_or_data) data = numpy.array(data, dtype='uint8')
filename_or_data = filename_or_data.encode(sys.getfilesystemencoding()) data.shape = (h, w, metadata['planes'])
else: if data.shape[2] == 1:
# path = numpy.fromstring(filename, 'uint8') # indexed color. remarkably straightforward.
pass data.shape = data.shape[:2]
try: data = numpy.array(reader.palette(), dtype='uint8')[data]
img = image.load(filename_or_data)
if data.shape[2] < 4:
img = img.convert_alpha() data = numpy.insert(data, 3, 255, 2)
data = numpy.fromstring(img.get_buffer().raw, 'uint8')
w, h = img.get_size()
data.shape = (h, w, 4) # xxx 32-bit images
format = GL.GL_BGRA
except Exception, e:
print repr(e), "while using pygame to load an image"
reader = png.Reader(filename_or_data)
(w, h, data, metadata) = reader.read_flat()
data = numpy.array(data, dtype='uint8')
data.shape = (h, w, metadata['planes'])
if data.shape[2] == 1:
# indexed color. remarkably straightforward.
data.shape = data.shape[:2]
data = numpy.array(reader.palette(), dtype='uint8')[data]
if data.shape[2] < 4:
data = numpy.insert(data, 3, 255, 2)
format = GL.GL_RGBA
if format == GL.GL_BGRA:
temp = numpy.array(data[:, :, 0])
data[:, :, 0] = data[:, :, 2]
data[:, :, 2] = temp
return w, h, data return w, h, data

View File

@ -121,7 +121,6 @@ def main():
data_files = get_data_files('fonts', 'toolicons') + [ data_files = get_data_files('fonts', 'toolicons') + [
('', [ ('', [
'history.txt',
'README.html', 'README.html',
'favicon.png', 'favicon.png',
'terrain-classic.png', 'terrain-classic.png',