43 for (i = 0; i < 128; i++) {
48 for (run = 0; run < 64; run++) {
50 int alevel =
FFABS(level);
52 len = (run >> 4) * huff_size_ac[0xf0];
55 code = ((15&
run) << 4) | nbits;
57 len += huff_size_ac[code] + nbits;
88 uint16_t luma_intra_matrix[64],
89 uint16_t chroma_intra_matrix[64],
101 int matrix_count = 1 + !!memcmp(luma_intra_matrix,
103 sizeof(luma_intra_matrix[0]) * 64);
108 put_bits(p, 16, 2 + matrix_count * (1 + 64));
113 put_bits(p, 8, luma_intra_matrix[j]);
116 if (matrix_count > 1) {
121 put_bits(p, 8, chroma_intra_matrix[j]);
173 if (sar.
num > 65535 || sar.
den > 65535) {
176 "Cannot store exact aspect ratio %d:%d\n",
216 size = strlen(
"CS=ITU601")+3;
223 int chroma_h_shift, chroma_v_shift;
231 vsample[0] = hsample[0] =
232 vsample[1] = hsample[1] =
233 vsample[2] = hsample[2] =
234 vsample[3] = hsample[3] = 1;
236 vsample[0] = vsample[1] = vsample[2] = 2;
237 hsample[0] = hsample[1] = hsample[2] = 1;
240 vsample[1] = 2 >> chroma_v_shift;
241 vsample[2] = 2 >> chroma_v_shift;
243 hsample[1] = 2 >> chroma_h_shift;
244 hsample[2] = 2 >> chroma_h_shift;
250 uint16_t luma_intra_matrix[64],
251 uint16_t chroma_intra_matrix[64])
254 int hsample[4], vsample[4];
257 int chroma_matrix = !!memcmp(luma_intra_matrix,
259 sizeof(luma_intra_matrix[0])*64);
270 jpeg_table_header(avctx, pb, intra_scantable, luma_intra_matrix, chroma_intra_matrix, hsample);
299 put_bits(pb, 8, lossless ? 0 : chroma_matrix);
305 put_bits(pb, 8, lossless ? 0 : chroma_matrix);
307 if (components == 4) {
334 if (components == 4) {
341 put_bits(pb, 8, lossless ? pred : 0);
369 int i, nbits, code, table_id;
379 size_t total_bits = 0;
389 total_bits += huff_size[table_id][code] + nbits;
392 bytes_needed = (total_bits + 7) / 8;
400 put_bits(&s->
pb, huff_size[table_id][code], huff_code[table_id][code]);
415 int align= (-(size_t)(buf))&3;
428 for(i=0; i<size && i<
align; i++){
429 if(buf[i]==0xFF) ff_count++;
431 for(; i<size-15; i+=16){
434 v= *(uint32_t*)(&buf[i]);
435 acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
436 v= *(uint32_t*)(&buf[i+4]);
437 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
438 v= *(uint32_t*)(&buf[i+8]);
439 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
440 v= *(uint32_t*)(&buf[i+12]);
441 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
449 if(buf[i]==0xFF) ff_count++;
452 if(ff_count==0)
return;
457 for(i=size-1; ff_count; i--){
479 int i, table_id, code;
488 &ac_chrominance_ctx};
489 for (i = 0; i < 4; i++) {
595 uint8_t *huff_size, uint16_t *huff_code)
600 put_bits(pb, huff_size[0], huff_code[0]);
610 put_bits(pb, huff_size[nbits], huff_code[nbits]);
const struct AVCodec * codec
const char const char void * val
Holds JPEG frame data and Huffman table data.
static void put_sbits(PutBitContext *pb, int n, int32_t value)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
uint16_t chroma_intra_matrix[64]
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint8_t * intra_ac_vlc_length
#define UNI_AC_ENC_INDEX(run, level)
int av_log2_16bit(unsigned v)
av_cold void ff_init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len)
MJPEG encoder and decoder.
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
static void ff_mjpeg_build_optimal_huffman(MJpegContext *m)
Builds all 4 optimal Huffman tables.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
static av_cold int end(AVCodecContext *avctx)
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC (in MpegEncContext)
int force_duplicated_matrix
Force duplication of mjpeg matrices, useful for rtp streaming.
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17], uint8_t val[], int max_nval)
Produces a Huffman encoding with a given input.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
uint8_t table_id
The Huffman table id associated with the data.
static int get_bits_diff(MpegEncContext *s)
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
int slice_context_count
number of used thread_contexts
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
uint16_t mant
The mantissa.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
int last_dc[3]
last DC values for MPEG-1
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
int active_thread_type
Which multithreading methods are in use by the codec.
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
uint8_t * intra_chroma_ac_vlc_length
int flags
AV_CODEC_FLAG_*.
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
uint8_t * intra_ac_vlc_last_length
static void put_marker(PutBitContext *p, enum JpegMarker code)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
int width
picture width / height.
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC (in MpegEncContext)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
packed RGB 8:8:8, 24bpp, BGRBGR...
Compute and use optimal Huffman tables.
the normal 2^n-1 "JPEG" YUV ranges
static const float pred[4]
struct MJpegContext * mjpeg_ctx
const AVS_VideoInfo int align
struct MpegEncContext * thread_context[MAX_THREADS]
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
Libavcodec external API header.
static void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s, uint8_t val)
uint8_t * intra_chroma_ac_vlc_last_length
main external API structure.
ScanTable intra_scantable
static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, ScanTable *intra_scantable, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64], int hsample[3])
const uint8_t avpriv_mjpeg_val_dc[12]
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
Rational number (pair of numerator and denominator).
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, ScanTable *intra_scantable, int pred, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64])
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Huffman table generation for MJPEG encoder.
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
the normal 219*2^(n-8) "MPEG" YUV ranges
struct AVCodecContext * avctx
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.
PutBitContext pb
bit output
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
common internal and external API header
uint8_t code
The exponent.
size_t huff_ncode
Number of current entries in the buffer.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
const uint8_t avpriv_mjpeg_val_ac_luminance[]
static int put_huffman_table(PutBitContext *p, int table_class, int table_id, const uint8_t *bits_table, const uint8_t *value_table)
void ff_mjpeg_encode_picture_frame(MpegEncContext *s)
Encodes and outputs the entire frame in the JPEG format.
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)