huffyuvenc.c 37.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at>
3 4 5 6
 *
 * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
 * the algorithm used
 *
7
 * This file is part of FFmpeg.
8
 *
9
 * FFmpeg is free software; you can redistribute it and/or
10 11 12 13
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
14
 * FFmpeg is distributed in the hope that it will be useful,
15 16 17 18 19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with FFmpeg; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 23
 *
 * yuva, gray, 4:4:4, 4:1:1, 4:1:0 and >8 bit per sample support sponsored by NOA
24 25 26 27 28 29 30 31 32 33
 */

/**
 * @file
 * huffyuv encoder
 */

#include "avcodec.h"
#include "huffyuv.h"
#include "huffman.h"
34
#include "huffyuvencdsp.h"
35
#include "internal.h"
36
#include "put_bits.h"
37
#include "libavutil/opt.h"
38
#include "libavutil/pixdesc.h"
39

40 41 42 43
static inline void diff_bytes(HYuvContext *s, uint8_t *dst,
                              const uint8_t *src0, const uint8_t *src1, int w)
{
    if (s->bps <= 8) {
44
        s->hencdsp.diff_bytes(dst, src0, src1, w);
45
    } else {
46
        s->llviddsp.diff_int16((uint16_t *)dst, (const uint16_t *)src0, (const uint16_t *)src1, s->n - 1, w);
47 48 49
    }
}

50
static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst,
51
                                      const uint8_t *src, int w, int left)
52 53
{
    int i;
54 55 56 57 58 59 60 61 62
    if (s->bps <= 8) {
        if (w < 32) {
            for (i = 0; i < w; i++) {
                const int temp = src[i];
                dst[i] = temp - left;
                left   = temp;
            }
            return left;
        } else {
63
            for (i = 0; i < 32; i++) {
64 65 66 67
                const int temp = src[i];
                dst[i] = temp - left;
                left   = temp;
            }
68
            s->hencdsp.diff_bytes(dst + 32, src + 32, src + 31, w - 32);
69
            return src[w-1];
70 71
        }
    } else {
72 73
        const uint16_t *src16 = (const uint16_t *)src;
        uint16_t       *dst16 = (      uint16_t *)dst;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        if (w < 32) {
            for (i = 0; i < w; i++) {
                const int temp = src16[i];
                dst16[i] = temp - left;
                left   = temp;
            }
            return left;
        } else {
            for (i = 0; i < 16; i++) {
                const int temp = src16[i];
                dst16[i] = temp - left;
                left   = temp;
            }
            s->llviddsp.diff_int16(dst16 + 16, src16 + 16, src16 + 15, s->n - 1, w - 16);
            return src16[w-1];
89 90 91 92 93
        }
    }
}

static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst,
94
                                             const uint8_t *src, int w,
95 96
                                             int *red, int *green, int *blue,
                                             int *alpha)
97 98
{
    int i;
99
    int r, g, b, a;
100 101 102
    r = *red;
    g = *green;
    b = *blue;
103
    a = *alpha;
104 105 106 107 108

    for (i = 0; i < FFMIN(w, 4); i++) {
        const int rt = src[i * 4 + R];
        const int gt = src[i * 4 + G];
        const int bt = src[i * 4 + B];
109
        const int at = src[i * 4 + A];
110 111 112
        dst[i * 4 + R] = rt - r;
        dst[i * 4 + G] = gt - g;
        dst[i * 4 + B] = bt - b;
113
        dst[i * 4 + A] = at - a;
114 115 116
        r = rt;
        g = gt;
        b = bt;
117
        a = at;
118 119
    }

120
    s->hencdsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
121 122 123 124

    *red   = src[(w - 1) * 4 + R];
    *green = src[(w - 1) * 4 + G];
    *blue  = src[(w - 1) * 4 + B];
125 126 127
    *alpha = src[(w - 1) * 4 + A];
}

128 129 130 131
static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst,
                                             uint8_t *src, int w,
                                             int *red, int *green, int *blue)
{
132
    int i;
133
    int r, g, b;
134 135 136
    r = *red;
    g = *green;
    b = *blue;
137 138 139 140 141 142 143
    for (i = 0; i < FFMIN(w, 16); i++) {
        const int rt = src[i * 3 + 0];
        const int gt = src[i * 3 + 1];
        const int bt = src[i * 3 + 2];
        dst[i * 3 + 0] = rt - r;
        dst[i * 3 + 1] = gt - g;
        dst[i * 3 + 2] = bt - b;
144 145 146 147 148
        r = rt;
        g = gt;
        b = bt;
    }

149
    s->hencdsp.diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
150

151 152 153
    *red   = src[(w - 1) * 3 + 0];
    *green = src[(w - 1) * 3 + 1];
    *blue  = src[(w - 1) * 3 + 2];
154 155
}

156 157 158
static void sub_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
{
    if (s->bps <= 8) {
159
        s->hencdsp.sub_hfyu_median_pred(dst, src1, src2, w , left, left_top);
160
    } else {
161
        s->llviddsp.sub_hfyu_median_pred_int16((uint16_t *)dst, (const uint16_t *)src1, (const uint16_t *)src2, s->n - 1, w , left, left_top);
162 163 164
    }
}

