39 for (i = 0; i < w; i++) {
40 const int temp = src[i];
46 for (i = 0; i < 16; i++) {
47 const int temp = src[i];
58 int *red,
int *green,
int *blue,
68 for (i = 0; i <
FFMIN(w, 4); i++) {
69 const int rt = src[i * 4 +
R];
70 const int gt = src[i * 4 +
G];
71 const int bt = src[i * 4 +
B];
72 const int at = src[i * 4 +
A];
73 dst[i * 4 +
R] = rt -
r;
74 dst[i * 4 +
G] = gt -
g;
75 dst[i * 4 +
B] = bt -
b;
76 dst[i * 4 +
A] = at -
a;
85 *red = src[(w - 1) * 4 +
R];
86 *green = src[(w - 1) * 4 +
G];
87 *blue = src[(w - 1) * 4 +
B];
88 *alpha = src[(w - 1) * 4 +
A];
93 int *red,
int *green,
int *blue)
100 for (i = 0; i <
FFMIN(w, 16); i++) {
101 const int rt = src[i * 3 + 0];
102 const int gt = src[i * 3 + 1];
103 const int bt = src[i * 3 + 2];
104 dst[i * 3 + 0] = rt -
r;
105 dst[i * 3 + 1] = gt -
g;
106 dst[i * 3 + 2] = bt -
b;
112 s->
dsp.
diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
114 *red = src[(w - 1) * 3 + 0];
115 *green = src[(w - 1) * 3 + 1];
116 *blue = src[(w - 1) * 3 + 2];
124 for (i = 0; i < 256;) {
128 for (; i < 256 && len[i] == val && repeat < 255; i++)
131 assert(val < 32 && val >0 && repeat<256 && repeat>0);
134 buf[index++] = repeat;
136 buf[index++] = val | (repeat << 5);
188 "context=1 is not compatible with "
189 "2 pass huffyuv encoding\n");
197 "Error: YV12 is not supported by huffyuv; use "
198 "vcodec=ffvhuff or format=422p\n");
203 "Error: per-frame huffman tables are not supported "
204 "by huffyuv; use vcodec=ffvhuff\n");
209 "using huffyuv 2.2.0 or newer interlacing flag\n");
214 "Error: RGB is incompatible with median predictor\n");
229 for (i = 0; i < 3; i++)
230 for (j = 0; j < 256; j++)
234 for (i = 0; i < 3; i++) {
237 for (j = 0; j < 256; j++) {
238 s->
stats[i][j] += strtol(p, &next, 0);
239 if (next == p)
return -1;
243 if (p[0] == 0 || p[1] == 0 || p[2] == 0)
break;
246 for (i = 0; i < 3; i++)
247 for (j = 0; j < 256; j++) {
248 int d =
FFMIN(j, 256 - j);
250 s->
stats[i][j] = 100000000 / (d + 1);
254 for (i = 0; i < 3; i++) {
266 for (i = 0; i < 3; i++) {
268 for (j = 0; j < 256; j++) {
269 int d =
FFMIN(j, 256 - j);
270 s->
stats[i][j] = pels/(d + 1);
274 for (i = 0; i < 3; i++)
275 for (j = 0; j < 256; j++)
299 int y1 = y[2 * i + 1];\
306 for(i = 0; i < count; i++) {
317 for (i = 0; i < count; i++) {
329 for(i = 0; i < count; i++) {
350 int y0 = s->temp[0][2 * i];\
351 int y1 = s->temp[0][2 * i + 1];
356 put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
357 put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
362 for (i = 0; i < count; i++) {
371 for (i = 0; i < count; i++) {
377 for (i = 0; i < count; i++) {
390 4 * planes * count) {
396 int g = s->temp[0][planes == 3 ? 3 * i + 1 : 4 * i + G]; \
397 int b = s->temp[0][planes == 3 ? 3 * i + 2 : 4 * i + B] - g & 0xFF; \
398 int r = s->temp[0][planes == 3 ? 3 * i + 0 : 4 * i + R] - g & 0xFF; \
399 int a = s->temp[0][planes * i + A];
409 put_bits(&s->pb, s->len[1][g], s->bits[1][g]); \
410 put_bits(&s->pb, s->len[0][b], s->bits[0][b]); \
411 put_bits(&s->pb, s->len[2][r], s->bits[2][r]); \
413 put_bits(&s->pb, s->len[2][a], s->bits[2][a]);
417 for (i = 0; i < count; i++) {
422 for (i = 0; i < count; i++) {
428 for (i = 0; i < count; i++) {
437 const AVFrame *pict,
int *got_packet)
441 const int width2 = s->
width>>1;
446 const AVFrame *
const p = pict;
447 int i, j,
size = 0, ret;
456 for (i = 0; i < 3; i++) {
463 for (i = 0; i < 3; i++)
464 for (j = 0; j < 256; j++)
465 s->
stats[i][j] >>= 1;
472 int lefty, leftu, leftv, y, cy;
486 int lefttopy, lefttopu, lefttopv;
503 lefttopy = p->
data[0][3];
504 lefttopu = p->
data[1][1];
505 lefttopv = p->
data[2][1];
512 for (; y <
height; y++,cy++) {
522 if (y >= height)
break;
535 for (cy = y = 1; y <
height; y++, cy++) {
551 if (y >= height)
break;
578 const int fake_stride = -fake_ystride;
580 int leftr, leftg, leftb, lefta;
588 &leftr, &leftg, &leftb, &lefta);
591 for (y = 1; y < s->
height; y++) {
596 &leftr, &leftg, &leftb, &lefta);
599 &leftr, &leftg, &leftb, &lefta);
606 const int fake_stride = -fake_ystride;
608 int leftr, leftg, leftb;
616 &leftr, &leftg, &leftb);
619 for (y = 1; y < s->
height; y++) {
625 &leftr, &leftg, &leftb);
628 &leftr, &leftg, &leftb);
645 char *end = p + 1024*30;
646 for (i = 0; i < 3; i++) {
647 for (j = 0; j < 256; j++) {
648 snprintf(p, end-p,
"%"PRIu64
" ", s->
stats[i][j]);
652 snprintf(p, end-p,
"\n");
664 pkt->
size = size * 4;
685 #if CONFIG_HUFFYUV_ENCODER
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)
#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)
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.
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.
void(* sub_hfyu_median_prediction)(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 note, this might read from src1[-1], src2[-1]
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
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.
#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.
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)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void(* diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
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)