Re:Convert 1-bit b&w bitmap to grayscale bitmap
Quote
> I see pleny of examples of how to convert a 24 bit color bitmap to
> grayscale, but not a 1-bit b&w to grayscale.....
Grayscale (8 bit) stores more information than b&w (1 bit), so it should
be pretty easy to convert it (the difficult part is to reduce the
information, which is not needed in this case). Do you need a fast
scanline algorithm? It would be something like...
var
BWPointer: ^Byte;
GrayPointer: ^Byte;
x,y: Integer;
BitNumber,BitValue: Byte;
begin
for y := 0 to Height-1 do begin
BWPointer := BWBitmap.ScanLine[y];
GrayPointer := GrayBitmap.ScanLine[y];
for x := 0 to Width-1 do begin
BitNumber := x AND 7; // or maybe 7-(x AND 7) ???
BitValue := BWPointer^ SHR (BitNumber) AND 1;
GrayPointer^ := BitValue*255; // or more general: a+BitValue*b;
Inc (GrayPointer);
if (x AND 7) = 7 then Inc (BWPointer);
end;
end;
end;
This code was not tested and can probably be enhanced (for example by
using a 32 bit BWPointer).
Jens