Hi *,
attached is a small patch which enables the LCL to read RLE encoded BMP
files (successfully tested with some hundreds of small 8 bpp bitmaps, 4
bpp should work as well).
Maybe somebody wants to commit this small patch :)
Diff is against Lazarus 0.9.24
Regards,
Sebastian
426a427
> FIsRLE: Boolean; // Is data RLE compressed?
432c433
< procedure SetupRead(nPalette, nRowBits: Integer; ReadPalette: Boolean); virtual;
---
> procedure SetupRead(nPalette, nRowBits: Integer; ReadPalette, AIsRLE: Boolean); virtual;
443a445
> property IsRLE: Boolean read FIsRLE;
4411c4413
< procedure TLazReaderBMP.SetupRead(nPalette, nRowBits: Integer; ReadPalette: Boolean);
---
> procedure TLazReaderBMP.SetupRead(nPalette, nRowBits: Integer; ReadPalette, AIsRLE: Boolean);
4415a4418
> FIsRLE := AIsRLE;
4443a4447,4449
> var
> d: array[0..1] of Byte;
> Offset: Integer;
4450c4456,4484
< TheStream.Read(LineBuf[0], ReadSize);
---
> if IsRLE then
> begin
> Offset := 0;
> while True do
> begin
> TheStream.Read(d[0], 2);
> if d[0] > 0 then
> begin
> while d[0] > 0 do
> begin
> LineBuf[Offset] := d[1];
> Inc(Offset);
> Dec(d[0]);
> end;
> end else
> case d[1] of
> 0, 1: break; // End of scanline or end of bitmap
> 2: raise FPImageException.Create('RLE code #2 is not supported');
> else
> begin
> TheStream.Read(LineBuf[Offset], d[1]);
> Inc(Offset, d[1]);
> if Odd(d[1]) then
> TheStream.Read(d[1], 1); // Jump to even file position
> end;
> end;
> end;
> end else
> TheStream.Read(LineBuf[0], ReadSize);
4623c4657
< SetupRead(2, TheImage.Width, true);
---
> SetupRead(2, TheImage.Width, True, False);
4627,4629c4661,4662
< BI_RGB: SetupRead(16, TheImage.Width * 4, true);
< BI_RLE4:
< raise FPImageException.Create('4 bit RLE Bitmaps not supported');
---
> BI_RGB: SetupRead(16, TheImage.Width * 4, True, False);
> BI_RLE4: SetupRead(16, TheImage.Width * 4, True, True);
4636,4638c4669,4670
< BI_RGB: SetupRead(256, TheImage.Width * 8, true);
< BI_RLE8:
< raise FPImageException.Create('8 bit RLE Bitmaps not supported');
---
> BI_RGB: SetupRead(256, TheImage.Width * 8, True, False);
> BI_RLE8: SetupRead(256, TheImage.Width * 8, True, True);
4669c4701
< SetupRead(0, TheImage.Width * 16, True);
---
> SetupRead(0, TheImage.Width * 16, True, False);
4689c4721
< SetupRead(0, TheImage.Width * 24, True);
---
> SetupRead(0, TheImage.Width * 24, True, False);
4712c4744
< SetupRead(0, TheImage.Width * 32, True);
---
> SetupRead(0, TheImage.Width * 32, True, False);
4816c4848
< SetupRead(2, Img.Width, False);
---
> SetupRead(2, Img.Width, False, False);