- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this program works with libz, fails with ipp_z, using l_ipp-samples_p-6.0.0.142 on linux, and icc 10.1.022.
#include
#include
#include
#include
#include
static void ztest(int length, int clevel, int nzeros) {
unsigned char *b = (unsigned char *) malloc(length);
assert(b);
int i;
for (i = 0; i < nzeros; i++)
b = 0;
for (; i < length; i++)
b = random();
uLongf clength = compressBound(length);
unsigned char *cb = (unsigned char *) malloc(clength);
assert(cb);
int r;
uLongf dlength = clength;
r = compress2(cb, &dlength, b, length, clevel);
assert(dlength <= clength);
assert(r == Z_OK);
unsigned char *nb = (unsigned char *) malloc(length);
assert(nb);
uLongf ulength = length;
r = uncompress(nb, &ulength, cb, dlength);
assert(r == Z_OK);
assert(ulength == (uLongf) length);
assert(memcmp(b, nb, length) == 0);
free(cb);
free(nb);
free(b);
}
int main(int argc, char *argv[]) {
ztest(120001, 1, 120001);
return 0;
}
#include
#include
#include
#include
#include
static void ztest(int length, int clevel, int nzeros) {
unsigned char *b = (unsigned char *) malloc(length);
assert(b);
int i;
for (i = 0; i < nzeros; i++)
b = 0;
for (; i < length; i++)
b = random();
uLongf clength = compressBound(length);
unsigned char *cb = (unsigned char *) malloc(clength);
assert(cb);
int r;
uLongf dlength = clength;
r = compress2(cb, &dlength, b, length, clevel);
assert(dlength <= clength);
assert(r == Z_OK);
unsigned char *nb = (unsigned char *) malloc(length);
assert(nb);
uLongf ulength = length;
r = uncompress(nb, &ulength, cb, dlength);
assert(r == Z_OK);
assert(ulength == (uLongf) length);
assert(memcmp(b, nb, length) == 0);
free(cb);
free(nb);
free(b);
}
int main(int argc, char *argv[]) {
ztest(120001, 1, 120001);
return 0;
}
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Sergey Khlystov@Intel
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IPP 6.1 is coming soon, please stay tuned. We expect it will be available sometime in Q2 this year.
Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Sergey Khlystov@Intel
thanks
#include
#include
#include
#include
#include
static void ztest(int length, int clevel, int nzeros) {
unsigned char *b = (unsigned char *) malloc(length);
assert(b);
int i;
for (i = 0; i < nzeros; i++)
b = 0;
for (; i < length; i++)
b = random();
uLongf clength = compressBound(length);
unsigned char *cb = (unsigned char *) malloc(clength);
assert(cb);
int r;
uLongf dlength = clength;
r = compress2(cb, &dlength, b, length, clevel);
assert(dlength <= clength);
assert(r == Z_OK);
unsigned char *nb = (unsigned char *) malloc(length);
assert(nb);
uLongf ulength = length;
r = uncompress(nb, &ulength, cb, dlength);
assert(r == Z_OK);
assert(ulength == length);
assert(memcmp(b, nb, length) == 0);
free(cb);
free(nb);
free(b);
}
int main(int argc, char *argv[]) {
ztest(1000000, 1, 0);
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK. It's clear now. The problem is in uncompressible data and zlib's estimation function (compressBound). For truly uncompressible data zlib uses the specific "stored block" format (i.e. output data is just a copy of input data + some header). And zlib's "compressBound" function computes that "worst case" result length.
IPP zlib function implementation does have estimation functionality via "ippsEncodeLZ77SelectHuffMode_8u" function call, but this functionality is not in zlib source code. So, IPP-ZLIB compress function uses dynamic Huffman coding for uncompressible data. As a result the amount of data produced is a bit more than original zlib's "stored block" method.
In another words, zlib "compressBound" function's computation, in general, cannot be used to predict compressed data size. I don't know the exact numbers, but very empirically compressed data length is <= 1.002*(input data size)+11 bytes.
So, if you change in your code
uLongf clength = compressBound(length);
to
uLongf clength = (uLongf)(length * 1.002 + 11);
(or something similar and more elegant), the "cb" buffer will be long enough to hold the compressed data.
Thanks and regards,
Sergey
IPP zlib function implementation does have estimation functionality via "ippsEncodeLZ77SelectHuffMode_8u" function call, but this functionality is not in zlib source code. So, IPP-ZLIB compress function uses dynamic Huffman coding for uncompressible data. As a result the amount of data produced is a bit more than original zlib's "stored block" method.
In another words, zlib "compressBound" function's computation, in general, cannot be used to predict compressed data size. I don't know the exact numbers, but very empirically compressed data length is <= 1.002*(input data size)+11 bytes.
So, if you change in your code
uLongf clength = compressBound(length);
to
uLongf clength = (uLongf)(length * 1.002 + 11);
(or something similar and more elegant), the "cb" buffer will be long enough to hold the compressed data.
Thanks and regards,
Sergey
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page