Recent

Author Topic: New version of BGRABitmap  (Read 175681 times)

lainz

  • Hero Member
  • *****
  • Posts: 3420
    • Lainz
Re: New version of BGRABitmap
« Reply #165 on: July 12, 2015, 10:45:55 pm »
Ok.

Here is the thread: http://forum.lazarus.freepascal.org/index.php/topic,29038.0.html

 :)

Nice!
Please everyone get in! No matter how good you are (i'm like a noob, just an user). This will be a richer experience with more people participating in the BGRABitmap graphic contest!
« Last Edit: July 12, 2015, 11:06:25 pm by 007 »

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: New version of BGRABitmap
« Reply #166 on: July 13, 2015, 12:37:14 am »
Yes BGRABitmap is unique and sure it will help all.

circular

  • Hero Member
  • *****
  • Posts: 3082
    • Personal webpage
Re: New version of BGRABitmap
« Reply #167 on: March 11, 2016, 06:54:43 pm »
New version of BGRABitmap (8.8.2).

Download location:
https://sourceforge.net/projects/lazpaint/files/src/

What's new compared to version 8.8 regarding OpenGL:
  • Added TBGLVirtualScreen component in bgrabitmappack4lcl_opengl package, that makes it easy to use OpenGL (see updated example in folder test4lcl_opengl). This new component appears in the OpenGL component tab.
  • In OpenGL canvas, added an additional parameter to procedures to fill polygons to use non-centered coordinates if needed
  • In OpenGL canvas, added FillRectLinearColor to make it simpler to draw a background gradient
  • In OpenGL canvas, added Matrix property, and Translate/Scale functions, to apply a transform, for example to offset the content
  • For OpenGL canvas and TBGRABitmap, added RectangleWithin to make it simpler to draw a rectangle which borders are included in a rectangular area

Other new things:
  • Added DominantColor property to palette and to color quantizer (in unit BGRAColorQuantization). Using the quantizer on an image, it allows to know the dominant color of an image
  • When creating a TBGRABitmap from a TBitmap, there is a parameter to specify to use the Transparent property. For example, if the image had a purple background that is supposed to be transparent, that will become transparent in the TBGRABitmap (note that TransparentColor/TransparentMode needs to be correctly set).
  • The loading of the TBitmap raw data has been rewritten to optimise and hopefully fix the bugs on MacOS
  • Expanded colors fixed for TBGRAMultiGradient
  • It is possible to change the gamma value using BGRASetGamma and BGRAGetGamma functions of BGRABitmaTypes (demonstrated in aa_demo project of bgraaaggtest folder)

Example of usage of DomantColor:
Code: Delphi  [Select]
  1. uses BGRAColorQuantization;
  2.  
  3. function GetDominantColor(ABitmap: TBGRABitmap): TBGRAPixel;
  4. var quant: TBGRAColorQuantizer;
  5. begin
  6.   quant := TBGRAColorQuantizer.Create(ABitmap, acIgnore, 16);
  7.   result := quant.DominantColor;
  8.   quant.Free;
  9. end;  

Example of gradient dithering:
Code: Delphi  [Select]
  1.     uses BGRABitmap, BGRABitmapTypes;
  2.      
  3.     { TForm1 }
  4.      
  5.     procedure TForm1.FormPaint(Sender: TObject);
  6.     begin
  7.       with TBGRABitmap.Create(ClientWidth,ClientHeight) do
  8.       begin
  9.         GradientFill(0,0,Width,Height div 2, BGRA(80,80,80),BGRA(140,140,140),gtLinear,
  10.                                        PointF(0,0),PointF(Width,0),
  11.                                        dmSet,true,False,daFloydSteinberg);
  12.         GradientFill(0,Height div 2,Width,Height, BGRA(80,80,80),BGRA(140,140,140),gtLinear,
  13.                                        PointF(0,0),PointF(Width,0),
  14.                                        dmSet,true,False,daNearestNeighbor);
  15.         Draw(self.Canvas, 0,0);
  16.         Free;
  17.       end;
  18.     end;  
Conscience is the debugger of the mind

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: New version of BGRABitmap
« Reply #168 on: March 11, 2016, 08:35:18 pm »
Good news for me.
Thanks Circular.

wp

  • Hero Member
  • *****
  • Posts: 6654
Re: New version of BGRABitmap
« Reply #169 on: March 11, 2016, 11:55:44 pm »
The new version does not compile with Laz trunk/fpc3.0 (it does with 1.6/3.0). The issues are in unit BGRAUTF8, the compiler complains about
Quote
bgrautf8.pas(91,22) Error: Identifier not found "UTF8ToSys"
bgrautf8.pas(96,22) Error: Identifier not found "SysToUTF8"
bgrautf8.pas(121,22) Error: Identifier not found "FileOpenUTF8"
bgrautf8.pas(126,22) Error: Identifier not found "FileCreateUTF8"
bgrautf8.pas(131,22) Error: Identifier not found "FileCreateUTF8"
bgrautf8.pas(136,22) Error: Identifier not found "FileExistsUTF8"
bgrautf8.pas(142,22) Error: Identifier not found "FindFirstUTF8"
bgrautf8.pas(147,22) Error: Identifier not found "FindNextUTF8"
bgrautf8.pas(152,12) Error: Identifier not found "FindCloseUTF8"

Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

circular

  • Hero Member
  • *****
  • Posts: 3082
    • Personal webpage
Re: New version of BGRABitmap
« Reply #170 on: March 13, 2016, 12:52:41 am »
Hmmm... those functions have been removed?
Conscience is the debugger of the mind

wp

  • Hero Member
  • *****
  • Posts: 6654
Re: New version of BGRABitmap
« Reply #171 on: March 13, 2016, 01:30:18 am »
They are in LazFileUtils, LazUtf8, and maybe some other units of the LazUtils package (see Juha's mail to the mailing list of July 7 2015). There were wrappers all the time with "deprecated" warnings, but they were disabled recently.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

circular

  • Hero Member
  • *****
  • Posts: 3082
    • Personal webpage
Re: New version of BGRABitmap
« Reply #172 on: March 13, 2016, 09:20:34 am »
Ok. I made wrappers in BGRAUTF8 to make it easier to adapt this code. I wanted to avoid redundant code as those functions were already defined.

Does it solve the problem to add
{$UNDEF BGRABITMAP_USE_LCL}

after
{$i bgrabitmap.inc}

?
« Last Edit: March 13, 2016, 09:22:55 am by circular »
Conscience is the debugger of the mind

wp

  • Hero Member
  • *****
  • Posts: 6654
Re: New version of BGRABitmap
« Reply #173 on: March 13, 2016, 10:05:29 am »
Yes, it compiles with BGRABITMAP_USE_LCL undefined, of course - but then some of the available functions are duplicated. Instead, I used LazFileUtils and LazUtf8 instead of FileUtil and LCLProc (see attached zipped unit), and now BGRABitmapPack compiles with Laz trunk, 1.6, all 1.4, and even 1.2.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3672
  • I like bugs.
Re: New version of BGRABitmap
« Reply #174 on: March 13, 2016, 10:15:04 am »
They are in LazFileUtils, LazUtf8, and maybe some other units of the LazUtils package (see Juha's mail to the mailing list of July 7 2015). There were wrappers all the time with "deprecated" warnings, but they were disabled recently.

You can still use the wrappers by defining "EnableWrapperFunctions" but I don't recommend it. The functions will give deprecated warnings and later you must fix it properly anyway. Just use the right units, it is not a big change.

circular

  • Hero Member
  • *****
  • Posts: 3082
    • Personal webpage
Re: New version of BGRABitmap
« Reply #175 on: March 13, 2016, 10:37:24 am »
Oh ok. I was not aware of that.

I updated on SVN and replaced the zip file with the fix.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 3420
    • Lainz
Re: New version of BGRABitmap
« Reply #176 on: March 19, 2016, 08:36:51 pm »
I've updated GitHub mirror of BGRABitmap\lazpaint. Other repos like bgracontest, bgracontrols, bgragames already updated, uecontrols maybe outdated.

https://github.com/bgrabitmap

circular

  • Hero Member
  • *****
  • Posts: 3082
    • Personal webpage
Re: New version of BGRABitmap
« Reply #177 on: March 19, 2016, 10:28:44 pm »
Thanks!  :)
Conscience is the debugger of the mind

VTwin

  • Hero Member
  • *****
  • Posts: 841
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #178 on: March 26, 2016, 03:17:55 pm »
Thanks for your fantastic work on this circular!

I just ran through some of the demos in 8.8.2 and it is very impressive. The bspline demo is very helpful to see the effect of the options.

So far the only issue I see on OS X is the text display. I'm using the workaround from Zittergie:

http://forum.lazarus.freepascal.org/index.php/topic,29064.0.html

In bgrapixel.inc:

Code: Pascal  [Select]
  1.  (*
  2.  {$IFDEF DARWIN}
  3.     {$DEFINE BGRABITMAP_RGBAPIXEL}
  4.  {$ENDIF}
  5.  *)    
  6.  

Maybe an OS X guru here can help track this down.

Cheers,
VTwin


“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.7 fixes svn r62562 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

circular

  • Hero Member
  • *****
  • Posts: 3082
    • Personal webpage
Re: New version of BGRABitmap
« Reply #179 on: April 01, 2016, 05:15:39 pm »
Hmmm so the text is still not displayed  :'(

The thing is that not using RGBA order for MacOS is slower, as it requires to swap red and blue each time an image is drawn on the screen. So it would be great to have some help from an OS X guru.

In the meantime, here is a new version 8.8.3:
- small bug fixes
- compatibility with NoGUI and ZenGL
- compilation of BGRABitmapPack4lcl_opengl in separate folder to avoid interference with the regular package
- embedded ZenGL examples in test4other folder
- added support for font rendering with OpenGL. Default renderer is LCL. One can specify font size, quality, color, gradient color, etc. See example in test4lcl_opengl folder
- added frame per second event in TBGLVirtualScreen component

Example of usage of font with OpenGL:
Code: Pascal  [Select]
  1. font := BGLFont('Arial', 20, CSSLightYellow,CSSBlack, [fsBold]);
Creates a font with face 'Arial', em-height 20 pixels, color light yellow with black outline, with style bold.

Code: Pascal  [Select]
  1. font.TextOut(ctx.Width-5,0,'Text at the upper-right corner',taRightJustify);
Conscience is the debugger of the mind