40 for (i = 0; i < w; i++) {
41 const int temp = src[i];
47 for (i = 0; i < 16; i++) {
48 const int temp = src[i];
59 int *red,
int *green,
int *blue,
69 for (i = 0; i <
FFMIN(w, 4); i++) {
70 const int rt = src[i * 4 +
R];
71 const int gt = src[i * 4 +
G];
72 const int bt = src[i * 4 +
B];
73 const int at = src[i * 4 +
A];
74 dst[i * 4 +
R] = rt -
r;
75 dst[i * 4 +
G] = gt -
g;
76 dst[i * 4 +
B] = bt -
b;
77 dst[i * 4 +
A] = at -
a;
86 *red = src[(w - 1) * 4 +
R];
87 *green = src[(w - 1) * 4 +
G];
88 *blue = src[(w - 1) * 4 +
B];
89 *alpha = src[(w - 1) * 4 +
A];
94 int *red,
int *green,
int *blue)
101 for (i = 0; i <
FFMIN(w, 16); i++) {
102 const int rt = src[i * 3 + 0];
103 const int gt = src[i * 3 + 1];
104 const int bt = src[i * 3 + 2];
105 dst[i * 3 + 0] = rt -
r;
106 dst[i * 3 + 1] = gt -
g;
107 dst[i * 3 + 2] = bt -
b;
115 *red = src[(w - 1) * 3 + 0];
116 *green = src[(w - 1) * 3 + 1];
117 *blue = src[(w - 1) * 3 + 2];
125 for (i = 0; i < 256;) {
129 for (; i < 256 && len[i] == val && repeat < 255; i++)
132 assert(val < 32 && val >0 && repeat<256 && repeat>0);
135 buf[index++] = repeat;
137 buf[index++] = val | (repeat << 5);
190 "context=1 is not compatible with "
191 "2 pass huffyuv encoding\n");
199 "Error: YV12 is not supported by huffyuv; use "
200 "vcodec=ffvhuff or format=422p\n");
205 "Error: per-frame huffman tables are not supported "
206 "by huffyuv; use vcodec=ffvhuff\n");
211 "using huffyuv 2.2.0 or newer interlacing flag\n");
216 "Error: RGB is incompatible with median predictor\n");
231 for (i = 0; i < 3; i++)
232 for (j = 0; j < 256; j++)
236 for (i = 0; i < 3; i++) {
239 for (j = 0; j < 256; j++) {
240 s->
stats[i][j] += strtol(p, &next, 0);
241 if (next == p)
return -1;
245 if (p[0] == 0 || p[1] == 0 || p[2] == 0)
break;
248 for (i = 0; i < 3; i++)
249 for (j = 0; j < 256; j++) {
250 int d =
FFMIN(j, 256 - j);
252 s->
stats[i][j] = 100000000 / (d + 1);
256 for (i = 0; i < 3; i++) {
268 for (i = 0; i < 3; i++) {
270 for (j = 0; j < 256; j++) {
271 int d =
FFMIN(j, 256 - j);
272 s->
stats[i][j] = pels/(d + 1);
276 for (i = 0; i < 3; i++)
277 for (j = 0; j < 256; j++)
301 int y1 = y[2 * i + 1];\
308 for(i = 0; i < count; i++) {
319 for (i = 0; i < count; i++) {
331 for(i = 0; i < count; i++) {
352 int y0 = s->temp[0][2 * i];\
353 int y1 = s->temp[0][2 * i + 1];
358 put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
359 put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
364 for (i = 0; i < count; i++) {
373 for (i = 0; i < count; i++) {
379 for (i = 0; i < count; i++) {
392 4 * planes * count) {
398 int g = s->temp[0][planes == 3 ? 3 * i + 1 : 4 * i + G]; \
399 int b = s->temp[0][planes == 3 ? 3 * i + 2 : 4 * i + B] - g & 0xFF; \
400 int r = s->temp[0][planes == 3 ? 3 * i + 0 : 4 * i + R] - g & 0xFF; \
401 int a = s->temp[0][planes * i + A];
411 put_bits(&s->pb, s->len[1][g], s->bits[1][g]); \
412 put_bits(&s->pb, s->len[0][b], s->bits[0][b]); \
413 put_bits(&s->pb, s->len[2][r], s->bits[2][r]); \
415 put_bits(&s->pb, s->len[2][a], s->bits[2][a]);
419 for (i = 0; i < count; i++) {
424 for (i = 0; i < count; i++) {
430 for (i = 0; i < count; i++) {
439 const AVFrame *pict,
int *got_packet)
443 const int width2 = s->
width>>1;
448 const AVFrame *
const p = pict;
449 int i, j,
size = 0, ret;
458 for (i = 0; i < 3; i++) {
465 for (i = 0; i < 3; i++)
466 for (j = 0; j < 256; j++)
467 s->
stats[i][j] >>= 1;
474 int lefty, leftu, leftv, y, cy;
488 int lefttopy, lefttopu, lefttopv;
505 lefttopy = p->
data[0][3];
506 lefttopu = p->
data[1][1];
507 lefttopv = p->
data[2][1];
514 for (; y <
height; y++,cy++) {
524 if (y >= height)
break;
537 for (cy = y = 1; y <
height; y++, cy++) {
553 if (y >= height)
break;
580 const int fake_stride = -fake_ystride;
582 int leftr, leftg, leftb, lefta;
590 &leftr, &leftg, &leftb, &lefta);
593 for (y = 1; y < s->
height; y++) {
598 &leftr, &leftg, &leftb, &lefta);
601 &leftr, &leftg, &leftb, &lefta);
608 const int fake_stride = -fake_ystride;
610 int leftr, leftg, leftb;
618 &leftr, &leftg, &leftb);
621 for (y = 1; y < s->
height; y++) {
627 &leftr, &leftg, &leftb);
630 &leftr, &leftg, &leftb);
647 char *end = p + 1024*30;
648 for (i = 0; i < 3; i++) {
649 for (j = 0; j < 256; j++) {
650 snprintf(p, end-p,
"%"PRIu64
" ", s->
stats[i][j]);
654 snprintf(p, end-p,
"\n");
666 pkt->
size = size * 4;
702 #if CONFIG_FFVHUFF_ENCODER
const struct AVCodec * codec
This structure describes decoded (raw) audio or video data.
static av_cold int encode_init(AVCodecContext *avctx)
static int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left)
void(* diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
packed RGB 8:8:8, 24bpp, RGBRGB...
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
AVFrame * coded_frame
the picture in the bitstream
void ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
void ff_huffyuv_common_end(HYuvContext *s)
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int context_model
context model
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
char * stats_out
pass1 encoding statistics output buffer
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
huffyuv codec for libavcodec.
int flags
A combination of AV_PKT_FLAG values.
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
enum AVPictureType pict_type
Picture type of the frame.
AVCodec ff_huffyuv_encoder
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
static av_cold int encode_end(AVCodecContext *avctx)
#define AV_LOG_INFO
Standard information.
void(* sub_hfyu_median_pred)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
Subtract HuffYUV's variant of median prediction.
Libavcodec external API header.
static int encode_422_bitstream(HYuvContext *s, int offset, int count)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void close(AVCodecParserContext *s)
huffman tree builder and VLC generator
static int encode_bgra_bitstream(HYuvContext *s, int count, int planes)
HuffYUVEncDSPContext hencdsp
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define CODEC_FLAG2_NO_OUTPUT
Skip bitstream encoding.
static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
static void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue, int *alpha)
int prediction_method
prediction method (needed for huffyuv)
static int encode_gray_bitstream(HYuvContext *s, int count)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static av_cold int init(AVCodecParserContext *s)
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
int key_frame
1 -> keyframe, 0-> not
AVPixelFormat
Pixel format.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)