62#define SKIP_PREFIX 0x8400
63#define SKIPS_MAX 0x03FF
64#define MKRGB555(in, off) (((in)[off] << 10) | ((in)[(off) + 1] << 5) | ((in)[(off) + 2]))
66static const int remap[16] = { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15 };
69 const AVFrame *pict,
int *got_packet)
78 int i, j, k, x, y, ret;
91 src = (
const uint16_t*)(p->data[0] + p->linesize[0]*(
FFALIGN(avctx->
height, 4) - 1));
96 for(y = 0; y < avctx->
height; y += 4){
97 for(x = 0; x < avctx->
width; x += 4){
99 int bestscore = INT_MAX;
103 for(j = 0; j < 4; j++){
104 for(
i = 0;
i < 4;
i++){
105 uint16_t
val =
src[x +
i - j*p->linesize[0]/2];
106 for(k = 0; k < 3; k++){
107 c->block[(
i + j*4)*3 + k] =
108 c->block2[
remap[
i + j*4]*3 + k] = (
val >> (10-k*5)) & 0x1F;
114 for(j = 0; j < 4; j++){
115 for(
i = 0;
i < 4*3;
i++){
116 int t = prevptr[x*3 +
i - j*3*avctx->
width] -
c->block[
i + j*4*3];
125 1, 1,
c->output, &
c->rnd, 0);
130 for(j = 0; j < 4; j++){
131 for(
i = 0;
i < 4;
i++){
132 for(k = 0; k < 3; k++){
133 int t =
c->avg[k] -
c->block[(
i+j*4)*3+k];
140 if(score < bestscore){
147 2, 1,
c->output, &
c->rnd, 0);
152 for(
i = 0;
i < 3;
i++)
153 FFSWAP(uint8_t,
c->codebook[
i],
c->codebook[
i+3]);
154 for(
i = 0;
i < 16;
i++)
157 for(j = 0; j < 4; j++){
158 for(
i = 0;
i < 4;
i++){
159 for(k = 0; k < 3; k++){
160 int t =
c->codebook[
c->output[
i+j*4]*3 + k] -
c->block[
i*3+k+j*4*3];
167 if(score < bestscore){
173 for(
i = 0;
i < 4;
i++){
175 c->codebook2 +
i * 2 * 3, 2, 1,
176 c->output2 +
i * 4, &
c->rnd, 0);
182 for(
i = 0;
i < 3;
i++)
183 FFSWAP(uint8_t,
c->codebook2[
i+18],
c->codebook2[
i+21]);
184 for(
i = 12;
i < 16;
i++)
187 for(j = 0; j < 4; j++){
188 for(
i = 0;
i < 4;
i++){
189 for(k = 0; k < 3; k++){
190 int t =
c->codebook2[(
c->output2[
remap[
i+j*4]] + (
i&2) + (j&2)*2)*3+k] -
c->block[
i*3+k + j*4*3];
197 if(score < bestscore){
214 for(j = 0; j < 4; j++)
215 for(
i = 0;
i < 4;
i++)
216 for(k = 0; k < 3; k++)
217 prevptr[x*3 +
i*3 + k - j*3*avctx->
width] =
c->avg[k];
220 for(j = 0; j < 4; j++){
221 for(
i = 0;
i < 4;
i++){
222 flags |= (
c->output[
i + j*4]^1) << (
i + j*4);
223 for(k = 0; k < 3; k++)
224 prevptr[x*3 +
i*3 + k - j*3*avctx->
width] =
c->codebook[
c->output[
i + j*4]*3 + k];
232 for(j = 0; j < 4; j++){
233 for(
i = 0;
i < 4;
i++){
235 for(k = 0; k < 3; k++)
236 prevptr[x*3 +
i*3 + k - j*3*avctx->
width] =
c->codebook2[(
c->output2[
remap[
i+j*4]] + (
i&2) + (j&2)*2)*3 + k];
240 bytestream_put_le16(&
dst,
MKRGB555(
c->codebook2, 0) | 0x8000);
241 for(
i = 3;
i < 24;
i += 3)
246 src -= p->linesize[0] << 1;
247 prevptr -= avctx->
width * 3 * 4;
252 bytestream_put_byte(&
dst, 0);
253 bytestream_put_byte(&
dst, 0);
309 .p.name =
"msvideo1",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_msvideo1_encoder
static av_cold int encode_init(AVCodecContext *avctx)
Libavcodec external API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
int(* init)(AVBSFContext *ctx)
int avpriv_elbg_do(ELBGContext **elbgp, int *points, int dim, int numpoints, int *codebook, int num_cb, int max_steps, int *closest_cb, AVLFG *rand_state, uintptr_t flags)
Implementation of the Enhanced LBG Algorithm Based on the paper "Neural Networks 14:1219-1237" that c...
av_cold void avpriv_elbg_free(ELBGContext **elbgp)
Free an ELBGContext and reset the pointer to it.
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
static av_cold int encode_end(AVCodecContext *avctx)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
#define FFSWAP(type, a, b)
Memory handling functions.
static const int remap[16]
static av_cold int encode_init(AVCodecContext *avctx)
init encoder
#define MKRGB555(in, off)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static av_cold int encode_end(AVCodecContext *avctx)
Uninit encoder.
#define AV_PIX_FMT_RGB555
main external API structure.
int width
picture width / height.
int keyint_min
minimum GOP size
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
This structure describes decoded (raw) audio or video data.
Context structure for the Lagged Fibonacci PRNG.
This structure stores compressed data.
struct ELBGContext * elbg
static const uint8_t quality[]