I am trying to convert some Delphi code to Python PIL. The problem is two pronged. First, I'm not a Delphi programmer. Second, I haven't used PIL before today so I may have problems in either area.
case PixelFormat of
pf32bit: PixSize:=4;
pf24bit: PixSize:=3;
pf16bit: PixSize:=2;
end;
BitCounter:=0;
for i:=0 to Height-1 do begin
Row:=ScanLine[i];
PB:=@Row[PixSize-1];
for j:=0 to Width-1 do begin
Ch[BitCounter] := (PB^ and 1);
....
inc(BitCounter);
inc(PB, PixSize);
end;
So I get that the PixelFormat attribute denotes the size of each pixel in bytes. I also get that the ScanLine method is supposed to get an array of pixels that represent the line. What I don't get is that I tend to visualize each pixel as an RGB value. I'm used to extracting the least significant bit of a color value. However, I don't think I'm even sure what the existing code is extracting. I have some python PIL code that will extract RGB values of each pixel in the same image, but I don't know how the tuple of RGB values compares to PB variable obtained in the earlier code. Based on some experiments I'm guessing that it doesn't compare at all.
Thanks in advance.
In case anyone is trying to do this later. Thanks to David for the help in clarifying what ScanLine was returning.