The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Using CairoGraphics to draw directly on VisualWorks Images

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Using CairoGraphics to draw directly on VisualWorks Images Posted: Sep 5, 2008 11:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Using CairoGraphics to draw directly on VisualWorks Images
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

There's been a flurry of work on the CairoGraphics package found in the Open Repository of late. A bunch of small stuff and fixes. And then there's one truly new feature.

We've added (need to stop to give credit here, Michael Lucas-Smith started this effort, he had the idea to try it, and did a lot of the ground work, so thanks go to him) the ability to use Cairo to draw on VisualWorks Image objects.

This is kind of cool. Historically to "draw" on a VisualWorks Image object, you had to convert it to a Pixmap, which allows one to instantiate a GraphicsContext to draw with, and then finally convert back. Now you can draw directly on the bits of the Image.

There are some pretty severe caveats though. Like other VW objects, you use the newCairoContextWhile: message to draw with it. Unless two conditions are met though, it will raise an error.

The first is pretty easy. The bits have to be allocated as a FixedSpace object. There is a useFixedSpaceBits method added to Image which you can use to move its bits into FixedSpace. This can be done on just about any image without negative side affects.

The second is that the palette has to be such that the bits of the Image are in a format that Cairo is happy with. There is a message which provides the transformation, becomeCairoCompatible (which should possibly be better named). This uses the convertToPalette:... message to create a new copy of the image, and then become:'s with the copy. So your image changes in place.

As it currently stands, you should send these two messages to an Image before using the newCairoContextWhile: message. I'm of two minds on this. The one is that these preparatory conversions should be explicit. On the sly, warping side affects, shouldn't happen out the open to surprise the programmer at a later point. The flip position, is that it's a pain to have to do this all the time, and it'd just be easier to have the newCairoContextWhile: automatically promote the Image to work with Cairo.

I'm curious what others think. Should an Image that is hit with Cairo methods automatically be coerced to something that Cairo is happy with? Or should that action be left to the programmer?

Read: Using CairoGraphics to draw directly on VisualWorks Images

Topic: Smalltalk Daily 9/4/08: Using Change Sets Previous Topic   Next Topic Topic: The iTunes Alarm App

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use