Recent

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

lainz

  • Hero Member
  • *****
  • Posts: 3197
    • Lainz
Re: New version of BGRABitmap
« Reply #420 on: June 16, 2018, 10:55:53 pm »
Hi, I will add it now to the package. Thanks for sharing it.

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #421 on: August 20, 2018, 06:43:25 pm »
New version of BGRABitmap (9.9) with:

Unicode text

Full support for Unicode bidirectional text. The unit BGRAUnicode implements the bidirectional algorithm. You won't need to access it directly in most cases. The unit BGRAUTF8 contains new functions to use these features with UTF8. In particular:
- AnalyzeBidiUTF8 that returns an array with bidirectional analysis. You can specify if text is to be assumed RightToLeft or leave it as automatic.
- GetUTF8DisplayOrder will give you the display order of characters, supposing there is no line break (in this case it is a bit more complicated and there is a unit BGRATextBidi for that). For example, a text in hebrew will be displayed from right to left.
- UTF8OverrideDirection adds special unicode characters around the text to change it's direction. For example "hello" would be displayed as "olleh".
- UTF8EmbedDirection adds special unicode characters to make it a quote in a specific direction. For example you can add a quote in arabic that will be right to left inside a text in latin alphabet. This is useful for example if there is punctiation at the end of the quote, so that it will be displayed on the correct side.

The unit BGRATextBidi computes the layout of text. Basically you create the class TBidiTextLayout with a certain UTF8 string. It will analyse it and count paragraphs. You can then set paragraph alignement for each paragraph. There are also simple formatting options like the maximum width and the paragraph spacing. Tab characters are handled and you can set the size of tabs in number of corresponding spaces via TabSize property. This class can be used to compute the height of the text with its TotalTextHeight property.

It can render the text, caret and selection. There is a sample program in test\testbiditext2 that shows some minimalist text editor using this layout. Note that the paragraph alignment is lost when text is changed. To do a proper text editor one would need to create one TBidiTextLayout class for each paragraph and arrange them as you see fit. You can get the information about where paragraphs start and end from the bidi text analysis or by looking at the paragraph separators (cf function IsUnicodeParagraphSeparator of BGRAUnicode).

TBGRABitmap provides new text function TextMultiline to use this layout. So you can display bidirectional text with paragraph spacing. It supports FontOrientation whereas TextRect always displays text horizontally. Note that there is a new alignment type called TBidiTextAlignment that adds btaNatural and btaOpposite alignements. Natural means that LeftToRight text will be left-aligned and RightToLeft text will be right-aligned. Opposite means it will be the other way around. btaNatural is to be used by default when there is no particular formatting.

On Linux, text measurement is slow, so if you want speed, better use TextOut or TextRect when possible. Note that if text contains bidirectional formatting, it will fallback to TBidiTextLayout class anyway. However, TextRect will not fare well with multiple paragraphs because each paragraph may have a different text direction but TextRect cannot handle that.

Colorspaces

BGRABitmap supports more colorspaces and color conversions. Special thanks to Okoba for providing color conversions and code generation.

The directory test\colorspace contains two sample projects. ColorsDemo shows color values for all colorspaces and their conversion in real-time. HorseShoe shows a gradient in each colorspace and their gamut on the xy horseshoe diagramm.

For now, a TBGRABitmap is only in sRGB colorspace (TBGRAPixel). It is possible however to convert from an array in memory from any colorspace to any other colorspace. So you can store an image in any colorspace, and quickly display it by calling the adequate conversion. This process is used in the Horseshoe program to display a gradient in any colorspace.

Available colorspaces are:
- StdRGB also called sRGB. That's the colorspace used by most file formats.
- AdobeRGB which is an approximation of Adobe RGB colorspace.
- StdHSL and StdHSVA are HSL and HSV colorspace based on sRGB. That's the cylindrical representation hue/saturation/lightness or value. Those are the values you will find on the web when describing a color.
- StdCMYK is a theoretical Cyan-Magenta-Yellow-Black colorspace based on sRGB. It is not accurate for describing real printing colorspaces, but it is an interesting representation that is sometimes used. In fact, there is no formula to compute real CMYK values, one need conversion tables that are provided by color profiles, not handled yet by BGRABitmap.
- LinearRGB is the RGB colorspace but with gamma correction. RGB values varies proportionaly to the percieved brightness of the color.
- HSLAPixel is the HSL colorspace but based on linear RGB. Values will differ from values found on the web but they are more representative of color perception.
- GSBAPixel is yet another improvement on HSLAPixel so that the lightness is replaced by the actual brightness of the color. Indeed, depending on the hue, the fully saturated color will be darker or brighter. Blue is dark and yellow is bright. This colorspace that it into account, so that if you do a hue shift, the image will keep the same brightness. Low resolution JPEG can be thus manipulated without having artifacts due to the loss of precision.
- XYZ is the colorspace that includes all possible colors. It is a linear transformation of linear RGB, so that in theory one could also store all colors in linear RGB, though by using negative values. XYZA is used as a neutral colorspace to convert to any colorspace.
- Lab is a colorspace that encompasses most colors and that reflects human perception: L for lightness, a for red/green contrast and b for yellow/blue contrast. That's how the eye perceive colors by computing contrasts. Note that Lab has a "reference white" which is the color that is perceived as white in XYZ colorspace. The reason is that depending an the ambiant lighting, the perceived color will change.
- LCh is kind of an equivalent of HSV colorspace but based on Lab.

Layer system

In order to go in the direction of vectorial graphics, the TBGRALayeredBitmap can have its layers generated by an "original" that can be an image, an SVG, or anything that can generate an image. The original is transformed according to an affine transformation. Originals are stored in the serialized file and also in LazPaint format. Note that LazPaint format is now available within BGRABitmap by using unit BGRALazPaint. The class TBGRALazPaintImage contains the layer system and the originals and can load/save files used in LazPaint. Though LazPaint does not handle the originals yet, so even if it will load the images with originals, when saving the originals would be lost.

You can also create your own originals by deriving the class TBGRALayerCustomOriginal from the unit BGRALayerOriginal. You can look at the originals provided in BGRALayerOriginal, BGRAGradientOriginal and BGRASVGOriginal units to see examples, and as well in the demo repository in the Superformula program made by Lainz. By the way special thanks to him for testing BGRABitmap on Windows and on MacOS.
https://github.com/bgrabitmap/demo/tree/master/superformula_ui

There is also a test project in the folder test/layeroriginal that shows how to use an SVG file.

Polygon filling

There are two modes to fill polygons, winding and alternate. While most of the time winding is good enough, sometimes you want alternate. Problem is that polylines do not render well with alternate. Now when you specify alternate fill mode to draw a shape, it will be filled with alternate fill mode, but the stroke around it will be using winding fill mode. So that you can have both of the best worlds.

This goes with an improvement of TBGRAMultishapeFiller of unit BGRAPolygon. Now adding a shape return an index to it, and you can override its fill mode by calling OverrideFillMode. So you can mix fill modes.

Miscellaneous

- FreeType: added a patch to render text with angle with FreeType. Useful with NoGUI.
- TColor: when converting using ColorToBGRA, system colors are now automatically converted into RGB.
- Old Lazarus: added helpers so that you can compile projects with Lazarus 1.6 that make use of TRect.Width and the like.
- Cubic Bézier: optimization of the computation of the curve (thanks to PFradin)

https://github.com/bgrabitmap/bgrabitmap/releases
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #422 on: August 20, 2018, 06:59:56 pm »
I forgot the screenshots. Here they are.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 3197
    • Lainz
Re: New version of BGRABitmap
« Reply #423 on: August 20, 2018, 08:32:17 pm »
Thanks.

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #424 on: August 20, 2018, 09:16:15 pm »
 :) Colorspace and unicode have been waiting for a long time. I am happy to finally publish that.

I hope there is no bug.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 3197
    • Lainz
Re: New version of BGRABitmap
« Reply #425 on: August 20, 2018, 09:39:17 pm »
I like bugs, seems that I'm a 'Tero' (Vanellus chilensis).

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #426 on: August 20, 2018, 10:22:48 pm »
 :D

Beautiful bird
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 3197
    • Lainz