165 166 167 168
static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
{
    int i;
    int index = 0;
169
    int n = s->vlc_n;
170

171
    for (i = 0; i < n;) {
172 173 174
        int val = len[i];
        int repeat = 0;

175
        for (; i < n && len[i] == val && repeat < 255; i++)
176 177
            repeat++;

178
        av_assert0(val < 32 && val >0 && repeat < 256 && repeat>0);
179
        if (repeat > 7) {
180 181 182 183 184 185 186 187 188 189
            buf[index++] = val;
            buf[index++] = repeat;
        } else {
            buf[index++] = val | (repeat << 5);
        }
    }

    return index;
}

190 191
static int store_huffman_tables(HYuvContext *s, uint8_t *buf)
{
192
    int i, ret;
193 194 195 196 197 198 199
    int size = 0;
    int count = 3;

    if (s->version > 2)
        count = 1 + s->alpha + 2*s->chroma;

    for (i = 0; i < count; i++) {
200
        if ((ret = ff_huff_gen_len_table(s->len[i], s->stats[i], s->vlc_n, 0)) < 0)
201
            return ret;
202

203
        if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i], s->vlc_n) < 0) {
204 205 206 207 208 209 210 211
            return -1;
        }

        size += store_table(s, s->len[i], buf + size);
    }
    return size;
}

212 213 214 215
static av_cold int encode_init(AVCodecContext *avctx)
{
    HYuvContext *s = avctx->priv_data;
    int i, j;
216
    int ret;
217
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
218 219

    ff_huffyuv_common_init(avctx);
220
    ff_huffyuvencdsp_init(&s->hencdsp);
221

222
    avctx->extradata = av_mallocz(3*MAX_N + 4);
223
    if (s->flags&AV_CODEC_FLAG_PASS1) {
224 225 226 227
#define STATS_OUT_SIZE 21*MAX_N*3 + 4
        avctx->stats_out = av_mallocz(STATS_OUT_SIZE); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
        if (!avctx->stats_out)
            return AVERROR(ENOMEM);
228
    }
229 230
    s->version = 2;

231
    if (!avctx->extradata)
232 233
        return AVERROR(ENOMEM);

234 235
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
236 237
    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
    avctx->coded_frame->key_frame = 1;
238
FF_ENABLE_DEPRECATION_WARNINGS
239 240 241 242 243 244
#endif
#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
    if (avctx->context_model == 1)
        s->context = avctx->context_model;
FF_ENABLE_DEPRECATION_WARNINGS
245
#endif
246

247
    s->bps = desc->comp[0].depth;
248 249 250 251 252 253 254
    s->yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
    s->chroma = desc->nb_components > 2;
    s->alpha = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
    av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt,
                                     &s->chroma_h_shift,
                                     &s->chroma_v_shift);

255 256 257
    switch (avctx->pix_fmt) {
    case AV_PIX_FMT_YUV420P:
    case AV_PIX_FMT_YUV422P:
258
        if (s->width & 1) {
259
            av_log(avctx, AV_LOG_ERROR, "Width must be even for this colorspace.\n");
260 261 262
            return AVERROR(EINVAL);
        }
        s->bitstream_bpp = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 12 : 16;
263
        break;
264 265 266 267
    case AV_PIX_FMT_YUV444P:
    case AV_PIX_FMT_YUV410P:
    case AV_PIX_FMT_YUV411P:
    case AV_PIX_FMT_YUV440P:
268
    case AV_PIX_FMT_GBRP:
269 270 271 272 273
    case AV_PIX_FMT_GBRP9:
    case AV_PIX_FMT_GBRP10:
    case AV_PIX_FMT_GBRP12:
    case AV_PIX_FMT_GBRP14:
    case AV_PIX_FMT_GBRP16:
274
    case AV_PIX_FMT_GRAY8:
275
    case AV_PIX_FMT_GRAY16:
276 277 278 279 280
    case AV_PIX_FMT_YUVA444P:
    case AV_PIX_FMT_YUVA420P:
    case AV_PIX_FMT_YUVA422P:
    case AV_PIX_FMT_GBRAP:
    case AV_PIX_FMT_GRAY8A:
281
    case AV_PIX_FMT_YUV420P9:
282
    case AV_PIX_FMT_YUV420P10:
283 284
    case AV_PIX_FMT_YUV420P12:
    case AV_PIX_FMT_YUV420P14:
285
    case AV_PIX_FMT_YUV420P16:
286 287 288 289
    case AV_PIX_FMT_YUV422P9:
    case AV_PIX_FMT_YUV422P10:
    case AV_PIX_FMT_YUV422P12:
    case AV_PIX_FMT_YUV422P14:
290
    case AV_PIX_FMT_YUV422P16:
291 292 293 294
    case AV_PIX_FMT_YUV444P9:
    case AV_PIX_FMT_YUV444P10:
    case AV_PIX_FMT_YUV444P12:
    case AV_PIX_FMT_YUV444P14:
295
    case AV_PIX_FMT_YUV444P16:
296 297
    case AV_PIX_FMT_YUVA420P9:
    case AV_PIX_FMT_YUVA420P10:
298
    case AV_PIX_FMT_YUVA420P16:
299 300
    case AV_PIX_FMT_YUVA422P9:
    case AV_PIX_FMT_YUVA422P10:
301
    case AV_PIX_FMT_YUVA422P16:
302 303
    case AV_PIX_FMT_YUVA444P9:
    case AV_PIX_FMT_YUVA444P10:
304
    case AV_PIX_FMT_YUVA444P16:
305 306
        s->version = 3;
        break;
307
    case AV_PIX_FMT_RGB32:
308 309 310
        s->bitstream_bpp = 32;
        break;
    case AV_PIX_FMT_RGB24:
311 312 313 314
        s->bitstream_bpp = 24;
        break;
    default:
        av_log(avctx, AV_LOG_ERROR, "format not supported\n");
315
        return AVERROR(EINVAL);
316
    }
