Jump to content




GIF API

api media

25 replies to this topic

#1 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 26 April 2015 - 11:39 PM

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.


#2 Antelux

  • Members
  • 295 posts
  • LocationSomewhere in the middle of nowhere.

Posted 27 April 2015 - 12:32 AM

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

#3 SquidDev

    Frickin' laser beams

  • Members
  • 1,409 posts
  • LocationDoes anyone put something serious here?

Posted 28 April 2015 - 02:08 PM

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.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 April 2015 - 11:18 PM

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.


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,452 posts

Posted 28 April 2015 - 11:56 PM

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

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 April 2015 - 11:57 PM

Yes, it does.

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 04 May 2015 - 12:20 PM

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.


#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 May 2015 - 12:39 PM

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.

#9 Pyuu

  • Members
  • 203 posts

Posted 30 May 2015 - 03:33 PM

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.

#10 DaKodiMaster

  • Members
  • 7 posts

Posted 30 May 2015 - 09:03 PM

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

#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 May 2015 - 03:59 AM

View PostMayushii, 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.

View PostDaKodiMaster, 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.


#12 minecraftwarlock

  • Members
  • 34 posts

Posted 07 June 2015 - 02:34 AM

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

#13 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 June 2015 - 02:59 AM

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.

#14 minecraftwarlock

  • Members
  • 34 posts

Posted 20 June 2015 - 10:22 PM

Where in the code could the RGB values be found?

#15 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 21 June 2015 - 12:07 AM

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.

#16 uaBArt

  • New Members
  • 2 posts

Posted 23 February 2016 - 07:33 PM

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.


#17 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 February 2016 - 01:13 AM

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.

#18 uaBArt

  • New Members
  • 2 posts

Posted 24 February 2016 - 11:08 AM

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.

#19 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 February 2016 - 01:32 AM

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).

#20 Chelebi

  • Members
  • 3 posts

Posted 18 September 2016 - 09:32 AM

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 :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users