Hi David,
Bitmaps are indeed 32-bit RGBA images, so each channel is represented by just eight bits (in the format AARRGGBB).
If what you have to draw is (or can be decomposed into a set of) rectangular regions, you can do that very easily with image selections. Here is a little example that will guide you.
#include <pjsr/ColorSpace.jsh>
/**
* A simple region filling primitive.
*/
function FillRegions( image, regions, fillWith )
{
for ( var i = 0; i < regions.length; ++i )
{
image.selectedRect = regions[i];
image.fill( fillWith );
}
}
/**
* Draws a rectangle of thickness t around an inner rectangular region r,
* filled with a constant value v, over the specified image. This routine
* fills pixel samples on the currently selected channel of image.
*/
function DrawRect( image, r, t, v )
{
// Push current image selections so we can restore them on exit.
image.pushSelections();
// Fill an array of rectangular regions.
FillRegions( image, [ new Rect( r.x0-t, r.y0, r.x0, r.y1 ), // left
new Rect( r.x1, r.y0, r.x1+t, r.y1 ), // right
new Rect( r.x0-t, r.y0-t, r.x1+t, r.y0 ), // top
new Rect( r.x0-t, r.y1, r.x1+t, r.y1+t ) ], // bottom
v );
// Restore original image selections
image.popSelections();
}
function test( t, v )
{
var window = ImageWindow.activeWindow;
if ( window.isNull )
throw new Error( "No active image window!" );
with ( window.mainView )
{
var center = image.bounds.center;
var rect = new Rect( Math.floor( center.x - image.width/4 ),
Math.floor( center.y - image.height/4 ),
Math.ceil( center.x + image.width/4 ),
Math.ceil( center.y + image.height/4 ) );
var c0 = 0;
var c1 = (image.colorSpace == ColorSpace_Gray) ? 0 : 2;
beginProcess();
for ( var c = c0; c <= c1; ++c )
{
image.selectedChannel = c;
DrawRect( image, rect, t, v );
}
endProcess();
}
}
test( 20, 0.75 );
I have saved it as DrawThickRect.js.