Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
Scroom::MemoryBlobs::Detail Namespace Reference

Functions

PageList compressBlob (const uint8_t *in, size_t size, const PageProvider::Ptr &provider)
 
void decompressBlob (uint8_t *out, size_t size, PageList list, const PageProvider::Ptr &provider)
 

Function Documentation

◆ compressBlob()

PageList Scroom::MemoryBlobs::Detail::compressBlob ( const uint8_t *  in,
size_t  size,
const PageProvider::Ptr provider 
)
32 {
34 z_stream stream;
35 const size_t pageSize = provider->getPageSize();
36
37 stream.next_in = const_cast<uint8_t*>(in); // NOLINT(cppcoreguidelines-pro-type-const-cast)
38 stream.avail_in = size;
39 stream.avail_out = 0;
40 stream.zalloc = Z_NULL;
41 stream.zfree = Z_NULL;
42 stream.opaque = Z_NULL;
43
44 int r = deflateInit(&stream, Z_BEST_SPEED);
45 zlib_verify(r == Z_OK, "deflateInit", r, stream);
46
47 do
48 {
49 verify(stream.avail_out == 0);
50
51 Page::Ptr const currentPage = provider->getFreePage();
52 result.push_back(currentPage);
53
54 RawPageData::Ptr const currentPageRaw = currentPage->get();
55
56 stream.next_out = currentPageRaw.get();
57 stream.avail_out = pageSize;
58
59 r = deflate(&stream, Z_FINISH);
60
61 } while(r == Z_OK);
62
63 zlib_verify(r == Z_STREAM_END, "deflate", r, stream);
64
65 r = deflateEnd(&stream);
66 zlib_verify(r == Z_OK, "deflateEnd", r, stream);
67
68 return result;
69 }
#define verify(expr)
Definition assertions.hh:40
#define zlib_verify(condition, function_name, r, stream)
Definition blob-compression.cc:19
PageProvider::Ptr provider
Definition blob-tests.cc:26
uint8_t in[blobSize]
Definition compression-tests.cc:25
std::shared_ptr< Scroom::MemoryBlocks::Page > Ptr
Definition memoryblobs.hh:33
std::shared_ptr< uint8_t > Ptr
Definition memoryblobs.hh:26
std::list< Page::Ptr > PageList
Definition memoryblobs.hh:35
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94
Scroom::Utils::Rectangle< double > const r
Definition transformpresentation_test.cc:65

Referenced by Scroom::MemoryBlobs::Blob::compress().

Here is the caller graph for this function:

◆ decompressBlob()

void Scroom::MemoryBlobs::Detail::decompressBlob ( uint8_t *  out,
size_t  size,
PageList  list,
const PageProvider::Ptr provider 
)
72 {
73 z_stream stream;
74 const size_t pageSize = provider->getPageSize();
75
76 stream.next_out = out;
77 stream.avail_out = size;
78 stream.avail_in = 0;
79 stream.zalloc = Z_NULL;
80 stream.zfree = Z_NULL;
81 stream.opaque = Z_NULL;
82
83 int r = inflateInit(&stream);
84 zlib_verify(r == Z_OK, "inflateInit", r, stream);
85
86 while(!list.empty() && r == Z_OK)
87 {
88 verify(stream.avail_in == 0);
89
90 Page::Ptr const currentPage = list.front();
91 list.pop_front();
92
93 RawPageData::Ptr const currentPageRaw = currentPage->get();
94
95 stream.next_in = currentPageRaw.get();
96 stream.avail_in = pageSize;
97
98 const int flush = (list.empty() ? Z_FINISH : Z_NO_FLUSH);
99
100 r = inflate(&stream, flush);
101 }
102 zlib_verify(r == Z_OK || r == Z_STREAM_END, "inflate", r, stream);
103
104 r = inflateEnd(&stream);
105 zlib_verify(r == Z_OK, "inflateEnd", r, stream);
106 }
uint8_t out[blobSize]
Definition compression-tests.cc:35

Referenced by Scroom::MemoryBlobs::Blob::load().

Here is the caller graph for this function: