00001 /* 00002 * Copyright (c) 1990 James Ashton - Sydney University 00003 * Copyright (c) 2012 Stefano Sabatini 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00027 #include <stdint.h> 00028 00029 /* define the face size - 48x48x1 */ 00030 #define XFACE_WIDTH 48 00031 #define XFACE_HEIGHT 48 00032 #define XFACE_PIXELS (XFACE_WIDTH * XFACE_HEIGHT) 00033 00034 /* compressed output uses the full range of printable characters. 00035 * In ASCII these are in a contiguous block so we just need to know 00036 * the first and last. The total number of printables is needed too. */ 00037 #define XFACE_FIRST_PRINT '!' 00038 #define XFACE_LAST_PRINT '~' 00039 #define XFACE_PRINTS (XFACE_LAST_PRINT - XFACE_FIRST_PRINT + 1) 00040 00041 /* 00042 * Image is encoded as a big integer, using characters from '~' to 00043 * '!', for a total of 92 symbols. In order to express 48x48=2304 00044 * bits, we need a total of 354 digits, as given by: 00045 * ceil(lg_92(2^2304)) = 354 00046 */ 00047 #define XFACE_MAX_DIGITS 354 00048 00049 #define XFACE_BITSPERWORD 8 00050 #define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD) 00051 #define XFACE_WORDMASK (XFACE_WORDCARRY - 1) 00052 00053 #define XFACE_MAX_WORDS ((XFACE_PIXELS * 2 + XFACE_BITSPERWORD - 1) / XFACE_BITSPERWORD) 00054 00055 /* Portable, very large unsigned integer arithmetic is needed. 00056 * Implementation uses arrays of WORDs. */ 00057 typedef struct { 00058 int nb_words; 00059 uint8_t words[XFACE_MAX_WORDS]; 00060 } BigInt; 00061 00065 void ff_big_add(BigInt *b, uint8_t a); 00066 00071 void ff_big_div(BigInt *b, uint8_t a, uint8_t *r); 00072 00076 void ff_big_mul(BigInt *b, uint8_t a); 00077 00078 /* Each face is encoded using 9 octrees of 16x16 each. Each level of the 00079 * trees has varying probabilities of being white, grey or black. 00080 * The table below is based on sampling many faces */ 00081 enum XFaceColor { XFACE_COLOR_BLACK = 0, XFACE_COLOR_GREY, XFACE_COLOR_WHITE }; 00082 00083 /* Data of varying probabilities are encoded by a value in the range 0 - 255. 00084 * The probability of the data determines the range of possible encodings. 00085 * Offset gives the first possible encoding of the range. */ 00086 typedef struct { 00087 int range; 00088 int offset; 00089 } ProbRange; 00090 00091 extern const ProbRange ff_xface_probranges_per_level[4][3]; 00092 00093 extern const ProbRange ff_xface_probranges_2x2[16]; 00094 00095 void ff_xface_generate_face(uint8_t *dst, uint8_t * const src);
1.5.8