Jump to content




CC 1.48 CCReadImage


  • You cannot reply to this topic
28 replies to this topic

#1 coranos

  • Members
  • 36 posts

Posted 26 December 2012 - 05:54 AM

Current Version is CCReadImage 1.0 rc6. It will become 1.0 once I fix some bugs.

Bugs in 1.0 rc6
- max white value of Color Changing Wool is less than max white value of actual wool.
- data not saving on server shutdown (server savs it but client doesn't update right)
- can cause an error on a server by setting resolution too high (will have a configurable max resolution, defaults to 64)

Features:
- A Color Changing Wool Peripheral. This peripheral is a block of redstone and wool that will display little blocks inside it. Programmable. Resolution can be set arbitrarily high, but if you render something at resolution 64x64x64 or higher it'll lag a ton.
-- incremental data is sent for incremental updates, about 17 bytes per pixel.A 64x64x64 block would send 4.25 mb of data ((64^3)*17 bytes) for a complete update. a single pixel update sends around 17 bytes, plus minecraft overhead.
-- Recipe is shapeless, of one White Wool, Black Wool, Red Wool, Lime Wool, Blue Wool, Yellow Wool, Brown Wool, and Redstone.

- A Image Reading Turtle Peripheral. This allows you to read an image off of any URL, and have it's pixels returned as either RGB, or as the closest wool color. If the wool color is not close enough to your liking, use the Color Changing Wool peripheral instead of real wool.
-- Recipe requires a Turtle and a Painting.
-- Due to large build requiring lots of wool, which causes a refueling and resupplying problem, this peripheral alchemical converts fuel to and from basic unrefined blocks such as wool, cobblestone, and sand. (can be turned off in the config)

These two peripherals allows you to fill your turtle full of wool and fuel and create giant builds based on pixel art.
If you fill your turtle full of wool, in the standard wool order, this script will give you which slot to use for each pixel in the image:
imageApi = peripheral.wrap("right")
error = imageApi.setUrl(url)
if(error ~= nil) then
print("error loading url:" .. tostring(error))
end
--print("image = " .. imageApi.getWidth() .. "," .. imageApi.getHeight());
woolInventorySlots = {};
for y=1,imageApi.getHeight() do
woolInventorySlots[y] = {}
for x=1,imageApi.getWidth() do
  woolInventorySlots[y][x] = imageApi.getWoolIdYX(x-1,y-1)
end
end

Here's videos of the three scripts I wrote, that make:
1) A picture
2) A statue based on a minecraft skin
3) A 3D statue based on a series of images.

#1 and #2, picture and statue (source picture attached below)


#3 a 3d statue from a series of pictures

Attached Thumbnails

  • Attached Image: sshot.jpg
  • Attached Image: block-screenshot.png

Attached Files



#2 sirdabalot

  • Members
  • 115 posts

Posted 26 December 2012 - 09:35 AM

Looks pretty frikin' good, keep at it. :D

#3 bobster71

  • Members
  • 36 posts

Posted 28 December 2012 - 10:11 AM

THANK YOU!

I had been trying to load a bitmap or any image using CC and never found a way. Even had a few pros look into it and they failed.

Once CClights updates, I can finish my rgb display, might try again now redpowers back and he had updated CClights with 128 pixel lights while I was creating that otherwise it would have been better, can't wait to try it.
Check out

Spoiler

Thanks for the mod.

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 28 December 2012 - 12:17 PM

I've been working a little on reading a bmp since your other thread. I succesfully loaded some bmp images, but it's still a wip. It can load just a few formats and bmp versions, but I'll add support for as many as I can and share it when/if it's ready.

#5 coranos

  • Members
  • 36 posts

Posted 28 December 2012 - 12:44 PM

I'll update to include full source, it should read most formats java reads natively.
For some reason it didn't read gif animations ;/

