Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread Dominique Louis

Marc Weustink wrote:

Should I define lRow as a PByteArray?

In delphi mode, Yes.

Unless you want to compile this in Delphi, there is no reason to use 
delphi mode. You can, if needed, use a different mode per unit.


Hi Marc,
  Thanks for that and I'm a little bit further, but now get a crash.

The original data is stored as follows...

type
  TDWordArray = array [WORD] of DWord;
 PDWordArray = ^TDWordArray;
 TBGR = packed record b,g,r: BYTE; end;   // for 24-bit bitmaps
 TBGRArray = array [WORD] of TBGR;
 PBGRArray = ^TBGRArray;

  TBGRA = packed record b,g,r,a: BYTE; end;// for 32-bit bitmaps
 TBGRAArray = array [WORD] of TBGRA;
 PBGRAArray = ^TBGRAArray;

var
  s_data:PDWordArray;  // the actual data

and I'm trying to convert it to a TBitmap using the following code...

function TInternalBitmap.CreateBitmap24 : TBitmap;
// Returns a 24-bit bitmap from the object
var
  row:PBGRArray;   // Row in the bitmap
  i,j:integer;

  ScanLineImage : TLazIntfImage;
  ImgFormatDescription : TRawImageDescription;
begin
  Result := nil;

  Result := TBitmap.Create;
  Result.PixelFormat := pf24bit;
  Result.Width := s_w;
  Result.Height := s_h;

  ScanLineImage := TLazIntfImage.Create( s_w, s_h );
  ImgFormatDescription.Init_BPP24_B8G8R8_BIO_TTB( s_w, s_h );
  ScanLineImage.DataDescription := ImgFormatDescription;

  for j := 0 to s_h - 1 do
  begin
row := ScanLineImage.GetDataLineStart( j );
for i := 0 to s_w-1 do
begin
  row[i].r := (s_data[j*s_w+i] shr 16) and $ff;
  row[i].g := (s_data[j*s_w+i] shr 8) and $ff;
  row[i].b := s_data[j*s_w+i] and $ff;
end;
  end;

  // create IntfImage with the format of the current LCL interface
  Result.Width := ScanLineImage.Width;
  Result.Height := ScanLineImage.Height;

  // convert the content from the very specific to the current format
  Result.LoadFromIntfImage( ScanLineImage );

  ScanLineImage.Free;

  { Original Delphi code...

  // Copy the data to the bitmap
  for j := 0 to s_h-1 do
  begin
row := Result.ScanLine[j];
for i := 0 to s_w-1 do
begin
  row[i].r := (s_data[j*s_w+i] shr 16) and $ff;
  row[i].g := (s_data[j*s_w+i] shr 8) and $ff;
  row[i].b := s_data[j*s_w+i] and $ff;
end;
  end;}
end;

But the call to Result.LoadFromIntfImage( ScanLineImage ); causes an AV 
and I'm not sure why.


From what I can tell it's correctly grabbing the scanline information.

Any ideas?


Dominique.

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread wile64
Hi,


I am not sure but this test.

var
  BmpResult: TBitmap;
begin
  ...
  ...

BmpResult:=TBitmap.Create;
BmpResult.LoadFromIntfImage( ScanLineImage );



-- 
Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread wile64
Sorry, He's not finish


I am not sure but this test.

var
  BmpResult: TBitmap;
begin
  ...
  ...

BmpResult:=TBitmap.Create;
BmpResult.LoadFromIntfImage( ScanLineImage );

Result:=BmpResult;
ScanLineImage.Free;

Not BmpResult.Free in function

-- 
Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread Dominique Louis

Sorry I don't quite understand what you mean.

Result is not freed in the function so the Bitmap should be fine.

Please explain further.

wile64 wrote:

Sorry, He's not finish


I am not sure but this test.

var
  BmpResult: TBitmap;
begin
  ...
  ...

BmpResult:=TBitmap.Create;
BmpResult.LoadFromIntfImage( ScanLineImage );

Result:=BmpResult;
ScanLineImage.Free;

Not BmpResult.Free in function

--
Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64 
http://wiki.lazarus.freepascal.org/Wile64

French Forum : http://lazforum-fr.tuxfamily.org/index.php


_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread wile64
2007/11/25, Dominique Louis [EMAIL PROTECTED]:

 Sorry I don't quite understand what you mean.

 Result is not freed in the function so the Bitmap should be fine.

 Please explain further.



We need to create a function that returns a bitmap created by this or that
it is necessary to create a procedure with a bitmap variable his modified by
procedure

Because I have a bad English I give an example ;)

example With function TInternalBitmap.CreateBitmap24 : TBitmap;

var MyBitmap: TBitmap;
begin
  MyBitmap:=CreateBitmap24;
  ...
  ...
  MyBitmap.Free;
end;
or
example with procedure TInternalBitmap.CreateBitmap24(ABitmap: TBitmap);

var MyBitmap: TBitmap;
begin
  MyBitmap:= TBitmap.Create;
  CreateBitmap24(MyBitmap);
  ...
  ...
  MyBitmap.Free;
end;

