FFmpeg
Loading...
Searching...
No Matches
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 "gain_map.h"
35#include "mjpegenc_common.h"
36#include "mjpeg.h"
37#include "version.h"
38
39/* table_class: 0 = DC coef, 1 = AC coefs */
40static int put_huffman_table(PutBitContext *p, int table_class, int table_id,
41 const uint8_t *bits_table, const uint8_t *value_table)
42{
43 int n = 0;
44
45 put_bits(p, 4, table_class);
46 put_bits(p, 4, table_id);
47
48 for (int i = 1; i <= 16; i++) {
49 n += bits_table[i];
50 put_bits(p, 8, bits_table[i]);
51 }
52
53 for (int i = 0; i < n; i++)
54 put_bits(p, 8, value_table[i]);
55
56 return n + 17;
57}
58
60 const MJpegContext *m,
61 const uint8_t intra_matrix_permutation[64],
62 const uint16_t luma_intra_matrix[64],
63 const uint16_t chroma_intra_matrix[64],
64 int hsample[3], int use_slices, int matrices_differ)
65{
66 int 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 (int i = 0; i < 64; i++) {
87 uint8_t 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);
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) {
113
118 } else {
123
128 }
129 AV_WB16(ptr, size);
130}
131
132enum {
133 ICC_HDR_SIZE = 16, /* ICC_PROFILE\0 tag + 4 bytes */
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 %zu 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
163static int want_gain_map_xmp(const struct MJpegContext *m,
164 const AVGainMapParams *p)
165{
166 return m && m->xmp_gain_map && ff_gain_map_params_check_xmp(p);
167}
168
170 const AVFrame *frame, size_t *max_pkt_size)
171{
172 if (avctx->codec_id != AV_CODEC_ID_MJPEG)
173 return 0;
174
175 AVFrameSideData *sd;
177 if (!sd || sd->size < sizeof(AVGainMapParams))
178 return 0;
179
180 const AVGainMapParams *params = (const AVGainMapParams *) sd->data;
182 if (ret < 0)
183 return ret;
184
185 size_t extra_size = 4 + sizeof(AV_ISO21496_IDENTIFIER) + FF_GAIN_MAP_MAX_PAYLOAD_SIZE;
186 if (m && m->xmp_gain_map) {
188 const int level = m->xmp_gain_map > 0 ? AV_LOG_ERROR : AV_LOG_WARNING;
190 "Gain map metadata is incompatible with Ultra HDR XMP\n");
191 if (m->xmp_gain_map > 0)
192 return AVERROR(ENOTSUP);
193 } else {
194 extra_size += 4 + sizeof(FF_GAIN_MAP_XMP_IDENT) + FF_GAIN_MAP_XMP_MAX_LEN;
195 }
196 }
197
198 size_t new_pkt_size = *max_pkt_size + extra_size;
199 if (new_pkt_size < *max_pkt_size) /* overflow */
200 return AVERROR_INVALIDDATA;
201 *max_pkt_size = new_pkt_size;
202 return 0;
203}
204
206 const AVFrame *frame, const struct MJpegContext *m)
207{
208 const AVFrameSideData *sd = NULL;
209 int size;
210 uint8_t *ptr;
211
212 if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) {
213 AVRational sar = avctx->sample_aspect_ratio;
214
215 if (sar.num > 65535 || sar.den > 65535) {
216 if (!av_reduce(&sar.num, &sar.den, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 65535))
217 av_log(avctx, AV_LOG_WARNING,
218 "Cannot store exact aspect ratio %d:%d\n",
220 avctx->sample_aspect_ratio.den);
221 }
222
223 /* JFIF header */
224 put_marker(p, APP0);
225 put_bits(p, 16, 16);
226 ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
227 /* The most significant byte is used for major revisions, the least
228 * significant byte for minor revisions. Version 1.02 is the current
229 * released revision. */
230 put_bits(p, 16, 0x0102);
231 put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
232 put_bits(p, 16, sar.num);
233 put_bits(p, 16, sar.den);
234 put_bits(p, 8, 0); /* thumbnail width */
235 put_bits(p, 8, 0); /* thumbnail height */
236 }
237
238 /* ICC profile */
240 if (sd && sd->size) {
241 const int nb_chunks = (sd->size + ICC_CHUNK_SIZE - 1) / ICC_CHUNK_SIZE;
242 const uint8_t *data = sd->data;
243 size_t remaining = sd->size;
244 /* must already be checked by the packat allocation code */
247 for (int i = 0; i < nb_chunks; i++) {
248 size = FFMIN(remaining, ICC_CHUNK_SIZE);
249 av_assert1(size > 0);
250 ptr = put_bits_ptr(p);
251 ptr[0] = 0xff; /* chunk marker, not part of ICC_HDR_SIZE */
252 ptr[1] = APP2;
253 AV_WB16(ptr+2, size + ICC_HDR_SIZE);
254 AV_WL32(ptr+4, MKTAG('I','C','C','_'));
255 AV_WL32(ptr+8, MKTAG('P','R','O','F'));
256 AV_WL32(ptr+12, MKTAG('I','L','E','\0'));
257 ptr[16] = i+1;
258 ptr[17] = nb_chunks;
259 memcpy(&ptr[18], data, size);
261 remaining -= size;
262 data += size;
263 }
264 av_assert1(!remaining);
265 }
266
267 /* Gain map metadata; the ISO 21496-1 blob is written directly after the
268 * XMP packet, as recommended by the Ultra HDR specification */
269 sd = avctx->codec_id == AV_CODEC_ID_MJPEG ?
271
272 const AVGainMapParams *gmp = sd ? (const AVGainMapParams *) sd->data : NULL;
273 if (sd && sd->size >= sizeof(AVGainMapParams) && want_gain_map_xmp(m, gmp)) {
274 put_marker(p, APP1);
276 ptr = put_bits_ptr(p);
277 put_bits(p, 16, 0); /* patched later */
280
281 /* pre-validated by ff_mjpeg_add_gain_map_size() */
283 av_assert0(size >= 0);
285 AV_WB16(ptr, 2 + sizeof(FF_GAIN_MAP_XMP_IDENT) + size);
286 }
287
288 if (sd && sd->size >= sizeof(AVGainMapParams)) {
289 put_marker(p, APP2);
291 ptr = put_bits_ptr(p);
292 put_bits(p, 16, 0); /* patched later */
295
296 /* pre-validated by ff_mjpeg_add_gain_map_size() */
298 av_assert0(size >= 0);
300 AV_WB16(ptr, 2 + sizeof(AV_ISO21496_IDENTIFIER) + size);
301 }
302
303 /* comment */
304 if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT)) {
305 put_marker(p, COM);
307 ptr = put_bits_ptr(p);
308 put_bits(p, 16, 0); /* patched later */
310 size = strlen(LIBAVCODEC_IDENT)+3;
311 AV_WB16(ptr, size);
312 }
313
314 if (((avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
315 avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
317 || avctx->color_range == AVCOL_RANGE_MPEG) {
318 put_marker(p, COM);
320 ptr = put_bits_ptr(p);
321 put_bits(p, 16, 0); /* patched later */
322 ff_put_string(p, "CS=ITU601", 1);
323 size = strlen("CS=ITU601")+3;
324 AV_WB16(ptr, size);
325 }
326}
327
328void ff_mjpeg_init_hvsample(const AVCodecContext *avctx, int hsample[4], int vsample[4])
329{
330 if (avctx->codec_id == AV_CODEC_ID_LJPEG &&
331 ( avctx->pix_fmt == AV_PIX_FMT_BGR0
332 || avctx->pix_fmt == AV_PIX_FMT_BGRA
333 || avctx->pix_fmt == AV_PIX_FMT_BGR24)) {
334 vsample[0] = hsample[0] =
335 vsample[1] = hsample[1] =
336 vsample[2] = hsample[2] =
337 vsample[3] = hsample[3] = 1;
338 } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P) {
339 vsample[0] = vsample[1] = vsample[2] = 2;
340 hsample[0] = hsample[1] = hsample[2] = 1;
341 } else {
342 int chroma_h_shift, chroma_v_shift;
343 av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
344 &chroma_v_shift);
345 vsample[0] = 2;
346 vsample[1] = 2 >> chroma_v_shift;
347 vsample[2] = 2 >> chroma_v_shift;
348 hsample[0] = 2;
349 hsample[1] = 2 >> chroma_h_shift;
350 hsample[2] = 2 >> chroma_h_shift;
351 }
352}
353
355 const AVFrame *frame, const struct MJpegContext *m,
356 const uint8_t intra_matrix_permutation[64], int pred,
357 const uint16_t luma_intra_matrix[64],
358 const uint16_t chroma_intra_matrix[64],
359 int use_slices)
360{
361 const int lossless = !m;
362 int hsample[4], vsample[4];
363 int components = 3 + (avctx->pix_fmt == AV_PIX_FMT_BGRA);
364 int chroma_matrix;
365
366 ff_mjpeg_init_hvsample(avctx, hsample, vsample);
367
368 put_marker(pb, SOI);
369
370 // hack for AMV mjpeg format
371 if (avctx->codec_id == AV_CODEC_ID_AMV)
372 return;
373
374 jpeg_put_comments(avctx, pb, frame, m);
375
376 chroma_matrix = !lossless && !!memcmp(luma_intra_matrix,
377 chroma_intra_matrix,
378 sizeof(luma_intra_matrix[0]) * 64);
379 jpeg_table_header(avctx, pb, m, intra_matrix_permutation,
380 luma_intra_matrix, chroma_intra_matrix, hsample,
381 use_slices, chroma_matrix);
382
383 switch (avctx->codec_id) {
384 case AV_CODEC_ID_MJPEG: put_marker(pb, SOF0 ); break;
385 case AV_CODEC_ID_LJPEG: put_marker(pb, SOF3 ); break;
386 default: av_unreachable("ff_mjpeg_encode_picture_header only called by "
387 "AMV, LJPEG, MJPEG and the former has been ruled out");
388 }
389
390 put_bits(pb, 16, 8 + 3 * components);
391 if (lossless && ( avctx->pix_fmt == AV_PIX_FMT_BGR0
392 || avctx->pix_fmt == AV_PIX_FMT_BGRA
393 || avctx->pix_fmt == AV_PIX_FMT_BGR24))
394 put_bits(pb, 8, 9); /* 9 bits/component RCT */
395 else
396 put_bits(pb, 8, 8); /* 8 bits/component */
397 put_bits(pb, 16, avctx->height);
398 put_bits(pb, 16, avctx->width);
399 put_bits(pb, 8, components); /* 3 or 4 components */
400
401 /* Y component */
402 put_bits(pb, 8, 1); /* component number */
403 put_bits(pb, 4, hsample[0]); /* H factor */
404 put_bits(pb, 4, vsample[0]); /* V factor */
405 put_bits(pb, 8, 0); /* select matrix */
406
407 /* Cb component */
408 put_bits(pb, 8, 2); /* component number */
409 put_bits(pb, 4, hsample[1]); /* H factor */
410 put_bits(pb, 4, vsample[1]); /* V factor */
411 put_bits(pb, 8, lossless ? 0 : chroma_matrix); /* select matrix */
412
413 /* Cr component */
414 put_bits(pb, 8, 3); /* component number */
415 put_bits(pb, 4, hsample[2]); /* H factor */
416 put_bits(pb, 4, vsample[2]); /* V factor */
417 put_bits(pb, 8, lossless ? 0 : chroma_matrix); /* select matrix */
418
419 if (components == 4) {
420 put_bits(pb, 8, 4); /* component number */
421 put_bits(pb, 4, hsample[3]); /* H factor */
422 put_bits(pb, 4, vsample[3]); /* V factor */
423 put_bits(pb, 8, 0); /* select matrix */
424 }
425
426 /* scan header */
427 put_marker(pb, SOS);
428 put_bits(pb, 16, 6 + 2*components); /* length */
429 put_bits(pb, 8, components); /* 3 components */
430
431 /* Y component */
432 put_bits(pb, 8, 1); /* index */
433 put_bits(pb, 4, 0); /* DC huffman table index */
434 put_bits(pb, 4, 0); /* AC huffman table index */
435
436 /* Cb component */
437 put_bits(pb, 8, 2); /* index */
438 put_bits(pb, 4, 1); /* DC huffman table index */
439 put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
440
441 /* Cr component */
442 put_bits(pb, 8, 3); /* index */
443 put_bits(pb, 4, 1); /* DC huffman table index */
444 put_bits(pb, 4, lossless ? 0 : 1); /* AC huffman table index */
445
446 if (components == 4) {
447 /* Alpha component */
448 put_bits(pb, 8, 4); /* index */
449 put_bits(pb, 4, 0); /* DC huffman table index */
450 put_bits(pb, 4, 0); /* AC huffman table index */
451 }
452
453 put_bits(pb, 8, pred); /* Ss (not used); pred only nonzero for LJPEG */
454
455 switch (avctx->codec_id) {
456 case AV_CODEC_ID_MJPEG: put_bits(pb, 8, 63); break; /* Se (not used) */
457 case AV_CODEC_ID_LJPEG: put_bits(pb, 8, 0); break; /* not used */
458 default: av_unreachable("Only LJPEG, MJPEG possible here");
459 }
460
461 put_bits(pb, 8, 0); /* Ah/Al (not used) */
462}
463
465{
466 int size;
467 int i, ff_count;
468 uint8_t *buf = pb->buf + start;
469 int align= (-(size_t)(buf))&3;
470 int pad = (-put_bits_count(pb))&7;
471
472 if (pad)
473 put_bits(pb, pad, (1<<pad)-1);
474
475 flush_put_bits(pb);
476 size = put_bytes_output(pb) - start;
477
478 ff_count=0;
479 for(i=0; i<size && i<align; i++){
480 if(buf[i]==0xFF) ff_count++;
481 }
482 for(; i<size-15; i+=16){
483 int acc, v;
484
485 v= *(uint32_t*)(&buf[i]);
486 acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
487 v= *(uint32_t*)(&buf[i+4]);
488 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
489 v= *(uint32_t*)(&buf[i+8]);
490 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
491 v= *(uint32_t*)(&buf[i+12]);
492 acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
493
494 acc>>=4;
495 acc+= (acc>>16);
496 acc+= (acc>>8);
497 ff_count+= acc&0xFF;
498 }
499 for(; i<size; i++){
500 if(buf[i]==0xFF) ff_count++;
501 }
502
503 if(ff_count==0) return;
504
505 skip_put_bytes(pb, ff_count);
506
507 for(i=size-1; ff_count; i--){
508 int v= buf[i];
509
510 if(v==0xFF){
511 buf[i+ff_count]= 0;
512 ff_count--;
513 }
514
515 buf[i+ff_count]= v;
516 }
517}
518
519/* isn't this function nicer than the one in the libjpeg ? */
520void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
521 const uint8_t *bits_table,
522 const uint8_t *val_table)
523{
524 int k, code;
525
526 k = 0;
527 code = 0;
528 for (int i = 1; i <= 16; i++) {
529 int nb = bits_table[i];
530 for (int j = 0; j < nb; j++) {
531 int sym = val_table[k++];
532 huff_size[sym] = i;
533 huff_code[sym] = code;
534 code++;
535 }
536 code <<= 1;
537 }
538}
539
541{
542 av_assert1((header_bits & 7) == 0);
543
544 put_marker(pb, EOI);
545}
546
548 const uint8_t huff_size[], const uint16_t huff_code[])
549{
550 int mant, nbits;
551
552 if (val == 0) {
553 put_bits(pb, huff_size[0], huff_code[0]);
554 } else {
555 mant = val;
556 if (val < 0) {
557 val = -val;
558 mant--;
559 }
560
561 nbits= av_log2_16bit(val) + 1;
562
563 put_bits(pb, huff_size[nbits], huff_code[nbits]);
564
565 put_sbits(pb, nbits, mant);
566 }
567}
568
570{
572 avctx->color_range != AVCOL_RANGE_JPEG &&
573 (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
574 avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
575 avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
576 avctx->color_range == AVCOL_RANGE_MPEG)) {
577 av_log(avctx, AV_LOG_ERROR,
578 "Non full-range YUV is non-standard, set strict_std_compliance "
579 "to at most unofficial to use it.\n");
580 return AVERROR(EINVAL);
581 }
582 return 0;
583}
SwsAArch64OpImplParams params
Definition ops.c:51
static double val(void *priv, double ch)
Definition aeval.c:77
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
Definition bitstream.c:39
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
#define EOI
End Of Image marker.
Definition cpia.c:43
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition defs.h:61
static AVFrame * frame
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition avcodec.h:322
@ AV_CODEC_ID_LJPEG
Definition codec_id.h:59
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
@ AV_CODEC_ID_AMV
Definition codec_id.h:157
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
@ 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_FRAME_DATA_GAIN_MAP_PARAMS
Parameters describing how to combine this gain map with its base image to form an alternate rendition...
Definition frame.h:314
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
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
#define av_log2_16bit
Definition intmath.h:85
#define AV_WL32(p, v)
#define AV_WB16(p, v)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154
FF_VISIBILITY_PUSH_HIDDEN const uint8_t ff_mjpeg_bits_dc_luminance[]
Definition jpegtabs.h:32
const uint8_t ff_mjpeg_val_ac_chrominance[]
Definition jpegtabs.h:69
const uint8_t ff_mjpeg_bits_ac_luminance[]
Definition jpegtabs.h:40
const uint8_t ff_mjpeg_bits_dc_chrominance[]
Definition jpegtabs.h:37
const uint8_t ff_mjpeg_bits_ac_chrominance[]
Definition jpegtabs.h:66
const uint8_t ff_mjpeg_val_dc[]
Definition jpegtabs.h:34
const uint8_t ff_mjpeg_val_ac_luminance[]
Definition jpegtabs.h:42
int ff_gain_map_params_check_xmp(const AVGainMapParams *p)
Returns 1 if the gain map parameters are compatible with the XMP-based encoding, or 0 otherwise.
Definition gain_map.c:173
int ff_gain_map_params_to_xmp(const AVGainMapParams *p, char *buf)
Serialize an AVGainMapParams as an Ultra HDR XMP packet.
Definition gain_map.c:209
int ff_gain_map_params_to_iso21496(const AVGainMapParams *p, uint8_t *buf)
Serialize an AVGainMapParams as an ISO 21496-1 gain map metadata blob.
Definition gain_map.c:132
Serialization of AVGainMapParams into the metadata blobs that image formats carry it in,...
#define FF_GAIN_MAP_XMP_MAX_LEN
Definition gain_map.h:39
#define FF_GAIN_MAP_XMP_IDENT
Definition gain_map.h:37
#define FF_GAIN_MAP_MAX_PAYLOAD_SIZE
Definition gain_map.h:34
Libavcodec version macros.
#define LIBAVCODEC_IDENT
Definition version.h:43
int av_gain_map_params_validate(const AVGainMapParams *p)
Returns >= 0 if the given AVGainMapParams struct contains valid data; or a negative AVERROR otherwise...
Definition gain_map.c:46
#define AV_ISO21496_IDENTIFIER
Definition gain_map.h:28
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition log.c:450
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
MJPEG encoder and decoder.
@ DQT
Definition mjpeg.h:73
@ DRI
Definition mjpeg.h:75
@ DHT
Definition mjpeg.h:56
@ APP1
Definition mjpeg.h:80
@ APP2
Definition mjpeg.h:81
@ SOS
Definition mjpeg.h:72
@ APP0
Definition mjpeg.h:79
@ SOI
Definition mjpeg.h:70
@ COM
Definition mjpeg.h:111
@ SOF3
Definition mjpeg.h:42
@ SOF0
Definition mjpeg.h:39
MJPEG encoder.
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
Definition mjpegenc.h:88
static void put_marker(PutBitContext *p, enum JpegMarker code)
Definition mjpegenc.h:92
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, const uint8_t huff_size[], const uint16_t huff_code[])
@ ICC_CHUNK_SIZE
@ ICC_MAX_CHUNKS
@ ICC_HDR_SIZE
int ff_mjpeg_add_gain_map_size(AVCodecContext *avctx, struct MJpegContext *m, const AVFrame *frame, size_t *max_pkt_size)
void ff_mjpeg_init_hvsample(const AVCodecContext *avctx, int hsample[4], int vsample[4])
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame, const struct MJpegContext *m, const uint8_t intra_matrix_permutation[64], int pred, const uint16_t luma_intra_matrix[64], const uint16_t chroma_intra_matrix[64], int use_slices)
static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p, const AVFrame *frame, const struct MJpegContext *m)
int ff_mjpeg_add_icc_profile_size(AVCodecContext *avctx, const AVFrame *frame, size_t *max_pkt_size)
int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx)
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
static int put_huffman_table(PutBitContext *p, int table_class, int table_id, const uint8_t *bits_table, const uint8_t *value_table)
static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, const MJpegContext *m, const uint8_t intra_matrix_permutation[64], const uint16_t luma_intra_matrix[64], const uint16_t chroma_intra_matrix[64], int hsample[3], int use_slices, int matrices_differ)
static int want_gain_map_xmp(const struct MJpegContext *m, const AVGainMapParams *p)
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
const char data[16]
Definition mxf.c:149
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:3488
pixel format definitions
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ 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:87
bitstream writer API
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition put_bits.h:291
static int put_bits_count(PutBitContext *s)
Definition put_bits.h:90
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:402
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition put_bits.h:153
static int put_bytes_output(const PutBitContext *s)
Definition put_bits.h:99
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition put_bits.h:411
static const float pred[4]
Definition siprdata.h:259
const uint8_t * code
Definition spdifenc.c:433
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition avcodec.h:1376
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:628
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
enum AVCodecID codec_id
Definition avcodec.h:453
Structure to hold side data for an AVFrame.
Definition frame.h:334
size_t size
Definition frame.h:337
uint8_t * data
Definition frame.h:336
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
Parameters describing how to combine a gain map rendition with its base rendition to recover the alte...
Definition gain_map.h:39
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Holds JPEG frame data and Huffman table data.
Definition mjpegenc.h:44
int force_duplicated_matrix
Definition mjpegenc.h:47
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
Definition mjpegenc.h:68
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
Definition mjpegenc.h:74
int xmp_warned
Definition mjpegenc.h:50
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
Definition mjpegenc.h:75
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
Definition mjpegenc.h:77
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
Definition mjpegenc.h:70
int xmp_gain_map
Definition mjpegenc.h:49
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
Definition mjpegenc.h:69
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
Definition mjpegenc.h:76
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
Definition mjpegenc.h:71
uint8_t * buf
Definition put_bits.h:53
uint8_t level
Definition svq3.c:208
#define av_log(a,...)
int size