The two tricky parts are:
1) Java javax.imageio.ImageIO.read() can read most formats.
2) Computercraft can only return strings or numbers, not arrays, so you can't load an image all in one go.
You have to load one image per peripheral, and then read each pixel one by one and create the lua table on the lua side.

#6 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 28 December 2012 - 02:00 PM

View Postcoranos, on 28 December 2012 - 12:44 PM, said:

I'll update to include full source, it should read most formats java reads natively.
For some reason it didn't read gif animations ;/

The two tricky parts are:
1) Java javax.imageio.ImageIO.read() can read most formats.
2) Computercraft can only return strings or numbers, not arrays, so you can't load an image all in one go.
You have to load one image per peripheral, and then read each pixel one by one and create the lua table on the lua side.
You can actually return a Map, and it will be converted to a Lua table.

#7 bobster71

  • Members
  • 36 posts

Posted 28 December 2012 - 11:45 PM

Just a Q, but is this SMP?
I can't get it to work if it is, the turtle disapear. Am I doing something wrong?
Playing around with them in SP, they are really cool.

#8 bobster71

  • Members
  • 36 posts

Posted 28 December 2012 - 11:55 PM

View PostMysticT, on 28 December 2012 - 12:17 PM, said:

I've been working a little on reading a bmp since your other thread. I succesfully loaded some bmp images, but it's still a wip. It can load just a few formats and bmp versions, but I'll add support for as many as I can and share it when/if it's ready.

Thanks, I'm still waiting on CClights to update, (hint to mod maker :) ) but once it has I'll remake my display, I want to watch TV using CC. Can it be done?
mp3 on a CC monitor. I know its not what CC was made for, but I can't help myself. :)

Most prob not, but a huge bmp display would be great, but I'd like to keep it within the MC building blocks. So no huge peripheral already built, ppl still have to build the display and programe it themselves.

Its an old idea I had with laser mod and CC when CC first came out, back in 1.81beta (or later 1.1?) days I think.

Keep it up, I dont have the time to spend on it, it will take some time, but thats what makes MC great, we can do anything.
thanks agin
Bobster

#9 coranos

  • Members
  • 36 posts

Posted 29 December 2012 - 02:01 AM

Hm, watching tv sounds like you either want VLCJ (play tv on a diff computer, and link them) or FMJ(play media).
The hard part will be to get a single frame of the video to display.

#10 coranos

  • Members
  • 36 posts

Posted 29 December 2012 - 02:03 AM

Hm, it worked when I did it locally. Sure your server has the mod as well?

View Postbobster71, on 28 December 2012 - 11:45 PM, said:

Just a Q, but is this SMP?


#11 coranos

  • Members
  • 36 posts

Posted 29 December 2012 - 06:07 AM

hm, I'll see if I can get java working to pull image caps (low res of course, as max size is 128x128)
Looks like there have been a lot of false starts in this area, so may hit a wall quickly.

If it works, I'll also try to incorporate immibis's fix, and have a method that returns all pixels in a lua table.

http://www.xuggle.com/xuggler/

http://build.xuggle....tureFrames.java

#12 bobster71

  • Members
  • 36 posts

Posted 29 December 2012 - 04:23 PM

View Postcoranos, on 29 December 2012 - 02:03 AM, said:

Hm, it worked when I did it locally. Sure your server has the mod as well?

View Postbobster71, on 28 December 2012 - 11:45 PM, said:

Just a Q, but is this SMP?

I did get it working, but I think I was trying for a solar one, or chunck loading one, coz I can't get them working. I can get a wireles image reading turtle working. Soz for any trouble. Setting up a server is a pain in the butt sometimes.

#13 bobster71

  • Members
  • 36 posts

Posted 29 December 2012 - 04:31 PM

View Postcoranos, on 29 December 2012 - 02:01 AM, said:

Hm, watching tv sounds like you either want VLCJ (play tv on a diff computer, and link them) or FMJ(play media).
The hard part will be to get a single frame of the video to display.

