Helper functions for writing 16/24/32/64-bit values to fout

This commit is contained in:
Christian Schneider 2016-02-14 11:46:09 +01:00
parent d521448acb
commit 491ebece69

View file

@ -289,6 +289,13 @@ bz_stream otf_bz2_stream_c, otf_bz2_stream_d;
void own_fputc(char c, FILE* f); void own_fputc(char c, FILE* f);
unsigned char fin_fgetc(); unsigned char fin_fgetc();
void fout_fputc(char c); void fout_fputc(char c);
void fout_fput16(int v);
void fout_fput24(int v);
void fout_fput32_little_endian(int v);
void fout_fput32(int v);
void fout_fput32(unsigned int v);
void fout_fput64(long long v);
void fout_fput64(unsigned long long v);
void init_compress_otf(); void init_compress_otf();
void denit_compress_otf(); void denit_compress_otf();
void init_decompress_otf(); void init_decompress_otf();
@ -2740,14 +2747,7 @@ void end_uncompressed_data() {
if (!uncompressed_data_in_work) return; if (!uncompressed_data_in_work) return;
fout_fputc((uncompressed_length >> 56) % 256); fout_fput64(uncompressed_length);
fout_fputc((uncompressed_length >> 48) % 256);
fout_fputc((uncompressed_length >> 40) % 256);
fout_fputc((uncompressed_length >> 32) % 256);
fout_fputc((uncompressed_length >> 24) % 256);
fout_fputc((uncompressed_length >> 16) % 256);
fout_fputc((uncompressed_length >> 8) % 256);
fout_fputc(uncompressed_length % 256);
// fast copy of uncompressed data // fast copy of uncompressed data
seek_64(fin, uncompressed_pos); seek_64(fin, uncompressed_pos);
@ -2901,9 +2901,7 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width,
pdf_header_length -= 12; pdf_header_length -= 12;
fout_fputc((pdf_header_length >> 16) % 256); fout_fput24(pdf_header_length);
fout_fputc((pdf_header_length >> 8) % 256);
fout_fputc(pdf_header_length % 256);
own_fwrite(in_buf + cb + 12, 1, pdf_header_length, fout); own_fwrite(in_buf + cb + 12, 1, pdf_header_length, fout);
@ -2912,24 +2910,14 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width,
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
// eventually write BMP header // eventually write BMP header
@ -2947,10 +2935,7 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width,
} else { } else {
bmp_size += 54; bmp_size += 54;
} }
fout_fputc(bmp_size % 256); fout_fput32_little_endian(bmp_size);
fout_fputc((bmp_size >> 8) % 256);
fout_fputc((bmp_size >> 16) % 256);
fout_fputc((bmp_size >> 24) % 256);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
fout_fputc(0); fout_fputc(0);
@ -2968,15 +2953,8 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width,
fout_fputc(0); fout_fputc(0);
fout_fputc(0); fout_fputc(0);
fout_fputc(img_width % 256); fout_fput32_little_endian(img_width);
fout_fputc((img_width >> 8) % 256); fout_fput32_little_endian(img_height);
fout_fputc((img_width >> 16) % 256);
fout_fputc((img_width >> 24) % 256);
fout_fputc(img_height % 256);
fout_fputc((img_height >> 8) % 256);
fout_fputc((img_height >> 16) % 256);
fout_fputc((img_height >> 24) % 256);
fout_fputc(1); fout_fputc(1);
fout_fputc(0); fout_fputc(0);
@ -2996,10 +2974,7 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width,
int datasize = ((img_width+3) & -4) * img_height; int datasize = ((img_width+3) & -4) * img_height;
if (bmp_header_type == 2) datasize *= 3; if (bmp_header_type == 2) datasize *= 3;
fout_fputc(datasize % 256); fout_fput32_little_endian(datasize);
fout_fputc((datasize >> 8) % 256);
fout_fputc((datasize >> 16) % 256);
fout_fputc((datasize >> 24) % 256);
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
fout_fputc(0); fout_fputc(0);
@ -3145,9 +3120,7 @@ void try_decompression_zip(int zip_header_length) {
zip_header_length -= 4; zip_header_length -= 4;
fout_fputc((zip_header_length >> 16) % 256); fout_fput24(zip_header_length);
fout_fputc((zip_header_length >> 8) % 256);
fout_fputc(zip_header_length % 256);
own_fwrite(in_buf + cb + 4, 1, zip_header_length, fout); own_fwrite(in_buf + cb + 4, 1, zip_header_length, fout);
@ -3156,34 +3129,17 @@ void try_decompression_zip(int zip_header_length) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -6338,9 +6294,7 @@ void try_decompression_gzip(int gzip_header_length) {
gzip_header_length -= 2; gzip_header_length -= 2;
fout_fputc((gzip_header_length >> 16) % 256); fout_fput24(gzip_header_length);
fout_fputc((gzip_header_length >> 8) % 256);
fout_fputc(gzip_header_length % 256);
own_fwrite(in_buf + cb + 2, 1, gzip_header_length, fout); own_fwrite(in_buf + cb + 2, 1, gzip_header_length, fout);
@ -6349,34 +6303,17 @@ void try_decompression_gzip(int gzip_header_length) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -6491,24 +6428,14 @@ void try_decompression_png (int windowbits) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
// write decompressed data // write decompressed data
@ -6627,14 +6554,10 @@ void try_decompression_png_multi(int windowbits) {
} while (i < idat_count); } while (i < idat_count);
} }
// store IDAT pairs count // store IDAT pairs count
fout_fputc((idat_pairs_written_count >> 8) % 256); fout_fput16(idat_pairs_written_count);
fout_fputc(idat_pairs_written_count % 256);
// store IDAT CRCs and lengths // store IDAT CRCs and lengths
fout_fputc((idat_lengths[0] >> 24) % 256); fout_fput32(idat_lengths[0]);
fout_fputc((idat_lengths[0] >> 16) % 256);
fout_fputc((idat_lengths[0] >> 8) % 256);
fout_fputc(idat_lengths[0] % 256);
// store IDAT CRCs and lengths // store IDAT CRCs and lengths
i = 1; i = 1;
@ -6642,15 +6565,8 @@ void try_decompression_png_multi(int windowbits) {
idat_pairs_written_count = 0; idat_pairs_written_count = 0;
if (idat_pos <= best_identical_bytes) { if (idat_pos <= best_identical_bytes) {
do { do {
fout_fputc((idat_crcs[i] >> 24) % 256); fout_fput32(idat_crcs[i]);
fout_fputc((idat_crcs[i] >> 16) % 256); fout_fput32(idat_lengths[i]);
fout_fputc((idat_crcs[i] >> 8) % 256);
fout_fputc(idat_crcs[i] % 256);
fout_fputc((idat_lengths[i] >> 24) % 256);
fout_fputc((idat_lengths[i] >> 16) % 256);
fout_fputc((idat_lengths[i] >> 8) % 256);
fout_fputc(idat_lengths[i] % 256);
idat_pairs_written_count++; idat_pairs_written_count++;
@ -6666,24 +6582,14 @@ void try_decompression_png_multi(int windowbits) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
// write decompressed data // write decompressed data
@ -7268,10 +7174,7 @@ void try_decompression_gif(unsigned char version[5]) {
fout_fputc(5); // GIF fout_fputc(5); // GIF
// store diff bytes // store diff bytes
fout_fputc((gDiff.GIFDiffIndex >> 24) % 256); fout_fput32(gDiff.GIFDiffIndex);
fout_fputc((gDiff.GIFDiffIndex >> 16) % 256);
fout_fputc((gDiff.GIFDiffIndex >> 8) % 256);
fout_fputc(gDiff.GIFDiffIndex % 256);
if(DEBUG_MODE) { if(DEBUG_MODE) {
if (gDiff.GIFDiffIndex > 0) if (gDiff.GIFDiffIndex > 0)
printf("Diff bytes were used: %i bytes\n", gDiff.GIFDiffIndex); printf("Diff bytes were used: %i bytes\n", gDiff.GIFDiffIndex);
@ -7286,25 +7189,15 @@ void try_decompression_gif(unsigned char version[5]) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(decomp_length);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((decomp_length >> 24) % 256);
fout_fputc((decomp_length >> 16) % 256);
fout_fputc((decomp_length >> 8) % 256);
fout_fputc(decomp_length % 256);
// write decompressed data // write decompressed data
@ -7478,15 +7371,8 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) {
} }
fout_fputc(6); // JPG fout_fputc(6); // JPG
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
// write compressed JPG // write compressed JPG
write_decompressed_data(best_identical_bytes_decomp); write_decompressed_data(best_identical_bytes_decomp);
@ -7576,15 +7462,8 @@ void try_decompression_mp3 (long long mp3_length) {
fout_fputc(1); // no penalty bytes fout_fputc(1); // no penalty bytes
fout_fputc(10); // MP3 fout_fputc(10); // MP3
fout_fputc((best_identical_bytes >> 24) % 256); fout_fputc(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fputc(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
// write compressed MP3 // write compressed MP3
write_decompressed_data(best_identical_bytes_decomp); write_decompressed_data(best_identical_bytes_decomp);
@ -7707,34 +7586,17 @@ void try_decompression_zlib(int windowbits) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fputc(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fputc(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -7866,34 +7728,17 @@ void try_decompression_brute() {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -8019,34 +7864,17 @@ void try_decompression_swf(int windowbits, char swf_version) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -8137,34 +7965,17 @@ void try_decompression_bzip2(int compression_level) {
if (DEBUG_MODE) { if (DEBUG_MODE) {
printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len);
} }
fout_fputc((best_penalty_bytes_len >> 24) % 256); fout_fput32(best_penalty_bytes_len);
fout_fputc((best_penalty_bytes_len >> 16) % 256);
fout_fputc((best_penalty_bytes_len >> 8) % 256);
fout_fputc(best_penalty_bytes_len % 256);
for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) { for (int pbc = 0; pbc < best_penalty_bytes_len; pbc++) {
fout_fputc(best_penalty_bytes[pbc]); fout_fputc(best_penalty_bytes[pbc]);
} }
} }
fout_fputc((best_identical_bytes >> 24) % 256); fout_fput32(best_identical_bytes);
fout_fputc((best_identical_bytes >> 16) % 256); fout_fput32(best_identical_bytes_decomp);
fout_fputc((best_identical_bytes >> 8) % 256);
fout_fputc(best_identical_bytes % 256);
fout_fputc((best_identical_bytes_decomp >> 24) % 256);
fout_fputc((best_identical_bytes_decomp >> 16) % 256);
fout_fputc((best_identical_bytes_decomp >> 8) % 256);
fout_fputc(best_identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -8473,15 +8284,13 @@ void try_decompression_base64(int base64_header_length) {
fout_fputc(header_byte); fout_fputc(header_byte);
fout_fputc(8); // Base64 fout_fputc(8); // Base64
fout_fputc((base64_header_length >> 8) % 256); fout_fput16(base64_header_length);
fout_fputc(base64_header_length % 256);
// write "header", but change first char to prevent re-detection // write "header", but change first char to prevent re-detection
fout_fputc(in_buf[cb] - 1); fout_fputc(in_buf[cb] - 1);
own_fwrite(in_buf + cb + 1, 1, base64_header_length - 1, fout); own_fwrite(in_buf + cb + 1, 1, base64_header_length - 1, fout);
fout_fputc((line_count >> 8) % 256); fout_fput16(line_count);
fout_fputc(line_count % 256);
if (line_case == 2) { if (line_case == 2) {
for (i = 0; i < line_count; i++) { for (i = 0; i < line_count; i++) {
fout_fputc(base64_line_len[i]); fout_fputc(base64_line_len[i]);
@ -8491,25 +8300,11 @@ void try_decompression_base64(int base64_header_length) {
if (line_case == 1) fout_fputc(base64_line_len[line_count - 1]); if (line_case == 1) fout_fputc(base64_line_len[line_count - 1]);
} }
fout_fputc((identical_bytes >> 24) % 256); fout_fput32(identical_bytes);
fout_fputc((identical_bytes >> 16) % 256); fout_fput32(identical_bytes_decomp);
fout_fputc((identical_bytes >> 8) % 256);
fout_fputc(identical_bytes % 256);
fout_fputc((identical_bytes_decomp >> 24) % 256);
fout_fputc((identical_bytes_decomp >> 16) % 256);
fout_fputc((identical_bytes_decomp >> 8) % 256);
fout_fputc(identical_bytes_decomp % 256);
if (r.success) { if (r.success) {
fout_fputc((r.file_length >> 56) % 256); fout_fput64(r.file_length);
fout_fputc((r.file_length >> 48) % 256);
fout_fputc((r.file_length >> 40) % 256);
fout_fputc((r.file_length >> 32) % 256);
fout_fputc((r.file_length >> 24) % 256);
fout_fputc((r.file_length >> 16) % 256);
fout_fputc((r.file_length >> 8) % 256);
fout_fputc(r.file_length % 256);
} }
// write decompressed data // write decompressed data
@ -9052,6 +8847,60 @@ void fout_fputc(char c) {
} }
} }
void fout_fput16(int v) {
fout_fputc((v >> 8) % 256);
fout_fputc(v % 256);
}
void fout_fput24(int v) {
fout_fputc((v >> 16) % 256);
fout_fputc((v >> 8) % 256);
fout_fputc(v % 256);
}
void fout_fput32_little_endian(int v) {
fout_fputc(v % 256);
fout_fputc((v >> 8) % 256);
fout_fputc((v >> 16) % 256);
fout_fputc((v >> 24) % 256);
}
void fout_fput32(int v) {
fout_fputc((v >> 24) % 256);
fout_fputc((v >> 16) % 256);
fout_fputc((v >> 8) % 256);
fout_fputc(v % 256);
}
void fout_fput32(unsigned int v) {
fout_fputc((v >> 24) % 256);
fout_fputc((v >> 16) % 256);
fout_fputc((v >> 8) % 256);
fout_fputc(v % 256);
}
void fout_fput64(long long v) {
fout_fputc((v >> 56) % 256);
fout_fputc((v >> 48) % 256);
fout_fputc((v >> 40) % 256);
fout_fputc((v >> 32) % 256);
fout_fputc((v >> 24) % 256);
fout_fputc((v >> 16) % 256);
fout_fputc((v >> 8) % 256);
fout_fputc(v % 256);
}
void fout_fput64(unsigned long long v) {
fout_fputc((v >> 56) % 256);
fout_fputc((v >> 48) % 256);
fout_fputc((v >> 40) % 256);
fout_fputc((v >> 32) % 256);
fout_fputc((v >> 24) % 256);
fout_fputc((v >> 16) % 256);
fout_fputc((v >> 8) % 256);
fout_fputc(v % 256);
}
unsigned char fin_fgetc() { unsigned char fin_fgetc() {
if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_from_method; if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_from_method;