1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * MJPEG encoder 3cabdff1aSopenharmony_ci * Copyright (c) 2016 William Ma, Ted Ying, Jerry Jiang 4cabdff1aSopenharmony_ci * 5cabdff1aSopenharmony_ci * This file is part of FFmpeg. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11cabdff1aSopenharmony_ci * 12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15cabdff1aSopenharmony_ci * Lesser General Public License for more details. 16cabdff1aSopenharmony_ci * 17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20cabdff1aSopenharmony_ci */ 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci/** 23cabdff1aSopenharmony_ci * @file 24cabdff1aSopenharmony_ci * Huffman table generation for MJPEG encoder. 25cabdff1aSopenharmony_ci */ 26cabdff1aSopenharmony_ci 27cabdff1aSopenharmony_ci#ifndef AVCODEC_MJPEGENC_HUFFMAN_H 28cabdff1aSopenharmony_ci#define AVCODEC_MJPEGENC_HUFFMAN_H 29cabdff1aSopenharmony_ci 30cabdff1aSopenharmony_ci#include <stdint.h> 31cabdff1aSopenharmony_ci 32cabdff1aSopenharmony_citypedef struct MJpegEncHuffmanContext { 33cabdff1aSopenharmony_ci int val_count[256]; 34cabdff1aSopenharmony_ci} MJpegEncHuffmanContext; 35cabdff1aSopenharmony_ci 36cabdff1aSopenharmony_ci// Uses the package merge algorithm to compute the Huffman table. 37cabdff1aSopenharmony_civoid ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s); 38cabdff1aSopenharmony_cistatic inline void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s, 39cabdff1aSopenharmony_ci uint8_t val) 40cabdff1aSopenharmony_ci{ 41cabdff1aSopenharmony_ci s->val_count[val]++; 42cabdff1aSopenharmony_ci} 43cabdff1aSopenharmony_civoid ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, 44cabdff1aSopenharmony_ci uint8_t bits[17], uint8_t val[], 45cabdff1aSopenharmony_ci int max_nval); 46cabdff1aSopenharmony_ci 47cabdff1aSopenharmony_ci 48cabdff1aSopenharmony_ci/** 49cabdff1aSopenharmony_ci * Used to assign a occurrence count or "probability" to an input value 50cabdff1aSopenharmony_ci */ 51cabdff1aSopenharmony_citypedef struct PTable { 52cabdff1aSopenharmony_ci int value; ///< input value 53cabdff1aSopenharmony_ci int prob; ///< number of occurences of this value in input 54cabdff1aSopenharmony_ci} PTable; 55cabdff1aSopenharmony_ci 56cabdff1aSopenharmony_ci/** 57cabdff1aSopenharmony_ci * Used to store intermediate lists in the package merge algorithm 58cabdff1aSopenharmony_ci */ 59cabdff1aSopenharmony_citypedef struct PackageMergerList { 60cabdff1aSopenharmony_ci int nitems; ///< number of items in the list and probability ex. 4 61cabdff1aSopenharmony_ci int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13 62cabdff1aSopenharmony_ci int probability[514]; ///< probability of each item 3, 8, 18, 46 63cabdff1aSopenharmony_ci int items[257 * 16]; ///< chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D, D, E 64cabdff1aSopenharmony_ci} PackageMergerList; 65cabdff1aSopenharmony_ci 66cabdff1aSopenharmony_ci/** 67cabdff1aSopenharmony_ci * Used to store optimal huffman encoding results 68cabdff1aSopenharmony_ci */ 69cabdff1aSopenharmony_citypedef struct HuffTable { 70cabdff1aSopenharmony_ci int code; ///< code is the input value 71cabdff1aSopenharmony_ci int length; ///< length of the encoding 72cabdff1aSopenharmony_ci} HuffTable; 73cabdff1aSopenharmony_ci 74cabdff1aSopenharmony_civoid ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts, 75cabdff1aSopenharmony_ci int size, int max_length); 76cabdff1aSopenharmony_ci#endif /* AVCODEC_MJPEGENC_HUFFMAN_H */ 77