Recent

Author Topic: Bitmap raw data access in Mac OS X / Cocoa  (Read 3217 times)

agorka

  • New Member
  • *
  • Posts: 25
Bitmap raw data access in Mac OS X / Cocoa
« on: June 26, 2018, 02:42:38 pm »
Hello!

I have an lazarus app that runs fine on OS X + Carbon, but since carbon is going to be deprecated in the next OS X release, I 'm trying to switch to Cocoa Widgetset.

I'm stuck with direct pixels access. The code that worked in Carbon doesn't work anymore, RawImage.Data is just returning all zeroes.
I made a small testing procedure:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TestBitmaps;
  2. var Bmp : TBitmap;
  3. begin
  4. Bmp:=TBitmap.Create;
  5. Bmp.Width:=32;
  6. Bmp.Height:=32;
  7. Bmp.PixelFormat:=pf32bit;
  8. Bmp.Canvas.Pixels[0,0]:=$123456;
  9. ShowMessage(ColorToString(Bmp.Canvas.Pixels[0,0]));
  10. Bmp.BeginUpdate();
  11. Bmp.EndUpdate();
  12. ShowMessage(ColorToString(Bmp.Canvas.Pixels[0,0]));
  13. Bmp.Free;
  14. end;    
First message shows $00123456, but after calling BeginUpdate / EndUpdate, second message shows $00000000,
so Begin/EndUpdate seem to vipe all the bitmap data.
I tried using LazIntfImage to access pixels, but once again I'm getting zeroes instead of real color values.

Can anyone help me with that?
I'm using Lazarus 1.8.4/FPC3.0.4
Thanks in advance!

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Bitmap raw data access in Mac OS X / Cocoa
« Reply #1 on: June 26, 2018, 03:10:21 pm »
Hi,
Graphics with FCL/LCL are heavy buggy in all OS, like i said in the topic on my TGIFViewer component. It need to be rework. In waiting i suggest you try to BGRABitmap instead is very very more stable, and pretty is pretty cool.  I you can post this issue in the bugtracker
« Last Edit: June 26, 2018, 03:51:12 pm by BeanzMaster »

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: Bitmap raw data access in Mac OS X / Cocoa
« Reply #2 on: June 26, 2018, 03:27:02 pm »
I tested on Windows and see the same - clBlack after the Bitmap.EndUpdate.

What do you want to achieve with BeginUpdate/EndUpdate? Investigating the sources I found that they are used when a TRawImage (an ancestor of TBitmap) is loaded from a stream or another image. Is it that what you want to do?

Looking at the declaration of BeginUpdate I see an optional boolean parameter ACanvasOnly which defaults to False. After setting this to true (Bitmap.BeginUpdate(true)) the set color is indicated also by the second ShowMessage.

Code: Pascal  [Select][+][-]
  1. type
  2.   TRasterImage = class(TGraphic)  // TRasterImage is ancestor of TBitmap
  3.   ...
  4.     procedure BeginUpdate(ACanvasOnly: Boolean = False);
  5.     procedure EndUpdate(AStreamIsValid: Boolean = False);
  6.   ...
  7. end;

agorka

  • New Member
  • *
  • Posts: 25
Re: Bitmap raw data access in Mac OS X / Cocoa
« Reply #3 on: June 26, 2018, 03:42:05 pm »
Thanks for answering!

I made more complex test function:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TestBitmaps;
  2. var Bmp : TBitmap;
  3.     LazIntfImage : TLazIntfImage;
  4. begin
  5. Bmp:=TBitmap.Create;
  6. Bmp.Width:=32;
  7. Bmp.Height:=32;
  8. Bmp.PixelFormat:=pf32bit;
  9. Bmp.Canvas.Brush.Color:=$234567;
  10. Bmp.Canvas.FillRect(0,0,32,32);
  11. LazIntfImage:=Bmp.CreateIntfImage;
  12. ShowMessage(ColorToString(Bmp.Canvas.Pixels[0,0])+'-LazIntf.Colors:'+IntToStr(LazIntfImage.Colors[0,0].green)+
  13.           '-LazIntf.PixelData:'+IntToStr(LazIntfImage.PixelData[1]));
  14. Bmp.BeginUpdate(True);
  15. ShowMessage(ColorToString(Bmp.Canvas.Pixels[0,0])+'-Raw:'+IntToStr(Bmp.RawImage.Data[1]));
  16. Bmp.EndUpdate(False);
  17. ShowMessage(ColorToString(Bmp.Canvas.Pixels[0,0]));
  18. Bmp.Free;
  19. end;    

On Cocoa I get:
$00234567-LazIntf.Colors:0-LazIntf.PixelData:0
$00234567-Raw:0
$00234567

On Carbon the same code gives:
$00234567-LazIntf.Colors:17733-LazIntf.PixelData:103
$00234567-Raw:103
$00234567

So probably this problem is not caused by BeginUpdate wiping data but by some raw pixel data copying to RawImage.Data.

Oleg.

 

TinyPortal © 2005-2018