Recent

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

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: New version of BGRABitmap
« Reply #255 on: November 10, 2016, 11:51:58 pm »
You can upload your test project? So is easy to test if works in any other context.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #256 on: November 11, 2016, 12:07:37 am »
Thanks lainz,

I'm testing again on another system, and then will post it.

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #257 on: November 11, 2016, 02:05:42 am »
I tried running this on a new machine (MacBook Pro with Windows 7 on VirtualBox). I'm having trouble reproducing errors, but am still not able to get this to run. On Windows 7 (64 bit) it is now compiling, but I get a blank form. On Mac 10.11.5 I get a blue rectangle instead of the expected red.

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls,
  BGRABitmap, BGRABitmapTypes;

type

  { TForm1 }

  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { private declarations }
    fBmp: TBGRABitmap;
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  w, h: integer;
  tsp: TBGRAPixel;
begin
  tsp := BGRA($00, $00, $00, $00);
  w := PaintBox1.Width;
  h := PaintBox1.Height;
  fBmp := TBGRABitmap.Create(w, h);
  fBmp.FillRect(0, 0, w-1, h-1, cssWhite, dmSet);
  fBmp.FillRect(0, 0, w-1, h-1, cssRed, dmDrawWithTransparency);
  fBmp.Rectangle(0, 0, w-1, h-1, cssBlack, tsp, dmDrawWithTransparency);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  fBmp.Draw(PaintBox1.Canvas, 1, 1, true);
end;

end.

See attached project.

I appreciate any suggestions.

Cheers,
VTwin
« Last Edit: November 11, 2016, 02:08:05 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #258 on: November 11, 2016, 02:24:05 pm »
I commented out in TBRAPixel.inc:

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

as in previous versions. Now on Mac (10.10.5) the expected blue rectangle is cyan with a blue border.  %)

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: New version of BGRABitmap
« Reply #259 on: November 11, 2016, 03:14:52 pm »
There are some things I see:

1) You can use BGRAPixelTransparent instead of tsp
Quote
fBmp.Rectangle(0, 0, w-1, h-1, cssBlack, BGRAPixelTransparent, dmDrawWithTransparency);

2) You must use OnPaint event of PaintBox, not of Form
Quote
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  fbmp.Draw(PaintBox1.Canvas, 1, 1, true);
end;

Edit:

3) Also you need only a line to paint black border filled with red:
Quote
  //fBmp.FillRect(0, 0, w-1, h-1, cssWhite, dmSet);
  //fBmp.FillRect(0, 0, w-1, h-1, cssRed, dmDrawWithTransparency);
  fBmp.Rectangle(0, 0, w, h, cssBlack, cssRed, dmDrawWithTransparency); //<---

4) You can use w, h, and 0, 0 coordinates to paint to fill the entire rectangle
Quote

