Don't require buffer size to be preset if using TJFLAG_NOREALLOC
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@626 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
@@ -81,7 +81,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -786,7 +786,7 @@ Variables</h2></td></tr>
|
|||||||
<li>set <code>*jpegBuf</code> to NULL to tell TurboJPEG to allocate the buffer for you, or</li>
|
<li>set <code>*jpegBuf</code> to NULL to tell TurboJPEG to allocate the buffer for you, or</li>
|
||||||
<li>pre-allocate the buffer to a "worst case" size determined by calling <a class="el" href="group___turbo_j_p_e_g.html#ga68f4761dc5213cb9653a2f6ce236716e" title="The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters...">TJBUFSIZE()</a>. This should ensure that the buffer never has to be re-allocated (setting <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a> guarantees this.)</li>
|
<li>pre-allocate the buffer to a "worst case" size determined by calling <a class="el" href="group___turbo_j_p_e_g.html#ga68f4761dc5213cb9653a2f6ce236716e" title="The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters...">TJBUFSIZE()</a>. This should ensure that the buffer never has to be re-allocated (setting <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a> guarantees this.)</li>
|
||||||
</ol>
|
</ol>
|
||||||
If you choose option 1 or 3, <code>*jpegSize</code> should be set to the size of your pre-allocated buffer. In any case, unless you have set <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a>, you should always check <code>*jpegBuf</code> upon return from this function, as it may have changed. </td></tr>
|
If you choose option 1, <code>*jpegSize</code> should be set to the size of your pre-allocated buffer. In any case, unless you have set <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a>, you should always check <code>*jpegBuf</code> upon return from this function, as it may have changed. </td></tr>
|
||||||
<tr><td class="paramname">jpegSize</td><td>pointer to an unsigned long variable which holds the size of the JPEG image buffer. If <code>*jpegBuf</code> points to a pre-allocated buffer, then <code>*jpegSize</code> should be set to the size of the buffer. Upon return, <code>*jpegSize</code> will contain the size of the JPEG image (in bytes.) </td></tr>
|
<tr><td class="paramname">jpegSize</td><td>pointer to an unsigned long variable which holds the size of the JPEG image buffer. If <code>*jpegBuf</code> points to a pre-allocated buffer, then <code>*jpegSize</code> should be set to the size of the buffer. Upon return, <code>*jpegSize</code> will contain the size of the JPEG image (in bytes.) </td></tr>
|
||||||
<tr><td class="paramname">jpegSubsamp</td><td>the level of chrominance subsampling to be used when generating the JPEG image (see <a class="el" href="group___turbo_j_p_e_g.html#ga1d047060ea80bb9820d540bb928e9074">Chrominance subsampling options</a>.) </td></tr>
|
<tr><td class="paramname">jpegSubsamp</td><td>the level of chrominance subsampling to be used when generating the JPEG image (see <a class="el" href="group___turbo_j_p_e_g.html#ga1d047060ea80bb9820d540bb928e9074">Chrominance subsampling options</a>.) </td></tr>
|
||||||
<tr><td class="paramname">jpegQual</td><td>the image quality of the generated JPEG image (1 = worst, 100 = best) </td></tr>
|
<tr><td class="paramname">jpegQual</td><td>the image quality of the generated JPEG image (1 = worst, 100 = best) </td></tr>
|
||||||
@@ -1301,7 +1301,7 @@ If you choose option 1 or 3, <code>*jpegSize</code> should be set to the size of
|
|||||||
<li>set <code>dstBufs[i]</code> to NULL to tell TurboJPEG to allocate the buffer for you, or</li>
|
<li>set <code>dstBufs[i]</code> to NULL to tell TurboJPEG to allocate the buffer for you, or</li>
|
||||||
<li>pre-allocate the buffer to a "worst case" size determined by calling <a class="el" href="group___turbo_j_p_e_g.html#ga68f4761dc5213cb9653a2f6ce236716e" title="The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters...">TJBUFSIZE()</a> with the cropped width and height. This should ensure that the buffer never has to be re-allocated (setting <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a> guarantees this.)</li>
|
<li>pre-allocate the buffer to a "worst case" size determined by calling <a class="el" href="group___turbo_j_p_e_g.html#ga68f4761dc5213cb9653a2f6ce236716e" title="The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters...">TJBUFSIZE()</a> with the cropped width and height. This should ensure that the buffer never has to be re-allocated (setting <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a> guarantees this.)</li>
|
||||||
</ol>
|
</ol>
|
||||||
If you choose option 1 or 3, <code>dstSizes[i]</code> should be set to the size of your pre-allocated buffer. In any case, unless you have set <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a>, you should always check <code>dstBufs[i]</code> upon return from this function, as it may have changed. </td></tr>
|
If you choose option 1, <code>dstSizes[i]</code> should be set to the size of your pre-allocated buffer. In any case, unless you have set <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a>, you should always check <code>dstBufs[i]</code> upon return from this function, as it may have changed. </td></tr>
|
||||||
<tr><td class="paramname">dstSizes</td><td>pointer to an array of n unsigned long variables which will receive the actual sizes (in bytes) of each transformed JPEG image. If <code>dstBufs[i]</code> points to a pre-allocated buffer, then <code>dstSizes[i]</code> should be set to the size of the buffer. Upon return, <code>dstSizes[i]</code> will contain the size of the JPEG image (in bytes.) </td></tr>
|
<tr><td class="paramname">dstSizes</td><td>pointer to an array of n unsigned long variables which will receive the actual sizes (in bytes) of each transformed JPEG image. If <code>dstBufs[i]</code> points to a pre-allocated buffer, then <code>dstSizes[i]</code> should be set to the size of the buffer. Upon return, <code>dstSizes[i]</code> will contain the size of the JPEG image (in bytes.) </td></tr>
|
||||||
<tr><td class="paramname">transforms</td><td>pointer to an array of n tjtransform structures, each of which specifies the transform parameters and/or cropping region for the corresponding transformed output image. </td></tr>
|
<tr><td class="paramname">transforms</td><td>pointer to an array of n tjtransform structures, each of which specifies the transform parameters and/or cropping region for the corresponding transformed output image. </td></tr>
|
||||||
<tr><td class="paramname">flags</td><td>the bitwise OR of one or more of the <a class="el" href="group___turbo_j_p_e_g.html#ga72ecf4ebe6eb702d3c6f5ca27455e1ec">flags</a>.</td></tr>
|
<tr><td class="paramname">flags</td><td>the bitwise OR of one or more of the <a class="el" href="group___turbo_j_p_e_g.html#ga72ecf4ebe6eb702d3c6f5ca27455e1ec">flags</a>.</td></tr>
|
||||||
@@ -1435,7 +1435,7 @@ If you choose option 1 or 3, <code>dstSizes[i]</code> should be set to the size
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ Data Fields</h2></td></tr>
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ Data Fields</h2></td></tr>
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ Data Fields</h2></td></tr>
|
|||||||
</iframe>
|
</iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by 
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by 
|
||||||
<a href="http://www.doxygen.org/index.html">
|
<a href="http://www.doxygen.org/index.html">
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
|
|||||||
* calling #TJBUFSIZE(). This should ensure that the buffer never has
|
* calling #TJBUFSIZE(). This should ensure that the buffer never has
|
||||||
* to be re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
|
* to be re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
|
||||||
* .
|
* .
|
||||||
* If you choose option 1 or 3, <tt>*jpegSize</tt> should be set to the
|
* If you choose option 1, <tt>*jpegSize</tt> should be set to the
|
||||||
* size of your pre-allocated buffer. In any case, unless you have
|
* size of your pre-allocated buffer. In any case, unless you have
|
||||||
* set #TJFLAG_NOREALLOC, you should always check <tt>*jpegBuf</tt> upon
|
* set #TJFLAG_NOREALLOC, you should always check <tt>*jpegBuf</tt> upon
|
||||||
* return from this function, as it may have changed.
|
* return from this function, as it may have changed.
|
||||||
@@ -692,7 +692,7 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void);
|
|||||||
* ensure that the buffer never has to be re-allocated (setting
|
* ensure that the buffer never has to be re-allocated (setting
|
||||||
* #TJFLAG_NOREALLOC guarantees this.)
|
* #TJFLAG_NOREALLOC guarantees this.)
|
||||||
* .
|
* .
|
||||||
* If you choose option 1 or 3, <tt>dstSizes[i]</tt> should be set to
|
* If you choose option 1, <tt>dstSizes[i]</tt> should be set to
|
||||||
* the size of your pre-allocated buffer. In any case, unless you have
|
* the size of your pre-allocated buffer. In any case, unless you have
|
||||||
* set #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt>
|
* set #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt>
|
||||||
* upon return from this function, as it may have changed.
|
* upon return from this function, as it may have changed.
|
||||||
|
|||||||
18
turbojpegl.c
18
turbojpegl.c
@@ -312,7 +312,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf,
|
|||||||
int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
|
int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
|
||||||
unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags)
|
unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags)
|
||||||
{
|
{
|
||||||
int i, retval=0; JSAMPROW *row_pointer=NULL;
|
int i, retval=0, alloc=1; JSAMPROW *row_pointer=NULL;
|
||||||
|
|
||||||
getinstance(handle)
|
getinstance(handle)
|
||||||
if((this->init&COMPRESS)==0)
|
if((this->init&COMPRESS)==0)
|
||||||
@@ -339,7 +339,11 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf,
|
|||||||
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
|
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
|
||||||
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
|
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
|
||||||
|
|
||||||
jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, (flags&TJFLAG_NOREALLOC)==0);
|
if(flags&TJFLAG_NOREALLOC)
|
||||||
|
{
|
||||||
|
alloc=0; *jpegSize=TJBUFSIZE(width, height);
|
||||||
|
}
|
||||||
|
jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
|
||||||
setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual);
|
setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual);
|
||||||
|
|
||||||
jpeg_start_compress(cinfo, TRUE);
|
jpeg_start_compress(cinfo, TRUE);
|
||||||
@@ -376,7 +380,6 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
size=TJBUFSIZE(width, height);
|
|
||||||
retval=tjCompress2(handle, srcBuf, width, pitch, height,
|
retval=tjCompress2(handle, srcBuf, width, pitch, height,
|
||||||
getPixelFormat(pixelSize, flags), &jpegBuf, &size, jpegSubsamp, jpegQual,
|
getPixelFormat(pixelSize, flags), &jpegBuf, &size, jpegSubsamp, jpegQual,
|
||||||
flags|TJFLAG_NOREALLOC);
|
flags|TJFLAG_NOREALLOC);
|
||||||
@@ -953,9 +956,7 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf,
|
|||||||
|
|
||||||
for(i=0; i<n; i++)
|
for(i=0; i<n; i++)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h, alloc=1;
|
||||||
jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i],
|
|
||||||
(flags&TJFLAG_NOREALLOC)==0);
|
|
||||||
if(!xinfo[i].crop)
|
if(!xinfo[i].crop)
|
||||||
{
|
{
|
||||||
w=dinfo->image_width; h=dinfo->image_height;
|
w=dinfo->image_width; h=dinfo->image_height;
|
||||||
@@ -964,6 +965,11 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf,
|
|||||||
{
|
{
|
||||||
w=xinfo[i].crop_width; h=xinfo[i].crop_height;
|
w=xinfo[i].crop_width; h=xinfo[i].crop_height;
|
||||||
}
|
}
|
||||||
|
if(flags&TJFLAG_NOREALLOC)
|
||||||
|
{
|
||||||
|
alloc=0; dstSizes[i]=TJBUFSIZE(w, h);
|
||||||
|
}
|
||||||
|
jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc);
|
||||||
jpeg_copy_critical_parameters(dinfo, cinfo);
|
jpeg_copy_critical_parameters(dinfo, cinfo);
|
||||||
dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs,
|
dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs,
|
||||||
&xinfo[i]);
|
&xinfo[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user