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