| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | /* | ||
| 2 | * MJPEG decoder VLC code | ||
| 3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
| 4 | * Copyright (c) 2003 Alex Beregszaszi | ||
| 5 | * Copyright (c) 2003-2004 Michael Niedermayer | ||
| 6 | * | ||
| 7 | * This file is part of FFmpeg. | ||
| 8 | * | ||
| 9 | * FFmpeg is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with FFmpeg; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <stdint.h> | ||
| 25 | #include "libavutil/avassert.h" | ||
| 26 | #include "mjpegdec.h" | ||
| 27 | #include "vlc.h" | ||
| 28 | |||
| 29 | 15330 | static int build_huffman_codes(uint8_t *huff_size, const uint8_t *bits_table) | |
| 30 | { | ||
| 31 | 15330 | int nb_codes = 0; | |
| 32 | 
        2/2✓ Branch 0 taken 245280 times. 
          ✓ Branch 1 taken 15330 times. 
         | 
      260610 | for (int i = 1, j = 0; i <= 16; i++) { | 
| 33 | 245280 | nb_codes += bits_table[i]; | |
| 34 | av_assert1(nb_codes <= 256); | ||
| 35 | 
        2/2✓ Branch 0 taken 1228462 times. 
          ✓ Branch 1 taken 245280 times. 
         | 
      1473742 | for (; j < nb_codes; j++) | 
| 36 | 1228462 | huff_size[j] = i; | |
| 37 | } | ||
| 38 | 15330 | return nb_codes; | |
| 39 | } | ||
| 40 | |||
| 41 | 15330 | int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, | |
| 42 | const uint8_t *val_table, int is_ac, void *logctx) | ||
| 43 | { | ||
| 44 | uint8_t huff_size[256]; | ||
| 45 | uint16_t huff_sym[256]; | ||
| 46 | 15330 | int nb_codes = build_huffman_codes(huff_size, bits_table); | |
| 47 | |||
| 48 | 
        2/2✓ Branch 0 taken 1228462 times. 
          ✓ Branch 1 taken 15330 times. 
         | 
      1243792 | for (int i = 0; i < nb_codes; i++) { | 
| 49 | 1228462 | huff_sym[i] = val_table[i] + 16 * is_ac; | |
| 50 | |||
| 51 | 
        4/4✓ Branch 0 taken 588510 times. 
          ✓ Branch 1 taken 639952 times. 
          ✓ Branch 2 taken 5127 times. 
          ✓ Branch 3 taken 583383 times. 
         | 
      1228462 | if (is_ac && !val_table[i]) | 
| 52 | 5127 | huff_sym[i] = 16 * 256; | |
| 53 | } | ||
| 54 | |||
| 55 | 15330 | return ff_vlc_init_from_lengths(vlc, 9, nb_codes, huff_size, 1, | |
| 56 | huff_sym, 2, 2, 0, 0, logctx); | ||
| 57 | } | ||
| 58 |