67 unsigned slice_pos[4];
82 for (i = 0; i <
width; i++) {
83 dst[i] = src[i] - prev;
88 for (j = 1; j <
height; j++) {
90 for (i = 0; i <
width; i++) {
91 dst[i] = src[i] - prev;
103 int left = 0, top, lefttop;
106 for (i = 0; i <
width; i++) {
107 dst[i] = src[i] - left;
112 for (j = 1; j <
height; j++) {
116 for (i = 1; i <
width; i++) {
118 lefttop = src[i - (stride + 1)];
120 dst[i] = (src[i] - top) - left + lefttop;
131 int left = 0, lefttop;
134 for (i = 0; i <
width; i++) {
135 dst[i] = src[i] - left;
140 for (j = 1; j <
height; j++) {
141 left = lefttop = src[-
stride];
202 for (i = 0; i < s->
planes; i++) {
223 return (aa->
len - bb->len) * 256 + aa->
sym - bb->sym;
229 return bb->sym - aa->
sym;
240 for (i = 255; i >= 0; i--) {
241 he[i].
code = code >> (32 - he[i].
len);
242 code += 0x80000000
u >> (he[i].
len - 1);
253 for (j = 0; j <
height; j++) {
254 for (i = 0; i <
width; i++) {
255 counts[src[i]].
prob++;
264 int probability[514];
276 int size,
int max_length)
280 int nbits[257] = {0};
288 from->item_idx[0] = 0;
291 for (times = 0; times <= max_length; times++) {
298 if (times < max_length) {
301 while (i < size || j + 1 < from->nitems) {
305 (j + 1 >= from->nitems ||
307 from->probability[j] + from->probability[j + 1])) {
312 for (k = from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
316 from->probability[j] + from->probability[j + 1];
325 min = (size - 1 < from->nitems) ? size - 1 : from->nitems;
326 for (i = 0; i < from->item_idx[
min]; i++) {
327 nbits[from->items[i]]++;
330 for (i = 0; i <
size; i++) {
331 distincts[i].
sym = i;
332 distincts[i].
len = nbits[i];
340 PTable counts[256] = { {0} };
345 for (i = 0; i < 256; i++) {
347 counts[i].
value = 255 - i;
354 for (i = 0; i < 256; i++) {
374 for (j = 0; j <
height; j++) {
375 for (i = 0; i <
width; i++) {
376 const int idx = src[i];
401 int pos, slice, i, j, ret = 0;
409 bytestream2_put_le32(&pb,
MKTAG(
'M',
'A',
'G',
'Y'));
410 bytestream2_put_le32(&pb, 32);
411 bytestream2_put_byte(&pb, 7);
412 bytestream2_put_byte(&pb, s->
format);
413 bytestream2_put_byte(&pb, 0);
414 bytestream2_put_byte(&pb, 0);
415 bytestream2_put_le32(&pb, 0);
417 bytestream2_put_le32(&pb, avctx->
width);
418 bytestream2_put_le32(&pb, avctx->
height);
419 bytestream2_put_le32(&pb, avctx->
width);
420 bytestream2_put_le32(&pb, avctx->
height);
421 bytestream2_put_le32(&pb, 0);
423 for (i = 0; i < s->
planes; i++) {
424 bytestream2_put_le32(&pb, 0);
426 bytestream2_put_le32(&pb, 0);
430 bytestream2_put_byte(&pb, s->
planes);
432 for (i = 0; i < s->
planes; i++) {
433 for (slice = 0; slice < s->
nb_slices; slice++) {
434 bytestream2_put_byte(&pb, i);
446 for (i = 0; i <
height; i++) {
457 for (i = 0; i < s->
planes; i++) {
458 for (slice = 0; slice < s->
nb_slices; slice++) {
466 for (i = 0; i < s->
planes; i++) {
467 for (slice = 0; slice < s->
nb_slices; slice++) {
477 for (i = 0; i < s->
planes; i++) {
486 for (i = 0; i < s->
planes; i++) {
500 bytestream2_put_le32(&pb, s->
slice_pos[0] - 32);
501 for (i = 0; i < s->
planes; i++) {
502 bytestream2_put_le32(&pb, s->
slice_pos[i] - 32);
519 for (i = 0; i < s->
planes; i++)
525 #define OFFSET(x) offsetof(MagicYUVContext, x) 526 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 548 .priv_class = &magicyuv_class,
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static const AVOption options[]
static void calculate_codes(HuffEntry *he)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
const char * av_default_item_name(void *ptr)
Return the context name.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
static void left_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Multithreading support functions.
static av_cold int magy_encode_init(AVCodecContext *avctx)
#define u(width, name, range_min, range_max)
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
static int encode_table(AVCodecContext *avctx, uint8_t *dst, int width, int height, PutBitContext *pb, HuffEntry *he)
int nitems
number of items in the list and probability ex. 4
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static void median_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* sub_median_pred)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w, int *left, int *left_top)
Subtract HuffYUV's variant of median prediction.
static void magy_huffman_compute_bits(PTable *prob_table, HuffEntry *distincts, int size, int max_length)
void(* predict)(struct MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
static av_cold int magy_encode_close(AVCodecContext *avctx)
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. ...
const char * name
Name of the codec implementation.
int64_t prob
number of occurences of this value in input
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
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)
LLVidEncDSPContext llvidencdsp
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
static void gradient_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
int item_idx[515]
index range for each item in items 0, 2, 5, 9, 13
static int encode_slice(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he, int prediction)
int width
picture width / height.
static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
AVCodec ff_magicyuv_encoder
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Used to store intermediate lists in the package merge algorithm.
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
static int compare_by_prob(const void *a, const void *b)
Libavcodec external API header.
typedef void(RENAME(mix_any_func_type))
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
main external API structure.
Used to assign a occurrence count or "probability" to an input value.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Describe the class of an AVClass context structure.
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int probability[514]
probability of each item 3, 8, 18, 46
static int huff_cmp_sym(const void *a, const void *b)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
planar GBRA 4:4:4:4 32bpp
static int magy_huff_cmp_len(const void *a, const void *b)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static const struct @272 planes[]
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static const AVClass magicyuv_class
static void count_usage(uint8_t *src, int width, int height, PTable *counts)
int items[257 *16]
chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D, D, E
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
#define AV_CEIL_RSHIFT(a, b)