diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-07-25 12:23:31 +0200 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2012-10-15 08:32:18 +0200 |
commit | cd559bb49a3417ab1ca75df3de0029300e5095df (patch) | |
tree | 7819ecb065e546cbed1e518ca0798886f3b44494 /libavcodec/xface.h | |
parent | 35782bfbca0abe39e33d65a771834c6b87855c16 (diff) | |
download | ffmpeg-cd559bb49a3417ab1ca75df3de0029300e5095df.tar.gz |
lavc: add xface image decoder and encoder
Based on libcompface code by James Ashton <James.Ashton@anu.edu.au>, and
relicensed to LGPL with the author's consent.
Diffstat (limited to 'libavcodec/xface.h')
-rw-r--r-- | libavcodec/xface.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/libavcodec/xface.h b/libavcodec/xface.h new file mode 100644 index 0000000000..cd59ba084a --- /dev/null +++ b/libavcodec/xface.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 1990 James Ashton - Sydney University + * Copyright (c) 2012 Stefano Sabatini + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * X-Face common definitions. + */ + +#include <stdint.h> + +/* define the face size - 48x48x1 */ +#define XFACE_WIDTH 48 +#define XFACE_HEIGHT 48 +#define XFACE_PIXELS (XFACE_WIDTH * XFACE_HEIGHT) + +/* compressed output uses the full range of printable characters. + * In ASCII these are in a contiguous block so we just need to know + * the first and last. The total number of printables is needed too. */ +#define XFACE_FIRST_PRINT '!' +#define XFACE_LAST_PRINT '~' +#define XFACE_PRINTS (XFACE_LAST_PRINT - XFACE_FIRST_PRINT + 1) + +/* + * Image is encoded as a big integer, using characters from '~' to + * '!', for a total of 92 symbols. In order to express 48x48=2304 + * bits, we need a total of 354 digits, as given by: + * ceil(lg_92(2^2304)) = 354 + */ +#define XFACE_MAX_DIGITS 354 + +#define XFACE_BITSPERWORD 8 +#define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD) +#define XFACE_WORDMASK (XFACE_WORDCARRY - 1) + +#define XFACE_MAX_WORDS ((XFACE_PIXELS * 2 + XFACE_BITSPERWORD - 1) / XFACE_BITSPERWORD) + +/* Portable, very large unsigned integer arithmetic is needed. + * Implementation uses arrays of WORDs. */ +typedef struct { + int nb_words; + uint8_t words[XFACE_MAX_WORDS]; +} BigInt; + +/** + * Add a to b storing the result in b. + */ +void ff_big_add(BigInt *b, uint8_t a); + +/** + * Divide b by a storing the result in b and the remainder in the word + * pointed to by r. + */ +void ff_big_div(BigInt *b, uint8_t a, uint8_t *r); + +/** + * Multiply a by b storing the result in b. + */ +void ff_big_mul(BigInt *b, uint8_t a); + +/* Each face is encoded using 9 octrees of 16x16 each. Each level of the + * trees has varying probabilities of being white, grey or black. + * The table below is based on sampling many faces */ +enum XFaceColor { XFACE_COLOR_BLACK = 0, XFACE_COLOR_GREY, XFACE_COLOR_WHITE }; + +/* Data of varying probabilities are encoded by a value in the range 0 - 255. + * The probability of the data determines the range of possible encodings. + * Offset gives the first possible encoding of the range. */ +typedef struct { + int range; + int offset; +} ProbRange; + +extern const ProbRange ff_xface_probranges_per_level[4][3]; + +extern const ProbRange ff_xface_probranges_2x2[16]; + +void ff_xface_generate_face(uint8_t *dst, uint8_t * const src); |