Solved

Antialiased TImage?

Posted on 2000-04-08
25
537 Views
Last Modified: 2010-04-04
Is there anyway to remove the jagged edges of an line drawn on the canvas of a TImage in realtime?
0
Comment
Question by:sageryd
  • 14
  • 10
25 Comments
 

Expert Comment

by:Portal
ID: 2697387
Have a look at this component which antialiases shapes and lines.

www.delphipages.com/edit/count.cfm?ID=292

Quoted from the author Dean Wilkinson:
"SmoothLn is derived from TPaintBox. It provides antialiasing line and shape methods to produce smooth, high quality graphics. antialiasing eliminates staircase patterns from lines drawn at angles other than vertical or horizontal. "
0
 
LVL 1

Author Comment

by:sageryd
ID: 2697473
Nice component, but I can't install it since I'm running D5. Need either the .pas file or a .dcu compiled in D5.

--johan
0
 
LVL 2

Expert Comment

by:brainware
ID: 2698272
sageryd if you need Source for an Anti-Aliased Line i could write one i guess..
for use on a TCanvas or?

so far i have never seen any Source for such in Delphi and i checked almost everywhere some weeks ago...

0
 
LVL 1

Author Comment

by:sageryd
ID: 2698341
Thanks brainware! Yes, I'm using the canvas of a TImage. Isn't it quite hard writing such stuff??

:0)

--johan
0
 
LVL 2

Expert Comment

by:brainware
ID: 2698606
well it aint exactly all easy hehe..
but if it is what you need well you need it... :)
but REALTIME you say... thats NOT 100% Possiple with a TImage or Canvas now days hehe.. well AA can be done fast yes but like most other Image Effects they need a fast access to the pixels.

Where do you need it and for how much drawing... aka you trying to do like 10 fps redraws on a Timage or just Regular Replaint whatever...
0
 
LVL 1

Author Comment

by:sageryd
ID: 2699088
Actually I am making kind of a game, similar to Pictionary. There are some clients connected to a server, one of the clients draw an image and the others get it broadcasted. So I want the just drawn line to be antialiased, like when the user has the mousebutton dow and moves the mouse on the canvas the MouseMove event calls Canvas.MoveTo(X, Y); That's where I'd like the AA. I can't tell ya the FPS though...the drawing client's picture is painted up smoothly, the other clients get the picture in small portions.
0
 
LVL 1

Author Comment

by:sageryd
ID: 2699111
I forgot to mention, I'm not only drawing lines, there are rectangles and circles and stuff to. But only the shapes that the TImage.Canvas have procedures/functions for.

--johan
0
 
LVL 2

Expert Comment

by:brainware
ID: 2705582
Well what you can do is this, Draw at a Larger SCALE and Resample it 'Down-Sample' this is a easy way to do Global AntiAliasing.

anyhow... check our product at www.wrapx.suite.dk / www.bw-soft.com
is a DirectX 6 Wrapper (commercial), So far most power is on the 2D Side, next version comes with AALine.. but if you wanna use regular GDI.. well i can get you the AALine Rutine for that, But for Circle etc you gotta do alot more work..

Resampling is prolly the best way if it would work with the thing you are doing.

www.efg2.com <-- check this page for some AA or Resampling stuff..
www.melander.dk <-- a Unit for Resampling..

Resample from like 200x200 to 220x220 and down to 200x200 again..


-Michael
0
 
LVL 1

Author Comment

by:sageryd
ID: 2706463
Well I can't really downsample it, because the user draws in realtime and it must get antialiased directly. Like in photoshop.
0
 
LVL 1

Author Comment

by:sageryd
ID: 2706477
I think what I really need is that AALine routine, as I havn't figured out a way to draw circles like mspaint does I might just skip that part.
0
 
LVL 2

Expert Comment

by:brainware
ID: 2707432
Tell ya what.. ill do what i can to help ya, tho it aint many points for such rutines but as im already working on such with Christian, we can share some i guess...

Have you ever worked with DIB's ?
'Device-Independant-Bitmaps'
just becuse when you want to be workng with Realtime Graphics a TBitmap/Image aint the best solution when you wanna do good quality graphic rutines.

-Michael who is in need of Coffee.....
0
 
LVL 1

Author Comment

by:sageryd
ID: 2708060
Adjusted points from 100 to 200
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:sageryd
ID: 2708061
Thanx! That would be nice.

No, I havn't used DIBs, at least I think i havn't. What is it really? What is the difference between a normal canvas and a DIB canvas?

You are from denmark right?
0
 
LVL 2

Expert Comment

by:brainware
ID: 2709979
Well a great example of compare is hmm TBitmap's Pixels[] speed vs if you make a good DIB Class.. you can get a extremly nice speed boost, involves alot of LowLevel api stuff but also a big preformance difference.. its prolly the best preformance you can get without DirectX.

Denmark.. yeah why?

anyhow.. if ya have DirectX 6+ installed i can show you some AA Line in works.. the code me and christian will make a small Canvas version of.
0
 
LVL 1

Author Comment

by:sageryd
ID: 2710636
ok, DIB sounds good. And yes please, send any examples you want: sageryd@gmx.net

My program has to work without DirectX though.

