image: Support rotation of monochrome JPEGs.

Extends the existing 90°-increment rotation support
(i.e. /Resized/ID?rotation=DEG) to monochrome JPEGs.

SF Patch #135 (Thanks R.L. Horn).
This commit is contained in:
Justin Maggard 2015-07-30 15:53:15 -07:00
parent f09339d95c
commit c29a9cf52b

View File

@ -526,6 +526,7 @@ image_new_from_jpeg(const char *path, int is_file, const uint8_t *buf, int size,
}
else if(cinfo.output_components == 1)
{
int rx, ry;
ofs = 0;
for(i = 0; i < cinfo.rec_outbuf_height; i++)
{
@ -543,12 +544,19 @@ image_new_from_jpeg(const char *path, int is_file, const uint8_t *buf, int size,
}
for(y = 0; y < h; y += cinfo.rec_outbuf_height)
{
ry = (rotate & (ROTATE_90|ROTATE_180)) ? (y - h + 1) * -1 : y;
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
for(i = 0; i < cinfo.rec_outbuf_height; i++)
{
for(x = 0; x < w; x++)
{
vimage->buf[ofs++] = COL(line[i][x], line[i][x], line[i][x]);
rx = (rotate & (ROTATE_180|ROTATE_270)) ?
(x - w + 1) * -1 : x;
ofs = (rotate & (ROTATE_90|ROTATE_270)) ?
ry + (rx * h) : rx + (ry * w);
if( ofs < maxbuf )
vimage->buf[ofs] =
COL(line[i][x], line[i][x], line[i][x]);
}
}
}