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)
66 for (i = 0; i <
FFMIN(w, 4); i++) {
67 const int rt = src[i * 4 +
R];
68 const int gt = src[i * 4 +
G];
69 const int bt = src[i * 4 +
B];
70 dst[i * 4 +
R] = rt -
r;
71 dst[i * 4 +
G] = gt -
g;
72 dst[i * 4 +
B] = bt -
b;
80 *red = src[(w - 1) * 4 +
R];
81 *green = src[(w - 1) * 4 +
G];
82 *blue = src[(w - 1) * 4 +
B];
90 for (i = 0; i < 256;) {
94 for (; i < 256 && len[i] == val && repeat < 255; i++)
97 assert(val < 32 && val >0 && repeat<256 && repeat>0);
100 buf[index++] = repeat;
102 buf[index++] = val | (repeat << 5);
144 "context=1 is not compatible with "
145 "2 pass huffyuv encoding\n");
153 "Error: YV12 is not supported by huffyuv; use "
154 "vcodec=ffvhuff or format=422p\n");
159 "Error: per-frame huffman tables are not supported "
160 "by huffyuv; use vcodec=ffvhuff\n");
165 "using huffyuv 2.2.0 or newer interlacing flag\n");
170 "Error: RGB is incompatible with median predictor\n");
185 for (i = 0; i < 3; i++)
186 for (j = 0; j < 256; j++)
190 for (i = 0; i < 3; i++) {
193 for (j = 0; j < 256; j++) {
194 s->
stats[i][j] += strtol(p, &next, 0);
195 if (next == p)
return -1;
199 if (p[0] == 0 || p[1] == 0 || p[2] == 0)
break;
202 for (i = 0; i < 3; i++)
203 for (j = 0; j < 256; j++) {
204 int d =
FFMIN(j, 256 - j);
206 s->
stats[i][j] = 100000000 / (d + 1);
210 for (i = 0; i < 3; i++) {
222 for (i = 0; i < 3; i++) {
224 for (j = 0; j < 256; j++) {
225 int d =
FFMIN(j, 256 - j);
226 s->
stats[i][j] = pels/(d + 1);
230 for (i = 0; i < 3; i++)
231 for (j = 0; j < 256; j++)
255 int y1 = y[2 * i + 1];\
262 for(i = 0; i < count; i++) {
273 for (i = 0; i < count; i++) {
285 for(i = 0; i < count; i++) {
306 int y0 = s->temp[0][2 * i];\
307 int y1 = s->temp[0][2 * i + 1];
312 put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
313 put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
318 for (i = 0; i < count; i++) {
327 for (i = 0; i < count; i++) {
333 for (i = 0; i < count; i++) {
351 int g = s->temp[0][4 * i + G];\
352 int b = (s->temp[0][4 * i + B] - g) & 0xff;\
353 int r = (s->temp[0][4 * i + R] - g) & 0xff;
359 put_bits(&s->pb, s->len[1][g], s->bits[1][g]);\
360 put_bits(&s->pb, s->len[0][b], s->bits[0][b]);\
361 put_bits(&s->pb, s->len[2][r], s->bits[2][r]);
365 for (i = 0; i < count; i++) {
370 for (i = 0; i < count; i++) {
376 for (i = 0; i < count; i++) {
385 const AVFrame *pict,
int *got_packet)
389 const int width2 = s->
width>>1;
395 int i, j,
size = 0, ret;
408 for (i = 0; i < 3; i++) {
415 for (i = 0; i < 3; i++)
416 for (j = 0; j < 256; j++)
417 s->
stats[i][j] >>= 1;
424 int lefty, leftu, leftv, y, cy;
438 int lefttopy, lefttopu, lefttopv;
455 lefttopy = p->
data[0][3];
456 lefttopu = p->
data[1][1];
457 lefttopv = p->
data[2][1];
464 for (; y <
height; y++,cy++) {
474 if (y >= height)
break;
487 for (cy = y = 1; y <
height; y++, cy++) {
503 if (y >= height)
break;
530 const int fake_stride = -fake_ystride;
532 int leftr, leftg, leftb;
542 for (y = 1; y < s->
height; y++) {
565 char *end = p + 1024*30;
566 for (i = 0; i < 3; i++) {
567 for (j = 0; j < 256; j++) {
568 snprintf(p, end-p,
"%"PRIu64
" ", s->
stats[i][j]);
572 snprintf(p, end-p,
"\n");
584 pkt->
size = size * 4;
603 #if CONFIG_HUFFYUV_ENCODER
619 #if CONFIG_FFVHUFF_ENCODER
const struct AVCodec * codec
This structure describes decoded (raw) audio or video data.
#define CODEC_FLAG_INTERLACED_ME
static av_cold int encode_init(AVCodecContext *avctx)
struct HYuvContext HYuvContext
static int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left)
AVFrame * coded_frame
the picture in the bitstream
#define FF_MIN_BUFFER_SIZE
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
static void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue)
#define CODEC_FLAG2_NO_OUTPUT
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
char * stats_out
pass1 encoding statistics output buffer
static int init(AVCodecParserContext *s)
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)
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]
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
#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, see ?_TYPE below.
static av_cold int encode_end(AVCodecContext *avctx)
static int encode_422_bitstream(HYuvContext *s, int offset, int count)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
huffman tree builder and VLC generator
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.
static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
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.
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
int key_frame
1 -> keyframe, 0-> not
static int encode_bgr_bitstream(HYuvContext *s, int count)
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)