Don't call jpeg_finish_compress() with YUV output, because it tries to insert an EOI marker right in the middle of our image data.


git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.1.x@475 632fc199-4ca6-4c93-a231-07263d6284db
diff --git a/turbojpegl.c b/turbojpegl.c
index 8e3f2b0..5cc5437 100644
--- a/turbojpegl.c
+++ b/turbojpegl.c
@@ -300,6 +300,7 @@
 		}
 		*size=yuvsize;
 		cinfo->next_scanline+=height;
+		jpeg_abort_compress(&j->cinfo);
 	}
 	else
 	{
@@ -315,11 +316,10 @@
 			jpeg_write_scanlines(&j->cinfo, &row_pointer[j->cinfo.next_scanline],
 				j->cinfo.image_height-j->cinfo.next_scanline);
 		}
-	}
-	jpeg_finish_compress(&j->cinfo);
-	if(!(flags&TJ_YUV))
+		jpeg_finish_compress(&j->cinfo);
 		*size=TJBUFSIZE(j->cinfo.image_width, j->cinfo.image_height)
 			-(unsigned long)(j->jdms.free_in_buffer);
+	}
 
 	bailout:
 	if(j->cinfo.global_state>CSTATE_START) jpeg_abort_compress(&j->cinfo);