This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#101 2012-08-27 08:18:05

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

in fixed_objects.py:

Code:

try:
    import png
except ImportError:
    png = None
    #Trying to import PIL
    try:
        from PIL import Image
    except ImportError:
        Image = None

#line 627
    def save_png(self, path):
        if not path.endswith(".png"): path += ".png"

        #If pypng installed
        if png:
            f = open(path, "wb")
            width, height, rgba_array = self.to_array()
            writer = png.Writer(width, height, alpha=True)
            writer.write_array(f, rgba_array)
            f.flush()
            f.close()

        #if PIL installed
        elif Image:
            width, height, rgba_array = self.to_array()
            im = Image.fromstring("RGBA", (width, height), rgba_array.tostring())
            im.save(path)

        else:
            raise ValueError, "Missing dependency: pypng or PIL needed for " \
                              "PNG support"

not sure if faster cause i don't have pypng, but much more people have PIL than pypng, and its easier to install

also, why not replace the pythonic arrays with numpy?
should be faster  smile

Last edited by roijac (2012-08-27 08:30:52)

Offline

 

#102 2012-08-27 12:59:43

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

roijac wrote:

not sure if faster cause i don't have pypng, but much more people have PIL than pypng, and its easier to install

also, why not replace the pythonic arrays with numpy?
should be faster  smile

Thanks -- I managed to download a copy of PIL, so I'll try it out. I've never used Numpy, but that might be worth a try, too  smile

(The mobile internet where we're staying is sooo slow. I can load one page about every five minutes... We're at the supermarket, so I downloaded the documentation for Numpy & PIL as PDFs  big_smile  )

Last edited by blob8108 (2012-08-27 13:12:27)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#103 2012-08-27 13:15:19

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

roijac wrote:

not sure if faster cause i don't have pypng, but much more people have PIL than pypng, and its easier to install

also, why not replace the pythonic arrays with numpy?
should be faster  smile

Thanks -- I managed to download a copy of PIL, so I'll try it out. I've never used Numpy, but that might be worth a try, too  smile

(The mobile internet where we're staying is sooo slow. I can load one page about every five minutes... We're at the supermarket, so I downloaded the documentation for Numpy & PIL as PDFs  big_smile  )

xD

Offline

 

#104 2012-08-27 13:32:19

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

roijac wrote:

not sure if faster cause i don't have pypng, but much more people have PIL than pypng, and its easier to install

also, why not replace the pythonic arrays with numpy?
should be faster  smile

(The mobile internet where we're staying is sooo slow. I can load one page about every five minutes... We're at the supermarket, so I downloaded the documentation for Numpy & PIL as PDFs  big_smile  )

I just love being in those positions. I like to pickup documentation when we stop for gas or something. Almost done... "DOWNLOAD FASTEEEEE...R."


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#105 2012-08-28 11:55:24

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

MathWizz wrote:

blob8108 wrote:

(The mobile internet where we're staying is sooo slow. I can load one page about every five minutes... We're at the supermarket, so I downloaded the documentation for Numpy & PIL as PDFs  big_smile  )

I just love being in those positions. I like to pickup documentation when we stop for gas or something. Almost done... "DOWNLOAD FASTEEEEE...R."

Hehe  tongue

Presumably you live in one of those countries that has wifi hotspots *everywhere*? /jealous


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#106 2012-08-28 11:56:20

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

MathWizz wrote:

blob8108 wrote:

(The mobile internet where we're staying is sooo slow. I can load one page about every five minutes... We're at the supermarket, so I downloaded the documentation for Numpy & PIL as PDFs  big_smile  )

I just love being in those positions. I like to pickup documentation when we stop for gas or something. Almost done... "DOWNLOAD FASTEEEEE...R."

Hehe  tongue

Presumably you live in one of those countries that has wifi hotspots *everywhere*? /jealous

Just about. xD


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#107 2012-08-28 12:06:32

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

Hardmath123 wrote:

Err... an embarrassingly nonsecure socket-based chat.

