mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 21:58:22 +01:00
Fix remaining PNG predictors.
This commit is contained in:
parent
d30579f905
commit
3c034eb919
@ -216,6 +216,7 @@ _pdfioStreamCreate(
|
|||||||
if (predictor >= 10)
|
if (predictor >= 10)
|
||||||
st->pbsize ++; // Add PNG predictor byte
|
st->pbsize ++; // Add PNG predictor byte
|
||||||
|
|
||||||
|
fprintf(stderr, "colors=%d, bpc=%d, pbpixel=%u\n", colors, bpc, (unsigned)st->pbpixel);
|
||||||
if ((st->prbuffer = calloc(1, st->pbsize - 1)) == NULL || (st->psbuffer = calloc(1, st->pbsize)) == NULL)
|
if ((st->prbuffer = calloc(1, st->pbsize - 1)) == NULL || (st->psbuffer = calloc(1, st->pbsize)) == NULL)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Predictor buffers.", (unsigned long)st->pbsize);
|
_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Predictor buffers.", (unsigned long)st->pbsize);
|
||||||
@ -644,11 +645,11 @@ pdfioStreamWrite(
|
|||||||
// Size of pixel in bytes
|
// Size of pixel in bytes
|
||||||
pbline = st->pbsize - 1,
|
pbline = st->pbsize - 1,
|
||||||
// Bytes per line
|
// Bytes per line
|
||||||
remaining, // Remaining bytes on this line
|
remaining; // Remaining bytes on this line
|
||||||
firstcol = pbline - pbpixel;
|
const unsigned char *bufptr = (const unsigned char *)buffer,
|
||||||
// First column bytes remaining
|
|
||||||
const unsigned char *bufptr = (const unsigned char *)buffer;
|
|
||||||
// Pointer into buffer
|
// Pointer into buffer
|
||||||
|
*bufsecond = buffer + pbpixel;
|
||||||
|
// Pointer to second pixel in buffer
|
||||||
unsigned char *sptr, // Pointer into sbuffer
|
unsigned char *sptr, // Pointer into sbuffer
|
||||||
*pptr; // Previous raw buffer
|
*pptr; // Previous raw buffer
|
||||||
|
|
||||||
@ -704,7 +705,7 @@ pdfioStreamWrite(
|
|||||||
// Encode the difference from the previous column
|
// Encode the difference from the previous column
|
||||||
for (remaining = pbline; remaining > 0; remaining --, bufptr ++, sptr ++)
|
for (remaining = pbline; remaining > 0; remaining --, bufptr ++, sptr ++)
|
||||||
{
|
{
|
||||||
if (remaining < firstcol)
|
if (bufptr >= bufsecond)
|
||||||
*sptr = *bufptr - bufptr[-pbpixel];
|
*sptr = *bufptr - bufptr[-pbpixel];
|
||||||
else
|
else
|
||||||
*sptr = *bufptr;
|
*sptr = *bufptr;
|
||||||
@ -723,7 +724,7 @@ pdfioStreamWrite(
|
|||||||
// Encode the difference with the average of the previous column and line
|
// Encode the difference with the average of the previous column and line
|
||||||
for (remaining = pbline; remaining > 0; remaining --, bufptr ++, sptr ++, pptr ++)
|
for (remaining = pbline; remaining > 0; remaining --, bufptr ++, sptr ++, pptr ++)
|
||||||
{
|
{
|
||||||
if (remaining < firstcol)
|
if (bufptr >= bufsecond)
|
||||||
*sptr = *bufptr - (bufptr[-pbpixel] + *pptr) / 2;
|
*sptr = *bufptr - (bufptr[-pbpixel] + *pptr) / 2;
|
||||||
else
|
else
|
||||||
*sptr = *bufptr - *pptr / 2;
|
*sptr = *bufptr - *pptr / 2;
|
||||||
@ -735,7 +736,7 @@ pdfioStreamWrite(
|
|||||||
// Encode the difference with a linear transform function
|
// Encode the difference with a linear transform function
|
||||||
for (remaining = pbline; remaining > 0; remaining --, bufptr ++, sptr ++, pptr ++)
|
for (remaining = pbline; remaining > 0; remaining --, bufptr ++, sptr ++, pptr ++)
|
||||||
{
|
{
|
||||||
if (remaining < firstcol)
|
if (bufptr >= bufsecond)
|
||||||
*sptr = *bufptr - stream_paeth(bufptr[-pbpixel], *pptr, pptr[-pbpixel]);
|
*sptr = *bufptr - stream_paeth(bufptr[-pbpixel], *pptr, pptr[-pbpixel]);
|
||||||
else
|
else
|
||||||
*sptr = *bufptr - stream_paeth(0, *pptr, 0);
|
*sptr = *bufptr - stream_paeth(0, *pptr, 0);
|
||||||
@ -844,12 +845,12 @@ stream_read(pdfio_stream_t *st, // I - Stream
|
|||||||
// PNG predictor
|
// PNG predictor
|
||||||
size_t pbpixel = st->pbpixel,
|
size_t pbpixel = st->pbpixel,
|
||||||
// Size of pixel in bytes
|
// Size of pixel in bytes
|
||||||
remaining = st->pbsize - 1,
|
remaining = st->pbsize - 1;
|
||||||
// Remaining bytes
|
// Remaining bytes
|
||||||
firstcol = remaining - pbpixel;
|
|
||||||
// First column bytes remaining
|
|
||||||
unsigned char *bufptr = (unsigned char *)buffer,
|
unsigned char *bufptr = (unsigned char *)buffer,
|
||||||
// Pointer into buffer
|
// Pointer into buffer
|
||||||
|
*bufsecond = (unsigned char *)buffer + pbpixel,
|
||||||
|
// Pointer to second pixel in buffer
|
||||||
*sptr = st->psbuffer + 1,
|
*sptr = st->psbuffer + 1,
|
||||||
// Current (raw) line
|
// Current (raw) line
|
||||||
*pptr = st->prbuffer;
|
*pptr = st->prbuffer;
|
||||||
@ -906,7 +907,7 @@ stream_read(pdfio_stream_t *st, // I - Stream
|
|||||||
memcpy(buffer, sptr, remaining);
|
memcpy(buffer, sptr, remaining);
|
||||||
break;
|
break;
|
||||||
case 1 : // Sub
|
case 1 : // Sub
|
||||||
for (; remaining > firstcol; remaining --, sptr ++)
|
for (; bufptr < bufsecond; remaining --, sptr ++)
|
||||||
*bufptr++ = *sptr;
|
*bufptr++ = *sptr;
|
||||||
for (; remaining > 0; remaining --, sptr ++, bufptr ++)
|
for (; remaining > 0; remaining --, sptr ++, bufptr ++)
|
||||||
*bufptr = *sptr + bufptr[-pbpixel];
|
*bufptr = *sptr + bufptr[-pbpixel];
|
||||||
@ -916,13 +917,13 @@ stream_read(pdfio_stream_t *st, // I - Stream
|
|||||||
*bufptr++ = *sptr + *pptr;
|
*bufptr++ = *sptr + *pptr;
|
||||||
break;
|
break;
|
||||||
case 3 : // Average
|
case 3 : // Average
|
||||||
for (; remaining > firstcol; remaining --, sptr ++, pptr ++)
|
for (; bufptr < bufsecond; remaining --, sptr ++, pptr ++)
|
||||||
*bufptr++ = *sptr + *pptr / 2;
|
*bufptr++ = *sptr + *pptr / 2;
|
||||||
for (; remaining > 0; remaining --, sptr ++, pptr ++, bufptr ++)
|
for (; remaining > 0; remaining --, sptr ++, pptr ++, bufptr ++)
|
||||||
*bufptr = *sptr + (bufptr[-pbpixel] + *pptr) / 2;
|
*bufptr = *sptr + (bufptr[-pbpixel] + *pptr) / 2;
|
||||||
break;
|
break;
|
||||||
case 4 : // Paeth
|
case 4 : // Paeth
|
||||||
for (; remaining > firstcol; remaining --, sptr ++, pptr ++)
|
for (; bufptr < bufsecond; remaining --, sptr ++, pptr ++)
|
||||||
*bufptr++ = *sptr + stream_paeth(0, *pptr, 0);
|
*bufptr++ = *sptr + stream_paeth(0, *pptr, 0);
|
||||||
for (; remaining > 0; remaining --, sptr ++, pptr ++, bufptr ++)
|
for (; remaining > 0; remaining --, sptr ++, pptr ++, bufptr ++)
|
||||||
*bufptr = *sptr + stream_paeth(bufptr[-pbpixel], *pptr, pptr[-pbpixel]);
|
*bufptr = *sptr + stream_paeth(bufptr[-pbpixel], *pptr, pptr[-pbpixel]);
|
||||||
|
Loading…
Reference in New Issue
Block a user