|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* jmemnobs.c
|
|
kusano |
7d535a |
*
|
|
shun-iwasawa |
82a8f5 |
* This file was part of the Independent JPEG Group's software:
|
|
kusano |
7d535a |
* Copyright (C) 1992-1996, Thomas G. Lane.
|
|
shun-iwasawa |
82a8f5 |
* libjpeg-turbo Modifications:
|
|
shun-iwasawa |
82a8f5 |
* Copyright (C) 2017-2018, D. R. Commander.
|
|
shun-iwasawa |
82a8f5 |
* For conditions of distribution and use, see the accompanying README.ijg
|
|
shun-iwasawa |
82a8f5 |
* file.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* This file provides a really simple implementation of the system-
|
|
kusano |
7d535a |
* dependent portion of the JPEG memory manager. This implementation
|
|
kusano |
7d535a |
* assumes that no backing-store files are needed: all required space
|
|
kusano |
7d535a |
* can be obtained from malloc().
|
|
kusano |
7d535a |
* This is very portable in the sense that it'll compile on almost anything,
|
|
kusano |
7d535a |
* but you'd better have lots of main memory (or virtual memory) if you want
|
|
kusano |
7d535a |
* to process big images.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define JPEG_INTERNALS
|
|
kusano |
7d535a |
#include "jinclude.h"
|
|
kusano |
7d535a |
#include "jpeglib.h"
|
|
shun-iwasawa |
82a8f5 |
#include "jmemsys.h" /* import the system-dependent declarations */
|
|
kusano |
7d535a |
|
|
shun-iwasawa |
82a8f5 |
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */</stdlib.h>
|
|
shun-iwasawa |
82a8f5 |
extern void *malloc(size_t size);
|
|
shun-iwasawa |
82a8f5 |
extern void free(void *ptr);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Memory allocation and freeing are controlled by the regular library
|
|
kusano |
7d535a |
* routines malloc() and free().
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(void *)
|
|
shun-iwasawa |
82a8f5 |
jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
|
|
kusano |
7d535a |
{
|
|
shun-iwasawa |
82a8f5 |
return (void *)malloc(sizeofobject);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(void)
|
|
shun-iwasawa |
82a8f5 |
jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
free(object);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* "Large" objects are treated the same as "small" ones.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
shun-iwasawa |
82a8f5 |
GLOBAL(void *)
|
|
shun-iwasawa |
82a8f5 |
jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
|
|
kusano |
7d535a |
{
|
|
shun-iwasawa |
82a8f5 |
return (void *)malloc(sizeofobject);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(void)
|
|
shun-iwasawa |
82a8f5 |
jpeg_free_large(j_common_ptr cinfo, void *object, size_t sizeofobject)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
free(object);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* This routine computes the total memory space available for allocation.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
shun-iwasawa |
82a8f5 |
GLOBAL(size_t)
|
|
shun-iwasawa |
82a8f5 |
jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
|
|
shun-iwasawa |
82a8f5 |
size_t max_bytes_needed, size_t already_allocated)
|
|
kusano |
7d535a |
{
|
|
shun-iwasawa |
82a8f5 |
if (cinfo->mem->max_memory_to_use) {
|
|
shun-iwasawa |
82a8f5 |
if ((size_t)cinfo->mem->max_memory_to_use > already_allocated)
|
|
shun-iwasawa |
82a8f5 |
return cinfo->mem->max_memory_to_use - already_allocated;
|
|
shun-iwasawa |
82a8f5 |
else
|
|
shun-iwasawa |
82a8f5 |
return 0;
|
|
shun-iwasawa |
82a8f5 |
} else {
|
|
shun-iwasawa |
82a8f5 |
/* Here we always say, "we got all you want bud!" */
|
|
shun-iwasawa |
82a8f5 |
return max_bytes_needed;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Backing store (temporary file) management.
|
|
kusano |
7d535a |
* Since jpeg_mem_available always promised the moon,
|
|
kusano |
7d535a |
* this should never be called and we can just error out.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(void)
|
|
shun-iwasawa |
82a8f5 |
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info,
|
|
shun-iwasawa |
82a8f5 |
long total_bytes_needed)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
ERREXIT(cinfo, JERR_NO_BACKING_STORE);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* These routines take care of any system-dependent initialization and
|
|
kusano |
7d535a |
* cleanup required. Here, there isn't any.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(long)
|
|
shun-iwasawa |
82a8f5 |
jpeg_mem_init(j_common_ptr cinfo)
|
|
kusano |
7d535a |
{
|
|
shun-iwasawa |
82a8f5 |
return 0; /* just set max_memory_to_use to 0 */
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(void)
|
|
shun-iwasawa |
82a8f5 |
jpeg_mem_term(j_common_ptr cinfo)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/* no work */
|
|
kusano |
7d535a |
}
|