Recent

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

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #450 on: December 19, 2018, 01:31:07 pm »
All you need to do is create a new application and place a TBGRASHAPE component on it.
You get a Blank Square, rather than a Black Lined Diamond shape.

TShape works fine.

I had thought about posting on bugtracker, do you post issue on bugtracker for lazarus whuch are 3rd party related?
Hmm maybe we can try to narrow down a bit the issue. It seems to be related to transparency. What if you put in the OnPaint event of the form something like:
Code: [Select]
uses BGRABitmap, BGRABitmapTypes;

{ TForm1 }

procedure TForm1.FormPaint(Sender: TObject);
var
  bmp: TBGRABitmap;
  w: single;
begin
  bmp := TBGRAbitmap.Create(ClientWidth,ClientHeight);
  w := ClientWidth/10;
  bmp.EllipseAntialias(ClientWidth/2-0.5,ClientHeight/2-0.5,ClientWidth/2-w/2,ClientHeight/2-w/2,CSSBlack,w,CSSRed);
  bmp.Draw(Canvas,0,0,False);
  bmp.Free;
end;
?

@Windsurfer: On which repository is it? Maybe it can be updated
Conscience is the debugger of the mind

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: New version of BGRABitmap
« Reply #451 on: December 20, 2018, 01:36:36 am »
Hi Circular,

Changed the css color codes to cl color codes. and the form shows the painted eclipses.

The BGRAShae is still not drawn.

It is to do with the TBGRASHAPE component, as there components like tbcbutton render fine.

Hope that helps.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #452 on: December 20, 2018, 06:14:25 pm »
Hmm so that would not be related to the drawing on the Canvas but on the code that generates the image of the shape.

What if you replace in BGRAShape unit in TBGRAShape.Paint the line:
Code: [Select]
  FBGRA.FillTransparent;by
Code: [Select]
  FBGRA.Fill(clRed);?
Conscience is the debugger of the mind

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: New version of BGRABitmap
« Reply #453 on: December 21, 2018, 12:31:29 am »
Hi Circular,

If I change the code then It draws a Red Rectangle.

I have done some further tests, It does not draw the border or fill the color, if I create the cradient and set the option to draw the border and fill with fradient then it renders.

Some pics, I have tried differing Opacity values all have no effect.

The first one you cant see where the tbgrashape is on the form, setting the gradient otion it then renders.

Hope that helps track it down, please note that the same bgrabitmap and bgracontrols work fine on RC2 and 1.8.5, it the trunk version that is having the problem, in the IDE and in Compiled code.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: New version of BGRABitmap
« Reply #454 on: December 25, 2018, 12:32:57 pm »
Hi

Just an update.

Problem is still in RC3 and latest trunk as of 25-12-18.

Tried latest BGRABITMAP and BGRACONTROLS, as well as previous versions I have that work fine in 1.8.5.

I also have issue with StringGrid not showing Border, whether this is related or not I do not know, i have created a Bug Report for the String Grid Issue 34761
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #455 on: December 26, 2018, 01:42:40 pm »
If I change the code then It draws a Red Rectangle.

I have done some further tests, It does not draw the border or fill the color, if I create the cradient and set the option to draw the border and fill with fradient then it renders.
That suggests that the problem would be with the Canvas2d thing, maybe in case of solid color.

What do you get with the test/testcanvas2d program?
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #456 on: January 19, 2019, 06:10:30 pm »
New version of BGRABitmap 9.9.3
https://github.com/bgrabitmap/bgrabitmap/releases

Added support for resources.

You can load bitmaps and other objects like SVG using the LoadFromResource function. It takes a filename as a parameter. Example:
Code: Delphi  [Select][+][-]
  1. var
  2.   FBmp, FPng, FIco: TBGRABitmap;  
  3. begin
  4.   FBmp := TBGRABitmap.Create;
  5.   FBmp.LoadFromResource('CIRCLE1.BMP');
  6.   FPng := TBGRABitmap.Create;
  7.   FPng.LoadFromResource('MYCIRCLE2.PNG');
  8.   FIco := TBGRABitmap.Create;
  9.   FIco.LoadFromResource('MYICON.ICO');
  10.   ...
Both Lazarus resources and Windows resources are checked. Note that if it is a Windows resource, the extension of anything other than BMP, ICO, CUR and HTML will be equivalent to DAT (RCDATA). So the following will do the same (on Windows resources) :
Code: Delphi  [Select][+][-]
  1.   FPng.LoadFromResource('MYCIRCLE2.PNG');
  2.   FPng.LoadFromResource('MYCIRCLE2.DAT');
  3.   FPng.LoadFromResource('MYCIRCLE2');
  4.  
