Removed bz2 support
This commit is contained in:
@@ -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)
|
||||
@@ -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)
|
||||
|
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user