Turned libjpeg into a shared library (pertask).
[AROS.git] / workbench / libs / jpeg / jmemamiga.c
blob3ece66c024748ee79be46fc03921e72518ba8a8b
1 /*
2 * jmemamiga.c
4 * Copyright (C) 1992-1996, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
8 * Copyright (C) 2009-2011, The AROS development team.
10 * This file provides a simple implementation of the system-dependent portion
11 * of the JPEG memory manager using the Amiga API. This implementation
12 * assumes that no backing-store files are needed: all required space
13 * can be obtained from the system.
14 * You'll need to have lots of main memory (or virtual memory) if you want
15 * to process big images.
16 * Note that the max_memory_to_use option is ignored by this implementation.
19 #include <proto/exec.h>
20 #include <exec/memory.h>
21 #include <exec/types.h>
23 static APTR _mempool;
25 #if defined(__AROS__)
26 #undef GLOBAL
27 #endif
29 #define JPEG_INTERNALS
30 #include "jinclude.h"
31 #include "jpeglib.h"
32 #include "jmemsys.h" /* import the system-dependent declarations */
35 * Memory allocation and freeing are controlled by the regular library
36 * routines malloc() and free().
39 GLOBAL(void *)
40 jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
42 return (void *) AllocPooled(_mempool, sizeofobject);
45 GLOBAL(void)
46 jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
48 FreePooled(_mempool, object, sizeofobject);
53 * "Large" objects are treated the same as "small" ones.
54 * NB: although we include FAR keywords in the routine declarations,
55 * this file won't actually work in 80x86 small/medium model; at least,
56 * you probably won't be able to process useful-size images in only 64KB.
59 GLOBAL(void FAR *)
60 jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
62 return (void FAR *) AllocPooled(_mempool, sizeofobject);
65 GLOBAL(void)
66 jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
68 FreePooled(_mempool, object, sizeofobject);
73 * This routine computes the total memory space available for allocation.
74 * Here we always say, "we got all you want bud!"
77 GLOBAL(long)
78 jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
79 long max_bytes_needed, long already_allocated)
81 long avail = (long)AvailMem(MEMF_LARGEST);
83 return max_bytes_needed > avail ? avail : max_bytes_needed;
88 * Backing store (temporary file) management.
89 * Since jpeg_mem_available always promised the moon,
90 * this should never be called and we can just error out.
93 GLOBAL(void)
94 jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
95 long total_bytes_needed)
97 ERREXIT(cinfo, JERR_NO_BACKING_STORE);
102 * These routines take care of any system-dependent initialization and
103 * cleanup required.
106 GLOBAL(long)
107 jpeg_mem_init (j_common_ptr cinfo)
109 _mempool = CreatePool(MEMF_ANY | MEMF_SEM_PROTECTED, 65536L, 4096L);
111 return AvailMem(MEMF_LARGEST);
114 GLOBAL(void)
115 jpeg_mem_term (j_common_ptr cinfo)
117 DeletePool(_mempool);