xface.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * @file
  23. * X-Face common definitions.
  24. */
  25. #ifndef AVCODEC_XFACE_H
  26. #define AVCODEC_XFACE_H
  27. #include <stdint.h>
  28. /* define the face size - 48x48x1 */
  29. #define XFACE_WIDTH 48
  30. #define XFACE_HEIGHT 48
  31. #define XFACE_PIXELS (XFACE_WIDTH * XFACE_HEIGHT)
  32. /* compressed output uses the full range of printable characters.
  33. * In ASCII these are in a contiguous block so we just need to know
  34. * the first and last. The total number of printables is needed too. */
  35. #define XFACE_FIRST_PRINT '!'
  36. #define XFACE_LAST_PRINT '~'
  37. #define XFACE_PRINTS (XFACE_LAST_PRINT - XFACE_FIRST_PRINT + 1)
  38. /*
  39. * Image is encoded as a big integer, using characters from '~' to
  40. * '!', for a total of 94 symbols. In order to express
  41. * 48x48 pixels with the worst case encoding 666 symbols should
  42. * be sufficient.
  43. */
  44. #define XFACE_MAX_DIGITS 666
  45. #define XFACE_BITSPERWORD 8
  46. #define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD)
  47. #define XFACE_WORDMASK (XFACE_WORDCARRY - 1)
  48. // This must be larger or equal to log256(94^XFACE_MAX_DIGITS)
  49. #define XFACE_MAX_WORDS 546
  50. /* Portable, very large unsigned integer arithmetic is needed.
  51. * Implementation uses arrays of WORDs. */
  52. typedef struct {
  53. int nb_words;
  54. uint8_t words[XFACE_MAX_WORDS];
  55. } BigInt;
  56. /**
  57. * Add a to b storing the result in b.
  58. */
  59. void ff_big_add(BigInt *b, uint8_t a);
  60. /**
  61. * Divide b by a storing the result in b and the remainder in the word
  62. * pointed to by r.
  63. */
  64. void ff_big_div(BigInt *b, uint8_t a, uint8_t *r);
  65. /**
  66. * Multiply a by b storing the result in b.
  67. */
  68. void ff_big_mul(BigInt *b, uint8_t a);
  69. /* Each face is encoded using 9 octrees of 16x16 each. Each level of the
  70. * trees has varying probabilities of being white, grey or black.
  71. * The table below is based on sampling many faces */
  72. enum XFaceColor { XFACE_COLOR_BLACK = 0, XFACE_COLOR_GREY, XFACE_COLOR_WHITE };
  73. /* Data of varying probabilities are encoded by a value in the range 0 - 255.
  74. * The probability of the data determines the range of possible encodings.
  75. * Offset gives the first possible encoding of the range. */
  76. typedef struct {
  77. uint8_t range;
  78. uint8_t offset;
  79. } ProbRange;
  80. extern const ProbRange ff_xface_probranges_per_level[4][3];
  81. extern const ProbRange ff_xface_probranges_2x2[16];
  82. void ff_xface_generate_face(uint8_t *dst, uint8_t * const src);
  83. #endif /* AVCODEC_XFACE_H */