Jump to content




[MC 1.4.7][CC1.481][Version: 1.4.1] CCLights! Bug fix!

peripheral java utility

144 replies to this topic

#121 Goz3rr

  • Members
  • 7 posts

Posted 10 February 2013 - 03:10 AM

Here's some code to pull images from the internet, and display them on a CCLights peripheral:

local args = {...}

function split(str, pat)
   local t = {}
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
      if s ~= 1 or cap ~= "" then
	 table.insert(t,cap)
      end
      last_end = e+1
      s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
      cap = str:sub(last_end)
      table.insert(t, cap)
   end
   return t
end

if #args == 0 then
  print("No link!")
else
  http.request("http://goz3rr.kuubstudios.com/image2text.php?url=" .. table.concat(args, "%20"))
  local requesting = true
  while requesting do
    local event, url, sourceText = os.pullEvent()
    if event == "http_success" then
      local data = split(sourceText.readAll(),",")
	  local status = tonumber(data[1])
      if status == 1 then
		local width = tonumber(data[2])
		local height = tonumber(data[3])
		if width > 0 and height > 0 then
          print("Received image with resolution: " .. width .. "x" .. height)
		  local oldx, oldy = term.getCursorPos()
		  local screen = peripheral.wrap("left")
		  screen.fill(255, 255, 255)
		  local index = 4
		  local pixel = 0
		  for x = 1, width do
		    for y = 1, height do
			  local r = tonumber(data[index])
			  local g = tonumber(data[index+1])
			  local b = tonumber(data[index+2])
			  screen.setColorRGB(r, g, b, x, y)
              screen.setColorRGB(r, g, b, x, y)
			  index = index + 3
			  pixel = pixel + 1
			end
			
			if pixel > 65536 then	
                          pixel = 0	              
			  coroutine.yield() -- yield every now and then, 256x256 and lower images should load instantly
			end
		  end
        end
	  elseif status == 0 then
		print("Server returned error code 0x" .. data[2])
	  else
	    print("An unknown error occured")
	  end
      requesting = false
    elseif event == "http_failure" then
      print("Server didn't respond.")
      requesting = false
    end
  end
end

The only arguments the program takes is the URL.

#122 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 10 February 2013 - 09:31 AM

View Posttiin57, on 16 November 2012 - 11:27 AM, said:

View Postds84182, on 16 November 2012 - 11:18 AM, said:

View Postkaj, on 16 November 2012 - 08:07 AM, said:

One thing i can think of is maybe make the pixels start at 1 instead of zero - so as to be more consistent with the CCterminal.
I could make a config option to make pixels start at 1 :P/>
You ought to do that by default; starting at 0 is a Java thing, not Lua. Lua starts at 1.

Starting at 0 is an everything but Lua thing.

#123 ds84182

  • Members
  • 184 posts

Posted 13 February 2013 - 05:13 AM

View PostMads, on 10 February 2013 - 09:31 AM, said:

View Posttiin57, on 16 November 2012 - 11:27 AM, said:

View Postds84182, on 16 November 2012 - 11:18 AM, said:

View Postkaj, on 16 November 2012 - 08:07 AM, said:

One thing i can think of is maybe make the pixels start at 1 instead of zero - so as to be more consistent with the CCterminal.
I could make a config option to make pixels start at 1 :P/>/>
You ought to do that by default; starting at 0 is a Java thing, not Lua. Lua starts at 1.

Starting at 0 is an everything but Lua thing.
And you would really bring that up now?

#124 ds84182

  • Members
  • 184 posts

Posted 13 February 2013 - 05:16 AM

View PostGoz3rr, on 10 February 2013 - 03:10 AM, said:

Here's some code to pull images from the internet, and display them on a CCLights peripheral:

-snip-

The only arguments the program takes is the URL.
That's awesome! I'm going to have to make a program to go through imgur albums!

#125 absorr

  • Members
  • 41 posts
  • LocationUnited States

Posted 16 February 2013 - 10:31 AM

Hi, I would like to add your mod into a Tekkit addon I am making called the Hackers' Modkit. The modkit is all about adding more things for programming lovers to be able to do more with their code within Tekkit Lite. It will be an addon through the new custom zip feature in the Technic Launcher. You will, of course, be given the proper credit for your mod. I hope to hear from you soon with your reply!

#126 Hadley

  • New Members
  • 1 posts

Posted 17 February 2013 - 03:34 PM

It looks like the latest version of CCLights has an awful memory leak. I was having trouble on a server with a custom modpack composed of about 40 different mods, but by process of elimination I've tracked the leak down to this mod.

If you hit F3 and look at the "Used memory" in the corner, with CCLights installed it grows at around a gigabyte or so per second, and is causing a significant drop in performance as Java has to clean up after it. When I remove only this mod and leave the other 40+ mods running, it instead grows at about 5MB a second.

This even happens on a freshly-generated singleplayer server, in which there are no computers around, much less CCLights displays.

#127 Kye_Duo

  • Members
  • 70 posts

Posted 18 February 2013 - 04:01 AM

View PostHadley, on 17 February 2013 - 03:34 PM, said:

It looks like the latest version of CCLights has an awful memory leak. I was having trouble on a server with a custom modpack composed of about 40 different mods, but by process of elimination I've tracked the leak down to this mod.

If you hit F3 and look at the "Used memory" in the corner, with CCLights installed it grows at around a gigabyte or so per second, and is causing a significant drop in performance as Java has to clean up after it. When I remove only this mod and leave the other 40+ mods running, it instead grows at about 5MB a second.

This even happens on a freshly-generated singleplayer server, in which there are no computers around, much less CCLights displays.
I can confirm this as well.
I'd love to use this mod but can't because of this mem leak...(personally I wonder if its your super animated textures for the items when they are in inventory)

#128 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 18 February 2013 - 08:40 AM

There are some series bugs in CCLights which ds is fixing in CCLights 2.
You may want to find that forum topic and look out for a release.

#129 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 19 February 2013 - 01:32 AM

Just to clarifiy, ds knows what is causing the bugs; they will be fixed in CCLights2.

#130 iownall555

  • Members
  • 54 posts

Posted 19 February 2013 - 09:00 PM

http://www.computerc...-wip-cclights2/

For anyone who wants the link.

#131 amtra5

  • Members
  • 166 posts
  • LocationMelbourne, Australia

Posted 04 March 2013 - 12:58 AM

If you could make the screen touch, someone is going to make MCPE :P

#132 Shnupbups

  • Members
  • 596 posts
  • LocationThat place over there. Y'know. The one where I am.

Posted 05 March 2013 - 07:09 PM

View Postamtra5, on 04 March 2013 - 12:58 AM, said:

If you could make the screen touch, someone is going to make MCPE :P
Touch screens will be in CCLights2

#133 ds84182

  • Members
  • 184 posts

Posted 09 March 2013 - 08:59 AM

View Postabsorr, on 16 February 2013 - 10:31 AM, said:

Hi, I would like to add your mod into a Tekkit addon I am making called the Hackers' Modkit. The modkit is all about adding more things for programming lovers to be able to do more with their code within Tekkit Lite. It will be an addon through the new custom zip feature in the Technic Launcher. You will, of course, be given the proper credit for your mod. I hope to hear from you soon with your reply!
I am going to have to turn this down. I don't want my mod to be in Tekkit.

#134 vScourge

  • Members
  • 7 posts

Posted 18 March 2013 - 08:49 AM

Does anyone have a fix/workaround for the big leak/slowdown with the latest CCLights build? Or a link to the previous build? I'd love to use this mod but see no way to do so at the moment.

#135 Kye_Duo

  • Members
  • 70 posts

Posted 18 March 2013 - 08:51 AM

no...but the author is working on a 2.0 version

#136 Campagnol

  • New Members
  • 1 posts

Posted 18 March 2013 - 10:29 AM

Hi!
I discovered this mod a while ago but unfortunately, I can't found a way to turn my pictures into a CCLights file.
Does someone have an idee or maybe THE solution ;-)
Good evening!
Campagnol

#137 Goz3rr

  • Members
  • 7 posts

Posted 20 March 2013 - 10:44 AM

View PostCampagnol, on 18 March 2013 - 10:29 AM, said:

Hi!
I discovered this mod a while ago but unfortunately, I can't found a way to turn my pictures into a CCLights file.
Does someone have an idee or maybe THE solution ;-)
Good evening!
Campagnol

- Use my program at the top of the page
- Write a program that reads actual image files (I think if you just open an image file in computercraft, it will read the actual bytes)
- Use the CCImage addon, i think it can load image files and then you can get the color data
- Write an external program that converts image files, then read that file with a cc program

#138 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 21 March 2013 - 04:44 AM

touch screen would make a windows 8 emulator actually possible
c_c
would take alot of rendering code though

#139 Flenix

  • New Members
  • 2 posts

Posted 13 April 2013 - 12:03 AM

View Postds84182, on 15 November 2012 - 12:28 PM, said:

Photoshoot (AKA Screenies AKA Screenshots)
Spoiler

How did you load up images like that? I can't imagine you doing those screenshots pixel by pixel...

#140 ds84182

  • Members
  • 184 posts

Posted 13 April 2013 - 07:08 AM

View PostFlenix, on 13 April 2013 - 12:03 AM, said:

View Postds84182, on 15 November 2012 - 12:28 PM, said:

Photoshoot (AKA Screenies AKA Screenshots)
Spoiler

How did you load up images like that? I can't imagine you doing those screenshots pixel by pixel...
Somewhere in the 7 pages, I said how. Please try to find it and your question is answered.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users