I posted earlier about creating images using different fonts and text HERE and I wanted to do some transparency manipulation and I know I can do that when I load the png, but I didn't want to reinvent the inter-space Einstein-Rosen-Podolsky bridge navigator, oops, I mean wheel. So I looked to ImageMagick, which I think can do about anything at command line, if you know what you want. So I modified the code as follows:
filename[14] = (char)((int)('p')); filename[15] = (char)((int)('n')); filename[16] = (char)((int)('g')); filename[11] = (char)((int)('A')+ii); filename[12] = (char)((int)('1')+jj); if ( ImageCheck(filename) == 0 ) { filename[14] = (char)((int)('b')); filename[15] = (char)((int)('m')); filename[16] = (char)((int)('p')); LoadGLTexture(filename, texture, textureNum); } else { loadTexture(filename, texture, textureNum, 256, 256); }
In the code I try and open the png first and if it exists ( ImageCheck() returns 1 if it exists and 0 otherwise ) , I apply the libpng and otherwise fall back to loading the crappy bmp.
I then applied the script below. Note that I had to set "depth 8" as it defaults to 16, which seems odd, but not for somebody who wants every bit of color they can scrape together. I use the ridiculous value of "-fuzz 75%" around the transparency center of "-transparent #ffffff" to get rid of all the jaggy edges in this case. Your mileage may vary and different values and colors would be for different purposes. The script finds bmps "for i in *.bmp" takes the names and makes a copy of the name and switches bmp to png in the copy using sed, " x=`echo "$i"|sed s/.bmp/.png/` " and then uses the original name and the new name with png to create the new texture.
cd res for i in *.bmp do x=`echo "$i"|sed s/.bmp/.png/` convert -fuzz 75% -transparent "#ffffff" -depth 8 -resize 256x256 "$i" "$x" done cd ..
I am planning to have 9 rows and columns as the default puzzle size and the 7th row is images, the 8th is Egyptian Hieroglyphs and the 9th is a surprise Alien dictionary lookup or perhaps it will be common poly-peptides from RasMol :). It will keep me interested as it evolves to a DNA and protein microcode generator. It takes me longer to blog about this , than it does to run the script. I suppose I could have Gimped all the images, but, come on, you have to know how lazy I am. Once I have all the scripts, I won't pack images with the source, just add a line to the make file to create the images the first time.
ADDED: in the sed method I substitute by finding ".bmp", and in practice that may work, but be warned it is just because of some limited possibilities. What would be proper and safe is "[.]bmp" which isolates the "." as a real character and not a wild card match to anything. I just thought I would mention that, as I looked back on posts and saw that I had done something expedient, which was poor form in general.
0 comments:
Post a Comment