317
    s->n = 1<<s->bps;
318
    s->vlc_n = FFMIN(s->n, MAX_VLC_N);
319

320
    avctx->bits_per_coded_sample = s->bitstream_bpp;
321
    s->decorrelate = s->bitstream_bpp >= 24 && !s->yuv && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
322 323 324 325 326 327
#if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
    if (avctx->prediction_method)
        s->predictor = avctx->prediction_method;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
328
    s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0;
329
    if (s->context) {
330
        if (s->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) {
331 332 333
            av_log(avctx, AV_LOG_ERROR,
                   "context=1 is not compatible with "
                   "2 pass huffyuv encoding\n");
334
            return AVERROR(EINVAL);
335
        }
336
    }
337 338 339 340 341 342

    if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) {
        if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
            av_log(avctx, AV_LOG_ERROR,
                   "Error: YV12 is not supported by huffyuv; use "
                   "vcodec=ffvhuff or format=422p\n");
343
            return AVERROR(EINVAL);
344
        }
345 346
#if FF_API_PRIVATE_OPT
        if (s->context) {
347 348 349
            av_log(avctx, AV_LOG_ERROR,
                   "Error: per-frame huffman tables are not supported "
                   "by huffyuv; use vcodec=ffvhuff\n");
350
            return AVERROR(EINVAL);
351
        }
352 353 354 355 356 357
        if (s->version > 2) {
            av_log(avctx, AV_LOG_ERROR,
                   "Error: ver>2 is not supported "
                   "by huffyuv; use vcodec=ffvhuff\n");
            return AVERROR(EINVAL);
        }
358
#endif
359 360 361 362 363
        if (s->interlaced != ( s->height > 288 ))
            av_log(avctx, AV_LOG_INFO,
                   "using huffyuv 2.2.0 or newer interlacing flag\n");
    }

364 365
    if (s->version > 3 && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
        av_log(avctx, AV_LOG_ERROR, "Ver > 3 is under development, files encoded with it may not be decodable with future versions!!!\n"
366 367 368 369
               "Use vstrict=-2 / -strict -2 to use it anyway.\n");
        return AVERROR(EINVAL);
    }

370
    if (s->bitstream_bpp >= 24 && s->predictor == MEDIAN && s->version <= 2) {
371 372
        av_log(avctx, AV_LOG_ERROR,
               "Error: RGB is incompatible with median predictor\n");
373
        return AVERROR(EINVAL);
374 375 376 377 378 379
    }

    ((uint8_t*)avctx->extradata)[0] = s->predictor | (s->decorrelate << 6);
    ((uint8_t*)avctx->extradata)[2] = s->interlaced ? 0x10 : 0x20;
    if (s->context)
        ((uint8_t*)avctx->extradata)[2] |= 0x40;
380 381 382 383 384 385 386 387 388 389 390
    if (s->version < 3) {
        ((uint8_t*)avctx->extradata)[1] = s->bitstream_bpp;
        ((uint8_t*)avctx->extradata)[3] = 0;
    } else {
        ((uint8_t*)avctx->extradata)[1] = ((s->bps-1)<<4) | s->chroma_h_shift | (s->chroma_v_shift<<2);
        if (s->chroma)
            ((uint8_t*)avctx->extradata)[2] |= s->yuv ? 1 : 2;
        if (s->alpha)
            ((uint8_t*)avctx->extradata)[2] |= 4;
        ((uint8_t*)avctx->extradata)[3] = 1;
    }
391 392 393 394 395
    s->avctx->extradata_size = 4;

    if (avctx->stats_in) {
        char *p = avctx->stats_in;

396
        for (i = 0; i < 4; i++)
397
            for (j = 0; j < s->vlc_n; j++)
398 399 400
                s->stats[i][j] = 1;

        for (;;) {
401
            for (i = 0; i < 4; i++) {
402 403
                char *next;

404
                for (j = 0; j < s->vlc_n; j++) {
405 406 407 408 409 410 411 412
                    s->stats[i][j] += strtol(p, &next, 0);
                    if (next == p) return -1;
                    p = next;
                }
            }
            if (p[0] == 0 || p[1] == 0 || p[2] == 0) break;
        }
    } else {
413
        for (i = 0; i < 4; i++)
414 415
            for (j = 0; j < s->vlc_n; j++) {
                int d = FFMIN(j, s->vlc_n - j);
416

417
                s->stats[i][j] = 100000000 / (d*d + 1);
418 419 420
            }
    }

