/*
 * Copyright (C) 2007 Loren Merritt <lorenm@u.washington.edu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef _XLSC_H
#define _XLSC_H

#include <inttypes.h>

#define XLSC_API_VERSION 0

#define XLSC_FRAME_P 0
#define XLSC_FRAME_I 1
#define XLSC_FRAME_AUTO 2

#define XLSC_MC_2TAP 0
#define XLSC_MC_4TAP 1
#define XLSC_MC_4TAP_THRESHOLD 2
#define XLSC_MC_4TAP_ADAPTIVE 3
#define XLSC_MC_4TAP_ADAPTIVE_THRESHOLD 4

/* opaque context */
typedef struct xlsc_t xlsc_t;

typedef struct
{
    int width, height;
    int deadzone;      // quantization bias, 0 = round nearest, 1000 = round down
    char *dump_file;
    int keyint;        // max GOP length
    int lambda_mult;   // development only, to be removed
    int lookahead;
    float lookahead_lambda; // development only, to be removed
    int mb_decision;   // rdo vs inter-only
    int qp;
    int threads;
    int umv;           // allow subpel and mvs outside of the frame
    int verbose;
} xlsc_param_t;

typedef struct
{
    /* in: force picture type (if not auto)
     * out: type of the encoded picture */
    int     type;
    /* in: force quantizer if > 0
     * out: quantizer of the encoded picture */
    int     qp;
    /* in: raw data, luma only
     * out: reconstructed picture */
    int     stride;
    uint8_t *plane;
} xlsc_picture_t;

xlsc_t *xlsc_encoder_open( xlsc_param_t *, uint8_t **header, int *header_size );
int xlsc_encoder_close( xlsc_t * );

/* xlsc_encoder_encode:
 *  compress one frame
 *  out: buffer
 *  out: buffer_size
 *  in: pic
 *  return: 0 for success, negative for error */
int xlsc_encoder_encode( xlsc_t *, uint8_t **buffer, int *buffer_size, xlsc_picture_t *pic );

/* xlsc_decoder_open:
 * param is for returning stream info, not for configuring the decoder */
xlsc_t *xlsc_decoder_open( xlsc_param_t *, uint8_t *header, int header_size );
int xlsc_decoder_close( xlsc_t * );

/* xlsc_decoder_decode:
 *  decompress one frame
 *  in: buffer
 *  out: pic.
 *      pic->plane points into internal memory, so it must not be modified by the app,
 *      and it will be modified by libxlsc when you decode the next frame.
 *  return: 0 for success, negative for error */
int xlsc_decoder_decode( xlsc_t *, uint8_t *buffer, int buffer_size, xlsc_picture_t *pic );

/* xlsc_param_parse:
 *  set one parameter by name.
 *  returns 0 on success, or returns one of the following errors.
 *  note: BAD_VALUE occurs only if it can't even parse the value,
 *  numerical range is not checked until xlsc_encoder_open() or
 *  xlsc_encoder_reconfig().
 *  value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. */
#define XLSC_PARAM_BAD_NAME  (-1)
#define XLSC_PARAM_BAD_VALUE (-2)
int xlsc_param_parse( xlsc_param_t *, const char *name, const char *value );

void xlsc_param_default( xlsc_param_t * );

#endif //_XLSC_H
