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());
43  0, rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(),
44  rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
45  }
46  else if (rGraphic.ImplIsAnimated())
47  {
48  const Animation aAnimation(rGraphic.ImplGetAnimation());
49 
50  mnID1 |= (aAnimation.Count() & 0x0fffffff);
51  mnID2 = aAnimation.GetDisplaySizePixel().Width();
52  mnID3 = aAnimation.GetDisplaySizePixel().Height();
53  mnID4 = rGraphic.ImplGetChecksum();
54  }
55  else
56  {
57  const BitmapEx aBmpEx(rGraphic.ImplGetBitmapEx(GraphicConversionParameters()));
58 
59  mnID1 |= (((static_cast<sal_uLong>(aBmpEx.GetTransparentType()) << 8)
60  | (aBmpEx.IsAlpha() ? 1 : 0))
61  & 0x0fffffff);
62  mnID2 = aBmpEx.GetSizePixel().Width();
63  mnID3 = aBmpEx.GetSizePixel().Height();
64  mnID4 = rGraphic.ImplGetChecksum();
65  }
66  }
67  else if (rGraphic.ImplGetType() == GraphicType::GdiMetafile)
68  {
69  const GDIMetaFile& rMtf = rGraphic.ImplGetGDIMetaFile();
70 
71  mnID1 |= (rMtf.GetActionSize() & 0x0fffffff);
72  mnID2 = rMtf.GetPrefSize().Width();
73  mnID3 = rMtf.GetPrefSize().Height();
74  mnID4 = rGraphic.ImplGetChecksum();
75  }
76 }
77 
78 OString GraphicID::getIDString() const
79 {
80  static const char aHexData[]
81  = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
82 
83  sal_Int32 nShift, nIndex = 0;
84  sal_Int32 nLen = 24 + (2 * BITMAP_CHECKSUM_SIZE);
85  OStringBuffer aHexStr(nLen);
86  aHexStr.setLength(nLen);
87 
88  for (nShift = 28; nShift >= 0; nShift -= 4)
89  aHexStr[nIndex++] = aHexData[(mnID1 >> static_cast<sal_uInt32>(nShift)) & 0xf];
90 
91  for (nShift = 28; nShift >= 0; nShift -= 4)
92  aHexStr[nIndex++] = aHexData[(mnID2 >> static_cast<sal_uInt32>(nShift)) & 0xf];
93 
94  for (nShift = 28; nShift >= 0; nShift -= 4)
95  aHexStr[nIndex++] = aHexData[(mnID3 >> static_cast<sal_uInt32>(nShift)) & 0xf];
96 
97  for (nShift = (8 * BITMAP_CHECKSUM_SIZE) - 4; nShift >= 0; nShift -= 4)
98  aHexStr[nIndex++] = aHexData[(mnID4 >> static_cast<sal_uInt32>(nShift)) & 0xf];
99 
100  return aHexStr.makeStringAndClear();
101 }
102 
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
const GDIMetaFile & ImplGetGDIMetaFile() const
Definition: impgraph.cxx:722
sal_Int32 nIndex
double getHeight() const
long Height() 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:1404
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:1552
B2IRange fround(const B2DRange &rRange)
#define BITMAP_CHECKSUM_SIZE
Definition: checksum.hxx:28
OString getIDString() const
Definition: GraphicID.cxx:78
const Size & GetPrefSize() const
Definition: gdimtf.hxx:173
BitmapEx ImplGetBitmapEx(const GraphicConversionParameters &rParameters) const
Definition: impgraph.cxx:666
GraphicType ImplGetType() const
Definition: impgraph.hxx:123
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
Definition: impgraph.cxx:380
bool ImplIsAnimated() const
Definition: impgraph.cxx:520
size_t GetActionSize() const
Definition: gdimtf.cxx:157
Animation ImplGetAnimation() const
Definition: impgraph.cxx:705
sal_uInt32 mnID3
Definition: GraphicID.hxx:33