10 #define JPEG_INTERNALS 11 #define AM_MEMORY_MANAGER 18 extern char * getenv
JPP((
const char *
name));
56 #define ALIGN_TYPE double 179 fprintf(stderr,
"Freeing pool %d, total space = %ld\n",
182 for (lhdr_ptr = mem->
large_list[pool_id]; lhdr_ptr != NULL;
183 lhdr_ptr = lhdr_ptr->hdr.next) {
184 fprintf(stderr,
" Large chunk used %ld\n",
185 (
long) lhdr_ptr->hdr.bytes_used);
188 for (shdr_ptr = mem->
small_list[pool_id]; shdr_ptr != NULL;
189 shdr_ptr = shdr_ptr->
hdr.
next) {
190 fprintf(stderr,
" Small chunk used %ld free %ld\n",
191 (
long) shdr_ptr->hdr.bytes_used,
192 (
long) shdr_ptr->hdr.bytes_left);
205 cinfo->err->trace_level = 2;
207 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
246 size_t odd_bytes, min_request, slop;
259 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
262 while (hdr_ptr != NULL) {
265 prev_hdr_ptr = hdr_ptr;
270 if (hdr_ptr == NULL) {
273 if (prev_hdr_ptr == NULL)
294 if (prev_hdr_ptr == NULL)
297 prev_hdr_ptr->
hdr.
next = hdr_ptr;
301 data_ptr = (
char *) (hdr_ptr + 1);
306 return (
void *) data_ptr;
343 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
357 hdr_ptr->hdr.bytes_left = 0;
360 return (
void FAR *) (hdr_ptr + 1);
392 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
393 if (ltemp < (
long) numrows)
396 rowsperchunk = numrows;
405 while (currow < numrows) {
406 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
408 (
size_t) ((size_t) rowsperchunk * (
size_t) samplesperrow
410 for (i = rowsperchunk; i > 0; i--) {
411 result[currow++] = workspace;
412 workspace += samplesperrow;
440 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
441 if (ltemp < (
long) numrows)
444 rowsperchunk = numrows;
453 while (currow < numrows) {
454 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
456 (
size_t) ((size_t) rowsperchunk * (
size_t) blocksperrow
458 for (i = rowsperchunk; i > 0; i--) {
459 result[currow++] = workspace;
460 workspace += blocksperrow;
516 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
522 result->mem_buffer = NULL;
523 result->rows_in_array = numrows;
524 result->samplesperrow = samplesperrow;
525 result->maxaccess = maxaccess;
526 result->pre_zero = pre_zero;
527 result->b_s_open =
FALSE;
546 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
552 result->mem_buffer = NULL;
553 result->rows_in_array = numrows;
554 result->blocksperrow = blocksperrow;
555 result->maxaccess = maxaccess;
556 result->pre_zero = pre_zero;
557 result->b_s_open =
FALSE;
570 long space_per_minheight, maximum_space,avail_mem;
571 long minheights, max_minheights;
579 space_per_minheight = 0;
582 if (sptr->mem_buffer == NULL) {
583 space_per_minheight += (long) sptr->
maxaccess *
585 maximum_space += (long) sptr->rows_in_array *
590 if (bptr->mem_buffer == NULL) {
591 space_per_minheight += (long) bptr->maxaccess *
593 maximum_space += (long) bptr->rows_in_array *
598 if (space_per_minheight <= 0)
609 if (avail_mem >= maximum_space)
610 max_minheights = 1000000000L;
612 max_minheights = avail_mem / space_per_minheight;
616 if (max_minheights <= 0)
623 if (sptr->mem_buffer == NULL) {
624 minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
625 if (minheights <= max_minheights) {
627 sptr->rows_in_mem = sptr->rows_in_array;
630 sptr->rows_in_mem = (
JDIMENSION) (max_minheights * sptr->maxaccess);
632 (
long) sptr->rows_in_array *
633 (
long) sptr->samplesperrow *
635 sptr->b_s_open =
TRUE;
638 sptr->samplesperrow, sptr->rows_in_mem);
640 sptr->cur_start_row = 0;
641 sptr->first_undef_row = 0;
647 if (bptr->mem_buffer == NULL) {
648 minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
649 if (minheights <= max_minheights) {
651 bptr->rows_in_mem = bptr->rows_in_array;
654 bptr->rows_in_mem = (
JDIMENSION) (max_minheights * bptr->maxaccess);
656 (
long) bptr->rows_in_array *
657 (
long) bptr->blocksperrow *
659 bptr->b_s_open =
TRUE;
662 bptr->blocksperrow, bptr->rows_in_mem);
664 bptr->cur_start_row = 0;
665 bptr->first_undef_row = 0;
676 long bytesperrow, file_offset, byte_count, rows, thisrow, i;
679 file_offset = ptr->cur_start_row * bytesperrow;
681 for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
683 rows =
MIN((
long) ptr->rowsperchunk, (
long) ptr->rows_in_mem - i);
685 thisrow = (long) ptr->cur_start_row + i;
686 rows =
MIN(rows, (
long) ptr->first_undef_row - thisrow);
688 rows =
MIN(rows, (
long) ptr->rows_in_array - thisrow);
691 byte_count = rows * bytesperrow;
693 (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
694 (
void FAR *) ptr->mem_buffer[i],
695 file_offset, byte_count);
697 (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
698 (
void FAR *) ptr->mem_buffer[i],
699 file_offset, byte_count);
700 file_offset += byte_count;
709 long bytesperrow, file_offset, byte_count, rows, thisrow, i;
711 bytesperrow = (long) ptr->blocksperrow *
SIZEOF(
JBLOCK);
712 file_offset = ptr->cur_start_row * bytesperrow;
714 for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
716 rows =
MIN((
long) ptr->rowsperchunk, (
long) ptr->rows_in_mem - i);
718 thisrow = (long) ptr->cur_start_row + i;
719 rows =
MIN(rows, (
long) ptr->first_undef_row - thisrow);
721 rows =
MIN(rows, (
long) ptr->rows_in_array - thisrow);
724 byte_count = rows * bytesperrow;
726 (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
727 (
void FAR *) ptr->mem_buffer[i],
728 file_offset, byte_count);
730 (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
731 (
void FAR *) ptr->mem_buffer[i],
732 file_offset, byte_count);
733 file_offset += byte_count;
750 if (end_row > ptr->rows_in_array ||
num_rows > ptr->maxaccess ||
751 ptr->mem_buffer == NULL)
752 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
755 if (start_row < ptr->cur_start_row ||
756 end_row > ptr->cur_start_row+ptr->rows_in_mem) {
758 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
771 if (start_row > ptr->cur_start_row) {
772 ptr->cur_start_row = start_row;
777 ltemp = (long) end_row - (
long) ptr->rows_in_mem;
792 if (ptr->first_undef_row < end_row) {
793 if (ptr->first_undef_row < start_row) {
795 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
796 undef_row = start_row;
798 undef_row = ptr->first_undef_row;
801 ptr->first_undef_row = end_row;
803 size_t bytesperrow = (size_t) ptr->samplesperrow *
SIZEOF(
JSAMPLE);
804 undef_row -= ptr->cur_start_row;
805 end_row -= ptr->cur_start_row;
806 while (undef_row < end_row) {
807 jzero_far((
void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
812 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
819 return ptr->mem_buffer + (start_row - ptr->cur_start_row);
835 if (end_row > ptr->rows_in_array ||
num_rows > ptr->maxaccess ||
836 ptr->mem_buffer == NULL)
837 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
840 if (start_row < ptr->cur_start_row ||
841 end_row > ptr->cur_start_row+ptr->rows_in_mem) {
843 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
856 if (start_row > ptr->cur_start_row) {
857 ptr->cur_start_row = start_row;
862 ltemp = (long) end_row - (
long) ptr->rows_in_mem;
877 if (ptr->first_undef_row < end_row) {
878 if (ptr->first_undef_row < start_row) {
880 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
881 undef_row = start_row;
883 undef_row = ptr->first_undef_row;
886 ptr->first_undef_row = end_row;
888 size_t bytesperrow = (size_t) ptr->blocksperrow *
SIZEOF(
JBLOCK);
889 undef_row -= ptr->cur_start_row;
890 end_row -= ptr->cur_start_row;
891 while (undef_row < end_row) {
892 jzero_far((
void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
897 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
904 return ptr->mem_buffer + (start_row - ptr->cur_start_row);
921 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
924 if (cinfo->err->trace_level > 1)
925 print_mem_stats(cinfo, pool_id);
953 while (lhdr_ptr != NULL) {
955 space_freed = lhdr_ptr->hdr.bytes_used +
956 lhdr_ptr->hdr.bytes_left +
960 lhdr_ptr = next_lhdr_ptr;
967 while (shdr_ptr != NULL) {
970 shdr_ptr->hdr.bytes_left +
974 shdr_ptr = next_shdr_ptr;
1028 ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1037 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1046 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
1078 cinfo->mem = & mem->
pub;
1089 if ((memenv = getenv(
"JPEGMEM")) != NULL) {
1092 if (sscanf(memenv,
"%ld%c", &max_to_use, &ch) > 0) {
1093 if (ch ==
'm' || ch ==
'M')
1094 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)
struct large_pool_struct::@78 hdr
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
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
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]
int JSAMPARRAY int int num_rows
union small_pool_struct * small_pool_ptr
#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::@77 hdr
GLuint const GLchar * name
backing_store_info b_s_info
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