/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
// fprintf(stderr,"zos flush: calling deflate, avail_in %d, avail_out %d\n",
// zs->avail_in,zs->avail_out);
checkCompressionLevel();
+ if (zs->avail_in != 0) {
+ int rc = deflate(zs, Z_SYNC_FLUSH);
+ if (rc != Z_OK) throw Exception("ZlibOutStream: deflate failed");
+ }
// fprintf(stderr,"zos flush: after deflate: %d bytes\n",
// zs->next_out-underlying->getptr());
// fprintf(stderr,"zos overrun: calling deflate, avail_in %d, avail_out %d\n",
// zs->avail_in,zs->avail_out);
- checkCompressionLevel();
+ checkCompressionLevel();
+ if (zs->avail_in != 0) {
+ int rc = deflate(zs, 0);
+ if (rc != Z_OK) throw Exception("ZlibOutStream: deflate failed");
+ }
// fprintf(stderr,"zos overrun: after deflate: %d bytes\n",
// zs->next_out-underlying->getptr());
void ZlibOutStream::checkCompressionLevel()
{
if (newLevel != compressionLevel) {
- int rc = deflate(zs, Z_SYNC_FLUSH);
- if (rc != Z_OK)
- throw Exception("ZlibOutStream: deflate failed");
- if (deflateParams (zs, newLevel, Z_DEFAULT_STRATEGY) != Z_OK)
+ if (deflateParams (zs, newLevel, Z_DEFAULT_STRATEGY) != Z_OK) {
throw Exception("ZlibOutStream: deflateParams failed");
+ }
compressionLevel = newLevel;
- } else {
- int rc = deflate(zs, Z_SYNC_FLUSH);
- if (rc != Z_OK)
- throw Exception("ZlibOutStream: deflate failed");
}
}
/* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
+ * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
} else {
// FIXME: Using a temporary MemOutStream may be not efficient.
// Maybe use the same static object used in the JPEG coder?
- rdr::MemOutStream mem_os;
+ int maxBeforeSize = s_pconf->maxRectSize * (BPP / 8);
+ int maxAfterSize = maxBeforeSize + (maxBeforeSize + 99) / 100 + 12;
+ rdr::MemOutStream mem_os(maxAfterSize);
zos->setUnderlying(&mem_os);
zos->setCompressionLevel(zlibLevel);
zos->writeBytes(buf, length);