aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/html/annotated.html2
-rw-r--r--doc/html/classes.html2
-rw-r--r--doc/html/functions.html2
-rw-r--r--doc/html/functions_vars.html2
-rw-r--r--doc/html/group___turbo_j_p_e_g.html63
-rw-r--r--doc/html/index.html2
-rw-r--r--doc/html/modules.html2
-rw-r--r--doc/html/structtjregion.html2
-rw-r--r--doc/html/structtjscalingfactor.html2
-rw-r--r--doc/html/structtjtransform.html2
-rw-r--r--jpegut.c12
-rwxr-xr-xturbojpeg-mapfile2
-rwxr-xr-xturbojpeg-mapfile.jni2
-rw-r--r--turbojpeg.h33
-rw-r--r--turbojpegl.c17
15 files changed, 125 insertions, 22 deletions
diff --git a/doc/html/annotated.html b/doc/html/annotated.html
index 09db2cb4..7206554f 100644
--- a/doc/html/annotated.html
+++ b/doc/html/annotated.html
@@ -81,7 +81,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/classes.html b/doc/html/classes.html
index d9b8c9ab..10afb969 100644
--- a/doc/html/classes.html
+++ b/doc/html/classes.html
@@ -80,7 +80,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/functions.html b/doc/html/functions.html
index edf3963d..ae7d0720 100644
--- a/doc/html/functions.html
+++ b/doc/html/functions.html
@@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/functions_vars.html b/doc/html/functions_vars.html
index a10da770..8dabf4c5 100644
--- a/doc/html/functions_vars.html
+++ b/doc/html/functions_vars.html
@@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/group___turbo_j_p_e_g.html b/doc/html/group___turbo_j_p_e_g.html
index 2540b94a..3dadaf12 100644
--- a/doc/html/group___turbo_j_p_e_g.html
+++ b/doc/html/group___turbo_j_p_e_g.html
@@ -176,6 +176,10 @@ Functions</h2></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Losslessly transform a JPEG image into another JPEG image. <a href="#gae403193ceb4aafb7e0f56ab587b48616"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">DLLEXPORT int DLLCALL&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga674adee917b95ad4a896f1ba39e12540">tjDestroy</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Destroy a TurboJPEG compressor, decompressor, or transformer instance. <a href="#ga674adee917b95ad4a896f1ba39e12540"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">DLLEXPORT unsigned char *DLLCALL&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff">tjAlloc</a> (int bytes)</td></tr>
+<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate an image buffer for use with TurboJPEG. <a href="#ga5c9234bda6d993cdaffdd89bf81a00ff"></a><br/></td></tr>
+<tr><td class="memItemLeft" align="right" valign="top">DLLEXPORT void DLLCALL&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga8c4a1231dc06a450514c835f6471f137">tjFree</a> (unsigned char *buffer)</td></tr>
+<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Free an image buffer previously allocated by TurboJPEG. <a href="#ga8c4a1231dc06a450514c835f6471f137"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">DLLEXPORT char *DLLCALL&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga9af79c908ec131b1ae8d52fe40375abf">tjGetErrorStr</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a descriptive error message explaining why the last command failed. <a href="#ga9af79c908ec131b1ae8d52fe40375abf"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="var-members"></a>
@@ -612,6 +616,33 @@ Variables</h2></td></tr>
</div>
</div>
<hr/><h2>Function Documentation</h2>
+<a class="anchor" id="ga5c9234bda6d993cdaffdd89bf81a00ff"></a><!-- doxytag: member="turbojpeg.h::tjAlloc" ref="ga5c9234bda6d993cdaffdd89bf81a00ff" args="(int bytes)" -->
+<div class="memitem">
+<div class="memproto">
+ <table class="memname">
+ <tr>
+ <td class="memname">DLLEXPORT unsigned char* DLLCALL tjAlloc </td>
+ <td>(</td>
+ <td class="paramtype">int&#160;</td>
+ <td class="paramname"><em>bytes</em></td><td>)</td>
+ <td></td>
+ </tr>
+ </table>
+</div>
+<div class="memdoc">
+
+<p>Allocate an image buffer for use with TurboJPEG. </p>
+<p>You should always use this function to allocate the JPEG destination buffer(s) for <a class="el" href="group___turbo_j_p_e_g.html#gaba62b7a98f960839b588579898495cf2" title="Compress an RGB or grayscale image into a JPEG image.">tjCompress2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#gae403193ceb4aafb7e0f56ab587b48616" title="Losslessly transform a JPEG image into another JPEG image.">tjTransform()</a> unless you are disabling automatic buffer (re)allocation (by setting <a class="el" href="group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963" title="Disable buffer (re)allocation.">TJFLAG_NOREALLOC</a>.)</p>
+<dl><dt><b>Parameters:</b></dt><dd>
+ <table class="params">
+ <tr><td class="paramname">bytes</td><td>the number of bytes to allocate</td></tr>
+ </table>
+ </dd>
+</dl>
+<dl class="return"><dt><b>Returns:</b></dt><dd>a pointer to a newly-allocated buffer with the specified number of bytes </dd></dl>
+
+</div>
+</div>
<a class="anchor" id="ga68f4761dc5213cb9653a2f6ce236716e"></a><!-- doxytag: member="turbojpeg.h::TJBUFSIZE" ref="ga68f4761dc5213cb9653a2f6ce236716e" args="(int width, int height)" -->
<div class="memitem">
<div class="memproto">
@@ -782,7 +813,7 @@ Variables</h2></td></tr>
<tr><td class="paramname">height</td><td>height (in pixels) of the source image </td></tr>
<tr><td class="paramname">pixelFormat</td><td>pixel format of the source image (see <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">Pixel formats</a>.) </td></tr>
<tr><td class="paramname">jpegBuf</td><td>address of a pointer to an image buffer that will receive the JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to accommodate the size of the JPEG image. Thus, you can choose to:<ol type="1">
-<li>pre-allocate the JPEG buffer with an arbitrary size and let TurboJPEG grow the buffer as needed,</li>
+<li>pre-allocate the JPEG buffer with an arbitrary size using <a class="el" href="group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff" title="Allocate an image buffer for use with TurboJPEG.">tjAlloc()</a> and let TurboJPEG grow the buffer as needed,</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>
</ol>
@@ -1121,6 +1152,32 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
</div>
</div>
+<a class="anchor" id="ga8c4a1231dc06a450514c835f6471f137"></a><!-- doxytag: member="turbojpeg.h::tjFree" ref="ga8c4a1231dc06a450514c835f6471f137" args="(unsigned char *buffer)" -->
+<div class="memitem">
+<div class="memproto">
+ <table class="memname">
+ <tr>
+ <td class="memname">DLLEXPORT void DLLCALL tjFree </td>
+ <td>(</td>
+ <td class="paramtype">unsigned char *&#160;</td>
+ <td class="paramname"><em>buffer</em></td><td>)</td>
+ <td></td>
+ </tr>
+ </table>
+</div>
+<div class="memdoc">
+
+<p>Free an image buffer previously allocated by TurboJPEG. </p>
+<p>You should always use this function to free JPEG destination buffer(s) that were automatically (re)allocated by <a class="el" href="group___turbo_j_p_e_g.html#gaba62b7a98f960839b588579898495cf2" title="Compress an RGB or grayscale image into a JPEG image.">tjCompress2()</a> or <a class="el" href="group___turbo_j_p_e_g.html#gae403193ceb4aafb7e0f56ab587b48616" title="Losslessly transform a JPEG image into another JPEG image.">tjTransform()</a> or that were manually allocated using <a class="el" href="group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff" title="Allocate an image buffer for use with TurboJPEG.">tjAlloc()</a>.</p>
+<dl><dt><b>Parameters:</b></dt><dd>
+ <table class="params">
+ <tr><td class="paramname">buffer</td><td>address of the buffer to free </td></tr>
+ </table>
+ </dd>
+</dl>
+
+</div>
+</div>
<a class="anchor" id="ga9af79c908ec131b1ae8d52fe40375abf"></a><!-- doxytag: member="turbojpeg.h::tjGetErrorStr" ref="ga9af79c908ec131b1ae8d52fe40375abf" args="(void)" -->
<div class="memitem">
<div class="memproto">
@@ -1297,7 +1354,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
<tr><td class="paramname">jpegSize</td><td>size of the JPEG image (in bytes) </td></tr>
<tr><td class="paramname">n</td><td>the number of transformed JPEG images to generate </td></tr>
<tr><td class="paramname">dstBufs</td><td>pointer to an array of n image buffers. <code>dstBufs[i]</code> will receive a JPEG image that has been transformed using the parameters in <code>transforms[i]</code>. TurboJPEG has the ability to reallocate the JPEG buffer to accommodate the size of the JPEG image. Thus, you can choose to:<ol type="1">
-<li>pre-allocate the JPEG buffer with an arbitrary size and let TurboJPEG grow the buffer as needed,</li>
+<li>pre-allocate the JPEG buffer with an arbitrary size using <a class="el" href="group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff" title="Allocate an image buffer for use with TurboJPEG.">tjAlloc()</a> and let TurboJPEG grow the buffer as needed,</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>
</ol>
@@ -1435,7 +1492,7 @@ If you choose option 1, <code>dstSizes[i]</code> should be set to the size of yo
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/index.html b/doc/html/index.html
index 8969bb04..b6f40e80 100644
--- a/doc/html/index.html
+++ b/doc/html/index.html
@@ -69,7 +69,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/modules.html b/doc/html/modules.html
index 9328d404..00855f00 100644
--- a/doc/html/modules.html
+++ b/doc/html/modules.html
@@ -72,7 +72,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/structtjregion.html b/doc/html/structtjregion.html
index 8a23e46b..72186781 100644
--- a/doc/html/structtjregion.html
+++ b/doc/html/structtjregion.html
@@ -165,7 +165,7 @@ Data Fields</h2></td></tr>
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/structtjscalingfactor.html b/doc/html/structtjscalingfactor.html
index ad7858c7..2f8892a8 100644
--- a/doc/html/structtjscalingfactor.html
+++ b/doc/html/structtjscalingfactor.html
@@ -127,7 +127,7 @@ Data Fields</h2></td></tr>
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/doc/html/structtjtransform.html b/doc/html/structtjtransform.html
index 52524b22..86b23f7c 100644
--- a/doc/html/structtjtransform.html
+++ b/doc/html/structtjtransform.html
@@ -144,7 +144,7 @@ Data Fields</h2></td></tr>
</iframe>
</div>
-<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 11:42:39 for TurboJPEG by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
diff --git a/jpegut.c b/jpegut.c
index d1dbbe84..115d0cb1 100644
--- a/jpegut.c
+++ b/jpegut.c
@@ -500,7 +500,7 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp,
if(!alloc)
{
size=(yuv==YUVENCODE? TJBUFSIZEYUV(w, h, subsamp):TJBUFSIZE(w, h));
- if((dstBuf=(unsigned char *)malloc(size))==NULL)
+ if((dstBuf=(unsigned char *)tjAlloc(size))==NULL)
_throw("Memory allocation failure.");
}
@@ -529,7 +529,7 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp,
if(chandle) tjDestroy(chandle);
if(dhandle) tjDestroy(dhandle);
- if(dstBuf) free(dstBuf);
+ if(dstBuf) tjFree(dstBuf);
}
@@ -553,7 +553,7 @@ void doTest1(void)
_throw("Memory allocation failure");
if(!alloc)
{
- if((jpegBuf=(unsigned char *)malloc(TJBUFSIZE(w, h)))==NULL)
+ if((jpegBuf=(unsigned char *)tjAlloc(TJBUFSIZE(w, h)))==NULL)
_throw("Memory allocation failure");
jpegSize=TJBUFSIZE(w, h);
}
@@ -564,13 +564,13 @@ void doTest1(void)
_tj(tjCompress2(handle, srcBuf, w, 0, h, TJPF_BGRX, &jpegBuf, &jpegSize,
TJSAMP_444, 100, alloc? 0:TJFLAG_NOREALLOC));
free(srcBuf); srcBuf=NULL;
- free(jpegBuf); jpegBuf=NULL;
+ tjFree(jpegBuf); jpegBuf=NULL;
if((srcBuf=(unsigned char *)malloc(h*w*4))==NULL)
_throw("Memory allocation failure");
if(!alloc)
{
- if((jpegBuf=(unsigned char *)malloc(TJBUFSIZE(h, w)))==NULL)
+ if((jpegBuf=(unsigned char *)tjAlloc(TJBUFSIZE(h, w)))==NULL)
_throw("Memory allocation failure");
jpegSize=TJBUFSIZE(h, w);
}
@@ -583,7 +583,7 @@ void doTest1(void)
_tj(tjCompress2(handle, srcBuf, h, 0, w, TJPF_BGRX, &jpegBuf, &jpegSize,
TJSAMP_444, 100, alloc? 0:TJFLAG_NOREALLOC));
free(srcBuf); srcBuf=NULL;
- free(jpegBuf); jpegBuf=NULL;
+ tjFree(jpegBuf); jpegBuf=NULL;
}
}
printf("Done. \n");
diff --git a/turbojpeg-mapfile b/turbojpeg-mapfile
index fbe2cc68..0e704ec0 100755
--- a/turbojpeg-mapfile
+++ b/turbojpeg-mapfile
@@ -25,9 +25,11 @@ TURBOJPEG_1.1
TURBOJPEG_1.2
{
global:
+ tjAlloc;
tjCompress2;
tjDecompress2;
tjEncodeYUV2;
+ tjFree;
tjGetScalingFactors;
tjInitTransform;
tjTransform;
diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni
index 5b322cbe..1465ad20 100755
--- a/turbojpeg-mapfile.jni
+++ b/turbojpeg-mapfile.jni
@@ -25,9 +25,11 @@ TURBOJPEG_1.1
TURBOJPEG_1.2
{
global:
+ tjAlloc;
tjCompress2;
tjDecompress2;
tjEncodeYUV2;
+ tjFree;
tjGetScalingFactors;
tjInitTransform;
tjTransform;
diff --git a/turbojpeg.h b/turbojpeg.h
index 17bc306e..f6855479 100644
--- a/turbojpeg.h
+++ b/turbojpeg.h
@@ -432,8 +432,8 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
* @param jpegBuf address of a pointer to an image buffer that will receive the
* JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer
* to accommodate the size of the JPEG image. Thus, you can choose to:
- * -# pre-allocate the JPEG buffer with an arbitrary size and let
- * TurboJPEG grow the buffer as needed,
+ * -# pre-allocate the JPEG buffer with an arbitrary size using
+ * #tjAlloc() and let TurboJPEG grow the buffer as needed,
* -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the
* buffer for you, or
* -# pre-allocate the buffer to a "worst case" size determined by
@@ -683,8 +683,8 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void);
* parameters in <tt>transforms[i]</tt>. TurboJPEG has the ability to
* reallocate the JPEG buffer to accommodate the size of the JPEG image.
* Thus, you can choose to:
- * -# pre-allocate the JPEG buffer with an arbitrary size and let
- * TurboJPEG grow the buffer as needed,
+ * -# pre-allocate the JPEG buffer with an arbitrary size using
+ * #tjAlloc() and let TurboJPEG grow the buffer as needed,
* -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the
* buffer for you, or
* -# pre-allocate the buffer to a "worst case" size determined by
@@ -727,6 +727,31 @@ DLLEXPORT int DLLCALL tjDestroy(tjhandle handle);
/**
+ * Allocate an image buffer for use with TurboJPEG. You should always use
+ * this function to allocate the JPEG destination buffer(s) for #tjCompress2()
+ * and #tjTransform() unless you are disabling automatic buffer
+ * (re)allocation (by setting #TJFLAG_NOREALLOC.)
+ *
+ * @param bytes the number of bytes to allocate
+ *
+ * @return a pointer to a newly-allocated buffer with the specified number of
+ * bytes
+ */
+DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes);
+
+
+/**
+ * Free an image buffer previously allocated by TurboJPEG. You should always
+ * use this function to free JPEG destination buffer(s) that were automatically
+ * (re)allocated by #tjCompress2() or #tjTransform() or that were manually
+ * allocated using #tjAlloc().
+ *
+ * @param buffer address of the buffer to free
+ */
+DLLEXPORT void DLLCALL tjFree(unsigned char *buffer);
+
+
+/**
* Returns a descriptive error message explaining why the last command failed.
*
* @return a descriptive error message explaining why the last command failed.
diff --git a/turbojpegl.c b/turbojpegl.c
index 37a72c90..ba2967c2 100644
--- a/turbojpegl.c
+++ b/turbojpegl.c
@@ -236,6 +236,23 @@ DLLEXPORT int DLLCALL tjDestroy(tjhandle handle)
}
+/* These are exposed mainly because Windows can't malloc() and free() across
+ DLL boundaries except when the CRT DLL is used, and we don't use the CRT DLL
+ with turbojpeg.dll for compatibility reasons. However, these functions
+ can potentially be used for other purposes by different implementations. */
+
+DLLEXPORT void DLLCALL tjFree(unsigned char *buf)
+{
+ if(buf) free(buf);
+}
+
+
+DLLEXPORT unsigned char *DLLCALL tjAlloc(int bytes)
+{
+ return (unsigned char *)malloc(bytes);
+}
+
+
/* Compressor */
static tjhandle _tjInitCompress(tjinstance *this)