Go to the documentation of this file.
43 for (
i = 0;
i < 128;
i++) {
52 len = (
run >> 4) * huff_size_ac[0xf0];
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);
104 if (
s &&
s->force_duplicated_matrix)
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]);
143 s->mjpeg_ctx->val_dc_luminance);
145 s->mjpeg_ctx->val_dc_chrominance);
148 s->mjpeg_ctx->val_ac_luminance);
150 s->mjpeg_ctx->val_ac_chrominance);
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) {
357 for(
i=1;
i<
s->slice_context_count;
i++)
358 s->thread_context[
i]->esc_pos = 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;
429 if(
buf[
i]==0xFF) ff_count++;
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++) {
543 int mb_y =
s->mb_y - !
s->mb_x;
556 s->intra_ac_vlc_length =
558 s->intra_chroma_ac_vlc_length =
562 s->pred,
s->intra_matrix,
s->chroma_intra_matrix);
582 s->last_dc[
i] = 128 <<
s->intra_dc_precision;
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]);
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
#define AV_LOG_WARNING
Something somehow does not look correct.
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC (in MpegEncContext)
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
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])
static void put_sbits(PutBitContext *pb, int n, int32_t value)
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])
static av_cold int end(AVCodecContext *avctx)
int av_log2_16bit(unsigned v)
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.
#define UNI_AC_ENC_INDEX(run, level)
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
const uint8_t avpriv_mjpeg_val_ac_luminance[]
@ AVCOL_RANGE_JPEG
the normal 2^n-1 "JPEG" YUV ranges
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
uint16_t mant
The mantissa.
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
static int put_huffman_table(PutBitContext *p, int table_class, int table_id, const uint8_t *bits_table, const uint8_t *value_table)
uint8_t table_id
The Huffman table id associated with the data.
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC (in MpegEncContext)
const struct AVCodec * codec
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
int flags
AV_CODEC_FLAG_*.
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 av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
const uint8_t avpriv_mjpeg_val_dc[12]
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
size_t huff_ncode
Number of current entries in the buffer.
static void ff_mjpeg_build_optimal_huffman(MJpegContext *m)
Builds all 4 optimal Huffman tables.
static void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s, uint8_t val)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
const char const char void * val
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static int put_bits_count(PutBitContext *s)
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AVCOL_RANGE_MPEG
the normal 219*2^(n-8) "MPEG" YUV ranges
static int get_bits_diff(MpegEncContext *s)
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
static const float pred[4]
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
void ff_mjpeg_encode_picture_frame(MpegEncContext *s)
Encodes and outputs the entire frame in the JPEG format.
const AVS_VideoInfo int align
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
av_cold void ff_init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len)
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Holds JPEG frame data and Huffman table data.
static void put_marker(PutBitContext *p, enum JpegMarker code)
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int width
picture width / height.
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
uint8_t code
The exponent.
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.