Bitmap is always free by calling...

Regards,

Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread Dominique Louis
Yes in this case the function that calls CreateBitmap24 will take care 
of freeing the Bitmap. But this does not fix my original problem to do 
with the AV on line Result.LoadFromIntfImage( ScanLineImage );


Dominique.

wile64 wrote:



2007/11/25, Dominique Louis [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]:


Sorry I don't quite understand what you mean.

Result is not freed in the function so the Bitmap should be fine.

Please explain further.



We need to create a function that returns a bitmap created by this or 
that it is necessary to create a procedure with a bitmap variable his 
modified by procedure


Because I have a bad English I give an example ;)

example With function TInternalBitmap.CreateBitmap24 : TBitmap;

var MyBitmap: TBitmap;
begin
  MyBitmap:=CreateBitmap24;
  ...
  ...
  MyBitmap.Free;
end;
or
example with procedure TInternalBitmap.CreateBitmap24(ABitmap: TBitmap);

var MyBitmap: TBitmap;
begin
  MyBitmap:= TBitmap.Create;
  CreateBitmap24(MyBitmap);
  ...
  ...
  MyBitmap.Free;
end;

Bitmap is always free by calling...

Regards,

Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php



_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread wile64
2007/11/25, Dominique Louis [EMAIL PROTECTED]:

 Yes in this case the function that calls CreateBitmap24 will take care
 of freeing the Bitmap. But this does not fix my original problem to do
 with the AV on line Result.LoadFromIntfImage( ScanLineImage );

 Dominique.


Result does not exist, it must be created that is why there was an error.


-- 
Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread wile64
I say a mistake, sorry :)

2007/11/25, wile64 [EMAIL PROTECTED]:

 2007/11/25, Dominique Louis [EMAIL PROTECTED]:
 
  Yes in this case the function that calls CreateBitmap24 will take care
  of freeing the Bitmap. But this does not fix my original problem to do
  with the AV on line Result.LoadFromIntfImage( ScanLineImage );
 
  Dominique.
 

 Result does not exist, it must be created that is why there was an error.


 --
 Laurent.

 My Components: http://wiki.lazarus.freepascal.org/Wile64
 French Forum : http://lazforum-fr.tuxfamily.org/index.php




-- 
Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread Dominique Louis

But the first 3 lines of the CreateBitmap24 function are


begin
  Result := nil;

  Result := TBitmap.Create; // CREATED HERE!
  Result.PixelFormat := pf24bit;
  Result.Width := s_w;
  Result.Height := s_h;
.
.
.

end;

wile64 wrote:
2007/11/25, Dominique Louis [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]:


Yes in this case the function that calls CreateBitmap24 will take care
of freeing the Bitmap. But this does not fix my original problem to do
with the AV on line Result.LoadFromIntfImage( ScanLineImage );

Dominique.


Result does not exist, it must be created that is why there was an error.


--
Laurent.


_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-25 Thread wile64
Did you test the example of lazarus in
lazarus\example\scanline\bitmapscanline1.lpi see if it works ?

Regards,

-- 
Laurent.

My Components: http://wiki.lazarus.freepascal.org/Wile64
French Forum : http://lazforum-fr.tuxfamily.org/index.php


Re: [lazarus] Mac OS X : Bitmap ScanLine....

2007-11-21 Thread Marc Weustink

Dominique Louis wrote:
I know I've labeled this as Mac OS X, it's probably not specific to that 
 OS.


I've looked at the scanline demo and it works fine on Mac OS X.

My question is when I try to use the code in my project using Delphi 
compatability mode,  I get the error listed below...


var
  lRow : Pointer;
  ScanLineImage : TLazIntfImage;
begin
  for j := 0 to Height - 1 do
  begin
lRow := ScanLineImage.GetDataLineStart( j );
i := 0;
while ( i  Width - 1 ) do
begin
  PByte(lRow)[i] := 0;  // Error : Array type required
end;
  end;
end;

Why and is there a fix for this? 


in objfpc mode you can access any typed pointer as an array like:

var
  p: PWord;
begin
  ...
  p[someindex] := 12345;


Should I define lRow as a PByteArray?

In delphi mode, Yes.

Unless you want to compile this in Delphi, there is no reason to use 
delphi mode. You can, if needed, use a different mode per unit.


Marc

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


[lazarus] Mac OS X : Bitmap ScanLine....

2007-11-20 Thread Dominique Louis
I know I've labeled this as Mac OS X, it's probably not specific to that 
 OS.


I've looked at the scanline demo and it works fine on Mac OS X.

My question is when I try to use the code in my project using Delphi 
compatability mode,  I get the error listed below...


var
  lRow : Pointer;
  ScanLineImage : TLazIntfImage;
begin
  for j := 0 to Height - 1 do
  begin
lRow := ScanLineImage.GetDataLineStart( j );
i := 0;
while ( i  Width - 1 ) do
begin
  PByte(lRow)[i] := 0;  // Error : Array type required
end;
  end;
end;

Why and is there a fix for this? Should I define lRow as a PByteArray?

Thanks,


Dominique.

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives