Index: poppler/Stream.cc =================================================================== --- poppler/Stream.cc (revision 67) +++ poppler/Stream.cc (working copy) @@ -331,20 +331,69 @@ int i; if (nBits == 1) { - for (i = 0; i < nVals; i += 8) { - c = str->getChar(); - imgLine[i+0] = (Guchar)((c >> 7) & 1); - imgLine[i+1] = (Guchar)((c >> 6) & 1); - imgLine[i+2] = (Guchar)((c >> 5) & 1); - imgLine[i+3] = (Guchar)((c >> 4) & 1); - imgLine[i+4] = (Guchar)((c >> 3) & 1); - imgLine[i+5] = (Guchar)((c >> 2) & 1); - imgLine[i+6] = (Guchar)((c >> 1) & 1); - imgLine[i+7] = (Guchar)(c & 1); + Guchar *tmpImgLine = imgLine; + if (str->hasGetBuf()) { + int leftBytes = nVals / 8; + if (nVals % 8 > 0) + ++leftBytes; + char *buf; + int bufSize; + while (leftBytes > 0) { + /* not checking for result of getBuf for compatibility with + the non-buffered branch */ + str->getBuf(&buf, &bufSize, leftBytes); + assert(bufSize > 0); + leftBytes -= bufSize; + while (bufSize > 0) { + c = *(unsigned char*)buf; + ++buf; + bufSize--; + *tmpImgLine++ = (Guchar)((c >> 7) & 1); + *tmpImgLine++ = (Guchar)((c >> 6) & 1); + *tmpImgLine++ = (Guchar)((c >> 5) & 1); + *tmpImgLine++ = (Guchar)((c >> 4) & 1); + *tmpImgLine++ = (Guchar)((c >> 3) & 1); + *tmpImgLine++ = (Guchar)((c >> 2) & 1); + *tmpImgLine++ = (Guchar)((c >> 1) & 1); + *tmpImgLine++ = (Guchar)(c & 1); + } + } + } else { + Guchar *tmpImgLine = imgLine; + for (i = 0; i < nVals; i += 8) { + c = str->getChar(); + *tmpImgLine++ = (Guchar)((c >> 7) & 1); + *tmpImgLine++ = (Guchar)((c >> 6) & 1); + *tmpImgLine++ = (Guchar)((c >> 5) & 1); + *tmpImgLine++ = (Guchar)((c >> 4) & 1); + *tmpImgLine++ = (Guchar)((c >> 3) & 1); + *tmpImgLine++ = (Guchar)((c >> 2) & 1); + *tmpImgLine++ = (Guchar)((c >> 1) & 1); + *tmpImgLine++ = (Guchar)(c & 1); + } } } else if (nBits == 8) { - for (i = 0; i < nVals; ++i) { - imgLine[i] = str->getChar(); + if (str->hasGetBuf()) { + int left = nVals; + char *buf; + int bufSize; + Guchar *tmpImgLine = imgLine; + while (left > 0) { + /* not checking for result of getBuf for compatibility with + the non-buffered branch */ + str->getBuf(&buf, &bufSize, left); + left -= bufSize; + while (bufSize > 0) { + c = *(unsigned char*)buf; + ++buf; + bufSize--; + *tmpImgLine++ = c; + } + } + } else { + for (i = 0; i < nVals; ++i) { + imgLine[i] = str->getChar(); + } } } else { bitMask = (1 << nBits) - 1;