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.ImplGetType()) << 28;
30  mnID2 = mnID3 = mnID4 = 0;
31 
32  if (rGraphic.ImplGetType() == GraphicType::Bitmap)
33  {
34  auto const& rVectorGraphicDataPtr = rGraphic.getVectorGraphicData();
35  if (rVectorGraphicDataPtr)
36  {
37  const basegfx::B2DRange& rRange = rVectorGraphicDataPtr->getRange();
38 
39  mnID1 |= rVectorGraphicDataPtr->getVectorGraphicDataArrayLength();
40  mnID2 = basegfx::fround(rRange.getWidth());
41  mnID3 = basegfx::fround(rRange.getHeight());
42  mnID4 = vcl_get_checksum(0, rVectorGraphicDataPtr->getBinaryDataContainer().getData(),
43  rVectorGraphicDataPtr->getBinaryDataContainer().getSize());
44  }
45  else if (rGraphic.ImplIsAnimated())
46  {
47  const Animation aAnimation(rGraphic.ImplGetAnimation());
48 
49  mnID1 |= (aAnimation.Count() & 0x0fffffff);
50  mnID2 = aAnimation.GetDisplaySizePixel().Width();
51  mnID3 = aAnimation.GetDisplaySizePixel().Height();
52  mnID4 = rGraphic.ImplGetChecksum();
53  }
54  else
55  {
56  const BitmapEx aBmpEx(rGraphic.ImplGetBitmapEx(GraphicConversionParameters()));
57 
58  mnID1 |= (((static_cast<sal_uLong>(aBmpEx.GetTransparentType()) << 8)
59  | (aBmpEx.IsAlpha() ? 1 : 0))
60  & 0x0fffffff);
61  mnID2 = aBmpEx.GetSizePixel().Width();
62  mnID3 = aBmpEx.GetSizePixel().Height();
63  mnID4 = rGraphic.ImplGetChecksum();
64  }
65  }
66  else if (rGraphic.ImplGetType() == GraphicType::GdiMetafile)
67  {
68  const GDIMetaFile& rMtf = rGraphic.ImplGetGDIMetaFile();
69 
70  mnID1 |= (rMtf.GetActionSize() & 0x0fffffff);
71  mnID2 = rMtf.GetPrefSize().Width();
72  mnID3 = rMtf.GetPrefSize().Height();
73  mnID4 = rGraphic.ImplGetChecksum();
74  }
75 }
76 
77 OString GraphicID::getIDString() const
78 {
79  static const char aHexData[]
80  = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
81 
82  sal_Int32 nShift, nIndex = 0;
83  sal_Int32 nLen = 24 + (2 * BITMAP_CHECKSUM_SIZE);
84  OStringBuffer aHexStr(nLen);
85  aHexStr.setLength(nLen);
86 
87  for (nShift = 28; nShift >= 0; nShift -= 4)
88  aHexStr[nIndex++] = aHexData[(mnID1 >> static_cast<sal_uInt32>(nShift)) & 0xf];
89 
90  for (nShift = 28; nShift >= 0; nShift -= 4)
91  aHexStr[nIndex++] = aHexData[(mnID2 >> static_cast<sal_uInt32>(nShift)) & 0xf];
92 
93  for (nShift = 28; nShift >= 0; nShift -= 4)
94  aHexStr[nIndex++] = aHexData[(mnID3 >> static_cast<sal_uInt32>(nShift)) & 0xf];
95 
96  for (nShift = (8 * BITMAP_CHECKSUM_SIZE) - 4; nShift >= 0; nShift -= 4)
97  aHexStr[nIndex++] = aHexData[(mnID4 >> static_cast<sal_uInt32>(nShift)) & 0xf];
98 
99  return aHexStr.makeStringAndClear();
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const GDIMetaFile & ImplGetGDIMetaFile() const
Definition: impgraph.cxx:670
sal_Int32 nIndex
double getHeight() const
sal_uInt32 mnID1
Definition: GraphicID.hxx:31
sal_uIntPtr sal_uLong
GraphicID(ImpGraphic const &rGraphic)
Definition: GraphicID.cxx:25
BitmapChecksum mnID4
Definition: GraphicID.hxx:34
B2DVector getRange() const
bool ensureAvailable() const
Definition: impgraph.cxx:1343
BitmapChecksum vcl_get_checksum(BitmapChecksum Checksum, const void *Data, sal_uInt32 DatLen)
Definition: checksum.hxx:72
sal_uInt32 mnID2
Definition: GraphicID.hxx:32
double getWidth() const
BitmapChecksum ImplGetChecksum() const
Definition: impgraph.cxx:1646
B2IRange fround(const B2DRange &rRange)
#define BITMAP_CHECKSUM_SIZE
Definition: checksum.hxx:28
OString getIDString() const
Definition: GraphicID.cxx:77
const Size & GetPrefSize() const
Definition: gdimtf.hxx:175
BitmapEx ImplGetBitmapEx(const GraphicConversionParameters &rParameters) const
Definition: impgraph.cxx:614
tools::Long Width() const
GraphicType ImplGetType() const
Definition: impgraph.hxx:131
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
Definition: impgraph.cxx:324
bool ImplIsAnimated() const
Definition: impgraph.cxx:468
tools::Long Height() const
size_t GetActionSize() const
Definition: gdimtf.cxx:180
Animation ImplGetAnimation() const
Definition: impgraph.cxx:653
sal_uInt32 mnID3
Definition: GraphicID.hxx:33