ANN: AC-Vector, AC-Colour and AC-EasyRaster-GTK

OK, so having released AC-HalfInteger, I got slightly carried away and released three other small packages. These are packages that many programs I write all end up using. I'm forever copying these files, so I made them into actual bonafide packages. http://hackage.haskell.org/package/AC-Vector-1.1.1 This provides two types, Vector2 and Vector3, which are unboxed vectors of Doubles, with arithmetic, dot product and cross product, and a few other useful items. http://hackage.haskell.org/package/AC-Colour-1.1.1 This provides two types, Colour and Colour8. Both implement simple RGB colour types with arithmetic. Colour has unboxed Double fields, and Colour8 has unboxed Word8 fields. My usual workflow is to do all the image generation with Colour, and to convert to Colour8 just before the data hits the I/O channels. You can, however, do arithmetic directly on Colour8. (I haven't extensively tested that it works properly though...) http://hackage.haskell.org/package/AC-EasyRaster-GTK-1.1.1 This is a layer over Gtk2hs. As you all probably know, Gtk2hs provides a Cairo binding that makes vector graphics wonderfully easy. However, *bitmapped* graphics is darned tricky. I basically had to sit in the #haskell channel with Duncan for a few hours trying to figure out how the hell to do it. This knowledge is now codified in the above package. Load it up and you don't need to know a thing about GTK; you can just create an ImageBuffer, write some pixels to it (efficiently!), save it to disk or display it on screen. (But you *can* access the underlying GTK+ resources if you wish...) In other news, it appears that the batch job to generate the documentation just ran, so you can view it all online. :-D Comments, suggestions, random flames, etc... [I'm particularly curios to know what Duncan will make of the GTK thing...]

On Sat, Jul 04, 2009 at 06:56:44PM +0100, Andrew Coppin wrote:
Why don't you use colour[1]? [1] http://hackage.haskell.org/package/colour -- Felipe.

Felipe Lessa wrote:
On Sat, Jul 04, 2009 at 06:56:44PM +0100, Andrew Coppin wrote:
Why don't you use colour[1]?
A few reasons: 1. I never knew it existed. ;-) 2. It's mind-blowingly complex. 3. It doesn't appear to provide arithmetic over colours. 4. It's parameterised over the component type; my library is hard-coded to specific types for speed.

On Sat, Jul 4, 2009 at 8:38 PM, Andrew
Coppin
A few reasons:
1. I never knew it existed. ;-)
A good reason. However, it's good to do a quick search over Hackage before uploading (or before writing) so you know what's out there. Also, if you hadn't used an "AC-" prefix, you'd have had a name collision. Is there a particular reason why you want your name in the package name rather than just the author field?
2. It's mind-blowingly complex.
Colour *is* complex. Which is why I'm so glad Russell O'Connor did all the hard work for me :)
3. It doesn't appear to provide arithmetic over colours.
It provides darken, blend and addition (though addition is called mappend rather than (+)). signum, abs and fromInteger don't make a huge amount of sense for colours.
4. It's parameterised over the component type; my library is hard-coded to specific types for speed.
My feeling would be to trust the specializer until it lets me down. Has it let you down in the past? BTW, the EasyRaster package looks useful. --Max

