FFmpeg
mjpegenc_common.c
Go to the documentation of this file.
1 /*
2  * lossless JPEG shared bits
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2003 Alex Beregszaszi
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <stdint.h>
24 #include <string.h>
25 
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/pixfmt.h"
28 
29 #include "avcodec.h"
30 #include "idctdsp.h"
31 #include "jpegtables.h"
32 #include "put_bits.h"
33 #include "mjpegenc.h"
34 #include "mjpegenc_common.h"
35 #include "mjpeg.h"
36 #include "version.h"
37 
38 /* table_class: 0 = DC coef, 1 = AC coefs */
39 static int put_huffman_table(PutBitContext *p, int table_class, int table_id,
40  const uint8_t *bits_table, const uint8_t *value_table)
41 {
42  int n, i;
43 
44  put_bits(p, 4, table_class);
45  put_bits(p, 4, table_id);
46 
47  n = 0;
48  for(i=1;i<=16;i++) {
49  n += bits_table[i];
50  put_bits(p, 8, bits_table[i]);
51  }
52 
53  for(i=0;i<n;i++)
54  put_bits(p, 8, value_table[i]);
55 
56  return n + 17;
57 }
58 
60  MJpegContext *m,
61  const uint8_t intra_matrix_permutation[64],
62  uint16_t luma_intra_matrix[64],
63  uint16_t chroma_intra_matrix[64],
64  int hsample[3], int use_slices, int matrices_differ)
65 {
66  int i, j, size;
67  uint8_t *ptr;
68 
69  if (m) {
70  int matrix_count = 1 + matrices_differ;
72  matrix_count = 2;
73  /* quant matrixes */
74  put_marker(p, DQT);
75  put_bits(p, 16, 2 + matrix_count * (1 + 64));
76  put_bits(p, 4, 0); /* 8 bit precision */
77  put_bits(p, 4, 0); /* table 0 */
78  for (int i = 0; i < 64; i++) {
79  uint8_t j = intra_matrix_permutation[i];
80  put_bits(p, 8, luma_intra_matrix[j]);
81  }
82 
83  if (matrix_count > 1) {
84  put_bits(p, 4, 0); /* 8 bit precision */
85  put_bits(p, 4, 1); /* table 1 */
86  for(i=0;i<64;i++) {
87  j = intra_matrix_permutation[i];
88  put_bits(p, 8, chroma_intra_matrix[j]);
89  }
90  }
91  }
92 
93  if (use_slices) {
94  put_marker(p, DRI);
95  put_bits(p, 16, 4);
96  put_bits(p, 16, (avctx->width-1)/(8*hsample[0]) + 1);
97  }
98 
99  /* huffman table */
100  put_marker(p, DHT);
101  flush_put_bits(p);
102  ptr = put_bits_ptr(p);
103  put_bits(p, 16, 0); /* patched later */
104  size = 2;
105 
106  // Only MJPEG can have a variable Huffman variable. All other
107  // formats use the default Huffman table.
108  if (m && m->huffman == HUFFMAN_TABLE_OPTIMAL) {
110  m->val_dc_luminance);
112  m->val_dc_chrominance);
113 
115  m->val_ac_luminance);
117  m->val_ac_chrominance);
118  } else {
123 
128  }
129  AV_WB16(ptr, size);
130 }
131 
132 enum {
133  ICC_HDR_SIZE = 16, /* ICC_PROFILE\0 tag + 4 bytes */
134  ICC_CHUNK_SIZE = UINT16_MAX - ICC_HDR_SIZE,
135  ICC_MAX_CHUNKS = UINT8_MAX,
136 };
137 
139  size_t *max_pkt_size)
140 {
141  const AVFrameSideData *sd;
142  size_t new_pkt_size;
143  int nb_chunks;
145  if (!sd || !sd->size)
146  return 0;
147 
148  if (sd->size > ICC_MAX_CHUNKS * ICC_CHUNK_SIZE) {
149  av_log(avctx, AV_LOG_ERROR, "Cannot store %"SIZE_SPECIFIER" byte ICC "
150  "profile: too large for JPEG\n",
151  sd->size);
152  return AVERROR_INVALIDDATA;
153  }
154 
155  nb_chunks = (sd->size + ICC_CHUNK_SIZE - 1) / ICC_CHUNK_SIZE;
156  new_pkt_size = *max_pkt_size + nb_chunks * (UINT16_MAX + 2 /* APP2 marker */);
157  if (new_pkt_size < *max_pkt_size) /* overflow */
158  return AVERROR_INVALIDDATA;
159  *max_pkt_size = new_pkt_size;
160  return 0;
161 }
162 
164  const AVFrame *frame)
165 {
166  const AVFrameSideData *sd = NULL;
167  int size;
168  uint8_t *ptr;
169 
170  if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) {
171  AVRational sar = avctx->sample_aspect_ratio;
172 
173  if (sar.num > 65535 || sar.den > 65535) {
174  if (!av_reduce(&sar.num, &sar.den, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 65535))
175  av_log(avctx, AV_LOG_WARNING,
176  "Cannot store exact aspect ratio %d:%d\n",
177  avctx->sample_aspect_ratio.num,
178  avctx->sample_aspect_ratio.den);
179  }
180 
181  /* JFIF header */
182  put_marker(p, APP0);
183  put_bits(p, 16, 16);
184  ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
185  /* The most significant byte is used for major revisions, the least
186  * significant byte for minor revisions. Version 1.02 is the current
187  * released revision. */
188  put_bits(p, 16, 0x0102);
189  put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
190  put_bits(p, 16, sar.num);
191  put_bits(p, 16, sar.den);
192  put_bits(p, 8, 0); /* thumbnail width */
193  put_bits(p, 8, 0); /* thumbnail height */
194  }
195 
196  /* ICC profile */
198  if (sd && sd->size) {
199  const int nb_chunks = (sd->size + ICC_CHUNK_SIZE - 1) / ICC_CHUNK_SIZE;
200  const uint8_t *data = sd->data;
201  size_t remaining = sd->size;
202  /* must already be checked by the packat allocation code */
203  av_assert0(remaining <= ICC_MAX_CHUNKS * ICC_CHUNK_SIZE);
204  flush_put_bits(p);
205  for (int i = 0; i < nb_chunks; i++) {
206  size = FFMIN(remaining, ICC_CHUNK_SIZE);
207  av_assert1(size > 0);
208  ptr = put_bits_ptr(p);
209  ptr[0] = 0xff; /* chunk marker, not part of ICC_HDR_SIZE */
210  ptr[1] = APP2;
211  AV_WB16(ptr+2, size + ICC_HDR_SIZE);
212  AV_WL32(ptr+4, MKTAG('I','C','C','_'));
213  AV_WL32(ptr+8, MKTAG('P','R','O','F'));
214  AV_WL32(ptr+12, MKTAG('I','L','E','\0'));
215  ptr[16] = i+1;
216  ptr[17] = nb_chunks;
217  memcpy(&ptr[18], data, size);
218  skip_put_bytes(p, size + ICC_HDR_SIZE + 2);
219  remaining -= size;
220  data += size;
221  }
222  av_assert1(!remaining);
223  }
224 
225  /* comment */
226  if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT)) {
227  put_marker(p, COM);
228  flush_put_bits(p);
229  ptr = put_bits_ptr(p);
230  put_bits(p, 16, 0); /* patched later */
232  size = strlen(LIBAVCODEC_IDENT)+3;
233  AV_WB16(ptr, size);
234  }
235 
236  if (((avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
237  avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
238  avctx->pix_fmt == AV_PIX_FMT_YUV444P) && avctx->color_range != AVCOL_RANGE_JPEG)
239  || avctx->color_range == AVCOL_RANGE_MPEG) {
240  put_marker(p, COM);
241  flush_put_bits(p);
242  ptr = put_bits_ptr(p);
243  put_bits(p, 16, 0); /* patched later */
244  ff_put_string(p, "CS=ITU601", 1);
245  size = strlen("CS=ITU601")+3;
246  AV_WB16(ptr, size);
247  }
248 }
249 
250 void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
251 {
252  if (avctx->codec_id == AV_CODEC_ID_LJPEG &&
253  ( avctx->pix_fmt == AV_PIX_FMT_BGR0
254  || avctx->pix_fmt == AV_PIX_FMT_BGRA
255  || avctx->pix_fmt == AV_PIX_FMT_BGR24)) {
256  vsample[0] = hsample[0] =
257  vsample[1] = hsample[1] =
258  vsample[2] = hsample[2] =
259  vsample[3] = hsample[3] = 1;
260  } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P) {
261  vsample[0] = vsample[1] = vsample[2] = 2;
262  hsample[0] = hsample[1] = hsample[2] = 1;
263  } else {
264  int chroma_h_shift, chroma_v_shift;
265  av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
266  &chroma_v_shift);
267  vsample[0] = 2;
268  vsample[1] = 2 >> chroma_v_shift;
269  vsample[2] = 2 >> chroma_v_shift;
270  hsample[0] = 2;
271  hsample[1] = 2 >> chroma_h_shift;
272  hsample[2] = 2 >> chroma_h_shift;
273  }
274 }
275 
277  const AVFrame *frame, struct MJpegContext *m,
278  const uint8_t intra_matrix_permutation[64], int pred,
279  uint16_t luma_intra_matrix[64],
280  uint16_t chroma_intra_matrix[64],
281  int use_slices)
282 {
283  const int lossless = !m;
284  int hsample[4], vsample[4];
285  int components = 3 + (avctx->pix_fmt == AV_PIX_FMT_BGRA);
286  int chroma_matrix;
287 
288  ff_mjpeg_init_hvsample(avctx, hsample, vsample);
289 
290  put_marker(pb, SOI);
291 
292  // hack for AMV mjpeg format
293  if (avctx->codec_id == AV_CODEC_ID_AMV)
294  return;
295 
296  jpeg_put_comments(avctx, pb, frame);
297 
298  chroma_matrix = !lossless && !!memcmp(luma_intra_matrix,
299  chroma_intra_matrix,
300  sizeof(luma_intra_matrix[0]) * 64);
301  jpeg_table_header(avctx, pb, m, intra_matrix_permutation,
302  luma_intra_matrix, chroma_intra_matrix, hsample,
303  use_slices, chroma_matrix);
304 
305  switch (avctx->codec_id) {
306  case AV_CODEC_ID_MJPEG: put_marker(pb, SOF0 ); break;
307  case AV_CODEC_ID_LJPEG: put_marker(pb, SOF3 ); break;
308  default: av_assert0(0);
309  }
310 
311  put_bits(pb, 16, 8 + 3 * components);
312  if (lossless && ( avctx->pix_fmt == AV_PIX_FMT_BGR0
313  || avctx->pix_fmt == AV_PIX_FMT_BGRA
314  || avctx->pix_fmt == AV_PIX_FMT_BGR24))
315  put_bits(pb, 8, 9); /* 9 bits/component RCT */
316  else
317  put_bits(pb, 8, 8); /* 8 bits/component */
318  put_bits(pb, 16, avctx->height);
319  put_bits(pb, 16, avctx->width);
320  put_bits(pb, 8, components); /* 3 or 4 components */
321 
322  /* Y component */
323  put_bits(pb, 8, 1); /* component number */
324  put_bits(pb, 4, hsample[0]); /* H factor */
325  put_bits(pb, 4, vsample[0]); /* V factor */
326  put_bits(pb, 8, 0); /* select matrix */
327 
328  /* Cb component */
329  put_bits(pb, 8, 2); /* component number */
330  put_bits(pb, 4, hsample[1]); /* H factor */
331  put_bits(pb, 4, vsample[1]); /* V factor */
332  put_bits(pb, 8, lossless ? 0 : chroma_matrix); /* select matrix */
333 
334  /* Cr component */
335  put_bits(pb, 8, 3); /* component number */
336  put_bits(pb, 4, hsample[2]); /* H factor */
337  put_bits(pb, 4, vsample[2]); /* V factor */
338  put_bits(pb, 8, lossless ? 0 : chroma_matrix); /* select matrix */
339 
340  if (components == 4) {
341  put_bits(pb, 8, 4); /* component number */
342  put_bits(pb, 4, hsample[3]); /* H factor */
343  put_bits(pb, 4, vsample[3]); /* V factor */
344  put_bits(pb, 8, 0); /* select matrix */
345  }
346 
347  /* scan header */
348  put_marker(pb, SOS);
349  put_bits(pb, 16, 6 + 2*components); /* length */
350  put_bits(pb, 8, components); /* 3 components */
351 
352  /* Y component */
353  put_bits(pb, 8, 1); /* index */
354  put_bits(pb, 4, 0); /* DC huffman table index */
355  put_bits(pb, 4, 0); /* AC huffman table index */
356 
357  /* Cb component */
358  put_bits(pb, 8, 2); /* index */
359  put_bits(pb, 4, 1); /* DC huffman table index */
360  put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
361 
362  /* Cr component */
363  put_bits(pb, 8, 3); /* index */
364  put_bits(pb, 4, 1); /* DC huffman table index */
365  put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
366 
367  if (components == 4) {
368  /* Alpha component */
369  put_bits(pb, 8, 4); /* index */
370  put_bits(pb, 4, 0); /* DC huffman table index */
371  put_bits(pb, 4, 0); /* AC huffman table index */
372  }
373 
374  put_bits(pb, 8, pred); /* Ss (not used); pred only nonzero for LJPEG */
375 
376  switch (avctx->codec_id) {
377  case AV_CODEC_ID_MJPEG: put_bits(pb, 8, 63); break; /* Se (not used) */
378  case AV_CODEC_ID_LJPEG: put_bits(pb, 8, 0); break; /* not used */
379  default: av_assert0(0);
380  }
381 
382  put_bits(pb, 8, 0); /* Ah/Al (not used) */
383 }
384 
385 void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
386 {
387  int size;
388  int i, ff_count;
389  uint8_t *buf = pb->buf + start;
390  int align= (-(size_t)(buf))&3;
391  int pad = (-put_bits_count(pb))&7;
392 
393  if (pad)
394  put_bits(pb, pad, (1<<pad)-1);
395 
396  flush_put_bits(pb);
397  size = put_bytes_output(pb) - start;
398 
399  ff_count=0;
400  for(i=0; i<size && i<align; i++){
401  if(buf[i]==0xFF) ff_count++;
402  }
403  for(; i<size-15; i+=16){
404  int acc, v;
405 
406  v= *(uint32_t*)(&buf[i]);
407  acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
408  v= *(uint32_t*)(&buf[i+4]);
409  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
410  v= *(uint32_t*)(&buf[i+8]);
411  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
412  v= *(uint32_t*)(&buf[i+12]);
413  acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
414 
415  acc>>=4;
416  acc+= (acc>>16);
417  acc+= (acc>>8);
418  ff_count+= acc&0xFF;
419  }
420  for(; i<size; i++){
421  if(buf[i]==0xFF) ff_count++;
422  }
423 
424  if(ff_count==0) return;
425 
426  skip_put_bytes(pb, ff_count);
427 
428  for(i=size-1; ff_count; i--){
429  int v= buf[i];
430 
431  if(v==0xFF){
432  buf[i+ff_count]= 0;
433  ff_count--;
434  }
435 
436  buf[i+ff_count]= v;
437  }
438 }
439 
440 /* isn't this function nicer than the one in the libjpeg ? */
441 void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
442  const uint8_t *bits_table,
443  const uint8_t *val_table)
444 {
445  int k, code;
446 
447  k = 0;
448  code = 0;
449  for (int i = 1; i <= 16; i++) {
450  int nb = bits_table[i];
451  for (int j = 0; j < nb; j++) {
452  int sym = val_table[k++];
453  huff_size[sym] = i;
454  huff_code[sym] = code;
455  code++;
456  }
457  code <<= 1;
458  }
459 }
460 
462 {
463  av_assert1((header_bits & 7) == 0);
464 
465  put_marker(pb, EOI);
466 }
467 
469  uint8_t *huff_size, uint16_t *huff_code)
470 {
471  int mant, nbits;
472 
473  if (val == 0) {
474  put_bits(pb, huff_size[0], huff_code[0]);
475  } else {
476  mant = val;
477  if (val < 0) {
478  val = -val;
479  mant--;
480  }
481 
482  nbits= av_log2_16bit(val) + 1;
483 
484  put_bits(pb, huff_size[nbits], huff_code[nbits]);
485 
486  put_sbits(pb, nbits, mant);
487  }
488 }
489 
491 {
493  avctx->color_range != AVCOL_RANGE_JPEG &&
494  (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
495  avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
496  avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
497  avctx->color_range == AVCOL_RANGE_MPEG)) {
498  av_log(avctx, AV_LOG_ERROR,
499  "Non full-range YUV is non-standard, set strict_std_compliance "
500  "to at most unofficial to use it.\n");
501  return AVERROR(EINVAL);
502  }
503  return 0;
504 }
ff_mjpeg_encode_dc
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, uint8_t *huff_size, uint16_t *huff_code)
Definition: mjpegenc_common.c:468
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
jpegtables.h
mjpeg.h
acc
int acc
Definition: yuv2rgb.c:554
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
LIBAVCODEC_IDENT
#define LIBAVCODEC_IDENT
Definition: version.h:43
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
jpeg_put_comments
static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p, const AVFrame *frame)
Definition: mjpegenc_common.c:163
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:89
SOS
@ SOS
Definition: mjpeg.h:72
mjpegenc_common.h
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:682
ICC_MAX_CHUNKS
@ ICC_MAX_CHUNKS
Definition: mjpegenc_common.c:135
SOF0
@ SOF0
Definition: mjpeg.h:39
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:281
av_log2_16bit
int av_log2_16bit(unsigned v)
Definition: intmath.c:31
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
MJpegContext::bits_ac_chrominance
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
Definition: mjpegenc.h:88
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:221
pixdesc.h
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:661
data
const char data[16]
Definition: mxf.c:146
MJpegContext::val_dc_chrominance
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
Definition: mjpegenc.h:83
MJpegContext::huffman
int huffman
Definition: mjpegenc.h:60
ff_mjpeg_val_dc
const uint8_t ff_mjpeg_val_dc[]
Definition: jpegtabs.h:34
version.h
ICC_HDR_SIZE
@ ICC_HDR_SIZE
Definition: mjpegenc_common.c:133
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
put_huffman_table
static int put_huffman_table(PutBitContext *p, int table_class, int table_id, const uint8_t *bits_table, const uint8_t *value_table)
Definition: mjpegenc_common.c:39
MJpegContext::force_duplicated_matrix
int force_duplicated_matrix
Definition: mjpegenc.h:62
ICC_CHUNK_SIZE
@ ICC_CHUNK_SIZE
Definition: mjpegenc_common.c:134
ff_mjpeg_bits_ac_chrominance
const uint8_t ff_mjpeg_bits_ac_chrominance[]
Definition: jpegtabs.h:66
SOF3
@ SOF3
Definition: mjpeg.h:42
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:506
val
static double val(void *priv, double ch)
Definition: aeval.c:77
av_pix_fmt_get_chroma_sub_sample
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.
Definition: pixdesc.c:2916
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVFrameSideData::size
size_t size
Definition: frame.h:239
MJpegContext::bits_dc_luminance
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
Definition: mjpegenc.h:80
COM
@ COM
Definition: mjpeg.h:111
MJpegContext::val_dc_luminance
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
Definition: mjpegenc.h:81
HUFFMAN_TABLE_OPTIMAL
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
Definition: mjpegenc.h:100
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
MJpegContext::val_ac_chrominance
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
Definition: mjpegenc.h:89
ff_put_string
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
Definition: bitstream.c:39
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
PutBitContext
Definition: put_bits.h:50
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:436
ff_mjpeg_encode_picture_header
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame, struct MJpegContext *m, const uint8_t intra_matrix_permutation[64], int pred, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64], int use_slices)
Definition: mjpegenc_common.c:276
PutBitContext::buf
uint8_t * buf
Definition: put_bits.h:53
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1009
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:258
ff_mjpeg_val_ac_chrominance
const uint8_t ff_mjpeg_val_ac_chrominance[]
Definition: jpegtabs.h:69
DRI
@ DRI
Definition: mjpeg.h:75
ff_mjpeg_val_ac_luminance
const uint8_t ff_mjpeg_val_ac_luminance[]
Definition: jpegtabs.h:42
jpeg_table_header
static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, MJpegContext *m, const uint8_t intra_matrix_permutation[64], uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64], int hsample[3], int use_slices, int matrices_differ)
Definition: mjpegenc_common.c:59
ff_mjpeg_bits_ac_luminance
const uint8_t ff_mjpeg_bits_ac_luminance[]
Definition: jpegtabs.h:40
size
int size
Definition: twinvq_data.h:10344
AVFrameSideData::data
uint8_t * data
Definition: frame.h:238
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
FF_COMPLIANCE_UNOFFICIAL
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: defs.h:61
DQT
@ DQT
Definition: mjpeg.h:73
ff_mjpeg_add_icc_profile_size
int ff_mjpeg_add_icc_profile_size(AVCodecContext *avctx, const AVFrame *frame, size_t *max_pkt_size)
Definition: mjpegenc_common.c:138
ff_mjpeg_build_huffman_codes
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
Definition: mjpegenc_common.c:441
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
code
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
Definition: filter_design.txt:178
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:80
EOI
@ EOI
Definition: mjpeg.h:71
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_mjpeg_encode_check_pix_fmt
int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx)
Definition: mjpegenc_common.c:490
DHT
@ DHT
Definition: mjpeg.h:56
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:644
idctdsp.h
avcodec.h
MJpegContext::bits_dc_chrominance
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
Definition: mjpegenc.h:82
pred
static const float pred[4]
Definition: siprdata.h:259
pixfmt.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1341
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:150
AV_CODEC_ID_AMV
@ AV_CODEC_ID_AMV
Definition: codec_id.h:159
AVCodecContext
main external API structure.
Definition: avcodec.h:426
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:377
AVRational::den
int den
Denominator.
Definition: rational.h:60
APP2
@ APP2
Definition: mjpeg.h:81
ff_mjpeg_escape_FF
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
Definition: mjpegenc_common.c:385
skip_put_bytes
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition: put_bits.h:386
MJpegContext
Holds JPEG frame data and Huffman table data.
Definition: mjpegenc.h:59
put_marker
static void put_marker(PutBitContext *p, enum JpegMarker code)
Definition: mjpegenc.h:104
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
ff_mjpeg_bits_dc_chrominance
const uint8_t ff_mjpeg_bits_dc_chrominance[]
Definition: jpegtabs.h:37
APP0
@ APP0
Definition: mjpeg.h:79
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:321
SOI
@ SOI
Definition: mjpeg.h:70
ff_mjpeg_init_hvsample
void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
Definition: mjpegenc_common.c:250
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:236
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
ff_mjpeg_bits_dc_luminance
const FF_VISIBILITY_PUSH_HIDDEN uint8_t ff_mjpeg_bits_dc_luminance[]
Definition: jpegtabs.h:32
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_mjpeg_encode_picture_trailer
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
Definition: mjpegenc_common.c:461
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
MJpegContext::bits_ac_luminance
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
Definition: mjpegenc.h:86
MJpegContext::val_ac_luminance
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
Definition: mjpegenc.h:87
put_bits.h
mjpegenc.h
AV_CODEC_ID_LJPEG
@ AV_CODEC_ID_LJPEG
Definition: codec_id.h:61
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:795