Re: New version of BGRABitmap
« Reply #427 on: August 21, 2018, 08:12:01 pm »
I like more the winged serpent, but that is just an untold history...

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #428 on: August 21, 2018, 08:32:08 pm »
This one?  :)
Conscience is the debugger of the mind

Phoenix

  • Jr. Member
  • **
  • Posts: 54
Re: New version of BGRABitmap
« Reply #429 on: August 21, 2018, 10:02:35 pm »
Release very impressive.
Thanks so much!!!  :D

lainz

  • Hero Member
  • *****
  • Posts: 3197
    • Lainz
Re: New version of BGRABitmap
« Reply #430 on: August 21, 2018, 10:23:38 pm »
Thanks for the point of view, mythology seems more difficult from that is in reality.

Again thanks for your help.

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #431 on: August 22, 2018, 09:40:53 am »
Release very impressive.
Thanks so much!!!  :D
Glad you like it. That was a lot of work.  :)

Again thanks for your help.
Well you help me as well.  8-)
Conscience is the debugger of the mind

Lulu

  • Full Member
  • ***
  • Posts: 111
Re: New version of BGRABitmap
« Reply #432 on: August 29, 2018, 10:45:21 pm »
Awesome  release !
However, I have a compilation error (win10, 64b, Laz 1.8.0)
Quote
Compiler le paquet BGRABitmapPack 9.9 : Code de sortie 1 - Erreurs : 1 - Conseils : 2
bgracustombitmap.inc(1096,24) Error: Identifier not found "GetFirstStrongBidiClass"
generatedcolorspace.inc(4072,34) Hint: Mixing signed expressions and longwords gives a 64bit result
generatedcolorspace.inc(4075,34) Hint: Mixing signed expressions and longwords gives a 64bit result
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: New version of BGRABitmap
« Reply #433 on: August 30, 2018, 02:43:14 pm »
Hmmm, I don't understand because I don't see GetFirstStrongBidiClass identifier in the code. Can you copy and paste what you have in bgracustombitmap.inc on line 1096 and around it?
Conscience is the debugger of the mind

Lulu

  • Full Member
  • ***
  • Posts: 111
Re: New version of BGRABitmap
« Reply #434 on: August 30, 2018, 03:49:50 pm »
Code: Pascal  [Select]
  1. function TBGRACustomBitmap.GetTextureGL: IUnknown;
  2. begin
  3.   result := nil;
  4. end;
  5.  
  6. function TBGRACustomBitmap.GetFontRightToLeftFor(AText: string): boolean;
  7. begin
  8.   case FontBidiMode of
  9.     fbmAuto: result := GetFirstStrongBidiClass(AText) in[ubcRightToLeft,ubcArabicLetter];
  10.     fbmRightToLeft: result := true;
  11.   else
  12.     {fbmLeftToRight}
  13.     result := false;
  14.   end;
  15. end;
  16.  
  17. procedure TBGRACustomBitmap.InternalArc(cx, cy, rx, ry: single;
  18.   const StartPoint, EndPoint: TPointF; ABorderColor: TBGRAPixel; w: single; AFillColor: TBGRAPixel; AOptions: TArcOptions;
  19.   ADrawChord: boolean; ATexture: IBGRAScanner);
  20. var angle1,angle2: single;
  21. begin
  22.   if (rx = 0) or (ry = 0) then exit;
  23.   angle1 := arctan2(-(StartPoint.y-cy)/ry,(StartPoint.x-cx)/rx);
  24.   angle2 := arctan2(-(EndPoint.y-cy)/ry,(EndPoint.x-cx)/rx);
  25.   if angle1 = angle2 then angle2 := angle1+2*Pi;
  26.   InternalArc(cx,cy,rx,ry, angle1,angle2,
  27.               ABorderColor,w,AFillColor, AOptions, ADrawChord, ATexture);
  28. end;
  29.  

GetFirstStrongBidiClass is used in function TBGRACustomBitmap.GetFontRightToLeftFor.
this issue appear when I have updated BGRABitmap library with OPM
« Last Edit: August 30, 2018, 03:51:26 pm by Lulu »
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)