Bug 127992 - Cairo backend does not return GetPixel() correctly
Summary: Cairo backend does not return GetPixel() correctly
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-06 22:55 UTC by Chris Sherlock
Modified: 2019-11-08 05:14 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Sherlock 2019-10-06 22:55:33 UTC
Description:
On systems that use Cairo as the VCL backend, the following occurs:

VirtualDevice aRenderContext;
aRenderContext.DrawPixel(Point(8, 1), COL_GREEN);
aRenderContext.GetPixel(Point(8, 1)));

Last line returns 000000ff! This is wrong

https://github.com/chrissherlock/libreoffice-experimental/blob/pixelbug/vcl/qa/cppunit/outdev/PixelTest.cxx

Steps to Reproduce:
1. Cherry pick my commit on github:

https://github.com/chrissherlock/libreoffice-experimental/commit/515c1b3e3ddf1a06028982b5741350dfeedc010f

2. Run make CppunitTest_PixelTest

Actual Results:
/home/chris/repos/libreoffice-latest/vcl/qa/cppunit/outdev/PixelTest.cxx:35:PixelTest::testPixel
equality assertion failed
- Expected: c[00800000]
- Actual  : c[000000ff]

PixelTest::testPixel finished in: 21ms
PixelTest.cxx:35:Assertion
Test name: PixelTest::testPixel
equality assertion failed
- Expected: c[00800000]
- Actual  : c[000000ff]

Failures !!!
Run: 1   Failure total: 1   Failures: 1   Errors: 0

Error: a unit test failed, please do one of:

make CppunitTest_PixelTest CPPUNITTRACE="gdb --args"
    # for interactive debugging on Linux
make CppunitTest_PixelTest VALGRIND=memcheck
    # for memory checking
make CppunitTest_PixelTest DEBUGCPPUNIT=TRUE
    # for exception catching


Expected Results:
Should be returning 00800000 (COL_GREEN). 


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Chris Sherlock 2019-10-06 23:02:04 UTC
Please note, I did step through this, I think the issue may occur in
Comment 2 Tomaz Vajngerl 2019-10-07 06:37:02 UTC
Luckily we don't use GetPixel practically anywhere except for tests. This looks like an issue of not taking account of per-multiplied alpha and misinterpretation of RGBA / ARGB or something like that..

Anyway the GetPixel should already be tested in BackendTest.cxx once we can enable that (needs fixing issues with the backends first and enable backend by backend).
Comment 3 Chris Sherlock 2019-10-09 23:47:28 UTC
I debugged this, and it isn't an issue with premultiplied alpha as far as I can see. In SvpSalGraphics::getPixel, the value of data is 0x0000 

 unsigned char *data = cairo_image_surface_get_data(target);

data[SVP_CAIRO_ALPHA] is 0
data[SVP_CAIRO_BLUE] is 0  
data[SVP_CAIRO_GREEN] is 0
data[SVP_CAIRO_RED] is 0
Comment 4 Joe browns 2019-10-11 10:31:41 UTC Comment hidden (spam)
Comment 5 Caolán McNamara 2019-10-20 15:04:51 UTC
...

    VirtualDevice aRenderContext;

    aRenderContext.DrawPixel(Point(8, 1), COL_GREEN);
...

aRenderContext is 0x0 so you are drawing outside the bounds of the device. Change it to ...

    VirtualDevice aRenderContext;
    aRenderContext.SetOutputSizePixel(Size(10,10));
    aRenderContext.DrawPixel(Point(8, 1), COL_GREEN);

and it will work
Comment 6 Chris Sherlock 2019-11-08 05:14:04 UTC
Thanks!