View Issue Details

IDProjectCategoryView StatusLast Update
0015893LazarusLCLpublic2010-11-26 10:20
ReporterPetr-K Assigned ToMarc Weustink  
PrioritynormalSeverityminorReproducibilityalways
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/gtkwidgetset.inc
===================================================================
--- lcl/interfaces/gtk/gtkwidgetset.inc (revision 23714)
+++ lcl/interfaces/gtk/gtkwidgetset.inc (working copy)
@@ -1861,7 +1861,7 @@
 
   if IsBitmap
   then begin
- ADesc.LineEnd := rileByteBoundary;
+ ADesc.LineEnd := rileDWordBoundary;
     ADesc.RedPrec := 1;
     ADesc.RedShift := 0;
   end
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

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;

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

procedure pimg(c: TCanvas);
var
  Img: TPicture;
begin
  Img := TPicture.Create;
  Img.LoadFromFile('psc.png');
  c.StretchDraw(Rect(10, 10,1000,1000), Img.Graphic);
  Img.Free;
end;


var
  c: TPostScriptCanvas;
begin
  c := TPostScriptCanvas.Create(nil);
  c.BeginDoc;
  c.OutPutFileName := 'psc.ps';
  pimg(c);
  c.EndDoc;
  c.Free;
end.
psc1.pas (443 bytes)   

Petr-K

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.

Petr-K

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.

Petr-K

2010-10-21 16:21

reporter   ~0041959

I adjusted my patch to newly separated gtk2 tree:

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

Patch was tested successfully on 32 and 64-bit Linuxes
Debian Lenny x86 with libgdk-x11-2.0.so.0.1200.12
and Ubuntu 10.10 AMD64 with libgdk-x11-2.0.so.0.2200.0

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.

Petr-K

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)   

Petr-K

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}

uses
   Graphics, IntfGraphics, FPImage, interfaces;
var
  P: TPicture;
  Img: TLazIntfImage;
  x, y: Word;
  c: TFPColor;
  f: TextFile;
begin
  P := TPicture.Create;
  P.LoadFromFile('1.png');
  AssignFile(f, '1.ppm');
  Rewrite(f);
  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(c.red), ' ', Hi(c.green), ' ', Hi(c.blue));
    end;
  end;
  Close(f);
  Img.Free;
  P.Free;
end.

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