27 #define JPEG_INTERNALS 28 #define AM_MEMORY_MANAGER 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",
199 for (lhdr_ptr = mem->
large_list[pool_id]; lhdr_ptr != NULL;
200 lhdr_ptr = lhdr_ptr->hdr.next) {
201 fprintf(stderr,
" Large chunk used %ld\n",
202 (
long) lhdr_ptr->hdr.bytes_used);
205 for (shdr_ptr = mem->
small_list[pool_id]; shdr_ptr != NULL;
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);
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)
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;
360 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
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);
539 result->mem_buffer = NULL;
540 result->rows_in_array = numrows;
541 result->samplesperrow = samplesperrow;
542 result->maxaccess = maxaccess;
543 result->pre_zero = pre_zero;
544 result->b_s_open =
FALSE;
563 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
569 result->mem_buffer = NULL;
570 result->rows_in_array = numrows;
571 result->blocksperrow = blocksperrow;
572 result->maxaccess = maxaccess;
573 result->pre_zero = pre_zero;
574 result->b_s_open =
FALSE;
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 = 1000000000L;
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 - 1L) / sptr->maxaccess + 1L;
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 - 1L) / bptr->maxaccess + 1L;
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;
696 file_offset =
ptr->cur_start_row * bytesperrow;
698 for (
i = 0;
i < (long)
ptr->rows_in_mem;
i +=
ptr->rowsperchunk) {
700 rows =
MIN((
long)
ptr->rowsperchunk, (
long)
ptr->rows_in_mem -
i);
702 thisrow = (long)
ptr->cur_start_row +
i;
703 rows =
MIN(rows, (
long)
ptr->first_undef_row - thisrow);
705 rows =
MIN(rows, (
long)
ptr->rows_in_array - thisrow);
708 byte_count = rows * bytesperrow;
710 (*
ptr->b_s_info.write_backing_store) (cinfo, &
ptr->b_s_info,
711 (
void FAR *)
ptr->mem_buffer[
i],
712 file_offset, byte_count);
714 (*
ptr->b_s_info.read_backing_store) (cinfo, &
ptr->b_s_info,
715 (
void FAR *)
ptr->mem_buffer[
i],
716 file_offset, byte_count);
717 file_offset += byte_count;
726 long bytesperrow, file_offset, byte_count, rows, thisrow,
i;
729 file_offset =
ptr->cur_start_row * bytesperrow;
731 for (
i = 0;
i < (long)
ptr->rows_in_mem;
i +=
ptr->rowsperchunk) {
733 rows =
MIN((
long)
ptr->rowsperchunk, (
long)
ptr->rows_in_mem -
i);
735 thisrow = (long)
ptr->cur_start_row +
i;
736 rows =
MIN(rows, (
long)
ptr->first_undef_row - thisrow);
738 rows =
MIN(rows, (
long)
ptr->rows_in_array - thisrow);
741 byte_count = rows * bytesperrow;
743 (*
ptr->b_s_info.write_backing_store) (cinfo, &
ptr->b_s_info,
744 (
void FAR *)
ptr->mem_buffer[
i],
745 file_offset, byte_count);
747 (*
ptr->b_s_info.read_backing_store) (cinfo, &
ptr->b_s_info,
748 (
void FAR *)
ptr->mem_buffer[
i],
749 file_offset, byte_count);
750 file_offset += byte_count;
768 ptr->mem_buffer == NULL)
769 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
772 if (start_row < ptr->cur_start_row ||
773 end_row >
ptr->cur_start_row+
ptr->rows_in_mem) {
775 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
788 if (start_row >
ptr->cur_start_row) {
789 ptr->cur_start_row = start_row;
794 ltemp = (long) end_row - (
long)
ptr->rows_in_mem;
809 if (
ptr->first_undef_row < end_row) {
810 if (
ptr->first_undef_row < start_row) {
812 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
813 undef_row = start_row;
815 undef_row =
ptr->first_undef_row;
818 ptr->first_undef_row = end_row;
821 undef_row -=
ptr->cur_start_row;
822 end_row -=
ptr->cur_start_row;
823 while (undef_row < end_row) {
829 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
836 return ptr->mem_buffer + (start_row -
ptr->cur_start_row);
853 ptr->mem_buffer == NULL)
854 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
857 if (start_row < ptr->cur_start_row ||
858 end_row >
ptr->cur_start_row+
ptr->rows_in_mem) {
860 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
873 if (start_row >
ptr->cur_start_row) {
874 ptr->cur_start_row = start_row;
879 ltemp = (long) end_row - (
long)
ptr->rows_in_mem;
894 if (
ptr->first_undef_row < end_row) {
895 if (
ptr->first_undef_row < start_row) {
897 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
898 undef_row = start_row;
900 undef_row =
ptr->first_undef_row;
903 ptr->first_undef_row = end_row;
906 undef_row -=
ptr->cur_start_row;
907 end_row -=
ptr->cur_start_row;
908 while (undef_row < end_row) {
914 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
921 return ptr->mem_buffer + (start_row -
ptr->cur_start_row);
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) {
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) {
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);
1095 cinfo->mem = & mem->
pub;
1106 if ((memenv =
getenv(
"JPEGMEM")) != NULL) {
1109 if (sscanf(memenv,
"%ld%c", &max_to_use, &ch) > 0) {
1110 if (ch ==
'm' || ch ==
'M')
1111 max_to_use *= 1000L;
request_virt_barray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
jpeg_mem_term(j_common_ptr cinfo)
do_barray_io(j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
out_of_memory(j_common_ptr cinfo, int which)
png_infop png_charpp name
struct jpeg_memory_mgr pub
#define ERREXIT(cinfo, code)
jvirt_sarray_ptr virt_sarray_list
my_memory_mgr * my_mem_ptr
#define MIN(a, b)
Returns the min value between a and b.
alloc_large(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
free_pool(j_common_ptr cinfo, int pool_id)
struct small_pool_struct::@4 hdr
JDIMENSION first_undef_row
self_destruct(j_common_ptr cinfo)
union large_pool_struct large_pool_hdr
union large_pool_struct FAR * large_pool_ptr
long total_space_allocated
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
union small_pool_struct * small_pool_ptr
JDIMENSION last_rowsperchunk
int JSAMPARRAY int int num_rows
union small_pool_struct small_pool_hdr
jpeg_free_large(j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
jinit_memory_mgr(j_common_ptr cinfo)
large_pool_ptr large_list[JPOOL_NUMPOOLS]
jzero_far(void FAR *target, size_t bytestozero)
access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
#define ERREXIT1(cinfo, code, p1)
static const size_t first_pool_slop[JPOOL_NUMPOOLS]
jpeg_mem_available(j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
struct jvirt_barray_control * jvirt_barray_ptr
jvirt_barray_ptr virt_barray_list
char * getenv(const char *name)
backing_store_info b_s_info
jpeg_mem_init(j_common_ptr cinfo)
jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
realize_virt_arrays(j_common_ptr cinfo)
static const size_t extra_pool_slop[JPOOL_NUMPOOLS]
alloc_barray(j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
backing_store_info b_s_info
request_virt_sarray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
small_pool_ptr small_list[JPOOL_NUMPOOLS]
struct jvirt_sarray_control * jvirt_sarray_ptr
JDIMENSION first_undef_row
access_virt_barray(j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)