I dont want to watch mp3 in mc, but it would still be cool to use as a slideshow in an adventure map. I'm not thinking of a tv in MC, my main idea is a display for pics or any rgb format. CClights is the key. With that and a image reading peripheral you could display pics with ease.

Anyone tried placeing RP2 half blocks with a turtle? I am about to try, I like the idea of pixel art with RP2 small blocks, no one uses them for it. It makes 1/2 size pixel art. Just a thought I had at lunch.


bobster

#14 bobster71

  • Members
  • 36 posts

Posted 29 December 2012 - 04:34 PM

View Postcoranos, on 29 December 2012 - 06:07 AM, said:

hm, I'll see if I can get java working to pull image caps (low res of course, as max size is 128x128)
Looks like there have been a lot of false starts in this area, so may hit a wall quickly.

If it works, I'll also try to incorporate immibis's fix, and have a method that returns all pixels in a lua table.

http://www.xuggle.com/xuggler/

http://build.xuggle....tureFrames.java

wow I saw this a long time ago ( in a galaxy far far away.)

I had the idea of using that, but I didn't have the time to look at it, and my java sux. Not done much prog in it.

bobster

#15 TehSomeLuigi

  • Members
  • 70 posts

Posted 30 December 2012 - 02:42 AM

This is cool. I'm going to install on my server :).

#16 coranos

  • Members
  • 36 posts

Posted 05 January 2013 - 04:51 PM

Quote

You can actually return a Map, and it will be converted to a Lua table.

I've tried doing this, and it doesn't work. The table returns but has no elements in it.
Or are only single dimensional tables supported?

Map<String, Map<String, String>> map = new TreeMap<String, Map<String, String>>();
for (int x = 0; x < width; x++) {
Map<String, String> xMap = new TreeMap<String, String>();
map.put(String.valueOf(x), xMap);
for (int y = 0; y < height; y++) {
  xMap.put(String.valueOf(y), String.valueOf(image.getRGB(x, y) & 0x00FFFFFF));
}
}
return new Object[] { map };


#17 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 05 January 2013 - 09:52 PM

has it really no elements? Or just no numbered elements? You are storing each value as a string here. That means, if you type table[2][3], it will ever be nil as the value would be table["2"]["3"]. You should use java.lang.Integer instead of string, then they will be numbers.

#18 coranos

  • Members
  • 36 posts

Posted 06 January 2013 - 04:34 AM

View PostXfel, on 05 January 2013 - 09:52 PM, said:

has it really no elements? Or just no numbered elements? You are storing each value as a string here. That means, if you type table[2][3], it will ever be nil as the value would be table["2"]["3"]. You should use java.lang.Integer instead of string, then they will be numbers.

This LUA says it returns a table of length zero:
    local rgbValues = imageApi.getValuesRGB()
    print("using rgbValues " .. tostring(rgbValues))
    print("using rgbValues.length " .. tostring(table.getn(rgbValues)))


Do you have a code snippet that returns a table with two elements in it?
I can try debugging through / decompiling the ComputerCraft code, but would prefer not to.

#19 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 06 January 2013 - 06:50 AM

The map has to use integers as the keys if you want to access it like
table[2][4]
You are using strings right now, so you have to access the values like
table["2"]["4"]
So, this would be java-side:
Map<Integer, Map<Integer, Integer>> map = new TreeMap<Integer, Map<Integer, Integer>>();
for (int x = 0; x < width; x++) {
  Map<Integer, Integer> xMap = new TreeMap<Integer, Integer>();
  map.put(x, xMap);
  for (int y = 0; y < height; y++) {
	xMap.put(y, image.getRGB(x, y) & 0x00FFFFFF)
  }
}
Then you can use it like you wanted in lua:
local rgbValues = imageApi.getValuesRGB()
print("Size: ", #rgbValues)
print("First value: ", rgbValues[1][1])


#20 coranos

  • Members
  • 36 posts

Posted 06 January 2013 - 07:39 AM

Ok, the integers worked.
The strings weren't being transferred over. wierd ;/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users