Re: AntiAlias Line Optimization
- From: "wxforecaster" <wxforecaster@xxxxxxxxx>
- Date: Sun, 21 Jan 2007 21:59:23 -0600
Excellent reply. Only question I had was that in the example below you have
it in order RGBA, while your ModifyDIBArrayHack code (and my examples)
suggest that is BGRA is the correct byte order for a given pixel.
If I can get this working I'd be more than happy to share the class.
Evan
"Mike D Sutton" <EDais@xxxxxxxx> wrote in message
news:OeC%23lsbPHHA.2340@xxxxxxxxxxxxxxxxxxxxxxx
Mike, are you referring to your ModifyDIBArrayHack code? If so, I've used
this to pre-multiple the alpha value across a DIB before:
Correct.
However, in that case it didn't matter if you knew each pixel's position
since you're looping over the entire byte array. In my case here, I need
to modify the R,G,B values of a DIB given a known x,y point.
a.) Within the BMData byte array (created by your ModifyDIBArrayHack
code), how do I know which bytes in the array are associated with B, G,
and R at bitmap location x,y???
Assuming a true-colour (24/32-bit), bottom to top BGR buffer:
'***
BPP = Depth \ 8 ' Only need to do this once, outside the loop!
DataPos = (X * BPP) + ((Height - 1) - (Y * ScanLine))
R = DataPos
G = DataPos + 1
B = DataPos + 2
If (Depth = 32) Then A = DataPos + 3
'***
Where ScanLine is the DWord aligned scan-line width of the DIB, and Depth
is the bit depth of the image. In the case of the line drawing routine,
you can save the two multiplications per pixel since it always advances
one pixel in one axis. For near horizontal lines you would add BPP per
loop iteration, and only add ScanLine if the y position changed. For near
vertical lines you would add ScanLine per pixel and only add BPP if the x
position changes.
Remember though that the vertical axis is flipped for a 'normal' DIB data
buffer, so to increment the y coordinate you actually subtract ScanLine
and to decrement the y coordinate you add ScanLine.
b.) The Anti-Alias code can obviously attempt to draw a line in which
some or part of the line goes beyond the width/height bounds of the DIB.
I assume I still need to perform a clipping check?
If you perform clipping at the data level (i.e. clip the coordinates
before you even hit the line drawing) then you need only perform clipping
once rather than for every pixel. This also gives you the added benefit
that you don't need to calculate the plot weights for pixels that won't
ever get plotted, and lines that are completely off-screen will simply get
skipped.
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/
.
- Follow-Ups:
- Re: AntiAlias Line Optimization
- From: Mike D Sutton
- Re: AntiAlias Line Optimization
- References:
- AntiAlias Line Optimization
- From: wxforecaster
- Re: AntiAlias Line Optimization
- From: Mike D Sutton
- Re: AntiAlias Line Optimization
- From: wxforecaster
- Re: AntiAlias Line Optimization
- From: Mike D Sutton
- Re: AntiAlias Line Optimization
- From: wxforecaster
- Re: AntiAlias Line Optimization
- From: Mike D Sutton
- AntiAlias Line Optimization
- Prev by Date: Re: AntiAlias Line Optimization
- Next by Date: Capture Window with MPEG file
- Previous by thread: Re: AntiAlias Line Optimization
- Next by thread: Re: AntiAlias Line Optimization
- Index(es):
Relevant Pages
|