View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0036254 | Lazarus | Widgetset | public | 2019-11-03 18:31 | 2019-12-11 12:36 |
Reporter | Alexey Tor. | Assigned To | Juha Manninen | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | reopened | ||
Platform | Ubuntu 19 x64 | OS | OS Version | ||
Product Version | 2.1 (SVN) | Product Build | |||
Target Version | Fixed in Version | ||||
Summary | 0036254: gtk3: PNG images render badly | ||||
Description | CudaText gtk3 build shows many paint bugs. screenshot shows them. PNG icons render badly. these are icons https://github.com/Alexey-T/CudaText/tree/master/app/data/toolbaricons/default_24x24 they are painted from usual PNG class to TBitmap's canvas, then TBitmap canvas CopyRect'ed to screen. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | r62310, r62377 | ||||
LazTarget | - | ||||
Widgetset | GTK 3 | ||||
Attached Files |
|
related to | 0027225 | closed | Zeljan Rikalo | [GTK3] RawImage_CreateBitmaps create every bitmap with alpha channel |
related to | 0036374 | new | gtk3: Canvas artifacts, swapped R/B colors |
|
|
|
Please provide a simple example with one PNG->BMP painting. |
|
Added small demo+ ugly screenshot (compare its look on gtk2--gtk3). tst-gtk3-png.zip (10,153 bytes) |
|
gtk3: a) no transparent color is used for last 2 icons. b) very blurry first icons (red, blue). |
|
Patch provided. Original drawsurface worked with already prepared surfaces - so alpha disappeared. New method drawImage1() acesses original PGdkPixbuf.
gtk3winapi_fix.diff (3,451 bytes)
Index: interfaces/gtk3/gtk3objects.pas =================================================================== --- interfaces/gtk3/gtk3objects.pas (revision 62295) +++ interfaces/gtk3/gtk3objects.pas (working copy) @@ -239,6 +239,8 @@ mask: PGdkPixBuf; maskRect: PRect); procedure drawImage(targetRect: PRect; image: PGdkPixBuf; sourceRect: PRect; mask: PGdkPixBuf; maskRect: PRect); + procedure drawImage1(targetRect: PRect; image: PGdkPixBuf; sourceRect: PRect; + mask: PGdkPixBuf; maskRect: PRect); procedure drawPixmap(p: PPoint; pm: PGdkPixbuf; sr: PRect); procedure drawPolyLine(P: PPoint; NumPts: Integer); procedure drawPolygon(P: PPoint; NumPts: Integer; FillRule: integer); @@ -1468,6 +1470,8 @@ // ASurface := cairo_image_surface_create_for_data(AData, CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pm), gdk_pixbuf_get_height(pm), gdk_pixbuf_get_rowstride(pm)); // cairo_set_source_surface(Widget, ASurface, targetRect^.Left, targetRect^.Top); gdk_cairo_set_source_pixbuf(Widget, Image, 0, 0); + with targetRect^ do + cairo_rectangle(Widget, Left, Top, Right-Left, Bottom-Top); cairo_paint(Widget); finally // cairo_surface_destroy(ASurface); @@ -1475,6 +1479,35 @@ end; end; +procedure TGtk3DeviceContext.drawImage1(targetRect: PRect; image: PGdkPixBuf; + sourceRect: PRect; mask: PGdkPixBuf; maskRect: PRect); +var + M: cairo_matrix_t; +begin + {$IFDEF VerboseGtk3DeviceContext} + DebugLn('TGtk3DeviceContext.DrawImage '); + {$ENDIF} + cairo_save(Widget); + try + gdk_cairo_set_source_pixbuf(Widget, Image, 0, 0); + with targetRect^ do + cairo_rectangle(Widget, Left, Top, Right - Left, Bottom - Top); + + cairo_matrix_init_identity(@M); + cairo_matrix_translate(@M, SourceRect^.Left, SourceRect^.Top); + cairo_matrix_scale(@M, (sourceRect^.Right-sourceRect^.Left) / (targetRect^.Right-targetRect^.Left), + (sourceRect^.Bottom-sourceRect^.Top) / (targetRect^.Bottom-targetRect^.Top)); + cairo_matrix_translate(@M, -targetRect^.Left, -targetRect^.Top); + cairo_pattern_set_matrix(cairo_get_source(Widget), @M); + //cairo_fill (Widget); + cairo_clip(Widget); + cairo_paint(Widget); + finally + cairo_restore(Widget); + end; +end; + + procedure TGtk3DeviceContext.drawPixmap(p: PPoint; pm: PGdkPixbuf; sr: PRect); var AImage: PGtkImage; Index: interfaces/gtk3/gtk3winapi.inc =================================================================== --- interfaces/gtk3/gtk3winapi.inc (revision 62295) +++ interfaces/gtk3/gtk3winapi.inc (working copy) @@ -4066,7 +4066,6 @@ DestContext: TGtk3DeviceContext absolute DestDC; SrcContext: TGtk3DeviceContext absolute SrcDC; ATargetRect, ASrcRect: TRect; - //AImage: PGdkPixbuf; begin Result := False; {$IFDEF GTK3DEBUGNOTIMPLEMENTED} @@ -4074,11 +4073,7 @@ {$ENDIF} ATargetRect := Rect(X, Y, Width + X, Height + Y); ASrcRect := Rect(XSrc, YSrc, SrcWidth + XSrc, SrcHeight + YSrc); - // AImage := gdk_pixbuf_new_subpixbuf(); - // DestContext.drawImage(@ATargetRect, SrcContext.ParentPixmap, @ASrcRect, nil, nil); - // Ask for DestContext type of surface (surface/image) and then draw - DestContext.drawSurface(@ATargetRect, SrcContext.CairoSurface, @ASrcRect, nil, nil); - // DestContext.drawImage(); + DestContext.drawImage1(@ATargetRect, PgdkPixbuf(SrcContext.CurrentImage.Handle) , @ASrcRect, nil, nil); // Result := True; end; |
|
The fix works, thanks. but.... now CudaText gtk3 shows broken main editor area (painted on bitmap first). and crashes. #0 SYSTEM_$$_MOVE$formal$formal$INT64 at :0 0000001 RAWIMAGE_FROMBITMAP(0x7ffff7f3c040, {DESCRIPTION = {FORMAT = RICFRGBA, WIDTH = 14, HEIGHT = 512, DEPTH = 24, BITORDER = RIBOREVERSEDBITS, BYTEORDER = RIBOLSBFIRST, LINEORDER = RILOTOPTOBOTTOM, LINEEND = RILEDWORDBOUNDARY, BITSPERPIXEL = 32, REDPREC = 8, REDSHIFT = 16, GREENPREC = 8, GREENSHIFT = 8, BLUEPREC = 8, BLUESHIFT = 0, ALPHAPREC = 0, ALPHASHIFT = 0, MASKBITSPERPIXEL = 1, MASKSHIFT = 0, MASKLINEEND = RILEDWORDBOUNDARY, MASKBITORDER = RIBOREVERSEDBITS, PALETTECOLORCOUNT = 0, PALETTEBITSPERINDEX = 0, PALETTESHIFT = 0, PALETTELINEEND = RILETIGHT, PALETTEBITORDER = RIBOBITSINORDER, PALETTEBYTEORDER = RIBOLSBFIRST}, DATA = 0x7fffe46c3050 0000208#208#208#255#208#208#208#255#208#208#208#255#208#208#208#255#208#208#208#255#208#208#208#255#208..., DATASIZE = 28658, MASK = 0x7fffe46ca070 '', MASKSIZE = 28658, PALETTE = 0x0, PALETTESIZE = 0}, 140737053338816, 140737053338880, 0x0) at gtk3/gtk3lclintf.inc:759 0000002 RAWIMAGE_FROMBITMAP({DESCRIPTION = {FORMAT = RICFRGBA, WIDTH = 14, HEIGHT = 512, DEPTH = 24, BITORDER = RIBOREVERSEDBITS, BYTEORDER = RIBOLSBFIRST, LINEORDER = RILOTOPTOBOTTOM, LINEEND = RILEDWORDBOUNDARY, BITSPERPIXEL = 32, REDPREC = 8, REDSHIFT = 16, GREENPREC = 8, GREENSHIFT = 8, BLUEPREC = 8, BLUESHIFT = 0, ALPHAPREC = 0, ALPHASHIFT = 0, MASKBITSPERPIXEL = 1, MASKSHIFT = 0, MASKLINEEND = RILEDWORDBOUNDARY, MASKBITORDER = RIBOREVERSEDBITS, PALETTECOLORCOUNT = 0, PALETTEBITSPERINDEX = 0, PALETTESHIFT = 0, PALETTELINEEND = RILETIGHT, PALETTEBITORDER = RIBOBITSINORDER, PALETTEBYTEORDER = RIBOLSBFIRST}, DATA = 0x7fffe46c3050 0000208#208#208#255#208#208#208#255#208#208#208#255#208#208#208#255#208#208#208#255#208#208#208#255#208..., DATASIZE = 28658, MASK = 0x7fffe46ca070 '', MASKSIZE = 28658, PALETTE = 0x0, PALETTESIZE = 0}, 140737053338816, 140737053338880, 0x0) at include/lclintf.inc:172 0000003 RAWIMAGENEEDED(0x7fffe7088a40, false) at include/custombitmap.inc:210 0000004 SETSIZE(0x7fffe7088a40, 15, 512) at include/custombitmap.inc:328 0000005 SETWIDTH(0x7fffe7088a40, 15) at include/rasterimage.inc:971 0000006 RESIZE(0x7fffe75a3250) at atscrollbar.pas:595 0000015 CALLALLONRESIZE(0x7fffffff7a00, 0x7ffff7f63ed0) at include/control.inc:3055 0000016 DOALLAUTOSIZE(0x7ffff7f63ed0) at include/control.inc:3086 0000017 DOALLAUTOSIZE(0x7ffff7f63ed0) at include/wincontrol.inc:3546 0000026 ADJUSTSIZE(0x7fffe75a3250) at include/control.inc:351 0000027 CHANGEBOUNDS(0x7fffe75a3250, 1035, 0, 15, 488, true) at include/control.inc:696 0000028 SETBOUNDSKEEPBASE(0x7fffe75a3250, 1035, 0, 15, 488) at include/control.inc:5488 0000029 WMSIZE(0x7fffe75a3250, {MSG = 5, UNUSEDMSG = 0, SIZETYPE = 128, WIDTH = 15, HEIGHT = 488, UNUSED = 0, RESULT = 0}) at include/wincontrol.inc:7077 |
|
how to repro it? install ATSynEdit from OnlinePackageManager, it run its app/demo_editor project. |
|
Btw colors are swapped on my screenshot R<->B Stack trace you have posted has no relation to GTK3 -system.move crashed on invalid block size. Can you please simplify demo? If reverting fix ceases problem? |
|
|
|
here it comes - new demo to show problem of Anton's patch. and its bad screenshot. tst-gtk3-png2.zip (10,833 bytes) |
|
This helps b:= TBitmap.Create; b.PixelFormat:=pf32bit; I would search further, but choosing Win32 GDI as abstraction level for graphics was diversion of winduzoids. LCL componets should use LCL methods instead of win-like API. |
|
This also helps in gtk3lclintf.inc:222 without explicit specification b.PixelFormat:=pf32bit; descriptor comes with 32-bit image without alpha, but this code makes the bitmap 24-bit ----------------cut---------------------- // this is only a rough implementation, there is no check against bitsperpixel case Desc.Depth of 1: ImageFormat := CAIRO_FORMAT_A1; 2: ImageFormat := CAIRO_FORMAT_A8; else {if Desc.AlphaPrec=0 then ImageFormat := CAIRO_FORMAT_RGB24 else} ImageFormat := CAIRO_FORMAT_ARGB32; end; -------------cut end ---------------------------- Even found whom blame with 0027225 |
|
gtk3lclintf.diff (519 bytes)
--- /home/anton/net/work/projects/lazarus/lcl/interfaces/gtk3/gtk3lclintf.inc +++ /projects/lazarus/lcl/interfaces/gtk3/gtk3lclintf.inc @@ -224,9 +224,9 @@ 1: ImageFormat := CAIRO_FORMAT_A1; 2: ImageFormat := CAIRO_FORMAT_A8; else - if Desc.AlphaPrec=0 then + {if Desc.AlphaPrec=0 then ImageFormat := CAIRO_FORMAT_RGB24 - else + else} ImageFormat := CAIRO_FORMAT_ARGB32; end; ARowStride := GetBytesPerLine(Desc.Width, Desc.BitsPerPixel, rileDWordBoundary); |
|
At least colors in place |
|
Ok, with both patches it is fixed. |
|
I applied both patches in r62310. Nice. Thanks! |
|
Anton, can you see pls? https://bugs.freepascal.org/view.php?id=36374 |
|
Reopening. r62310 caused swapping of the colors. See the related issue for details. |
|
Colors are fixed in r62377. |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-11-03 18:31 | Alexey Tor. | New Issue | |
2019-11-03 18:32 | Alexey Tor. | File Added: Screenshot from 2019-11-03 20-25-03.png | |
2019-11-25 08:37 | Anton Kavalenka | Note Added: 0119482 | |
2019-11-25 08:37 | Anton Kavalenka | Note Edited: 0119482 | View Revisions |
2019-11-25 09:59 | Alexey Tor. | File Added: tst-gtk3-png.zip | |
2019-11-25 09:59 | Alexey Tor. | File Added: Screenshot from 2019-11-25 11-58-44.png | |
2019-11-25 09:59 | Alexey Tor. | Note Added: 0119485 | |
2019-11-25 09:59 | Alexey Tor. | Note Edited: 0119485 | View Revisions |
2019-11-25 10:02 | Alexey Tor. | Note Edited: 0119485 | View Revisions |
2019-11-25 10:02 | Alexey Tor. | Note Edited: 0119485 | View Revisions |
2019-11-25 10:03 | Alexey Tor. | Note Added: 0119486 | |
2019-11-26 15:05 | Anton Kavalenka | File Added: gtk3winapi_fix.diff | |
2019-11-26 15:05 | Anton Kavalenka | File Added: Здымак экрана, 2019-11-26 17-05-26.png | |
2019-11-26 15:05 | Anton Kavalenka | Note Added: 0119508 | |
2019-11-26 15:44 | Alexey Tor. | Note Added: 0119510 | |
2019-11-26 15:45 | Alexey Tor. | Note Edited: 0119510 | View Revisions |
2019-11-26 15:48 | Alexey Tor. | Note Edited: 0119510 | View Revisions |
2019-11-26 15:51 | Alexey Tor. | Note Added: 0119511 | |
2019-11-26 17:04 | Anton Kavalenka | Note Added: 0119512 | |
2019-11-26 17:07 | Anton Kavalenka | Note Edited: 0119512 | View Revisions |
2019-11-26 17:39 | Alexey Tor. | File Added: broken ATSynedit.png | |
2019-11-26 17:57 | Alexey Tor. | File Added: broken-after-patch.png | |
2019-11-26 17:57 | Alexey Tor. | File Added: tst-gtk3-png2.zip | |
2019-11-26 17:57 | Alexey Tor. | Note Added: 0119514 | |
2019-11-27 15:37 | Anton Kavalenka | Note Added: 0119526 | |
2019-11-27 16:03 | Anton Kavalenka | Note Added: 0119527 | |
2019-11-27 16:07 | Anton Kavalenka | Note Edited: 0119527 | View Revisions |
2019-11-27 16:43 | Anton Kavalenka | File Added: Здымак экрана, 2019-11-27 18-40-13.png | |
2019-11-27 16:43 | Anton Kavalenka | File Added: gtk3lclintf.diff | |
2019-11-27 16:43 | Anton Kavalenka | Note Added: 0119528 | |
2019-11-27 16:43 | Anton Kavalenka | Note Edited: 0119528 | View Revisions |
2019-11-27 17:53 | Alexey Tor. | Note Added: 0119529 | |
2019-11-27 22:38 | Juha Manninen | Assigned To | => Juha Manninen |
2019-11-27 22:38 | Juha Manninen | Status | new => assigned |
2019-11-27 22:44 | Juha Manninen | Relationship added | related to 0027225 |
2019-11-28 17:55 | Juha Manninen | Status | assigned => resolved |
2019-11-28 17:55 | Juha Manninen | Resolution | open => fixed |
2019-11-28 17:55 | Juha Manninen | Fixed in Revision | => r62310 |
2019-11-28 17:55 | Juha Manninen | LazTarget | => - |
2019-11-28 17:55 | Juha Manninen | Widgetset | GTK 3 => GTK 3 |
2019-11-28 17:55 | Juha Manninen | Note Added: 0119536 | |
2019-11-28 20:52 | Alexey Tor. | Note Added: 0119539 | |
2019-12-10 07:32 | Juha Manninen | Relationship added | related to 0036374 |
2019-12-10 07:36 | Juha Manninen | Status | resolved => assigned |
2019-12-10 07:36 | Juha Manninen | Resolution | fixed => reopened |
2019-12-10 07:36 | Juha Manninen | Note Added: 0119722 | |
2019-12-11 12:36 | Juha Manninen | Status | assigned => resolved |
2019-12-11 12:36 | Juha Manninen | Fixed in Revision | r62310 => r62310, r62377 |
2019-12-11 12:36 | Juha Manninen | Widgetset | GTK 3 => GTK 3 |
2019-12-11 12:36 | Juha Manninen | Note Added: 0119746 |