Main MRPT website > C++ reference for MRPT 1.5.7
jmemmgr.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #define JPEG_INTERNALS
11 #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
12 #include "jinclude.h"
13 #include "mrpt_jpeglib.h"
14 #include "jmemsys.h" /* import the system-dependent declarations */
15 
16 #ifndef NO_GETENV
17 #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
18 extern char * getenv JPP((const char * name));
19 #endif
20 #endif
21 
22 
23 /*
24  * Some important notes:
25  * The allocation routines provided here must never return NULL.
26  * They should exit to error_exit if unsuccessful.
27  *
28  * It's not a good idea to try to merge the sarray and barray routines,
29  * even though they are textually almost the same, because samples are
30  * usually stored as bytes while coefficients are shorts or ints. Thus,
31  * in machines where byte pointers have a different representation from
32  * word pointers, the resulting machine code could not be the same.
33  */
34 
35 
36 /*
37  * Many machines require storage alignment: longs must start on 4-byte
38  * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc()
39  * always returns pointers that are multiples of the worst-case alignment
40  * requirement, and we had better do so too.
41  * There isn't any really portable way to determine the worst-case alignment
42  * requirement. This module assumes that the alignment requirement is
43  * multiples of sizeof(ALIGN_TYPE).
44  * By default, we define ALIGN_TYPE as double. This is necessary on some
45  * workstations (where doubles really do need 8-byte alignment) and will work
46  * fine on nearly everything. If your machine has lesser alignment needs,
47  * you can save a few bytes by making ALIGN_TYPE smaller.
48  * The only place I know of where this will NOT work is certain Macintosh
49  * 680x0 compilers that define double as a 10-byte IEEE extended float.
50  * Doing 10-byte alignment is counterproductive because longwords won't be
51  * aligned well. Put "#define ALIGN_TYPE long" in mrpt_jconfig.h if you have
52  * such a compiler.
53  */
54 
55 #ifndef ALIGN_TYPE /* so can override from mrpt_jconfig.h */
56 #define ALIGN_TYPE double
57 #endif
58 
59 
60 /*
61  * We allocate objects from "pools", where each pool is gotten with a single
62  * request to jpeg_get_small() or jpeg_get_large(). There is no per-object
63  * overhead within a pool, except for alignment padding. Each pool has a
64  * header with a link to the next pool of the same class.
65  * Small and large pool headers are identical except that the latter's
66  * link pointer must be FAR on 80x86 machines.
67  * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE
68  * field. This forces the compiler to make SIZEOF(small_pool_hdr) a multiple
69  * of the alignment requirement of ALIGN_TYPE.
70  */
71 
73 
74 typedef union small_pool_struct {
75  struct {
76  small_pool_ptr next; /* next in list of pools */
77  size_t bytes_used; /* how many bytes already used within pool */
78  size_t bytes_left; /* bytes still available in this pool */
79  } hdr;
80  ALIGN_TYPE dummy; /* included in union to ensure alignment */
82 
84 
85 typedef union large_pool_struct {
86  struct {
87  large_pool_ptr next; /* next in list of pools */
88  size_t bytes_used; /* how many bytes already used within pool */
89  size_t bytes_left; /* bytes still available in this pool */
90  } hdr;
91  ALIGN_TYPE dummy; /* included in union to ensure alignment */
93 
94 
95 /*
96  * Here is the full definition of a memory manager object.
97  */
98 
99 typedef struct {
100  struct jpeg_memory_mgr pub; /* public fields */
101 
102  /* Each pool identifier (lifetime class) names a linked list of pools. */
105 
106  /* Since we only have one lifetime class of virtual arrays, only one
107  * linked list is necessary (for each datatype). Note that the virtual
108  * array control blocks being linked together are actually stored somewhere
109  * in the small-pool list.
110  */
113 
114  /* This counts total space obtained from jpeg_get_small/large */
115  size_t /*JLBC for MRPT, was: long */ total_space_allocated;
116 
117  /* alloc_sarray and alloc_barray set this value for use by virtual
118  * array routines.
119  */
120  JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
121 } my_memory_mgr;
122 
124 
125 
126 /*
127  * The control blocks for virtual arrays.
128  * Note that these blocks are allocated in the "small" pool area.
129  * System-dependent info for the associated backing store (if any) is hidden
130  * inside the backing_store_info struct.
131  */
132 
134  JSAMPARRAY mem_buffer; /* => the in-memory buffer */
135  JDIMENSION rows_in_array; /* total virtual array height */
136  JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
137  JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
138  JDIMENSION rows_in_mem; /* height of memory buffer */
139  JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
140  JDIMENSION cur_start_row; /* first logical row # in the buffer */
141  JDIMENSION first_undef_row; /* row # of first uninitialized row */
142  boolean pre_zero; /* pre-zero mode requested? */
143  boolean dirty; /* do current buffer contents need written? */
144  boolean b_s_open; /* is backing-store data valid? */
145  jvirt_sarray_ptr next; /* link to next virtual sarray control block */
146  backing_store_info b_s_info; /* System-dependent control info */
147 };
148 
150  JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
151  JDIMENSION rows_in_array; /* total virtual array height */
152  JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
153  JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
154  JDIMENSION rows_in_mem; /* height of memory buffer */
155  JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
156  JDIMENSION cur_start_row; /* first logical row # in the buffer */
157  JDIMENSION first_undef_row; /* row # of first uninitialized row */
158  boolean pre_zero; /* pre-zero mode requested? */
159  boolean dirty; /* do current buffer contents need written? */
160  boolean b_s_open; /* is backing-store data valid? */
161  jvirt_barray_ptr next; /* link to next virtual barray control block */
162  backing_store_info b_s_info; /* System-dependent control info */
163 };
164 
165 
166 #ifdef MEM_STATS /* optional extra stuff for statistics */
167 
168 LOCAL(void)
169 print_mem_stats (j_common_ptr cinfo, int pool_id)
170 {
171  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
172  small_pool_ptr shdr_ptr;
173  large_pool_ptr lhdr_ptr;
174 
175  /* Since this is only a debugging stub, we can cheat a little by using
176  * fprintf directly rather than going through the trace message code.
177  * This is helpful because message parm array can't handle longs.
178  */
179  fprintf(stderr, "Freeing pool %d, total space = %ld\n",
180  pool_id, mem->total_space_allocated);
181 
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);
186  }
187 
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);
193  }
194 }
195 
196 #endif /* MEM_STATS */
197 
198 
199 LOCAL(void)
200 out_of_memory (j_common_ptr cinfo, int which)
201 /* Report an out-of-memory error and stop execution */
202 /* If we compiled MEM_STATS support, report alloc requests before dying */
203 {
204 #ifdef MEM_STATS
205  cinfo->err->trace_level = 2; /* force self_destruct to report stats */
206 #endif
207  ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
208 }
209 
210 
211 /*
212  * Allocation of "small" objects.
213  *
214  * For these, we use pooled storage. When a new pool must be created,
215  * we try to get enough space for the current request plus a "slop" factor,
216  * where the slop will be the amount of leftover space in the new pool.
217  * The speed vs. space tradeoff is largely determined by the slop values.
218  * A different slop value is provided for each pool class (lifetime),
219  * and we also distinguish the first pool of a class from later ones.
220  * NOTE: the values given work fairly well on both 16- and 32-bit-int
221  * machines, but may be too small if longs are 64 bits or more.
222  */
223 
224 static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
225 {
226  1600, /* first PERMANENT pool */
227  16000 /* first IMAGE pool */
228 };
229 
230 static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
231 {
232  0, /* additional PERMANENT pools */
233  5000 /* additional IMAGE pools */
234 };
235 
236 #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
237 
238 
239 METHODDEF(void *)
240 alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
241 /* Allocate a "small" object */
242 {
243  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
244  small_pool_ptr hdr_ptr, prev_hdr_ptr;
245  char * data_ptr;
246  size_t odd_bytes, min_request, slop;
247 
248  /* Check for unsatisfiable request (do now to ensure no overflow below) */
250  out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
251 
252  /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
253  odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
254  if (odd_bytes > 0)
255  sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
256 
257  /* See if space is available in any existing pool */
258  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
259  ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
260  prev_hdr_ptr = NULL;
261  hdr_ptr = mem->small_list[pool_id];
262  while (hdr_ptr != NULL) {
263  if (hdr_ptr->hdr.bytes_left >= sizeofobject)
264  break; /* found pool with enough space */
265  prev_hdr_ptr = hdr_ptr;
266  hdr_ptr = hdr_ptr->hdr.next;
267  }
268 
269  /* Time to make a new pool? */
270  if (hdr_ptr == NULL) {
271  /* min_request is what we need now, slop is what will be leftover */
272  min_request = sizeofobject + SIZEOF(small_pool_hdr);
273  if (prev_hdr_ptr == NULL) /* first pool in class? */
274  slop = first_pool_slop[pool_id];
275  else
276  slop = extra_pool_slop[pool_id];
277  /* Don't ask for more than MAX_ALLOC_CHUNK */
278  if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
279  slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
280  /* Try to get space, if fail reduce slop and try again */
281  for (;;) {
282  hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
283  if (hdr_ptr != NULL)
284  break;
285  slop /= 2;
286  if (slop < MIN_SLOP) /* give up when it gets real small */
287  out_of_memory(cinfo, 2); /* jpeg_get_small failed */
288  }
289  mem->total_space_allocated += min_request + slop;
290  /* Success, initialize the new pool header and add to end of list */
291  hdr_ptr->hdr.next = NULL;
292  hdr_ptr->hdr.bytes_used = 0;
293  hdr_ptr->hdr.bytes_left = sizeofobject + slop;
294  if (prev_hdr_ptr == NULL) /* first pool in class? */
295  mem->small_list[pool_id] = hdr_ptr;
296  else
297  prev_hdr_ptr->hdr.next = hdr_ptr;
298  }
299 
300  /* OK, allocate the object from the current pool */
301  data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
302  data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
303  hdr_ptr->hdr.bytes_used += sizeofobject;
304  hdr_ptr->hdr.bytes_left -= sizeofobject;
305 
306  return (void *) data_ptr;
307 }
308 
309 
310 /*
311  * Allocation of "large" objects.
312  *
313  * The external semantics of these are the same as "small" objects,
314  * except that FAR pointers are used on 80x86. However the pool
315  * management heuristics are quite different. We assume that each
316  * request is large enough that it may as well be passed directly to
317  * jpeg_get_large; the pool management just links everything together
318  * so that we can free it all on demand.
319  * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
320  * structures. The routines that create these structures (see below)
321  * deliberately bunch rows together to ensure a large request size.
322  */
323 
324 METHODDEF(void FAR *)
325 alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
326 /* Allocate a "large" object */
327 {
328  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
329  large_pool_ptr hdr_ptr;
330  size_t odd_bytes;
331 
332  /* Check for unsatisfiable request (do now to ensure no overflow below) */
334  out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
335 
336  /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
337  odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
338  if (odd_bytes > 0)
339  sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
340 
341  /* Always make a new pool */
342  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
343  ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
344 
345  hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
347  if (hdr_ptr == NULL)
348  out_of_memory(cinfo, 4); /* jpeg_get_large failed */
350 
351  /* Success, initialize the new pool header and add to list */
352  hdr_ptr->hdr.next = mem->large_list[pool_id];
353  /* We maintain space counts in each pool header for statistical purposes,
354  * even though they are not needed for allocation.
355  */
356  hdr_ptr->hdr.bytes_used = sizeofobject;
357  hdr_ptr->hdr.bytes_left = 0;
358  mem->large_list[pool_id] = hdr_ptr;
359 
360  return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
361 }
362 
363 
364 /*
365  * Creation of 2-D sample arrays.
366  * The pointers are in near heap, the samples themselves in FAR heap.
367  *
368  * To minimize allocation overhead and to allow I/O of large contiguous
369  * blocks, we allocate the sample rows in groups of as many rows as possible
370  * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
371  * NB: the virtual array control routines, later in this file, know about
372  * this chunking of rows. The rowsperchunk value is left in the mem manager
373  * object so that it can be saved away if this sarray is the workspace for
374  * a virtual array.
375  */
376 
378 alloc_sarray (j_common_ptr cinfo, int pool_id,
379  JDIMENSION samplesperrow, JDIMENSION numrows)
380 /* Allocate a 2-D sample array */
381 {
382  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
383  JSAMPARRAY result;
384  JSAMPROW workspace;
385  JDIMENSION rowsperchunk, currow, i;
386  long ltemp;
387 
388  /* Calculate max # of rows allowed in one allocation chunk */
390  ((long) samplesperrow * SIZEOF(JSAMPLE));
391  if (ltemp <= 0)
392  ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
393  if (ltemp < (long) numrows)
394  rowsperchunk = (JDIMENSION) ltemp;
395  else
396  rowsperchunk = numrows;
397  mem->last_rowsperchunk = rowsperchunk;
398 
399  /* Get space for row pointers (small object) */
400  result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
401  (size_t) (numrows * SIZEOF(JSAMPROW)));
402 
403  /* Get the rows themselves (large objects) */
404  currow = 0;
405  while (currow < numrows) {
406  rowsperchunk = MIN(rowsperchunk, numrows - currow);
407  workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
408  (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
409  * SIZEOF(JSAMPLE)));
410  for (i = rowsperchunk; i > 0; i--) {
411  result[currow++] = workspace;
412  workspace += samplesperrow;
413  }
414  }
415 
416  return result;
417 }
418 
419 
420 /*
421  * Creation of 2-D coefficient-block arrays.
422  * This is essentially the same as the code for sample arrays, above.
423  */
424 
426 alloc_barray (j_common_ptr cinfo, int pool_id,
427  JDIMENSION blocksperrow, JDIMENSION numrows)
428 /* Allocate a 2-D coefficient-block array */
429 {
430  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
431  JBLOCKARRAY result;
432  JBLOCKROW workspace;
433  JDIMENSION rowsperchunk, currow, i;
434  long ltemp;
435 
436  /* Calculate max # of rows allowed in one allocation chunk */
438  ((long) blocksperrow * SIZEOF(JBLOCK));
439  if (ltemp <= 0)
440  ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
441  if (ltemp < (long) numrows)
442  rowsperchunk = (JDIMENSION) ltemp;
443  else
444  rowsperchunk = numrows;
445  mem->last_rowsperchunk = rowsperchunk;
446 
447  /* Get space for row pointers (small object) */
448  result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
449  (size_t) (numrows * SIZEOF(JBLOCKROW)));
450 
451  /* Get the rows themselves (large objects) */
452  currow = 0;
453  while (currow < numrows) {
454  rowsperchunk = MIN(rowsperchunk, numrows - currow);
455  workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
456  (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
457  * SIZEOF(JBLOCK)));
458  for (i = rowsperchunk; i > 0; i--) {
459  result[currow++] = workspace;
460  workspace += blocksperrow;
461  }
462  }
463 
464  return result;
465 }
466 
467 
468 /*
469  * About virtual array management:
470  *
471  * The above "normal" array routines are only used to allocate strip buffers
472  * (as wide as the image, but just a few rows high). Full-image-sized buffers
473  * are handled as "virtual" arrays. The array is still accessed a strip at a
474  * time, but the memory manager must save the whole array for repeated
475  * accesses. The intended implementation is that there is a strip buffer in
476  * memory (as high as is possible given the desired memory limit), plus a
477  * backing file that holds the rest of the array.
478  *
479  * The request_virt_array routines are told the total size of the image and
480  * the maximum number of rows that will be accessed at once. The in-memory
481  * buffer must be at least as large as the maxaccess value.
482  *
483  * The request routines create control blocks but not the in-memory buffers.
484  * That is postponed until realize_virt_arrays is called. At that time the
485  * total amount of space needed is known (approximately, anyway), so free
486  * memory can be divided up fairly.
487  *
488  * The access_virt_array routines are responsible for making a specific strip
489  * area accessible (after reading or writing the backing file, if necessary).
490  * Note that the access routines are told whether the caller intends to modify
491  * the accessed strip; during a read-only pass this saves having to rewrite
492  * data to disk. The access routines are also responsible for pre-zeroing
493  * any newly accessed rows, if pre-zeroing was requested.
494  *
495  * In current usage, the access requests are usually for nonoverlapping
496  * strips; that is, successive access start_row numbers differ by exactly
497  * num_rows = maxaccess. This means we can get good performance with simple
498  * buffer dump/reload logic, by making the in-memory buffer be a multiple
499  * of the access height; then there will never be accesses across bufferload
500  * boundaries. The code will still work with overlapping access requests,
501  * but it doesn't handle bufferload overlaps very efficiently.
502  */
503 
504 
506 request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
507  JDIMENSION samplesperrow, JDIMENSION numrows,
508  JDIMENSION maxaccess)
509 /* Request a virtual 2-D sample array */
510 {
511  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
512  jvirt_sarray_ptr result;
513 
514  /* Only IMAGE-lifetime virtual arrays are currently supported */
515  if (pool_id != JPOOL_IMAGE)
516  ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
517 
518  /* get control block */
519  result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
520  SIZEOF(struct jvirt_sarray_control));
521 
522  result->mem_buffer = NULL; /* marks array not yet realized */
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; /* no associated backing-store object */
528  result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
529  mem->virt_sarray_list = result;
530 
531  return result;
532 }
533 
534 
536 request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
537  JDIMENSION blocksperrow, JDIMENSION numrows,
538  JDIMENSION maxaccess)
539 /* Request a virtual 2-D coefficient-block array */
540 {
541  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
542  jvirt_barray_ptr result;
543 
544  /* Only IMAGE-lifetime virtual arrays are currently supported */
545  if (pool_id != JPOOL_IMAGE)
546  ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
547 
548  /* get control block */
549  result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
550  SIZEOF(struct jvirt_barray_control));
551 
552  result->mem_buffer = NULL; /* marks array not yet realized */
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; /* no associated backing-store object */
558  result->next = mem->virt_barray_list; /* add to list of virtual arrays */
559  mem->virt_barray_list = result;
560 
561  return result;
562 }
563 
564 
565 METHODDEF(void)
567 /* Allocate the in-memory buffers for any unrealized virtual arrays */
568 {
569  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
570  long space_per_minheight, maximum_space,avail_mem;
571  long minheights, max_minheights;
572  jvirt_sarray_ptr sptr;
573  jvirt_barray_ptr bptr;
574 
575  /* Compute the minimum space needed (maxaccess rows in each buffer)
576  * and the maximum space needed (full image height in each buffer).
577  * These may be of use to the system-dependent jpeg_mem_available routine.
578  */
579  space_per_minheight = 0;
580  maximum_space = 0;
581  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
582  if (sptr->mem_buffer == NULL) { /* if not realized yet */
583  space_per_minheight += (long) sptr->maxaccess *
584  (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
585  maximum_space += (long) sptr->rows_in_array *
586  (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
587  }
588  }
589  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
590  if (bptr->mem_buffer == NULL) { /* if not realized yet */
591  space_per_minheight += (long) bptr->maxaccess *
592  (long) bptr->blocksperrow * SIZEOF(JBLOCK);
593  maximum_space += (long) bptr->rows_in_array *
594  (long) bptr->blocksperrow * SIZEOF(JBLOCK);
595  }
596  }
597 
598  if (space_per_minheight <= 0)
599  return; /* no unrealized arrays, no work */
600 
601  /* Determine amount of memory to actually use; this is system-dependent. */
602  avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
603  (long)mem->total_space_allocated);
604 
605  /* If the maximum space needed is available, make all the buffers full
606  * height; otherwise parcel it out with the same number of minheights
607  * in each buffer.
608  */
609  if (avail_mem >= maximum_space)
610  max_minheights = 1000000000L;
611  else {
612  max_minheights = avail_mem / space_per_minheight;
613  /* If there doesn't seem to be enough space, try to get the minimum
614  * anyway. This allows a "stub" implementation of jpeg_mem_available().
615  */
616  if (max_minheights <= 0)
617  max_minheights = 1;
618  }
619 
620  /* Allocate the in-memory buffers and initialize backing store as needed. */
621 
622  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
623  if (sptr->mem_buffer == NULL) { /* if not realized yet */
624  minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
625  if (minheights <= max_minheights) {
626  /* This buffer fits in memory */
627  sptr->rows_in_mem = sptr->rows_in_array;
628  } else {
629  /* It doesn't fit in memory, create backing store. */
630  sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
631  jpeg_open_backing_store(cinfo, & sptr->b_s_info,
632  (long) sptr->rows_in_array *
633  (long) sptr->samplesperrow *
634  (long) SIZEOF(JSAMPLE));
635  sptr->b_s_open = TRUE;
636  }
637  sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
638  sptr->samplesperrow, sptr->rows_in_mem);
639  sptr->rowsperchunk = mem->last_rowsperchunk;
640  sptr->cur_start_row = 0;
641  sptr->first_undef_row = 0;
642  sptr->dirty = FALSE;
643  }
644  }
645 
646  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
647  if (bptr->mem_buffer == NULL) { /* if not realized yet */
648  minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
649  if (minheights <= max_minheights) {
650  /* This buffer fits in memory */
651  bptr->rows_in_mem = bptr->rows_in_array;
652  } else {
653  /* It doesn't fit in memory, create backing store. */
654  bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
655  jpeg_open_backing_store(cinfo, & bptr->b_s_info,
656  (long) bptr->rows_in_array *
657  (long) bptr->blocksperrow *
658  (long) SIZEOF(JBLOCK));
659  bptr->b_s_open = TRUE;
660  }
661  bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
662  bptr->blocksperrow, bptr->rows_in_mem);
663  bptr->rowsperchunk = mem->last_rowsperchunk;
664  bptr->cur_start_row = 0;
665  bptr->first_undef_row = 0;
666  bptr->dirty = FALSE;
667  }
668  }
669 }
670 
671 
672 LOCAL(void)
673 do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
674 /* Do backing store read or write of a virtual sample array */
675 {
676  long bytesperrow, file_offset, byte_count, rows, thisrow, i;
677 
678  bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
679  file_offset = ptr->cur_start_row * bytesperrow;
680  /* Loop to read or write each allocation chunk in mem_buffer */
681  for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
682  /* One chunk, but check for short chunk at end of buffer */
683  rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
684  /* Transfer no more than is currently defined */
685  thisrow = (long) ptr->cur_start_row + i;
686  rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
687  /* Transfer no more than fits in file */
688  rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
689  if (rows <= 0) /* this chunk might be past end of file! */
690  break;
691  byte_count = rows * bytesperrow;
692  if (writing)
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);
696  else
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;
701  }
702 }
703 
704 
705 LOCAL(void)
706 do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
707 /* Do backing store read or write of a virtual coefficient-block array */
708 {
709  long bytesperrow, file_offset, byte_count, rows, thisrow, i;
710 
711  bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
712  file_offset = ptr->cur_start_row * bytesperrow;
713  /* Loop to read or write each allocation chunk in mem_buffer */
714  for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
715  /* One chunk, but check for short chunk at end of buffer */
716  rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
717  /* Transfer no more than is currently defined */
718  thisrow = (long) ptr->cur_start_row + i;
719  rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
720  /* Transfer no more than fits in file */
721  rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
722  if (rows <= 0) /* this chunk might be past end of file! */
723  break;
724  byte_count = rows * bytesperrow;
725  if (writing)
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);
729  else
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;
734  }
735 }
736 
737 
740  JDIMENSION start_row, JDIMENSION num_rows,
741  boolean writable)
742 /* Access the part of a virtual sample array starting at start_row */
743 /* and extending for num_rows rows. writable is true if */
744 /* caller intends to modify the accessed area. */
745 {
746  JDIMENSION end_row = start_row + num_rows;
747  JDIMENSION undef_row;
748 
749  /* debugging check */
750  if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
751  ptr->mem_buffer == NULL)
752  ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
753 
754  /* Make the desired part of the virtual array accessible */
755  if (start_row < ptr->cur_start_row ||
756  end_row > ptr->cur_start_row+ptr->rows_in_mem) {
757  if (! ptr->b_s_open)
758  ERREXIT(cinfo, JERR_VIRTUAL_BUG);
759  /* Flush old buffer contents if necessary */
760  if (ptr->dirty) {
761  do_sarray_io(cinfo, ptr, TRUE);
762  ptr->dirty = FALSE;
763  }
764  /* Decide what part of virtual array to access.
765  * Algorithm: if target address > current window, assume forward scan,
766  * load starting at target address. If target address < current window,
767  * assume backward scan, load so that target area is top of window.
768  * Note that when switching from forward write to forward read, will have
769  * start_row = 0, so the limiting case applies and we load from 0 anyway.
770  */
771  if (start_row > ptr->cur_start_row) {
772  ptr->cur_start_row = start_row;
773  } else {
774  /* use long arithmetic here to avoid overflow & unsigned problems */
775  long ltemp;
776 
777  ltemp = (long) end_row - (long) ptr->rows_in_mem;
778  if (ltemp < 0)
779  ltemp = 0; /* don't fall off front end of file */
780  ptr->cur_start_row = (JDIMENSION) ltemp;
781  }
782  /* Read in the selected part of the array.
783  * During the initial write pass, we will do no actual read
784  * because the selected part is all undefined.
785  */
786  do_sarray_io(cinfo, ptr, FALSE);
787  }
788  /* Ensure the accessed part of the array is defined; prezero if needed.
789  * To improve locality of access, we only prezero the part of the array
790  * that the caller is about to access, not the entire in-memory array.
791  */
792  if (ptr->first_undef_row < end_row) {
793  if (ptr->first_undef_row < start_row) {
794  if (writable) /* writer skipped over a section of array */
795  ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
796  undef_row = start_row; /* but reader is allowed to read ahead */
797  } else {
798  undef_row = ptr->first_undef_row;
799  }
800  if (writable)
801  ptr->first_undef_row = end_row;
802  if (ptr->pre_zero) {
803  size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
804  undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
805  end_row -= ptr->cur_start_row;
806  while (undef_row < end_row) {
807  jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
808  undef_row++;
809  }
810  } else {
811  if (! writable) /* reader looking at undefined data */
812  ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
813  }
814  }
815  /* Flag the buffer dirty if caller will write in it */
816  if (writable)
817  ptr->dirty = TRUE;
818  /* Return address of proper part of the buffer */
819  return ptr->mem_buffer + (start_row - ptr->cur_start_row);
820 }
821 
822 
825  JDIMENSION start_row, JDIMENSION num_rows,
826  boolean writable)
827 /* Access the part of a virtual block array starting at start_row */
828 /* and extending for num_rows rows. writable is true if */
829 /* caller intends to modify the accessed area. */
830 {
831  JDIMENSION end_row = start_row + num_rows;
832  JDIMENSION undef_row;
833 
834  /* debugging check */
835  if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
836  ptr->mem_buffer == NULL)
837  ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
838 
839  /* Make the desired part of the virtual array accessible */
840  if (start_row < ptr->cur_start_row ||
841  end_row > ptr->cur_start_row+ptr->rows_in_mem) {
842  if (! ptr->b_s_open)
843  ERREXIT(cinfo, JERR_VIRTUAL_BUG);
844  /* Flush old buffer contents if necessary */
845  if (ptr->dirty) {
846  do_barray_io(cinfo, ptr, TRUE);
847  ptr->dirty = FALSE;
848  }
849  /* Decide what part of virtual array to access.
850  * Algorithm: if target address > current window, assume forward scan,
851  * load starting at target address. If target address < current window,
852  * assume backward scan, load so that target area is top of window.
853  * Note that when switching from forward write to forward read, will have
854  * start_row = 0, so the limiting case applies and we load from 0 anyway.
855  */
856  if (start_row > ptr->cur_start_row) {
857  ptr->cur_start_row = start_row;
858  } else {
859  /* use long arithmetic here to avoid overflow & unsigned problems */
860  long ltemp;
861 
862  ltemp = (long) end_row - (long) ptr->rows_in_mem;
863  if (ltemp < 0)
864  ltemp = 0; /* don't fall off front end of file */
865  ptr->cur_start_row = (JDIMENSION) ltemp;
866  }
867  /* Read in the selected part of the array.
868  * During the initial write pass, we will do no actual read
869  * because the selected part is all undefined.
870  */
871  do_barray_io(cinfo, ptr, FALSE);
872  }
873  /* Ensure the accessed part of the array is defined; prezero if needed.
874  * To improve locality of access, we only prezero the part of the array
875  * that the caller is about to access, not the entire in-memory array.
876  */
877  if (ptr->first_undef_row < end_row) {
878  if (ptr->first_undef_row < start_row) {
879  if (writable) /* writer skipped over a section of array */
880  ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
881  undef_row = start_row; /* but reader is allowed to read ahead */
882  } else {
883  undef_row = ptr->first_undef_row;
884  }
885  if (writable)
886  ptr->first_undef_row = end_row;
887  if (ptr->pre_zero) {
888  size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
889  undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
890  end_row -= ptr->cur_start_row;
891  while (undef_row < end_row) {
892  jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
893  undef_row++;
894  }
895  } else {
896  if (! writable) /* reader looking at undefined data */
897  ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
898  }
899  }
900  /* Flag the buffer dirty if caller will write in it */
901  if (writable)
902  ptr->dirty = TRUE;
903  /* Return address of proper part of the buffer */
904  return ptr->mem_buffer + (start_row - ptr->cur_start_row);
905 }
906 
907 
908 /*
909  * Release all objects belonging to a specified pool.
910  */
911 
912 METHODDEF(void)
913 free_pool (j_common_ptr cinfo, int pool_id)
914 {
915  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
916  small_pool_ptr shdr_ptr;
917  large_pool_ptr lhdr_ptr;
918  size_t space_freed;
919 
920  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
921  ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
922 
923 #ifdef MEM_STATS
924  if (cinfo->err->trace_level > 1)
925  print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
926 #endif
927 
928  /* If freeing IMAGE pool, close any virtual arrays first */
929  if (pool_id == JPOOL_IMAGE) {
930  jvirt_sarray_ptr sptr;
931  jvirt_barray_ptr bptr;
932 
933  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
934  if (sptr->b_s_open) { /* there may be no backing store */
935  sptr->b_s_open = FALSE; /* prevent recursive close if error */
936  (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
937  }
938  }
939  mem->virt_sarray_list = NULL;
940  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
941  if (bptr->b_s_open) { /* there may be no backing store */
942  bptr->b_s_open = FALSE; /* prevent recursive close if error */
943  (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
944  }
945  }
946  mem->virt_barray_list = NULL;
947  }
948 
949  /* Release large objects */
950  lhdr_ptr = mem->large_list[pool_id];
951  mem->large_list[pool_id] = NULL;
952 
953  while (lhdr_ptr != NULL) {
954  large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
955  space_freed = lhdr_ptr->hdr.bytes_used +
956  lhdr_ptr->hdr.bytes_left +
958  jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
959  mem->total_space_allocated -= space_freed;
960  lhdr_ptr = next_lhdr_ptr;
961  }
962 
963  /* Release small objects */
964  shdr_ptr = mem->small_list[pool_id];
965  mem->small_list[pool_id] = NULL;
966 
967  while (shdr_ptr != NULL) {
968  small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
969  space_freed = shdr_ptr->hdr.bytes_used +
970  shdr_ptr->hdr.bytes_left +
972  jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
973  mem->total_space_allocated -= space_freed;
974  shdr_ptr = next_shdr_ptr;
975  }
976 }
977 
978 
979 /*
980  * Close up shop entirely.
981  * Note that this cannot be called unless cinfo->mem is non-NULL.
982  */
983 
984 METHODDEF(void)
986 {
987  int pool;
988 
989  /* Close all backing store, release all memory.
990  * Releasing pools in reverse order might help avoid fragmentation
991  * with some (brain-damaged) malloc libraries.
992  */
993  for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
994  free_pool(cinfo, pool);
995  }
996 
997  /* Release the memory manager control block too. */
998  jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
999  cinfo->mem = NULL; /* ensures I will be called only once */
1000 
1001  jpeg_mem_term(cinfo); /* system-dependent cleanup */
1002 }
1003 
1004 
1005 /*
1006  * Memory manager initialization.
1007  * When this is called, only the error manager pointer is valid in cinfo!
1008  */
1009 
1010 GLOBAL(void)
1012 {
1013  my_mem_ptr mem;
1014  long max_to_use;
1015  int pool;
1016  size_t test_mac;
1017 
1018  cinfo->mem = NULL; /* for safety if init fails */
1019 
1020  /* Check for configuration errors.
1021  * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
1022  * doesn't reflect any real hardware alignment requirement.
1023  * The test is a little tricky: for X>0, X and X-1 have no one-bits
1024  * in common if and only if X is a power of 2, ie has only one one-bit.
1025  * Some compilers may give an "unreachable code" warning here; ignore it.
1026  */
1027  if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
1028  ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1029  /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
1030  * a multiple of SIZEOF(ALIGN_TYPE).
1031  * Again, an "unreachable code" warning may be ignored here.
1032  * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
1033  */
1034  test_mac = (size_t) MAX_ALLOC_CHUNK;
1035  if ((long) test_mac != MAX_ALLOC_CHUNK ||
1036  (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
1037  ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1038 
1039  max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
1040 
1041  /* Attempt to allocate memory manager's control block */
1042  mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
1043 
1044  if (mem == NULL) {
1045  jpeg_mem_term(cinfo); /* system-dependent cleanup */
1046  ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
1047  }
1048 
1049  /* OK, fill in the method pointers */
1050  mem->pub.alloc_small = alloc_small;
1051  mem->pub.alloc_large = alloc_large;
1052  mem->pub.alloc_sarray = alloc_sarray;
1053  mem->pub.alloc_barray = alloc_barray;
1054  mem->pub.request_virt_sarray = request_virt_sarray;
1055  mem->pub.request_virt_barray = request_virt_barray;
1056  mem->pub.realize_virt_arrays = realize_virt_arrays;
1057  mem->pub.access_virt_sarray = access_virt_sarray;
1058  mem->pub.access_virt_barray = access_virt_barray;
1059  mem->pub.free_pool = free_pool;
1060  mem->pub.self_destruct = self_destruct;
1061 
1062  /* Make MAX_ALLOC_CHUNK accessible to other modules */
1064 
1065  /* Initialize working state */
1066  mem->pub.max_memory_to_use = max_to_use;
1067 
1068  for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
1069  mem->small_list[pool] = NULL;
1070  mem->large_list[pool] = NULL;
1071  }
1072  mem->virt_sarray_list = NULL;
1073  mem->virt_barray_list = NULL;
1074 
1076 
1077  /* Declare ourselves open for business */
1078  cinfo->mem = & mem->pub;
1079 
1080  /* Check for an environment variable JPEGMEM; if found, override the
1081  * default max_memory setting from jpeg_mem_init. Note that the
1082  * surrounding application may again override this value.
1083  * If your system doesn't support getenv(), define NO_GETENV to disable
1084  * this feature.
1085  */
1086 #ifndef NO_GETENV
1087  { char * memenv;
1088 
1089  if ((memenv = getenv("JPEGMEM")) != NULL) {
1090  char ch = 'x';
1091 
1092  if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
1093  if (ch == 'm' || ch == 'M')
1094  max_to_use *= 1000L;
1095  mem->pub.max_memory_to_use = max_to_use * 1000L;
1096  }
1097  }
1098  }
1099 #endif
1100 
1101 }
jzero_far(void FAR *target, size_t bytestozero)
Definition: jutils.cpp:161
size_t bytes_used
Definition: jmemmgr.cpp:77
jpeg_mem_init(j_common_ptr)
Definition: jmemnobs.cpp:92
realize_virt_arrays(j_common_ptr cinfo)
Definition: jmemmgr.cpp:566
jpeg_get_small(j_common_ptr, size_t sizeofobject)
Definition: jmemnobs.cpp:27
ALIGN_TYPE dummy
Definition: jmemmgr.cpp:91
struct large_pool_struct::@78 hdr
char JSAMPLE
Definition: jmorecfg.h:61
union small_pool_struct small_pool_hdr
union large_pool_struct large_pool_hdr
JDIMENSION maxaccess
Definition: jmemmgr.cpp:137
#define JPOOL_PERMANENT
Definition: mrpt_jpeglib.h:745
static const size_t extra_pool_slop[JPOOL_NUMPOOLS]
Definition: jmemmgr.cpp:230
jpeg_free_small(j_common_ptr, void *object, size_t)
Definition: jmemnobs.cpp:33
do_barray_io(j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
Definition: jmemmgr.cpp:706
JDIMENSION cur_start_row
Definition: jmemmgr.cpp:140
JDIMENSION rows_in_array
Definition: jmemmgr.cpp:151
struct jpeg_memory_mgr pub
Definition: jmemmgr.cpp:100
#define MIN(a, b)
Definition: jpegint.h:266
request_virt_barray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
Definition: jmemmgr.cpp:536
#define ERREXIT(cinfo, code)
Definition: jerror.h:199
jvirt_sarray_ptr virt_sarray_list
Definition: jmemmgr.cpp:111
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:412
jvirt_sarray_ptr next
Definition: jmemmgr.cpp:145
#define SIZEOF(object)
Definition: jinclude.h:73
self_destruct(j_common_ptr cinfo)
Definition: jmemmgr.cpp:985
JBLOCKARRAY mem_buffer
Definition: jmemmgr.cpp:150
JSAMPLE FAR * JSAMPROW
Definition: mrpt_jpeglib.h:63
my_memory_mgr * my_mem_ptr
Definition: jmemmgr.cpp:123
JDIMENSION first_undef_row
Definition: jmemmgr.cpp:141
alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
Definition: jmemmgr.cpp:378
size_t sizeofobject
Definition: jmemsys.h:36
JDIMENSION rowsperchunk
Definition: jmemmgr.cpp:139
access_virt_barray(j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
Definition: jmemmgr.cpp:824
size_t bytes_left
Definition: jmemmgr.cpp:78
large_pool_ptr next
Definition: jmemmgr.cpp:87
JSAMPARRAY mem_buffer
Definition: jmemmgr.cpp:134
JDIMENSION blocksperrow
Definition: jmemmgr.cpp:152
JDIMENSION rows_in_array
Definition: jmemmgr.cpp:135
struct jvirt_barray_control * jvirt_barray_ptr
Definition: mrpt_jpeglib.h:750
JDIMENSION rows_in_mem
Definition: jmemmgr.cpp:138
JDIMENSION maxaccess
Definition: jmemmgr.cpp:153
jinit_memory_mgr(j_common_ptr cinfo)
Definition: jmemmgr.cpp:1011
#define FALSE
Definition: jmorecfg.h:227
#define JPOOL_IMAGE
Definition: mrpt_jpeglib.h:746
ALIGN_TYPE dummy
Definition: jmemmgr.cpp:80
#define LOCAL(type)
Definition: jmorecfg.h:183
JDIMENSION last_rowsperchunk
Definition: jmemmgr.cpp:120
jvirt_barray_ptr next
Definition: jmemmgr.cpp:161
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:64
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr, long)
Definition: jmemnobs.cpp:79
static const size_t first_pool_slop[JPOOL_NUMPOOLS]
Definition: jmemmgr.cpp:224
access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
Definition: jmemmgr.cpp:739
do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
Definition: jmemmgr.cpp:673
union large_pool_struct FAR * large_pool_ptr
Definition: jmemmgr.cpp:83
request_virt_sarray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
Definition: jmemmgr.cpp:506
large_pool_ptr large_list[JPOOL_NUMPOOLS]
Definition: jmemmgr.cpp:104
int JSAMPARRAY int int num_rows
Definition: jpegint.h:370
#define JPP(arglist)
Definition: mrpt_jpeglib.h:815
#define JPOOL_NUMPOOLS
Definition: mrpt_jpeglib.h:747
union small_pool_struct * small_pool_ptr
Definition: jmemmgr.cpp:72
#define TRUE
Definition: jmorecfg.h:230
JDIMENSION rows_in_mem
Definition: jmemmgr.cpp:154
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:202
#define ALIGN_TYPE
Definition: jmemmgr.cpp:56
jvirt_barray_ptr virt_barray_list
Definition: jmemmgr.cpp:112
size_t bytes_left
Definition: jmemmgr.cpp:89
JBLOCKROW * JBLOCKARRAY
Definition: mrpt_jpeglib.h:69
size_t total_space_allocated
Definition: jmemmgr.cpp:115
jpeg_mem_available(j_common_ptr, long, long max_bytes_needed, long)
Definition: jmemnobs.cpp:65
free_pool(j_common_ptr cinfo, int pool_id)
Definition: jmemmgr.cpp:913
small_pool_ptr next
Definition: jmemmgr.cpp:76
jpeg_mem_term(j_common_ptr)
Definition: jmemnobs.cpp:98
backing_store_info b_s_info
Definition: jmemmgr.cpp:162
JDIMENSION cur_start_row
Definition: jmemmgr.cpp:156
alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
Definition: jmemmgr.cpp:240
#define GLOBAL(type)
Definition: jmorecfg.h:185
size_t bytes_used
Definition: jmemmgr.cpp:88
jpeg_free_large(j_common_ptr, void FAR *object, size_t)
Definition: jmemnobs.cpp:53
JDIMENSION rowsperchunk
Definition: jmemmgr.cpp:155
#define METHODDEF(type)
Definition: jmorecfg.h:181
struct small_pool_struct::@77 hdr
GLuint const GLchar * name
Definition: glext.h:3891
JBLOCK FAR * JBLOCKROW
Definition: mrpt_jpeglib.h:68
backing_store_info b_s_info
Definition: jmemmgr.cpp:146
unsigned int JDIMENSION
Definition: jmorecfg.h:168
#define FAR
Definition: zconf.h:261
#define MAX_ALLOC_CHUNK
Definition: jmemsys.h:67
jpeg_get_large(j_common_ptr, size_t sizeofobject)
Definition: jmemnobs.cpp:47
alloc_large(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
Definition: jmemmgr.cpp:325
#define MIN_SLOP
Definition: jmemmgr.cpp:236
JCOEF JBLOCK[DCTSIZE2]
Definition: mrpt_jpeglib.h:67
small_pool_ptr small_list[JPOOL_NUMPOOLS]
Definition: jmemmgr.cpp:103
struct jvirt_sarray_control * jvirt_sarray_ptr
Definition: mrpt_jpeglib.h:749
alloc_barray(j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
Definition: jmemmgr.cpp:426
JDIMENSION samplesperrow
Definition: jmemmgr.cpp:136
out_of_memory(j_common_ptr cinfo, int which)
Definition: jmemmgr.cpp:200
JDIMENSION first_undef_row
Definition: jmemmgr.cpp:157



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019