Fun with code (since 2006)

Bitmap Drawing API


01.04.07 Posted in Actionscript 3 by

I've just begun to write a Raster class which provides some drawing methods onto BitmapData instances (pixel per pixel) :

Code example :

// create the BitmapData to work on
var pixels:Raster = new Raster(320, 240, true);

// draw stuff
pixels.drawRoundRect( new Rectangle ( 20, 20, 200, 100), 18, 0xFF00FFFF );
pixels.drawRect( new Rectangle ( 70, 70, 100, 100 ), 0xFF009900 );
pixels.filledTri( 40, 40, 80, 110, 50, 30, 0xFF998811 );
pixels.aaCircle(100, 100, 40, 0x77AA88 );
pixels.circle(40, 40, 30, 0xFF000000);
pixels.line(10, 10, 60, 80, 0xFF000000 );

// show it
addChild ( new Bitmap ( pixels ) );

Here's a simple demonstration

Open Source This project is OPEN SOURCE under RPL License.
2009-10-16 v1.4 raster_v1_4.zip
2007-01-07 v1.3 raster_v1_3.zip
2007-01-07 v1.2 raster_v1_2.zip
2007-01-07 v1.1 raster_v1_1.zip
2007-01-07 v1.0 raster_v1_0.zip

Raster

V1.4 API :
line()
triangle()
filledTri()
aaLine()
circle()
aaCircle()
quadBezier()
cubicBezier()
drawRect()
drawRoundRect()

This class use
rastering : Bresenham algorithm
anti-alias rendering : Xiaolin Wu algorithm

Authors (contribution) :
Didier Brun (original class)
Drew Cummins (bezier curves)
Thibault Imbert (performance optimizations, rectangles)



63 Responses to “Bitmap Drawing API”

  1. Thibault Imbert says:

    Hi Justin,

    It’s fixed, the default color in the constructor was not specifying the alpha channel ;)

    Thanks!

    Thibault

  2. JustinFact says:

    thanks! great work Thibault!

  3. [...] Bitmap Drawing API [ by Didier Brun aka Foxy ] – ByteArray.org [...]

     
  4. wrobel221 says:

    I added the Bresenham algorithm drawing an ellipse. Here is an updated version http://dl.dropbox.com/u/1333188/Raster.as

  5. [...] Brun (Foxy) s’est jeté dans le portage en Actionscript 3 des puissants algorithmes de Bresenham et Xiaolin Wu. Il nous livre les sources résultant de son travail ainsi qu’un banc d’essai [...]

     
  6. grabek says:

    Neat stuff, but what might make it even FASTER is to avoid repettative code. For example:
    drawAlphaPixel(px+vx,py+vy,1-dry,color)

    The color here gets’s shifted around each time you call the function. Well, in aaCircle you are calling drawAlphaPixel with thesame color 16 times. Think about “precalculating the rgb” as so:

    var r1:uint = ((color & 0x00FF0000) >> 16);
    var g1:uint = ((color & 0x0000FF00) >> 8);
    var b1:uint = ((color & 0x000000FF));

    drawAlphaPixel(x,y,r1,g1,b1)

  7. lolo says:

    great !

  8. aristotle9 says:

    version 1.4 has a problem with aaLine method.

    var steep:Boolean = (y2 – y1) (x2 – x1) “.
    and, Number is better than int when you want draw a aaLine using that method.

  9. aristotle9 says:

    I mean “steep” incorrect calculated beacause of the priority of operator ? 〉.

  10. Thibault Imbert says:

    Hi wrobel221, grabek and aristotle9,

    Sorry for the late feedback, very nice additions/comments. I will add it as a 1.5 revision. Thanks!

    Thibault

  11. Paul says:

    I would love a Filled Raster Circle Function :)

  12. a_____ says:

    Was revision 1.5 ever posted? It’s mentioned here:
    “Thibault Imbert wrote::

    Hi wrobel221, grabek and aristotle9,

    Sorry for the late feedback, very nice additions/comments. I will add it as a 1.5 revision. Thanks!

    Thibault
    Saturday, December 31, 2011 at 10:21 am ”
    but I don’t see it at the top under the links.

  13. GGPlay says:

    thx for the work !! awesome :)

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh

ByteArray.org
Fun with code since 2006.