LibreOffice Module vcl (master) 1
GraphicID.cxx
Go to the documentation of this file.
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/strbuf.hxx>
24
26{
27 rGraphic.ensureAvailable();
28
29 mnID1 = static_cast<sal_uLong>(rGraphic.getType()) << 28;
30 mnID2 = mnID3 = mnID4 = 0;
31
32 if (rGraphic.getType() == GraphicType::Bitmap)
33 {
34 auto const& rVectorGraphicDataPtr = rGraphic.getVectorGraphicData();
35 if (rVectorGraphicDataPtr)
36 {
37 const basegfx::B2DRange& rRange = rVectorGraphicDataPtr->getRange();
38
39 mnID1 |= rVectorGraphicDataPtr->getBinaryDataContainer().getSize();
40 mnID2 = basegfx::fround(rRange.getWidth());
42 mnID4 = vcl_get_checksum(0, rVectorGraphicDataPtr->getBinaryDataContainer().getData(),
43 rVectorGraphicDataPtr->getBinaryDataContainer().getSize());
44 }
45 else if (rGraphic.isAnimated())
46 {
47 const Animation aAnimation(rGraphic.getAnimation());
48
49 mnID1 |= (aAnimation.Count() & 0x0fffffff);
50 mnID2 = aAnimation.GetDisplaySizePixel().Width();
51 mnID3 = aAnimation.GetDisplaySizePixel().Height();
52 mnID4 = rGraphic.getChecksum();
53 }
54 else
55 {
56 const BitmapEx aBmpEx(rGraphic.getBitmapEx(GraphicConversionParameters()));
57
58 mnID1 |= aBmpEx.IsAlpha() ? 1 : 0;
59 mnID2 = aBmpEx.GetSizePixel().Width();
60 mnID3 = aBmpEx.GetSizePixel().Height();
61 mnID4 = rGraphic.getChecksum();
62 }
63 }
64 else if (rGraphic.getType() == GraphicType::GdiMetafile)
65 {
66 const GDIMetaFile& rMtf = rGraphic.getGDIMetaFile();
67
68 mnID1 |= (rMtf.GetActionSize() & 0x0fffffff);
69 mnID2 = rMtf.GetPrefSize().Width();
70 mnID3 = rMtf.GetPrefSize().Height();
71 mnID4 = rGraphic.getChecksum();
72 }
73}
74
76{
77 static const char aHexData[]
78 = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
79
80 sal_Int32 nShift, nIndex = 0;
81 sal_Int32 nLen = 24 + (2 * BITMAP_CHECKSUM_SIZE);
82 OStringBuffer aHexStr(nLen);
83 aHexStr.setLength(nLen);
84
85 for (nShift = 28; nShift >= 0; nShift -= 4)
86 aHexStr[nIndex++] = aHexData[(mnID1 >> static_cast<sal_uInt32>(nShift)) & 0xf];
87
88 for (nShift = 28; nShift >= 0; nShift -= 4)
89 aHexStr[nIndex++] = aHexData[(mnID2 >> static_cast<sal_uInt32>(nShift)) & 0xf];
90
91 for (nShift = 28; nShift >= 0; nShift -= 4)
92 aHexStr[nIndex++] = aHexData[(mnID3 >> static_cast<sal_uInt32>(nShift)) & 0xf];
93
94 for (nShift = (8 * BITMAP_CHECKSUM_SIZE) - 4; nShift >= 0; nShift -= 4)
95 aHexStr[nIndex++] = aHexData[(mnID4 >> static_cast<sal_uInt32>(nShift)) & 0xf];
96
97 return aHexStr.makeStringAndClear();
98}
99
100/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BITMAP_CHECKSUM_SIZE
Definition: checksum.hxx:28
BitmapChecksum vcl_get_checksum(BitmapChecksum Checksum, const void *Data, sal_uInt32 DatLen)
Definition: checksum.hxx:72
size_t Count() const
Definition: Animation.hxx:71
const Size & GetDisplaySizePixel() const
Definition: Animation.hxx:57
bool IsAlpha() const
Definition: BitmapEx.cxx:207
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
size_t GetActionSize() const
Definition: gdimtf.cxx:181
const Size & GetPrefSize() const
Definition: gdimtf.hxx:176
OString getIDString() const
Definition: GraphicID.cxx:75
sal_uInt32 mnID3
Definition: GraphicID.hxx:33
sal_uInt32 mnID1
Definition: GraphicID.hxx:31
GraphicID(ImpGraphic const &rGraphic)
Definition: GraphicID.cxx:25
BitmapChecksum mnID4
Definition: GraphicID.hxx:34
sal_uInt32 mnID2
Definition: GraphicID.hxx:32
BitmapEx getBitmapEx(const GraphicConversionParameters &rParameters) const
Definition: impgraph.cxx:638
BitmapChecksum getChecksum() const
Definition: impgraph.cxx:1725
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
Definition: impgraph.cxx:346
Animation getAnimation() const
Definition: impgraph.cxx:677
bool ensureAvailable() const
Definition: impgraph.cxx:1366
const GDIMetaFile & getGDIMetaFile() const
Definition: impgraph.cxx:694
GraphicType getType() const
Definition: impgraph.hxx:134
bool isAnimated() const
Definition: impgraph.cxx:499
constexpr tools::Long Height() const
constexpr tools::Long Width() const
B2DVector getRange() const
TYPE getWidth() const
TYPE getHeight() const
sal_Int32 nIndex
B2IRange fround(const B2DRange &rRange)
sal_uIntPtr sal_uLong