Passing manual lines jpeg_write_scanlines

I am having some weird problems using libjpeg-turbo, in particular I have an rgba buffer 1920x1080 which I read through mmap (so it is read-only) which I am trying to encode as jpeg, d only to encode the top left corner. let's say 320x568 pixels (and some other sizes). There's some overhead associated with memcpying those pixels that I'm trying to avoid, so I'm trying to set the width and height in the cinfo to 320x568 and then manually pass jpeg_write_scanlines only the lines that match.

Here is an image showing what I mean: http://i.imgur.com/lKwkjZS.png

I hope it occupies the first 320 pixels of each of the 568 lines that I pass from the 1920x1080 buffer.

JSAMPROW row_pointer[1];
int row_stride = 1920 * bpp;
while (cinfo.next_scanline < cinfo.image_height) {
    row_pointer[0] = &in[cinfo.next_scanline * row_stride];
    jpeg_write_scanlines(&cinfo, row_pointer, 1);
}

      

So, I set up jpeg compress to be 320x568 and pass it a 1920x1080 buffer and then tell it to skip the 1920x4bpp pointer on each line.

Only half works, I get an image that looks correct for the first ~ 94 lines or so, and then the rest is garbage. Does anyone know why this is not working?

+3


source to share





All Articles