vpx/vp9/encoder/vp9_writer.h
hui su caccf06acd Palette-based coding experiment
Added palette coding option for Y channel only, key frame only.
Palette colors are obtained with k-means clustering algorithm.
Run-length coding is used to compress the color indices.

On screen_content:
--enable-palette                            + 5.75%
--enable-palette --enable-tx_skip           +15.04% (was 13.3%)

On derflr:
--enable-palette                            - 0.03%
with all the other expriments               + 5.95% (was 5.98%)

Change-Id: I6d1cf45c889be764d14083170fdf14a424bd31b5
2015-02-23 09:23:50 -08:00

122 lines
2.6 KiB
C

/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VP9_ENCODER_VP9_WRITER_H_
#define VP9_ENCODER_VP9_WRITER_H_
#include "vpx_ports/mem.h"
#include "vp9/common/vp9_prob.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned int lowvalue;
unsigned int range;
int count;
unsigned int pos;
uint8_t *buffer;
} vp9_writer;
void vp9_start_encode(vp9_writer *bc, uint8_t *buffer);
void vp9_stop_encode(vp9_writer *bc);
static INLINE void vp9_write(vp9_writer *br, int bit, int probability) {
unsigned int split;
int count = br->count;
unsigned int range = br->range;
unsigned int lowvalue = br->lowvalue;
register unsigned int shift;
split = 1 + (((range - 1) * probability) >> 8);
range = split;
if (bit) {
lowvalue += split;
range = br->range - split;
}
shift = vp9_norm[range];
range <<= shift;
count += shift;
if (count >= 0) {
int offset = shift - count;
if ((lowvalue << (offset - 1)) & 0x80000000) {
int x = br->pos - 1;
while (x >= 0 && br->buffer[x] == 0xff) {
br->buffer[x] = 0;
x--;
}
br->buffer[x] += 1;
}
br->buffer[br->pos++] = (lowvalue >> (24 - offset));
lowvalue <<= offset;
shift = count;
lowvalue &= 0xffffff;
count -= 8;
}
lowvalue <<= shift;
br->count = count;
br->lowvalue = lowvalue;
br->range = range;
}
static INLINE void vp9_write_bit(vp9_writer *w, int bit) {
vp9_write(w, bit, 128); // vp9_prob_half
}
static INLINE void vp9_write_literal(vp9_writer *w, int data, int bits) {
int bit;
for (bit = bits - 1; bit >= 0; bit--)
vp9_write_bit(w, 1 & (data >> bit));
}
static INLINE void vp9_encode_uniform(vp9_writer *w, int n, int v) {
int l = get_unsigned_bits(n);
int m = (1 << l) - n;
if (l == 0)
return;
if (v < m) {
vp9_write_literal(w, v, l - 1);
} else {
vp9_write_literal(w, m + ((v - m) >> 1), l - 1);
vp9_write_literal(w, (v - m) & 1, 1);
}
}
static INLINE int vp9_encode_uniform_cost(int n, int v) {
int l = get_unsigned_bits(n), m = (1 << l) - n;
if (l == 0)
return 0;
if (v < m)
return l - 1;
else
return l;
}
#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
#ifdef __cplusplus
} // extern "C"
#endif
#endif // VP9_ENCODER_VP9_WRITER_H_