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

CC 1.48 CCReadImage

Started by coranos, 26 December 2012 - 04:54 AM
coranos #1
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)
[media]http://www.youtube.com/watch?v=8HccmLNYxZY[/media]

#3 a 3d statue from a series of pictures
[media]http://youtu.be/-q5LcARRI30[/media]
sirdabalot #2
Posted 26 December 2012 - 09:35 AM
Looks pretty frikin' good, keep at it. :D/>
bobster71 #3
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[media]http://www.youtube.com/watch?v=e6nfSW4xmtk[/media]

Thanks for the mod.
MysticT #4
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.
coranos #5
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.
immibis #6
Posted 28 December 2012 - 02:00 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.
You can actually return a Map, and it will be converted to a Lua table.
bobster71 #7
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.
bobster71 #8
Posted 28 December 2012 - 11:55 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.

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
coranos #9
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.
coranos #10
Posted 29 December 2012 - 02:03 AM
Hm, it worked when I did it locally. Sure your server has the mod as well?

Just a Q, but is this SMP?
coranos #11
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.com/view/Stable/job/xuggler_jdk5_stable/ws/workingcopy/src/com/xuggle/mediatool/demos/DecodeAndCaptureFrames.java
bobster71 #12
Posted 29 December 2012 - 04:23 PM
Hm, it worked when I did it locally. Sure your server has the mod as well?

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.
bobster71 #13
Posted 29 December 2012 - 04:31 PM
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
bobster71 #14
Posted 29 December 2012 - 04:34 PM
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
TehSomeLuigi #15
Posted 30 December 2012 - 02:42 AM
This is cool. I'm going to install on my server :)/>.
coranos #16
Posted 05 January 2013 - 04:51 PM
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) &amp; 0x00FFFFFF));
}
}
return new Object[] { map };
Xfel #17
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.
coranos #18
Posted 06 January 2013 - 04:34 AM
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.
MysticT #19
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) &amp; 0x00FFFFFF)
  }
}
Then you can use it like you wanted in lua:

local rgbValues = imageApi.getValuesRGB()
print("Size: ", #rgbValues)
print("First value: ", rgbValues[1][1])
coranos #20
Posted 06 January 2013 - 07:39 AM
Ok, the integers worked.
The strings weren't being transferred over. wierd ;/
thanke #21
Posted 08 January 2013 - 02:18 AM
Hi all. Does somebody have the same problem :
Is single player, i can place a "color changing whool" without any problem but once in MP, it disapears immediatly after i place it. (i use a local server for testing so every mods have same version)
coranos #22
Posted 08 January 2013 - 03:05 AM
Hm, I may not have written it right for MP.
For some reason the tile entity used to render the block isn't the same tile entity used to run the program. (I think one's server side one's client side)
coranos #23
Posted 08 January 2013 - 06:01 PM
Anyone have any sample code for updating the client from the server?
I can get it to save and load, and I added this code to send a message to the client:

	    Side side = FMLCommonHandler.instance().getEffectiveSide();
	    if (side == Side.SERVER) {
		    FMLServerHandler.instance().sendPacket(getDescriptionPacket());
	    }
I just can't figure out how to get from there to onDataPacket() on the client.

Am I even doing it the right way?
coranos #24
Posted 08 January 2013 - 06:12 PM
nevermind figured it out.
I've added a new version, should work in multiplayer, but it's SUPER laggy as it sends the entire block every time.
Will optimize that.
thanke #25
Posted 09 January 2013 - 02:47 AM
Yeah. It works :-). Thanks a lot. I'm writing program to transform a computer into multichannel wireless redstone and display the frequency on the top using your mod :-)
columna1 #26
Posted 21 January 2013 - 01:53 PM
You know i like this mod and i have downloaded almost every version to date but…
you seem to have stopped updating your mod and I am saddened by that fact…
I liked using your mod and making cool things with it and i wish that it would not fall and become a dead project.
I would love to see what you come up with next and what cool things you have planned for the newer updates so,
I guess I'm kinda cheering you on right now :3
So thank you for your peripheral and i hope to see more
-columna1-
bobster71 #27
Posted 11 February 2013 - 01:14 PM
Hey, I got your mod to work with cclights on my server finanlly. I have a question, the rgb values it returns represent what? hex? I"m lost.
Is there a way to convert it to a rgb to use to cclights?
I'm not sure what's being return by getValuesRGBXY()…
thanks
Bobster71
absorr #28
Posted 15 February 2013 - 04:33 AM
The config file creates itself but it is just blank! I don't think that is supposed to happen.
coranos #29
Posted 17 March 2013 - 07:22 AM
I took a hiatus until1.5 came out. I'll be updating the mod presently.

Sorry I dropped off the earth for a few months, I started playing Volts, and now Starcraft.

Btw I wouldn't call it a dead mod, It's just nearly complete.