Modify

Opened 2 years ago

Closed 2 years ago

#3589 closed Bug (No Bug)

GDIPlus.au3 contains unecessary string conversions

Reported by: Imp Owned by:
Milestone: Component: AutoIt
Version: 3.3.14.3 Severity: None
Keywords: Cc:

Description

_GDIPlus_Encoders may be rewritten without using _WinAPI_WideCharsToMultibyte()

Func _GDIPlus_Encoders()
    Local $iCount = _GDIPlus_EncodersGetCount()
    Local $iSize = _GDIPlus_EncodersGetSize()
    Local $tBuffer = DllStructCreate("byte[" & $iSize & "]")
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageEncoders", "uint", $iCount, "uint", $iSize, "struct*", $tBuffer)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)

    Local $pBuffer = DllStructGetPtr($tBuffer)
    Local $tCodec, $aInfo[$iCount + 1][14]
    $aInfo[0][0] = $iCount
    For $iI = 1 To $iCount
        $tCodec = DllStructCreate($tagGDIPIMAGECODECINFO, $pBuffer)
        $aInfo[$iI][1] = _WinAPI_StringFromGUID(DllStructGetPtr($tCodec, "CLSID"))
        $aInfo[$iI][2] = _WinAPI_StringFromGUID(DllStructGetPtr($tCodec, "FormatID"))
        $aInfo[$iI][3] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "CodecName")), 1 )
        $aInfo[$iI][4] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "DllName")), 1 )
        $aInfo[$iI][5] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "FormatDesc")), 1 )
        $aInfo[$iI][6] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "FileExt")), 1 )
        $aInfo[$iI][7] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "MimeType")), 1 )
        $aInfo[$iI][8] = DllStructGetData($tCodec, "Flags")
        $aInfo[$iI][9] = DllStructGetData($tCodec, "Version")
        $aInfo[$iI][10] = DllStructGetData($tCodec, "SigCount")
        $aInfo[$iI][11] = DllStructGetData($tCodec, "SigSize")
        $aInfo[$iI][12] = DllStructGetData($tCodec, "SigPattern")
        $aInfo[$iI][13] = DllStructGetData($tCodec, "SigMask")
        $pBuffer += DllStructGetSize($tCodec)
    Next
    Return $aInfo
EndFunc   ;==>_GDIPlus_Encoders

And _GDIPlus_Decoders():

Func _GDIPlus_Decoders()
    Local $iCount = _GDIPlus_DecodersGetCount()
    Local $iSize = _GDIPlus_DecodersGetSize()
    Local $tBuffer = DllStructCreate("byte[" & $iSize & "]")
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetImageDecoders", "uint", $iCount, "uint", $iSize, "struct*", $tBuffer)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)

    Local $pBuffer = DllStructGetPtr($tBuffer)
    Local $tCodec, $aInfo[$iCount + 1][14]
    $aInfo[0][0] = $iCount
    For $iI = 1 To $iCount
        $tCodec = DllStructCreate($tagGDIPIMAGECODECINFO, $pBuffer)
        $aInfo[$iI][1] = _WinAPI_StringFromGUID(DllStructGetPtr($tCodec, "CLSID"))
        $aInfo[$iI][2] = _WinAPI_StringFromGUID(DllStructGetPtr($tCodec, "FormatID"))
        $aInfo[$iI][3] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "CodecName")), 1 )
        $aInfo[$iI][4] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "DllName")), 1 )
        $aInfo[$iI][5] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "FormatDesc")), 1 )
        $aInfo[$iI][6] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "FileExt")), 1 )
        $aInfo[$iI][7] = DllStructGetData( DllStructCreate( "wchar[128]", DllStructGetData($tCodec, "MimeType")), 1 )
        $aInfo[$iI][8] = DllStructGetData($tCodec, "Flags")
        $aInfo[$iI][9] = DllStructGetData($tCodec, "Version")
        $aInfo[$iI][10] = DllStructGetData($tCodec, "SigCount")
        $aInfo[$iI][11] = DllStructGetData($tCodec, "SigSize")
        $aInfo[$iI][12] = DllStructGetData($tCodec, "SigPattern")
        $aInfo[$iI][13] = DllStructGetData($tCodec, "SigMask")
        $pBuffer += DllStructGetSize($tCodec)
    Next
    Return $aInfo
EndFunc   ;==>_GDIPlus_Decoders

Also #include "WinAPIConv.au3" may be removed from top of file.

Attachments (0)

Change History (4)

comment:1 follow-up: Changed 2 years ago by Jpm

re you sure that it is working on Asian Windows?

comment:2 in reply to: ↑ 1 Changed 2 years ago by anonymous

Replying to Jpm:

re you sure that it is working on Asian Windows?

Why not? All of these members declared as WCHAR * in Microsoft documentation. AutoIt internally also uses WCHAR. Furthermore, conversion to multibyte and then to AutoIt strings from char[] (one by one as single chars) as is done by _WinAPI_WideCharsToMultibyte() will break the string data.

I do not have Asan Windows, but on Russian all of these string in latin alphabet.

comment:3 Changed 2 years ago by Jpm

Thanks,
I would have prefer to have a chinese,Japanese/Korean validation
I just wait a little bit before validation

comment:4 Changed 2 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

In fact the conversion is not done one by one but as the size is not specified the current solution is better

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.