27 #include "libavutil/imgutils.h"
28 #include "libavutil/intreadwrite.h"
42 return aa->
sym - bb->sym;
52 for (i = 0; i < 4; i++)
62 uint32_t original_format;
82 "4:2:0 video requires even width and height.\n");
90 if (avctx->
width & 1) {
92 "4:2:2 video requires even width.\n");
110 "Prediction method %d is not supported in Ut Video.\n",
117 "Plane prediction is not supported in Ut Video.\n");
149 for (i = 0; i < c->
planes; i++) {
205 int k = 2 * dst_stride;
208 for (j = 0; j <
height; j++) {
210 for (i = 0; i < width * step; i += step) {
214 dst[1][k] = src[i + 2] -
g;
215 dst[2][k] = src[i + 0] -
g;
219 for (i = 0; i < width * step; i += step) {
223 dst[1][k] = src[i + 2] -
g;
224 dst[2][k] = src[i + 0] -
g;
225 dst[3][k] = src[i + 3];
229 k += dst_stride -
width;
242 for (j = 0; j <
height; j++) {
243 for (i = 0; i <
width; i++) {
244 *dst++ = src[i] - prev;
261 for (i = 0; i <
width; i++) {
262 *dst++ = src[i] - prev;
278 for (j = 1; j <
height; j++) {
287 int height, uint64_t *counts)
291 for (j = 0; j <
height; j++) {
292 for (i = 0; i <
width; i++) {
308 while (he[last].
len == 255 && last)
312 for (i = last; i >= 0; i--) {
313 he[i].
code = code >> (32 - he[i].
len);
314 code += 0x80000000
u >> (he[i].
len - 1);
331 for (j = 0; j <
height; j++) {
332 for (i = 0; i <
width; i++)
359 uint64_t counts[256] = { 0 };
363 uint32_t
offset = 0, slice_len = 0;
364 int i, sstart, send = 0;
370 for (i = 0; i < c->
slices; i++) {
372 send = height * (i + 1) / c->
slices;
374 src + sstart * stride, stride,
375 width, send - sstart);
379 for (i = 0; i < c->
slices; i++) {
381 send = height * (i + 1) / c->
slices;
382 left_predict(src + sstart * stride, dst + sstart * width,
383 stride, width, send - sstart);
387 for (i = 0; i < c->
slices; i++) {
389 send = height * (i + 1) / c->
slices;
391 stride, width, send - sstart);
404 for (symbol = 0; symbol < 256; symbol++) {
406 if (counts[symbol]) {
408 if (counts[symbol] == width * (int64_t)height) {
413 for (i = 0; i < 256; i++) {
415 bytestream2_put_byte(pb, 0);
417 bytestream2_put_byte(pb, 0xFF);
421 for (i = 0; i < c->
slices; i++)
422 bytestream2_put_le32(pb, 0);
439 for (i = 0; i < 256; i++) {
440 bytestream2_put_byte(pb, lengths[i]);
442 he[i].
len = lengths[i];
450 for (i = 0; i < c->
slices; i++) {
452 send = height * (i + 1) / c->
slices;
459 width * (send - sstart),
width,
460 send - sstart, he) >> 3;
462 slice_len = offset - slice_len;
470 bytestream2_put_le32(pb, offset);
474 offset - slice_len, SEEK_CUR);
493 const AVFrame *pic,
int *got_packet)
533 for (i = 0; i < c->
planes; i++) {
545 for (i = 0; i < c->
planes; i++) {
547 pic->
linesize[i], width >> !!i, height, &pb);
556 for (i = 0; i < c->
planes; i++) {
558 pic->
linesize[i], width >> !!i, height >> !!i,
579 bytestream2_put_le32(&pb, frame_info);
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
static void mangle_rgb_planes(uint8_t *dst[4], int dst_stride, uint8_t *src, int step, int stride, int width, int height)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
static int huff_cmp_sym(const void *a, const void *b)
static av_cold int init(AVCodecContext *avctx)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
packed RGB 8:8:8, 24bpp, RGBRGB...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
void ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_cold int utvideo_encode_init(AVCodecContext *avctx)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
AVCodec ff_utvideo_encoder
static const uint8_t offset[511][2]
const char * name
Name of the codec implementation.
static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
static void left_predict(uint8_t *src, uint8_t *dst, int stride, int width, int height)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const int ff_ut_pred_order[5]
#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]
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. ...
static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he)
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Libavcodec external API header.
AVPixelFormat
Pixel format.
int flags
A combination of AV_PKT_FLAG values.
static int put_bits_count(PutBitContext *s)
static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int stride, int width, int height)
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int encode_plane(AVCodecContext *avctx, uint8_t *src, uint8_t *dst, int stride, int width, int height, PutByteContext *pb)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
main external API structure.
static void close(AVCodecParserContext *s)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
#define AVERROR_OPTION_NOT_FOUND
BYTE int const BYTE int int int height
#define MKTAG(a, b, c, d)
AVFrame * coded_frame
the picture in the bitstream
huffman tree builder and VLC generator
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_ut_huff_cmp_len(const void *a, const void *b)
static void calculate_codes(HuffEntry *he)
static void count_usage(uint8_t *src, int width, int height, uint64_t *counts)
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int prediction_method
prediction method (needed for huffyuv)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
uint8_t * slice_buffer[4]
#define AVERROR_INVALIDDATA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int key_frame
1 -> keyframe, 0-> not
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
static av_cold int utvideo_encode_close(AVCodecContext *avctx)
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...