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_arr ay;
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]))=colou r then
inc(pixel_count);
end;
end;
end;
TIA
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_arr
colour_array=array[0..max_
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^[
inc(pixel_count);
end;
end;
end;
TIA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
// some code using Y, U and V
end;
end;
end;