I tried looking through the forum and Javadoc for something which would do this, but I haven't came back with much luck. What I'm trying to do is generate new pictures from a template image, which would reduce the need to package the game with multiple images.
Each template image is a 256x256 nodpi png in an 8-bit format. Currently what I'm doing is converting the template image into int[] "done once per game start", create a new int[] of the same size, test each pixel if it matches a list of values, then change that pixel to another pixel color (in the new int[]). Then when the new int[] is finished, its made into a ARGB_8888 bitmap which it loaded into the TextureManager.
Example: change all the pixels which have a red channel of 20 into a ARGB of 200:128:0:128 (purple with a transparency of 200, change all the pixels with an red channel of 40 into an ARGB of 200:255:0:0. Every other pixel is copied as is.
The method I have now works, but it takes about 3-4 second per image (good thing they are all done in threads). The problem is that the whole bulk of them are created each time the game starts (and oddly when the phone resumes from standby). I was thinking about using the ITextureEffect, but I'm still not sure how to use it.
Is there another method of doing this or a tutorial of how ITextureEffect works? Majority of the new images won't change, but I would want to have some of the images animated eventually (using the same color scheme).
= Current code to generate the images =
private void MakeImage(Panel data, int[] pcolors)
{
if(tm.containsTexture(data.Name))
return;
if(!rawBmp.containsKey(data.ImageAttribute.Location))
return;// if the template image was not able to be added, then skip making this image
Bitmap nBit = Bitmap.createBitmap(adjust(data.ImageAttribute.Location, pcolors), 256, 256, Config.ARGB_8888);
tm.addTexture(data.Name, new Texture(nBit, true));
nBit.recycle();
data.TexHandle = tm.getTextureID(data.Name);
data.Colors = pcolors;
panels.put(data.Name, data);
}
private int[] adjust(String d, int[] pcolors)
{
if(pcolors == null)
return rawBmp.get(d);
int cID = -1;
int toColor = 0;
int nPixel = 0;
int[] nPanel = new int[256*256];
for(int p = 0; p < rawBmp.get(d).length; p++)
{
nPixel = rawBmp.get(d)[p];
nPanel[p] = nPixel;
cID = match(nPixel);
if(cID > -1 && cID < pcolors.length)
{
toColor = Color.argb(Color.green(nPixel), Color.red(Colors[pcolors[cID]]), Color.green(Colors[pcolors[cID]]), Color.blue(Colors[pcolors[cID]]));
nPanel[p] = toColor;
}
if(cID == -2)
{
toColor = Color.argb(Color.green(nPixel), 100, 100, 100);
nPanel[p] = toColor;
}
}
return nPanel;
}
private int match(int pixel)
{
switch(Color.red(pixel))
{
case 0:
return -2;
case 20:
return 0;
case 40:
return 1;
case 60:
return 2;
case 80:
return 3;
case 100:
return 4;
}
return -1;
}