diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-02-08 15:18:08 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-02-08 17:51:15 +0100 |
commit | cb769c62e55599e9f980001830bc61d9fcaa64a9 (patch) | |
tree | 0bf980c385a61cbc8720cf990762ffc1200f9d6a /libqpdf/Pl_LZWDecoder.cc | |
parent | 716381f65a2b2dc72f8da2426ba71aeab02c507f (diff) | |
download | qpdf-cb769c62e55599e9f980001830bc61d9fcaa64a9.tar.zst |
WHITESPACE ONLY -- expand tabs in source code
This comment expands all tabs using an 8-character tab-width. You
should ignore this commit when using git blame or use git blame -w.
In the early days, I used to use tabs where possible for indentation,
since emacs did this automatically. In recent years, I have switched
to only using spaces, which means qpdf source code has been a mixture
of spaces and tabs. I have avoided cleaning this up because of not
wanting gratuitous whitespaces change to cloud the output of git
blame, but I changed my mind after discussing with users who view qpdf
source code in editors/IDEs that have other tab widths by default and
in light of the fact that I am planning to start applying automatic
code formatting soon.
Diffstat (limited to 'libqpdf/Pl_LZWDecoder.cc')
-rw-r--r-- | libqpdf/Pl_LZWDecoder.cc | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc index 81069da6..bace3854 100644 --- a/libqpdf/Pl_LZWDecoder.cc +++ b/libqpdf/Pl_LZWDecoder.cc @@ -8,7 +8,7 @@ #include <assert.h> Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next, - bool early_code_change) : + bool early_code_change) : Pipeline(identifier, next), code_size(9), next(0), @@ -31,16 +31,16 @@ Pl_LZWDecoder::write(unsigned char* bytes, size_t len) { for (size_t i = 0; i < len; ++i) { - this->buf[next++] = bytes[i]; - if (this->next == 3) - { - this->next = 0; - } - this->bits_available += 8; - if (this->bits_available >= this->code_size) - { - sendNextCode(); - } + this->buf[next++] = bytes[i]; + if (this->next == 3) + { + this->next = 0; + } + this->bits_available += 8; + if (this->bits_available >= this->code_size) + { + sendNextCode(); + } } } @@ -62,8 +62,8 @@ Pl_LZWDecoder::sendNextCode() unsigned int bits_from_low = 0; if (bits_from_med > 8) { - bits_from_low = bits_from_med - 8; - bits_from_med = 8; + bits_from_low = bits_from_med - 8; + bits_from_med = 8; } unsigned int high_mask = (1U << bits_from_high) - 1U; unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U); @@ -73,21 +73,21 @@ Pl_LZWDecoder::sendNextCode() code += ((this->buf[med] & med_mask) >> (8 - bits_from_med)); if (bits_from_low) { - code <<= bits_from_low; - code += ((this->buf[low] & low_mask) >> (8 - bits_from_low)); - this->byte_pos = low; - this->bit_pos = bits_from_low; + code <<= bits_from_low; + code += ((this->buf[low] & low_mask) >> (8 - bits_from_low)); + this->byte_pos = low; + this->bit_pos = bits_from_low; } else { - this->byte_pos = med; - this->bit_pos = bits_from_med; + this->byte_pos = med; + this->bit_pos = bits_from_med; } if (this->bit_pos == 8) { - this->bit_pos = 0; - ++this->byte_pos; - this->byte_pos %= 3; + this->bit_pos = 0; + ++this->byte_pos; + this->byte_pos %= 3; } this->bits_available -= this->code_size; @@ -100,18 +100,18 @@ Pl_LZWDecoder::getFirstChar(unsigned int code) unsigned char result = '\0'; if (code < 256) { - result = static_cast<unsigned char>(code); + result = static_cast<unsigned char>(code); } else if (code > 257) { - unsigned int idx = code - 258; - if (idx >= table.size()) + unsigned int idx = code - 258; + if (idx >= table.size()) { throw std::runtime_error( "Pl_LZWDecoder::getFirstChar: table overflow"); } - Buffer& b = table.at(idx); - result = b.getBuffer()[0]; + Buffer& b = table.at(idx); + result = b.getBuffer()[0]; } else { @@ -131,21 +131,21 @@ Pl_LZWDecoder::addToTable(unsigned char next) if (this->last_code < 256) { - tmp[0] = static_cast<unsigned char>(this->last_code); - last_data = tmp; - last_size = 1; + tmp[0] = static_cast<unsigned char>(this->last_code); + last_data = tmp; + last_size = 1; } else if (this->last_code > 257) { - unsigned int idx = this->last_code - 258; - if (idx >= table.size()) + unsigned int idx = this->last_code - 258; + if (idx >= table.size()) { throw std::runtime_error( "Pl_LZWDecoder::addToTable: table overflow"); } - Buffer& b = table.at(idx); - last_data = b.getBuffer(); - last_size = QIntC::to_uint(b.getSize()); + Buffer& b = table.at(idx); + last_data = b.getBuffer(); + last_size = QIntC::to_uint(b.getSize()); } else { @@ -166,88 +166,88 @@ Pl_LZWDecoder::handleCode(unsigned int code) { if (this->eod) { - return; + return; } if (code == 256) { - if (! this->table.empty()) - { - QTC::TC("libtests", "Pl_LZWDecoder intermediate reset"); - } - this->table.clear(); - this->code_size = 9; + if (! this->table.empty()) + { + QTC::TC("libtests", "Pl_LZWDecoder intermediate reset"); + } + this->table.clear(); + this->code_size = 9; } else if (code == 257) { - this->eod = true; + this->eod = true; } else { - if (this->last_code != 256) - { - // Add to the table from last time. New table entry would - // be what we read last plus the first character of what - // we're reading now. - unsigned char next = '\0'; - unsigned int table_size = QIntC::to_uint(table.size()); - if (code < 256) - { - // just read < 256; last time's next was code - next = static_cast<unsigned char>(code); - } - else if (code > 257) - { - size_t idx = code - 258; - if (idx > table_size) - { - throw std::runtime_error("LZWDecoder: bad code received"); - } - else if (idx == table_size) - { - // The encoder would have just created this entry, - // so the first character of this entry would have - // been the same as the first character of the - // last entry. - QTC::TC("libtests", "Pl_LZWDecoder last was table size"); - next = getFirstChar(this->last_code); - } - else - { - next = getFirstChar(code); - } - } - unsigned int new_idx = 258 + table_size; - if (new_idx == 4096) - { - throw std::runtime_error("LZWDecoder: table full"); - } - addToTable(next); - unsigned int change_idx = new_idx + code_change_delta; - if ((change_idx == 511) || - (change_idx == 1023) || - (change_idx == 2047)) - { - ++this->code_size; - } - } - - if (code < 256) - { - unsigned char ch = static_cast<unsigned char>(code); - getNext()->write(&ch, 1); - } - else - { + if (this->last_code != 256) + { + // Add to the table from last time. New table entry would + // be what we read last plus the first character of what + // we're reading now. + unsigned char next = '\0'; + unsigned int table_size = QIntC::to_uint(table.size()); + if (code < 256) + { + // just read < 256; last time's next was code + next = static_cast<unsigned char>(code); + } + else if (code > 257) + { + size_t idx = code - 258; + if (idx > table_size) + { + throw std::runtime_error("LZWDecoder: bad code received"); + } + else if (idx == table_size) + { + // The encoder would have just created this entry, + // so the first character of this entry would have + // been the same as the first character of the + // last entry. + QTC::TC("libtests", "Pl_LZWDecoder last was table size"); + next = getFirstChar(this->last_code); + } + else + { + next = getFirstChar(code); + } + } + unsigned int new_idx = 258 + table_size; + if (new_idx == 4096) + { + throw std::runtime_error("LZWDecoder: table full"); + } + addToTable(next); + unsigned int change_idx = new_idx + code_change_delta; + if ((change_idx == 511) || + (change_idx == 1023) || + (change_idx == 2047)) + { + ++this->code_size; + } + } + + if (code < 256) + { + unsigned char ch = static_cast<unsigned char>(code); + getNext()->write(&ch, 1); + } + else + { unsigned int idx = code - 258; if (idx >= table.size()) { throw std::runtime_error( "Pl_LZWDecoder::handleCode: table overflow"); } - Buffer& b = table.at(idx); - getNext()->write(b.getBuffer(), b.getSize()); - } + Buffer& b = table.at(idx); + getNext()->write(b.getBuffer(), b.getSize()); + } } this->last_code = code; |