Recent

Author Topic: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2  (Read 17632 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1046
BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« on: October 17, 2012, 11:12:15 pm »
Hi,

Referring to this topic about BGRA Controls bug: http://www.lazarus.freepascal.org/index.php/topic,18596.msg105177.html

I created this new topic for BGRA Bitmap. I attached simple demo with paint box which cause drawing bug reported in above BGRA Controls topic.

I have still this same version of BGRABitmap, but just updated Lazarus from SVN and can confirm this bug. But seems that something is wrong with GTK or someone fixed very old bug in LCL (attached demo is using simple BGRABitmap.Draw(Canvas, 0,0,false) method).
Circular, I want post this issue on lazarus bugtracker but maybe you want look at this demo. If you don't have Linux: it's looks like BGRABitmap.Draw() always draw starting from form left-top corner (0,0), but you don's see what is drawing if paintbox is on form center, if you move paint box to form left-top coner then you will se red rectangle. Have you any idea what it could be? :) Some hazardous change in LCL :D

This code in pure LCL is working well:
Code: Pascal  [Select]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. var b: TBGRABitmap;
  3. begin
  4. //  b := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height);
  5. //  b.Fill(ColorToBGRA(ColorToRGB(clRed)));
  6. //  b.Draw(PaintBox1.Canvas, 0, 0,False);
  7. //  b.Free;
  8.   PaintBox1.Canvas.Brush.Color := clRed;
  9.   PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
  10. end;
  11.  

Regards
« Last Edit: October 17, 2012, 11:16:44 pm by Dibo »

circular

  • Hero Member
  • *****
  • Posts: 3099
    • Personal webpage
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #1 on: October 19, 2012, 12:20:07 pm »
All I can tell you is that Gtk drawing is using conversion of type of pointers, so that it is not garanteed that the good fields are used.

So maybe it is related to the way Gtk contexts are defined. They are accessed like this :
Code: [Select]
TGtkDeviceContext(ACanvas.Handle)
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #2 on: October 19, 2012, 01:11:19 pm »
Hm, what I should mention in this bug report on lazarus bug tracker?

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #3 on: October 19, 2012, 08:29:00 pm »
Something is going wrong with GTK on latest lazarus from SVN. I can't compile BGRA Bitmap (ver 6.1) without comment TGtkDeviceContext type. This same with other controls like VirtualTreeView (but there is more errors related to GTK)

circular

  • Hero Member
  • *****
  • Posts: 3099
    • Personal webpage
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #4 on: October 19, 2012, 11:30:04 pm »
I do not know what you should mention. Maybe simply that TGtkDeviceContext type seems to have been changed.
Conscience is the debugger of the mind

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 458
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #5 on: October 20, 2012, 04:20:26 pm »
About TGtkContext:

The class name changed. To compile both in new and old LCL see how i did in http://code.google.com/p/luipack/source/detail?r=901 (Must have LCLVersion unit in uses)

About Gtk coordinates:

It was changed to fix some bugs. Please add a bugreport with a small demo so we can look where the bug is

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #6 on: October 20, 2012, 04:26:45 pm »
@Luiz:
Code: [Select]
{$if (lcl_major <> 1) or (lcl_minor <> 0)}Wouldn't this be very nasty if Lazarus 1.2 is ever released?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #7 on: October 20, 2012, 04:55:57 pm »
About TGtkContext:

The class name changed. To compile both in new and old LCL see how i did in http://code.google.com/p/luipack/source/detail?r=901 (Must have LCLVersion unit in uses)

About Gtk coordinates:

It was changed to fix some bugs. Please add a bugreport with a small demo so we can look where the bug is

In bgra bitmap is:

Code: [Select]
{$IFDEF LCLgtk2}
type TGtkDeviceContext = TGtk2DeviceContext;
{$ENDIF} 

And it should be changed to:
Code: [Select]
{$IFDEF LCLgtk2}
{$MACRO ON}
{$if (lcl_major <> 1) or (lcl_minor <> 0)}
{$define type TGtkDeviceContext = TGtk2DeviceContext;}
{$endif}
{$ENDIF} 

Is it ok? I don't know what "define" in this context means. Now BGRABitmap is compiling on Lazarus 1.0.2 but I don't know if this trick will work on older lazarus. I will report now draw issue. Thanks

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #8 on: October 20, 2012, 05:11:43 pm »
The macro evaluates the compiler defines/constants (whatever they're called) at build time. There is similar functionality for the FPC version using FPC_FULLVERSION

I would rather do something like this; see lclversion.pas for the numbering scheme by the way.

Note: haven't tested the numbers themselves or even if this code compiles:
Edit: ah, I already corrected an error
Code: [Select]
// Start with enabling macros for all widgetsets so you're not surprised later on that something doesn't compile right:
{$MACRO ON}
{$IF LCL_FULLVERSION<1000200} //for laz older than say 1.0.2; you can also use >= and other operators
//((lcl_major *  100 + lcl_minor) * 100 + lcl_release) * 100 + lcl_patch;
//1.0.2.0
  {$IFDEF LCLgtk2}
  // This code will be compiled only if all IFDEFs are true, so the type will only be compiled/appear
  // in LCL/Lazarus older than 1.0.2
  type TGtkDeviceContext = TGtk2DeviceContext;
  {$ENDIF LCLgtk2}
{$ENDIF LCL_FULLVERSION>=10002}

... hope I didn't make a mistake somewhere...
« Last Edit: October 20, 2012, 05:17:03 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #9 on: October 22, 2012, 12:46:41 pm »
I have posted report issue here:
http://bugs.freepascal.org/view.php?id=23168

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #10 on: October 22, 2012, 04:18:18 pm »
Circular I think I fixed it.

BGRAGTKBitmap unit, TBGRAGtkBitmap.DrawTransparent method. Existing code:
Code: Pascal  [Select]
  1.   gdk_pixbuf_render_to_drawable(FPixBuf,
  2.     TGtkDeviceContext(ACanvas.Handle).Drawable,
  3.     TGtkDeviceContext(ACanvas.Handle).GC,
  4.     0,0,
  5.     TGtkDeviceContext(ACanvas.Handle).Offset.X+Rect.Left,
  6.     TGtkDeviceContext(ACanvas.Handle).Offset.y+Rect.Top,
  7.     Width,Height,
  8.     GDK_RGB_DITHER_NORMAL,0,0);  
  9.  
I changed to:
Code: [Select]
  gdk_pixbuf_render_to_drawable(FPixBuf,
    TGtkDeviceContext(ACanvas.Handle).Drawable,
    TGtkDeviceContext(ACanvas.Handle).GC,
    0,0,
    TGtkDeviceContext(ACanvas.Handle).ClipRect.X+Rect.Left,
    TGtkDeviceContext(ACanvas.Handle).ClipRect.y+Rect.Top,
    Width,Height,
    GDK_RGB_DITHER_NORMAL,0,0);   
Seems that before Offset had some values, but now X and Y are 0. I changed to ClipRect and now it is working. I will ask in buckracker issue why this rect is now 0

circular

  • Hero Member
  • *****
  • Posts: 3099
    • Personal webpage
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #11 on: October 22, 2012, 07:52:49 pm »
Ok. Well, let's wait for their answer then.
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #12 on: November 03, 2012, 05:26:49 pm »
@circular: There is a new answer about this issue:
http://bugs.freepascal.org/view.php?id=23168

Seems that ClipRec is not safety too. Paul posted example to use

circular

  • Hero Member
  • *****
  • Posts: 3099
    • Personal webpage
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #13 on: November 04, 2012, 09:24:49 pm »
Ok. I'm updating... Done on subversion.

Does the corrected version for Gtk (offset + window translation) work ?
« Last Edit: November 04, 2012, 09:29:51 pm by circular »
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1046
Re: BGRABitmap - drawing coordinates changed since Lazarus 1.0.2
« Reply #14 on: November 05, 2012, 11:46:47 am »
Is this correct link for svn? svn checkout svn://svn.code.sf.net/p/lazpaint/code/ lazpaint-code
Seems that there is old bgrabitmap (5.9.4)

About new solution. I thought that it is working, but my test project still remembered path to previous BGRABitmap. Now I see that solution posted by Paul doesn't work. I need to ask him:

This:
Code: Pascal  [Select]
  1. p := Rect.TopLeft;
  2. DpToLP(ACanvas.Handle, P, 1);
  3.  
... return correct points, but in negative. I must use Abs() function:
Code: Pascal  [Select]
  1. TGtkDeviceContext(ACanvas.Handle).Offset.X+abs(P.X)
  2. TGtkDeviceContext(ACanvas.Handle).Offset.Y+abs(P.Y)
  3.