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 #include <stdint.h>
28 
29 /* define the face size - 48x48x1 */
30 #define XFACE_WIDTH 48
31 #define XFACE_HEIGHT 48
32 #define XFACE_PIXELS (XFACE_WIDTH * XFACE_HEIGHT)
33 
34 /* compressed output uses the full range of printable characters.
35  * In ASCII these are in a contiguous block so we just need to know
36  * the first and last. The total number of printables is needed too. */
37 #define XFACE_FIRST_PRINT '!'
38 #define XFACE_LAST_PRINT '~'
39 #define XFACE_PRINTS (XFACE_LAST_PRINT - XFACE_FIRST_PRINT + 1)
40 
41 /*
42  * Image is encoded as a big integer, using characters from '~' to
43  * '!', for a total of 92 symbols. In order to express 48x48=2304
44  * bits, we need a total of 354 digits, as given by:
45  * ceil(lg_92(2^2304)) = 354
46  */
47 #define XFACE_MAX_DIGITS 354
48 
49 #define XFACE_BITSPERWORD 8
50 #define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD)
51 #define XFACE_WORDMASK (XFACE_WORDCARRY - 1)
52 
53 #define XFACE_MAX_WORDS ((XFACE_PIXELS * 2 + XFACE_BITSPERWORD - 1) / XFACE_BITSPERWORD)
54 
55 /* Portable, very large unsigned integer arithmetic is needed.
56  * Implementation uses arrays of WORDs. */
57 typedef struct {
58  int nb_words;
60 } BigInt;
61 
62 /**
63  * Add a to b storing the result in b.
64  */
65 void ff_big_add(BigInt *b, uint8_t a);
66 
67 /**
68  * Divide b by a storing the result in b and the remainder in the word
69  * pointed to by r.
70  */
71 void ff_big_div(BigInt *b, uint8_t a, uint8_t *r);
72 
73 /**
74  * Multiply a by b storing the result in b.
75  */
76 void ff_big_mul(BigInt *b, uint8_t a);
77 
78 /* Each face is encoded using 9 octrees of 16x16 each. Each level of the
79  * trees has varying probabilities of being white, grey or black.
80  * The table below is based on sampling many faces */
82 
83 /* Data of varying probabilities are encoded by a value in the range 0 - 255.
84  * The probability of the data determines the range of possible encodings.
85  * Offset gives the first possible encoding of the range. */
86 typedef struct {
87  int range;
88  int offset;
89 } ProbRange;
90 
91 extern const ProbRange ff_xface_probranges_per_level[4][3];
92 
93 extern const ProbRange ff_xface_probranges_2x2[16];
94 
int range
Definition: xface.h:87
void ff_big_add(BigInt *b, uint8_t a)
Add a to b storing the result in b.
Definition: xface.c:29
uint8_t
void ff_xface_generate_face(uint8_t *dst, uint8_t *const src)
Definition: xface.c:281
#define b
Definition: input.c:42
Definition: xface.h:57
XFaceColor
Definition: xface.h:81
#define XFACE_MAX_WORDS
Definition: xface.h:53
const char * r
Definition: vf_curves.c:94
void ff_big_mul(BigInt *b, uint8_t a)
Multiply a by b storing the result in b.
Definition: xface.c:90
AVS_Value src
Definition: avisynth_c.h:523
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:51
int offset
Definition: xface.h:88
const ProbRange ff_xface_probranges_per_level[4][3]
Definition: xface.c:124
const ProbRange ff_xface_probranges_2x2[16]
Definition: xface.c:132
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
int nb_words
Definition: xface.h:58