Recent

Author Topic: Paint anti-aliased triangle, cross-platform  (Read 9801 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Paint anti-aliased triangle, cross-platform
« on: May 24, 2014, 08:25:22 pm »
I want to paint a **filled* triangle on Canvas, anti-aliased, so that if green triangle painted
on light BG image, then light greenish pixels appear near trinagle borders.

I need it cross platform (Win/Mac/L) w/out BIG libraries.
For atTabs

Any sample? I know that I may paint big triangle on temp canvas and scale it maybe...i need sample pls

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Paint anti-aliased triangle, cross-platform
« Reply #1 on: May 24, 2014, 08:48:30 pm »
Simply us the AggPas library. It is 100% implemented in Object Pascal and has very high quality anti-aliasing implemented. There are a couple versions of AggPas floating around, but as far as I know the one included with fpGUI Toolkit is the most maintained and used version. You can use the AggPas included in the fpGUI repository without actually using the fpGUI toolkit.

AggPas has about 20-30 demos showing various features. Here is a screenshot of a simple demo I put together.

Code: [Select]
TAgg2D.Triangle (x1, y1, x2, y2, x3, y3 )
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
..
« Reply #2 on: May 24, 2014, 10:31:39 pm »
hmm. I cannot use AggPas:
a) too complex to paint a rectangle (some classes needed):

Code: [Select]
var
  b: TfpgWindowBase;
  a: TAgg2d;
begin
  b:= TfpgWindowBase.Create(nil);
  ////need to set canvas??? how?
  a:= TAgg2d.Create(b);
  a.Color:= Color;
  a.Triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  a.Free;
  b.Free;

b) too much overhead (300K for 1.8M exe) for simple rectangle painting. My app is light
« Last Edit: May 24, 2014, 10:41:11 pm by Alex22 »

Rails

  • Guest
Re: Paint anti-aliased triangle, cross-platform
« Reply #3 on: May 24, 2014, 11:25:23 pm »
Take a look at the TCairoPaintBox component. It might work for you. You can find it in LuiPack.

http://code.google.com/p/luipack/




AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
-
« Reply #4 on: May 24, 2014, 11:51:47 pm »
Why CairoPaintbox?? How to use it to paint a triangle?

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: Paint anti-aliased triangle, cross-platform
« Reply #5 on: May 25, 2014, 01:34:45 am »
If you want it very light, maybe you can consider not using a library at all. Create a memory image (FPImage) and draw the triangle yourself (linear interpolation).
Conscience is the debugger of the mind

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
-
« Reply #6 on: May 25, 2014, 01:47:02 am »
As I wrote I need pas sample, not advice "create memory image ...etc..."

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Paint anti-aliased triangle, cross-platform
« Reply #7 on: May 25, 2014, 02:17:27 am »
Well no one is going to create an anti aliased routine just to show you a sample the funny thing is that you say anti aliased but you mean alpha blend and on top of that you are demanding a pascal sample I was close to ignore this completely. Anyway here is a color blend function that I found on the net somewhere don't remember where I did not had any reference in my snippets for it.
Code: [Select]
Function ColorBlend(Const aColor1, aColor2:TColor; Const aAlpha: Byte): TColor;
//by chesso
Var
  vRed, vGreen, vBlue : Byte;
  vPrimary, vSecondary : Real; // Primary And Secondary Intensity.
Begin
  vPrimary := ((aAlpha+1) /$100);
  vSecondary := (($100-aAlpha) /$100);

  vRed := Trunc(GetRValue(aColor1)*vPrimary);
  vGreen := Trunc(GetGValue(aColor1)*vPrimary);
  vBlue := Trunc(GetBValue(aColor1)*vPrimary);

  vRed := vRed+Trunc(GetRValue(aColor2)*vSecondary);
  vGreen := vGreen+Trunc(GetGValue(aColor2)*vSecondary);
  vBlue := vBlue+Trunc(GetBValue(aColor2)*vSecondary);

  If (vRed > $FF) Then vRed := $FF;
  If (vGreen > $FF) Then vGreen := $FF;
  If (vBlue > $FF) Then vBlue := $FF;

  Result := RGB(vRed, vGreen, vBlue);
End;
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
ю
« Reply #8 on: May 25, 2014, 02:30:46 am »
Hm- thank- I have this func already- from Torry-net WuLine() sample code http://www.swissdelphicenter.ch/torry/showcode.php?id=1812
Hm I guess no such sample exists, cannot find ...
« Last Edit: May 25, 2014, 02:32:35 am by Alex22 »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Paint anti-aliased triangle, cross-platform
« Reply #9 on: May 25, 2014, 02:40:25 am »
OK is the background a flat color or it can be a image? if the former then use this to calculate the drawing color then draw the triangle if the later then I will do an example a bit later for you.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
-
« Reply #10 on: May 25, 2014, 02:43:57 am »
BG is flat color. What do u mean "use this to calculate.... etc"? Can u elaborate. WuLine func cannot paint filled triangle

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Paint anti-aliased triangle, cross-platform
« Reply #11 on: May 25, 2014, 03:02:18 am »
Ok I just downloaded the zip from your repository and looked at your code, you use the function DrawTriangleRaw to draw your triangle right? and you pass to it the ATabBg color while your tab is painted using the FColorBg variable correct? then you do something like this in your dopaintto method.
Code: [Select]
  PR1:= Point(ARect.Right-FTabAngle-1, ARect.Top);
  PR2:= Point(ARect.Right+FTabAngle-1, ARect.Bottom-1);
  DrawTriangleRaw(C, PR1, PR2, Point(PR1.X, PR2.Y), ColorBlend(ATabBg, FColorbg, 50));

That should give a transparent look, play with the 50 value to find a value best suited for you.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
v
« Reply #12 on: May 25, 2014, 03:13:28 am »
taaz,
This will paint blended entire triangle, pale one. I need another thing.I need to smooth triangle edges. Edges only. Not touch filling

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Paint anti-aliased triangle, cross-platform
« Reply #13 on: May 25, 2014, 04:03:55 am »
well in that case use the wulines you linked earlier to draw the outline then shrink then paint the triangle on top of the lines.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
-
« Reply #14 on: May 25, 2014, 12:13:24 pm »
"then shrink" isn't ok. This won't work for real case

 

TinyPortal © 2005-2018