#include "utvideo.h"
#include "huffman.h"
+typedef struct HuffEntry {
+ uint16_t sym;
+ uint8_t len;
+ uint32_t code;
+} HuffEntry;
+
+#if FF_API_PRIVATE_OPT
+static const int ut_pred_order[5] = {
+ PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT
+};
+#endif
+
+/* Compare huffman tree nodes */
+static int ut_huff_cmp_len(const void *a, const void *b)
+{
+ const HuffEntry *aa = a, *bb = b;
+ return (aa->len - bb->len)*256 + aa->sym - bb->sym;
+}
+
/* Compare huffentry symbols */
static int huff_cmp_sym(const void *a, const void *b)
{
/* Convert from libavcodec prediction type to Ut Video's */
if (avctx->prediction_method)
- c->frame_pred = ff_ut_pred_order[avctx->prediction_method];
+ c->frame_pred = ut_pred_order[avctx->prediction_method];
FF_ENABLE_DEPRECATION_WARNINGS
#endif
int last, i;
uint32_t code;
- qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
+ qsort(he, 256, sizeof(*he), ut_huff_cmp_len);
last = 255;
while (he[last].len == 255 && last)
last--;
- code = 1;
+ code = 0;
for (i = last; i >= 0; i--) {
he[i].code = code >> (32 - he[i].len);
code += 0x80000000u >> (he[i].len - 1);
if (count)
put_bits(&pb, 32 - count, 0);
- /* Get the amount of bits written */
- count = put_bits_count(&pb);
-
/* Flush the rest with zeroes */
flush_put_bits(&pb);
- return count;
+ /* Return the amount of bytes written */
+ return put_bytes_output(&pb);
}
static int encode_plane(AVCodecContext *avctx, uint8_t *src,
/*
* Write the huffman codes to a buffer,
- * get the offset in bits and convert to bytes.
+ * get the offset in bytes.
*/
offset += write_huff_codes(dst + sstart * width, c->slice_bits,
width * height + 4, width,
- send - sstart, he) >> 3;
+ send - sstart, he);
slice_len = offset - slice_len;