Bug 149714 - BitsPerPixel property of Graphic has Boolean UNO type
Summary: BitsPerPixel property of Graphic has Boolean UNO type
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: reviewed:2022
Keywords: difficultyBeginner, easyHack, skillCpp
Depends on:
Blocks: Macro
  Show dependency treegraph
 
Reported: 2022-06-24 11:53 UTC by Mike Kaganski
Modified: 2022-07-11 16:39 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2022-06-24 11:53:05 UTC
Consider the code:

Sub TestGraphicBitsPerPixel
  Dim oProps(0) As New com.sun.star.beans.PropertyValue 
  oProps(0).Name = "URL"
  oProps(0).Value = "https://bug-attachments.documentfoundation.org/attachment.cgi?id=177261"

  oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
  oGraphic = oProvider.queryGraphic(oProps())

  MsgBox oGraphic.BitsPerPixel
End Sub

It uses attachment 177261 [details] (that is simply a small PNG having 24 BPP), and the expected output would be 24; but the actual result is "True".

The problem is implementation of BitsPerPixel property (documented to have 'byte' UNO type) [1] in vcl/source/graphic/UnoGraphicDescriptor.cxx, where the UNO type is defined as  cppu::UnoType< sal_uInt8 > [2]. But that type maps to TypeClass::BOOLEAN [3], which makes Basic to convert the non-0 value to True.

The actual type that maps to TypeClass::BYTE is cppu::UnoType< sal_Int8 >.

The problem was since the introduction of the code in commit 7e83653a7fac894bee2c7c35fa2b84daac026642; there also was GraphicType property using that type initially, but that was fixed in commit 0170d51253bddd1e8ec1c8c887b526f2fc18d019. The code that sets the numeric value to the property [4] uses the correct sal_Int8 type.

The fix of this easyhack should contain a unit test.

[1] https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1graphic_1_1GraphicDescriptor.html#ac99c505108bd7f6220e43c3f7a7a9040
[2] https://opengrok.libreoffice.org/xref/core/vcl/source/graphic/UnoGraphicDescriptor.cxx?r=912b8fa6#241
[3] https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1uno.html#a00683ed3ec24b47c36ead10a20d6f328a8a583f16e8d237a423c8c1d9087a4c72
[4] https://opengrok.libreoffice.org/xref/core/vcl/source/graphic/UnoGraphicDescriptor.cxx?r=912b8fa6#381