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 * jdtrans.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1995-1997, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * Modified 2000-2009 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 library routines for transcoding decompression,
shoaib_ahmed 0:791a779d6220 10 * that is, reading raw DCT coefficient arrays from an input JPEG file.
shoaib_ahmed 0:791a779d6220 11 * The routines in jdapimin.c will also be needed by a transcoder.
shoaib_ahmed 0:791a779d6220 12 */
shoaib_ahmed 0:791a779d6220 13
shoaib_ahmed 0:791a779d6220 14 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 15 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 16 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 17
shoaib_ahmed 0:791a779d6220 18
shoaib_ahmed 0:791a779d6220 19 /* Forward declarations */
shoaib_ahmed 0:791a779d6220 20 LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
shoaib_ahmed 0:791a779d6220 21
shoaib_ahmed 0:791a779d6220 22
shoaib_ahmed 0:791a779d6220 23 /*
shoaib_ahmed 0:791a779d6220 24 * Read the coefficient arrays from a JPEG file.
shoaib_ahmed 0:791a779d6220 25 * jpeg_read_header must be completed before calling this.
shoaib_ahmed 0:791a779d6220 26 *
shoaib_ahmed 0:791a779d6220 27 * The entire image is read into a set of virtual coefficient-block arrays,
shoaib_ahmed 0:791a779d6220 28 * one per component. The return value is a pointer to the array of
shoaib_ahmed 0:791a779d6220 29 * virtual-array descriptors. These can be manipulated directly via the
shoaib_ahmed 0:791a779d6220 30 * JPEG memory manager, or handed off to jpeg_write_coefficients().
shoaib_ahmed 0:791a779d6220 31 * To release the memory occupied by the virtual arrays, call
shoaib_ahmed 0:791a779d6220 32 * jpeg_finish_decompress() when done with the data.
shoaib_ahmed 0:791a779d6220 33 *
shoaib_ahmed 0:791a779d6220 34 * An alternative usage is to simply obtain access to the coefficient arrays
shoaib_ahmed 0:791a779d6220 35 * during a buffered-image-mode decompression operation. This is allowed
shoaib_ahmed 0:791a779d6220 36 * after any jpeg_finish_output() call. The arrays can be accessed until
shoaib_ahmed 0:791a779d6220 37 * jpeg_finish_decompress() is called. (Note that any call to the library
shoaib_ahmed 0:791a779d6220 38 * may reposition the arrays, so don't rely on access_virt_barray() results
shoaib_ahmed 0:791a779d6220 39 * to stay valid across library calls.)
shoaib_ahmed 0:791a779d6220 40 *
shoaib_ahmed 0:791a779d6220 41 * Returns NULL if suspended. This case need be checked only if
shoaib_ahmed 0:791a779d6220 42 * a suspending data source is used.
shoaib_ahmed 0:791a779d6220 43 */
shoaib_ahmed 0:791a779d6220 44
shoaib_ahmed 0:791a779d6220 45 GLOBAL(jvirt_barray_ptr *)
shoaib_ahmed 0:791a779d6220 46 jpeg_read_coefficients (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 47 {
shoaib_ahmed 0:791a779d6220 48 if (cinfo->global_state == DSTATE_READY) {
shoaib_ahmed 0:791a779d6220 49 /* First call: initialize active modules */
shoaib_ahmed 0:791a779d6220 50 transdecode_master_selection(cinfo);
shoaib_ahmed 0:791a779d6220 51 cinfo->global_state = DSTATE_RDCOEFS;
shoaib_ahmed 0:791a779d6220 52 }
shoaib_ahmed 0:791a779d6220 53 if (cinfo->global_state == DSTATE_RDCOEFS) {
shoaib_ahmed 0:791a779d6220 54 /* Absorb whole file into the coef buffer */
shoaib_ahmed 0:791a779d6220 55 for (;;) {
shoaib_ahmed 0:791a779d6220 56 int retcode;
shoaib_ahmed 0:791a779d6220 57 /* Call progress monitor hook if present */
shoaib_ahmed 0:791a779d6220 58 if (cinfo->progress != NULL)
shoaib_ahmed 0:791a779d6220 59 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 60 /* Absorb some more input */
shoaib_ahmed 0:791a779d6220 61 retcode = (*cinfo->inputctl->consume_input) (cinfo);
shoaib_ahmed 0:791a779d6220 62 if (retcode == JPEG_SUSPENDED)
shoaib_ahmed 0:791a779d6220 63 return NULL;
shoaib_ahmed 0:791a779d6220 64 if (retcode == JPEG_REACHED_EOI)
shoaib_ahmed 0:791a779d6220 65 break;
shoaib_ahmed 0:791a779d6220 66 /* Advance progress counter if appropriate */
shoaib_ahmed 0:791a779d6220 67 if (cinfo->progress != NULL &&
shoaib_ahmed 0:791a779d6220 68 (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
shoaib_ahmed 0:791a779d6220 69 if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
shoaib_ahmed 0:791a779d6220 70 /* startup underestimated number of scans; ratchet up one scan */
shoaib_ahmed 0:791a779d6220 71 cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
shoaib_ahmed 0:791a779d6220 72 }
shoaib_ahmed 0:791a779d6220 73 }
shoaib_ahmed 0:791a779d6220 74 }
shoaib_ahmed 0:791a779d6220 75 /* Set state so that jpeg_finish_decompress does the right thing */
shoaib_ahmed 0:791a779d6220 76 cinfo->global_state = DSTATE_STOPPING;
shoaib_ahmed 0:791a779d6220 77 }
shoaib_ahmed 0:791a779d6220 78 /* At this point we should be in state DSTATE_STOPPING if being used
shoaib_ahmed 0:791a779d6220 79 * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
shoaib_ahmed 0:791a779d6220 80 * to the coefficients during a full buffered-image-mode decompression.
shoaib_ahmed 0:791a779d6220 81 */
shoaib_ahmed 0:791a779d6220 82 if ((cinfo->global_state == DSTATE_STOPPING ||
shoaib_ahmed 0:791a779d6220 83 cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
shoaib_ahmed 0:791a779d6220 84 return cinfo->coef->coef_arrays;
shoaib_ahmed 0:791a779d6220 85 }
shoaib_ahmed 0:791a779d6220 86 /* Oops, improper usage */
shoaib_ahmed 0:791a779d6220 87 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
shoaib_ahmed 0:791a779d6220 88 return NULL; /* keep compiler happy */
shoaib_ahmed 0:791a779d6220 89 }
shoaib_ahmed 0:791a779d6220 90
shoaib_ahmed 0:791a779d6220 91
shoaib_ahmed 0:791a779d6220 92 /*
shoaib_ahmed 0:791a779d6220 93 * Master selection of decompression modules for transcoding.
shoaib_ahmed 0:791a779d6220 94 * This substitutes for jdmaster.c's initialization of the full decompressor.
shoaib_ahmed 0:791a779d6220 95 */
shoaib_ahmed 0:791a779d6220 96
shoaib_ahmed 0:791a779d6220 97 LOCAL(void)
shoaib_ahmed 0:791a779d6220 98 transdecode_master_selection (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 99 {
shoaib_ahmed 0:791a779d6220 100 /* This is effectively a buffered-image operation. */
shoaib_ahmed 0:791a779d6220 101 cinfo->buffered_image = TRUE;
shoaib_ahmed 0:791a779d6220 102
shoaib_ahmed 0:791a779d6220 103 /* Compute output image dimensions and related values. */
shoaib_ahmed 0:791a779d6220 104 jpeg_core_output_dimensions(cinfo);
shoaib_ahmed 0:791a779d6220 105
shoaib_ahmed 0:791a779d6220 106 /* Entropy decoding: either Huffman or arithmetic coding. */
shoaib_ahmed 0:791a779d6220 107 if (cinfo->arith_code)
shoaib_ahmed 0:791a779d6220 108 jinit_arith_decoder(cinfo);
shoaib_ahmed 0:791a779d6220 109 else {
shoaib_ahmed 0:791a779d6220 110 jinit_huff_decoder(cinfo);
shoaib_ahmed 0:791a779d6220 111 }
shoaib_ahmed 0:791a779d6220 112
shoaib_ahmed 0:791a779d6220 113 /* Always get a full-image coefficient buffer. */
shoaib_ahmed 0:791a779d6220 114 jinit_d_coef_controller(cinfo, TRUE);
shoaib_ahmed 0:791a779d6220 115
shoaib_ahmed 0:791a779d6220 116 /* We can now tell the memory manager to allocate virtual arrays. */
shoaib_ahmed 0:791a779d6220 117 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 118
shoaib_ahmed 0:791a779d6220 119 /* Initialize input side of decompressor to consume first scan. */
shoaib_ahmed 0:791a779d6220 120 (*cinfo->inputctl->start_input_pass) (cinfo);
shoaib_ahmed 0:791a779d6220 121
shoaib_ahmed 0:791a779d6220 122 /* Initialize progress monitoring. */
shoaib_ahmed 0:791a779d6220 123 if (cinfo->progress != NULL) {
shoaib_ahmed 0:791a779d6220 124 int nscans;
shoaib_ahmed 0:791a779d6220 125 /* Estimate number of scans to set pass_limit. */
shoaib_ahmed 0:791a779d6220 126 if (cinfo->progressive_mode) {
shoaib_ahmed 0:791a779d6220 127 /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
shoaib_ahmed 0:791a779d6220 128 nscans = 2 + 3 * cinfo->num_components;
shoaib_ahmed 0:791a779d6220 129 } else if (cinfo->inputctl->has_multiple_scans) {
shoaib_ahmed 0:791a779d6220 130 /* For a nonprogressive multiscan file, estimate 1 scan per component. */
shoaib_ahmed 0:791a779d6220 131 nscans = cinfo->num_components;
shoaib_ahmed 0:791a779d6220 132 } else {
shoaib_ahmed 0:791a779d6220 133 nscans = 1;
shoaib_ahmed 0:791a779d6220 134 }
shoaib_ahmed 0:791a779d6220 135 cinfo->progress->pass_counter = 0L;
shoaib_ahmed 0:791a779d6220 136 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
shoaib_ahmed 0:791a779d6220 137 cinfo->progress->completed_passes = 0;
shoaib_ahmed 0:791a779d6220 138 cinfo->progress->total_passes = 1;
shoaib_ahmed 0:791a779d6220 139 }
shoaib_ahmed 0:791a779d6220 140 }