well, glad to be here again. i've pushed all my changes over the
last week. they are all related to images and image blocks. images
are much improved and enhanced. image blocks are still catching.
a summary.
-* images and image blocks are just: images *-
previously, i had an Image class and an ImageBlock class. now,
there is only Image.
previously, an Image was a surface of pixels. now an Image is a
reference to a cached object or a reference to a surface of pixels.
an ImageBlock was a type of canvas, but i realized that was bad
because it means all these objects get created, killing memory.
-* drawing on images *-
@icon = image "static/shoes-icon.png"
@icon.oval(0, 0, 128, :fill => red)
normally, when you draw an oval on to a canvas, it creates a Shape
object representing the oval. when you draw onto an image, it draws
the oval directly on the image, no object is created.
-* altering image pixels *-
to get a pixel:
@icon[left, top]
#=> color or pattern
to set a pixel:
@icon[left, top] = color or pattern.
to turn an image red, but respect the alpha channel of each pixel:
@icon = image "static/shoes-icon.png"
@icon.full_width.times do |x|
@icon.full_height.times do |y|
@icon[x, y] = red(@icon[x, y].alpha)
end
end
-* blank images *-
a 128 x 128 blank:
@icon = image 128, 128
-* auto-dup of images *-
if you load an image from the hard drive or over http, you can draw
on that image (like in the pixel examples above.) the memory and
disk caches though will keep the original image. once you start
drawing on an image, its pixels get dup'd safely behind the scenes.
@icon = image "static/shoes-icon.png"
@icon.oval(0, 0, 128, :fill => red)
@icon2 = image "static/shoes-icon.png"
so, the image is only loaded once. @icon is a red silhouette of the
image. and @icon2 is the original image.
-* nicer 1px lines *-
i did some debugging and figured out why cairo was drawing fuzzy 1
pixel lines. it turns out that for odd-numbered stroke widths, you
have to offset the (x, y) coordinates by 0.5. so, you should see
crisper lines on your lines and shapes.
-* caveats *-
first of all, image blocks aren't completely back in business.
nor effects. i am still working on effects.
lines are having some issue, too. (i noticed simple-mask.rb is
busted.)
_why