* * *

Author Topic: BGRABitmap tutorial  (Read 137445 times)

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #285 on: November 19, 2011, 07:42:16 pm »
Good idea.
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #286 on: November 27, 2011, 05:07:44 pm »
Here is a new version (5.3) of BGRABitmap with layer support (in BGRALayers) :

http://sourceforge.net/projects/lazpaint/files/src/

How to use :
Code: [Select]
  layers := TBGRALayeredBitmap.Create(640,480);
  layers.AddLayer(someBmp,128);
  layers.AddLayerFromFile('filename1');
  layers.LayerOpacity[layers.AddLayerFromFile('filename1')] := 128;
  ...
  layers.Draw(bmp,0,0);
  ...
  layers.free;
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #287 on: November 28, 2011, 01:16:30 am »
New version (5.4) :
- blend op string conversion
- layer offset, layer bitmap access
- owned layer, optimization and bug fix

Here is a screenshot :
« Last Edit: November 28, 2011, 11:15:57 am by circular »
Conscience is the debugger of the mind

lainz

  • Guest
Re: BGRABitmap tutorial
« Reply #288 on: December 11, 2011, 01:38:10 am »
I've added 'Animation' in TBGRAImageButton, basically it call Invalidate every 20 ms.

To create a 'fade' effect I do PutImage in this way:

Code: [Select]
     
..
bsHot: begin
        FBGRA.PutImage(0, 0, FBGRAUp, dmDrawWithTransparency);
        FBGRA.PutImage(0, 0, FBGRAHot, dmDrawWithTransparency, FTimerStep);
      end;   
..
 

This works fine in squared buttons, but with the image of the 'bigeyes' ( http://wiki.lazarus.freepascal.org/Image:samplebgraimagebuttonalpha.png ) I get an error External: SIGFPE in the line 3379 of bgradefaultbitmap

To reproduce this check the latest git sources of BGRAControls and mouse over the top right image button (the bigeyes one).

I'm doing something wrong?

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #289 on: December 11, 2011, 11:19:51 am »
I think it's a problem of compilation. Just remove old binaries and it should work. But looking at the code, I realized there was a little error un BGRABitmap, and that you code could be improved.

I propose you to replace TCustomBGRAImageButton.UpdateBmp code by this :

Code: [Select]
procedure CustomReplace(var Destination: TBGRACustomBitmap; Temp: TObject);
begin
  Destination.Free;
  Destination := Temp as TBGRACustomBitmap;
end;

var
  TBmp: TBGRABitmap;
begin
  if csLoading in ComponentState then
    exit;

  if (Bitmap = nil) or (Bitmap.Width < 1) and (Bitmap.Height < 1) then
    exit;

  FBmpHeight := Bitmap.Height div 4;

  FBGRA.SetSize(Width, Height);

  TBmp := TBGRABitmap.Create(FBmp);

  //get pointer bitmaps
  FreeAndNil(FBGRAUp);
  FBGRAUp := TBmp.GetPtrBitmap(0,FBmpHeight);
  FBGRAUp.ResampleFilter:= rfBestQuality;
  FreeAndNil(FBGRAHot);
  FBGRAHot := TBmp.GetPtrBitmap(FBmpHeight,FBmpHeight*2);
  FBGRAHot.ResampleFilter:= rfBestQuality;
  FreeAndNil(FBGRADown);
  FBGRADown := TBmp.GetPtrBitmap(FBmpHeight*2,FBmpHeight*3);
  FBGRADown.ResampleFilter:= rfBestQuality;
  FreeAndNil(FBGRADisabled);
  FBGRADisabled := TBmp.GetPtrBitmap(FBmpHeight*3,FBmpHeight*4);
  FBGRADisabled.ResampleFilter:= rfBestQuality;

  if BitmapOptions.Enable then
  begin
    CustomReplace(FBGRAUp,CustomResizeBitmap(FBGRAUp,BitmapOptions.BorderWidth,BitmapOptions.BorderHeight,Width,Height,BitmapOptions.DrawMode,BitmapOptions.ResampleMode,BitmapOptions.ResampleFilter));
    CustomReplace(FBGRADown,CustomResizeBitmap(FBGRADown,BitmapOptions.BorderWidth,BitmapOptions.BorderHeight,Width,Height,BitmapOptions.DrawMode,BitmapOptions.ResampleMode,BitmapOptions.ResampleFilter));
    CustomReplace(FBGRAHot,CustomResizeBitmap(FBGRAHot,BitmapOptions.BorderWidth,BitmapOptions.BorderHeight,Width,Height,BitmapOptions.DrawMode,BitmapOptions.ResampleMode,BitmapOptions.ResampleFilter));
    CustomReplace(FBGRADisabled,CustomResizeBitmap(FBGRADisabled,BitmapOptions.BorderWidth,BitmapOptions.BorderHeight,Width,Height,BitmapOptions.DrawMode,BitmapOptions.ResampleMode,BitmapOptions.ResampleFilter));
  end
  else
  begin //needed even if same size in order to make a real copy
    CustomReplace(FBGRAUp, FBGRAUp.Resample(Width, Height));
    CustomReplace(FBGRADown, FBGRADown.Resample(Width, Height));
    CustomReplace(FBGRAHot, FBGRAHot.Resample(Width, Height));
    CustomReplace(FBGRADisabled, FBGRADisabled.Resample(Width, Height));
  end;

  TBmp.Free;

  InvalidatePreferredSize;
  AdjustSize;

  if Sender is TBitmap then
    Invalidate;

  {$IFDEF DEBUG}
  Inc(FUpdateCount);
  {$ENDIF}
end;         

And to use this code in the constructor :
Code: [Select]
  FBGRAUp := nil;
  FBGRADown := nil;
  FBGRADisabled := nil;
  FBGRAHot := nil;

How it works : GetPtrBitmap returns a pointer to the TBmp. The result is thus valid until TBmp is freed. Horizontal slices of bitmaps have the same format that the whole bitmap, so there is no need to copy it.

About fading : you may consider drawing a fading effect that is a transition between two bitmaps by using a temporary bitmap, drawing first bitmap with dmSet and second bitmap with dmSet and opacity. Finally to draw the temporary bitmap.

What you do here is a superposition, which means that if the second bitmap has transparent parts, these parts will still show the underlying bitmap. But this is cool if you want to do a glowing effect.

See what I mean ?
« Last Edit: December 11, 2011, 11:38:17 am by circular »
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #290 on: December 11, 2011, 02:26:24 pm »
In fact, it seems that the error I found in BGRABitmap is causing the error you mentionned. Anyway here is a new version of BGRABitmap (5.5) :
- new blend operations : boNiceGlow and boDarkOverlay
- merged boMultiply and boLinearMultiply because it looked the same
- css colors : CSSBlue, CSSRed etc.
- TBGRAColorList : CSSColors.ByName[...]
- StrToBGRA handles CSS color names
- alpha PutImage fix

http://sourceforge.net/projects/lazpaint/files/src/
Conscience is the debugger of the mind

lainz

  • Guest
Re: BGRABitmap tutorial
« Reply #291 on: December 11, 2011, 02:34:06 pm »
In fact, it seems that the error I found in BGRABitmap is causing the error you mentionned. Anyway here is a new version of BGRABitmap (5.5) :
- new blend operations : boNiceGlow and boDarkOverlay
- merged boMultiply and boLinearMultiply because it looked the same
- css colors : CSSBlue, CSSRed etc.
- TBGRAColorList : CSSColors.ByName[...]
- StrToBGRA handles CSS color names
- alpha PutImage fix

http://sourceforge.net/projects/lazpaint/files/src/

You're the best  :D

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #292 on: December 11, 2011, 05:31:30 pm »
lol if I am only compared with myself, yes I am the best   :D
Conscience is the debugger of the mind

lainz

  • Guest
Re: BGRABitmap tutorial
« Reply #293 on: December 11, 2011, 06:03:45 pm »
 ::)