421 422 423 424
    ret = store_huffman_tables(s, s->avctx->extradata + s->avctx->extradata_size);
    if (ret < 0)
        return ret;
    s->avctx->extradata_size += ret;
425 426

    if (s->context) {
427
        for (i = 0; i < 4; i++) {
428
            int pels = s->width * s->height / (i ? 40 : 10);
429 430
            for (j = 0; j < s->vlc_n; j++) {
                int d = FFMIN(j, s->vlc_n - j);
431
                s->stats[i][j] = pels/(d*d + 1);
432 433 434
            }
        }
    } else {
435
        for (i = 0; i < 4; i++)
436
            for (j = 0; j < s->vlc_n; j++)
437 438 439
                s->stats[i][j]= 0;
    }

440 441 442 443
    if (ff_huffyuv_alloc_temp(s)) {
        ff_huffyuv_common_end(s);
        return AVERROR(ENOMEM);
    }
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

    s->picture_number=0;

    return 0;
}
static int encode_422_bitstream(HYuvContext *s, int offset, int count)
{
    int i;
    const uint8_t *y = s->temp[0] + offset;
    const uint8_t *u = s->temp[1] + offset / 2;
    const uint8_t *v = s->temp[2] + offset / 2;

    if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 2 * 4 * count) {
        av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
        return -1;
    }

#define LOAD4\
            int y0 = y[2 * i];\
            int y1 = y[2 * i + 1];\
            int u0 = u[i];\
            int v0 = v[i];

    count /= 2;

469
    if (s->flags & AV_CODEC_FLAG_PASS1) {
470 471 472 473 474 475 476 477
        for(i = 0; i < count; i++) {
            LOAD4;
            s->stats[0][y0]++;
            s->stats[1][u0]++;
            s->stats[0][y1]++;
            s->stats[2][v0]++;
        }
    }
478
    if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
        return 0;
    if (s->context) {
        for (i = 0; i < count; i++) {
            LOAD4;
            s->stats[0][y0]++;
            put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
            s->stats[1][u0]++;
            put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
            s->stats[0][y1]++;
            put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
            s->stats[2][v0]++;
            put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
        }
    } else {
        for(i = 0; i < count; i++) {
            LOAD4;
            put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
            put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
            put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
            put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
        }
    }
    return 0;
}

504
static int encode_plane_bitstream(HYuvContext *s, int width, int plane)
505
{
506
    int i, count = width/2;
507

508
    if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) {
509 510 511 512
        av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
        return -1;
    }

513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
#define LOADEND\
            int y0 = s->temp[0][width-1];
#define LOADEND_14\
            int y0 = s->temp16[0][width-1] & mask;
#define LOADEND_16\
            int y0 = s->temp16[0][width-1];
#define STATEND\
            s->stats[plane][y0]++;
#define STATEND_16\
            s->stats[plane][y0>>2]++;
#define WRITEEND\
            put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);
#define WRITEEND_16\
            put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
            put_bits(&s->pb, 2, y0&3);

529 530 531
#define LOAD2\
            int y0 = s->temp[0][2 * i];\
            int y1 = s->temp[0][2 * i + 1];
532
#define LOAD2_14\
533 534
            int y0 = s->temp16[0][2 * i] & mask;\
            int y1 = s->temp16[0][2 * i + 1] & mask;
535 536 537
#define LOAD2_16\
            int y0 = s->temp16[0][2 * i];\
            int y1 = s->temp16[0][2 * i + 1];
538 539 540
#define STAT2\
            s->stats[plane][y0]++;\
            s->stats[plane][y1]++;
541 542 543
#define STAT2_16\
            s->stats[plane][y0>>2]++;\
            s->stats[plane][y1>>2]++;
544 545 546
#define WRITE2\
            put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);\
            put_bits(&s->pb, s->len[plane][y1], s->bits[plane][y1]);
547 548 549 550 551
#define WRITE2_16\
            put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
            put_bits(&s->pb, 2, y0&3);\
            put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
            put_bits(&s->pb, 2, y1&3);
552

553
    if (s->bps <= 8) {
554
    if (s->flags & AV_CODEC_FLAG_PASS1) {
555 556 557 558
        for (i = 0; i < count; i++) {
            LOAD2;
            STAT2;
        }
559 560 561 562
        if (width&1) {
            LOADEND;
            STATEND;
        }
563
    }
564
    if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)
565 566 567 568 569 570 571 572
        return 0;

    if (s->context) {
        for (i = 0; i < count; i++) {
            LOAD2;
            STAT2;
            WRITE2;
        }
573 574 575 576 577
        if (width&1) {
            LOADEND;
            STATEND;
            WRITEEND;
        }
578 579 580 581 582
    } else {
        for (i = 0; i < count; i++) {
            LOAD2;
            WRITE2;
        }
583 584 585 586
        if (width&1) {
            LOADEND;
            WRITEEND;
        }
587
    }
