MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cups_raster_write

Function cups_raster_write

cups/raster-stream.c:1769–1894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1767 */
1768
1769static ssize_t /* O - Number of bytes written */
1770cups_raster_write(
1771 cups_raster_t *r, /* I - Raster stream */
1772 const unsigned char *pixels) /* I - Pixel data to write */
1773{
1774 const unsigned char *start, /* Start of sequence */
1775 *ptr, /* Current pointer in sequence */
1776 *pend, /* End of raster buffer */
1777 *plast; /* Pointer to last pixel */
1778 unsigned char *wptr; /* Pointer into write buffer */
1779 unsigned bpp, /* Bytes per pixel */
1780 count; /* Count */
1781 _cups_copyfunc_t cf; /* Copy function */
1782
1783
1784 DEBUG_printf(("3cups_raster_write(r=%p, pixels=%p)", (void *)r, (void *)pixels));
1785
1786 /*
1787 * Determine whether we need to swap bytes...
1788 */
1789
1790 if (r->swapped && (r->header.cupsBitsPerColor == 16 || r->header.cupsBitsPerPixel == 12 || r->header.cupsBitsPerPixel == 16))
1791 {
1792 DEBUG_puts("4cups_raster_write: Swapping bytes when writing.");
1793 cf = (_cups_copyfunc_t)cups_swap_copy;
1794 }
1795 else
1796 cf = (_cups_copyfunc_t)memcpy;
1797
1798 /*
1799 * Allocate a write buffer as needed...
1800 */
1801
1802 count = r->header.cupsBytesPerLine * 2;
1803 if (count < 65536)
1804 count = 65536;
1805
1806 if ((size_t)count > r->bufsize)
1807 {
1808 if (r->buffer)
1809 wptr = realloc(r->buffer, count);
1810 else
1811 wptr = malloc(count);
1812
1813 if (!wptr)
1814 {
1815 DEBUG_printf(("4cups_raster_write: Unable to allocate " CUPS_LLFMT " bytes for raster buffer: %s", CUPS_LLCAST count, strerror(errno)));
1816 return (-1);
1817 }
1818
1819 r->buffer = wptr;
1820 r->bufsize = count;
1821 }
1822
1823 /*
1824 * Write the row repeat count...
1825 */
1826

Callers 1

_cupsRasterWritePixelsFunction · 0.85

Calls 1

cups_raster_ioFunction · 0.85

Tested by

no test coverage detected