compress(&cinfo, (uint8_t*) inYuv, offsets);
jpeg_finish_compress(&cinfo);
+ jpeg_destroy_compress(&cinfo);
return true;
}
planes[1] = cb;
planes[2] = cr;
- int width = cinfo->image_width;
- int height = cinfo->image_height;
+ JDIMENSION width = cinfo->image_width;
+ JDIMENSION height = cinfo->image_height;
uint8_t* yPlanar = yuv + offsets[0];
uint8_t* vuPlanar = yuv + offsets[1]; //width * height;
- uint8_t* uRows = new uint8_t [8 * (width >> 1)];
- uint8_t* vRows = new uint8_t [8 * (width >> 1)];
-
+ uint8_t* uRows = new uint8_t [8 * (((width + 15) & ~15) >> 1)];
+ uint8_t* vRows = new uint8_t [8 * (((width + 15) & ~15) >> 1)];
+ uint8_t* yRows;
+ int lastLines;
+
+ if ((height & 0xf) != 0) {
+ lastLines = height & 0xf;
+ yRows = new uint8_t [16 * ((width + 15) & ~15)];
+ }
// process 16 lines of Y and 8 lines of U/V each time.
while (cinfo->next_scanline < cinfo->image_height) {
// Jpeg library ignores the rows whose indices are greater than height.
for (int i = 0; i < 16; i++) {
- // y row
- y[i] = yPlanar + (cinfo->next_scanline + i) * fStrides[0];
+ // y row. Add padding if height isn't aligned to 16 pixels.
+ if ((height & 0xf) != 0 && (cinfo->next_scanline + i) > height)
+ y[i] = &yRows[(i - lastLines) * ((width + 15) & ~15)];
+ else
+ y[i] = yPlanar + (cinfo->next_scanline + i) * fStrides[0];
// construct u row and v row
if ((i & 1) == 0) {
}
jpeg_write_raw_data(cinfo, planes, 16);
}
+ if ((height & 0xf) != 0)
+ delete [] yRows;
delete [] uRows;
delete [] vRows;
void Yuv420SpToJpegEncoder::deinterleave(uint8_t* vuPlanar, uint8_t* uRows,
uint8_t* vRows, int rowIndex, int width, int height) {
- int numRows = (height - rowIndex) / 2;
- if (numRows > 8) numRows = 8;
- for (int row = 0; row < numRows; ++row) {
+ int lines = 16;
+ //In case there isn't enough lines to process
+ if ((rowIndex + lines) > height)
+ lines = (height - rowIndex);
+
+ for (int row = 0; row < (lines >> 1); ++row) {
int offset = ((rowIndex >> 1) + row) * fStrides[1];
uint8_t* vu = vuPlanar + offset;
for (int i = 0; i < (width >> 1); ++i) {