This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mads's profile picture

Image Converter

Started by Mads, 14 October 2012 - 05:41 PM
Mads #1
Posted 14 October 2012 - 07:41 PM
Today I made a little program, which converts a PNG, JPEG, BMP etc. image file into a format, that my API can read, and construct an image from. This image can then be displayed on advanced computers.

These are the functions and variables, that this API let's you use with:

image.createQuad(x, y, w, h) -- returns a new quad_class

quad_class.x -- number
quad_class.y  -- number
quad_class.width  -- number
quad_class.height  -- number



image.createImage(path) -- returns an image_class
image_class:draw() -- draws the image
image_class:drawq(q) -- draws the image with a quad(google it)
image_class:getWidth() -- returns the width of the image
image_class:getHeight() -- returns the height of the image

image_class.x -- number
image_class.y -- number

This is how to use it:
SpoilerWindows:
  • Convert an image into a .ccimg file: In the console, type this in:
     love2d\love.exe CCImg <path/to/file> <save/to/path> 
  • Move the file to anywhere you want, as long as it can be acccessed by the computer.
  • Load it through the API.
  • Draw!
Linux/OSX:
NOTE: LÖVE MUST BE INSTALLED!
  • Convert an image into a .ccimg file: In the terminal, type this:
     love CCImg/ <path/to/file> <save/to/path> 
  • Move the file to anywhere you want, as long as it can be acccessed by the computer.
  • Load it through the API.
  • Draw!

Example of how to use it:

os.loadAPI(shell.resolve("image"))

term.setBackgroundColor(colours.pink)
term.clear()


local img = image.createImage("data/x.ccimg")
img.x = 3
img:draw()

read("")
term.setBackgroundColor(colours.black)
term.clear()
term.setCursorPos(1, 1)

Screenshots:
Spoiler
NOTE: The white line is caused by me typing, and is NOT an error in the API.

NOTE: The color LIGHT GREY is NOT supported.
NOTE: This might be very buggy. I have not have time to test this alot, but I hope for the best.

Download(Includes API and converter)
PixelToast #2
Posted 14 October 2012 - 09:12 PM
sounds cool but i dont have 1.45 working :C
Mads #3
Posted 15 October 2012 - 07:40 AM
Just download the beta :D/>/>
arronlee #4
Posted 14 May 2013 - 11:08 PM
Thank you for your sharing first.
I will try it later.
But I'm a little confused by your words.
What do yo exactly mean by saying "advanced computers"?
The image can only be displayed on advanced computers?
And what if I'm using an old one?
Mads #5
Posted 15 May 2013 - 10:49 AM
Your real life computer doesn't matter, but you have to use the advanced computer ingame. Look it up on the Wiki.
Pharap #6
Posted 15 May 2013 - 10:07 PM
I've got to give you credit for this one, I've tried several times to learn the file structures of the common image files, but every time I give up and decide I'd have better luck writing my own image formats. May not have fancy multiple colour passes, but at least I can read the damn things. (That image format thing goes for CC images and real computer images).