I suggest to use the actual extension if it is known (here PNG) because this will be compatible with Lazarus resources and it will help determine the proper image reader.

Note that you can replace the BGRAResource instance with your own and get the resources from anywhere you like.

Note that for now loading ICO and CUR from Windows resources is only implemented with the LCL. They can be embedded though as DAT files.

Related to https://github.com/bgrabitmap/bgrabitmap/issues/51

Layered bitmaps

Can handle now unknown originals, i.e. originals which class is not registered in the application. This allows for example to modify an existing layered bitmap without loosing the information of the existing originals. For example, one can flip the layers, thus changing the matrix transform for the original even if the original itself cannot be interpreted.

- Some bug fixes
- the "=" operator for TGuid is now public.
- LayoutRect parameter added to original editor (Render and GetRenderBounds functions)
- added editor snap to grid
- added click event and cursor for editor points
- added key events

Stretching and co

Added StretchPutImageProportionally. Just supply the bounding rectangle and the image will be stretched while keeping its aspect ratio.

CrossFade has been slightly optimised.

Image loading

New image format added ifSvg for SVG files. You need to add unit BGRASVG in the uses clause to define the image reader. SVG are rendered at 96 DPI by default though you can change it in the reader properties.

Thumbnail code has been a bit refactored so that SVG can also be rendered as thumbnails.

Text rendering

- Fixed memory leak in TextMultiline function.
- Fixed last paragraph bounds in TBGRATextBidi.

In BGRACanvas2d:
- take into account horizontal font alignment
- raster text replacement when not using vectorized text renderer

So it is not necessary anymore to use TBGRAVectorizedFontRenderer for Canvas2d text, though using regular text renderer is slower and won't handle drawing the text outline (using stroke instead of fill).

Polygon filling

- Fixed a bug when joining densities of polygon (there could be a seam)
- Added angular gradient gtAngular (see screenshot)
- Fixed solid color case for aliased RoundRect

Misc

- Compilation fix for fpGui
- opaque draw fix for Qt on Mac
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: New version of BGRABitmap
« Reply #457 on: January 19, 2019, 06:14:08 pm »
Congratulations that looks great, and will help the loading from resources, I was using it already in some bgracontrols but now we can move on and use directly from bgrabitmap with no extra coding :)

That angular gradient fill looks good.

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #458 on: January 19, 2019, 08:56:29 pm »
Thanks.  :)

I am progressing on LazPaint and VectorEdit. Some changes in the layered bitmaps will allow LazPaint to open an image with unknown layer originals, but preserve them, as long as there isn't any additional drawing on the layer of course.
Conscience is the debugger of the mind

bills

  • New Member
  • *
  • Posts: 44
Re: New version of BGRABitmap
« Reply #459 on: January 24, 2019, 03:52:32 am »
Great Work.

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #460 on: January 25, 2019, 12:49:49 am »
Thanks. The challenge is stimulating.  :)
Conscience is the debugger of the mind

Phoenix

  • Jr. Member
  • **
  • Posts: 87
Re: New version of BGRABitmap
« Reply #461 on: January 27, 2019, 11:10:37 am »
Many thanks!!  :D

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #462 on: May 16, 2019, 09:54:39 pm »
New version of BGRABitmap 9.9.4
https://github.com/bgrabitmap/bgrabitmap/releases

- added constant BGRABitmapVersion and function BGRABitmapVersionStr
- added "releaser" program. It can automatically update the version of a project, package and JSON file.
See: https://forum.lazarus.freepascal.org/index.php/topic,45146.0.html

Font rendering:
- fixed bidi text for TextOutAngle function
- underline fix for some Linux fonts
- better handling of font quality/extent on Linux
- bidi support for vectorized font (so RTL text is handled but without ligature)

SVG:
- added good text support : spaces, spans, tref, positionning, gradients, bidi text, alignment, relative font size
- fixing style/attribute precedence
- using more typed values for attributes
- more generic linking system

Bidi text layout:
- keep paragraph alignment when modifying text using provided functions
- added untransformed functions
- refactoring into separate BGRAUnicodeText unit
- fix layout update when changing font bidi mode
- various fixes with empty text and end of lines

Layered bitmap:
- added A-Z special keys
- added LayerOriginalClass property
- fix editor focus

Miscellaneous:
- improved vectorize algorithm (better diagonals, parameter for diagonal width)
- PutImageAffine option to not use pixel-centered coords
- patch for TextFitInfo on old LCL
- fix SSE code for 64 bit
- added 3d test for software only
- using more inc/dec/include/exclude and Offset function to increase compatibility with Delphi
- fixing static functions
« Last Edit: May 16, 2019, 10:13:47 pm by circular »
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: New version of BGRABitmap
« Reply #463 on: June 30, 2019, 03:10:02 pm »
New version of BGRABitmap 10.1
https://github.com/bgrabitmap/bgrabitmap/releases

