Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: hoffa on May 28, 2011, 02:58:26 pm

Title: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 28, 2011, 02:58:26 pm
Hello!

Here is a tool I wrote (even though I'm everything but a fan of PHP; it's just easier for everybody to use) to convert PNG/GIF/BMP/etc. images to the TI.Image format (http://wiki.inspired-lua.org/TI.Image), usable within Lua scripts. It supports all image sizes and is able to convert colored images. CX or non-CX, it should work with both (color will just be transformed into shades of gray). Anyway, here's the link, try it out yourself:

http://hoffa.franceserv.fr/tiimage/ (http://hoffa.franceserv.fr/tiimage/)

The usage is simple: select your file and press the button. The long string you'll see is the image in the TI.Image format. Use the image.new() (http://wiki.inspired-lua.org/image.new) function with that string to load the image, and draw it on the screen with gc:drawImage() (http://wiki.inspired-lua.org/gc:drawImage). Nothing too complicated.

(http://webgel.net/bf/5/screen3.png) (http://webgel.net/bf/6/screen3.png) (http://webgel.net/bf/6/screen2.png)
(that grayish square behind the sprite only shows up on the emulator, it shouldn't show up on the calculator. It's probably there so it's easier to differentiate transparent from white pixels)

Because the output is usually quite big, there will probably be some sort of compression (at least ~50% smaller) option in the near future, along with a Lua function to decompress the image in order to save some space.

Here is a very simple image viewer made with TI.Image images if you want to see what it looks like (use left and right arrows to change image): http://webgel.net/bf/simple_image_viewer.tns (http://webgel.net/bf/simple_image_viewer.tns)

Changelog:

Notes: (these are just interesting things I've noticed while playing around with Lua and graphics, might be useful to some)
Title: Re: Online PNG to TI.Image converter (images/sprites with Lua on the Nspire)
Post by: Jim Bauwens on May 28, 2011, 02:59:17 pm
Wow, nice!
I've been planning to do this, but haven't had any time.

Good job!

Edit:
If you need any help with the 'bit splitting' part, I'm willing to help!
Title: Re: Online PNG to TI.Image converter (images/sprites with Lua on the Nspire)
Post by: Adriweb on May 28, 2011, 03:12:11 pm
That goes well with jimbauwens' tools (http://bwns.be/jim/sprite.html) :)

And thanks for using the official wiki \o/
Title: Re: Online PNG to TI.Image converter (images/sprites with Lua on the Nspire)
Post by: hoffa on May 28, 2011, 04:11:02 pm
Alrighty added some basic transparency support (actually just transparency based on a certain color). Real PNG transparency is messy when it comes to small sprites, so I'll leave that out for now.

If you need any help with the 'bit splitting' part, I'm willing to help!
I just finished doing that monochrome converter, haven't really played around with actual color and the TI.Image format yet (I'll see how it all works when moved between CX/non-CX calculators, etc.). For now I don't need any help, but I'll probably need some hints later. I'll contact you as soon as I need any help, if that's fine for you. :) (also, that's a damn nice tool you're making) Edit: just noticed on the wiki that you have already made a converter in Python, seems like I wasn't the first one. Oh well, but I'll try to finish this one for the sake of it. o/

And thanks for using the official wiki \o/
No problem, thanks for having an official wiki. o/
Title: Re: Online PNG to TI.Image converter (images/sprites with Lua on the Nspire)
Post by: ruler501 on May 28, 2011, 08:18:48 pm
This looks great good job. I hope you keep up with good development for the Nspire community

key cracking maybe...
Title: Re: Online PNG to TI.Image converter (images/sprites with Lua on the Nspire)
Post by: DJ Omnimaga on May 29, 2011, 01:04:24 am
This looks nice! Also welcome on the forums.
Title: Re: Online PNG to TI.Image converter (now with CX/non-CX color support)
Post by: hoffa on May 29, 2011, 05:30:50 am
I added support for color. Haven't fully tested it, tried with a colored pikachu once and it seemed to work well. We'll see how it goes. Also the header is generated as it should, so no more resolution restriction.

Edit:
I tried with an actual picture of a landscape, this is what I got:
(http://bb.xieke.com/files/4/screen3.png)
I'll try to fix that as soon as possible, seems like the some very dark colors are not converted correctly.
Edit 2:
It's been fixed, check out the screenshot on the first post. Now I still need to make it transform some 'bytes' into ASCII characters in order to slightly decrease the size of the output.
Title: Re: Online PNG to TI.Image converter (now with CX/non-CX color support)
Post by: BrownyTCat on May 29, 2011, 05:50:22 am
Definately using this!
Title: Re: Online PNG to TI.Image converter (now with CX/non-CX color support)
Post by: Jim Bauwens on May 29, 2011, 09:43:46 am
Looks very good! Good job again!

Now I still need to make it transform some 'bytes' into ASCII characters in order to slightly decrease the size of the output.
The range of that you can compress it 32-126 (except 92 and 34), higher than that causes problems, because its stored in utf-8 and they then take 2 bytes.
Title: Re: Online PNG to TI.Image converter (now with CX/non-CX color support)
Post by: ruler501 on May 29, 2011, 10:07:31 am
This ooks great hopefully it will help the game developers out a lot.
Title: Re: Online PNG to TI.Image converter (now with CX/non-CX color support)
Post by: hoffa on May 29, 2011, 11:18:41 am
Looks very good! Good job again!

Now I still need to make it transform some 'bytes' into ASCII characters in order to slightly decrease the size of the output.
The range of that you can compress it 32-126 (except 92 and 34), higher than that causes problems, because its stored in utf-8 and they then take 2 bytes.
Thanks! The bytes are now compressed and everything should be working well. :)
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: DJ Omnimaga on May 29, 2011, 02:26:38 pm
WOAH! I just saw the new screenshots, awesome! Is it possible to display the images wherever you want? This could make game development much easier! Transparency will definitively be nice for that.
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on May 29, 2011, 02:33:27 pm
Yeah, you can place it where ever you want :)

The only thing is that the format is HUGE. But I've got some compression routines that I'll share one of these days to the world. (That is, when I have time)
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: pianoman on May 29, 2011, 02:37:39 pm
This. Is. Awesome.
Nice job!
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: DJ Omnimaga on May 29, 2011, 02:37:50 pm
Nice. How big is a full screen (well not really full, but taking all available space) image? Since we got 64 MB of RAM, hopefully for sprites size shouldn't be a concern, although compression would definitively be welcome for complex games with over 200 sprites.

What is the Nspire color depth anyway? I know on the Nspire Click/Touchpad it's 16 shades of gray and the Casio PRIZM 65536 colors (with the ability to switch in 8 colors mode)
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 29, 2011, 02:41:34 pm
Nice. How big is a full screen (well not really full, but taking all available space) image? Since we got 64 MB of RAM, hopefully for sprites size shouldn't be a concern, although compression would definitively be welcome for complex games with over 200 sprites.

What is the Nspire color depth anyway? I know on the Nspire Click/Touchpad it's 16 shades of gray and the Casio PRIZM 65536 colors (with the ability to switch in 8 colors mode)
The available space is 318*212 pixels (what an unpractical resolution I have to say, multiples of 8 would've been a lot better). It's 15-bit color, with 1 alpha bit. Not sure for the non-CX calculators though.
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: DJ Omnimaga on May 29, 2011, 02:45:57 pm
Thanks for the info. Hopefully this shouldn't make games too hard to make, although I am a bit concerned about how to draw images and sprites in softwares like paint that supports 2, 4, 8, 16 and 24 bit color depths but not 15. I hope it won't make it too hard to convert stuff. Granted, the quality drop shouldn't be as noticeable as someone converting an image from 8 bit to 6 or 7 bits, but I know for certain people quality is extremly important, and they might hate if certain image colors they think as important suddently appeared  in different colors on their TI-Nspire.

Oh well... at least TI finally added colors to their calcs. I'm also glad they opened them to Lua dev (now the next step for them is to not try blocking Ndless anymore)
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 29, 2011, 02:53:25 pm
What I meant was that the actual color data of the pixel holds on 15 bits, but there is another bit for alpha. So you might call it 16-bit color (but there are only 2^15 colors), just depends what kind of 16-bit (ARGB?). Any decent program can save in that format. Also as you can see there is not a huge amount of loss in the final result, so I don't think it will be too big of a problem.
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: DJ Omnimaga on May 29, 2011, 02:56:15 pm
OOh ok I see now. I guess that might be good then. And yeah it shouldn't be a big issue. After all, it's several thousands of colors on a tiny screen. Pixels are very small and the CX screen smaller than the regular TI-Nspire screen, so it's not like a few dithered sprites will hinder quality too much.
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: JosJuice on May 29, 2011, 03:02:50 pm
What is the Nspire color depth anyway? I know on the Nspire Click/Touchpad it's 16 shades of gray and the Casio PRIZM 65536 colors (with the ability to switch in 8 colors mode)
TI refuses to reveal the color depth of the screen (and I think they don't even tell us the size!) but I would guess that it's 16-bit. I think the image format for Lua is 15-bit with one transparency bit.
Title: Re: Online PNG to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on May 29, 2011, 03:49:47 pm
The screen itself is 16 bit color, but the Ti.image format can only handle 15 bit color (with the 1 bit alpha).
Title: Re: Online image to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 29, 2011, 04:50:16 pm
I changed the host, it should be a lot faster and now all kinds of image formats are supported. :)
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: BrownyTCat on May 29, 2011, 07:24:00 pm
I spy TF2!
Also great job implementing IM for more formats.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 30, 2011, 03:38:27 pm
I started playing around with sprites to see how well the Nspire handles tile-based games and games in general. I'll keep the notes updated on the first page (at the bottom of my first message). Right now it seems like the Nspire is very slow with a lot of stuff on the screen.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: pianoman on May 30, 2011, 03:39:11 pm
Like the 84, or slower?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on May 30, 2011, 03:41:10 pm
It depends how you use it.
I'm using this format in my game (Block Breaker), and it isn't really slow, while every step I redraw the whole screen.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 30, 2011, 03:49:44 pm
It's usually slow with colored images drawn on the whole screen (i.e. all the gc:drawImage() functions at the end draw on every pixel on the screen). A Mario-like platformer that utilizes every single pixel of the screen might not be very playable (Edit: unless there are a lot of transparent pixels). Those are the current results of years and years of rigorous scientific experiments on the Nspire using Lua.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on May 30, 2011, 05:10:52 pm
(http://bb.xieke.com/files/7/screen1.png)
I made a very simple tile-based platformer "game" to check out how it runs. With that many tiles, it runs reasonably well. I still got some optimization tricks up my sleeve.

Edit:
I also tried with only black and white sprites (i.e. more transparency), and it does run faster and shouldn't look too ugly.

Edit2:
(http://bb.xieke.com/files/8/screen2.png)
With more stuff on the screen (and Ash gone), the so-called game is still playable, but nothing great. The problem with platformers is that the whole screen has to be updated after every movement, and fluid movement is somewhat important in those games. I'll now play around with fullscreen Pokemon-like games, where the FPS is not as important (also movement is easier, no acceleration and other stuff).
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: DJ Omnimaga on June 07, 2011, 04:23:33 am
Hmm that looks nice :D

You should probably move those in another thread, though, so more people see it and it's less off-topic. :P

Also are monochrome images the same format as grayscale/color ones? I wonder what causes the slowdown otherwise?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: pianoman on June 09, 2011, 04:16:06 pm
Hoffa, is there any way to get an offline converter, or is this only online?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on June 09, 2011, 05:27:42 pm
Hoffa, is there any way to get an offline converter, or is this only online?
Actually there is, and there have been one since TI released Scripting Tools. I had never noticed it (actually I did, but wasn't sure what it was for), but the button for "image serialization" actually copies to clipboard the TI.Image of an traditional image format (PNG, BMP, nearly anything).
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: pianoman on June 09, 2011, 05:30:23 pm
Got it, thanks.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on June 09, 2011, 06:00:10 pm
I was first :p
I made a offline converter in python more than a month ago :D
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: DJ Omnimaga on June 09, 2011, 07:24:11 pm
Lol nice jim :P. Also we released Lua makers before TI did :P. On top of that on TI site good luck finding the Lua tool from the front page. It's well-hidden.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: pianoman on June 09, 2011, 07:31:23 pm
Wait, where is this python converter?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on June 10, 2011, 03:18:05 am
This is the link to it http://bwns.be/jim/convert.py .
You need pythonmagick to use it (Linux users can use the package manager to install it).

Usage: convert.py infile.png data.txt
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: jboavida on July 03, 2011, 02:48:02 pm
Hi Hoffa,
Can you please send me the Lua script for simple_image_viewer.tns?

I try to use the functions directly by I got an error

gc:drawimage (image,0,0)  attemp to index global "gc" (a nil value)

Thank you

Joaquim
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on July 03, 2011, 04:14:49 pm
jboavida, you need to put gc:drawimage (image,0,0) inside on.paint, like this:
Code: (Lua) [Select]
function on.paint(gc)
    gc:drawimage (image,0,0)
end

on.paint get called every time the screen gets/needs to be redrawn (for example when you open the program or run platform.window:invalidate()

Everything that uses gc should be called from on.paint. I recommend you to read  the tutorials at http://www.inspired-lua.org/category/tutorials/starting-in-lua/ , they will help you understand how nspire Lua works.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: jboavida on July 03, 2011, 06:50:03 pm
jimbauwens thanks for the tip . It's working now.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: cyanophycean314 on August 27, 2012, 09:13:21 pm
The website in the first post is now filled with pictures of birds and the hoffa.zzl.org site I had been using a while is now down.

So what're my options for converting pictures of .png into TI Image with support for transparency (any color)?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Deep Toaster on August 28, 2012, 02:35:11 pm
hoffa.zzl.org is up for me. It doesn't seem to be updated tho.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: cyanophycean314 on August 28, 2012, 08:16:09 pm
Ah it has returned!  :w00t: 0.6 is good enough for me.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on August 29, 2012, 05:13:48 am
I haven't been here for a while as I'm currently in the army. I updated the link to the newest version.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Jonius7 on January 29, 2013, 12:44:49 am
More necroposts. (shows a bit of inactivity in Lua lately)
Yeah Image to TI.Image is now at http://hoffa.franceserv.fr/tiimage
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Jim Bauwens on January 29, 2013, 05:38:58 am
shows a bit of inactivity in Lua lately

I've been fairly busy in the Lua world, I just don't post a lot ^^
And I'm sure others do the same ;)
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Matrefeytontias on January 29, 2013, 08:35:17 am
Do you think it should be a version for Ndless C / ASM ? It'd be really helpful.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: epic7 on January 29, 2013, 08:37:34 am
What format would it convert the images to?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: Matrefeytontias on January 29, 2013, 08:38:40 am
Well, Ti.Image too. Or NTI, as hoffa called it.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: epic7 on January 29, 2013, 08:42:44 am
Er, if it's the same format, why do we need a separate converter?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on January 29, 2013, 04:26:07 pm
I added an image to NTI converter: http://hoffa.franceserv.fr/nti/ (http://hoffa.franceserv.fr/nti/)
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: ElementCoder on January 30, 2013, 01:58:58 pm
How did you get that split screen in the 3rd image?
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: hoffa on January 30, 2013, 02:14:12 pm
Can't remember to be honest, it was some key combination to display two pages at once.
Title: Re: Online PNG/GIF/BMP/etc. to TI.Image converter (sprites/images on the Nspire)
Post by: someone on January 30, 2013, 02:36:46 pm
You can either group the pages, one at a time (Ctrl + 4), or change the layout from the Documents "Doc" menu -> Page Layout -> Select Layout -> Layout X