From dd51283f2c8efc0e2e36b3b33dc1c58c2a1d6eab Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 26 Dec 2017 10:16:33 +0100 Subject: [PATCH] [WIP] No tabs, 2 spaces for indentation --- contrib/liblzma/compress_easy_mt.cpp | 168 +++++++++++++-------------- precomp.cpp | 92 +++++++-------- 2 files changed, 130 insertions(+), 130 deletions(-) diff --git a/contrib/liblzma/compress_easy_mt.cpp b/contrib/liblzma/compress_easy_mt.cpp index 32174a8..32afc9b 100644 --- a/contrib/liblzma/compress_easy_mt.cpp +++ b/contrib/liblzma/compress_easy_mt.cpp @@ -8,95 +8,95 @@ #include "api/lzma.h" bool check(lzma_ret ret) { - if (ret == LZMA_OK) - return true; + if (ret == LZMA_OK) + return true; - const char *msg; - switch (ret) { - case LZMA_MEM_ERROR: - msg = "Memory allocation failed"; - break; + const char *msg; + switch (ret) { + case LZMA_MEM_ERROR: + msg = "Memory allocation failed"; + break; - case LZMA_OPTIONS_ERROR: - // We are no longer using a plain preset so this error - // message has been edited accordingly compared to - // 01_compress_easy.c. - msg = "Specified filter chain is not supported"; - break; + case LZMA_OPTIONS_ERROR: + // We are no longer using a plain preset so this error + // message has been edited accordingly compared to + // 01_compress_easy.c. + msg = "Specified filter chain is not supported"; + break; - case LZMA_UNSUPPORTED_CHECK: - msg = "Specified integrity check is not supported"; - break; + case LZMA_UNSUPPORTED_CHECK: + msg = "Specified integrity check is not supported"; + break; - default: - msg = "Unknown error, possibly a bug"; - break; - } + default: + msg = "Unknown error, possibly a bug"; + break; + } - fprintf(stderr, "Error initializing the encoder: %s (error code %u)\n", - msg, ret); - return false; + fprintf(stderr, "Error initializing the encoder: %s (error code %u)\n", + msg, ret); + return false; } bool init_decoder(lzma_stream *strm) { - lzma_ret ret = lzma_auto_decoder( - strm, UINT64_MAX, 0); - return check(ret); + lzma_ret ret = lzma_auto_decoder( + strm, UINT64_MAX, 0); + return check(ret); } lzma_filter get_filter(lzma_vli filter_id) { - lzma_filter result; - result.id = filter_id; - result.options = NULL; - return result; + lzma_filter result; + result.id = filter_id; + result.options = NULL; + return result; } bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage, uint64_t &block_size) { - // The threaded encoder takes the options as pointer to - // a lzma_mt structure. - lzma_mt mt; + // The threaded encoder takes the options as pointer to + // a lzma_mt structure. + lzma_mt mt; - // No flags are needed. - mt.flags = 0; + // No flags are needed. + mt.flags = 0; - // Let liblzma determine a sane block size. - mt.block_size = 0; + // Let liblzma determine a sane block size. + mt.block_size = 0; - // Use no timeout for lzma_code() calls by setting timeout - // to zero. That is, sometimes lzma_code() might block for - // a long time (from several seconds to even minutes). - // If this is not OK, for example due to progress indicator - // needing updates, specify a timeout in milliseconds here. - // See the documentation of lzma_mt in lzma/container.h for - // information how to choose a reasonable timeout. - mt.timeout = 110; - mt.check = LZMA_CHECK_CRC32; + // Use no timeout for lzma_code() calls by setting timeout + // to zero. That is, sometimes lzma_code() might block for + // a long time (from several seconds to even minutes). + // If this is not OK, for example due to progress indicator + // needing updates, specify a timeout in milliseconds here. + // See the documentation of lzma_mt in lzma/container.h for + // information how to choose a reasonable timeout. + mt.timeout = 110; + mt.check = LZMA_CHECK_CRC32; - mt.threads = threads; + mt.threads = threads; - uint64_t preset_memory_usage; + uint64_t preset_memory_usage; int preset_to_use = 1; // Always use at least preset 1, even if it exceeds the given memory limit for (int preset = 2; preset <= 9; preset++) { - lzma_options_lzma opt_lzma2; - if (lzma_lzma_preset(&opt_lzma2, preset)) { - fprintf(stderr, "Unsupported preset, possibly a bug\n"); - return false; - } + lzma_options_lzma opt_lzma2; + if (lzma_lzma_preset(&opt_lzma2, preset)) { + fprintf(stderr, "Unsupported preset, possibly a bug\n"); + return false; + } - lzma_filter filterLzma2; - filterLzma2.id = LZMA_FILTER_LZMA2; - filterLzma2.options = &opt_lzma2; + lzma_filter filterLzma2; + filterLzma2.id = LZMA_FILTER_LZMA2; + filterLzma2.options = &opt_lzma2; - // the executable filters we use don't change memory usage, so we just ignore them here - // and set them below - const lzma_filter filters[] = { - filterLzma2, - get_filter(LZMA_VLI_UNKNOWN) - }; + // the executable filters we use don't change memory usage, so we just ignore them here + // and set them below + const lzma_filter filters[] = { + filterLzma2, + get_filter(LZMA_VLI_UNKNOWN) + }; - mt.filters = filters; + mt.filters = filters; preset_memory_usage = lzma_stream_encoder_mt_memusage(&mt, &block_size); if (preset_memory_usage > max_memory) break; @@ -104,31 +104,31 @@ bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64 preset_to_use = preset; } - lzma_options_lzma opt_lzma2; - if (lzma_lzma_preset(&opt_lzma2, preset_to_use)) { - fprintf(stderr, "Unsupported preset, possibly a bug\n"); - return false; - } + lzma_options_lzma opt_lzma2; + if (lzma_lzma_preset(&opt_lzma2, preset_to_use)) { + fprintf(stderr, "Unsupported preset, possibly a bug\n"); + return false; + } - lzma_filter filterLzma2; - filterLzma2.id = LZMA_FILTER_LZMA2; - filterLzma2.options = &opt_lzma2; + lzma_filter filterLzma2; + filterLzma2.id = LZMA_FILTER_LZMA2; + filterLzma2.options = &opt_lzma2; - const lzma_filter filters[] = { - get_filter(LZMA_FILTER_X86), - get_filter(LZMA_FILTER_POWERPC), - //get_filter(LZMA_FILTER_IA64), - get_filter(LZMA_FILTER_ARM), - //get_filter(LZMA_FILTER_ARMTHUMB), - //get_filter(LZMA_FILTER_SPARC), - filterLzma2, - get_filter(LZMA_VLI_UNKNOWN) - }; + const lzma_filter filters[] = { + get_filter(LZMA_FILTER_X86), + get_filter(LZMA_FILTER_POWERPC), + //get_filter(LZMA_FILTER_IA64), + get_filter(LZMA_FILTER_ARM), + //get_filter(LZMA_FILTER_ARMTHUMB), + //get_filter(LZMA_FILTER_SPARC), + filterLzma2, + get_filter(LZMA_VLI_UNKNOWN) + }; - mt.filters = filters; + mt.filters = filters; - // Initialize the threaded encoder. - lzma_ret ret = lzma_stream_encoder_mt(strm, &mt); + // Initialize the threaded encoder. + lzma_ret ret = lzma_stream_encoder_mt(strm, &mt); // Determine memory usage and block size memory_usage = lzma_stream_encoder_mt_memusage(&mt, &block_size); diff --git a/precomp.cpp b/precomp.cpp index 6df108a..7879f16 100644 --- a/precomp.cpp +++ b/precomp.cpp @@ -2712,13 +2712,13 @@ int inf(FILE *source, int windowbits, int& compressed_stream_size, int& decompre unsigned char* buf_ptr; do { strm.avail_out = CHUNK; - if (in_memory) { + if (in_memory) { buf_ptr = decomp_io_buf + decompressed_stream_size; strm.next_out = buf_ptr; - } - else { + } + else { strm.next_out = out; - } + } ret = inflate(&strm, Z_NO_FLUSH); switch (ret) { @@ -2742,14 +2742,14 @@ int inf(FILE *source, int windowbits, int& compressed_stream_size, int& decompre safe_fclose(&ftempout); return Z_ERRNO; } - } - else { - if ((decompressed_stream_size + have + CHUNK) >= MAX_IO_BUFFER_SIZE) { - in_memory = false; - write_ftempout_if_not_present(decompressed_stream_size + have, true, true); - } - } - decompressed_stream_size += have; + } + else { + if ((decompressed_stream_size + have + CHUNK) >= MAX_IO_BUFFER_SIZE) { + in_memory = false; + write_ftempout_if_not_present(decompressed_stream_size + have, true, true); + } + } + decompressed_stream_size += have; } while (strm.avail_out == 0); @@ -4241,12 +4241,12 @@ bool compress_file(float min_percent, float max_percent) { if ((type == MPEG1_LAYER_III) && (frame_size > 4)) { unsigned char header2 = in[2]; unsigned char header3 = in[3]; - if (fread(in, 1, frame_size - 4, fin) != (unsigned int)(frame_size - 4)) { - // discard incomplete frame - n--; - mp3_length -= frame_size; - break; - } + if (fread(in, 1, frame_size - 4, fin) != (unsigned int)(frame_size - 4)) { + // discard incomplete frame + n--; + mp3_length -= frame_size; + break; + } if (!is_valid_mp3_frame(in, header2, header3, protection)) { n = 0; break; @@ -6004,7 +6004,7 @@ int try_to_decompress(FILE* file, int windowbits, int& compressed_stream_size, b if (file == fin) { seek_64(file, input_file_pos); } else { - seek_64(file, 0); + seek_64(file, 0); } in_memory = true; @@ -6050,12 +6050,12 @@ void try_recompress(FILE* origfile, int comp_level, int mem_level, int windowbit printf ("Identical decompressed bytes: %i of %i\n", identical_bytes_decomp, decomp_bytes_total); } - bool enough_identical_compressed_bytes = (identical_bytes == compressed_stream_size); - if (!enough_identical_compressed_bytes) { - if ((identical_bytes > DEF_COMPARE_CHUNK) && (identical_bytes + IDENTICAL_COMPRESSED_BYTES_TOLERANCE >= compressed_stream_size)) { - enough_identical_compressed_bytes = true; - } - } + bool enough_identical_compressed_bytes = (identical_bytes == compressed_stream_size); + if (!enough_identical_compressed_bytes) { + if ((identical_bytes > DEF_COMPARE_CHUNK) && (identical_bytes + IDENTICAL_COMPRESSED_BYTES_TOLERANCE >= compressed_stream_size)) { + enough_identical_compressed_bytes = true; + } + } final_compression_found = (identical_bytes_decomp == decomp_bytes_total) && (enough_identical_compressed_bytes) && (penalty_bytes_len < PENALTY_BYTES_TOLERANCE); @@ -6103,14 +6103,14 @@ void try_recompress_bzip2(FILE* origfile, int level, int& compressed_stream_size printf ("Identical decompressed bytes: %i of %i\n", identical_bytes_decomp, decomp_bytes_total); } - bool enough_identical_compressed_bytes = (identical_bytes == compressed_stream_size); - if (!enough_identical_compressed_bytes) { - if ((identical_bytes > DEF_COMPARE_CHUNK) && (identical_bytes + IDENTICAL_COMPRESSED_BYTES_TOLERANCE >= compressed_stream_size)) { - enough_identical_compressed_bytes = true; - } - } + bool enough_identical_compressed_bytes = (identical_bytes == compressed_stream_size); + if (!enough_identical_compressed_bytes) { + if ((identical_bytes > DEF_COMPARE_CHUNK) && (identical_bytes + IDENTICAL_COMPRESSED_BYTES_TOLERANCE >= compressed_stream_size)) { + enough_identical_compressed_bytes = true; + } + } - final_compression_found = (identical_bytes_decomp == decomp_bytes_total) && (enough_identical_compressed_bytes) && (penalty_bytes_len < PENALTY_BYTES_TOLERANCE); + final_compression_found = (identical_bytes_decomp == decomp_bytes_total) && (enough_identical_compressed_bytes) && (penalty_bytes_len < PENALTY_BYTES_TOLERANCE); } best_identical_bytes_decomp = identical_bytes_decomp; @@ -8059,21 +8059,21 @@ bool is_valid_mp3_frame(unsigned char* frame_data, unsigned char header2, unsign } /* ----------------------------------------------- - calculate frame crc - ----------------------------------------------- */ + calculate frame crc + ----------------------------------------------- */ inline unsigned short mp3_calc_layer3_crc(unsigned char header2, unsigned char header3, unsigned char* sideinfo, int sidesize) { - // crc has a start value of 0xFFFF - unsigned short crc = 0xFFFF; + // crc has a start value of 0xFFFF + unsigned short crc = 0xFFFF; - // process two last bytes from header... - crc = (crc << 8) ^ crc_table[(crc>>8) ^ header2]; - crc = (crc << 8) ^ crc_table[(crc>>8) ^ header3]; - // ... and all the bytes from the side information - for ( int i = 0; i < sidesize; i++ ) - crc = (crc << 8) ^ crc_table[(crc>>8) ^ sideinfo[i]]; + // process two last bytes from header... + crc = (crc << 8) ^ crc_table[(crc>>8) ^ header2]; + crc = (crc << 8) ^ crc_table[(crc>>8) ^ header3]; + // ... and all the bytes from the side information + for ( int i = 0; i < sidesize; i++ ) + crc = (crc << 8) ^ crc_table[(crc>>8) ^ sideinfo[i]]; - return crc; + return crc; } void try_decompression_zlib(int windowbits) { @@ -9522,7 +9522,7 @@ void init_compress_otf() { } case OTF_XZ_MT: { uint64_t memory_usage = 0; - uint64_t block_size = 0; + uint64_t block_size = 0; uint64_t max_memory = compression_otf_max_memory * 1024 * 1024LL; int threads = compression_otf_thread_count; @@ -9545,8 +9545,8 @@ void init_compress_otf() { printf("Compressing with LZMA, %i thread%s, memory usage: ", threads, plural.c_str()); print64(memory_usage / (1024 * 1024)); printf(" MiB, block size: "); - print64(block_size / (1024 * 1024)); - printf(" MiB\n\n"); + print64(block_size / (1024 * 1024)); + printf(" MiB\n\n"); break; } }