588
    } else if (s->bps <= 14) {
589
        int mask = s->n - 1;
590
        if (s->flags & AV_CODEC_FLAG_PASS1) {
591
            for (i = 0; i < count; i++) {
592
                LOAD2_14;
593 594
                STAT2;
            }
595 596 597 598
            if (width&1) {
                LOADEND_14;
                STATEND;
            }
599
        }
600
        if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)
601 602 603 604
            return 0;

        if (s->context) {
            for (i = 0; i < count; i++) {
605
                LOAD2_14;
606 607 608
                STAT2;
                WRITE2;
            }
609 610 611 612 613
            if (width&1) {
                LOADEND_14;
                STATEND;
                WRITEEND;
            }
614 615
        } else {
            for (i = 0; i < count; i++) {
616
                LOAD2_14;
617 618
                WRITE2;
            }
619 620 621 622
            if (width&1) {
                LOADEND_14;
                WRITEEND;
            }
623
        }
624
    } else {
625
        if (s->flags & AV_CODEC_FLAG_PASS1) {
626 627 628 629
            for (i = 0; i < count; i++) {
                LOAD2_16;
                STAT2_16;
            }
630 631 632 633
            if (width&1) {
                LOADEND_16;
                STATEND_16;
            }
634
        }
635
        if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)
636 637 638 639 640 641 642 643
            return 0;

        if (s->context) {
            for (i = 0; i < count; i++) {
                LOAD2_16;
                STAT2_16;
                WRITE2_16;
            }
644 645 646 647 648
            if (width&1) {
                LOADEND_16;
                STATEND_16;
                WRITEEND_16;
            }
649 650 651 652 653
        } else {
            for (i = 0; i < count; i++) {
                LOAD2_16;
                WRITE2_16;
            }
654 655 656 657
            if (width&1) {
                LOADEND_16;
                WRITEEND_16;
            }
658
        }
659
    }
660 661 662 663 664 665
#undef LOAD2
#undef STAT2
#undef WRITE2
    return 0;
}

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
static int encode_gray_bitstream(HYuvContext *s, int count)
{
    int i;

    if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 4 * count) {
        av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
        return -1;
    }

#define LOAD2\
            int y0 = s->temp[0][2 * i];\
            int y1 = s->temp[0][2 * i + 1];
#define STAT2\
            s->stats[0][y0]++;\
            s->stats[0][y1]++;
#define WRITE2\
            put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
            put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);

    count /= 2;

687
    if (s->flags & AV_CODEC_FLAG_PASS1) {
688 689 690 691 692
        for (i = 0; i < count; i++) {
            LOAD2;
            STAT2;
        }
    }
693
    if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
        return 0;

    if (s->context) {
        for (i = 0; i < count; i++) {
            LOAD2;
            STAT2;
            WRITE2;
        }
    } else {
        for (i = 0; i < count; i++) {
            LOAD2;
            WRITE2;
        }
    }
    return 0;
}

711
static inline int encode_bgra_bitstream(HYuvContext *s, int count, int planes)
712 713 714
{
    int i;

715 716
    if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) <
        4 * planes * count) {
717 718 719 720
        av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
        return -1;
    }

721 722
#define LOAD_GBRA                                                       \
    int g = s->temp[0][planes == 3 ? 3 * i + 1 : 4 * i + G];            \
723 724
    int b =(s->temp[0][planes == 3 ? 3 * i + 2 : 4 * i + B] - g) & 0xFF;\
    int r =(s->temp[0][planes == 3 ? 3 * i + 0 : 4 * i + R] - g) & 0xFF;\
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
    int a = s->temp[0][planes * i + A];

#define STAT_BGRA                                                       \
    s->stats[0][b]++;                                                   \
    s->stats[1][g]++;                                                   \
    s->stats[2][r]++;                                                   \
    if (planes == 4)                                                    \
        s->stats[2][a]++;

#define WRITE_GBRA                                                      \
    put_bits(&s->pb, s->len[1][g], s->bits[1][g]);                      \
    put_bits(&s->pb, s->len[0][b], s->bits[0][b]);                      \
    put_bits(&s->pb, s->len[2][r], s->bits[2][r]);                      \
    if (planes == 4)                                                    \
        put_bits(&s->pb, s->len[2][a], s->bits[2][a]);
740

741 742
    if ((s->flags & AV_CODEC_FLAG_PASS1) &&
        (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)) {
743
        for (i = 0; i < count; i++) {
744 745
            LOAD_GBRA;
            STAT_BGRA;
746
        }
747
    } else if (s->context || (s->flags & AV_CODEC_FLAG_PASS1)) {
748
        for (i = 0; i < count; i++) {
749 750 751
            LOAD_GBRA;
            STAT_BGRA;
            WRITE_GBRA;
752 753 754
        }
    } else {
        for (i = 0; i < count; i++) {
755 756
            LOAD_GBRA;
            WRITE_GBRA;
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
        }
    }
    return 0;
}

