Bug 142941 - [EMF+] DrawImagePoints and DrawImage SrcRect support
Summary: [EMF+] DrawImagePoints and DrawImage SrcRect support
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.3.0 target:7.2.0.0.beta2 tar...
Keywords:
Depends on:
Blocks: 59814 EMF-WMF 138087
  Show dependency treegraph
 
Reported: 2021-06-19 14:15 UTC by Valek Filippov
Modified: 2022-04-28 06:40 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
EMF sample with a problem (716 bytes, image/x-emf)
2021-06-19 14:17 UTC, Valek Filippov
Details
Inner EMF/EMF+ inserted into main sample (for a reference) (244 bytes, image/x-emf)
2021-06-19 14:19 UTC, Valek Filippov
Details
Screenshot with a sample opened in LO 7.3alpha and MS Paint (20.20 KB, image/png)
2021-06-19 14:22 UTC, Valek Filippov
Details
How it probably should work for a simple translation case (29.49 KB, image/png)
2021-06-19 14:52 UTC, Valek Filippov
Details
EMF+ sample with embedded bitmap (8.40 KB, image/x-emf)
2021-06-20 18:15 UTC, Valek Filippov
Details
Screenshot for EMF+ with embedded bitmap: LO7.3alpha vs MS Paint (87.36 KB, image/png)
2021-06-20 18:17 UTC, Valek Filippov
Details
JPEG embedded into EMF+ with bitmap sample (8.03 KB, image/jpeg)
2021-06-20 18:20 UTC, Valek Filippov
Details
EMF+ sample with bitmap cropped to the cell with digit 5 in it (8.40 KB, image/x-emf)
2021-06-20 19:06 UTC, Valek Filippov
Details
Screenshot for EMF+ with embedded bitmap and crop: LO7.3alpha vs MS Paint (31.45 KB, image/png)
2021-06-20 19:07 UTC, Valek Filippov
Details
Sample EMF+ with embedded EMF, containing green square (760 bytes, image/emf)
2021-09-06 07:07 UTC, Bartosz
Details
Sample EMF+ with embedded EMF, containing green square, exported to PNG with Paint (1.61 KB, image/png)
2021-09-06 07:10 UTC, Bartosz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Valek Filippov 2021-06-19 14:15:54 UTC
Description:
LO doesn't handle DrawImagePoints SrcRect properly.

Steps to Reproduce:
Open attached EMF sample.

Actual Results:
LO draws a piece of green rectangle in the top left corner and blue square in the middle of the image.

Expected Results:
It should draw green square of the same size as a blue one on the top part of the image.


Reproducible: Always


User Profile Reset: No



Additional Info:
In this case DrawImagePoints deals with an ObjectImage of the Metafile type. LO reads SrcRect and uses in in aGDI.Clip call, however it has wrong or no effect depends on the specific values provided.

This was identified during analysis of EMF+ part of the issue with a file from tdf#59814.
Solving this problem should also have a positive impact on tdf#59814.
Comment 1 Valek Filippov 2021-06-19 14:17:44 UTC
Created attachment 173012 [details]
EMF sample with a problem
Comment 2 Valek Filippov 2021-06-19 14:19:14 UTC
Created attachment 173013 [details]
Inner EMF/EMF+ inserted into main sample (for a reference)
Comment 3 Valek Filippov 2021-06-19 14:22:26 UTC
Created attachment 173014 [details]
Screenshot with a sample opened in LO 7.3alpha and MS Paint
Comment 4 Valek Filippov 2021-06-19 14:52:47 UTC
Created attachment 173015 [details]
How it probably should work for a simple translation case
Comment 5 Stéphane Guillou (stragu) 2021-06-20 08:33:13 UTC
Confirmed with:

Version: 7.3.0.0.alpha0+ / LibreOffice Community
Build ID: 94d552f94b427f884c004dba5d4619ecf729d605
CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
TinderBox: Linux-rpm_deb-x86_64@86-TDF, Branch:master, Time: 2021-06-18_13:30:27
Calc: threaded

Same with:

Version: 7.2.0.0.beta1 / LibreOffice Community
Build ID: c6974f7afec4cd5195617ae48c6ef9aacfe85ddd
CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded

Same result using the command:

libreofficedev7.3 --headless --convert-to png *.emf
Comment 6 Valek Filippov 2021-06-20 18:15:14 UTC
Created attachment 173038 [details]
EMF+ sample with embedded bitmap

As per Bartosz code for the two are quite similar --> keeping it in one bug.
Comment 7 Valek Filippov 2021-06-20 18:17:03 UTC
Created attachment 173039 [details]
Screenshot for EMF+ with embedded bitmap: LO7.3alpha vs MS Paint
Comment 8 Valek Filippov 2021-06-20 18:19:21 UTC
> EMF+ sample with embedded bitmap

It also scales the cropped picture by 2 in each direction.
Comment 9 Valek Filippov 2021-06-20 18:20:02 UTC
Created attachment 173040 [details]
JPEG embedded into EMF+ with bitmap sample
Comment 10 Valek Filippov 2021-06-20 19:06:21 UTC
Created attachment 173042 [details]
EMF+ sample with bitmap cropped to the cell with digit 5 in it

It works almost fine in LO except that right and bottom border of the 'cell' with digit 5 are not present.
SrcRect should be "inclusive" but LO cropped one pixel too early.
Comment 11 Valek Filippov 2021-06-20 19:07:32 UTC
Created attachment 173043 [details]
Screenshot for EMF+ with embedded bitmap and crop: LO7.3alpha vs MS Paint
Comment 12 Commit Notification 2021-07-03 13:00:12 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4992780d2bc996c111b333549314d72f6891308d

EMF+ tdf#142941 Fixes for SrcRect in DrawImagePoints

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Commit Notification 2021-07-07 20:01:48 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "libreoffice-7-2":

https://git.libreoffice.org/core/commit/032b00382f654962ec787029b3a887f9efbd2a3d

EMF+ tdf#142941 Fixes for SrcRect in DrawImagePoints

It will be available in 7.2.0.0.beta2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Commit Notification 2021-07-13 19:04:20 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/3adfb2d35bb34157ce0d1344f2a28b40360728a5

EMF+ tdf#142941 Fixes SrcRect implementation in DrawImage record

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Commit Notification 2021-07-14 07:54:10 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "libreoffice-7-2":

https://git.libreoffice.org/core/commit/5ee7cb39238a420f1b2ffc83d5b2dc79e0ee3875

EMF+ tdf#142941 Fixes SrcRect implementation in DrawImage record

It will be available in 7.2.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 16 Bartosz 2021-09-06 06:49:45 UTC
After fixes the EmfPlusRecordTypeDrawImage record with Bitmap embedded, is displaying fine.

The EmfPlusRecordTypeDrawImage record with EMF MetaFile embedded is not displaying correctly. The scale and width/heigh ratio is wrong. 
Here is the place where is the EmfPlusRecordTypeDrawImage implementation:
https://github.com/LibreOffice/core/blob/libreoffice-7-2/drawinglayer/source/tools/emfphelperdata.cxx#L1432


It seems that the EMF MetaFile was not displayed correctly due to an issue in GDIMetaFile creation:

  GDIMetaFile aGDI(image.graphic.GetGDIMetaFile());


Source code:
https://github.com/LibreOffice/core/blob/libreoffice-7-2/drawinglayer/source/tools/emfphelperdata.cxx#L1559-L1566


The ratio (eg. where square becomes rectangle) could be corrected with:
   
  aSize = image.graphic.GetGDIMetaFile().GetPrefSize();
  double ratio = double(aSize.Width()) / double(aSize.Height()); // ratio 0.63

but unfortunately it doesn't fix the scale (the image could be too small or too large).

I think the issue should be resolved in during invocation of image.graphic.GetGDIMetaFile() method itself.
Comment 17 Bartosz 2021-09-06 07:07:45 UTC
Created attachment 174801 [details]
Sample EMF+ with embedded EMF, containing green square
Comment 18 Bartosz 2021-09-06 07:10:32 UTC
Created attachment 174802 [details]
Sample EMF+ with embedded EMF, containing green square, exported to PNG with Paint