Recent

Author Topic: Delphi code using ScanLine  (Read 5386 times)

lainz

  • Guest
Delphi code using ScanLine
« on: February 04, 2013, 05:42:10 pm »
Hi, I have this code that works with Delphi, and it uses ScanLine that there's no available on lazarus, how I can convert it?

See attached file.

Code: [Select]
// Dan de pixels zelf. Blijkbaar bestaat een icoon uit 4x4 tiles van
      // 8x8 pixels.
      for y := 0 to 31 do
      begin
        ScanLine := Icon.ScanLine[y];

        for x := 0 to 31 do
        begin
          // Bereken de tile-index
          t := ((y shr 1) and not 3) + x shr 3;
          // Vermenigvuldig deze met 32 (32 bytes per tile) en tel er de
          // byte-index binnen de tile bij op. Doordat alles zo mooi met
          // machten van twee werkt kunnen we zelfs de modulo vervangen door
          // 'and'.
          i := (t shl 5) + ((x shr 1) and 3) + ((y and 7) shl 2);
          // Lees de juiste nibble uit de tile-data
          b := Banner.TileData[i];
          if x and 1 = 1 then
            b := b shr 4
          else
            b := b and $F;

          // Pixel zetten
          ScanLine^[x] := Palette[b];
        end;
      end;

Thanks.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Delphi code using ScanLine
« Reply #1 on: February 04, 2013, 06:16:23 pm »
The wiki suggests this:

"Since Lazarus has no TBitmap.ScanLines property, the best way to access the pixels of an image in a fast way for both reading and writing is by using TLazIntfImage. The TBitmap can be converted to a TLazIntfImage by using TBitmap.CreateIntfImage() and after modifying the pixels it can be converted back to a TBitmap by using TBitmap.LoadFromIntfImage(); Here's the sample on how to create TLazIntfImage from TBitmap, modify it and then go back to the TBitmap."

Code: [Select]
uses
  ...GraphType, IntfGraphics, LCLType, LCLProc,  LCLIntf ...
 
procedure TForm1.Button4Click(Sender: TObject);
var
  b: TBitmap;
  t: TLazIntfImage;
begin
  b := TBitmap.Create;
  try
    b.LoadFromFile('test.bmp');
    t := b.CreateIntfImage;
 
    // Read and/or write to the pixels
    t.Colors[10,20] := colGreen;
 
    b.LoadFromIntfImage(t);
  finally
    t.Free;
    b.Free;
  end;
end;

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Delphi code using ScanLine
« Reply #2 on: February 04, 2013, 06:22:59 pm »
Well, you can use BGRABitmap of course.
Conscience is the debugger of the mind

dcelso

  • Full Member
  • ***
  • Posts: 158
Re: Delphi code using ScanLine
« Reply #3 on: February 04, 2013, 06:35:09 pm »
uses
  ...GraphType, IntfGraphics, LCLType, LCLProc,  LCLIntf ...
 
procedure TForm1.Button4Click(Sender: TObject);
var
  bmp: TBitmap;
  t: TLazIntfImage;
begin
  bmp := TBitmap.Create;
  try
    bmp.LoadFromFile('test.bmp');
    t := b.CreateIntfImage;
 
for y := 0 to 31 do
      begin
        ScanLine := t.getdatalinestart(y);

        for x := 0 to 31 do
        begin
          // Bereken de tile-index
          t := ((y shr 1) and not 3) + x shr 3;
          // Vermenigvuldig deze met 32 (32 bytes per tile) en tel er de
          // byte-index binnen de tile bij op. Doordat alles zo mooi met
          // machten van twee werkt kunnen we zelfs de modulo vervangen door
          // 'and'.
          i := (t shl 5) + ((x shr 1) and 3) + ((y and 7) shl 2);
          // Lees de juiste nibble uit de tile-data
          b := Banner.TileData;
          if x and 1 = 1 then
            b := b shr 4
          else
            b := b and $F;

          // Pixel zetten
          ScanLine^
  • := Palette;

        end;
      end;
 
    bmp.LoadFromIntfImage(t);
  finally
    t.Free;
    bmp.Free;
  end;
end;

lainz

  • Guest
Re: Delphi code using ScanLine
« Reply #4 on: February 04, 2013, 07:44:34 pm »
Thanks to all, I will try the different solutions.

 :D

 

TinyPortal © 2005-2018