Link to home
Start Free TrialLog in
Avatar of andru
andru

asked on

What is the proper way to use Scanline?

Hi

I'm using the Scanline function to count pixels in a bitmap rather that use the pixels property which takes donkeys years to finish. But I'm not sure how Scanline works. The documentation in Delphi is pretty unclear as to what format the Scanline array is. So is the following code right?

const
  max_width=640;

type
  p_colour_array=^colour_array;
  colour_array=array[0..max_width-1] of longint;

  p_byte_array=^byte_array;
  byte_array=array[0..2] of byte;

procedure count_pixels(
  bitmap:tbitmap;
  colour:tcolor);
var
  py,px:integer;
  b:p_byte_array;
  l:p_colour_array;
begin
  pixel_count:=0;
  with bitmap do
     for py:=0 to height-1 do
    begin
       l:=scanline[py];
      for px:=0 to width-1 do
        begin
          b:=@l[px];
          if tcolor(rgb(b^[2],b^[1],b^[0]))=colour then
            inc(pixel_count);
        end;
    end;
 end;

TIA
Avatar of mokule
mokule
Flag of Poland image

Well
I'm using it as follows for example

procedure TForm1.Bmp2YUV(bmp:TBitmap);
var
  h,w: integer;
  i,j: integer;
  row: pByteArray;
  Y,U,V: Byte;
begin
  h := bmp.Height;
  w := bmp.Width;
  for i := 0 to h-1 do
    begin
    row := pByteArray(bmp.ScanLine[i]);
    for j := 0 to w-1 do
      begin
      BGR2YUV(row[3*j],row[3*j+1],row[3*j+2],Y,U,V);
//      some code using Y, U and V
      end;
    end;
end;
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial