Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shoaib_ahmed 0:791a779d6220 1 /*
shoaib_ahmed 0:791a779d6220 2 * jmemansi.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1992-1996, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 6 * For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 7 *
shoaib_ahmed 0:791a779d6220 8 * This file provides a simple generic implementation of the system-
shoaib_ahmed 0:791a779d6220 9 * dependent portion of the JPEG memory manager. This implementation
shoaib_ahmed 0:791a779d6220 10 * assumes that you have the ANSI-standard library routine tmpfile().
shoaib_ahmed 0:791a779d6220 11 * Also, the problem of determining the amount of memory available
shoaib_ahmed 0:791a779d6220 12 * is shoved onto the user.
shoaib_ahmed 0:791a779d6220 13 */
shoaib_ahmed 0:791a779d6220 14
shoaib_ahmed 0:791a779d6220 15 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 16 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 17 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 18 #include "jmemsys.h" /* import the system-dependent declarations */
shoaib_ahmed 0:791a779d6220 19
shoaib_ahmed 0:791a779d6220 20 #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
shoaib_ahmed 0:791a779d6220 21 extern void * malloc JPP((size_t size));
shoaib_ahmed 0:791a779d6220 22 extern void free JPP((void *ptr));
shoaib_ahmed 0:791a779d6220 23 #endif
shoaib_ahmed 0:791a779d6220 24
shoaib_ahmed 0:791a779d6220 25 #ifndef SEEK_SET /* pre-ANSI systems may not define this; */
shoaib_ahmed 0:791a779d6220 26 #define SEEK_SET 0 /* if not, assume 0 is correct */
shoaib_ahmed 0:791a779d6220 27 #endif
shoaib_ahmed 0:791a779d6220 28
shoaib_ahmed 0:791a779d6220 29
shoaib_ahmed 0:791a779d6220 30 /*
shoaib_ahmed 0:791a779d6220 31 * Memory allocation and freeing are controlled by the regular library
shoaib_ahmed 0:791a779d6220 32 * routines malloc() and free().
shoaib_ahmed 0:791a779d6220 33 */
shoaib_ahmed 0:791a779d6220 34
shoaib_ahmed 0:791a779d6220 35 GLOBAL(void *)
shoaib_ahmed 0:791a779d6220 36 jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
shoaib_ahmed 0:791a779d6220 37 {
shoaib_ahmed 0:791a779d6220 38 return (void *) malloc(sizeofobject);
shoaib_ahmed 0:791a779d6220 39 }
shoaib_ahmed 0:791a779d6220 40
shoaib_ahmed 0:791a779d6220 41 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 42 jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
shoaib_ahmed 0:791a779d6220 43 {
shoaib_ahmed 0:791a779d6220 44 free(object);
shoaib_ahmed 0:791a779d6220 45 }
shoaib_ahmed 0:791a779d6220 46
shoaib_ahmed 0:791a779d6220 47
shoaib_ahmed 0:791a779d6220 48 /*
shoaib_ahmed 0:791a779d6220 49 * "Large" objects are treated the same as "small" ones.
shoaib_ahmed 0:791a779d6220 50 * NB: although we include FAR keywords in the routine declarations,
shoaib_ahmed 0:791a779d6220 51 * this file won't actually work in 80x86 small/medium model; at least,
shoaib_ahmed 0:791a779d6220 52 * you probably won't be able to process useful-size images in only 64KB.
shoaib_ahmed 0:791a779d6220 53 */
shoaib_ahmed 0:791a779d6220 54
shoaib_ahmed 0:791a779d6220 55 GLOBAL(void FAR *)
shoaib_ahmed 0:791a779d6220 56 jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
shoaib_ahmed 0:791a779d6220 57 {
shoaib_ahmed 0:791a779d6220 58 return (void FAR *) malloc(sizeofobject);
shoaib_ahmed 0:791a779d6220 59 }
shoaib_ahmed 0:791a779d6220 60
shoaib_ahmed 0:791a779d6220 61 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 62 jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
shoaib_ahmed 0:791a779d6220 63 {
shoaib_ahmed 0:791a779d6220 64 free(object);
shoaib_ahmed 0:791a779d6220 65 }
shoaib_ahmed 0:791a779d6220 66
shoaib_ahmed 0:791a779d6220 67
shoaib_ahmed 0:791a779d6220 68 /*
shoaib_ahmed 0:791a779d6220 69 * This routine computes the total memory space available for allocation.
shoaib_ahmed 0:791a779d6220 70 * It's impossible to do this in a portable way; our current solution is
shoaib_ahmed 0:791a779d6220 71 * to make the user tell us (with a default value set at compile time).
shoaib_ahmed 0:791a779d6220 72 * If you can actually get the available space, it's a good idea to subtract
shoaib_ahmed 0:791a779d6220 73 * a slop factor of 5% or so.
shoaib_ahmed 0:791a779d6220 74 */
shoaib_ahmed 0:791a779d6220 75
shoaib_ahmed 0:791a779d6220 76 #ifndef DEFAULT_MAX_MEM /* so can override from makefile */
shoaib_ahmed 0:791a779d6220 77 #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */
shoaib_ahmed 0:791a779d6220 78 #endif
shoaib_ahmed 0:791a779d6220 79
shoaib_ahmed 0:791a779d6220 80 GLOBAL(long)
shoaib_ahmed 0:791a779d6220 81 jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
shoaib_ahmed 0:791a779d6220 82 long max_bytes_needed, long already_allocated)
shoaib_ahmed 0:791a779d6220 83 {
shoaib_ahmed 0:791a779d6220 84 return cinfo->mem->max_memory_to_use - already_allocated;
shoaib_ahmed 0:791a779d6220 85 }
shoaib_ahmed 0:791a779d6220 86
shoaib_ahmed 0:791a779d6220 87
shoaib_ahmed 0:791a779d6220 88 /*
shoaib_ahmed 0:791a779d6220 89 * Backing store (temporary file) management.
shoaib_ahmed 0:791a779d6220 90 * Backing store objects are only used when the value returned by
shoaib_ahmed 0:791a779d6220 91 * jpeg_mem_available is less than the total space needed. You can dispense
shoaib_ahmed 0:791a779d6220 92 * with these routines if you have plenty of virtual memory; see jmemnobs.c.
shoaib_ahmed 0:791a779d6220 93 */
shoaib_ahmed 0:791a779d6220 94
shoaib_ahmed 0:791a779d6220 95
shoaib_ahmed 0:791a779d6220 96 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 97 read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
shoaib_ahmed 0:791a779d6220 98 void FAR * buffer_address,
shoaib_ahmed 0:791a779d6220 99 long file_offset, long byte_count)
shoaib_ahmed 0:791a779d6220 100 {
shoaib_ahmed 0:791a779d6220 101 if (fseek(info->temp_file, file_offset, SEEK_SET))
shoaib_ahmed 0:791a779d6220 102 ERREXIT(cinfo, JERR_TFILE_SEEK);
shoaib_ahmed 0:791a779d6220 103 if (JFREAD(info->temp_file, buffer_address, byte_count)
shoaib_ahmed 0:791a779d6220 104 != (size_t) byte_count)
shoaib_ahmed 0:791a779d6220 105 ERREXIT(cinfo, JERR_TFILE_READ);
shoaib_ahmed 0:791a779d6220 106 }
shoaib_ahmed 0:791a779d6220 107
shoaib_ahmed 0:791a779d6220 108
shoaib_ahmed 0:791a779d6220 109 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 110 write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
shoaib_ahmed 0:791a779d6220 111 void FAR * buffer_address,
shoaib_ahmed 0:791a779d6220 112 long file_offset, long byte_count)
shoaib_ahmed 0:791a779d6220 113 {
shoaib_ahmed 0:791a779d6220 114 if (fseek(info->temp_file, file_offset, SEEK_SET))
shoaib_ahmed 0:791a779d6220 115 ERREXIT(cinfo, JERR_TFILE_SEEK);
shoaib_ahmed 0:791a779d6220 116 if (JFWRITE(info->temp_file, buffer_address, byte_count)
shoaib_ahmed 0:791a779d6220 117 != (size_t) byte_count)
shoaib_ahmed 0:791a779d6220 118 ERREXIT(cinfo, JERR_TFILE_WRITE);
shoaib_ahmed 0:791a779d6220 119 }
shoaib_ahmed 0:791a779d6220 120
shoaib_ahmed 0:791a779d6220 121
shoaib_ahmed 0:791a779d6220 122 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 123 close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
shoaib_ahmed 0:791a779d6220 124 {
shoaib_ahmed 0:791a779d6220 125 fclose(info->temp_file);
shoaib_ahmed 0:791a779d6220 126 /* Since this implementation uses tmpfile() to create the file,
shoaib_ahmed 0:791a779d6220 127 * no explicit file deletion is needed.
shoaib_ahmed 0:791a779d6220 128 */
shoaib_ahmed 0:791a779d6220 129 }
shoaib_ahmed 0:791a779d6220 130
shoaib_ahmed 0:791a779d6220 131
shoaib_ahmed 0:791a779d6220 132 /*
shoaib_ahmed 0:791a779d6220 133 * Initial opening of a backing-store object.
shoaib_ahmed 0:791a779d6220 134 *
shoaib_ahmed 0:791a779d6220 135 * This version uses tmpfile(), which constructs a suitable file name
shoaib_ahmed 0:791a779d6220 136 * behind the scenes. We don't have to use info->temp_name[] at all;
shoaib_ahmed 0:791a779d6220 137 * indeed, we can't even find out the actual name of the temp file.
shoaib_ahmed 0:791a779d6220 138 */
shoaib_ahmed 0:791a779d6220 139
shoaib_ahmed 0:791a779d6220 140 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 141 jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
shoaib_ahmed 0:791a779d6220 142 long total_bytes_needed)
shoaib_ahmed 0:791a779d6220 143 {
shoaib_ahmed 0:791a779d6220 144 if ((info->temp_file = tmpfile()) == NULL)
shoaib_ahmed 0:791a779d6220 145 ERREXITS(cinfo, JERR_TFILE_CREATE, "");
shoaib_ahmed 0:791a779d6220 146 info->read_backing_store = read_backing_store;
shoaib_ahmed 0:791a779d6220 147 info->write_backing_store = write_backing_store;
shoaib_ahmed 0:791a779d6220 148 info->close_backing_store = close_backing_store;
shoaib_ahmed 0:791a779d6220 149 }
shoaib_ahmed 0:791a779d6220 150
shoaib_ahmed 0:791a779d6220 151
shoaib_ahmed 0:791a779d6220 152 /*
shoaib_ahmed 0:791a779d6220 153 * These routines take care of any system-dependent initialization and
shoaib_ahmed 0:791a779d6220 154 * cleanup required.
shoaib_ahmed 0:791a779d6220 155 */
shoaib_ahmed 0:791a779d6220 156
shoaib_ahmed 0:791a779d6220 157 GLOBAL(long)
shoaib_ahmed 0:791a779d6220 158 jpeg_mem_init (j_common_ptr cinfo)
shoaib_ahmed 0:791a779d6220 159 {
shoaib_ahmed 0:791a779d6220 160 return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
shoaib_ahmed 0:791a779d6220 161 }
shoaib_ahmed 0:791a779d6220 162
shoaib_ahmed 0:791a779d6220 163 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 164 jpeg_mem_term (j_common_ptr cinfo)
shoaib_ahmed 0:791a779d6220 165 {
shoaib_ahmed 0:791a779d6220 166 /* no work */
shoaib_ahmed 0:791a779d6220 167 }