1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Copyright (c) 1990 James Ashton - Sydney University 3cabdff1aSopenharmony_ci * Copyright (c) 2012 Stefano Sabatini 4cabdff1aSopenharmony_ci * 5cabdff1aSopenharmony_ci * This file is part of FFmpeg. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11cabdff1aSopenharmony_ci * 12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15cabdff1aSopenharmony_ci * Lesser General Public License for more details. 16cabdff1aSopenharmony_ci * 17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20cabdff1aSopenharmony_ci */ 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci/** 23cabdff1aSopenharmony_ci * @file 24cabdff1aSopenharmony_ci * X-Face common definitions. 25cabdff1aSopenharmony_ci */ 26cabdff1aSopenharmony_ci 27cabdff1aSopenharmony_ci#ifndef AVCODEC_XFACE_H 28cabdff1aSopenharmony_ci#define AVCODEC_XFACE_H 29cabdff1aSopenharmony_ci 30cabdff1aSopenharmony_ci#include <stdint.h> 31cabdff1aSopenharmony_ci 32cabdff1aSopenharmony_ci/* define the face size - 48x48x1 */ 33cabdff1aSopenharmony_ci#define XFACE_WIDTH 48 34cabdff1aSopenharmony_ci#define XFACE_HEIGHT 48 35cabdff1aSopenharmony_ci#define XFACE_PIXELS (XFACE_WIDTH * XFACE_HEIGHT) 36cabdff1aSopenharmony_ci 37cabdff1aSopenharmony_ci/* compressed output uses the full range of printable characters. 38cabdff1aSopenharmony_ci * In ASCII these are in a contiguous block so we just need to know 39cabdff1aSopenharmony_ci * the first and last. The total number of printables is needed too. */ 40cabdff1aSopenharmony_ci#define XFACE_FIRST_PRINT '!' 41cabdff1aSopenharmony_ci#define XFACE_LAST_PRINT '~' 42cabdff1aSopenharmony_ci#define XFACE_PRINTS (XFACE_LAST_PRINT - XFACE_FIRST_PRINT + 1) 43cabdff1aSopenharmony_ci 44cabdff1aSopenharmony_ci/* 45cabdff1aSopenharmony_ci * Image is encoded as a big integer, using characters from '~' to 46cabdff1aSopenharmony_ci * '!', for a total of 94 symbols. In order to express 47cabdff1aSopenharmony_ci * 48x48 pixels with the worst case encoding 666 symbols should 48cabdff1aSopenharmony_ci * be sufficient. 49cabdff1aSopenharmony_ci */ 50cabdff1aSopenharmony_ci#define XFACE_MAX_DIGITS 666 51cabdff1aSopenharmony_ci 52cabdff1aSopenharmony_ci#define XFACE_BITSPERWORD 8 53cabdff1aSopenharmony_ci#define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD) 54cabdff1aSopenharmony_ci#define XFACE_WORDMASK (XFACE_WORDCARRY - 1) 55cabdff1aSopenharmony_ci 56cabdff1aSopenharmony_ci// This must be larger or equal to log256(94^XFACE_MAX_DIGITS) 57cabdff1aSopenharmony_ci#define XFACE_MAX_WORDS 546 58cabdff1aSopenharmony_ci 59cabdff1aSopenharmony_ci/* Portable, very large unsigned integer arithmetic is needed. 60cabdff1aSopenharmony_ci * Implementation uses arrays of WORDs. */ 61cabdff1aSopenharmony_citypedef struct { 62cabdff1aSopenharmony_ci int nb_words; 63cabdff1aSopenharmony_ci uint8_t words[XFACE_MAX_WORDS]; 64cabdff1aSopenharmony_ci} BigInt; 65cabdff1aSopenharmony_ci 66cabdff1aSopenharmony_ci/** 67cabdff1aSopenharmony_ci * Add a to b storing the result in b. 68cabdff1aSopenharmony_ci */ 69cabdff1aSopenharmony_civoid ff_big_add(BigInt *b, uint8_t a); 70cabdff1aSopenharmony_ci 71cabdff1aSopenharmony_ci/** 72cabdff1aSopenharmony_ci * Divide b by a storing the result in b and the remainder in the word 73cabdff1aSopenharmony_ci * pointed to by r. 74cabdff1aSopenharmony_ci */ 75cabdff1aSopenharmony_civoid ff_big_div(BigInt *b, uint8_t a, uint8_t *r); 76cabdff1aSopenharmony_ci 77cabdff1aSopenharmony_ci/** 78cabdff1aSopenharmony_ci * Multiply a by b storing the result in b. 79cabdff1aSopenharmony_ci */ 80cabdff1aSopenharmony_civoid ff_big_mul(BigInt *b, uint8_t a); 81cabdff1aSopenharmony_ci 82cabdff1aSopenharmony_ci/* Each face is encoded using 9 octrees of 16x16 each. Each level of the 83cabdff1aSopenharmony_ci * trees has varying probabilities of being white, grey or black. 84cabdff1aSopenharmony_ci * The table below is based on sampling many faces */ 85cabdff1aSopenharmony_cienum XFaceColor { XFACE_COLOR_BLACK = 0, XFACE_COLOR_GREY, XFACE_COLOR_WHITE }; 86cabdff1aSopenharmony_ci 87cabdff1aSopenharmony_ci/* Data of varying probabilities are encoded by a value in the range 0 - 255. 88cabdff1aSopenharmony_ci * The probability of the data determines the range of possible encodings. 89cabdff1aSopenharmony_ci * Offset gives the first possible encoding of the range. */ 90cabdff1aSopenharmony_citypedef struct { 91cabdff1aSopenharmony_ci uint8_t range; 92cabdff1aSopenharmony_ci uint8_t offset; 93cabdff1aSopenharmony_ci} ProbRange; 94cabdff1aSopenharmony_ci 95cabdff1aSopenharmony_ciextern const ProbRange ff_xface_probranges_per_level[4][3]; 96cabdff1aSopenharmony_ci 97cabdff1aSopenharmony_ciextern const ProbRange ff_xface_probranges_2x2[16]; 98cabdff1aSopenharmony_ci 99cabdff1aSopenharmony_civoid ff_xface_generate_face(uint8_t *dst, uint8_t * const src); 100cabdff1aSopenharmony_ci 101cabdff1aSopenharmony_ci#endif /* AVCODEC_XFACE_H */ 102