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 * jcapistd.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1994-1996, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * Modified 2013 by Guido Vollbeding.
shoaib_ahmed 0:791a779d6220 6 * This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 7 * For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 8 *
shoaib_ahmed 0:791a779d6220 9 * This file contains application interface code for the compression half
shoaib_ahmed 0:791a779d6220 10 * of the JPEG library. These are the "standard" API routines that are
shoaib_ahmed 0:791a779d6220 11 * used in the normal full-compression case. They are not used by a
shoaib_ahmed 0:791a779d6220 12 * transcoding-only application. Note that if an application links in
shoaib_ahmed 0:791a779d6220 13 * jpeg_start_compress, it will end up linking in the entire compressor.
shoaib_ahmed 0:791a779d6220 14 * We thus must separate this file from jcapimin.c to avoid linking the
shoaib_ahmed 0:791a779d6220 15 * whole compression library into a transcoder.
shoaib_ahmed 0:791a779d6220 16 */
shoaib_ahmed 0:791a779d6220 17
shoaib_ahmed 0:791a779d6220 18 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 19 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 20 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 21
shoaib_ahmed 0:791a779d6220 22
shoaib_ahmed 0:791a779d6220 23 /*
shoaib_ahmed 0:791a779d6220 24 * Compression initialization.
shoaib_ahmed 0:791a779d6220 25 * Before calling this, all parameters and a data destination must be set up.
shoaib_ahmed 0:791a779d6220 26 *
shoaib_ahmed 0:791a779d6220 27 * We require a write_all_tables parameter as a failsafe check when writing
shoaib_ahmed 0:791a779d6220 28 * multiple datastreams from the same compression object. Since prior runs
shoaib_ahmed 0:791a779d6220 29 * will have left all the tables marked sent_table=TRUE, a subsequent run
shoaib_ahmed 0:791a779d6220 30 * would emit an abbreviated stream (no tables) by default. This may be what
shoaib_ahmed 0:791a779d6220 31 * is wanted, but for safety's sake it should not be the default behavior:
shoaib_ahmed 0:791a779d6220 32 * programmers should have to make a deliberate choice to emit abbreviated
shoaib_ahmed 0:791a779d6220 33 * images. Therefore the documentation and examples should encourage people
shoaib_ahmed 0:791a779d6220 34 * to pass write_all_tables=TRUE; then it will take active thought to do the
shoaib_ahmed 0:791a779d6220 35 * wrong thing.
shoaib_ahmed 0:791a779d6220 36 */
shoaib_ahmed 0:791a779d6220 37
shoaib_ahmed 0:791a779d6220 38 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 39 jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
shoaib_ahmed 0:791a779d6220 40 {
shoaib_ahmed 0:791a779d6220 41 if (cinfo->global_state != CSTATE_START)
shoaib_ahmed 0:791a779d6220 42 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
shoaib_ahmed 0:791a779d6220 43
shoaib_ahmed 0:791a779d6220 44 if (write_all_tables)
shoaib_ahmed 0:791a779d6220 45 jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
shoaib_ahmed 0:791a779d6220 46
shoaib_ahmed 0:791a779d6220 47 /* (Re)initialize error mgr and destination modules */
shoaib_ahmed 0:791a779d6220 48 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 49 (*cinfo->dest->init_destination) (cinfo);
shoaib_ahmed 0:791a779d6220 50 /* Perform master selection of active modules */
shoaib_ahmed 0:791a779d6220 51 jinit_compress_master(cinfo);
shoaib_ahmed 0:791a779d6220 52 /* Set up for the first pass */
shoaib_ahmed 0:791a779d6220 53 (*cinfo->master->prepare_for_pass) (cinfo);
shoaib_ahmed 0:791a779d6220 54 /* Ready for application to drive first pass through jpeg_write_scanlines
shoaib_ahmed 0:791a779d6220 55 * or jpeg_write_raw_data.
shoaib_ahmed 0:791a779d6220 56 */
shoaib_ahmed 0:791a779d6220 57 cinfo->next_scanline = 0;
shoaib_ahmed 0:791a779d6220 58 cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
shoaib_ahmed 0:791a779d6220 59 }
shoaib_ahmed 0:791a779d6220 60
shoaib_ahmed 0:791a779d6220 61
shoaib_ahmed 0:791a779d6220 62 /*
shoaib_ahmed 0:791a779d6220 63 * Write some scanlines of data to the JPEG compressor.
shoaib_ahmed 0:791a779d6220 64 *
shoaib_ahmed 0:791a779d6220 65 * The return value will be the number of lines actually written.
shoaib_ahmed 0:791a779d6220 66 * This should be less than the supplied num_lines only in case that
shoaib_ahmed 0:791a779d6220 67 * the data destination module has requested suspension of the compressor,
shoaib_ahmed 0:791a779d6220 68 * or if more than image_height scanlines are passed in.
shoaib_ahmed 0:791a779d6220 69 *
shoaib_ahmed 0:791a779d6220 70 * Note: we warn about excess calls to jpeg_write_scanlines() since
shoaib_ahmed 0:791a779d6220 71 * this likely signals an application programmer error. However,
shoaib_ahmed 0:791a779d6220 72 * excess scanlines passed in the last valid call are *silently* ignored,
shoaib_ahmed 0:791a779d6220 73 * so that the application need not adjust num_lines for end-of-image
shoaib_ahmed 0:791a779d6220 74 * when using a multiple-scanline buffer.
shoaib_ahmed 0:791a779d6220 75 */
shoaib_ahmed 0:791a779d6220 76
shoaib_ahmed 0:791a779d6220 77 GLOBAL(JDIMENSION)
shoaib_ahmed 0:791a779d6220 78 jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
shoaib_ahmed 0:791a779d6220 79 JDIMENSION num_lines)
shoaib_ahmed 0:791a779d6220 80 {
shoaib_ahmed 0:791a779d6220 81 JDIMENSION row_ctr, rows_left;
shoaib_ahmed 0:791a779d6220 82
shoaib_ahmed 0:791a779d6220 83 if (cinfo->global_state != CSTATE_SCANNING)
shoaib_ahmed 0:791a779d6220 84 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
shoaib_ahmed 0:791a779d6220 85 if (cinfo->next_scanline >= cinfo->image_height)
shoaib_ahmed 0:791a779d6220 86 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
shoaib_ahmed 0:791a779d6220 87
shoaib_ahmed 0:791a779d6220 88 /* Call progress monitor hook if present */
shoaib_ahmed 0:791a779d6220 89 if (cinfo->progress != NULL) {
shoaib_ahmed 0:791a779d6220 90 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
shoaib_ahmed 0:791a779d6220 91 cinfo->progress->pass_limit = (long) cinfo->image_height;
shoaib_ahmed 0:791a779d6220 92 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 93 }
shoaib_ahmed 0:791a779d6220 94
shoaib_ahmed 0:791a779d6220 95 /* Give master control module another chance if this is first call to
shoaib_ahmed 0:791a779d6220 96 * jpeg_write_scanlines. This lets output of the frame/scan headers be
shoaib_ahmed 0:791a779d6220 97 * delayed so that application can write COM, etc, markers between
shoaib_ahmed 0:791a779d6220 98 * jpeg_start_compress and jpeg_write_scanlines.
shoaib_ahmed 0:791a779d6220 99 */
shoaib_ahmed 0:791a779d6220 100 if (cinfo->master->call_pass_startup)
shoaib_ahmed 0:791a779d6220 101 (*cinfo->master->pass_startup) (cinfo);
shoaib_ahmed 0:791a779d6220 102
shoaib_ahmed 0:791a779d6220 103 /* Ignore any extra scanlines at bottom of image. */
shoaib_ahmed 0:791a779d6220 104 rows_left = cinfo->image_height - cinfo->next_scanline;
shoaib_ahmed 0:791a779d6220 105 if (num_lines > rows_left)
shoaib_ahmed 0:791a779d6220 106 num_lines = rows_left;
shoaib_ahmed 0:791a779d6220 107
shoaib_ahmed 0:791a779d6220 108 row_ctr = 0;
shoaib_ahmed 0:791a779d6220 109 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
shoaib_ahmed 0:791a779d6220 110 cinfo->next_scanline += row_ctr;
shoaib_ahmed 0:791a779d6220 111 return row_ctr;
shoaib_ahmed 0:791a779d6220 112 }
shoaib_ahmed 0:791a779d6220 113
shoaib_ahmed 0:791a779d6220 114
shoaib_ahmed 0:791a779d6220 115 /*
shoaib_ahmed 0:791a779d6220 116 * Alternate entry point to write raw data.
shoaib_ahmed 0:791a779d6220 117 * Processes exactly one iMCU row per call, unless suspended.
shoaib_ahmed 0:791a779d6220 118 */
shoaib_ahmed 0:791a779d6220 119
shoaib_ahmed 0:791a779d6220 120 GLOBAL(JDIMENSION)
shoaib_ahmed 0:791a779d6220 121 jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
shoaib_ahmed 0:791a779d6220 122 JDIMENSION num_lines)
shoaib_ahmed 0:791a779d6220 123 {
shoaib_ahmed 0:791a779d6220 124 JDIMENSION lines_per_iMCU_row;
shoaib_ahmed 0:791a779d6220 125
shoaib_ahmed 0:791a779d6220 126 if (cinfo->global_state != CSTATE_RAW_OK)
shoaib_ahmed 0:791a779d6220 127 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
shoaib_ahmed 0:791a779d6220 128 if (cinfo->next_scanline >= cinfo->image_height) {
shoaib_ahmed 0:791a779d6220 129 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
shoaib_ahmed 0:791a779d6220 130 return 0;
shoaib_ahmed 0:791a779d6220 131 }
shoaib_ahmed 0:791a779d6220 132
shoaib_ahmed 0:791a779d6220 133 /* Call progress monitor hook if present */
shoaib_ahmed 0:791a779d6220 134 if (cinfo->progress != NULL) {
shoaib_ahmed 0:791a779d6220 135 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
shoaib_ahmed 0:791a779d6220 136 cinfo->progress->pass_limit = (long) cinfo->image_height;
shoaib_ahmed 0:791a779d6220 137 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 138 }
shoaib_ahmed 0:791a779d6220 139
shoaib_ahmed 0:791a779d6220 140 /* Give master control module another chance if this is first call to
shoaib_ahmed 0:791a779d6220 141 * jpeg_write_raw_data. This lets output of the frame/scan headers be
shoaib_ahmed 0:791a779d6220 142 * delayed so that application can write COM, etc, markers between
shoaib_ahmed 0:791a779d6220 143 * jpeg_start_compress and jpeg_write_raw_data.
shoaib_ahmed 0:791a779d6220 144 */
shoaib_ahmed 0:791a779d6220 145 if (cinfo->master->call_pass_startup)
shoaib_ahmed 0:791a779d6220 146 (*cinfo->master->pass_startup) (cinfo);
shoaib_ahmed 0:791a779d6220 147
shoaib_ahmed 0:791a779d6220 148 /* Verify that at least one iMCU row has been passed. */
shoaib_ahmed 0:791a779d6220 149 lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
shoaib_ahmed 0:791a779d6220 150 if (num_lines < lines_per_iMCU_row)
shoaib_ahmed 0:791a779d6220 151 ERREXIT(cinfo, JERR_BUFFER_SIZE);
shoaib_ahmed 0:791a779d6220 152
shoaib_ahmed 0:791a779d6220 153 /* Directly compress the row. */
shoaib_ahmed 0:791a779d6220 154 if (! (*cinfo->coef->compress_data) (cinfo, data)) {
shoaib_ahmed 0:791a779d6220 155 /* If compressor did not consume the whole row, suspend processing. */
shoaib_ahmed 0:791a779d6220 156 return 0;
shoaib_ahmed 0:791a779d6220 157 }
shoaib_ahmed 0:791a779d6220 158
shoaib_ahmed 0:791a779d6220 159 /* OK, we processed one iMCU row. */
shoaib_ahmed 0:791a779d6220 160 cinfo->next_scanline += lines_per_iMCU_row;
shoaib_ahmed 0:791a779d6220 161 return lines_per_iMCU_row;
shoaib_ahmed 0:791a779d6220 162 }