Animated GIF Demo (VEXcode)

Hers’s another demo that can be built with VEXcode. It’s not very well developed and uses a couple of C API’s that we don’t usually expose that were added to vexos 1.0.5. I’ll also explain a couple of more advanced aspects of the setup in another post later, specifically how to allow VEXcode access to more dynamic memory than is available with the default project build scripts.

output looks like this.
gifdemo

and uses this animated gif.
world

You can display more than one gif by creating additional instances of the gif class, however, if they overlap you will still see flicker with this initial version.

The code uses an open source gif reading library. The gif is included with the project and should be copied to an SD card which is then inserted into the brain.

displaying on the V5 screen is very simple, all it takes is this.

vex::brain       Brain;

int main() {
  int count = 0;

  vex::Gif gif("world.gif", 120, 0 );
  
  while(1) {
    Brain.Screen.printAt( 5, 230, "render %d", count++ );
    Brain.Screen.render();
  }
}

pass the name of the file and the x, y coordinates of the top left corner.

It’s not guaranteed to work with all gifs but most I have tested so far will work, keep them under the brain screen size of 480 x 240 pixels.

gifdemo.zip (485.2 KB)

22 Likes

Is there any time limit for gifs? I tried uploading a gif of my ~45 sec reveal and it wouldn’t play, but some shorter clips I had would.

I think you are just maxing out the brain’s storage with that long of a video.

You use an SD card to hold gifs @Gameoa

And that’s why I’m not a programmer :slight_smile:

10 Likes

No, I think @Gameoa is correct.
Even though the GIF is stored on the SD, I think it needs to load the images into a buffer in the memory to play, it can’t read directly from SD.

If your GIF is too large (45s is massive) you will run into problems, especially since a GIF has much worse (or maybe none) compression compared to a video format like mp4.
I might be wrong, but it is possible that the brain needs to store a raw bitmap of all the frames in memory, which takes a lot of space.

4 Likes

The gif’s are loaded onto the heap IIRC, I will explain at some point how to increase HEAP size, it’s just a change to the makefile, then longer gif’s will work.

2 Likes

Looks like I had already bumped the HEAP size up to 8MB for this demo, so 45 second gif I would have thought worked, however, you could try changing this line in mkenv.mk

LNK_FLAGS = --defsym _HEAP_SIZE=0x800000 -nostdlib -T "$(TOOLCHAIN)/$(PLATFORM)/lscript.ld" -R "$(TOOLCHAIN)/$(PLATFORM)/stdlib_0.lib" -Map="$(BUILD)/$(PROJECT).map" --gc-section -L"$(TOOLCHAIN)/$(PLATFORM)" ${TOOL_LIB}

The _HEAP_SIZE symbol control the size, the default for VEXcode if this is not defined is just 1MB, for this demo I had bumped to 8MB, you could try 16MB and see what happens.

--defsym _HEAP_SIZE=0x1000000

I found some gif’s that are not supported by the library I baed this code on, that may be another cause of the issue.

4 Likes

Kind of a long shot here, but has anyone got this to work and not completely die with the vexcode pro v5 app? I can get it to work without “updating” but that causes a lot of problems in other code.

thanks

I know I’m trying this a long time after it was first posted but I’m getting two errors when I try this. One of them says “No member named ‘Gif’ in namespace ‘vex’” and the other says “Use of undeclared identifier ‘gif’”. Any idea as to what could fix these?

I just tested the original project, still works ok. It’s easier to not upgrade the project when VEXcode asks. Did you make changes ?

3 Likes

Using this on the latest version it doesn’t seem to work anymore. was support for it cut or is there a new way to use it? Any help is appreciated

1 Like

Won’t work for me either :confused:

Fixed it anyone wanna see updated code?

Just post what you fixed here. Describe where the problem was, include the snippet of new code.

Or if it is with how to load the project, then describe it step by step.

You revived the thread, now make it worthwhile for all.

9 Likes

You have to remember that the original post contains three year old code and our APIs have changed slightly since that time. As this keeps coming up, and I think I fixed it for my own use months ago, I’ll put something up on github this weekend if I have time.

11 Likes

Just an update. I did look at the original code last weekend, it was still compiling and worked on the V5 for me so not sure why others had issues. VEXcode did throw a few warnings from static analysis, but that did not stop it from building. I cleaned up a little and pushed out a new VEXcode project on github, this removes the C API calls and replaces them with VEXcode C++ calls now everything is available there. I also combined the C++ class and gif decoding into one source file for simplicity.

7 Likes