Main MRPT website > C++ reference for MRPT 1.9.9
jutils.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #define JPEG_INTERNALS
11 #include "jinclude.h"
12 #include "mrpt_jpeglib.h"
13 
14 /*
15  * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
16  * of a DCT block read in natural order (left to right, top to bottom).
17  */
18 
19 #if 0 /* This table is not actually needed in v6a */
20 
21 const int jpeg_zigzag_order[DCTSIZE2] = {
22  0, 1, 5, 6, 14, 15, 27, 28,
23  2, 4, 7, 13, 16, 26, 29, 42,
24  3, 8, 12, 17, 25, 30, 41, 43,
25  9, 11, 18, 24, 31, 40, 44, 53,
26  10, 19, 23, 32, 39, 45, 52, 54,
27  20, 22, 33, 38, 46, 51, 55, 60,
28  21, 34, 37, 47, 50, 56, 59, 61,
29  35, 36, 48, 49, 57, 58, 62, 63
30 };
31 
32 #endif
33 
34 /*
35  * jpeg_natural_order[i] is the natural-order position of the i'th element
36  * of zigzag order.
37  *
38  * When reading corrupted data, the Huffman decoders could attempt
39  * to reference an entry beyond the end of this array (if the decoded
40  * zero run length reaches past the end of the block). To prevent
41  * wild stores without adding an inner-loop test, we put some extra
42  * "63"s after the real entries. This will cause the extra coefficient
43  * to be stored in location 63 of the block, not somewhere random.
44  * The worst case would be a run-length of 15, which means we need 16
45  * fake entries.
46  */
47 
48 const int jpeg_natural_order[DCTSIZE2 + 16] =
49  {
50  0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4,
51  5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14,
52  21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30,
53  37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54,
54  47, 55, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for
55  safety in decoder */
56  63, 63, 63, 63, 63, 63, 63, 63};
57 
58 /*
59  * Arithmetic utilities
60  */
61 
62 GLOBAL(long)
63 jdiv_round_up(long a, long b)
64 /* Compute a/b rounded up to next integer, ie, ceil(a/b) */
65 /* Assumes a >= 0, b > 0 */ { return (a + b - 1L) / b; }
66 GLOBAL(long)
67 jround_up(long a, long b)
68 /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
69 /* Assumes a >= 0, b > 0 */
70 {
71  a += b - 1L;
72  return a - (a % b);
73 }
74 
75 /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
76  * and coefficient-block arrays. This won't work on 80x86 because the arrays
77  * are FAR and we're assuming a small-pointer memory model. However, some
78  * DOS compilers provide far-pointer versions of memcpy() and memset() even
79  * in the small-model libraries. These will be used if USE_FMEM is defined.
80  * Otherwise, the routines below do it the hard way. (The performance cost
81  * is not all that great, because these routines aren't very heavily used.)
82  */
83 
84 #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
85 #define FMEMCOPY(dest, src, size) MEMCOPY(dest, src, size)
86 #define FMEMZERO(target, size) MEMZERO(target, size)
87 #else /* 80x86 case, define if we can */
88 #ifdef USE_FMEM
89 #define FMEMCOPY(dest, src, size) \
90  _fmemcpy((void FAR*)(dest), (const void FAR*)(src), (size_t)(size))
91 #define FMEMZERO(target, size) _fmemset((void FAR*)(target), 0, (size_t)(size))
92 #endif
93 #endif
94 
95 GLOBAL(void)
97  JSAMPARRAY input_array, int source_row, JSAMPARRAY output_array,
98  int dest_row, int num_rows, JDIMENSION num_cols)
99 /* Copy some rows of samples from one place to another.
100  * num_rows rows are copied from input_array[source_row++]
101  * to output_array[dest_row++]; these areas may overlap for duplication.
102  * The source and destination arrays must be at least as wide as num_cols.
103  */
104 {
106 #ifdef FMEMCOPY
107  size_t count = (size_t)(num_cols * SIZEOF(JSAMPLE));
108 #else
110 #endif
111  int row;
112 
113  input_array += source_row;
114  output_array += dest_row;
115 
116  for (row = num_rows; row > 0; row--)
117  {
118  inptr = *input_array++;
119  outptr = *output_array++;
120 #ifdef FMEMCOPY
122 #else
123  for (count = num_cols; count > 0; count--)
124  *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
125 #endif
126  }
127 }
128 
129 GLOBAL(void)
131  JBLOCKROW input_row, JBLOCKROW output_row, JDIMENSION num_blocks)
132 /* Copy a row of coefficient blocks from one place to another. */
133 {
134 #ifdef FMEMCOPY
135  FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
136 #else
138  long count;
139 
140  inptr = (JCOEFPTR)input_row;
141  outptr = (JCOEFPTR)output_row;
142  for (count = (long)num_blocks * DCTSIZE2; count > 0; count--)
143  {
144  *outptr++ = *inptr++;
145  }
146 #endif
147 }
148 
149 GLOBAL(void)
150 jzero_far(void FAR* target, size_t bytestozero)
151 /* Zero out a chunk of FAR memory. */
152 /* This might be sample-array data, block-array data, or alloc_large data. */
153 {
154 #ifdef FMEMZERO
155  FMEMZERO(target, bytestozero);
156 #else
157  char FAR* ptr = (char FAR*)target;
158  size_t count;
159 
160  for (count = bytestozero; count > 0; count--)
161  {
162  *ptr++ = 0;
163  }
164 #endif
165 }
jzero_far(void FAR *target, size_t bytestozero)
Definition: jutils.cpp:150
jdiv_round_up(long a, long b)
Definition: jutils.cpp:63
GLuint GLuint GLsizei count
Definition: glext.h:3528
char JSAMPLE
Definition: jmorecfg.h:58
jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row, JDIMENSION num_blocks)
Definition: jutils.cpp:130
jround_up(long a, long b)
Definition: jutils.cpp:67
#define SIZEOF(object)
Definition: jinclude.h:74
JSAMPLE FAR * JSAMPROW
Definition: mrpt_jpeglib.h:60
short JCOEF
Definition: jmorecfg.h:91
jcopy_sample_rows(JSAMPARRAY input_array, int source_row, JSAMPARRAY output_array, int dest_row, int num_rows, JDIMENSION num_cols)
Definition: jutils.cpp:96
const int jpeg_natural_order[DCTSIZE2+16]
Definition: jutils.cpp:48
#define FMEMZERO(target, size)
Definition: jutils.cpp:86
JCOEFPTR inptr
Definition: jidctflt.cpp:42
JSAMPROW outptr
Definition: jidctflt.cpp:45
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:61
JCOEF FAR * JCOEFPTR
Definition: mrpt_jpeglib.h:69
GLubyte GLubyte b
Definition: glext.h:6279
#define DCTSIZE2
Definition: mrpt_jpeglib.h:37
size_t bytestozero
Definition: jpegint.h:390
#define GLOBAL(type)
Definition: jmorecfg.h:177
GLenum GLenum GLvoid * row
Definition: glext.h:3576
JBLOCK FAR * JBLOCKROW
Definition: mrpt_jpeglib.h:65
unsigned int JDIMENSION
Definition: jmorecfg.h:161
#define FAR
Definition: zconf.h:262
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
#define FMEMCOPY(dest, src, size)
Definition: jutils.cpp:85



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019