| 1 | /* | 
|---|
| 2 | * reserved comment block | 
|---|
| 3 | * DO NOT REMOVE OR ALTER! | 
|---|
| 4 | */ | 
|---|
| 5 | /* | 
|---|
| 6 | * jmemnobs.c | 
|---|
| 7 | * | 
|---|
| 8 | * Copyright (C) 1992-1996, Thomas G. Lane. | 
|---|
| 9 | * This file is part of the Independent JPEG Group's software. | 
|---|
| 10 | * For conditions of distribution and use, see the accompanying README file. | 
|---|
| 11 | * | 
|---|
| 12 | * This file provides a really simple implementation of the system- | 
|---|
| 13 | * dependent portion of the JPEG memory manager.  This implementation | 
|---|
| 14 | * assumes that no backing-store files are needed: all required space | 
|---|
| 15 | * can be obtained from malloc(). | 
|---|
| 16 | * This is very portable in the sense that it'll compile on almost anything, | 
|---|
| 17 | * but you'd better have lots of main memory (or virtual memory) if you want | 
|---|
| 18 | * to process big images. | 
|---|
| 19 | * Note that the max_memory_to_use option is ignored by this implementation. | 
|---|
| 20 | */ | 
|---|
| 21 |  | 
|---|
| 22 | #define JPEG_INTERNALS | 
|---|
| 23 | #include "jinclude.h" | 
|---|
| 24 | #include "jpeglib.h" | 
|---|
| 25 | #include "jmemsys.h"            /* import the system-dependent declarations */ | 
|---|
| 26 |  | 
|---|
| 27 | #ifndef HAVE_STDLIB_H           /* <stdlib.h> should declare malloc(),free() */ | 
|---|
| 28 | extern void * malloc JPP((size_t size)); | 
|---|
| 29 | extern void free JPP((void *ptr)); | 
|---|
| 30 | #endif | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 | /* | 
|---|
| 34 | * Memory allocation and freeing are controlled by the regular library | 
|---|
| 35 | * routines malloc() and free(). | 
|---|
| 36 | */ | 
|---|
| 37 |  | 
|---|
| 38 | GLOBAL(void *) | 
|---|
| 39 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) | 
|---|
| 40 | { | 
|---|
| 41 | return (void *) malloc(sizeofobject); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | GLOBAL(void) | 
|---|
| 45 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) | 
|---|
| 46 | { | 
|---|
| 47 | free(object); | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 | /* | 
|---|
| 52 | * "Large" objects are treated the same as "small" ones. | 
|---|
| 53 | * NB: although we include FAR keywords in the routine declarations, | 
|---|
| 54 | * this file won't actually work in 80x86 small/medium model; at least, | 
|---|
| 55 | * you probably won't be able to process useful-size images in only 64KB. | 
|---|
| 56 | */ | 
|---|
| 57 |  | 
|---|
| 58 | GLOBAL(void FAR *) | 
|---|
| 59 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) | 
|---|
| 60 | { | 
|---|
| 61 | return (void FAR *) malloc(sizeofobject); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | GLOBAL(void) | 
|---|
| 65 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) | 
|---|
| 66 | { | 
|---|
| 67 | free(object); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | /* | 
|---|
| 72 | * This routine computes the total memory space available for allocation. | 
|---|
| 73 | * Here we always say, "we got all you want bud!" | 
|---|
| 74 | */ | 
|---|
| 75 |  | 
|---|
| 76 | GLOBAL(size_t) | 
|---|
| 77 | jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, | 
|---|
| 78 | size_t max_bytes_needed, size_t already_allocated) | 
|---|
| 79 | { | 
|---|
| 80 | return max_bytes_needed; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 |  | 
|---|
| 84 | /* | 
|---|
| 85 | * Backing store (temporary file) management. | 
|---|
| 86 | * Since jpeg_mem_available always promised the moon, | 
|---|
| 87 | * this should never be called and we can just error out. | 
|---|
| 88 | */ | 
|---|
| 89 |  | 
|---|
| 90 | GLOBAL(void) | 
|---|
| 91 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, | 
|---|
| 92 | long total_bytes_needed) | 
|---|
| 93 | { | 
|---|
| 94 | ERREXIT(cinfo, JERR_NO_BACKING_STORE); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | /* | 
|---|
| 99 | * These routines take care of any system-dependent initialization and | 
|---|
| 100 | * cleanup required.  Here, there isn't any. | 
|---|
| 101 | */ | 
|---|
| 102 |  | 
|---|
| 103 | GLOBAL(size_t) | 
|---|
| 104 | jpeg_mem_init (j_common_ptr cinfo) | 
|---|
| 105 | { | 
|---|
| 106 | return 0;                     /* just set max_memory_to_use to 0 */ | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | GLOBAL(void) | 
|---|
| 110 | jpeg_mem_term (j_common_ptr cinfo) | 
|---|
| 111 | { | 
|---|
| 112 | /* no work */ | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|