The question about Denmark was just out of curiosity, I'm from Sweden.

--johan
0
 
LVL 2

Expert Comment

by:brainware
ID: 2790225
Urg.. Im back 5% :) if you still need it that is, sorry that i have been I-Net dead for a 14 days time... i kinda bumped into a fantasic girl the weekend i was away :) and since then yeah you can guess....

0
 
LVL 1

Author Comment

by:sageryd
ID: 2791186
Ok, I understand ;)
0
 
LVL 2

Accepted Solution

by:
brainware earned 200 total points
ID: 2918229
I have the code ready for you now. This was written for use with TFastDIB so it was not danm slow :)
http://www.jps.net/gfody/


 Procedure AALine(Const aDIB : TFastDIB; A,B : TPoint; C : TFColor);
 Procedure SetAlphaPixel(Const aDib : TFastDIB; X,Y,Alpha : Integer; Color : TFColor);

implementation

Procedure AALine(Const aDIB : TFastDIB; A,B : TPoint; C : TFColor );
Const
  FP16_P5 = $8000;
  FP16_1 = $10000;
  FP16_1P5 = $18000;
Var
  DX,DY : Integer;
  S : Integer;
  I : Integer;
  T : TPoint;
  Q,P : Integer;
Begin
If (Round(A.X) = Round(B.X)) And (Round(A.Y) = Round(B.Y)) Then Exit;
DX := Abs(Round((B.X-A.X)*FP16_1));
DY := Abs(Round((B.Y-A.Y)*FP16_1));
With aDIB Do
If DX > DY Then
Begin
  If A.X > B.X Then
  Begin
    T := A;
    A := B;
    B := T;
  End;
  P := Round(A.X);
  S := Round(((B.Y-A.Y)/(B.X-A.X))*FP16_1);
  Q := Round(A.Y*FP16_1+S*Frac(A.X));
  For I := 0 To Round(DX Shr 16)-1 Do
  Begin
    SetAlphaPixel(aDIB,P+I,(Q-FP16_P5) Shr 16,Hi((Q-FP16_P5) And $FFFF) Xor $FF, C);
    SetAlphaPixel(aDIB,P+I,(Q+FP16_P5) Shr 16,Hi((Q-FP16_P5) And $FFFF), C);
    Q := Q+S;
  End;
End Else
Begin
  If A.Y > B.Y Then
  Begin
    T := A;
    A := B;
    B := T;
  End;
  P := Round(A.Y);
  S := Round(((B.X-A.X)/(B.Y-A.Y))*FP16_1);
  Q := Round(A.X*FP16_1+S*Frac(A.Y));
  For I := 0 To Round(DY Shr 16)-1 Do
  Begin
    SetAlphaPixel(aDIB,(Q-FP16_P5) Shr 16,P+I,Hi((Q-FP16_P5) And $FFFF) Xor $FF, C);
    SetAlphaPixel(aDIB,(Q+FP16_P5) Shr 16,P+I,Hi((Q-FP16_P5) And $FFFF), C);
    Q := Q+S;
  End;
End;
End;

Procedure SetAlphaPixel(Const aDib : TFastDIB; X,Y,Alpha : Integer; Color : TFColor);
 Var
   R,G,B : Byte;
   D2 : TFColor;
 Begin
 If (X > -1) And (X < Integer(aDib.Width)) And (Y > -1) And (Y < Integer(aDib.Height)) Then

  Case aDib.Bpp Of
   24 : Begin
          R := Color.R;
          G := Color.G;
          B := Color.B;

          D2 := aDIB.Pixels24[aDib.Height-Y,X];
          D2.R := (R*Alpha Shr 8)+D2.R*(255-Alpha) Shr 8;
          D2.G := (G*Alpha Shr 8)+D2.G*(255-Alpha) Shr 8;
          D2.B := (B*Alpha Shr 8)+D2.B*(255-Alpha) Shr 8;
          aDIB.Pixels24[aDib.Height-y,x] := D2;
        End;
  End;
 End;


Example
 AALine(myDIB,Point(0,0),Point(117,121),FRGB(255,255,255));


0
 
LVL 2

Expert Comment

by:brainware
ID: 2918240
Note - Original Source is from WrapX - Christian Iversen / BrainWare

www.wrapx.suite.dk - where it is also avalible using DirectX.

0
 
LVL 1

Author Comment

by:sageryd
ID: 2918475
Thanks! I'll try it A.S.A.P.!

johan
0
 
LVL 2

Expert Comment

by:brainware
ID: 2943146
So is it what ya need?

PS: i talked to author of FastDIB and he plans to implement the wu-AALine code above.
0
 
LVL 1

Author Comment

by:sageryd
ID: 2945116
Yes, I guess it's what I need, but as I havn't tried it yet, I don't really know, but it seems promising ;)

Nice! Did the FastDIB guy tell you when it will be ready?

--johan
0
 
LVL 2

Expert Comment

by:brainware
ID: 2980336
I think he will have it implemented shortly if not already done...
0
 
LVL 1

Author Comment

by:sageryd
ID: 2981832
Comment accepted as answer
0
 
LVL 1

Author Comment

by:sageryd
ID: 2981833
okay......well thanks! ;o)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now