Commit 949ae1ee authored by Mathis Rosenhauer's avatar Mathis Rosenhauer Committed by Thomas Jahns

Remove dependency on stdint in API

parent 731b2948
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include "libaec.h" #include "libaec.h"
...@@ -12,8 +11,8 @@ ...@@ -12,8 +11,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct aec_stream strm; struct aec_stream strm;
uint8_t *in; unsigned char *in;
uint8_t *out; unsigned char *out;
int chunk, total_out, status, c; int chunk, total_out, status, c;
int input_avail, output_avail; int input_avail, output_avail;
char *outfn, *infn, *ext; char *outfn, *infn, *ext;
...@@ -94,8 +93,8 @@ int main(int argc, char *argv[]) ...@@ -94,8 +93,8 @@ int main(int argc, char *argv[])
chunk *= 2; chunk *= 2;
} }
out = (uint8_t *)malloc(chunk); out = (unsigned char *)malloc(chunk);
in = (uint8_t *)malloc(chunk); in = (unsigned char *)malloc(chunk);
if (in == NULL || out == NULL) if (in == NULL || out == NULL)
...@@ -158,7 +157,7 @@ int main(int argc, char *argv[]) ...@@ -158,7 +157,7 @@ int main(int argc, char *argv[])
strm.avail_in = fread(in, 1, chunk, infp); strm.avail_in = fread(in, 1, chunk, infp);
if (strm.avail_in != chunk) if (strm.avail_in != chunk)
input_avail = 0; input_avail = 0;
strm.next_in = (uint8_t *)in; strm.next_in = in;
} }
if (dflag) if (dflag)
......
/* Adaptive Entropy Decoder */ /* Adaptive Entropy Decoder */
/* CCSDS 121.0-B-1 and CCSDS 120.0-G-2 */ /* 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 <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include "libaec.h" #include "libaec.h"
......
...@@ -8,10 +8,15 @@ ...@@ -8,10 +8,15 @@
* *
*/ */
#include <config.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include "libaec.h" #include "libaec.h"
......
#ifndef ENCODE_H #ifndef ENCODE_H
#define ENCODE_H #define ENCODE_H
#include <inttypes.h> #include <config.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include "libaec.h" #include "libaec.h"
#define M_CONTINUE 1 #define M_CONTINUE 1
......
#include <config.h> #include <config.h>
#include <inttypes.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include <string.h> #include <string.h>
#include "libaec.h" #include "libaec.h"
#include "encode.h" #include "encode.h"
......
#ifndef ENCODE_ACCESSORS_H #ifndef ENCODE_ACCESSORS_H
#define ENCODE_ACCESSORS_H #define ENCODE_ACCESSORS_H
#include <inttypes.h> #include <config.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include "libaec.h" #include "libaec.h"
uint32_t get_8(struct aec_stream *strm); uint32_t get_8(struct aec_stream *strm);
......
#ifndef LIBAEC_H #ifndef LIBAEC_H
#define LIBAEC_H #define LIBAEC_H
#include <inttypes.h>
#include <stddef.h> #include <stddef.h>
struct internal_state; struct internal_state;
struct aec_stream { struct aec_stream {
const uint8_t *next_in; const unsigned char *next_in;
size_t avail_in; /* number of bytes available at size_t avail_in; /* number of bytes available at
* next_in */ * next_in */
size_t total_in; /* total number of input bytes read so size_t total_in; /* total number of input bytes read so
* far */ * far */
uint8_t *next_out; unsigned char *next_out;
size_t avail_out; /* remaining free space at next_out */ size_t avail_out; /* remaining free space at next_out */
size_t total_out; /* total number of bytes output so far */ 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) */ * 1,..., 32) */
uint32_t block_size; /* block size in samples (J = 8 or 16) */ int block_size; /* block size in samples */
uint32_t rsi; /* Reference sample interval, the number of int rsi; /* Reference sample interval, the number of
blocks between consecutive reference blocks between consecutive reference
samples. */ samples. */
uint32_t flags; int flags;
struct internal_state *state; struct internal_state *state;
}; };
...@@ -43,19 +42,19 @@ struct aec_stream { ...@@ -43,19 +42,19 @@ struct aec_stream {
/* Options for flushing */ /* Options for flushing */
#define AEC_NO_FLUSH 0 /* Do not enforce output flushing. More #define AEC_NO_FLUSH 0 /* Do not enforce output flushing. More
* input may be provided with later * input may be provided with later
* calls. So far only relevant for * calls. So far only relevant for
* encoding. * encoding.
*/ */
#define AEC_FLUSH 1 /* Flush output and end encoding. The last #define AEC_FLUSH 1 /* Flush output and end encoding. The last
* call to aec_encode() must set AEC_FLUSH to * call to aec_encode() must set AEC_FLUSH to
* drain all output. * drain all output.
* *
* It is not possible to continue encoding * It is not possible to continue encoding
* of the same stream after it has been * of the same stream after it has been
* flushed because the last byte may be * flushed because the last byte may be
* padded with fill bits. * padded with fill bits.
*/ */
int aec_decode_init(struct aec_stream *strm); int aec_decode_init(struct aec_stream *strm);
int aec_decode(struct aec_stream *strm, int flush); int aec_decode(struct aec_stream *strm, int flush);
......
#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;
}
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include "szlib.h" #include "szlib.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment