summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2012-09-21 15:14:30 +0200
committerThomas Jahns <jahns@dkrz.de>2013-02-19 11:32:59 +0100
commit949ae1ee8d500ddd26651aef8f0b655770d06007 (patch)
treeac6182cc14f4d4fbc86d4dc062fd85dee6258d93
parent731b29482cae4dd7a8c0af894808cb8e96a53171 (diff)
downloadlibaec-949ae1ee8d500ddd26651aef8f0b655770d06007.tar.gz
libaec-949ae1ee8d500ddd26651aef8f0b655770d06007.tar.bz2
libaec-949ae1ee8d500ddd26651aef8f0b655770d06007.zip
Remove dependency on stdint in API
-rw-r--r--src/aec.c11
-rw-r--r--src/decode.c7
-rw-r--r--src/encode.c7
-rw-r--r--src/encode.h7
-rw-r--r--src/encode_accessors.c6
-rw-r--r--src/encode_accessors.h7
-rw-r--r--src/libaec.h37
-rw-r--r--src/pnoise.cc134
-rw-r--r--src/test_szcomp.c1
9 files changed, 52 insertions, 165 deletions
diff --git a/src/aec.c b/src/aec.c
index 932af80..4c6bca9 100644
--- a/src/aec.c
+++ b/src/aec.c
@@ -2,7 +2,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <inttypes.h>
#include <string.h>
#include <getopt.h>
#include "libaec.h"
@@ -12,8 +11,8 @@
int main(int argc, char *argv[])
{
struct aec_stream strm;
- uint8_t *in;
- uint8_t *out;
+ unsigned char *in;
+ unsigned char *out;
int chunk, total_out, status, c;
int input_avail, output_avail;
char *outfn, *infn, *ext;
@@ -94,8 +93,8 @@ int main(int argc, char *argv[])
chunk *= 2;
}
- out = (uint8_t *)malloc(chunk);
- in = (uint8_t *)malloc(chunk);
+ out = (unsigned char *)malloc(chunk);
+ in = (unsigned char *)malloc(chunk);
if (in == NULL || out == NULL)
@@ -158,7 +157,7 @@ int main(int argc, char *argv[])
strm.avail_in = fread(in, 1, chunk, infp);
if (strm.avail_in != chunk)
input_avail = 0;
- strm.next_in = (uint8_t *)in;
+ strm.next_in = in;
}
if (dflag)
diff --git a/src/decode.c b/src/decode.c
index 6378111..179cf7f 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -1,10 +1,15 @@
/* Adaptive Entropy Decoder */
/* CCSDS 121.0-B-1 and CCSDS 120.0-G-2 */
+#include <config.h>
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
-#include <inttypes.h>
#include <string.h>
#include "libaec.h"
diff --git a/src/encode.c b/src/encode.c
index 728f3b1..f79d05f 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -8,10 +8,15 @@
*
*/
+#include <config.h>
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <inttypes.h>
#include <string.h>
#include "libaec.h"
diff --git a/src/encode.h b/src/encode.h
index 2326a44..72b9629 100644
--- a/src/encode.h
+++ b/src/encode.h
@@ -1,7 +1,12 @@
#ifndef ENCODE_H
#define ENCODE_H
-#include <inttypes.h>
+#include <config.h>
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
#include "libaec.h"
#define M_CONTINUE 1
diff --git a/src/encode_accessors.c b/src/encode_accessors.c
index da56106..b318b64 100644
--- a/src/encode_accessors.c
+++ b/src/encode_accessors.c
@@ -1,5 +1,9 @@
#include <config.h>
-#include <inttypes.h>
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
#include <string.h>
#include "libaec.h"
#include "encode.h"
diff --git a/src/encode_accessors.h b/src/encode_accessors.h
index 3a4b44f..8b2039d 100644
--- a/src/encode_accessors.h
+++ b/src/encode_accessors.h
@@ -1,7 +1,12 @@
#ifndef ENCODE_ACCESSORS_H
#define ENCODE_ACCESSORS_H
-#include <inttypes.h>
+#include <config.h>
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
#include "libaec.h"
uint32_t get_8(struct aec_stream *strm);
diff --git a/src/libaec.h b/src/libaec.h
index 39cf40c..4d1f0f6 100644
--- a/src/libaec.h
+++ b/src/libaec.h
@@ -1,27 +1,26 @@
#ifndef LIBAEC_H
#define LIBAEC_H
-#include <inttypes.h>
#include <stddef.h>
struct internal_state;
struct aec_stream {
- const uint8_t *next_in;
+ const unsigned char *next_in;
size_t avail_in; /* number of bytes available at
* next_in */
size_t total_in; /* total number of input bytes read so
* far */
- uint8_t *next_out;
+ unsigned char *next_out;
size_t avail_out; /* remaining free space at next_out */
size_t total_out; /* total number of bytes output so far */
- uint32_t bit_per_sample; /* resolution in bits per sample (n =
+ int bit_per_sample; /* resolution in bits per sample (n =
* 1,..., 32) */
- uint32_t block_size; /* block size in samples (J = 8 or 16) */
- uint32_t rsi; /* Reference sample interval, the number of
+ int block_size; /* block size in samples */
+ int rsi; /* Reference sample interval, the number of
blocks between consecutive reference
samples. */
- uint32_t flags;
+ int flags;
struct internal_state *state;
};
@@ -43,19 +42,19 @@ struct aec_stream {
/* Options for flushing */
#define AEC_NO_FLUSH 0 /* Do not enforce output flushing. More
- * input may be provided with later
- * calls. So far only relevant for
- * encoding.
- */
+ * input may be provided with later
+ * calls. So far only relevant for
+ * encoding.
+ */
#define AEC_FLUSH 1 /* Flush output and end encoding. The last
- * call to aec_encode() must set AEC_FLUSH to
- * drain all output.
- *
- * It is not possible to continue encoding
- * of the same stream after it has been
- * flushed because the last byte may be
- * padded with fill bits.
- */
+ * call to aec_encode() must set AEC_FLUSH to
+ * drain all output.
+ *
+ * It is not possible to continue encoding
+ * of the same stream after it has been
+ * flushed because the last byte may be
+ * padded with fill bits.
+ */
int aec_decode_init(struct aec_stream *strm);
int aec_decode(struct aec_stream *strm, int flush);
diff --git a/src/pnoise.cc b/src/pnoise.cc
deleted file mode 100644
index 04e7cff..0000000
--- a/src/pnoise.cc
+++ /dev/null
@@ -1,134 +0,0 @@
-#include <getopt.h>
-#include <inttypes.h>
-#include <iostream>
-#include <new>
-#include <libnoise/noise.h>
-
-#define ROUND(x) ((x)>=0?(int64_t)((x)+0.5):(int64_t)((x)-0.5))
-#define CLIPL(x, l) ((x) < (l)?(l): (x))
-#define CLIPH(x, h) ((x) > (h)?(h): (x))
-#define CLIP(x, l, h) CLIPL(CLIPH(x, h), l)
-#define MIN(a, b) (((a) < (b))? (a): (b))
-
-#define CHUNK_SIZE 1024
-
-using namespace noise;
-using namespace std;
-
-int main (int argc, char** argv)
-{
- int i, j, c, cn, chunk;
- int sflag = 0;
- int msb = 0;
- int length = 1024;
- int bits = 8;
- int bytes = 1;
- double value, scaling, spacing;
- char *buf;
- int64_t ivalue, min_x, max_x;
-
- while ((c = getopt (argc, argv, "hsmB:b:n:")) != -1)
- switch (c)
- {
- case 'B':
- bits = atoi(optarg);
- break;
- case 'b':
- bytes = atoi(optarg);
- break;
- case 'n':
- length = atoi(optarg);
- break;
- case 's':
- sflag = 1;
- break;
- case 'm':
- msb = 1;
- break;
- case '?':
- if (optopt == 'b' || optopt == 'B' || optopt == 'n')
- cerr << "Option -" << (char)optopt
- << " requires an argument." << endl;
- else if (isprint (optopt))
- cerr << "Unknown option `-"
- << (char)optopt << "'."
- << endl;
- else
- cerr << "Unknown option character `\\x"
- << hex << optopt
- << "'." << endl;
- case 'h':
- cerr << "Usage: " << argv[0] << " [OPTION]" << endl;
- cerr << "-B Bit length of samples" << endl;
- cerr << "-b Byte length of samples, may be longer than bits"
- << endl;
- cerr << "-n Number of samples" << endl;
- cerr << "-s Samples are signed" << endl;
- cerr << "-m Store MSB first, default is LSB first" << endl;
- return 1;
- default:
- abort ();
- }
-
- if ((bits - 1) / 8 >= bytes)
- {
- cerr << "ERROR: "
- << bits << " bits don't fit in "
- << bytes << " bytes\n" << endl;
- return 1;
- }
-
- buf = new char[CHUNK_SIZE * bytes];
-
- module::Perlin myModule;
- myModule.SetOctaveCount(1);
-
- if (sflag)
- {
- min_x = -(1ULL << (bits - 1));
- max_x = (1ULL << (bits - 1)) - 1;
- }
- else
- {
- min_x = 0;
- max_x = (1ULL << bits) - 1;
- }
-
- scaling = (double)((1ULL << (bits + 1)) - 1);
- spacing = 10000.0 / (double)(1ULL << bits);
-
- for (cn = 0; cn <= length / CHUNK_SIZE; cn++)
- {
- chunk = MIN(CHUNK_SIZE, length - cn * CHUNK_SIZE);
-
- for (i = 0; i < chunk; i++)
- {
- value = myModule.GetValue (spacing * (double)i, 0, 0) / 2.0;
- if (sflag)
- {
- ivalue = ROUND(value * scaling);
- ivalue = CLIP(ivalue, min_x, max_x);
- }
- else
- {
- ivalue = ROUND((value + 0.5) * scaling);
- ivalue = CLIP(ivalue, 0, max_x);
- }
-
- ivalue &= (1ULL << bits) - 1;
- if (msb)
- {
- for (j = 0; j < bytes; j++)
- buf[i * bytes + j] = ivalue >> ((bytes - j - 1) * 8);
- }
- else
- {
- for (j = 0; j < bytes; j++)
- buf[i * bytes + j] = ivalue >> (j * 8);
- }
- }
- cout.write(buf, chunk * bytes);
- }
- delete buf;
- return 0;
-}
diff --git a/src/test_szcomp.c b/src/test_szcomp.c
index 7d16cfb..a8b885f 100644
--- a/src/test_szcomp.c
+++ b/src/test_szcomp.c
@@ -1,7 +1,6 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
-#include <inttypes.h>
#include <string.h>
#include "szlib.h"