summaryrefslogtreecommitdiff
path: root/utils/png2rgba.py
diff options
context:
space:
mode:
authorfalkTX <falktx@gmail.com>2015-04-23 22:42:22 +0200
committerfalkTX <falktx@gmail.com>2015-04-23 22:42:22 +0200
commitcba9f00f2c71ec7bb40963a3d05c0d8d17887f03 (patch)
treec99724e433ac526e398c210531072c3d764196f1 /utils/png2rgba.py
parent58c68c749f34596cd09a08ca07dda65e881274cf (diff)
png2rgba.py: Allow monochrome images
Diffstat (limited to 'utils/png2rgba.py')
-rwxr-xr-xutils/png2rgba.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/utils/png2rgba.py b/utils/png2rgba.py
index 64c6761a..7d992b40 100755
--- a/utils/png2rgba.py
+++ b/utils/png2rgba.py
@@ -5,6 +5,12 @@ import Image
# -----------------------------------------------------
+formats = {
+ 2: "GL_LUMINANCE",
+ 3: "GL_BGR",
+ 4: "GL_BGRA"
+}
+
def png2rgba(namespace, filenames):
fdH = open("%s.hpp" % namespace, "w")
@@ -36,17 +42,20 @@ def png2rgba(namespace, filenames):
height = len(pngData)
for dataBlock in pngData:
width = len(dataBlock)
- channels = len(dataBlock[0])
+ if isinstance(dataBlock[0], int):
+ channels = 2
+ else:
+ channels = len(dataBlock[0])
break
else:
print("Invalid image found, cannot continue!")
quit()
- if channels not in (3, 4):
+ if channels not in formats.keys():
print("Invalid image channel count, cannot continue!")
quit()
- print("Generating data for \"%s\" using '%s' type" % (filename, "GL_BGR" if channels == 3 else "GL_BGRA"))
+ print("Generating data for \"%s\" using '%s' type" % (filename, formats[channels]))
#print(" Width: %i" % width)
#print(" Height: %i" % height)
#print(" DataSize: %i" % (width * height * channels))
@@ -69,9 +78,13 @@ def png2rgba(namespace, filenames):
fdC.write(" ")
for data in dataBlock:
- if channels == 3:
+ if channels == 2:
+ fdC.write(" %3u," % data)
+
+ elif channels == 3:
r, g, b = data
fdC.write(" %3u, %3u, %3u," % (b, g, r))
+
else:
r, g, b, a = data