Skip to content

Commit 4b8d1ee

Browse files
authored
Merge pull request #206 from pornel/temppool
Use temporary pool for internal recompression
2 parents fb16334 + 5ff20ca commit 4b8d1ee

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

jcmaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ prepare_for_pass (j_compress_ptr cinfo)
518518
master->saved_dest = cinfo->dest;
519519
cinfo->dest = NULL;
520520
master->scan_size[master->scan_number] = 0;
521-
jpeg_mem_dest(cinfo, &master->scan_buffer[master->scan_number], &master->scan_size[master->scan_number]);
521+
jpeg_mem_dest_internal(cinfo, &master->scan_buffer[master->scan_number], &master->scan_size[master->scan_number], JPOOL_IMAGE);
522522
(*cinfo->dest->init_destination)(cinfo);
523523
}
524524
(*cinfo->entropy->start_pass) (cinfo, FALSE);

jdatadst.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
208208
{
209209
my_dest_ptr dest;
210210

211-
/* The destination object is made permanent so that multiple JPEG images
212-
* can be written to the same file without re-executing jpeg_stdio_dest.
213-
*/
211+
/* The destination object is made permanent so that multiple JPEG images
212+
* can be written to the same file without re-executing jpeg_stdio_dest.
213+
*/
214214
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
215215
cinfo->dest = (struct jpeg_destination_mgr *)
216216
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
@@ -249,8 +249,8 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
249249
*/
250250

251251
GLOBAL(void)
252-
jpeg_mem_dest (j_compress_ptr cinfo,
253-
unsigned char **outbuffer, unsigned long *outsize)
252+
jpeg_mem_dest_internal (j_compress_ptr cinfo,
253+
unsigned char **outbuffer, unsigned long *outsize, int pool_id)
254254
{
255255
my_mem_dest_ptr dest;
256256

@@ -262,7 +262,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
262262
*/
263263
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
264264
cinfo->dest = (struct jpeg_destination_mgr *)
265-
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
265+
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, pool_id,
266266
sizeof(my_mem_destination_mgr));
267267
} else if (cinfo->dest->init_destination != init_mem_destination) {
268268
/* It is unsafe to reuse the existing destination manager unless it was
@@ -290,4 +290,15 @@ jpeg_mem_dest (j_compress_ptr cinfo,
290290
dest->pub.next_output_byte = dest->buffer = *outbuffer;
291291
dest->pub.free_in_buffer = dest->bufsize = *outsize;
292292
}
293+
294+
GLOBAL(void)
295+
jpeg_mem_dest (j_compress_ptr cinfo,
296+
unsigned char **outbuffer, unsigned long *outsize)
297+
{
298+
/* The destination object is made permanent so that multiple JPEG images
299+
* can be written to the same file without re-executing jpeg_stdio_dest.
300+
*/
301+
jpeg_mem_dest_internal(cinfo, outbuffer, outsize, JPOOL_PERMANENT);
302+
}
303+
293304
#endif

jpegint.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ EXTERN(void) jinit_merged_upsampler (j_decompress_ptr cinfo);
402402
/* Memory manager initialization */
403403
EXTERN(void) jinit_memory_mgr (j_common_ptr cinfo);
404404

405+
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
406+
EXTERN(void)
407+
jpeg_mem_dest_internal (j_compress_ptr cinfo,
408+
unsigned char **outbuffer, unsigned long *outsize, int pool_id);
409+
#endif
410+
405411
/* Utility routines in jutils.c */
406412
EXTERN(long) jdiv_round_up (long a, long b);
407413
EXTERN(long) jround_up (long a, long b);

0 commit comments

Comments
 (0)