well comparing circular with Johann you're the best  :D

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #294 on: December 11, 2011, 06:16:11 pm »
Yes. Johann >= circular because Johann = circular
lol
Conscience is the debugger of the mind

lainz

  • Guest
Re: BGRABitmap tutorial
« Reply #295 on: December 18, 2011, 12:04:17 am »
There is a memory leak in bgrabitmaptypes. see attached pic.

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #296 on: December 19, 2011, 10:36:50 am »
Yes I know. It's fixed on subversion.
Conscience is the debugger of the mind

Khelle

  • New member
  • *
  • Posts: 6
Re: BGRABitmap tutorial
« Reply #297 on: December 25, 2011, 12:14:41 pm »
Is there any way to use graphics created by BGRABitmap as a cursor image?
And if there is, how can I do it?

circular

  • Hero Member
  • *****
  • Posts: 1401
    • Personal webpage
Re: BGRABitmap tutorial
« Reply #298 on: December 25, 2011, 03:04:27 pm »
There is no function in BGRABitmap to do this explicitely. Maybe it would be possible by creating a stream with CUR file format, and then load from this stream. It would be necessary to know CUR file format to do so.
Conscience is the debugger of the mind

Khelle

  • New member
  • *
  • Posts: 6
Re: BGRABitmap tutorial
« Reply #299 on: December 27, 2011, 07:34:33 pm »
Ok, I understand but there should be a function to use some graphics, as cursor.
For example in CSS we have:
cursor: url(...), default;

Is there something like that in lazarus? I would like to be able to use bitmap created by TBGRABitmap or simply graphic file like .png or .jpg?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads