1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <graphic/GraphicID.hxx>
22 #include <impgraph.hxx>
24 #include <rtl/strbuf.hxx>
26 GraphicID::GraphicID(ImpGraphic
const& rGraphic
)
28 rGraphic
.ensureAvailable();
30 mnID1
= static_cast<sal_uLong
>(rGraphic
.getType()) << 28;
31 mnID2
= mnID3
= mnID4
= 0;
33 if (rGraphic
.getType() == GraphicType::Bitmap
)
35 auto const& rVectorGraphicDataPtr
= rGraphic
.getVectorGraphicData();
36 if (rVectorGraphicDataPtr
)
38 const basegfx::B2DRange
& rRange
= rVectorGraphicDataPtr
->getRange();
40 mnID1
|= rVectorGraphicDataPtr
->getBinaryDataContainer().getSize();
41 mnID2
= basegfx::fround(rRange
.getWidth());
42 mnID3
= basegfx::fround(rRange
.getHeight());
43 mnID4
= rtl_crc32(0, rVectorGraphicDataPtr
->getBinaryDataContainer().getData(),
44 rVectorGraphicDataPtr
->getBinaryDataContainer().getSize());
46 else if (rGraphic
.isAnimated())
48 const Animation
aAnimation(rGraphic
.getAnimation());
50 mnID1
|= (aAnimation
.Count() & 0x0fffffff);
51 mnID2
= aAnimation
.GetDisplaySizePixel().Width();
52 mnID3
= aAnimation
.GetDisplaySizePixel().Height();
53 mnID4
= rGraphic
.getChecksum();
57 const BitmapEx
aBmpEx(rGraphic
.getBitmapEx(GraphicConversionParameters()));
59 mnID1
|= aBmpEx
.IsAlpha() ? 1 : 0;
60 mnID2
= aBmpEx
.GetSizePixel().Width();
61 mnID3
= aBmpEx
.GetSizePixel().Height();
62 mnID4
= rGraphic
.getChecksum();
65 else if (rGraphic
.getType() == GraphicType::GdiMetafile
)
67 const GDIMetaFile
& rMtf
= rGraphic
.getGDIMetaFile();
69 mnID1
|= (rMtf
.GetActionSize() & 0x0fffffff);
70 mnID2
= rMtf
.GetPrefSize().Width();
71 mnID3
= rMtf
.GetPrefSize().Height();
72 mnID4
= rGraphic
.getChecksum();
76 OString
GraphicID::getIDString() const
78 static const char aHexData
[]
79 = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
81 sal_Int32 nShift
, nIndex
= 0;
82 sal_Int32 nLen
= 24 + (2 * BITMAP_CHECKSUM_SIZE
);
83 OStringBuffer
aHexStr(nLen
);
84 aHexStr
.setLength(nLen
);
86 for (nShift
= 28; nShift
>= 0; nShift
-= 4)
87 aHexStr
[nIndex
++] = aHexData
[(mnID1
>> static_cast<sal_uInt32
>(nShift
)) & 0xf];
89 for (nShift
= 28; nShift
>= 0; nShift
-= 4)
90 aHexStr
[nIndex
++] = aHexData
[(mnID2
>> static_cast<sal_uInt32
>(nShift
)) & 0xf];
92 for (nShift
= 28; nShift
>= 0; nShift
-= 4)
93 aHexStr
[nIndex
++] = aHexData
[(mnID3
>> static_cast<sal_uInt32
>(nShift
)) & 0xf];
95 for (nShift
= (8 * BITMAP_CHECKSUM_SIZE
) - 4; nShift
>= 0; nShift
-= 4)
96 aHexStr
[nIndex
++] = aHexData
[(mnID4
>> static_cast<sal_uInt32
>(nShift
)) & 0xf];
98 return aHexStr
.makeStringAndClear();
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */