1*dfc6aa5cSAndroid Build Coastguard Worker /*
2*dfc6aa5cSAndroid Build Coastguard Worker * jmemnobs.c
3*dfc6aa5cSAndroid Build Coastguard Worker *
4*dfc6aa5cSAndroid Build Coastguard Worker * This file was part of the Independent JPEG Group's software:
5*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 1992-1996, Thomas G. Lane.
6*dfc6aa5cSAndroid Build Coastguard Worker * libjpeg-turbo Modifications:
7*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 2017-2018, D. R. Commander.
8*dfc6aa5cSAndroid Build Coastguard Worker * For conditions of distribution and use, see the accompanying README.ijg
9*dfc6aa5cSAndroid Build Coastguard Worker * file.
10*dfc6aa5cSAndroid Build Coastguard Worker *
11*dfc6aa5cSAndroid Build Coastguard Worker * This file provides a really simple implementation of the system-
12*dfc6aa5cSAndroid Build Coastguard Worker * dependent portion of the JPEG memory manager. This implementation
13*dfc6aa5cSAndroid Build Coastguard Worker * assumes that no backing-store files are needed: all required space
14*dfc6aa5cSAndroid Build Coastguard Worker * can be obtained from malloc().
15*dfc6aa5cSAndroid Build Coastguard Worker * This is very portable in the sense that it'll compile on almost anything,
16*dfc6aa5cSAndroid Build Coastguard Worker * but you'd better have lots of main memory (or virtual memory) if you want
17*dfc6aa5cSAndroid Build Coastguard Worker * to process big images.
18*dfc6aa5cSAndroid Build Coastguard Worker */
19*dfc6aa5cSAndroid Build Coastguard Worker
20*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_INTERNALS
21*dfc6aa5cSAndroid Build Coastguard Worker #include "jinclude.h"
22*dfc6aa5cSAndroid Build Coastguard Worker #include "jpeglib.h"
23*dfc6aa5cSAndroid Build Coastguard Worker #include "jmemsys.h" /* import the system-dependent declarations */
24*dfc6aa5cSAndroid Build Coastguard Worker
25*dfc6aa5cSAndroid Build Coastguard Worker
26*dfc6aa5cSAndroid Build Coastguard Worker /*
27*dfc6aa5cSAndroid Build Coastguard Worker * Memory allocation and freeing are controlled by the regular library
28*dfc6aa5cSAndroid Build Coastguard Worker * routines malloc() and free().
29*dfc6aa5cSAndroid Build Coastguard Worker */
30*dfc6aa5cSAndroid Build Coastguard Worker
31*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void *)
jpeg_get_small(j_common_ptr cinfo,size_t sizeofobject)32*dfc6aa5cSAndroid Build Coastguard Worker jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
33*dfc6aa5cSAndroid Build Coastguard Worker {
34*dfc6aa5cSAndroid Build Coastguard Worker return (void *)malloc(sizeofobject);
35*dfc6aa5cSAndroid Build Coastguard Worker }
36*dfc6aa5cSAndroid Build Coastguard Worker
37*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void)
jpeg_free_small(j_common_ptr cinfo,void * object,size_t sizeofobject)38*dfc6aa5cSAndroid Build Coastguard Worker jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
39*dfc6aa5cSAndroid Build Coastguard Worker {
40*dfc6aa5cSAndroid Build Coastguard Worker free(object);
41*dfc6aa5cSAndroid Build Coastguard Worker }
42*dfc6aa5cSAndroid Build Coastguard Worker
43*dfc6aa5cSAndroid Build Coastguard Worker
44*dfc6aa5cSAndroid Build Coastguard Worker /*
45*dfc6aa5cSAndroid Build Coastguard Worker * "Large" objects are treated the same as "small" ones.
46*dfc6aa5cSAndroid Build Coastguard Worker */
47*dfc6aa5cSAndroid Build Coastguard Worker
48*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void *)
jpeg_get_large(j_common_ptr cinfo,size_t sizeofobject)49*dfc6aa5cSAndroid Build Coastguard Worker jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
50*dfc6aa5cSAndroid Build Coastguard Worker {
51*dfc6aa5cSAndroid Build Coastguard Worker return (void *)malloc(sizeofobject);
52*dfc6aa5cSAndroid Build Coastguard Worker }
53*dfc6aa5cSAndroid Build Coastguard Worker
54*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void)
jpeg_free_large(j_common_ptr cinfo,void * object,size_t sizeofobject)55*dfc6aa5cSAndroid Build Coastguard Worker jpeg_free_large(j_common_ptr cinfo, void *object, size_t sizeofobject)
56*dfc6aa5cSAndroid Build Coastguard Worker {
57*dfc6aa5cSAndroid Build Coastguard Worker free(object);
58*dfc6aa5cSAndroid Build Coastguard Worker }
59*dfc6aa5cSAndroid Build Coastguard Worker
60*dfc6aa5cSAndroid Build Coastguard Worker
61*dfc6aa5cSAndroid Build Coastguard Worker /*
62*dfc6aa5cSAndroid Build Coastguard Worker * This routine computes the total memory space available for allocation.
63*dfc6aa5cSAndroid Build Coastguard Worker */
64*dfc6aa5cSAndroid Build Coastguard Worker
65*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(size_t)
jpeg_mem_available(j_common_ptr cinfo,size_t min_bytes_needed,size_t max_bytes_needed,size_t already_allocated)66*dfc6aa5cSAndroid Build Coastguard Worker jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
67*dfc6aa5cSAndroid Build Coastguard Worker size_t max_bytes_needed, size_t already_allocated)
68*dfc6aa5cSAndroid Build Coastguard Worker {
69*dfc6aa5cSAndroid Build Coastguard Worker if (cinfo->mem->max_memory_to_use) {
70*dfc6aa5cSAndroid Build Coastguard Worker if ((size_t)cinfo->mem->max_memory_to_use > already_allocated)
71*dfc6aa5cSAndroid Build Coastguard Worker return cinfo->mem->max_memory_to_use - already_allocated;
72*dfc6aa5cSAndroid Build Coastguard Worker else
73*dfc6aa5cSAndroid Build Coastguard Worker return 0;
74*dfc6aa5cSAndroid Build Coastguard Worker } else {
75*dfc6aa5cSAndroid Build Coastguard Worker /* Here we always say, "we got all you want bud!" */
76*dfc6aa5cSAndroid Build Coastguard Worker return max_bytes_needed;
77*dfc6aa5cSAndroid Build Coastguard Worker }
78*dfc6aa5cSAndroid Build Coastguard Worker }
79*dfc6aa5cSAndroid Build Coastguard Worker
80*dfc6aa5cSAndroid Build Coastguard Worker
81*dfc6aa5cSAndroid Build Coastguard Worker /*
82*dfc6aa5cSAndroid Build Coastguard Worker * Backing store (temporary file) management.
83*dfc6aa5cSAndroid Build Coastguard Worker * Since jpeg_mem_available always promised the moon,
84*dfc6aa5cSAndroid Build Coastguard Worker * this should never be called and we can just error out.
85*dfc6aa5cSAndroid Build Coastguard Worker */
86*dfc6aa5cSAndroid Build Coastguard Worker
87*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void)
jpeg_open_backing_store(j_common_ptr cinfo,backing_store_ptr info,long total_bytes_needed)88*dfc6aa5cSAndroid Build Coastguard Worker jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info,
89*dfc6aa5cSAndroid Build Coastguard Worker long total_bytes_needed)
90*dfc6aa5cSAndroid Build Coastguard Worker {
91*dfc6aa5cSAndroid Build Coastguard Worker ERREXIT(cinfo, JERR_NO_BACKING_STORE);
92*dfc6aa5cSAndroid Build Coastguard Worker }
93*dfc6aa5cSAndroid Build Coastguard Worker
94*dfc6aa5cSAndroid Build Coastguard Worker
95*dfc6aa5cSAndroid Build Coastguard Worker /*
96*dfc6aa5cSAndroid Build Coastguard Worker * These routines take care of any system-dependent initialization and
97*dfc6aa5cSAndroid Build Coastguard Worker * cleanup required. Here, there isn't any.
98*dfc6aa5cSAndroid Build Coastguard Worker */
99*dfc6aa5cSAndroid Build Coastguard Worker
100*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(long)
jpeg_mem_init(j_common_ptr cinfo)101*dfc6aa5cSAndroid Build Coastguard Worker jpeg_mem_init(j_common_ptr cinfo)
102*dfc6aa5cSAndroid Build Coastguard Worker {
103*dfc6aa5cSAndroid Build Coastguard Worker return 0; /* just set max_memory_to_use to 0 */
104*dfc6aa5cSAndroid Build Coastguard Worker }
105*dfc6aa5cSAndroid Build Coastguard Worker
106*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void)
jpeg_mem_term(j_common_ptr cinfo)107*dfc6aa5cSAndroid Build Coastguard Worker jpeg_mem_term(j_common_ptr cinfo)
108*dfc6aa5cSAndroid Build Coastguard Worker {
109*dfc6aa5cSAndroid Build Coastguard Worker /* no work */
110*dfc6aa5cSAndroid Build Coastguard Worker }
111