←  APIs and Utilities

ComputerCraft | Programmable Computers for Minecraft

»

GIF API

Bomb Bloke's Photo Bomb Bloke 26 Apr 2015

pastebin get 5uk9uRjC GIF

Requires BBPack:

pastebin get cUYTGbpb bbpack

So yeah, a GIF decoder (and encoder). You hand it a GIF and it draws it. If it's an animation, it can handle that too. Fairly straight-forward.

Video

CC 1.74+ gets a better rendering rate, though updated versions of the API run at about full speed on much older ComputerCraft builds.

For reference, a regular computer display has 51x19 characters available for rendering. A full-sized monitor, with a text scale of 0.5, has 164x81 characters. If you want some suitable images, try a web search, or perhaps this site. The API can resize loaded images to fit your display, but the process is processor-intensive compared to using an external tool.

Usage

Here's the sample script used in the video:

Example

Version History

Edited by Bomb Bloke, 09 June 2017 - 01:18 PM.
Quote

Antelux's Photo Antelux 27 Apr 2015

This is pretty cool. I can imagine using this to make a game of some sort.

... Hope I didn't just give anyone ideas. :P
Quote

SquidDev's Photo SquidDev 28 Apr 2015

Wow, oh wow. This is pretty awesome. I'm very impressed that the code is that small - though I guess you've already got LZW implemented. All we need now is PNG and JPEG parsers and then we have the complete suite! I'm also impressed how close the colours were, I don't remember that with my bitmap parser. Who says we need more colours? :P.
Quote

Bomb Bloke's Photo Bomb Bloke 28 Apr 2015

It probably looks like there's more colours than there are, at least in the video, where you've got compression artefacts muddying the waters.

That said, I reckon the effect's pretty good, even in-game. Especially with animations, where the mind has a hard time spotting odd colours before they're gone. :)
Spoiler

Edited by Bomb Bloke, 10 February 2016 - 11:15 PM.
Quote

Lyqyd's Photo Lyqyd 28 Apr 2015

Very nice! Palettizing the gif is impressively well done! Does it also handle individually paletted frames?
Quote

Bomb Bloke's Photo Bomb Bloke 28 Apr 2015

Yes, it does.
Quote

Bomb Bloke's Photo Bomb Bloke 04 May 2015

I'd been considering encoding functionality, but didn't think there to be much use for it. Then CrazedProgrammer went and posted a script that contained an animation represented via a single +30mb string, and I just had to try converting it...

Totally go watch the video he made out of that, by the way. It's pretty cool.

So yeah, added GIF.saveGIF(), and while I was at it, GIF.toPaintutils().
Edited by Bomb Bloke, 04 May 2015 - 12:21 PM.
Quote

Bomb Bloke's Photo Bomb Bloke 30 May 2015

Another update. I've tweaked things around such that rendering speeds are now quite reasonable under older versions of ComputerCraft; even testing under CC 1.5, most of the example GIFs from my original video play at full speed.

There've been a few other functions added, the most interestingish probably being GIF.resizeGIF(), which is useful for the purposes of getting a specific aspect ratio or simply forcing an image to fit a given display. It's slow as a dog, mind you, but handy if an external editor isn't immediately available.

I've also fleshed out the "usage" documentation somewhat.
Quote

Pyuu's Photo Pyuu 30 May 2015

This is amazing, I haven't looked through your code to find out how you decode gif files but it looks like you spent a lot of quality time working on this.
Quote

DaKodiMaster's Photo DaKodiMaster 30 May 2015

This looks amazing. I want to try this, but I dont have any gif files to use.
Quote

Bomb Bloke's Photo Bomb Bloke 31 May 2015

 Mayushii, on 30 May 2015 - 03:33 PM, said:

This is amazing, I haven't looked through your code to find out how you decode gif files but it looks like you spent a lot of quality time working on this.

In short, I do it the long way.

 DaKodiMaster, on 30 May 2015 - 09:03 PM, said:

This looks amazing. I want to try this, but I dont have any gif files to use.

Figured I might as well put together a demo which doesn't require a massive monitor:

pastebin get cUYTGbpb bbpack
pastebin get 5uk9uRjC GIF
bbpack get wZfpq9h8
slideshow

Edited by Bomb Bloke, 21 July 2017 - 12:19 AM.
Quote

minecraftwarlock's Photo minecraftwarlock 07 Jun 2015

Is there any way to get the original RGB values from the image?
Quote

Bomb Bloke's Photo Bomb Bloke 07 Jun 2015

The API doesn't offer any such method, but could be modified to provide one. I'm not certain why or how such a feature would be of any use, however.
Quote

minecraftwarlock's Photo minecraftwarlock 20 Jun 2015

Where in the code could the RGB values be found?
Quote

Bomb Bloke's Photo Bomb Bloke 21 Jun 2015

Well, in the current build (1.2), the global palette (if the file has one) is read in by lines 377-382, and local palettes (for individual frames within the files, if they have one) are read in by line 451.
Quote

uaBArt's Photo uaBArt 23 Feb 2016

I tried to play this GIF
wget http://www.webdevelo...files/neko2.gif someImage.gif

But I get

GIF:509: attempt to get length of boolean

I tried more and I had some fun
Posted Image
Edited by uaBArt, 23 February 2016 - 10:18 PM.
Quote

Bomb Bloke's Photo Bomb Bloke 24 Feb 2016

Note my bug, sorry; wget isn't suitable for downloading anything other than text files. Truth be told, ComputerCraft simply doesn't offer a method of getting any other files directly from the web, full stop.

Personally if I want to get them into a server environment I first place them onto the drive of a SSP CC system using my real computer's file manager, and then use Package to upload them to Pastebin in a format that can be downloaded within an SMP world.
Quote

uaBArt's Photo uaBArt 24 Feb 2016

I tried to get maximum from what we can output on CC huge monitor, so I have picture in 164 symbols width and I used all symbols that might to be
Original Image:
Spoiler

What I get
Spoiler

What we can get without symbols
Spoiler

P.S. But rendering of this took one night for creating 6x9 png for each symbol in each color combination (57033 unique files), and after close to 4 hours to compile that in mosaic using AndreaMosaic with custom config.
P.P.S. If someone need all images that I generated, you can take them on my OneDrive

And do we have something like format for images like in my picture above? For saving char and two colors for each pixel.
If we do, I'll probably upload my image in compatible format.
Quote

Bomb Bloke's Photo Bomb Bloke 25 Feb 2016

Figured I'd see what I could do in-game:

Low-Res

High-Res (Prescaled)

High-Res (In-game scaling)

The low res version dumps straight to the screen, while the others make use of Blittle. The difference between each of the latter two is that when I allow my code to handle the resizing (as opposed to having an external editor do it), the colour depth is reduced beforehand.

My code can do these translations within a minute (even when loading in the full-sized image at maximum GIF colour depth), but doing them using the whole CC character set would indeed take a lot longer - especially since AndreaMosaic isn't simply averaging out the colour depth within each character space (and it'd do it with no resizing prior to picking the characters, too). If you look at the pig's back for eg you can see it's chosen characters which are best shaped to match how the top of the characters should veer towards yellow.

There's a function in the BLittle API which could load and display the sort of images AndreaMosaic produces, if they were saved appropriately. It's a pretty simple affair so it shouldn't be hard to mimic (assuming you can get AndreaMosaic to give you some sort of text dump representing its output).
Quote

Chelebi's Photo Chelebi 18 Sep 2016

Hi everybody.

i'm trying to get a .gif running but im really lost :P can someone explain step by step what i need to do, to get a .gif running on a monitor please ?
i would really appreciate the help :)
Quote