Max Rabkin wrote:
On Sat, Jul 4, 2009 at 8:38 PM, Andrew Coppin
wrote: A few reasons:
1. I never knew it existed. ;-)
A good reason. However, it's good to do a quick search over Hackage before uploading (or before writing) so you know what's out there.
Fair enough. ;-)
Also, if you hadn't used an "AC-" prefix, you'd have had a name collision. Is there a particular reason why you want your name in the package name rather than just the author field?
Well, for example, there's seemingly half a dozen unrelated packages all called "binary", which is just confusing. I wanted to make sure my packages had unique names. (I mean, so do the existing binary packages, just not very useful ones...)
2. It's mind-blowingly complex.
Colour *is* complex. Which is why I'm so glad Russell O'Connor did all the hard work for me :)
Well, no, because now I'm going to have to spend a few hours trying to find out what CIE is before I can even use that library. I think really it's just aimed at a different problem. It looks like it's trying to specify actual real-world colours. [It's news to me that this isn't fundamentally impossible...] I'm only trying to specify colours on a computer screen. And as we all know, computer screens aren't calibrated in any way, and the same RGB value looks different on each display. But then, I'm only trying to write a fractal generator, so CIE specifications are somewhat overkill here. ;-)
3. It doesn't appear to provide arithmetic over colours.
It provides darken, blend and addition (though addition is called mappend rather than (+)). signum, abs and fromInteger don't make a huge amount of sense for colours.
Yeah, I implemented signum and so forth for colours and vectors, but they're not particularly meaningful... [Insert remark here about Haskell's numeric class hierachy.] So mappend gives you colour addition [with the perplexing comments about "gamut", presumably some kind of small mammal?], but there's no subtraction? No multiplication? No linear blending?
4. It's parameterised over the component type; my library is hard-coded to specific types for speed.
My feeling would be to trust the specializer until it lets me down. Has it let you down in the past?
Heh, my colour library includes a custom floor implementation that talks to the GHC primops directly because calling floor is too slow... [In case that sounds like idle talk, I had a program go from 10 seconds to less than 1 second just by using this function. There's a few tickets about it on the GHC Trac.]
BTW, the EasyRaster package looks useful.
Well, I'd like to think so... It doesn't do anything you couldn't do yourself if you spend a day or two trying to grok the GTK complexity. But it's much easier to just import some code somebody else has already written. ;-) Certainly when I'm in the middle of trying to build a complicated bit of software, figuring out how to just write a few pixels onto the screen is a low priority.

On Sat, Jul 4, 2009 at 9:18 PM, Andrew
Coppin
2. It's mind-blowingly complex.
Colour *is* complex. Which is why I'm so glad Russell O'Connor did all the hard work for me :)
Well, no, because now I'm going to have to spend a few hours trying to find out what CIE is before I can even use that library.
The sRGB function makes a Colour from RGB (actually sRGB, which is a "standardised" RGB -- basically RGB where the exact frequency and power of each channel is specified -- but you can pretend your monitor's RGB is sRGB.
So mappend gives you colour addition [with the perplexing comments about "gamut", presumably some kind of small mammal?]
The gamut of a device is the range of representable colours (a monitor's gamut looks something like a parabola with a flat base in XYZ space, whereas a printer's is much more complex and variable). This makes sense. If you double a monitor's brightest white, you don't get a colour twice as bright: you get the same colour.
but there's no subtraction? No multiplication? No linear blending?
affineCombo can do subtraction, again with the gamut warning. darken does scalar multiplication; it probably doesn't do componentwise multiplication, which doesn't make much sense if you're trying to work in a coordinate-independent setting, though I admit RGB-multiplication can be handy.
Heh, my colour library includes a custom floor implementation that talks to the GHC primops directly because calling floor is too slow...
[In case that sounds like idle talk, I had a program go from 10 seconds to less than 1 second just by using this function. There's a few tickets about it on the GHC Trac.]
Fair enough. Can your implementation not be turned into a patch? BTW, I'm also working on Haskell fractals. You might be interested in looking at my fractal package (though it's currently undocumented, and has no GUI). --Max

On Jul 4, 2009, at 15:01 , Max Rabkin wrote:
On Sat, Jul 4, 2009 at 8:38 PM, Andrew Coppin
wrote: 3. It doesn't appear to provide arithmetic over colours.
It provides darken, blend and addition (though addition is called mappend rather than (+)). signum, abs and fromInteger don't make a huge amount of sense for colours.
I don't see a good meaning for signum offhand, but fromInteger could take an X11-encoded RGB value and abs could produce grayscale brightness. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (4)
-
Andrew Coppin
-
Brandon S. Allbery KF8NH
-
Felipe Lessa
-
Max Rabkin