Re: AntiAlias Line Optimization

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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/



.



Relevant Pages

  • Re: AntiAlias Line Optimization
    ... In my case here, I need to modify the R,G,B values of a DIB given a known x,y point. ... Within the BMData byte array, how do I know which bytes in the array are ... 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. ...
    (microsoft.public.vb.winapi.graphics)
  • Re: AntiAlias Line Optimization
    ... Where ScanLine is the DWord aligned scan-line width of the DIB. ... I'm not really sure what your ModifyDIBArrayHack() procedure is up to, the name certainly doesn't sound like one of mine ... and the bmBits member of the BITMAP structure is the pointer to the DIB data which can use the array hack on. ...
    (microsoft.public.vb.winapi.graphics)
  • Re: SAFEARRAY1D and 32-bit DIBs
    ... we loose speed at time to stretch, but we increase it at time to process). ... DIB associated memory is not 'reseted', ... >> This seems to happen only on Windows 98 ... >> pixel format. ...
    (microsoft.public.vb.winapi.graphics)
  • Re: SAFEARRAY1D and 32-bit DIBs
    ... On Windows 9x, ... DIB associated memory is not 'reseted', ... |>> pixel format. ...
    (microsoft.public.vb.winapi.graphics)
  • Re: CBitmap: Color -> Grayscale
    ... Bei 24-Bit-Bitmaps hat man keine Tabelle! ... Du setzt einfach für jedes Pixel im 24-Bit-Bild die drei Farbwerte gleich, ... Man kann zwar direkt auf die Bits des DDB zugreifen, aber alles andere ist AFAIK unbekannt. ... Sonst einfach mit SetDIBitsToDevice dein DIB malen lassen. ...
    (microsoft.public.de.vc)