summaryrefslogtreecommitdiffstats
path: root/ext/tarkin
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tarkin')
-rw-r--r--ext/tarkin/bitcoder.h152
-rw-r--r--ext/tarkin/golomb.h134
-rw-r--r--ext/tarkin/gsttarkindec.h59
-rw-r--r--ext/tarkin/gsttarkinenc.h61
-rw-r--r--ext/tarkin/mem.h9
-rw-r--r--ext/tarkin/rle.h146
-rw-r--r--ext/tarkin/tarkin.h273
-rw-r--r--ext/tarkin/wavelet.h53
-rw-r--r--ext/tarkin/yuv.h17
9 files changed, 450 insertions, 454 deletions
diff --git a/ext/tarkin/bitcoder.h b/ext/tarkin/bitcoder.h
index fe1e6eae..312cd887 100644
--- a/ext/tarkin/bitcoder.h
+++ b/ext/tarkin/bitcoder.h
@@ -15,7 +15,7 @@
#define ENTROPY_ENCODER_FLUSH(coder) bitcoder_flush(coder)
#define ENTROPY_DECODER_INIT(coder,bitstream,limit) \
bitcoder_decoder_init(coder,bitstream,limit)
-#define ENTROPY_DECODER_DONE(coder) /* nothing to do ... */
+#define ENTROPY_DECODER_DONE(coder) /* nothing to do ... */
#define ENTROPY_CODER_BITSTREAM(coder) (coder)->bitstream
#define ENTROPY_CODER_SYMBOL(coder) 1
@@ -25,107 +25,106 @@
#endif
-typedef struct
-{
- int32_t bit_count; /* number of valid bits in byte */
- uint8_t byte; /* buffer to save bits */
- uint32_t byte_count; /* number of bytes written */
- uint8_t *bitstream;
- uint32_t limit; /* don't write more bytes to bitstream ... */
- int eos; /* end of stream reached */
+typedef struct {
+ int32_t bit_count; /* number of valid bits in byte */
+ uint8_t byte; /* buffer to save bits */
+ uint32_t byte_count; /* number of bytes written */
+ uint8_t *bitstream;
+ uint32_t limit; /* don't write more bytes to bitstream ... */
+ int eos; /* end of stream reached */
} BitCoderState;
-static inline void
-bitcoder_encoder_init (BitCoderState * s, uint32_t limit)
+static inline
+void bitcoder_encoder_init (BitCoderState *s, uint32_t limit)
{
- s->bit_count = 0;
- s->byte = 0;
- s->byte_count = 0;
- s->bitstream = (uint8_t *) MALLOC (limit);
- s->limit = limit;
- s->eos = 0;
+ s->bit_count = 0;
+ s->byte = 0;
+ s->byte_count = 0;
+ s->bitstream = (uint8_t*) MALLOC (limit);
+ s->limit = limit;
+ s->eos = 0;
}
-static inline void
-bitcoder_encoder_done (BitCoderState * s)
+static inline
+void bitcoder_encoder_done (BitCoderState *s)
{
- FREE (s->bitstream);
+ FREE (s->bitstream);
}
-static inline void
-bitcoder_decoder_init (BitCoderState * s, uint8_t * bitstream, uint32_t limit)
+static inline
+void bitcoder_decoder_init (BitCoderState *s, uint8_t *bitstream, uint32_t limit)
{
- s->bit_count = -1;
- s->byte = 0;
- s->byte_count = 0;
- s->bitstream = bitstream;
- s->limit = limit;
- s->eos = 0;
+ s->bit_count = -1;
+ s->byte = 0;
+ s->byte_count = 0;
+ s->bitstream = bitstream;
+ s->limit = limit;
+ s->eos = 0;
}
-static inline uint32_t
-bitcoder_flush (BitCoderState * s)
+static inline
+uint32_t bitcoder_flush (BitCoderState *s)
{
- if (s->bit_count > 0 && s->byte_count < s->limit)
- s->bitstream[s->byte_count++] = s->byte << (8 - s->bit_count);
+ if (s->bit_count > 0 && s->byte_count < s->limit)
+ s->bitstream [s->byte_count++] = s->byte << (8 - s->bit_count);
/*printf ("%s: %i bytes written.\n", __FUNCTION__, s->byte_count); */
/*printf ("%s: last bit %i\n", __FUNCTION__, s->bit_count); */
- return s->byte_count;
+ return s->byte_count;
}
-static inline void
-bitcoder_write_bit (BitCoderState * s, int bit)
+static inline
+void bitcoder_write_bit (BitCoderState *s, int bit)
{
- s->byte <<= 1;
- s->byte |= bit & 1;
-
- s->bit_count++;
-
- if (s->bit_count == 8) {
- if (s->byte_count < s->limit) {
- s->bitstream[s->byte_count++] = s->byte;
- s->bit_count = 0;
- } else {
- s->eos = 1;
- }
- }
+ s->byte <<= 1;
+ s->byte |= bit & 1;
+
+ s->bit_count++;
+
+ if (s->bit_count == 8) {
+ if (s->byte_count < s->limit) {
+ s->bitstream [s->byte_count++] = s->byte;
+ s->bit_count = 0;
+ } else {
+ s->eos = 1;
+ }
+ }
}
-static inline int
-bitcoder_read_bit (BitCoderState * s)
+static inline
+int bitcoder_read_bit (BitCoderState *s)
{
- int ret;
+ int ret;
- if (s->bit_count <= 0) {
- if (!s->bitstream) {
- s->eos = 1;
- return 0;
- }
+ if (s->bit_count <= 0) {
+ if (!s->bitstream) {
+ s->eos = 1;
+ return 0;
+ }
- if (s->byte_count < s->limit) {
- s->byte = s->bitstream[s->byte_count++];
- } else {
- s->eos = 1;
- s->byte = 0;
- }
+ if (s->byte_count < s->limit) {
+ s->byte = s->bitstream [s->byte_count++];
+ } else {
+ s->eos = 1;
+ s->byte = 0;
+ }
- s->bit_count = 8;
- }
+ s->bit_count = 8;
+ }
- ret = s->byte >> 7;
- s->byte <<= 1;
- s->bit_count--;
+ ret = s->byte >> 7;
+ s->byte <<= 1;
+ s->bit_count--;
- return ret & 1;
+ return ret & 1;
}
@@ -133,16 +132,17 @@ bitcoder_read_bit (BitCoderState * s)
-static inline void
-bit_print (TYPE byte)
+static inline
+void bit_print (TYPE byte)
{
- int bit = 8 * sizeof (TYPE);
+ int bit = 8*sizeof(TYPE);
- do {
- bit--;
- printf ((byte & (1 << bit)) ? "1" : "0");
- } while (bit);
- printf ("\n");
+ do {
+ bit--;
+ printf ((byte & (1 << bit)) ? "1" : "0");
+ } while (bit);
+ printf ("\n");
}
#endif
+
diff --git a/ext/tarkin/golomb.h b/ext/tarkin/golomb.h
index 47c23b44..95e63c30 100644
--- a/ext/tarkin/golomb.h
+++ b/ext/tarkin/golomb.h
@@ -5,126 +5,128 @@
#include "bitcoder.h"
-static inline unsigned int
-required_bits (unsigned int x)
+static inline
+unsigned int required_bits (unsigned int x)
{
- int bits = 31;
+ int bits = 31;
- while ((x & (1 << bits)) == 0 && bits)
- bits--;
+ while ((x & (1 << bits)) == 0 && bits)
+ bits--;
- return bits;
+ return bits;
}
-static inline void
-write_number_binary (BitCoderState * b, unsigned int x, int bits, int u)
+static inline
+void write_number_binary (BitCoderState *b, unsigned int x, int bits, int u)
{
/*printf ("wrote %i with %i bits (%i+%i)\n", x, u+bits, u, bits); */
- while (bits) {
- bits--;
- bitcoder_write_bit (b, (x >> bits) & 1);
- }
+ while (bits) {
+ bits--;
+ bitcoder_write_bit (b, (x >> bits) & 1);
+ }
}
-static inline unsigned int
-read_number_binary (BitCoderState * b, int bits)
+static inline
+unsigned int read_number_binary (BitCoderState *b, int bits)
{
- unsigned int x = 0;
+ unsigned int x = 0;
- while (bits) {
- bits--;
- x |= bitcoder_read_bit (b) << bits;
- }
+ while (bits) {
+ bits--;
+ x |= bitcoder_read_bit (b) << bits;
+ }
- return x;
+ return x;
}
-static inline void
-golomb_write_number (BitCoderState * b, unsigned int x, int bits)
+static inline
+void golomb_write_number (BitCoderState *b, unsigned int x, int bits)
{
- unsigned int q, r;
- int i = 0;
+ unsigned int q, r;
+int i = 0;
- assert (x > 0);
+ assert (x > 0);
- while ((q = (x - 1) >> bits) > 0) {
- bitcoder_write_bit (b, 1); /* fast temporary adaption, write */
- bits++; /* unary representation of q */
- i++;
- };
+ while ((q = (x - 1) >> bits) > 0) {
+ bitcoder_write_bit (b, 1); /* fast temporary adaption, write */
+ bits++; /* unary representation of q */
+i++;
+ };
- bitcoder_write_bit (b, 0);
+ bitcoder_write_bit (b, 0);
- r = x - 1 - (q << bits);
+ r = x - 1 - (q << bits);
- write_number_binary (b, r, bits, i + 1);
+ write_number_binary (b, r, bits, i+1);
}
-static inline unsigned int
-golomb_read_number (BitCoderState * b, int bits)
+static inline
+unsigned int golomb_read_number (BitCoderState *b, int bits)
{
- unsigned int q = 0, r, x;
+ unsigned int q = 0, r, x;
- while (bitcoder_read_bit (b) != 0) {
- bits++;
- }
+ while (bitcoder_read_bit (b) != 0) {
+ bits++;
+ }
- r = read_number_binary (b, bits);
- x = (q << bits) + r + 1;
+ r = read_number_binary (b, bits);
+ x = (q << bits) + r + 1;
- return x;
+ return x;
}
-typedef struct
-{
- uint8_t count;
- uint8_t bits; /* a 5.3 fixed point integer */
+typedef struct {
+ uint8_t count;
+ uint8_t bits; /* a 5.3 fixed point integer */
} GolombAdaptiveCoderState;
#define GOLOMB_ADAPTIVE_CODER_STATE_INITIALIZER { 8<<3, 0 }
-static const int golomb_w_tab[] = { 256, 128, 64 };
+static const int golomb_w_tab [] = { 256, 128, 64 };
-static inline void
-golombcoder_encode_number (GolombAdaptiveCoderState * g,
- BitCoderState * b, unsigned int x)
+static inline
+void golombcoder_encode_number (GolombAdaptiveCoderState *g,
+ BitCoderState *b,
+ unsigned int x)
{
- golomb_write_number (b, x, g->bits >> 3);
+ golomb_write_number (b, x, g->bits >> 3);
- g->bits = ((256 - golomb_w_tab[g->count]) * (int) g->bits +
- golomb_w_tab[g->count] * (required_bits (x) << 3)) / 256;
- g->count++;
+ g->bits = ((256 - golomb_w_tab[g->count]) * (int) g->bits +
+ golomb_w_tab[g->count] * (required_bits(x)<<3)) / 256;
+ g->count++;
- if (g->count > 2)
- g->count = 2;
+ if (g->count > 2)
+ g->count = 2;
}
-static inline unsigned int
-golombcoder_decode_number (GolombAdaptiveCoderState * g, BitCoderState * b)
+static inline
+unsigned int golombcoder_decode_number (GolombAdaptiveCoderState *g,
+ BitCoderState *b)
{
- unsigned int x;
+ unsigned int x;
- x = golomb_read_number (b, g->bits >> 3);
+ x = golomb_read_number (b, g->bits >> 3);
- g->bits = ((256 - golomb_w_tab[g->count]) * g->bits +
- golomb_w_tab[g->count] * (required_bits (x) << 3)) / 256;
- g->count++;
+ g->bits = ((256 - golomb_w_tab[g->count]) * g->bits +
+ golomb_w_tab[g->count] * (required_bits(x)<<3)) / 256;
+ g->count++;
- if (g->count > 2)
- g->count = 2;
+ if (g->count > 2)
+ g->count = 2;
- return x;
+ return x;
}
#endif
+
diff --git a/ext/tarkin/gsttarkindec.h b/ext/tarkin/gsttarkindec.h
index 77b8954d..b1baf4f3 100644
--- a/ext/tarkin/gsttarkindec.h
+++ b/ext/tarkin/gsttarkindec.h
@@ -27,9 +27,8 @@
#include "tarkin.h"
#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
+extern "C" {
+#endif /* __cplusplus */
#define GST_TYPE_TARKINDEC \
(tarkindec_get_type())
@@ -42,44 +41,42 @@ extern "C"
#define GST_IS_TARKINDEC_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TARKINDEC))
- typedef struct _TarkinDec TarkinDec;
- typedef struct _TarkinDecClass TarkinDecClass;
+typedef struct _TarkinDec TarkinDec;
+typedef struct _TarkinDecClass TarkinDecClass;
- struct _TarkinDec
- {
- GstElement element;
+struct _TarkinDec {
+ GstElement element;
- GstPad *sinkpad, *srcpad;
+ GstPad *sinkpad,*srcpad;
- ogg_sync_state oy;
- ogg_stream_state os;
- ogg_page og;
- ogg_packet op;
+ ogg_sync_state oy;
+ ogg_stream_state os;
+ ogg_page og;
+ ogg_packet op;
- TarkinStream *tarkin_stream;
- TarkinComment tc;
- TarkinInfo ti;
- TarkinVideoLayerDesc layer[1];
+ TarkinStream *tarkin_stream;
+ TarkinComment tc;
+ TarkinInfo ti;
+ TarkinVideoLayerDesc layer[1];
- gint frame_num;
- gint nheader;
+ gint frame_num;
+ gint nheader;
+
+ gboolean eos;
+ gint bitrate;
+ gboolean setup;
+};
- gboolean eos;
- gint bitrate;
- gboolean setup;
- };
+struct _TarkinDecClass {
+ GstElementClass parent_class;
+};
- struct _TarkinDecClass
- {
- GstElementClass parent_class;
- };
-
- GType tarkindec_get_type (void);
+GType tarkindec_get_type(void);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
+#endif /* __cplusplus */
-#endif /* __TARKINDEC_H__ */
+#endif /* __TARKINDEC_H__ */
diff --git a/ext/tarkin/gsttarkinenc.h b/ext/tarkin/gsttarkinenc.h
index 9e03e5ca..b6252a88 100644
--- a/ext/tarkin/gsttarkinenc.h
+++ b/ext/tarkin/gsttarkinenc.h
@@ -27,9 +27,8 @@
#include "tarkin.h"
#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
+extern "C" {
+#endif /* __cplusplus */
#define GST_TYPE_TARKINENC \
(tarkinenc_get_type())
@@ -42,45 +41,43 @@ extern "C"
#define GST_IS_TARKINENC_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TARKINENC))
- typedef struct _TarkinEnc TarkinEnc;
- typedef struct _TarkinEncClass TarkinEncClass;
+typedef struct _TarkinEnc TarkinEnc;
+typedef struct _TarkinEncClass TarkinEncClass;
- struct _TarkinEnc
- {
- GstElement element;
+struct _TarkinEnc {
+ GstElement element;
- GstPad *sinkpad, *srcpad;
+ GstPad *sinkpad,*srcpad;
- ogg_stream_state os; /* take physical pages, weld into a logical
- stream of packets */
- ogg_page og; /* one Ogg bitstream page. Tarkin packets are inside */
- ogg_packet op[3]; /* one raw packet of data for decode */
+ ogg_stream_state os; /* take physical pages, weld into a logical
+ stream of packets */
+ ogg_page og; /* one Ogg bitstream page. Tarkin packets are inside */
+ ogg_packet op[3]; /* one raw packet of data for decode */
- TarkinStream *tarkin_stream;
- TarkinComment tc;
- TarkinInfo ti;
- TarkinVideoLayerDesc layer[1];
+ TarkinStream *tarkin_stream;
+ TarkinComment tc;
+ TarkinInfo ti;
+ TarkinVideoLayerDesc layer[1];
- gint frame_num;
+ gint frame_num;
+
+ gboolean eos;
+ gint bitrate;
+ gint s_moments;
+ gint a_moments;
+ gboolean setup;
+};
- gboolean eos;
- gint bitrate;
- gint s_moments;
- gint a_moments;
- gboolean setup;
- };
+struct _TarkinEncClass {
+ GstElementClass parent_class;
+};
- struct _TarkinEncClass
- {
- GstElementClass parent_class;
- };
-
- GType tarkinenc_get_type (void);
+GType tarkinenc_get_type(void);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
+#endif /* __cplusplus */
-#endif /* __TARKINENC_H__ */
+#endif /* __TARKINENC_H__ */
diff --git a/ext/tarkin/mem.h b/ext/tarkin/mem.h
index f6e4c726..f218f8e4 100644
--- a/ext/tarkin/mem.h
+++ b/ext/tarkin/mem.h
@@ -9,11 +9,9 @@
#if defined(DBG_MEMLEAKS)
-extern void *dbg_malloc (char *file, int line, char *func, size_t bytes);
-extern void *dbg_calloc (char *file, int line, char *func, size_t count,
- size_t bytes);
-extern void *dbg_realloc (char *file, int line, char *func, char *what,
- void *mem, size_t bytes);
+extern void* dbg_malloc (char *file, int line, char *func, size_t bytes);
+extern void* dbg_calloc (char *file, int line, char *func, size_t count, size_t bytes);
+extern void* dbg_realloc (char *file, int line, char *func, char *what, void *mem, size_t bytes);
extern void dbg_free (char *file, int line, char *func, char *what, void *mem);
#define MALLOC(bytes) dbg_malloc(__FILE__,__LINE__,__FUNCTION__,bytes)
@@ -31,3 +29,4 @@ extern void dbg_free (char *file, int line, char *func, char *what, void *mem);
#endif
#endif
+
diff --git a/ext/tarkin/rle.h b/ext/tarkin/rle.h
index 6ccef22b..7cf79517 100644
--- a/ext/tarkin/rle.h
+++ b/ext/tarkin/rle.h
@@ -19,7 +19,7 @@
#define ENTROPY_ENCODER_FLUSH(coder) rlecoder_encoder_flush(coder)
#define ENTROPY_DECODER_INIT(coder,bitstream,limit) \
rlecoder_decoder_init(coder,bitstream,limit)
-#define ENTROPY_DECODER_DONE(coder) /* nothing to do ... */
+#define ENTROPY_DECODER_DONE(coder) /* nothing to do ... */
#define ENTROPY_CODER_BITSTREAM(coder) ((coder)->bitcoder.bitstream)
#define ENTROPY_CODER_EOS(coder) ((coder)->bitcoder.eos)
@@ -31,13 +31,12 @@
-typedef struct
-{
- int symbol;
- uint32_t count; /* have seen count symbol's */
- BitCoderState bitcoder;
- GolombAdaptiveCoderState golomb_state[2]; /* 2 states for 2 symbols... */
- int have_seen_1;
+typedef struct {
+ int symbol;
+ uint32_t count; /* have seen count symbol's */
+ BitCoderState bitcoder;
+ GolombAdaptiveCoderState golomb_state [2]; /* 2 states for 2 symbols... */
+ int have_seen_1;
} RLECoderState;
@@ -45,99 +44,100 @@ typedef struct
/*
* bit should be 0 or 1 !!!
*/
-static inline void
-rlecoder_write_bit (RLECoderState * s, int bit)
+static inline
+void rlecoder_write_bit (RLECoderState *s, int bit)
{
- assert (bit == 0 || bit == 1);
-
- if (s->symbol == -1) {
- s->symbol = bit & 1;
- s->count = 1;
- s->have_seen_1 = bit;
- bitcoder_write_bit (&s->bitcoder, bit);
- }
-
- if (s->symbol != bit) {
- golombcoder_encode_number (&s->golomb_state[s->symbol],
- &s->bitcoder, s->count);
- s->symbol = ~s->symbol & 1;
- s->have_seen_1 = 1;
- s->count = 1;
- } else
- s->count++;
+ assert (bit == 0 || bit == 1);
+
+ if (s->symbol == -1) {
+ s->symbol = bit & 1;
+ s->count = 1;
+ s->have_seen_1 = bit;
+ bitcoder_write_bit (&s->bitcoder, bit);
+ }
+
+ if (s->symbol != bit) {
+ golombcoder_encode_number (&s->golomb_state[s->symbol],
+ &s->bitcoder, s->count);
+ s->symbol = ~s->symbol & 1;
+ s->have_seen_1 = 1;
+ s->count = 1;
+ } else
+ s->count++;
}
-static inline int
-rlecoder_read_bit (RLECoderState * s)
+static inline
+int rlecoder_read_bit (RLECoderState *s)
{
- if (s->count == 0) {
- s->symbol = ~s->symbol & 1;
- s->count = golombcoder_decode_number (&s->golomb_state[s->symbol],
- &s->bitcoder);
- if (s->bitcoder.eos) {
- s->symbol = 0;
- s->count = ~0;
- }
- }
- s->count--;
- return (s->symbol);
+ if (s->count == 0) {
+ s->symbol = ~s->symbol & 1;
+ s->count = golombcoder_decode_number (&s->golomb_state[s->symbol],
+ &s->bitcoder);
+ if (s->bitcoder.eos) {
+ s->symbol = 0;
+ s->count = ~0;
+ }
+ }
+ s->count--;
+ return (s->symbol);
}
int coder_id = 0;
FILE *file = NULL;
-static inline void
-rlecoder_encoder_init (RLECoderState * s, uint32_t limit)
+static inline
+void rlecoder_encoder_init (RLECoderState *s, uint32_t limit)
{
- bitcoder_encoder_init (&s->bitcoder, limit);
- s->symbol = -1;
- s->have_seen_1 = 0;
- s->golomb_state[0].count = 0;
- s->golomb_state[1].count = 0;
- s->golomb_state[0].bits = 5 << 3;
- s->golomb_state[1].bits = 5 << 3;
+ bitcoder_encoder_init (&s->bitcoder, limit);
+ s->symbol = -1;
+ s->have_seen_1 = 0;
+ s->golomb_state[0].count = 0;
+ s->golomb_state[1].count = 0;
+ s->golomb_state[0].bits = 5 << 3;
+ s->golomb_state[1].bits = 5 << 3;
}
/**
* once you called this, you better should not encode any more symbols ...
*/
-static inline uint32_t
-rlecoder_encoder_flush (RLECoderState * s)
+static inline
+uint32_t rlecoder_encoder_flush (RLECoderState *s)
{
- if (s->symbol == -1 || !s->have_seen_1)
- return 0;
+ if (s->symbol == -1 || !s->have_seen_1)
+ return 0;
- golombcoder_encode_number (&s->golomb_state[s->symbol],
- &s->bitcoder, s->count);
- return bitcoder_flush (&s->bitcoder);
+ golombcoder_encode_number (&s->golomb_state[s->symbol],
+ &s->bitcoder, s->count);
+ return bitcoder_flush (&s->bitcoder);
}
-static inline void
-rlecoder_decoder_init (RLECoderState * s, uint8_t * bitstream, uint32_t limit)
+static inline
+void rlecoder_decoder_init (RLECoderState *s, uint8_t *bitstream, uint32_t limit)
{
- bitcoder_decoder_init (&s->bitcoder, bitstream, limit);
- s->golomb_state[0].count = 0;
- s->golomb_state[1].count = 0;
- s->golomb_state[0].bits = 5 << 3;
- s->golomb_state[1].bits = 5 << 3;
- s->symbol = bitcoder_read_bit (&s->bitcoder);
- s->count = golombcoder_decode_number (&s->golomb_state[s->symbol],
- &s->bitcoder) - 1;
- if (s->bitcoder.eos) {
- s->symbol = 0;
- s->count = ~0;
- }
+ bitcoder_decoder_init (&s->bitcoder, bitstream, limit);
+ s->golomb_state[0].count = 0;
+ s->golomb_state[1].count = 0;
+ s->golomb_state[0].bits = 5 << 3;
+ s->golomb_state[1].bits = 5 << 3;
+ s->symbol = bitcoder_read_bit (&s->bitcoder);
+ s->count = golombcoder_decode_number (&s->golomb_state[s->symbol],
+ &s->bitcoder) - 1;
+ if (s->bitcoder.eos) {
+ s->symbol = 0;
+ s->count = ~0;
+ }
}
-static inline void
-rlecoder_encoder_done (RLECoderState * s)
+static inline
+void rlecoder_encoder_done (RLECoderState *s)
{
- bitcoder_encoder_done (&s->bitcoder);
+ bitcoder_encoder_done (&s->bitcoder);
}
#endif
+
diff --git a/ext/tarkin/tarkin.h b/ext/tarkin/tarkin.h
index 680ba4b9..633f9a14 100644
--- a/ext/tarkin/tarkin.h
+++ b/ext/tarkin/tarkin.h
@@ -18,115 +18,105 @@
/* Theses determine what infos the packet comes with */
#define TARKIN_PACK_EXAMPLE 1
-typedef struct
-{
- uint8_t *data;
- uint32_t data_len;
- uint32_t storage;
-} TarkinPacket;
-
-
-typedef enum
-{
- TARKIN_GRAYSCALE,
- TARKIN_RGB24, /* tight packed RGB */
- TARKIN_RGB32, /* 32bit, no alphachannel */
- TARKIN_RGBA, /* dito w/ alphachannel */
- TARKIN_YUV2, /* 16 bits YUV */
- TARKIN_YUV12, /* 12 bits YUV */
- TARKIN_FYUV, /* Tarkin's Fast YUV-like? */
+typedef struct {
+ uint8_t *data;
+ uint32_t data_len;
+ uint32_t storage;
+} TarkinPacket;
+
+
+typedef enum {
+ TARKIN_GRAYSCALE,
+ TARKIN_RGB24, /* tight packed RGB */
+ TARKIN_RGB32, /* 32bit, no alphachannel */
+ TARKIN_RGBA, /* dito w/ alphachannel */
+ TARKIN_YUV2, /* 16 bits YUV */
+ TARKIN_YUV12, /* 12 bits YUV */
+ TARKIN_FYUV, /* Tarkin's Fast YUV-like? */
} TarkinColorFormat;
#define TARKIN_INTERNAL_FORMAT TARKIN_FYUV
-typedef enum
-{
- TARKIN_OK = 0,
- TARKIN_IO_ERROR,
- TARKIN_SIGNATURE_NOT_FOUND,
- TARKIN_INVALID_LAYER,
- TARKIN_INVALID_COLOR_FORMAT,
- TARKIN_VERSION,
- TARKIN_BAD_HEADER,
- TARKIN_NOT_TARKIN,
- TARKIN_FAULT,
- TARKIN_UNUSED,
- TARKIN_NEED_MORE,
- TARKIN_NOT_IMPLEMENTED
+typedef enum {
+ TARKIN_OK = 0,
+ TARKIN_IO_ERROR,
+ TARKIN_SIGNATURE_NOT_FOUND,
+ TARKIN_INVALID_LAYER,
+ TARKIN_INVALID_COLOR_FORMAT,
+ TARKIN_VERSION,
+ TARKIN_BAD_HEADER,
+ TARKIN_NOT_TARKIN,
+ TARKIN_FAULT,
+ TARKIN_UNUSED,
+ TARKIN_NEED_MORE,
+ TARKIN_NOT_IMPLEMENTED
} TarkinError;
-typedef struct
-{
- uint32_t width;
- uint32_t height;
- uint32_t a_moments;
- uint32_t s_moments;
- uint32_t frames_per_buf;
- uint32_t bitstream_len; /* for all color components, bytes */
- TarkinColorFormat format;
+typedef struct {
+ uint32_t width;
+ uint32_t height;
+ uint32_t a_moments;
+ uint32_t s_moments;
+ uint32_t frames_per_buf;
+ uint32_t bitstream_len; /* for all color components, bytes */
+ TarkinColorFormat format;
} TarkinVideoLayerDesc;
-typedef struct
-{
- TarkinVideoLayerDesc desc;
- uint32_t n_comp; /* number of color components */
- Wavelet3DBuf **waveletbuf;
- TarkinPacket *packet;
- uint32_t current_frame_in_buf;
- uint32_t frameno;
+typedef struct {
+ TarkinVideoLayerDesc desc;
+ uint32_t n_comp; /* number of color components */
+ Wavelet3DBuf **waveletbuf;
+ TarkinPacket *packet;
+ uint32_t current_frame_in_buf;
+ uint32_t frameno;
- void (*color_fwd_xform) (uint8_t * rgba, Wavelet3DBuf * yuva[],
- uint32_t count);
- void (*color_inv_xform) (Wavelet3DBuf * yuva[], uint8_t * rgba,
- uint32_t count);
+ void (*color_fwd_xform) (uint8_t *rgba, Wavelet3DBuf *yuva [], uint32_t count);
+ void (*color_inv_xform) (Wavelet3DBuf *yuva [], uint8_t *rgba, uint32_t count);
} TarkinVideoLayer;
-typedef struct
-{
- uint32_t numerator;
- uint32_t denominator;
-} TarkinTime; /* Let's say the unit is 1 second */
-
-typedef struct TarkinInfo
-{
- int version;
- int n_layers;
- TarkinVideoLayer *layer;
- TarkinTime inter; /* numerator == O if per-frame time info. */
- int frames_per_block;
- int comp_per_block; /* AKA "packets per block" for now */
- uint32_t max_bitstream_len;
+typedef struct {
+ uint32_t numerator;
+ uint32_t denominator;
+} TarkinTime; /* Let's say the unit is 1 second */
+
+typedef struct TarkinInfo {
+ int version;
+ int n_layers;
+ TarkinVideoLayer *layer;
+ TarkinTime inter; /* numerator == O if per-frame time info. */
+ int frames_per_block;
+ int comp_per_block; /* AKA "packets per block" for now */
+ uint32_t max_bitstream_len;
/* The below bitrate declarations are *hints*.
Combinations of the three values carry the following implications:
-
+
all three set to the same value:
- implies a fixed rate bitstream
+ implies a fixed rate bitstream
only nominal set:
- implies a VBR stream that averages the nominal bitrate. No hard
- upper/lower limit
+ implies a VBR stream that averages the nominal bitrate. No hard
+ upper/lower limit
upper and or lower set:
- implies a VBR bitstream that obeys the bitrate limits. nominal
- may also be set to give a nominal rate.
+ implies a VBR bitstream that obeys the bitrate limits. nominal
+ may also be set to give a nominal rate.
none set:
- the coder does not care to speculate.
- */
+ the coder does not care to speculate.
+ */
- long bitrate_upper;
- long bitrate_nominal;
- long bitrate_lower;
- long bitrate_window;
+ long bitrate_upper;
+ long bitrate_nominal;
+ long bitrate_lower;
+ long bitrate_window;
} TarkinInfo;
/* This is used for encoding */
-typedef struct
-{
- unsigned char *header;
- unsigned char *header1;
- unsigned char *header2;
+typedef struct {
+ unsigned char *header;
+ unsigned char *header1;
+ unsigned char *header2;
} tarkin_header_store;
@@ -134,33 +124,31 @@ typedef struct
/* Some of the fields in TarkinStream are redundent with TarkinInfo ones
* and will probably get deleted, namely n_layers and frames_per_buf */
-typedef struct TarkinStream
-{
- uint32_t n_layers;
- TarkinVideoLayer *layer;
- uint32_t current_frame;
- uint32_t current_frame_in_buf;
- ogg_int64_t packetno;
- uint32_t frames_per_buf;
- uint32_t max_bitstream_len;
- TarkinInfo *ti;
- tarkin_header_store headers;
- /* These callbacks are only used for encoding */
- TarkinError (*free_frame) (void *tarkinstream, void *ptr);
- /* These thing allows not to buffer but it needs global var in caller. */
- TarkinError (*packet_out) (void *tarkinstream, ogg_packet * ptr);
- void *user_ptr;
+typedef struct TarkinStream {
+ uint32_t n_layers;
+ TarkinVideoLayer *layer;
+ uint32_t current_frame;
+ uint32_t current_frame_in_buf;
+ ogg_int64_t packetno;
+ uint32_t frames_per_buf;
+ uint32_t max_bitstream_len;
+ TarkinInfo *ti;
+ tarkin_header_store headers;
+ /* These callbacks are only used for encoding */
+ TarkinError (*free_frame)(void *tarkinstream, void *ptr);
+ /* These thing allows not to buffer but it needs global var in caller. */
+ TarkinError (*packet_out)(void *tarkinstream, ogg_packet *ptr);
+ void * user_ptr;
} TarkinStream;
-typedef struct TarkinComment
-{
+typedef struct TarkinComment{
/* unlimited user comment fields. libtarkin writes 'libtarkin'
whatever vendor is set to in encode */
char **user_comments;
- int *comment_lengths;
- int comments;
- char *vendor;
+ int *comment_lengths;
+ int comments;
+ char *vendor;
} TarkinComment;
@@ -173,17 +161,17 @@ typedef struct TarkinComment
/* Theses are the very same than Vorbis versions, they could be shared. */
-extern TarkinStream *tarkin_stream_new ();
-extern void tarkin_stream_destroy (TarkinStream * s);
-extern void tarkin_info_init (TarkinInfo * vi);
-extern void tarkin_info_clear (TarkinInfo * vi);
-extern void tarkin_comment_init (TarkinComment * vc);
-extern void tarkin_comment_add (TarkinComment * vc, char *comment);
-extern void tarkin_comment_add_tag (TarkinComment * vc,
- char *tag, char *contents);
-extern char *tarkin_comment_query (TarkinComment * vc, char *tag, int count);
-extern int tarkin_comment_query_count (TarkinComment * vc, char *tag);
-extern void tarkin_comment_clear (TarkinComment * vc);
+extern TarkinStream* tarkin_stream_new ();
+extern void tarkin_stream_destroy (TarkinStream *s);
+extern void tarkin_info_init(TarkinInfo *vi);
+extern void tarkin_info_clear(TarkinInfo *vi);
+extern void tarkin_comment_init(TarkinComment *vc);
+extern void tarkin_comment_add(TarkinComment *vc, char *comment);
+extern void tarkin_comment_add_tag(TarkinComment *vc,
+ char *tag, char *contents);
+extern char *tarkin_comment_query(TarkinComment *vc, char *tag, int count);
+extern int tarkin_comment_query_count(TarkinComment *vc, char *tag);
+extern void tarkin_comment_clear(TarkinComment *vc);
/* Tarkin PRIMITIVES: analysis layer ****************************/
/* Tarkin encoding is done this way : you init it passing a fresh
@@ -193,50 +181,59 @@ extern void tarkin_comment_clear (TarkinComment * vc);
* is called when a packet is ready. The pointers given as arguments to
* these callback functions are of course only valid at the function call
* time. The user_ptr is stored in s and can be used by packet_out(). */
-extern int tarkin_analysis_init (TarkinStream * s,
- TarkinInfo * ti,
- TarkinError (*free_frame) (void *tarkinstream, void *ptr),
- TarkinError (*packet_out) (void *tarkinstream, ogg_packet * ptr),
- void *user_ptr);
+extern int tarkin_analysis_init(TarkinStream *s,
+ TarkinInfo *ti,
+ TarkinError (*free_frame)(void *tarkinstream, void *ptr),
+ TarkinError (*packet_out)(void *tarkinstream, ogg_packet *ptr),
+ void *user_ptr
+ );
/* Then you need to add at least a layer in your stream, passing a
* TarkinVideoLayerDesc renseigned at least on the width, height and
* format parameters. */
-extern int tarkin_analysis_add_layer (TarkinStream * s,
- TarkinVideoLayerDesc * tvld);
+extern int tarkin_analysis_add_layer(TarkinStream *s,
+ TarkinVideoLayerDesc *tvld);
/* At that point you are ready to get headers out the lib by calling
* tarkin_analysis_headerout() passing it a renseigned TarkinComment
* structure. It does fill your 3 ogg_packet headers, which are valid
* till next call */
-extern int TarkinCommentheader_out (TarkinComment * vc, ogg_packet * op);
-extern TarkinError tarkin_analysis_headerout (TarkinStream * s,
- TarkinComment * vc,
- ogg_packet * op, ogg_packet * op_comm, ogg_packet * op_code);
+extern int TarkinCommentheader_out(TarkinComment *vc, ogg_packet *op);
+extern TarkinError tarkin_analysis_headerout(TarkinStream *s,
+ TarkinComment *vc,
+ ogg_packet *op,
+ ogg_packet *op_comm,
+ ogg_packet *op_code);
/* You are now ready to pass in frames to the codec, however don't free
* them before the codec told you so. It'll tell you when packets are
* ready to be taken out. When you have no more frame, simply pass NULL.
* If you encode multiple layers you have to do it synchronously, putting
* one frame from each layer at a time. */
-extern uint32_t tarkin_analysis_framein (TarkinStream * s, uint8_t * frame, /* NULL for EOS */
- uint32_t layer, TarkinTime * date);
+extern uint32_t tarkin_analysis_framein(TarkinStream *s,
+ uint8_t *frame, /* NULL for EOS */
+ uint32_t layer,
+ TarkinTime *date);
/* Tarkin PRIMITIVES: synthesis layer *******************************/
/* For decoding, you needs first to give the three first packet of the
* stream to tarkin_synthesis_headerin() which will fill for you blank
* TarkinInfo and TarkinComment. */
-extern TarkinError tarkin_synthesis_headerin (TarkinInfo * vi,
- TarkinComment * vc, ogg_packet * op);
+extern TarkinError tarkin_synthesis_headerin(TarkinInfo *vi,TarkinComment *vc,
+ ogg_packet *op);
/* Then you can init your stream with your TarkinInfo struct. */
-extern TarkinError tarkin_synthesis_init (TarkinStream * s, TarkinInfo * ti);
-
+extern TarkinError tarkin_synthesis_init(TarkinStream *s,TarkinInfo *ti);
/* All subsequent packets are to this be passed to tarkin_synthesis_packetin*/
-extern TarkinError tarkin_synthesis_packetin (TarkinStream * s,
- ogg_packet * op);
+extern TarkinError tarkin_synthesis_packetin(TarkinStream *s, ogg_packet *op);
/* and then tarkin_synthesis_frameout gives you ptr on next frame, or NULL. It
* also fills for you date. */
-extern TarkinError tarkin_synthesis_frameout (TarkinStream * s,
- uint8_t ** frame, uint32_t layer_id, TarkinTime * date);
+extern TarkinError tarkin_synthesis_frameout(TarkinStream *s,
+ uint8_t **frame, uint32_t layer_id, TarkinTime *date);
/* When you're done with a frame, tell it to the codec with this. */
-extern int tarkin_synthesis_freeframe (TarkinStream * s, uint8_t * frame);
+extern int tarkin_synthesis_freeframe(TarkinStream *s, uint8_t *frame);
#endif
+
+
+
+
+
+
diff --git a/ext/tarkin/wavelet.h b/ext/tarkin/wavelet.h
index 13d84e8b..914c2799 100644
--- a/ext/tarkin/wavelet.h
+++ b/ext/tarkin/wavelet.h
@@ -4,25 +4,24 @@
#include <stdint.h>
-typedef struct
-{
- TYPE *data;
- uint32_t width;
- uint32_t height;
- uint32_t frames;
- uint32_t scales;
- uint32_t *w;
- uint32_t *h;
- uint32_t *f;
- uint32_t (*offset)[8];
- TYPE *scratchbuf;
+typedef struct {
+ TYPE *data;
+ uint32_t width;
+ uint32_t height;
+ uint32_t frames;
+ uint32_t scales;
+ uint32_t *w;
+ uint32_t *h;
+ uint32_t *f;
+ uint32_t (*offset)[8];
+ TYPE *scratchbuf;
} Wavelet3DBuf;
-extern Wavelet3DBuf *wavelet_3d_buf_new (uint32_t width, uint32_t height,
- uint32_t frames);
+extern Wavelet3DBuf* wavelet_3d_buf_new (uint32_t width, uint32_t height,
+ uint32_t frames);
-extern void wavelet_3d_buf_destroy (Wavelet3DBuf * buf);
+extern void wavelet_3d_buf_destroy (Wavelet3DBuf* buf);
/**
* transform buf->data
@@ -30,21 +29,25 @@ extern void wavelet_3d_buf_destroy (Wavelet3DBuf * buf);
* highpass filter,
* s_moments the one of the synthesizing lowpass filter.
*/
-extern void wavelet_3d_buf_fwd_xform (Wavelet3DBuf * buf,
- int a_moments, int s_moments);
-extern void wavelet_3d_buf_inv_xform (Wavelet3DBuf * buf,
- int a_moments, int s_moments);
+extern void wavelet_3d_buf_fwd_xform (Wavelet3DBuf* buf,
+ int a_moments, int s_moments);
+extern void wavelet_3d_buf_inv_xform (Wavelet3DBuf* buf,
+ int a_moments, int s_moments);
-extern int wavelet_3d_buf_encode_coeff (const Wavelet3DBuf * buf,
- uint8_t * bitstream, uint32_t limit);
+extern int wavelet_3d_buf_encode_coeff (const Wavelet3DBuf* buf,
+ uint8_t *bitstream,
+ uint32_t limit);
-extern void wavelet_3d_buf_decode_coeff (Wavelet3DBuf * buf,
- uint8_t * bitstream, uint32_t limit);
+extern void wavelet_3d_buf_decode_coeff (Wavelet3DBuf* buf,
+ uint8_t *bitstream,
+ uint32_t limit);
#if defined(DBG_XFORM)
extern void wavelet_3d_buf_dump (char *fmt,
- uint32_t first_frame_in_buf,
- uint32_t id, Wavelet3DBuf * buf, int16_t offset);
+ uint32_t first_frame_in_buf,
+ uint32_t id,
+ Wavelet3DBuf* buf,
+ int16_t offset);
#else
#define wavelet_3d_buf_dump(x...)
#endif
diff --git a/ext/tarkin/yuv.h b/ext/tarkin/yuv.h
index 31711bc6..42ceb072 100644
--- a/ext/tarkin/yuv.h
+++ b/ext/tarkin/yuv.h
@@ -5,16 +5,17 @@
#include <stdint.h>
#include "wavelet.h"
-extern void rgb24_to_yuv (uint8_t * rgb, Wavelet3DBuf * yuv[], uint32_t frame);
-extern void yuv_to_rgb24 (Wavelet3DBuf * yuv[], uint8_t * rgb, uint32_t frame);
+extern void rgb24_to_yuv (uint8_t *rgb, Wavelet3DBuf *yuv [], uint32_t frame);
+extern void yuv_to_rgb24 (Wavelet3DBuf *yuv [], uint8_t *rgb, uint32_t frame);
-extern void rgb32_to_yuv (uint8_t * rgb, Wavelet3DBuf * yuv[], uint32_t frame);
-extern void yuv_to_rgb32 (Wavelet3DBuf * yuv[], uint8_t * rgb, uint32_t frame);
+extern void rgb32_to_yuv (uint8_t *rgb, Wavelet3DBuf *yuv [], uint32_t frame);
+extern void yuv_to_rgb32 (Wavelet3DBuf *yuv [], uint8_t *rgb, uint32_t frame);
-extern void rgba_to_yuv (uint8_t * rgba, Wavelet3DBuf * yuva[], uint32_t frame);
-extern void yuv_to_rgba (Wavelet3DBuf * yuva[], uint8_t * rgba, uint32_t frame);
+extern void rgba_to_yuv (uint8_t *rgba, Wavelet3DBuf *yuva [], uint32_t frame);
+extern void yuv_to_rgba (Wavelet3DBuf *yuva [], uint8_t *rgba, uint32_t frame);
-extern void grayscale_to_y (uint8_t * rgba, Wavelet3DBuf * y[], uint32_t frame);
-extern void y_to_grayscale (Wavelet3DBuf * y[], uint8_t * rgba, uint32_t frame);
+extern void grayscale_to_y (uint8_t *rgba, Wavelet3DBuf *y [], uint32_t frame);
+extern void y_to_grayscale (Wavelet3DBuf *y [], uint8_t *rgba, uint32_t frame);
#endif
+