static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                        const AVFrame *pict, int *got_packet)
{
    HYuvContext *s = avctx->priv_data;
    const int width = s->width;
    const int width2 = s->width>>1;
    const int height = s->height;
    const int fake_ystride = s->interlaced ? pict->linesize[0]*2  : pict->linesize[0];
    const int fake_ustride = s->interlaced ? pict->linesize[1]*2  : pict->linesize[1];
    const int fake_vstride = s->interlaced ? pict->linesize[2]*2  : pict->linesize[2];
772
    const AVFrame * const p = pict;
773 774
    int i, j, size = 0, ret;

775
    if ((ret = ff_alloc_packet2(avctx, pkt, width * height * 3 * 4 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
776 777 778
        return ret;

    if (s->context) {
779 780 781
        size = store_huffman_tables(s, pkt->data);
        if (size < 0)
            return size;
782

783
        for (i = 0; i < 4; i++)
784
            for (j = 0; j < s->vlc_n; j++)
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
                s->stats[i][j] >>= 1;
    }

    init_put_bits(&s->pb, pkt->data + size, pkt->size - size);

    if (avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
        avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
        int lefty, leftu, leftv, y, cy;

        put_bits(&s->pb, 8, leftv = p->data[2][0]);
        put_bits(&s->pb, 8, lefty = p->data[0][1]);
        put_bits(&s->pb, 8, leftu = p->data[1][0]);
        put_bits(&s->pb, 8,         p->data[0][0]);

        lefty = sub_left_prediction(s, s->temp[0], p->data[0], width , 0);
        leftu = sub_left_prediction(s, s->temp[1], p->data[1], width2, 0);
        leftv = sub_left_prediction(s, s->temp[2], p->data[2], width2, 0);

        encode_422_bitstream(s, 2, width-2);

        if (s->predictor==MEDIAN) {
            int lefttopy, lefttopu, lefttopv;
            cy = y = 1;
            if (s->interlaced) {
                lefty = sub_left_prediction(s, s->temp[0], p->data[0] + p->linesize[0], width , lefty);
                leftu = sub_left_prediction(s, s->temp[1], p->data[1] + p->linesize[1], width2, leftu);
                leftv = sub_left_prediction(s, s->temp[2], p->data[2] + p->linesize[2], width2, leftv);

                encode_422_bitstream(s, 0, width);
                y++; cy++;
            }

            lefty = sub_left_prediction(s, s->temp[0], p->data[0] + fake_ystride, 4, lefty);
            leftu = sub_left_prediction(s, s->temp[1], p->data[1] + fake_ustride, 2, leftu);
            leftv = sub_left_prediction(s, s->temp[2], p->data[2] + fake_vstride, 2, leftv);

            encode_422_bitstream(s, 0, 4);

            lefttopy = p->data[0][3];
            lefttopu = p->data[1][1];
            lefttopv = p->data[2][1];
826 827 828
            s->hencdsp.sub_hfyu_median_pred(s->temp[0], p->data[0] + 4, p->data[0] + fake_ystride + 4, width  - 4, &lefty, &lefttopy);
            s->hencdsp.sub_hfyu_median_pred(s->temp[1], p->data[1] + 2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
            s->hencdsp.sub_hfyu_median_pred(s->temp[2], p->data[2] + 2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
829 830 831 832 833 834 835 836 837
            encode_422_bitstream(s, 0, width - 4);
            y++; cy++;

            for (; y < height; y++,cy++) {
                uint8_t *ydst, *udst, *vdst;

                if (s->bitstream_bpp == 12) {
                    while (2 * cy > y) {
                        ydst = p->data[0] + p->linesize[0] * y;
838
                        s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
839 840 841 842 843 844 845 846 847
                        encode_gray_bitstream(s, width);
                        y++;
                    }
                    if (y >= height) break;
                }
                ydst = p->data[0] + p->linesize[0] * y;
                udst = p->data[1] + p->linesize[1] * cy;
                vdst = p->data[2] + p->linesize[2] * cy;

848 849 850
                s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width,  &lefty, &lefttopy);
                s->hencdsp.sub_hfyu_median_pred(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
                s->hencdsp.sub_hfyu_median_pred(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
851 852 853 854 855 856 857 858 859 860 861 862

                encode_422_bitstream(s, 0, width);
            }
        } else {
            for (cy = y = 1; y < height; y++, cy++) {
                uint8_t *ydst, *udst, *vdst;

                /* encode a luma only line & y++ */
                if (s->bitstream_bpp == 12) {
                    ydst = p->data[0] + p->linesize[0] * y;

                    if (s->predictor == PLANE && s->interlaced < y) {
863
                        s->hencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878

                        lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
                    } else {
                        lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
                    }
                    encode_gray_bitstream(s, width);
                    y++;
                    if (y >= height) break;
                }

                ydst = p->data[0] + p->linesize[0] * y;
                udst = p->data[1] + p->linesize[1] * cy;
                vdst = p->data[2] + p->linesize[2] * cy;

                if (s->predictor == PLANE && s->interlaced < cy) {
879 880 881
                    s->hencdsp.diff_bytes(s->temp[1],          ydst, ydst - fake_ystride, width);
                    s->hencdsp.diff_bytes(s->temp[2],          udst, udst - fake_ustride, width2);
                    s->hencdsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899

                    lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
                    leftu = sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
                    leftv = sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
                } else {
                    lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
                    leftu = sub_left_prediction(s, s->temp[1], udst, width2, leftu);
                    leftv = sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
                }

                encode_422_bitstream(s, 0, width);
            }
        }
    } else if(avctx->pix_fmt == AV_PIX_FMT_RGB32) {
        uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
        const int stride = -p->linesize[0];
        const int fake_stride = -fake_ystride;
        int y;
900
        int leftr, leftg, leftb, lefta;
901

902
        put_bits(&s->pb, 8, lefta = data[A]);
903 904 905 906
        put_bits(&s->pb, 8, leftr = data[R]);
        put_bits(&s->pb, 8, leftg = data[G]);
        put_bits(&s->pb, 8, leftb = data[B]);

907 908
        sub_left_prediction_bgr32(s, s->temp[0], data + 4, width - 1,
                                  &leftr, &leftg, &leftb, &lefta);
909
        encode_bgra_bitstream(s, width - 1, 4);
910 911 912 913

        for (y = 1; y < s->height; y++) {
            uint8_t *dst = data + y*stride;
            if (s->predictor == PLANE && s->interlaced < y) {
914
                s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
915 916
                sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width,
                                          &leftr, &leftg, &leftb, &lefta);
917
            } else {
918 919
                sub_left_prediction_bgr32(s, s->temp[0], dst, width,
                                          &leftr, &leftg, &leftb, &lefta);
920 921 922
            }
            encode_bgra_bitstream(s, width, 4);
        }
923 924
    } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
        uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
925 926 927 928 929
        const int stride = -p->linesize[0];
        const int fake_stride = -fake_ystride;
        int y;
        int leftr, leftg, leftb;

930 931 932
        put_bits(&s->pb, 8, leftr = data[0]);
        put_bits(&s->pb, 8, leftg = data[1]);
        put_bits(&s->pb, 8, leftb = data[2]);
933 934
        put_bits(&s->pb, 8, 0);

935 936
        sub_left_prediction_rgb24(s, s->temp[0], data + 3, width - 1,
                                  &leftr, &leftg, &leftb);
937 938
        encode_bgra_bitstream(s, width-1, 3);

939 940 941
        for (y = 1; y < s->height; y++) {
            uint8_t *dst = data + y * stride;
            if (s->predictor == PLANE && s->interlaced < y) {
942 943
                s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
                                      width * 3);
944 945
                sub_left_prediction_rgb24(s, s->temp[0], s->temp[1], width,
                                          &leftr, &leftg, &leftb);
946
            } else {
947 948
                sub_left_prediction_rgb24(s, s->temp[0], dst, width,
                                          &leftr, &leftg, &leftb);
949
            }
950
            encode_bgra_bitstream(s, width, 3);
951
        }
952
    } else if (s->version > 2) {
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
        int plane;
        for (plane = 0; plane < 1 + 2*s->chroma + s->alpha; plane++) {
            int left, y;
            int w = width;
            int h = height;
            int fake_stride = fake_ystride;

            if (s->chroma && (plane == 1 || plane == 2)) {
                w >>= s->chroma_h_shift;
                h >>= s->chroma_v_shift;
                fake_stride = plane == 1 ? fake_ustride : fake_vstride;
            }

            left = sub_left_prediction(s, s->temp[0], p->data[plane], w , 0);

            encode_plane_bitstream(s, w, plane);

            if (s->predictor==MEDIAN) {
                int lefttop;
                y = 1;
                if (s->interlaced) {
                    left = sub_left_prediction(s, s->temp[0], p->data[plane] + p->linesize[plane], w , left);

                    encode_plane_bitstream(s, w, plane);
                    y++;
                }

                lefttop = p->data[plane][0];

                for (; y < h; y++) {
                    uint8_t *dst = p->data[plane] + p->linesize[plane] * y;

985
                    sub_median_prediction(s, s->temp[0], dst - fake_stride, dst, w , &left, &lefttop);
986 987 988 989 990 991 992 993

                    encode_plane_bitstream(s, w, plane);
                }
            } else {
                for (y = 1; y < h; y++) {
                    uint8_t *dst = p->data[plane] + p->linesize[plane] * y;

                    if (s->predictor == PLANE && s->interlaced < y) {
994
                        diff_bytes(s, s->temp[1], dst, dst - fake_stride, w);
995 996 997 998 999 1000 1001 1002 1003 1004

                        left = sub_left_prediction(s, s->temp[0], s->temp[1], w , left);
                    } else {
                        left = sub_left_prediction(s, s->temp[0], dst, w , left);
                    }

                    encode_plane_bitstream(s, w, plane);
                }
            }
        }
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
    } else {
        av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
    }
    emms_c();

    size += (put_bits_count(&s->pb) + 31) / 8;
    put_bits(&s->pb, 16, 0);
    put_bits(&s->pb, 15, 0);
    size /= 4;

1015
    if ((s->flags & AV_CODEC_FLAG_PASS1) && (s->picture_number & 31) == 0) {
1016 1017
        int j;
        char *p = avctx->stats_out;
1018
        char *end = p + STATS_OUT_SIZE;
1019
        for (i = 0; i < 4; i++) {
1020
            for (j = 0; j < s->vlc_n; j++) {
1021 1022 1023 1024 1025 1026
                snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
                p += strlen(p);
                s->stats[i][j]= 0;
            }
            snprintf(p, end-p, "\n");
            p++;
1027 1028
            if (end <= p)
                return AVERROR(ENOMEM);
1029
        }
1030
    } else if (avctx->stats_out)
1031
        avctx->stats_out[0] = '\0';
1032
    if (!(s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)) {
1033
        flush_put_bits(&s->pb);
1034
        s->bdsp.bswap_buf((uint32_t *) pkt->data, (uint32_t *) pkt->data, size);
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
    }

    s->picture_number++;

    pkt->size   = size * 4;
    pkt->flags |= AV_PKT_FLAG_KEY;
    *got_packet = 1;

    return 0;
}

static av_cold int encode_end(AVCodecContext *avctx)
{
    HYuvContext *s = avctx->priv_data;

    ff_huffyuv_common_end(s);

    av_freep(&avctx->extradata);
    av_freep(&avctx->stats_out);

    return 0;
}

1058 1059 1060
#define OFFSET(x) offsetof(HYuvContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM

1061 1062 1063 1064
#define COMMON_OPTIONS \
    { "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism", \
      OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 }, \
      0, 1, VE }, \
1065 1066 1067 1068
    { "pred", "Prediction method", OFFSET(predictor), AV_OPT_TYPE_INT, { .i64 = LEFT }, LEFT, MEDIAN, VE, "pred" }, \
        { "left",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT },   INT_MIN, INT_MAX, VE, "pred" }, \
        { "plane",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PLANE },  INT_MIN, INT_MAX, VE, "pred" }, \
        { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MEDIAN }, INT_MIN, INT_MAX, VE, "pred" }, \
1069 1070 1071 1072 1073 1074 1075 1076 1077

static const AVOption normal_options[] = {
    COMMON_OPTIONS
    { NULL },
};

static const AVOption ff_options[] = {
    COMMON_OPTIONS
    { "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1078 1079 1080 1081 1082 1083
    { NULL },
};

static const AVClass normal_class = {
    .class_name = "huffyuv",
    .item_name  = av_default_item_name,
1084
    .option     = normal_options,
1085 1086 1087 1088 1089 1090
    .version    = LIBAVUTIL_VERSION_INT,
};

static const AVClass ff_class = {
    .class_name = "ffvhuff",
    .item_name  = av_default_item_name,
1091
    .option     = ff_options,
1092 1093 1094
    .version    = LIBAVUTIL_VERSION_INT,
};

1095 1096
AVCodec ff_huffyuv_encoder = {
    .name           = "huffyuv",
1097
    .long_name      = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
1098 1099 1100 1101 1102 1103
    .type           = AVMEDIA_TYPE_VIDEO,
    .id             = AV_CODEC_ID_HUFFYUV,
    .priv_data_size = sizeof(HYuvContext),
    .init           = encode_init,
    .encode2        = encode_frame,
    .close          = encode_end,
1104
    .capabilities   = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY,
1105
    .priv_class     = &normal_class,
1106
    .pix_fmts       = (const enum AVPixelFormat[]){
1107 1108
        AV_PIX_FMT_YUV422P, AV_PIX_FMT_RGB24,
        AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE
1109
    },
1110 1111
    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE |
                      FF_CODEC_CAP_INIT_CLEANUP,
1112 1113 1114 1115 1116
};

#if CONFIG_FFVHUFF_ENCODER
AVCodec ff_ffvhuff_encoder = {
    .name           = "ffvhuff",
1117
    .long_name      = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
1118 1119 1120 1121 1122 1123
    .type           = AVMEDIA_TYPE_VIDEO,
    .id             = AV_CODEC_ID_FFVHUFF,
    .priv_data_size = sizeof(HYuvContext),
    .init           = encode_init,
    .encode2        = encode_frame,
    .close          = encode_end,
1124
    .capabilities   = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY,
1125
    .priv_class     = &ff_class,
1126
    .pix_fmts       = (const enum AVPixelFormat[]){
1127 1128
        AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV411P,
        AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P,
1129
        AV_PIX_FMT_GBRP,
1130
        AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14,
1131
        AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
1132 1133 1134
        AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
        AV_PIX_FMT_GBRAP,
        AV_PIX_FMT_GRAY8A,
1135 1136 1137 1138 1139 1140
        AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV420P16,
        AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV422P16,
        AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16,
        AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16,
        AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P16,
        AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P16,
1141
        AV_PIX_FMT_RGB24,
1142
        AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE
1143
    },
1144 1145
    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE |
                      FF_CODEC_CAP_INIT_CLEANUP,
1146 1147
};
#endif