Oh, like a telnet chat thing? Cool! Your next challenge is to make a MUD/multiplayer text-based game...  wink

Have you done the competition-thing yet?

Oh, and cool: you're a curator!  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#108 2012-08-28 12:20:44

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

Hardmath123 wrote:

Err... an embarrassingly nonsecure socket-based chat.

Oh, like a telnet chat thing? Cool! Your next challenge is to make a MUD/multiplayer text-based game...  wink

... I'll try.

Have you done the competition-thing yet?

What, the one I was ranting about or the AI one that died a month ago? If it's the prior, I'm just about to post the outcome at the MaC forums.  smile

Oh, and cool: you're a curator!  smile

Thanks!  big_smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#109 2012-08-28 13:26:32

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

Hardmath123 wrote:

blob8108 wrote:

Have you done the competition-thing yet?

What, the one I was ranting about or the AI one that died a month ago? If it's the prior, I'm just about to post the outcome at the MaC forums.  smile

The prior, of course  tongue  (I still think we should have that competition, even if it's just you and me...)

EDIT: I finally made the wi-fi here work! Not that it's much quicker...  tongue

Last edited by blob8108 (2012-08-28 13:29:12)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#110 2012-08-28 13:41:32

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: kurt — Scratch file format Python library

@blob8108, you should add this line to you scratchblocks test:

Code:

code.onchange = refresh;

tongue


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#111 2012-08-28 13:46:55

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

MathWizz wrote:

@blob8108, you should add this line to you scratchblocks test:

Code:

code.onchange = refresh;

tongue

Oh, cool! Someone noticed that  tongue

Why should I add that? I don't understand... How would that help?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#112 2012-08-28 14:16:05

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

A quick update: I just made a single optimization to Kurt which made saving 150x faster: from about 12 minutes (literally!) to 5 seconds. *

This is just the saving step, project.save(). Things like compiling the project, parsing scratchblocks and loading images add several more seconds -- it mainly depends on how many images you have.

And I still have images yet to optimize!

In case you're interested: Scratch stores everything in an Object Table, which is basically a list of all the objects. When objects are found as properties of other objects, they get encoded as references to an index in the list. The change I made was to temporarily store the index on the object itself, rather than search through the list, comparing it with each object (which is really slow, as you can imagine...)



* these tests were run with my roads project, which has a single script that's 600 lines long...


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#113 2012-08-28 14:22:05

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

MathWizz wrote:

@blob8108, you should add this line to you scratchblocks test:

Code:

code.onchange = refresh;

tongue

Oh, cool! Someone noticed that  tongue

Why should I add that? I don't understand... How would that help?

Live updating blocks.  big_smile

@update awesome!


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#114 2012-08-28 14:31:22

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

A quick update: I just made a single optimization to Kurt which made saving
And I still have images yet to optimize!

i tested pypng vs PIL, pypng is ~1 second faster on saving 1000 images, and i still believe numpy would be much faster  smile

Offline

 

#115 2012-08-28 14:39:08

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

MathWizz wrote:

blob8108 wrote:

MathWizz wrote:

@blob8108, you should add this line to you scratchblocks test:

Code:

code.onchange = refresh;

tongue

Oh, cool! Someone noticed that  tongue

Why should I add that? I don't understand... How would that help?

Live updating blocks.  big_smile

It should already do that...  ._.

EDIT: (checks) Yeah, it does for me. What are you using...?

Last edited by blob8108 (2012-08-28 14:52:33)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#116 2012-08-28 14:41:54

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

roijac wrote:

i tested pypng vs PIL, pypng is ~1 second faster on saving 1000 images, and i still believe numpy would be much faster  smile

Thanks for testing that! I'm very surprised that PyPNG is faster -- I thought it was pure-Python, so I was expecting it to be much slower.

Have you also tested reading images? That's almost more important...

And yes, I'm definitely going to see if I can make image-y things faster using Numpy  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#117 2012-08-28 15:00:22

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

roijac wrote:

i tested pypng vs PIL, pypng is ~1 second faster on saving 1000 images, and i still believe numpy would be much faster  smile

Thanks for testing that! I'm very surprised that PyPNG is faster -- I thought it was pure-Python, so I was expecting it to be much slower.

Have you also tested reading images? That's almost more important...

And yes, I'm definitely going to see if I can make image-y things faster using Numpy  smile

where are those scripts?
couldn't find the import part  wink

Offline

 

#118 2012-08-28 15:14:09

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

roijac wrote:

blob8108 wrote:

roijac wrote:

i tested pypng vs PIL, pypng is ~1 second faster on saving 1000 images, and i still believe numpy would be much faster  smile

Thanks for testing that! I'm very surprised that PyPNG is faster -- I thought it was pure-Python, so I was expecting it to be much slower.

Have you also tested reading images? That's almost more important...

And yes, I'm definitely going to see if I can make image-y things faster using Numpy  smile

where are those scripts?
couldn't find the import part  wink

Form.load_png -- see fixed_objects.py, line 673.

EDIT: line numbers are different in the latest version on Github (on the scratchblocks branch) to my version, of course...  tongue

Last edited by blob8108 (2012-08-28 15:16:40)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#119 2012-08-28 15:34:14

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

roijac wrote:

blob8108 wrote:

Thanks for testing that! I'm very surprised that PyPNG is faster -- I thought it was pure-Python, so I was expecting it to be much slower.

Have you also tested reading images? That's almost more important...

And yes, I'm definitely going to see if I can make image-y things faster using Numpy  smile

where are those scripts?
couldn't find the import part  wink

Form.load_png -- see fixed_objects.py, line 673.

EDIT: line numbers are different in the latest version on Github (on the scratchblocks branch) to my version, of course...  tongue

oh i see
but the code is way to complicated for my understanding of pngs  hmm

btw, you should check your code with pylint from time to time...  tongue

Last edited by roijac (2012-08-28 15:43:51)

Offline

 

#120 2012-08-28 21:12:35

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

Hardmath123 wrote:

blob8108 wrote:

Have you done the competition-thing yet?

What, the one I was ranting about or the AI one that died a month ago? If it's the prior, I'm just about to post the outcome at the MaC forums.  smile

The prior, of course  tongue  (I still think we should have that competition, even if it's just you and me...)

Agreed. Too many cooks cook too much.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#121 2012-08-28 21:22:27

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: kurt — Scratch file format Python library

Hardmath123 wrote:

blob8108 wrote:

Hardmath123 wrote:


What, the one I was ranting about or the AI one that died a month ago? If it's the prior, I'm just about to post the outcome at the MaC forums.  smile

The prior, of course  tongue  (I still think we should have that competition, even if it's just you and me...)

Agreed. Too many cooks cook too much.

But I'm HUNGRY. D:


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#122 2012-08-29 11:52:23

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

roijac wrote:

btw, you should check your code with pylint from time to time...  tongue

Why is that...? What's funny?  tongue

MathWizz wrote:

Hardmath123 wrote:

blob8108 wrote:

(I still think we should have that competition, even if it's just you and me...)

Agreed. Too many cooks cook too much.

But I'm HUNGRY. D:

xD


Did you see this...?

blob8108 wrote:

MathWizz wrote:

Live updating blocks.  big_smile

It should already do that...  ._.

EDIT: (checks) Yeah, it does for me. What are you using...?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#123 2012-08-29 11:53:21

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

roijac wrote:

btw, you should check your code with pylint from time to time...  tongue

Why is that...? What's funny?  tongue

tongue   tongue   tongue   tongue


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#124 2012-09-03 12:18:19

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

I think I've worked through most of the bugs, and it seems pretty solid! Can't wait to release it tomorrow...  big_smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#125 2012-09-03 12:31:53

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: kurt — Scratch file format Python library

Nice!  Congrats!  I can't wait to check it out!

Offline

 

Board footer