fBmp.Rectangle(0, 0, w, h,...

fbmp.Draw(PaintBox1.Canvas, 0, 0, true);
« Last Edit: November 11, 2016, 03:21:21 pm by lainz »

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #260 on: November 11, 2016, 03:53:29 pm »
lainz,

Thanks! I had the white background because it was a Form to set the transparency, and the form's background was not white, but yes, I can simplify it. Using (w, h) also makes sense, thanks. Now I have:

EDIT

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   w, h: integer;
  4. begin
  5.   w := PaintBox1.Width;
  6.   h := PaintBox1.Height;
  7.   fBmp := TBGRABitmap.Create(w, h);
  8.   //fBmp.FillRect(0, 0, w, h, cssWhite, dmSet);
  9.   //fBmp.FillRect(0, 0, w, h, cssRed, dmDrawWithTransparency);
  10.   //fBmp.Rectangle(0, 0, w, h, cssBlack, BGRAPixelTransparent, dmDrawWithTransparency);
  11.   fBmp.Rectangle(0, 0, w, h, cssBlack, cssRed, dmDrawWithTransparency);
  12. end;
  13.  
  14. procedure TForm1.PaintBox1Paint(Sender: TObject);
  15. begin
  16.   fBmp.Draw(PaintBox1.Canvas, 0, 0, true);
  17. end;        
  18.  

but still get the cyan square with blue border. :( I'll work on it more tonight.

Cheers,
VTwin
« Last Edit: November 11, 2016, 03:59:45 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: New version of BGRABitmap
« Reply #261 on: November 11, 2016, 03:58:45 pm »
Code: Pascal  [Select][+][-]
  1.  w := PaintBox1.Canvas.Width;
  2.   h := PaintBox1.Canvas.Height;

That's the wrong code.

You must use PaintBox width and height, not canvas.
Code: Pascal  [Select][+][-]
  1. w := PaintBox1.Width;
  2.   h := PaintBox1.Height;

Edit: OK, you updated your post with the right code. About the cyan color instead of red, I'm not sure why that happens on Mac.
« Last Edit: November 11, 2016, 04:25:58 pm by lainz »

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: New version of BGRABitmap
« Reply #262 on: November 11, 2016, 05:53:02 pm »
I have removed SVN repository from SourceForge, it only contains LazPaint now.
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: New version of BGRABitmap
« Reply #263 on: November 11, 2016, 07:02:00 pm »
@VTwin:
I suppose the error "There is no method in an ancestor class to be overridden" you're getting is related to the string type. In principle there is {$H+} at the top of both units BGRABitmapTypes and BGRADefaultBitmap so the type "string" is the same.

What if you replace "string" by "ansistring"?

About the strange colors, what is the endianness of your Mac computer?
« Last Edit: November 11, 2016, 07:16:29 pm by circular »
Conscience is the debugger of the mind

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #264 on: November 12, 2016, 12:54:32 am »
lainz,

Thanks. Yes I realized as soon as I posted that I had tried using the width and height of the Canvas. As soon as I switched back, I got the image again. The colors, so far, are a mystery.

circular,

Thanks. I was not able to reproduce the ancestor class error. I switched machines, and also reinstalled Lazarus as I was getting some odd errors. I just checked again and Windows 7 is compiling the test program ok, and giving the expected colors.

I thought perhaps this might be related to the known Mac bug. I use PaintBox often, and did not note a problem until now, so I was trying to isolate it.

As far as I can tell, from internet searches, the current i86 Macs are all little endian. The old Motorola Macs were big endian. I have not checked this myself in code though. If you wish to refresh my memory on a simple test, I can try that.

Cheers,
VTwin

Just to add, I use BGRABitmap extensively on Mac, Windows, and Linux, and normally it works extremely well. This is an unusual case that is puzzling. 
« Last Edit: November 12, 2016, 12:59:35 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #265 on: November 12, 2016, 01:20:52 am »
Just checked on Linux Ubuntu. The test program compiles and runs as expected. Since OS X has Linux underpinnings, I am surprised at the difference.
« Last Edit: November 12, 2016, 01:25:55 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: New version of BGRABitmap
« Reply #266 on: November 12, 2016, 10:39:22 am »
Hi VTwin,

So if I understand well, you were able to compile BGRABitmap on Windows 7.

On MacOS X, yes, I suppose it is little endian. Do you still have the strange colors?

What you described look like the RGBA format was interpreted as BGRA a format and the BGRA format interpreted as ARGB. That's a bit strange. The procedure that creates the bitmap as in procedure TBGRALCLBitmap.RebuildBitmap in bgralclbitmap.pas. Maybe you can try to debug and add a breakpoint there, and see what it does.
Conscience is the debugger of the mind

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #267 on: November 12, 2016, 06:14:20 pm »
Hi circular,

Thanks. Yes, the program runs as expected now on Windows. The error messages disappeared after I reinstalled Lazarus.

I am nearly certain it is little endian, I checked with a script I found. Yes, the colors are strange. Attached are two forms showing DEFINE BGRAPIXEL_RGBAPIXEL results and UNDEF BGRAPIXEL_RGBAPIXEL results.

I tried adding bgralclbitmap.pas to the project, and added a breakpoint, but it did not seem to call TBGRALCLBitmap.RebuildBitmap.

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

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New version of BGRABitmap
« Reply #268 on: November 12, 2016, 06:21:01 pm »
Here is the updated project if another Mac user would like to confirm.

Cheers,
VTwin

EDIT: It works as expected on Linux.
« Last Edit: November 12, 2016, 06:34:38 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: New version of BGRABitmap
« Reply #269 on: November 12, 2016, 09:07:58 pm »
Hi

Just tested, getting same problem. I think however its a problem with TPainBox; if you create a similar tbitmaps and send the generted image from bgrabitmap it renders correct/similar on cocoa and carbon

I have attached moded project, Maybe you can try sending to bug tracker.

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

 

TinyPortal © 2005-2018