yading@10: /* yading@10: * Copyright (c) 1990 James Ashton - Sydney University yading@10: * Copyright (c) 2012 Stefano Sabatini yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * X-Face common definitions. yading@10: */ yading@10: yading@10: #include yading@10: yading@10: /* define the face size - 48x48x1 */ yading@10: #define XFACE_WIDTH 48 yading@10: #define XFACE_HEIGHT 48 yading@10: #define XFACE_PIXELS (XFACE_WIDTH * XFACE_HEIGHT) yading@10: yading@10: /* compressed output uses the full range of printable characters. yading@10: * In ASCII these are in a contiguous block so we just need to know yading@10: * the first and last. The total number of printables is needed too. */ yading@10: #define XFACE_FIRST_PRINT '!' yading@10: #define XFACE_LAST_PRINT '~' yading@10: #define XFACE_PRINTS (XFACE_LAST_PRINT - XFACE_FIRST_PRINT + 1) yading@10: yading@10: /* yading@10: * Image is encoded as a big integer, using characters from '~' to yading@10: * '!', for a total of 92 symbols. In order to express 48x48=2304 yading@10: * bits, we need a total of 354 digits, as given by: yading@10: * ceil(lg_92(2^2304)) = 354 yading@10: */ yading@10: #define XFACE_MAX_DIGITS 354 yading@10: yading@10: #define XFACE_BITSPERWORD 8 yading@10: #define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD) yading@10: #define XFACE_WORDMASK (XFACE_WORDCARRY - 1) yading@10: yading@10: #define XFACE_MAX_WORDS ((XFACE_PIXELS * 2 + XFACE_BITSPERWORD - 1) / XFACE_BITSPERWORD) yading@10: yading@10: /* Portable, very large unsigned integer arithmetic is needed. yading@10: * Implementation uses arrays of WORDs. */ yading@10: typedef struct { yading@10: int nb_words; yading@10: uint8_t words[XFACE_MAX_WORDS]; yading@10: } BigInt; yading@10: yading@10: /** yading@10: * Add a to b storing the result in b. yading@10: */ yading@10: void ff_big_add(BigInt *b, uint8_t a); yading@10: yading@10: /** yading@10: * Divide b by a storing the result in b and the remainder in the word yading@10: * pointed to by r. yading@10: */ yading@10: void ff_big_div(BigInt *b, uint8_t a, uint8_t *r); yading@10: yading@10: /** yading@10: * Multiply a by b storing the result in b. yading@10: */ yading@10: void ff_big_mul(BigInt *b, uint8_t a); yading@10: yading@10: /* Each face is encoded using 9 octrees of 16x16 each. Each level of the yading@10: * trees has varying probabilities of being white, grey or black. yading@10: * The table below is based on sampling many faces */ yading@10: enum XFaceColor { XFACE_COLOR_BLACK = 0, XFACE_COLOR_GREY, XFACE_COLOR_WHITE }; yading@10: yading@10: /* Data of varying probabilities are encoded by a value in the range 0 - 255. yading@10: * The probability of the data determines the range of possible encodings. yading@10: * Offset gives the first possible encoding of the range. */ yading@10: typedef struct { yading@10: int range; yading@10: int offset; yading@10: } ProbRange; yading@10: yading@10: extern const ProbRange ff_xface_probranges_per_level[4][3]; yading@10: yading@10: extern const ProbRange ff_xface_probranges_2x2[16]; yading@10: yading@10: void ff_xface_generate_face(uint8_t *dst, uint8_t * const src);