Reputation: 13
I wanna load a large byte[] of colors. In opengl, i want to draw it like a video (for splashscreen). For now, I'm load each pixmap like GIF, but it takes too much memory (RAM). (I did it on the Android platform with libgdx).
public ImageSequences(int width, int height, byte[][] pixmaps) {
this.width = width;
this.height = height;
this.frameCount = pixmaps.length;
this.data = new Pixmap[frameCount];
for (int i = 0; i < frameCount; i++) {
this.data[i] = new Pixmap(width, height, mainFormat);
Pixmap p = new Pixmap(pixmaps[i], 0, pixmaps[i].length);
this.data[i].drawPixmap(p, 0, 0, p.getWidth(), p.getHeight(), 0, 0, width, height);
p.dispose();
}
this.base = new Texture(width, height, mainFormat);
}
int lastIndx = -1;
public Texture getKey(float timeState) {
int i = Math.round(timeState * 60) % frameCount;
if (lastIndx == i)
return base;
lastIndx = i;
base.draw(data[i], 0, 0);
return base;
}
And
int I = 574 + 1;// 574
byte[][] dats = new byte[I][];
int width = 1400;
int height = 720;
for (int i = 0; i < I; i++) {
dats[i] = Gdx.files.internal(String.format("seq/anim_%05d.jpg", i)).readBytes();
}
anim = new ImageSequences(width, height, dats);
Using the video player method looks more efficient. Any solution?
I hope, it can be done on multiplatform and without additional libraries.
Edit: with 500+ images and 1280x720 pixels or more high.
Sorry for bad english and Thanks.
Upvotes: 1
Views: 195
Reputation: 957
You should try to use an AssetManager. AssetManager will handle the asset for you (Multiple use by example).
You have to load your Asset before using it.
this.assetManager.load("Your internal Path", Texture.class);
assetManager.finishLoading();//optional but he just wait the end of assetLoading
And after that you can get your Asset.
The load of the asset can be done before in advance asynchronously in the startup of the application or the screen.
You can see more information about it in libGdx gitHub wiki
Also I think you should use a Texture instead of PixMap
and
change ImageSequence constructor
public ImageSequences(int width, int height, List<Texture> textures) {
....
}
After that imageSequence will just have to change the current texture for making the animation.
Texture class will directly handle the bit for you. And the Texture Object can directly be created by the assetManager
Teture texture = assetManager.get("Your internal Path", Texture.class);
Upvotes: 1