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 IJG JPEG LIBRARY: CODING RULES
shoaib_ahmed 0:791a779d6220 2
shoaib_ahmed 0:791a779d6220 3 Copyright (C) 1991-1996, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 4 This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 5 For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 6
shoaib_ahmed 0:791a779d6220 7
shoaib_ahmed 0:791a779d6220 8 Since numerous people will be contributing code and bug fixes, it's important
shoaib_ahmed 0:791a779d6220 9 to establish a common coding style. The goal of using similar coding styles
shoaib_ahmed 0:791a779d6220 10 is much more important than the details of just what that style is.
shoaib_ahmed 0:791a779d6220 11
shoaib_ahmed 0:791a779d6220 12 In general we follow the recommendations of "Recommended C Style and Coding
shoaib_ahmed 0:791a779d6220 13 Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
shoaib_ahmed 0:791a779d6220 14 Brader). This document is available in the IJG FTP archive (see
shoaib_ahmed 0:791a779d6220 15 jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
shoaib_ahmed 0:791a779d6220 16
shoaib_ahmed 0:791a779d6220 17 Block comments should be laid out thusly:
shoaib_ahmed 0:791a779d6220 18
shoaib_ahmed 0:791a779d6220 19 /*
shoaib_ahmed 0:791a779d6220 20 * Block comments in this style.
shoaib_ahmed 0:791a779d6220 21 */
shoaib_ahmed 0:791a779d6220 22
shoaib_ahmed 0:791a779d6220 23 We indent statements in K&R style, e.g.,
shoaib_ahmed 0:791a779d6220 24 if (test) {
shoaib_ahmed 0:791a779d6220 25 then-part;
shoaib_ahmed 0:791a779d6220 26 } else {
shoaib_ahmed 0:791a779d6220 27 else-part;
shoaib_ahmed 0:791a779d6220 28 }
shoaib_ahmed 0:791a779d6220 29 with two spaces per indentation level. (This indentation convention is
shoaib_ahmed 0:791a779d6220 30 handled automatically by GNU Emacs and many other text editors.)
shoaib_ahmed 0:791a779d6220 31
shoaib_ahmed 0:791a779d6220 32 Multi-word names should be written in lower case with underscores, e.g.,
shoaib_ahmed 0:791a779d6220 33 multi_word_name (not multiWordName). Preprocessor symbols and enum constants
shoaib_ahmed 0:791a779d6220 34 are similar but upper case (MULTI_WORD_NAME). Names should be unique within
shoaib_ahmed 0:791a779d6220 35 the first fifteen characters. (On some older systems, global names must be
shoaib_ahmed 0:791a779d6220 36 unique within six characters. We accommodate this without cluttering the
shoaib_ahmed 0:791a779d6220 37 source code by using macros to substitute shorter names.)
shoaib_ahmed 0:791a779d6220 38
shoaib_ahmed 0:791a779d6220 39 We use function prototypes everywhere; we rely on automatic source code
shoaib_ahmed 0:791a779d6220 40 transformation to feed prototype-less C compilers. Transformation is done
shoaib_ahmed 0:791a779d6220 41 by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript).
shoaib_ahmed 0:791a779d6220 42 ansi2knr is not very bright, so it imposes a format requirement on function
shoaib_ahmed 0:791a779d6220 43 declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions
shoaib_ahmed 0:791a779d6220 44 should be written in the following style:
shoaib_ahmed 0:791a779d6220 45
shoaib_ahmed 0:791a779d6220 46 LOCAL(int *)
shoaib_ahmed 0:791a779d6220 47 function_name (int a, char *b)
shoaib_ahmed 0:791a779d6220 48 {
shoaib_ahmed 0:791a779d6220 49 code...
shoaib_ahmed 0:791a779d6220 50 }
shoaib_ahmed 0:791a779d6220 51
shoaib_ahmed 0:791a779d6220 52 Note that each function definition must begin with GLOBAL(type), LOCAL(type),
shoaib_ahmed 0:791a779d6220 53 or METHODDEF(type). These macros expand to "static type" or just "type" as
shoaib_ahmed 0:791a779d6220 54 appropriate. They provide a readable indication of the routine's usage and
shoaib_ahmed 0:791a779d6220 55 can readily be changed for special needs. (For instance, special linkage
shoaib_ahmed 0:791a779d6220 56 keywords can be inserted for use in Windows DLLs.)
shoaib_ahmed 0:791a779d6220 57
shoaib_ahmed 0:791a779d6220 58 ansi2knr does not transform method declarations (function pointers in
shoaib_ahmed 0:791a779d6220 59 structs). We handle these with a macro JMETHOD, defined as
shoaib_ahmed 0:791a779d6220 60 #ifdef HAVE_PROTOTYPES
shoaib_ahmed 0:791a779d6220 61 #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
shoaib_ahmed 0:791a779d6220 62 #else
shoaib_ahmed 0:791a779d6220 63 #define JMETHOD(type,methodname,arglist) type (*methodname) ()
shoaib_ahmed 0:791a779d6220 64 #endif
shoaib_ahmed 0:791a779d6220 65 which is used like this:
shoaib_ahmed 0:791a779d6220 66 struct function_pointers {
shoaib_ahmed 0:791a779d6220 67 JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
shoaib_ahmed 0:791a779d6220 68 JMETHOD(void, term_entropy_encoder, (void));
shoaib_ahmed 0:791a779d6220 69 };
shoaib_ahmed 0:791a779d6220 70 Note the set of parentheses surrounding the parameter list.
shoaib_ahmed 0:791a779d6220 71
shoaib_ahmed 0:791a779d6220 72 A similar solution is used for forward and external function declarations
shoaib_ahmed 0:791a779d6220 73 (see the EXTERN and JPP macros).
shoaib_ahmed 0:791a779d6220 74
shoaib_ahmed 0:791a779d6220 75 If the code is to work on non-ANSI compilers, we cannot rely on a prototype
shoaib_ahmed 0:791a779d6220 76 declaration to coerce actual parameters into the right types. Therefore, use
shoaib_ahmed 0:791a779d6220 77 explicit casts on actual parameters whenever the actual parameter type is not
shoaib_ahmed 0:791a779d6220 78 identical to the formal parameter. Beware of implicit conversions to "int".
shoaib_ahmed 0:791a779d6220 79
shoaib_ahmed 0:791a779d6220 80 It seems there are some non-ANSI compilers in which the sizeof() operator
shoaib_ahmed 0:791a779d6220 81 is defined to return int, yet size_t is defined as long. Needless to say,
shoaib_ahmed 0:791a779d6220 82 this is brain-damaged. Always use the SIZEOF() macro in place of sizeof(),
shoaib_ahmed 0:791a779d6220 83 so that the result is guaranteed to be of type size_t.
shoaib_ahmed 0:791a779d6220 84
shoaib_ahmed 0:791a779d6220 85
shoaib_ahmed 0:791a779d6220 86 The JPEG library is intended to be used within larger programs. Furthermore,
shoaib_ahmed 0:791a779d6220 87 we want it to be reentrant so that it can be used by applications that process
shoaib_ahmed 0:791a779d6220 88 multiple images concurrently. The following rules support these requirements:
shoaib_ahmed 0:791a779d6220 89
shoaib_ahmed 0:791a779d6220 90 1. Avoid direct use of file I/O, "malloc", error report printouts, etc;
shoaib_ahmed 0:791a779d6220 91 pass these through the common routines provided.
shoaib_ahmed 0:791a779d6220 92
shoaib_ahmed 0:791a779d6220 93 2. Minimize global namespace pollution. Functions should be declared static
shoaib_ahmed 0:791a779d6220 94 wherever possible. (Note that our method-based calling conventions help this
shoaib_ahmed 0:791a779d6220 95 a lot: in many modules only the initialization function will ever need to be
shoaib_ahmed 0:791a779d6220 96 called directly, so only that function need be externally visible.) All
shoaib_ahmed 0:791a779d6220 97 global function names should begin with "jpeg_", and should have an
shoaib_ahmed 0:791a779d6220 98 abbreviated name (unique in the first six characters) substituted by macro
shoaib_ahmed 0:791a779d6220 99 when NEED_SHORT_EXTERNAL_NAMES is set.
shoaib_ahmed 0:791a779d6220 100
shoaib_ahmed 0:791a779d6220 101 3. Don't use global variables; anything that must be used in another module
shoaib_ahmed 0:791a779d6220 102 should be in the common data structures.
shoaib_ahmed 0:791a779d6220 103
shoaib_ahmed 0:791a779d6220 104 4. Don't use static variables except for read-only constant tables. Variables
shoaib_ahmed 0:791a779d6220 105 that should be private to a module can be placed into private structures (see
shoaib_ahmed 0:791a779d6220 106 the system architecture document, structure.txt).
shoaib_ahmed 0:791a779d6220 107
shoaib_ahmed 0:791a779d6220 108 5. Source file names should begin with "j" for files that are part of the
shoaib_ahmed 0:791a779d6220 109 library proper; source files that are not part of the library, such as cjpeg.c
shoaib_ahmed 0:791a779d6220 110 and djpeg.c, do not begin with "j". Keep source file names to eight
shoaib_ahmed 0:791a779d6220 111 characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep
shoaib_ahmed 0:791a779d6220 112 compression and decompression code in separate source files --- some
shoaib_ahmed 0:791a779d6220 113 applications may want only one half of the library.
shoaib_ahmed 0:791a779d6220 114
shoaib_ahmed 0:791a779d6220 115 Note: these rules (particularly #4) are not followed religiously in the
shoaib_ahmed 0:791a779d6220 116 modules that are used in cjpeg/djpeg but are not part of the JPEG library
shoaib_ahmed 0:791a779d6220 117 proper. Those modules are not really intended to be used in other
shoaib_ahmed 0:791a779d6220 118 applications.