Skip to content

Commit

Permalink
Removed bz2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
heckflosse committed Jun 13, 2017
1 parent 64eea2b commit 2fcb7d9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 168 deletions.
11 changes: 0 additions & 11 deletions CMakeLists.txt
Expand Up @@ -108,7 +108,6 @@ endif()

option(USE_EXPERIMENTAL_LANG_VERSIONS "Build with -std=c++0x" OFF)
option(BUILD_SHARED "Build with shared libraries" OFF)
option(WITH_BZIP "Build with Bzip2 support" ON)
option(WITH_MYFILE_MMAP "Build using memory mapped file" ON)
option(WITH_LTO "Build with link-time optimizations" OFF)
option(WITH_SAN "Build with run-time sanitizer" OFF)
Expand Down Expand Up @@ -294,16 +293,6 @@ find_package(PNG REQUIRED)
find_package(TIFF REQUIRED)
find_package(ZLIB REQUIRED)

# Link with bzip:
if(WITH_BZIP)
find_package(BZip2)
if(BZIP2_FOUND)
add_definitions(-DBZIP_SUPPORT)
set(EXTRA_INCDIR ${BZIP2_INCLUDE_DIR})
set(EXTRA_LIB ${EXTRA_LIB} ${BZIP2_LIBRARIES})
endif()
endif()

# Check for libcanberra-gtk3 (sound events on Linux):
if(UNIX AND(NOT APPLE))
pkg_check_modules(CANBERRA-GTK REQUIRED libcanberra-gtk3)
Expand Down
159 changes: 2 additions & 157 deletions rtengine/myfile.cc
Expand Up @@ -19,9 +19,6 @@
#include "myfile.h"
#include <cstdarg>
#include <glibmm.h>
#ifdef BZIP_SUPPORT
#include <bzlib.h>
#endif

// get mmap() sorted out
#ifdef MYFILE_MMAP
Expand Down Expand Up @@ -116,85 +113,6 @@ IMFILE* fopen (const char* fname)
mf->data = (char*)data;
mf->eof = false;

#ifdef BZIP_SUPPORT
{
bool bzip = false;
Glib::ustring bname = Glib::path_get_basename(fname);
size_t lastdot = bname.find_last_of ('.');

if (lastdot != bname.npos) {
bzip = bname.substr (lastdot).casefold() == Glib::ustring(".bz2").casefold();
}

if (bzip) {
int ret;

// initialize bzip stream structure
bz_stream stream;
stream.bzalloc = nullptr;
stream.bzfree = nullptr;
stream.opaque = nullptr;
ret = BZ2_bzDecompressInit(&stream, 0, 0);

if (ret != BZ_OK) {
printf("bzip initialization failed with error %d\n", ret);
} else {
// allocate initial buffer for decompressed data
unsigned int buffer_out_count = 0; // bytes of decompressed data
unsigned int buffer_size = 10 * 1024 * 1024; // 10 MB, extended dynamically if needed
char* buffer = nullptr;

stream.next_in = mf->data; // input data address
stream.avail_in = mf->size;

while (ret == BZ_OK) {
buffer = static_cast<char*>( realloc(buffer, buffer_size)); // allocate/resize buffer

if (!buffer) {
free(buffer);
}

stream.next_out = buffer + buffer_out_count; // output data adress
stream.avail_out = buffer_size - buffer_out_count;

ret = BZ2_bzDecompress(&stream);

buffer_size *= 2; // increase buffer size for next iteration
buffer_out_count = stream.total_out_lo32;

if (stream.total_out_hi32 > 0) {
printf("bzip decompressed data byte count high byte is nonzero: %d\n", stream.total_out_hi32);
}
}

if (ret == BZ_STREAM_END) {
//delete [] mf->data;
// close memory mapping, setting fd -1 will ensure deletion of mf->data upon fclose()
mf->fd = -1;
munmap((void*)mf->data, mf->size);
close(mf->fd);

char* realData = new char [buffer_out_count];
memcpy(realData, buffer, buffer_out_count);

mf->data = realData;
mf->size = buffer_out_count;
} else {
printf("bzip decompression failed with error %d\n", ret);
}

// cleanup
free(buffer);
ret = BZ2_bzDecompressEnd(&stream);

if (ret != BZ_OK) {
printf("bzip cleanup failed with error %d\n", ret);
}
}
}
}
#endif // BZIP_SUPPORT

return mf;
}

Expand Down Expand Up @@ -247,79 +165,6 @@ IMFILE* gfopen (const char* fname)
mf->pos = 0;
mf->eof = false;

#ifdef BZIP_SUPPORT
{
bool bzip = false;
Glib::ustring bname = Glib::path_get_basename(fname);
size_t lastdot = bname.find_last_of ('.');

if (lastdot != bname.npos) {
bzip = bname.substr (lastdot).casefold() == Glib::ustring(".bz2").casefold();
}

if (bzip) {
int ret;

// initialize bzip stream structure
bz_stream stream;
stream.bzalloc = 0;
stream.bzfree = 0;
stream.opaque = 0;
ret = BZ2_bzDecompressInit(&stream, 0, 0);

if (ret != BZ_OK) {
printf("bzip initialization failed with error %d\n", ret);
} else {
// allocate initial buffer for decompressed data
unsigned int buffer_out_count = 0; // bytes of decompressed data
unsigned int buffer_size = 10 * 1024 * 1024; // 10 MB, extended dynamically if needed
char* buffer = 0;

stream.next_in = mf->data; // input data address
stream.avail_in = mf->size;

while (ret == BZ_OK) {
buffer = static_cast<char*>( realloc(buffer, buffer_size)); // allocate/resize buffer

if (!buffer) {
free(buffer);
}

stream.next_out = buffer + buffer_out_count; // output data adress
stream.avail_out = buffer_size - buffer_out_count;

ret = BZ2_bzDecompress(&stream);

buffer_size *= 2; // increase buffer size for next iteration
buffer_out_count = stream.total_out_lo32;

if (stream.total_out_hi32 > 0) {
printf("bzip decompressed data byte count high byte is nonzero: %d\n", stream.total_out_hi32);
}
}

if (ret == BZ_STREAM_END) {
delete [] mf->data;
char* realData = new char [buffer_out_count];
memcpy(realData, buffer, buffer_out_count);

mf->data = realData;
mf->size = buffer_out_count;
} else {
printf("bzip decompression failed with error %d\n", ret);
}

// cleanup
free(buffer);
ret = BZ2_bzDecompressEnd(&stream);

if (ret != BZ_OK) {
printf("bzip cleanup failed with error %d\n", ret);
}
}
}
}
#endif // BZIP_SUPPORT
return mf;
}
#endif //MYFILE_MMAP
Expand Down Expand Up @@ -361,10 +206,10 @@ int fscanf (IMFILE* f, const char* s ...)
// of file data and vsscanf() won't tell us how many characters that
// were parsed. However, only dcraw.cc code use it and only for "%f" and
// "%d", so we make a dummy fscanf here just to support dcraw case.
char buf[50], *endptr = nullptr;
char buf[51], *endptr = nullptr;
int copy_sz = f->size - f->pos;

if (copy_sz > static_cast<int>(sizeof(buf))) {
if (copy_sz >= static_cast<int>(sizeof(buf))) {
copy_sz = sizeof(buf) - 1;
}

Expand Down

0 comments on commit 2fcb7d9

Please sign in to comment.