27 #define JPEG_INTERNALS
28 #define AM_MEMORY_MANAGER
35 extern char * getenv
JPP((
const char *
name));
73 #define ALIGN_TYPE double
189 small_pool_ptr shdr_ptr;
190 large_pool_ptr lhdr_ptr;
196 fprintf(stderr,
"Freeing pool %d, total space = %ld\n",
200 lhdr_ptr = lhdr_ptr->hdr.next) {
201 fprintf(stderr,
" Large chunk used %ld\n",
202 (
long) lhdr_ptr->hdr.bytes_used);
206 shdr_ptr = shdr_ptr->hdr.next) {
207 fprintf(stderr,
" Small chunk used %ld free %ld\n",
208 (
long) shdr_ptr->hdr.bytes_used,
209 (
long) shdr_ptr->hdr.bytes_left);
222 cinfo->err->trace_level = 2;
224 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
261 small_pool_ptr hdr_ptr, prev_hdr_ptr;
263 size_t odd_bytes, min_request, slop;
276 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
279 while (hdr_ptr !=
NULL) {
282 prev_hdr_ptr = hdr_ptr;
287 if (hdr_ptr ==
NULL) {
290 if (prev_hdr_ptr ==
NULL)
291 slop = first_pool_slop[pool_id];
293 slop = extra_pool_slop[pool_id];
311 if (prev_hdr_ptr ==
NULL)
314 prev_hdr_ptr->
hdr.
next = hdr_ptr;
318 data_ptr = (
char *) (hdr_ptr + 1);
323 return (
void *) data_ptr;
346 large_pool_ptr hdr_ptr;
360 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
373 hdr_ptr->hdr.bytes_used = sizeofobject;
374 hdr_ptr->hdr.bytes_left = 0;
377 return (
void FAR *) (hdr_ptr + 1);
409 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
410 if (ltemp < (
long) numrows)
413 rowsperchunk = numrows;
422 while (currow < numrows) {
423 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
425 (
size_t) ((size_t) rowsperchunk * (
size_t) samplesperrow
427 for (
i = rowsperchunk;
i > 0;
i--) {
428 result[currow++] = workspace;
429 workspace += samplesperrow;
457 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
458 if (ltemp < (
long) numrows)
461 rowsperchunk = numrows;
470 while (currow < numrows) {
471 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
473 (
size_t) ((size_t) rowsperchunk * (
size_t) blocksperrow
475 for (
i = rowsperchunk;
i > 0;
i--) {
476 result[currow++] = workspace;
477 workspace += blocksperrow;
533 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
540 result->rows_in_array = numrows;
541 result->samplesperrow = samplesperrow;
542 result->maxaccess = maxaccess;
543 result->pre_zero = pre_zero;
563 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
570 result->rows_in_array = numrows;
571 result->blocksperrow = blocksperrow;
572 result->maxaccess = maxaccess;
573 result->pre_zero = pre_zero;
587 long space_per_minheight, maximum_space, avail_mem;
588 long minheights, max_minheights;
596 space_per_minheight = 0;
599 if (sptr->mem_buffer ==
NULL) {
600 space_per_minheight += (long) sptr->
maxaccess *
602 maximum_space += (long) sptr->rows_in_array *
607 if (bptr->mem_buffer ==
NULL) {
608 space_per_minheight += (long) bptr->maxaccess *
610 maximum_space += (long) bptr->rows_in_array *
615 if (space_per_minheight <= 0)
626 if (avail_mem >= maximum_space)
627 max_minheights = 1000000000
L;
629 max_minheights = avail_mem / space_per_minheight;
633 if (max_minheights <= 0)
640 if (sptr->mem_buffer ==
NULL) {
641 minheights = ((long) sptr->rows_in_array - 1
L) / sptr->maxaccess + 1
L;
642 if (minheights <= max_minheights) {
644 sptr->rows_in_mem = sptr->rows_in_array;
647 sptr->rows_in_mem = (
JDIMENSION) (max_minheights * sptr->maxaccess);
649 (
long) sptr->rows_in_array *
650 (
long) sptr->samplesperrow *
652 sptr->b_s_open =
TRUE;
655 sptr->samplesperrow, sptr->rows_in_mem);
657 sptr->cur_start_row = 0;
658 sptr->first_undef_row = 0;
664 if (bptr->mem_buffer ==
NULL) {
665 minheights = ((long) bptr->rows_in_array - 1
L) / bptr->maxaccess + 1
L;
666 if (minheights <= max_minheights) {
668 bptr->rows_in_mem = bptr->rows_in_array;
671 bptr->rows_in_mem = (
JDIMENSION) (max_minheights * bptr->maxaccess);
673 (
long) bptr->rows_in_array *
674 (
long) bptr->blocksperrow *
676 bptr->b_s_open =
TRUE;
679 bptr->blocksperrow, bptr->rows_in_mem);
681 bptr->cur_start_row = 0;
682 bptr->first_undef_row = 0;
693 long bytesperrow, file_offset, byte_count, rows, thisrow,
i;
708 byte_count = rows * bytesperrow;
712 file_offset, byte_count);
716 file_offset, byte_count);
717 file_offset += byte_count;
726 long bytesperrow, file_offset, byte_count, rows, thisrow,
i;
741 byte_count = rows * bytesperrow;
745 file_offset, byte_count);
749 file_offset, byte_count);
750 file_offset += byte_count;
769 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
772 if (start_row < ptr->cur_start_row ||
775 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
812 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
813 undef_row = start_row;
823 while (undef_row < end_row) {
829 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
854 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
857 if (start_row < ptr->cur_start_row ||
860 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
897 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
898 undef_row = start_row;
908 while (undef_row < end_row) {
914 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
933 small_pool_ptr shdr_ptr;
934 large_pool_ptr lhdr_ptr;
938 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
941 if (cinfo->err->trace_level > 1)
942 print_mem_stats(cinfo, pool_id);
970 while (lhdr_ptr !=
NULL) {
971 large_pool_ptr next_lhdr_ptr = lhdr_ptr->
hdr.
next;
972 space_freed = lhdr_ptr->hdr.bytes_used +
973 lhdr_ptr->hdr.bytes_left +
977 lhdr_ptr = next_lhdr_ptr;
984 while (shdr_ptr !=
NULL) {
985 small_pool_ptr next_shdr_ptr = shdr_ptr->
hdr.
next;
987 shdr_ptr->hdr.bytes_left +
991 shdr_ptr = next_shdr_ptr;
1045 ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1054 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1063 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
1092 cinfo->mem = & mem->
pub;
1103 if ((memenv = getenv(
"JPEGMEM")) !=
NULL) {
1106 if (sscanf(memenv,
"%ld%c", &max_to_use, &ch) > 0) {
1107 if (ch ==
'm' || ch ==
'M')
1108 max_to_use *= 1000
L;
METHODDEF void FAR * alloc_large(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
GLOBAL void jpeg_mem_term(j_common_ptr cinfo)
struct large_pool_struct::@89 hdr
GLOBAL void jpeg_free_large(j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
GLOBAL long jpeg_mem_init(j_common_ptr cinfo)
METHODDEF void self_destruct(j_common_ptr cinfo)
struct jpeg_memory_mgr pub
#define ERREXIT(cinfo, code)
jvirt_sarray_ptr virt_sarray_list
my_memory_mgr * my_mem_ptr
JDIMENSION first_undef_row
union large_pool_struct large_pool_hdr
GLOBAL void jinit_memory_mgr(j_common_ptr cinfo)
union large_pool_struct FAR * large_pool_ptr
METHODDEF JBLOCKARRAY access_virt_barray(j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
LOCAL void do_barray_io(j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
long total_space_allocated
GLOBAL void jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
union small_pool_struct * small_pool_ptr
JDIMENSION last_rowsperchunk
METHODDEF void realize_virt_arrays(j_common_ptr cinfo)
GLOBAL void jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
METHODDEF JSAMPARRAY alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
union small_pool_struct small_pool_hdr
METHODDEF jvirt_barray_ptr request_virt_barray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
METHODDEF JBLOCKARRAY alloc_barray(j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
GLOBAL long jpeg_mem_available(j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
large_pool_ptr large_list[JPOOL_NUMPOOLS]
METHODDEF void free_pool(j_common_ptr cinfo, int pool_id)
GLOBAL void * jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
#define MIN(X, Y)
standard MIN macro
#define ERREXIT1(cinfo, code, p1)
LOCAL void do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
LOCAL void out_of_memory(j_common_ptr cinfo, int which)
struct jvirt_barray_control * jvirt_barray_ptr
jvirt_barray_ptr virt_barray_list
GLOBAL void jzero_far(void FAR *target, size_t bytestozero)
backing_store_info b_s_info
METHODDEF jvirt_sarray_ptr request_virt_sarray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
METHODDEF JSAMPARRAY access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
METHODDEF void * alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
backing_store_info b_s_info
GLOBAL void FAR * jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
struct small_pool_struct::@88 hdr
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
small_pool_ptr small_list[JPOOL_NUMPOOLS]
struct jvirt_sarray_control * jvirt_sarray_ptr
JDIMENSION first_undef_row