Colorspaces
Colorspaces were added some time ago, though you could not really use it to draw something, as anyway sRGB 8 bit was used. This release, introduces universal bitmaps and brushes. The types TCustomUniversalBitmap and TUniversalBrush can be used in principle with any colorspace. The following bitmap types are available:
- TBGRABitmap: sRGB, 8 bit per channel
- TGrayscaleBitmap: linear 8 bit grayscale. It now has drawing functions, so you can prepare a mask in 8 bit per pixel, avoiding to consume memory
- TExpandedBitmap: linear RGB, 16 bit per channel. It has more precision than TBGRABitmap and is linear, so that dmLinearBlend and dmDrawWithTransparency are equivalent.
- TLinearRGBABitmap: linear RGB, 32 bit per channel (single precision float). It has even more precision. Not really recommended though as it uses a lot of memory.
- TWordXYZABitmap: XYZ, 16 bit per channel. Can store any real and reflect color with great precision (see below for remarks about XYZ).
- TXYZABitmap: XYZ, 32 bit per channel (single precision float). It has even more precision and also a wider range, so that it can store fluorescent colors and light sources that would otherwise saturate.

XYZ is a colorspace that stores the actual stimulation of the average eye, relative to a max luminance (Y=1) considered as white. Fluorescent colors or light sources may have greater values for X/Y/Z so in this case you would rather use TXYZA floating-point format to avoid saturation. Otherwise, for most use cases, when the image represents an object reflecting daylight, TWordXYZA is sufficient.

The reference white is the color of an object that reflects all light, it depends on the illuminant. ICC recommends to use D50 as reference, which is a kind of natural daylight. While the reference white is always at Y = 1, its hue changes (X and Z values). So white is not necessary the simple value (1,1,1). This is only the case with the theoretical equal-energy illuminant (E).

So if you are not working with a specific illuminant, you would rather avoid defining colors as XYZ values. If they are in the RGB range, you can use automatic conversion and provide color constants as usual. Otherwise a convenient way is to use L*a*b* colors. For example those colors are outside of the RGB scope:
- TLabA.New(60,-145,45) is a deep mint color (greenish cyan)
- TLabA.New(90,0,140) is a deep golden yellow

While L*a*b* is convenient to specify colors, it is not so to merge colors and draw, so there isn't any bitmap that stores Lab values. Also it is worth noting that L*a*b* values do not have the exact same appearance depending on the illuminant. So I would rather use D50 to have the same values as ICC profiles.

If you want to change the reference white anyway, you can use SetReferenceWhite function. ReferenceWhite2E, ReferenceWhite2D50 and ReferenceWhite2D65 are provided as global variables.

It is also worth noting that in order to have the same values as most programs, the gamma value is now set to 2.2. This may give some gradients a different appearence, so you may want to switch back to the old 1.7 value or use your own with BGRASetGamma function.

When saving an image in XYZ colorspace, usual formats like PNG or BMP will result in colors being clipped or distorted. You need to use TIF format so that it will be saved in Lab colorspace. This format though is limited to -128..127 values for a and b, so unfortunately not all colors can be saved. If someone has an idea for a format, please let me know. You can use the Serialize/Deserialize function, though this would be readable by most programs and you need to take into account the endianness.

List of the changes
Universal bitmap:
- now TBGRACustomBitmap derives from TCustomUniversalBitmap
- TGrayscaleMask as well so it has drawing features
- brush can be customized as TUniversalBrush
- added bitmap types: TExpandedBitmap, TLinearRGBABitmap, TWordXYZABitmap, TXYZABitmap
- 16 bit/float colorspaces are saved by default as 16 bit when using PNG and TIFF format

Colorspaces:
- fixed color conversions by using gamma 2.2, D50 white point and chromatic adaptation
- bridged conversion via TExpandedPixel to reduced generated conversion code
- replace HasReferenceWhite function by GetFlags, fixed reference white point logic
- TIFF reader can handle L*a*b* colorspace
- added SpectrumRangeReflectToXYZA to get XYZ from spectrum range
- add check function for real colors in XYZABitmap unit
- can preserve hue when converting XYZ to RGB

Vectorized text:
- mirrored glyph when RTL context
- fix TexFitInfo, GetCharIndexAt
- ff ligatures

Layered bitmap:
- add render storage per layer for originals

SVG:
- handle xml:id alias to id
- container dimension applies to ComputedWidth/Height and Width/HeightAsPixels/Cm
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: New version of BGRABitmap
« Reply #464 on: June 30, 2019, 05:55:16 pm »
Amazing. The most complete library I've seen.

 

TinyPortal © 2005-2018