Mem_inspect and png

I’m pleased to announce to new libraries written by members of the
Seattle Ruby Brigade, mem_inspect and png!

===

mem_inspect is ObjectSpace.each_object on crack. mem_inspect gives
you the contents of each slot in Ruby’s heap. mem_inspect also
includes viewers that let you visualize the contents of Ruby’s heap.

To install:

$ sudo gem install mem_inspect

Then you’ll need to build a patched ruby:

ruby_mem_inspect_build

You’ll then have a ruby capable of running mem_inspect in
mem_inspect_ruby_1_8.

You can make an image with:

mem_inspect_ruby_1_8/ruby_mem_inspect -S ruby_mem_dump

Which will give you a PNG in your current directory named:

mem_inspect.PID.TIMESTAMP.png

You’ll get an image that looks something like this:

Memory Map | BLACK: unknown (char *, VALUE *, struct st_tabl… | Flickr

Bigger:

All sizes | Memory Map | Flickr - Photo Sharing!

To dump a PDF any time you want:

require ‘meminspect/png_viewer’

MemInspect::PNGViewer.new(1024, 768).draw

You can also dump to an AquaTerm plot window if you have RubyCocoa
and AquaTerm installed.

require ‘meminspect/aquaterm_viewer’

MemInspect::AquatermViewer.new(1024, 768).draw

===

png is a pure-ruby PNG writing library written by Ryan D…

To install:

$ sudo gem install png

To use:

require ‘png’

canvas = PNG::Canvas.new 200, 200

Set a point to a color

canvas[100, 100] = PNG::Color::Black

draw an anti-aliased line

canvas.line 50, 50, 100, 50, PNG::Color::Blue

png = PNG.new canvas
png.save ‘blah.png’


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

On Aug 31, 2006, at 5:46 PM, Eric H. wrote:

canvas = PNG::Canvas.new 200, 200

Set a point to a color

canvas[100, 100] = PNG::Color::Black

draw an anti-aliased line

canvas.line 50, 50, 100, 50, PNG::Color::Blue

png = PNG.new canvas
png.save ‘blah.png’

I’m lovin’ that. Too cool!

James Edward G. II

Eric H. wrote:

png is a pure-ruby PNG writing library written by Ryan D…

To install:

$ sudo gem install png

To use:

require ‘png’

canvas = PNG::Canvas.new 200, 200

Set a point to a color

canvas[100, 100] = PNG::Color::Black

draw an anti-aliased line

canvas.line 50, 50, 100, 50, PNG::Color::Blue

png = PNG.new canvas
png.save ‘blah.png’


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

Is there a website for it? Maybe an rDoc page? I’d like to know some
things like ‘Does it draw dashed/dotted lines?’ etc.

RMagick does, but it has a little glitch where if the last dash on a
line isn’t whole, it doesn’t draw it. (At least in my playing with it
so far.) I think I can work around it, but if I can find a library that
works better, I’ll use that instead.

If you’re wondering why it matters so much, I’m making a very very very
simple little plaid design creator in ruby. The dashed lines are used
to simulate the weaving of the threads. The upper and left edges are
smooth, but the right and bottom edges aren’t, because of this bug. I
think I can simply draw over the edge of the canvas and fix it, but I
haven’t gotten around to trying yet. Being able to simply draw it
correctly without hacks would be much better.

I could, of course, draw it pixel by pixel, but I think that’d be quite
a bit slower.

On 9/1/06, William C. [email protected] wrote:

line isn’t whole, it doesn’t draw it. (At least in my playing with it
so far.) I think I can work around it, but if I can find a library that
works better, I’ll use that instead.

If you’re wondering why it matters so much, I’m making a very very very
simple little plaid design creator in ruby. The dashed lines are used
to simulate the weaving of the threads. The upper and left edges are
smooth, but the right and bottom edges aren’t, because of this bug. I
think I can simply draw over the edge of the canvas and fix it, but I
haven’t gotten around to trying yet. Being able to simply draw it
correctly without hacks would be much better.

I think that drawing over the edge would be simplest – you can set
the clip so you don’t have to fix it later:
http://www.imagemagick.org/RMagick/doc/draw.html#clip_path

If you’re using RVG, there’s the same thing:
http://www.imagemagick.org/RMagick/doc/rvgclip.html

But anyway, cool work with the PNG library!

-RYaN

Ryan W. wrote:

I think that drawing over the edge would be simplest – you can set
the clip so you don’t have to fix it later:
http://www.imagemagick.org/RMagick/doc/draw.html#clip_path
-RYaN

Thanks, I figured out I could tell it to draw over the edge and it’d
work fine.

But then I came to another problem with rmagick. If you tell it to draw
the dashed line with 2 on and 2 off, it draws 3 on and 1 off. I think
it has something to do with aliasing or something. It’s a pain, anyhow.
So I’m probably going to try drawing each pixel individually, or
switching this new PNG library and see if that draws what I need.
(Pixel by pixel.)

On Sep 1, 2006, at 3:28 AM, William C. wrote:

Eric H. wrote:

png is a pure-ruby PNG writing library written by Ryan D…

Is there a website for it? Maybe an rDoc page? I’d like to know some
things like ‘Does it draw dashed/dotted lines?’ etc.

Not yet. Its really small so:

$ sudo gem install png
$ ri -l | grep PNG
[…]
PNG::Canvas#line
[…]
$ ri PNG::Canvas#line
------------------------------------------------------- PNG::Canvas#line
line(x0, y0, x1, y1, color)

  Draws a line using Xiaolin Wu's antialiasing technique.

  http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm\

(In short, no.)

quite
a bit slower.

PNG draws pixel by pixel.


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

On Sep 2, 2006, at 7:13 PM, Harold H. wrote:

On 9/1/06, Eric H. [email protected] wrote:

I’m pleased to announce to new libraries written by members of the
Seattle Ruby Brigade, mem_inspect and png!

png is a pure-ruby PNG writing library written by Ryan D…

File.open on windows needs to be explicitly told to be binary. Adding
the magic ‘b’ here got me going on win32:

Yes, I’ve fixed this in the source repository.


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

On 9/1/06, Eric H. [email protected] wrote:

I’m pleased to announce to new libraries written by members of the
Seattle Ruby Brigade, mem_inspect and png!

png is a pure-ruby PNG writing library written by Ryan D…

File.open on windows needs to be explicitly told to be binary. Adding
the magic ‘b’ here got me going on win32:

Writes the PNG to +path+.

def save(path)
# Hooray, magic ‘b’ !
File.open(path, “wb”) do |f|

end
end

#Thanks for this cool lib
-Harold