Board index » delphi » Convert 1-bit b&w bitmap to grayscale bitmap

Convert 1-bit b&w bitmap to grayscale bitmap

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.....

Can anyone provide me with an actual example of how to accomplish this?
--
Brent Hampton

 

Re:Convert 1-bit b&w bitmap to grayscale bitmap


You intend to create information that was not there before.
I'd start with 0 -> 0(black) and 1 -> 255(white)
then you could do a lowpass filter that smears a bit.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Quote
Brent Hampton wrote:

> 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.....

> Can anyone provide me with an actual example of how to accomplish this?
> --
> Brent Hampton

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

Re:Convert 1-bit b&w bitmap to grayscale bitmap


Thanks!

Quote
"Brent Hampton" <bhamp...@automatedconveyors.com> wrote in message

news:3c050b71$1_2@dnews...
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.....

> Can anyone provide me with an actual example of how to accomplish this?
> --
> Brent Hampton

Other Threads