/src/libwpd/src/lib/WP5GraphicsInformationPacket.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | | /* libwpd |
3 | | * Version: MPL 2.0 / LGPLv2.1+ |
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 | | * Major Contributor(s): |
10 | | * Copyright (C) 2005, 2007 Fridrich Strba (fridrich.strba@bluewin.ch) |
11 | | * |
12 | | * For minor contributions see the git repository. |
13 | | * |
14 | | * Alternatively, the contents of this file may be used under the terms |
15 | | * of the GNU Lesser General Public License Version 2.1 or later |
16 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
17 | | * applicable instead of those above. |
18 | | * |
19 | | * For further information visit http://libwpd.sourceforge.net |
20 | | */ |
21 | | |
22 | | /* "This product is not manufactured, approved, or supported by |
23 | | * Corel Corporation or Corel Corporation Limited." |
24 | | */ |
25 | | |
26 | | #include "WP5GraphicsInformationPacket.h" |
27 | | #include "libwpd_internal.h" |
28 | | |
29 | | WP5GraphicsInformationPacket::WP5GraphicsInformationPacket(librevenge::RVNGInputStream *input, WPXEncryption *encryption, int /* id */, unsigned dataOffset, unsigned dataSize) : |
30 | 0 | WP5GeneralPacketData(), |
31 | 0 | m_images() |
32 | 0 | { |
33 | 0 | _read(input, encryption, dataOffset, dataSize); |
34 | 0 | } |
35 | | |
36 | | WP5GraphicsInformationPacket::~WP5GraphicsInformationPacket() |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | | void WP5GraphicsInformationPacket::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption, unsigned /* dataSize */) |
41 | 0 | { |
42 | 0 | unsigned short tmpImagesCount = readU16(input, encryption); |
43 | 0 | std::vector<unsigned> tmpImagesSizes; |
44 | 0 | for (unsigned short i = 0; i < tmpImagesCount; i++) |
45 | 0 | tmpImagesSizes.push_back(readU32(input, encryption)); |
46 | |
|
47 | 0 | for (unsigned short j = 0; j < tmpImagesCount; j++) |
48 | 0 | { |
49 | 0 | const std::unique_ptr<unsigned char[]> tmpData{new unsigned char[tmpImagesSizes[j]]}; |
50 | |
|
51 | 0 | for (unsigned k = 0; k < tmpImagesSizes[j]; k++) |
52 | 0 | tmpData[k] = readU8(input, encryption); |
53 | | #if 0 |
54 | | librevenge::RVNGString filename; |
55 | | filename.sprintf("binarydump%.4x.wpg", j); |
56 | | FILE *f = fopen(filename.cstr(), "wb"); |
57 | | if (f) |
58 | | { |
59 | | if (tmpData[0]!=0xff || tmpData[1]!='W' || tmpData[2]!='P' || tmpData[3]!='C') |
60 | | { |
61 | | // Here we create a file header, since it looks like some embedded files do not contain it |
62 | | fprintf(f, "%c%c%c%c", 0xff, 0x57, 0x50, 0x43); |
63 | | fprintf(f, "%c%c%c%c", 0x10, 0x00, 0x00, 0x00); |
64 | | fprintf(f, "%c%c%c%c", 0x01, 0x16, 0x01, 0x00); |
65 | | fprintf(f, "%c%c%c%c", 0x00, 0x00, 0x00, 0x00); |
66 | | } |
67 | | |
68 | | for (unsigned l = 0; l < tmpImagesSizes[j]; l++) |
69 | | fprintf(f, "%c", tmpData[l]); |
70 | | fclose(f); |
71 | | } |
72 | | #endif |
73 | 0 | std::unique_ptr<librevenge::RVNGBinaryData> image {new librevenge::RVNGBinaryData(tmpData.get(), tmpImagesSizes[j])}; |
74 | 0 | m_images.push_back(std::move(image)); |
75 | 0 | } |
76 | 0 | } |
77 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |