gui
[lbook_fbreader.git] / fbreader / src / formats / pdb / PluckerImages.cpp
bloba56533ce6e2f17b2eaa0865362dd8376c80ffbef
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include <ZLFile.h>
21 #include <ZLInputStream.h>
22 #include <ZLZDecompressor.h>
23 #include <ZLStringUtil.h>
25 #include "PluckerImages.h"
26 #include "DocDecompressor.h"
28 const shared_ptr<std::string> ZCompressedFileImage::stringData() const {
29 shared_ptr<ZLInputStream> stream = ZLFile(myPath).inputStream();
31 shared_ptr<std::string> imageData = new std::string();
33 if (!stream.isNull() && stream->open()) {
34 stream->seek(myOffset, false);
35 ZLZDecompressor decompressor(myCompressedSize);
37 static const size_t charBufferSize = 2048;
38 char *charBuffer = new char[charBufferSize];
39 std::vector<std::string> buffer;
41 size_t s;
42 do {
43 s = decompressor.decompress(*stream, charBuffer, charBufferSize);
44 if (s != 0) {
45 buffer.push_back(std::string());
46 buffer.back().append(charBuffer, s);
48 } while (s == charBufferSize);
49 ZLStringUtil::append(*imageData, buffer);
51 delete[] charBuffer;
54 return imageData;
57 const shared_ptr<std::string> DocCompressedFileImage::stringData() const {
58 shared_ptr<ZLInputStream> stream = ZLFile(myPath).inputStream();
60 shared_ptr<std::string> imageData = new std::string();
62 if (!stream.isNull() && stream->open()) {
63 stream->seek(myOffset, false);
64 char *buffer = new char[65535];
65 size_t uncompressedSize = DocDecompressor().decompress(*stream, buffer, myCompressedSize, 65535);
66 imageData->append(buffer, uncompressedSize);
67 delete[] buffer;
70 return imageData;
73 shared_ptr<const ZLImage> PluckerMultiImage::subImage(unsigned int row, unsigned int column) const {
74 unsigned int index = row * myColumns + column;
75 if (index >= myIds.size()) {
76 return 0;
78 ZLImageMap::const_iterator entry = myImageMap.find(myIds[index]);
79 return (entry != myImageMap.end()) ? entry->second : 0;