| 1194 | */ |
| 1195 | |
| 1196 | unsigned /* O - Number of bytes written */ |
| 1197 | _cupsRasterWritePixels( |
| 1198 | cups_raster_t *r, /* I - Raster stream */ |
| 1199 | unsigned char *p, /* I - Bytes to write */ |
| 1200 | unsigned len) /* I - Number of bytes to write */ |
| 1201 | { |
| 1202 | ssize_t bytes; /* Bytes read */ |
| 1203 | unsigned remaining; /* Bytes remaining */ |
| 1204 | |
| 1205 | |
| 1206 | DEBUG_printf(("_cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u", (void *)r, (void *)p, len, r->remaining)); |
| 1207 | |
| 1208 | if (r == NULL || r->mode == CUPS_RASTER_READ || r->remaining == 0) |
| 1209 | return (0); |
| 1210 | |
| 1211 | if (!r->compressed) |
| 1212 | { |
| 1213 | /* |
| 1214 | * Without compression, just write the raster data raw unless the data needs |
| 1215 | * to be swapped... |
| 1216 | */ |
| 1217 | |
| 1218 | r->remaining -= len / r->header.cupsBytesPerLine; |
| 1219 | |
| 1220 | if (r->swapped && |
| 1221 | (r->header.cupsBitsPerColor == 16 || |
| 1222 | r->header.cupsBitsPerPixel == 12 || |
| 1223 | r->header.cupsBitsPerPixel == 16)) |
| 1224 | { |
| 1225 | unsigned char *bufptr; /* Pointer into write buffer */ |
| 1226 | |
| 1227 | /* |
| 1228 | * Allocate a write buffer as needed... |
| 1229 | */ |
| 1230 | |
| 1231 | if ((size_t)len > r->bufsize) |
| 1232 | { |
| 1233 | if (r->buffer) |
| 1234 | bufptr = realloc(r->buffer, len); |
| 1235 | else |
| 1236 | bufptr = malloc(len); |
| 1237 | |
| 1238 | if (!bufptr) |
| 1239 | return (0); |
| 1240 | |
| 1241 | r->buffer = bufptr; |
| 1242 | r->bufsize = len; |
| 1243 | } |
| 1244 | |
| 1245 | /* |
| 1246 | * Byte swap the pixels and write them... |
| 1247 | */ |
| 1248 | |
| 1249 | cups_swap_copy(r->buffer, p, len); |
| 1250 | |
| 1251 | bytes = cups_raster_io(r, r->buffer, len); |
| 1252 | } |
| 1253 | else |
no test coverage detected