10 #define JPEG_INTERNALS 11 #define AM_MEMORY_MANAGER 18 extern char* getenv
JPP((
const char*
name));
54 #define ALIGN_TYPE double 179 stderr,
"Freeing pool %d, total space = %ld\n", pool_id,
182 for (lhdr_ptr = mem->
large_list[pool_id]; lhdr_ptr !=
nullptr;
183 lhdr_ptr = lhdr_ptr->hdr.next)
186 stderr,
" Large chunk used %ld\n", (
long)lhdr_ptr->hdr.bytes_used);
189 for (shdr_ptr = mem->
small_list[pool_id]; shdr_ptr !=
nullptr;
193 stderr,
" Small chunk used %ld free %ld\n",
194 (
long)shdr_ptr->hdr.bytes_used, (
long)shdr_ptr->hdr.bytes_left);
206 cinfo->err->trace_level = 2;
208 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
243 size_t odd_bytes, min_request, slop;
255 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
256 prev_hdr_ptr =
nullptr;
258 while (hdr_ptr !=
nullptr)
262 prev_hdr_ptr = hdr_ptr;
267 if (hdr_ptr ==
nullptr)
271 if (prev_hdr_ptr ==
nullptr)
282 if (hdr_ptr !=
nullptr)
break;
292 if (prev_hdr_ptr ==
nullptr)
295 prev_hdr_ptr->
hdr.
next = hdr_ptr;
299 data_ptr = (
char*)(hdr_ptr + 1);
304 return (
void*)data_ptr;
339 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
352 hdr_ptr->hdr.bytes_left = 0;
355 return (
void FAR*)(hdr_ptr + 1);
386 if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
387 if (ltemp < (
long)numrows)
390 rowsperchunk = numrows;
399 while (currow < numrows)
401 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
403 cinfo, pool_id, (
size_t)(
404 (size_t)rowsperchunk * (
size_t)samplesperrow *
406 for (i = rowsperchunk; i > 0; i--)
436 if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
437 if (ltemp < (
long)numrows)
440 rowsperchunk = numrows;
449 while (currow < numrows)
451 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
455 (size_t)rowsperchunk * (
size_t)blocksperrow *
SIZEOF(
JBLOCK)));
456 for (i = rowsperchunk; i > 0; i--)
513 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
519 result->mem_buffer =
nullptr;
520 result->rows_in_array = numrows;
521 result->samplesperrow = samplesperrow;
522 result->maxaccess = maxaccess;
523 result->pre_zero = pre_zero;
524 result->b_s_open =
FALSE;
542 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
548 result->mem_buffer =
nullptr;
549 result->rows_in_array = numrows;
550 result->blocksperrow = blocksperrow;
551 result->maxaccess = maxaccess;
552 result->pre_zero = pre_zero;
553 result->b_s_open =
FALSE;
565 long space_per_minheight, maximum_space, avail_mem;
566 long minheights, max_minheights;
574 space_per_minheight = 0;
578 if (sptr->mem_buffer ==
nullptr)
580 space_per_minheight += (long)sptr->maxaccess *
582 maximum_space += (long)sptr->rows_in_array *
588 if (bptr->mem_buffer ==
nullptr)
590 space_per_minheight += (long)bptr->maxaccess *
592 maximum_space += (long)bptr->rows_in_array *
597 if (space_per_minheight <= 0)
return;
601 cinfo, space_per_minheight, maximum_space,
608 if (avail_mem >= maximum_space)
609 max_minheights = 1000000000L;
612 max_minheights = avail_mem / space_per_minheight;
616 if (max_minheights <= 0) max_minheights = 1;
623 if (sptr->mem_buffer ==
nullptr)
626 ((long)sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
627 if (minheights <= max_minheights)
630 sptr->rows_in_mem = sptr->rows_in_array;
636 (
JDIMENSION)(max_minheights * sptr->maxaccess);
638 cinfo, &sptr->b_s_info, (
long)sptr->rows_in_array *
639 (
long)sptr->samplesperrow *
641 sptr->b_s_open =
TRUE;
644 cinfo,
JPOOL_IMAGE, sptr->samplesperrow, sptr->rows_in_mem);
646 sptr->cur_start_row = 0;
647 sptr->first_undef_row = 0;
654 if (bptr->mem_buffer ==
nullptr)
657 ((long)bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
658 if (minheights <= max_minheights)
661 bptr->rows_in_mem = bptr->rows_in_array;
667 (
JDIMENSION)(max_minheights * bptr->maxaccess);
669 cinfo, &bptr->b_s_info, (
long)bptr->rows_in_array *
670 (
long)bptr->blocksperrow *
672 bptr->b_s_open =
TRUE;
675 cinfo,
JPOOL_IMAGE, bptr->blocksperrow, bptr->rows_in_mem);
677 bptr->cur_start_row = 0;
678 bptr->first_undef_row = 0;
688 long bytesperrow, file_offset, byte_count, rows, thisrow, i;
691 file_offset = ptr->cur_start_row * bytesperrow;
693 for (i = 0; i < (long)ptr->rows_in_mem; i += ptr->rowsperchunk)
696 rows =
MIN((
long)ptr->rowsperchunk, (
long)ptr->rows_in_mem - i);
698 thisrow = (long)ptr->cur_start_row + i;
699 rows =
MIN(rows, (
long)ptr->first_undef_row - thisrow);
701 rows =
MIN(rows, (
long)ptr->rows_in_array - thisrow);
704 byte_count = rows * bytesperrow;
706 (*ptr->b_s_info.write_backing_store)(
707 cinfo, &ptr->b_s_info, (
void FAR*)ptr->mem_buffer[i],
708 file_offset, byte_count);
710 (*ptr->b_s_info.read_backing_store)(
711 cinfo, &ptr->b_s_info, (
void FAR*)ptr->mem_buffer[i],
712 file_offset, byte_count);
713 file_offset += byte_count;
721 long bytesperrow, file_offset, byte_count, rows, thisrow, i;
724 file_offset = ptr->cur_start_row * bytesperrow;
726 for (i = 0; i < (long)ptr->rows_in_mem; i += ptr->rowsperchunk)
729 rows =
MIN((
long)ptr->rowsperchunk, (
long)ptr->rows_in_mem - i);
731 thisrow = (long)ptr->cur_start_row + i;
732 rows =
MIN(rows, (
long)ptr->first_undef_row - thisrow);
734 rows =
MIN(rows, (
long)ptr->rows_in_array - thisrow);
737 byte_count = rows * bytesperrow;
739 (*ptr->b_s_info.write_backing_store)(
740 cinfo, &ptr->b_s_info, (
void FAR*)ptr->mem_buffer[i],
741 file_offset, byte_count);
743 (*ptr->b_s_info.read_backing_store)(
744 cinfo, &ptr->b_s_info, (
void FAR*)ptr->mem_buffer[i],
745 file_offset, byte_count);
746 file_offset += byte_count;
762 if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
763 ptr->mem_buffer ==
nullptr)
764 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
767 if (start_row < ptr->cur_start_row ||
768 end_row > ptr->cur_start_row + ptr->rows_in_mem)
770 if (!ptr->b_s_open)
ERREXIT(cinfo, JERR_VIRTUAL_BUG);
786 if (start_row > ptr->cur_start_row)
788 ptr->cur_start_row = start_row;
795 ltemp = (long)end_row - (
long)ptr->rows_in_mem;
796 if (ltemp < 0) ltemp = 0;
809 if (ptr->first_undef_row < end_row)
811 if (ptr->first_undef_row < start_row)
814 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
815 undef_row = start_row;
819 undef_row = ptr->first_undef_row;
821 if (writable) ptr->first_undef_row = end_row;
824 size_t bytesperrow = (size_t)ptr->samplesperrow *
SIZEOF(
JSAMPLE);
827 end_row -= ptr->cur_start_row;
828 while (undef_row < end_row)
830 jzero_far((
void FAR*)ptr->mem_buffer[undef_row], bytesperrow);
837 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
841 if (writable) ptr->dirty =
TRUE;
843 return ptr->mem_buffer + (start_row - ptr->cur_start_row);
858 if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
859 ptr->mem_buffer ==
nullptr)
860 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
863 if (start_row < ptr->cur_start_row ||
864 end_row > ptr->cur_start_row + ptr->rows_in_mem)
866 if (!ptr->b_s_open)
ERREXIT(cinfo, JERR_VIRTUAL_BUG);
882 if (start_row > ptr->cur_start_row)
884 ptr->cur_start_row = start_row;
891 ltemp = (long)end_row - (
long)ptr->rows_in_mem;
892 if (ltemp < 0) ltemp = 0;
905 if (ptr->first_undef_row < end_row)
907 if (ptr->first_undef_row < start_row)
910 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
911 undef_row = start_row;
915 undef_row = ptr->first_undef_row;
917 if (writable) ptr->first_undef_row = end_row;
920 size_t bytesperrow = (size_t)ptr->blocksperrow *
SIZEOF(
JBLOCK);
923 end_row -= ptr->cur_start_row;
924 while (undef_row < end_row)
926 jzero_far((
void FAR*)ptr->mem_buffer[undef_row], bytesperrow);
933 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
937 if (writable) ptr->dirty =
TRUE;
939 return ptr->mem_buffer + (start_row - ptr->cur_start_row);
955 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
958 if (cinfo->err->trace_level > 1)
993 while (lhdr_ptr !=
nullptr)
996 space_freed = lhdr_ptr->hdr.bytes_used + lhdr_ptr->hdr.bytes_left +
1000 lhdr_ptr = next_lhdr_ptr;
1007 while (shdr_ptr !=
nullptr)
1010 space_freed = shdr_ptr->
hdr.
bytes_used + shdr_ptr->hdr.bytes_left +
1014 shdr_ptr = next_shdr_ptr;
1039 cinfo->mem =
nullptr;
1057 cinfo->mem =
nullptr;
1067 ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1076 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1086 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
1119 cinfo->mem = &mem->
pub;
1131 if ((memenv = getenv(
"JPEGMEM")) !=
nullptr)
1135 if (sscanf(memenv,
"%ld%c", &max_to_use, &ch) > 0)
1137 if (ch ==
'm' || ch ==
'M') max_to_use *= 1000L;
jzero_far(void FAR *target, size_t bytestozero)
jpeg_mem_init(j_common_ptr)
realize_virt_arrays(j_common_ptr cinfo)
jpeg_get_small(j_common_ptr, size_t sizeofobject)
FAST_FLOAT workspace[DCTSIZE2]
union small_pool_struct small_pool_hdr
union large_pool_struct large_pool_hdr
static const size_t extra_pool_slop[JPOOL_NUMPOOLS]
jpeg_free_small(j_common_ptr, void *object, size_t)
do_barray_io(j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
struct jpeg_memory_mgr pub
request_virt_barray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
#define ERREXIT(cinfo, code)
jvirt_sarray_ptr virt_sarray_list
for(ctr=DCTSIZE;ctr > 0;ctr--)
self_destruct(j_common_ptr cinfo)
my_memory_mgr * my_mem_ptr
JDIMENSION first_undef_row
alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
access_virt_barray(j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
struct jvirt_barray_control * jvirt_barray_ptr
jinit_memory_mgr(j_common_ptr cinfo)
JDIMENSION last_rowsperchunk
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr, long)
static const size_t first_pool_slop[JPOOL_NUMPOOLS]
access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
union large_pool_struct FAR * large_pool_ptr
request_virt_sarray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
large_pool_ptr large_list[JPOOL_NUMPOOLS]
union small_pool_struct * small_pool_ptr
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
#define ERREXIT1(cinfo, code, p1)
jvirt_barray_ptr virt_barray_list
size_t total_space_allocated
jpeg_mem_available(j_common_ptr, long, long max_bytes_needed, long)
free_pool(j_common_ptr cinfo, int pool_id)
jpeg_mem_term(j_common_ptr)
backing_store_info b_s_info
alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
jpeg_free_large(j_common_ptr, void FAR *object, size_t)
struct small_pool_struct::@75 hdr
GLuint const GLchar * name
backing_store_info b_s_info
struct large_pool_struct::@76 hdr
jpeg_get_large(j_common_ptr, size_t sizeofobject)
alloc_large(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
small_pool_ptr small_list[JPOOL_NUMPOOLS]
struct jvirt_sarray_control * jvirt_sarray_ptr
alloc_barray(j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
out_of_memory(j_common_ptr cinfo, int which)
JDIMENSION first_undef_row