vcl: Detect TGA graphic by inspecting the file footer

Works only with TGA ver.2 files.

Change-Id: I0378a1e03e238cd444175035768cccf491480191
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110898
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
diff --git a/vcl/source/filter/GraphicFormatDetector.cxx b/vcl/source/filter/GraphicFormatDetector.cxx
index 56f7a9f..e5a1eb5 100644
--- a/vcl/source/filter/GraphicFormatDetector.cxx
+++ b/vcl/source/filter/GraphicFormatDetector.cxx
@@ -513,6 +513,24 @@ bool GraphicFormatDetector::checkSVG()

bool GraphicFormatDetector::checkTGA()
{
    // Check TGA ver.2 footer bytes
    if (mnStreamLength > 18)
    {
        char sFooterBytes[18];

        mrStream.Seek(STREAM_SEEK_TO_END);
        mrStream.SeekRel(-18);
        mrStream.ReadBytes(sFooterBytes, 18);

        OString aFooterString(sFooterBytes);
        if (aFooterString == "TRUEVISION-XFILE.")
        {
            msDetectedFormat = "TGA";
            return true;
        }
    }

    // Fallback to file extension check
    if (maExtension.startsWith("TGA"))
    {
        msDetectedFormat = "TGA";