Recent

Author Topic: Yellow background with FontAntialias  (Read 12315 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Yellow background with FontAntialias
« on: May 27, 2012, 03:51:53 pm »
Hi,

When I set FontAtialias to true and font quality to fqSystemClearType in TBGRABitmap, then TextOut/TextRect have some yellow background (see attached screen) with some opacity (look at BCButton2). With fqFineAntialiasing is ok. Is this problem only on GTK2?

BGRABitmap 5.7.1 (but tested on 5.6 too)
Lazarus from SVN, GTK2 interface
FPC 2.6.0 stable
Linux Ubuntu 12.04 64bit

Regards

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #1 on: May 27, 2012, 05:48:55 pm »
Well in fact when you set font quality to fqSystemClearType, it overrides FontAntialias. This property is just for backward compatibility, you can ignore it and use FontQuality only. So I suppose the bug comes with fqSystemClearType even if you don't set FontAntalias to true, doesn't it ?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #2 on: May 27, 2012, 06:01:21 pm »
Yes, that's right

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #3 on: May 27, 2012, 06:09:44 pm »
Hmm... and what happens with FineClearType ?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #4 on: May 27, 2012, 06:17:34 pm »
With this type is ok

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #5 on: May 27, 2012, 06:24:50 pm »
In bgratext.pas, in BGRATextOut procedure, if you replace
Code: [Select]
  temp.Canvas.Brush.Style := bsClear;
by
Code: [Select]
  temp.Canvas.Brush.Style := bsSolid;
  temp.Canvas.Brush.Color := clBlack;

Does it solve the problem?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #6 on: May 27, 2012, 09:04:49 pm »
It doesn't help. Is this some low level procedure? Because I draw text using BGRABitmap.TextRect

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #7 on: May 27, 2012, 09:30:02 pm »
Oh in this case it is rather BGRATextRect at line 879.
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #8 on: May 27, 2012, 09:35:56 pm »
Nothing changed

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #9 on: May 28, 2012, 09:07:27 pm »
Strange. When you use a standard Canvas with Font.Quality = fqClearType, does it draw a yellow background ?

What if you change in bgradefaultbitmap.pas, at lines 575-576 in UpdateFont procedure, the code
Code: [Select]
  if FontQuality = fqSystemClearType then
    FFont.Quality := fqCleartype
by
Code: [Select]
  if FontQuality = fqSystemClearType then
    FFont.Quality := FontDefaultQuality
(this should remove the ClearType effect) ?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #10 on: May 28, 2012, 10:18:28 pm »
Strange. When you use a standard Canvas with Font.Quality = fqClearType, does it draw a yellow background ?
This code works fine (background is clear):
Code: [Select]
procedure TForm1.FormPaint(Sender: TObject);
begin
  Self.Canvas.Brush.Color := clRed;
  Self.Canvas.FillRect(Self.ClientRect);
  Self.Canvas.Brush.Style := bsClear;
  Self.Canvas.Font.Quality := fqCleartype;
  Self.Canvas.TextOut(5,5,'dssdfsdfsdf');
end;
Quote
What if you change in bgradefaultbitmap.pas, at lines 575-576 in UpdateFont procedure, the code
Code: [Select]
  if FontQuality = fqSystemClearType then
    FFont.Quality := fqCleartype
by
Code: [Select]
  if FontQuality = fqSystemClearType then
    FFont.Quality := FontDefaultQuality
(this should remove the ClearType effect) ?
Doesn't help. I will try update lazarus SVN source. Maybe something is wrong with my revision.

I tried some simple code:
Code: [Select]
procedure TForm1.FormPaint(Sender: TObject);
var b: TBGRABitmap;
begin
  b := TBGRABitmap.Create(100,100, BGRAPixelTransparent);
  b.Fill(clRed);
  b.FontHeight := 0;
  b.FontName := 'default';
  b.FontQuality := fqSystemClearType;
  b.TextOut(0,0,'sdsdsd',BGRABlack);
  b.Draw(self.Canvas,0,0,False);
  b.Free;
end; 
And this works fine... Hmm, what I am missing. It is strange because this background appear in old controls too (where the code was not changed almost at all). Ok I must do some more tests and I'll get back

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #11 on: May 29, 2012, 11:02:21 am »
Ok, above example with bgra bitmap has this strange background but it was not visible when main background is red (another clue?). So below example with white background occur yellow background under text (I know that you can't test it but now you see which methods exactly I am using):
Code: Pascal  [Select][+][-]
  1. uses BGRABitmap, BGRABitmapTypes;
  2.  
  3. procedure TForm1.FormPaint(Sender: TObject);
  4. var
  5.   b: TBGRABitmap;
  6. begin
  7.   b := TBGRABitmap.Create(100,100, BGRAPixelTransparent);
  8.   b.Fill(clWhite);
  9.   b.FontHeight := 0;
  10.   b.FontName := 'default';
  11.   b.FontQuality := fqSystemClearType;
  12.   b.TextOut(0,0,'sdsdsd',BGRABlack);
  13.   b.Draw(self.Canvas,0,0,False);
  14.   b.Free;
  15. end;
  16.  
My investigation:
I have installed old 5.6 version and some old bgracontrols package - this same problem. I updated today lazarus SVN but this did not change anything. So this problem must exist for a long time but no one noticed it (I have never used fpSystemClearType in my controls, Lainz did but he is working on Windows).
So question is: is this problem in lazarus gtk2 or in bgrabitmap? Because this code with white background works fine:
Code: Pascal  [Select][+][-]
  1. Self.Canvas.Brush.Color := clWhite;
  2. Self.Canvas.FillRect(Self.ClientRect);
  3. Self.Canvas.Brush.Style := bsClear;
  4. Self.Canvas.Font.Quality := fqCleartype;
  5. Self.Canvas.TextOut(5,5,'dssdfsdfsdf');
  6.  

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #12 on: May 29, 2012, 01:25:33 pm »
It looks as the blue channel is not considered as empty (thus substracting it gives yellow).

There are inline procedures so there may be a problem of linking. Try to remove lib directory of bgrabitmap.

I do not know if it is inside or outside ClearTypeDrawPixel. If the problem is inside this procedure, then if you call ClearTypeDrawPixel with Cr,Cg,Cb equal to 0, then you should obtain yellow color on white background. If the problem is outside, then if you replace line 886 of BGRAText.pas, in BGRATextRect procedure
Code: [Select]
BGRAFillClearTypeRGBMask(bmp,lim.Left, lim.Top, temp, c,tex)by
Code: [Select]
BGRAFillClearTypeRGBMask(bmp,lim.Left, lim.Top, temp, c,tex,false)
You should obtain instead a cyan background.


Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Yellow background with FontAntialias
« Reply #13 on: May 29, 2012, 02:50:59 pm »
So first I must see which color get me ClearTypeDrawPixel method? Can you show full example how to call it? Because there is some point to bgrapixel and the last param is some color

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Yellow background with FontAntialias
« Reply #14 on: May 31, 2012, 01:35:48 am »
Something like :
Code: [Select]
uses BGRABitmap,BGRABitmapTypes,BGRABlend;

{ TForm1 }

procedure TForm1.FormPaint(Sender: TObject);
var x,y: integer;
    p: PBGRAPixel;
    image: TBGRABitmap;
begin
  image := TBGRABitmap.Create(ClientWidth,ClientHeight,BGRAWhite);

  for y := 0 to image.Height-1 do
  begin
    p := image.Scanline[y];
    for x := 0 to image.Width-1 do
    begin
      ClearTypeDrawPixel(p, 128,128,128, BGRABlack);
      inc(p);
    end;
  end;
  image.InvalidateBitmap; // changé par accès direct

  image.Draw(Canvas,0,0,True);
  image.free;
end;

If you put zero instead of 128, it is like no pixel, and you should get a white image (and not yellow).
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018