
#!/usr/bin/env python

#makeCache: alle png inpakken in img.cache.

import sys
import os
import cPickle
import marshal
import wx
import array

app = wx.App()

modified_bitmap_buffer_cache = {}

srcDir = '.'
if os.path.exists("cache"):
	srcDir = "./cache"
files = os.listdir(srcDir)
for f in files:
	if f.lower().endswith(".png") == False:
		continue
	basename = f #os.path.split(f)[1]
	print "doing", basename
	img = wx.Image(srcDir + "/" + f, wx.BITMAP_TYPE_ANY)
	print "doing 2", basename
	bmp = wx.BitmapFromImage(img)
	w, h = bmp.GetSize()
	w = max(w, 1)
	h = max(h, 1)
	buf = array.array('B', [0] * (w * h * 4))
	bmp.CopyToBuffer(buf,wx.BitmapBufferFormat_ARGB32)
	for i in range (0,w*h):
		offset=i*4
		b=buf[offset]
		g=buf[offset+1]
		r=buf[offset+2]
		a=buf[offset+3]
		buf[offset]=r  
		buf[offset+1]=g 
		buf[offset+2]=b 
		buf[offset+3]=a 
	modified_bitmap_buffer_cache[basename] = (buf,w,h)
	print "did", basename

f = open("img.cache", "wb")
marshal.dump(modified_bitmap_buffer_cache,f,2)
f.close()