56 bits_(bits), rowLength_(rowLength), nextBitIndex_(0) {
75 for (BitVector::const_iterator iter =
bits_.begin(); iter !=
bits_.end();
77 BitVector::const_iterator nextIter = iter;
84 }
else if (nextIter ==
bits_.end()) {
130 std::ostream& stream,
int length,
bool padEnd)
const {
133 if (lastIndex >=
bits_.size() && !padEnd) {
134 const string procName =
"AsciiImageWriter::writeSequence";
135 throw OutOfRange(__FILE__, __LINE__, procName);
138 for (
unsigned int index =
nextBitIndex_; index <= lastIndex; index++) {
139 if (index <
bits_.size()) {
140 stream <<
bits_[index];
161 std::ostream& stream,
int length,
bool padEnd)
const {
164 if (lastIndex >=
bits_.size() && !padEnd) {
166 throw OutOfRange(__FILE__, __LINE__, procName);
169 const int nibbleCount =
static_cast<int>(ceil(
170 static_cast<double>(length) / 4.0));
172 std::vector<bool> bitRow;
176 bitRow.push_back(
bits_[i]);
180 int numPadBits = 4 * nibbleCount - length;
182 std::vector<bool> padBits(numPadBits, 0);
183 bitRow.insert(bitRow.begin(), padBits.begin(), padBits.end());
187 std::vector<uint8_t> Nibble;
188 for (
auto it = bitRow.begin(); it < bitRow.end(); it += 4) {
189 Nibble.push_back(std::accumulate(
190 it, it + 4, 0,[] (
int x,
int y) {
return (x << 1) + y;}));
194 for (
auto ui8 = Nibble.begin(); ui8 < Nibble.end(); ++ui8) {
195 stream << std::hex << (int) *ui8;