/* When suspending, the compressor will back up to a convenient restart point (typically the start of the current MCU). next_output_byte & free_in_buffer indicate where the restart point will be if the current call returns FALSE. Data beyond this point will be regenerated after resumption, so do not write it out when emptying the buffer externally.  */
empty_mem_output_buffer(j_compress_ptr cinfo)
/* When suspending, the compressor will back up to a convenient restart point (typically the start of the current MCU). next_output_byte & free_in_buffer indicate where the restart point will be if the current call returns FALSE. Data beyond this point will be regenerated after resumption, so do not write it out when emptying the buffer externally.  */
empty_mem_output_buffer(j_compress_ptr cinfo)
{
  size_t nextsize;
  JOCTET * nextbuffer;
  my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
  nextsize = dest->bufsize * 2;
  nextbuffer = (JOCTET *) malloc(nextsize);
  if (nextbuffer == NULL)
    ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
  MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
  if (dest->newbuffer != NULL)
    free(dest->newbuffer);
  dest->newbuffer = nextbuffer;
  dest->pub.next_output_byte = nextbuffer + dest->bufsize;
  dest->pub.free_in_buffer = dest->bufsize;
  dest->buffer = nextbuffer;
  dest->bufsize = nextsize;
  return TRUE;
}