Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/graphic/GraphicID.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <graphic/GraphicID.hxx>
21
22
#include <impgraph.hxx>
23
#include <rtl/crc.h>
24
#include <rtl/strbuf.hxx>
25
#include <vcl/vectorgraphicdata.hxx>
26
27
GraphicID::GraphicID(ImpGraphic const& rGraphic)
28
0
{
29
0
    rGraphic.ensureAvailable();
30
31
0
    mnID1 = static_cast<sal_uLong>(rGraphic.getType()) << 28;
32
0
    mnID2 = mnID3 = mnID4 = 0;
33
34
0
    if (rGraphic.getType() == GraphicType::Bitmap)
35
0
    {
36
0
        auto const& rVectorGraphicDataPtr = rGraphic.getVectorGraphicData();
37
0
        if (rVectorGraphicDataPtr)
38
0
        {
39
0
            const basegfx::B2DRange& rRange = rVectorGraphicDataPtr->getRange();
40
41
0
            mnID1 |= rVectorGraphicDataPtr->getBinaryDataContainer().getSize();
42
0
            mnID2 = basegfx::fround(rRange.getWidth());
43
0
            mnID3 = basegfx::fround(rRange.getHeight());
44
0
            mnID4 = rtl_crc32(0, rVectorGraphicDataPtr->getBinaryDataContainer().getData(),
45
0
                              rVectorGraphicDataPtr->getBinaryDataContainer().getSize());
46
0
        }
47
0
        else if (rGraphic.isAnimated())
48
0
        {
49
0
            const Animation aAnimation(rGraphic.getAnimation());
50
51
0
            mnID1 |= (aAnimation.Count() & 0x0fffffff);
52
0
            mnID2 = aAnimation.GetDisplaySizePixel().Width();
53
0
            mnID3 = aAnimation.GetDisplaySizePixel().Height();
54
0
            mnID4 = rGraphic.getChecksum();
55
0
        }
56
0
        else
57
0
        {
58
0
            const Bitmap aBmp(rGraphic.getBitmap(GraphicConversionParameters()));
59
60
0
            mnID1 |= aBmp.HasAlpha() ? 1 : 0;
61
0
            mnID2 = aBmp.GetSizePixel().Width();
62
0
            mnID3 = aBmp.GetSizePixel().Height();
63
0
            mnID4 = rGraphic.getChecksum();
64
0
        }
65
0
    }
66
0
    else if (rGraphic.getType() == GraphicType::GdiMetafile)
67
0
    {
68
0
        const GDIMetaFile& rMtf = rGraphic.getGDIMetaFile();
69
70
0
        mnID1 |= (rMtf.GetActionSize() & 0x0fffffff);
71
0
        mnID2 = rMtf.GetPrefSize().Width();
72
0
        mnID3 = rMtf.GetPrefSize().Height();
73
0
        mnID4 = rGraphic.getChecksum();
74
0
    }
75
0
}
76
77
OString GraphicID::getIDString() const
78
0
{
79
0
    static const char aHexData[]
80
0
        = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
81
82
0
    sal_Int32 nShift, nIndex = 0;
83
0
    sal_Int32 nLen = 24 + (2 * BITMAP_CHECKSUM_SIZE);
84
0
    OStringBuffer aHexStr(nLen);
85
0
    aHexStr.setLength(nLen);
86
87
0
    for (nShift = 28; nShift >= 0; nShift -= 4)
88
0
        aHexStr[nIndex++] = aHexData[(mnID1 >> static_cast<sal_uInt32>(nShift)) & 0xf];
89
90
0
    for (nShift = 28; nShift >= 0; nShift -= 4)
91
0
        aHexStr[nIndex++] = aHexData[(mnID2 >> static_cast<sal_uInt32>(nShift)) & 0xf];
92
93
0
    for (nShift = 28; nShift >= 0; nShift -= 4)
94
0
        aHexStr[nIndex++] = aHexData[(mnID3 >> static_cast<sal_uInt32>(nShift)) & 0xf];
95
96
0
    for (nShift = (8 * BITMAP_CHECKSUM_SIZE) - 4; nShift >= 0; nShift -= 4)
97
0
        aHexStr[nIndex++] = aHexData[(mnID4 >> static_cast<sal_uInt32>(nShift)) & 0xf];
98
99
0
    return aHexStr.makeStringAndClear();
100
0
}
101
102
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */