mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 21:58:22 +01:00
Implement Paeth predictor.
This commit is contained in:
parent
979ccf19ff
commit
f8f048b87a
@ -18,6 +18,7 @@
|
|||||||
// Local functions...
|
// Local functions...
|
||||||
//
|
//
|
||||||
|
|
||||||
|
static unsigned char stream_paeth(unsigned char a, unsigned char b, unsigned char c);
|
||||||
static ssize_t stream_read(pdfio_stream_t *st, char *buffer, size_t bytes);
|
static ssize_t stream_read(pdfio_stream_t *st, char *buffer, size_t bytes);
|
||||||
|
|
||||||
|
|
||||||
@ -504,6 +505,24 @@ pdfioStreamWrite(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// 'stream_paeth()' - PaethPredictor function for PNG decompression filter.
|
||||||
|
//
|
||||||
|
|
||||||
|
static unsigned char // O - Predictor value
|
||||||
|
stream_paeth(unsigned char a, // I - Left pixel
|
||||||
|
unsigned char b, // I - Top pixel
|
||||||
|
unsigned char c) // I - Top-left pixel
|
||||||
|
{
|
||||||
|
int p = a + b - c; // Initial estimate
|
||||||
|
int pa = abs(p - a); // Distance to a
|
||||||
|
int pb = abs(p - b); // Distance to b
|
||||||
|
int pc = abs(p - c); // Distance to c
|
||||||
|
|
||||||
|
return ((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'stream_read()' - Read data from a stream, including filters.
|
// 'stream_read()' - Read data from a stream, including filters.
|
||||||
//
|
//
|
||||||
@ -653,8 +672,10 @@ stream_read(pdfio_stream_t *st, // I - Stream
|
|||||||
*bufptr++ = *thisptr + (thisptr[-pbpixel] + *prevptr) / 2;
|
*bufptr++ = *thisptr + (thisptr[-pbpixel] + *prevptr) / 2;
|
||||||
break;
|
break;
|
||||||
case 4 : // Paeth
|
case 4 : // Paeth
|
||||||
// TODO: Implement Paeth predictor
|
for (; remaining > firstcol; remaining --, thisptr ++, prevptr ++)
|
||||||
memcpy(buffer, thisptr, remaining);
|
*bufptr++ = *thisptr + stream_paeth(0, *prevptr, 0);
|
||||||
|
for (; remaining > 0; remaining --, thisptr ++, prevptr ++)
|
||||||
|
*bufptr++ = *thisptr + stream_paeth(thisptr[-pbpixel], *prevptr, prevptr[-pbpixel]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
|
Loading…
Reference in New Issue
Block a user