View Issue Details

IDProjectCategoryView StatusLast Update
0015893LazarusLCLpublic2010-11-26 10:20
ReporterPetr-K Assigned ToMarc Weustink  
Status assignedResolutionopen 
OSLinux 2.6.26-2-686 #1 SMP 
Product Version0.9.28.3 (SVN) 
Summary0015893: BW bitmap in gtk and invalid Description.LineEnd
DescriptionI use TLazIntfImage to access color data in bitmap by TLazIntfImage.Colors[x, y].
In case of bw bitmap (1bbp) and image width not multiply of 32, result was unsynchronized (scanlines shifted).
Steps To ReproduceIn the attachment is problematic image.
Additional InformationThis patch solves my problem:

Index: lcl/interfaces/gtk/
--- lcl/interfaces/gtk/ (revision 23714)
+++ lcl/interfaces/gtk/ (working copy)
@@ -1861,7 +1861,7 @@
   if IsBitmap
   then begin
- ADesc.LineEnd := rileByteBoundary;
+ ADesc.LineEnd := rileDWordBoundary;
     ADesc.RedPrec := 1;
     ADesc.RedShift := 0;
TagsNo tags attached.
Fixed in Revision
WidgetsetGTK 2
Attached Files


2010-03-05 14:50


image_bad.png (404 bytes)   
image_bad.png (404 bytes)   

2010-03-05 14:57


psc1.pas (443 bytes)   
program psc1;

  interfaces, LCLType, LCLIntf,
  SysUtils, Classes, graphics, postscriptcanvas;

procedure pimg(c: TCanvas);
  Img: TPicture;
  Img := TPicture.Create;
  c.StretchDraw(Rect(10, 10,1000,1000), Img.Graphic);

  c: TPostScriptCanvas;
  c := TPostScriptCanvas.Create(nil);
  c.OutPutFileName := '';
psc1.pas (443 bytes)   


2010-03-05 14:58

reporter   ~0034952

Attched file psc1.pas is possibe to use for testing. TPoscriptCanvas uses the same access method.

2010-03-05 14:59


image_ok.png (308 bytes)   
image_ok.png (308 bytes)   

Marc Weustink

2010-04-13 00:04

administrator   ~0036653

Last edited: 2010-04-13 00:15

this is strange, since from the X bitmap specs it is on a byte boundary (iirc)
Changing it is not trivial

BTW, the ok sample image is 256 pix wide, so it is byte,word,dword and qword aligned (maybe the srcpointer isnt)

Marc Weustink

2010-04-14 00:40

administrator   ~0036683

Why do you think it should be aligned to a dword ? 1bpp bitmaps are aligned on ba byte boundary. IMO this is not a gtk error, but an error in the postscriptcanvas assuming this.

BTW, when accessing TLazIntfImage.Colors[x, y], no gtk function is used.


2010-04-16 11:46

reporter   ~0036748

Postscriptcanvas do not has nothing in common with this problem. It needs only access to image bit by bit and uses TLazIntfImage.Colors[x, y]. Here is mentioned only as error demonstration example.

IMHO Gtk(GDK) is responsible for loading image into memory. Function TGtkWidgetSet.RawImage_DescriptionFromDrawable discovers image format in memory.
And this information is used by TLazIntfImage.

In case of 1bbp image format discover algorithm fails. Setting DWord alignment solves my problem. But I'am not sure if this is right solution. I do not know gdk deeply. And do not know if it will work on 64-bit systems or in future gdk versions. But it provisionally works for me.


2010-10-21 16:21

reporter   ~0041959

I adjusted my patch to newly separated gtk2 tree:

Index: lcl/interfaces/gtk2/
--- lcl/interfaces/gtk2/ (revision 27585)
+++ lcl/interfaces/gtk2/ (working copy)
@@ -3002,7 +3002,7 @@
   if IsBitmap
   then begin
- ADesc.LineEnd := rileByteBoundary;
+ ADesc.LineEnd := rileDWordBoundary;
     ADesc.RedPrec := 1;
     ADesc.RedShift := 0;

Patch was tested successfully on 32 and 64-bit Linuxes
Debian Lenny x86 with
and Ubuntu 10.10 AMD64 with

Marc Weustink

2010-10-23 17:13

administrator   ~0042030

This only breaks it. 1bpp bitmaps are byte aligned. For all widgetsets. Your problem is elsewhere. Something assumes it is dword aligned. it is not. try fixing that.


2010-10-25 16:49

reporter   ~0042111

Function TGtk2WidgetSet.RawImage_DescriptionFromDrawable
gets ADrawable: PGdkDrawable (image loaded in memory by gdk) and returns ADesc: TRawImageDescription i.e. Width,Height,Depth,...LineEnd... that describes how is the image stored in memory.

TLazIntfImage uses this information to access individual poins of bitmap by function Colors[x, y].

I use this function to transfer bitmap point-by-point to cairo image surface.
Here is none alignment assumption.

Only one alignment assumption is in RawImage_DescriptionFromDrawable.

2010-10-26 14:27


1.png (312 bytes)   
1.png (312 bytes)   


2010-10-26 14:33

reporter   ~0042145

I'v done some working example. In attached files is problematic bitmap 1.png.

program toppm;

{$mode objfpc}

   Graphics, IntfGraphics, FPImage, interfaces;
  P: TPicture;
  Img: TLazIntfImage;
  x, y: Word;
  c: TFPColor;
  f: TextFile;
  P := TPicture.Create;
  AssignFile(f, '1.ppm');
  Writeln(f, 'P3');
  Writeln(f, P.Width, ' ', P.Height);
  Writeln(f, 255);
  Img := TRasterImage(P.Graphic).CreateIntfImage;
  for y := 0 to P.Height-1 do begin
    for x := 0 to P.Width-1 do begin
      c := Img.Colors[x, y];
      Writeln(f, Hi(, ' ', Hi(, ' ', Hi(;

Issue History

Date Modified Username Field Change
2010-03-05 14:50 Petr-K New Issue
2010-03-05 14:50 Petr-K File Added: image_bad.png
2010-03-05 14:50 Petr-K Widgetset => GTK 2
2010-03-05 14:57 Petr-K File Added: psc1.pas
2010-03-05 14:58 Petr-K Note Added: 0034952
2010-03-05 14:59 Petr-K File Added: image_ok.png
2010-03-05 20:13 Jesus Reyes Status new => assigned
2010-03-05 20:13 Jesus Reyes Assigned To => Marc Weustink
2010-04-13 00:04 Marc Weustink Note Added: 0036653
2010-04-13 00:05 Marc Weustink Note Edited: 0036653
2010-04-13 00:15 Marc Weustink Note Edited: 0036653
2010-04-14 00:40 Marc Weustink LazTarget => -
2010-04-14 00:40 Marc Weustink Note Added: 0036683
2010-04-14 00:40 Marc Weustink Status assigned => feedback
2010-04-16 11:46 Petr-K Note Added: 0036748
2010-10-21 16:21 Petr-K Note Added: 0041959
2010-10-23 17:13 Marc Weustink Note Added: 0042030
2010-10-25 16:49 Petr-K Note Added: 0042111
2010-10-26 14:27 Petr-K File Added: 1.png
2010-10-26 14:33 Petr-K Note Added: 0042145
2010-11-26 10:20 Vincent Snijders Status feedback => assigned