Fix an issue that prevented tjEncodeYUV2() and TJCompressor.encodeYUV() from working properly if the source image was very tiny. Basically, jpeg_start_compress() was attempting to write the JPEG headers, which was overrunning the YUV buffer. This patch removes the call to jpeg_start_compress() in tjEncodeYUV2() and replaces it with calls to the individual routines that are necessary to initialize the color converter and downsampler. TJUnitTest has also been modified to test for this condition (the buffer size regression test now works in YUV mode.)

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.3.x@1120 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2014-02-11 09:56:12 +00:00
parent 994b9819ac
commit 2a10cbaa27
5 changed files with 77 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2009-2012 D. R. Commander. All Rights Reserved.
* Copyright (C)2009-2012, 2014 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -731,7 +731,20 @@ DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf,
jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0);
if(setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags)==-1) return -1;
jpeg_start_compress(cinfo, TRUE);
/* Execute only the parts of jpeg_start_compress() that we need. If we
were to call the whole jpeg_start_compress() function, then it would try
to write the file headers, which could overflow the output buffer if the
YUV image were very small. */
if(cinfo->global_state!=CSTATE_START)
_throw("tjEncodeYUV3(): libjpeg API is in the wrong state");
(*cinfo->err->reset_error_mgr)((j_common_ptr)cinfo);
(*cinfo->dest->init_destination)(cinfo);
jinit_c_master_control(cinfo, FALSE);
jinit_color_converter(cinfo);
jinit_downsampler(cinfo);
jinit_c_prep_controller(cinfo, FALSE);
(*cinfo->mem->realize_virt_arrays)((j_common_ptr)cinfo);
pw=PAD(width, cinfo->max_h_samp_factor);
ph=PAD(height, cinfo->max_v_samp_factor);