]> granicus.if.org Git - libjpeg-turbo/commitdiff
Don't require buffer size to be preset if using TJFLAG_NOREALLOC
authorDRC <dcommander@users.sourceforge.net>
Tue, 24 May 2011 10:17:32 +0000 (10:17 +0000)
committerDRC <dcommander@users.sourceforge.net>
Tue, 24 May 2011 10:17:32 +0000 (10:17 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@626 632fc199-4ca6-4c93-a231-07263d6284db

12 files changed:
doc/html/annotated.html
doc/html/classes.html
doc/html/functions.html
doc/html/functions_vars.html
doc/html/group___turbo_j_p_e_g.html
doc/html/index.html
doc/html/modules.html
doc/html/structtjregion.html
doc/html/structtjscalingfactor.html
doc/html/structtjtransform.html
turbojpeg.h
turbojpegl.c

index 3c791b806d74a13b6eb6494ab8e0d3bd422bd34b..09db2cb42375736511e72a6dcb9192ae8eaa1afe 100644 (file)
@@ -81,7 +81,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index a294b86cc17613e7694596e7dc11b1744742874b..d9b8c9abb8969f4d2d2bf663b9f4da83cdba54f8 100644 (file)
@@ -80,7 +80,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 4ffd7c9a8ed37e8dfb9b109beb8de14d1dd5d735..edf3963dd35161ecbfd60ede6971a43be3b90168 100644 (file)
@@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 13d81218ce759fcd0a62d4e89721ef7e7d703eb3..a10da770a539b499141a4c562ae14bb78ffce442 100644 (file)
@@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index a79eb9a5f67c3a9065a3ecf83354de799ad6f40b..2540b94a4342ffc4a6db964225830c5ef56c172d 100644 (file)
@@ -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>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>
-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">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>
@@ -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>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>
-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">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>
@@ -1435,7 +1435,7 @@ If you choose option 1 or 3, <code>dstSizes[i]</code> should be set to the size
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 44528e9ac042a1e4cb24b31ab827525902cc97a3..8969bb045d5802aede5cbbfd84bc5faf3c650998 100644 (file)
@@ -69,7 +69,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 78d13ccc42da4c3fde43f700c42d7517f4f6d4b6..9328d4041bceeb54f49c72bdfddde51c06470f2d 100644 (file)
@@ -72,7 +72,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 792f0f276dab409cb550cd87e3159d3355b6822b..8a23e46b6d0a65a0bead7df5a0c89b691838d77a 100644 (file)
@@ -165,7 +165,7 @@ Data Fields</h2></td></tr>
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index c7be3570bd49bb4d33698976157e931c567d7f84..ad7858c7bb19253ff20ea78505f05db7babadee5 100644 (file)
@@ -127,7 +127,7 @@ Data Fields</h2></td></tr>
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 3ff7d6ed1af0a71aa8f6ddf6cd5e761ffab437c7..52524b2231ec686322bb1114b82ea862832584ee 100644 (file)
@@ -144,7 +144,7 @@ Data Fields</h2></td></tr>
 </iframe>
 </div>
 
-<hr class="footer"/><address class="footer"><small>Generated on Sat May 21 2011 10:32:20 for TurboJPEG by&#160;
+<hr class="footer"/><address class="footer"><small>Generated on Tue May 24 2011 05:15:41 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>
index 4bc91477e457388db14d3e6320d9e2c24f74cb20..17bc306ed4b8ec47015b8908368c171ab3466e21 100644 (file)
@@ -440,7 +440,7 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
  *        calling #TJBUFSIZE().  This should ensure that the buffer never has
  *        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
  *        set #TJFLAG_NOREALLOC, you should always check <tt>*jpegBuf</tt> upon
  *        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
  *        #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
  *        set #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt>
  *        upon return from this function, as it may have changed.
index 26fed45708d55ea3a1324dd3b187937808995361..37a72c9071588b55708239c89a1351af81e86b8c 100644 (file)
@@ -312,7 +312,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf,
        int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
        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)
        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_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);
 
        jpeg_start_compress(cinfo, TRUE);
@@ -376,7 +380,6 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf,
        }
        else
        {
-               size=TJBUFSIZE(width, height);
                retval=tjCompress2(handle, srcBuf, width, pitch, height,
                        getPixelFormat(pixelSize, flags), &jpegBuf, &size, jpegSubsamp, jpegQual,
                        flags|TJFLAG_NOREALLOC);
@@ -953,9 +956,7 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf,
 
        for(i=0; i<n; i++)
        {
-               int w, h;
-               jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i],
-                       (flags&TJFLAG_NOREALLOC)==0);
+               int w, h, alloc=1;
                if(!xinfo[i].crop)
                {
                        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;
                }
+               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);
                dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs,
                        &xinfo[i]);