81 for (i = 0; i <
width; i++) {
82 dst[i] = src[i] - prev;
87 for (j = 1; j <
height; j++) {
89 for (i = 0; i <
width; i++) {
90 dst[i] = src[i] - prev;
102 int left = 0, top, lefttop;
105 for (i = 0; i <
width; i++) {
106 dst[i] = src[i] - left;
111 for (j = 1; j <
height; j++) {
115 for (i = 1; i <
width; i++) {
117 lefttop = src[i - (stride + 1)];
119 dst[i] = (src[i] - top) - left + lefttop;
130 int left = 0, lefttop;
133 for (i = 0; i <
width; i++) {
134 dst[i] = src[i] - left;
139 for (j = 1; j <
height; j++) {
140 left = lefttop = src[-
stride];
202 for (i = 0; i < s->
planes; i++) {
228 bytestream2_put_le32(&pb,
MKTAG(
'M',
'A',
'G',
'Y'));
229 bytestream2_put_le32(&pb, 32);
230 bytestream2_put_byte(&pb, 7);
231 bytestream2_put_byte(&pb, s->
format);
232 bytestream2_put_byte(&pb, 12);
233 bytestream2_put_byte(&pb, 0);
235 bytestream2_put_byte(&pb, 0);
236 bytestream2_put_byte(&pb, 0);
237 bytestream2_put_byte(&pb, 32);
238 bytestream2_put_byte(&pb, 0);
240 bytestream2_put_le32(&pb, avctx->
width);
241 bytestream2_put_le32(&pb, avctx->
height);
242 bytestream2_put_le32(&pb, avctx->
width);
243 bytestream2_put_le32(&pb, avctx->
height);
251 return (aa->
len - bb->len) * 256 + aa->
sym - bb->sym;
257 return bb->sym - aa->
sym;
268 for (i = 255; i >= 0; i--) {
269 he[i].
code = code >> (32 - he[i].
len);
270 code += 0x80000000
u >> (he[i].
len - 1);
281 for (j = 0; j <
height; j++) {
282 for (i = 0; i <
width; i++) {
283 counts[src[i]].
prob++;
304 int size,
int max_length)
308 int nbits[257] = {0};
316 from->item_idx[0] = 0;
319 for (times = 0; times <= max_length; times++) {
326 if (times < max_length) {
329 while (i < size || j + 1 < from->nitems) {
333 (j + 1 >= from->nitems ||
335 from->probability[j] + from->probability[j + 1])) {
340 for (k = from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
344 from->probability[j] + from->probability[j + 1];
353 min = (size - 1 < from->nitems) ? size - 1 : from->nitems;
354 for (i = 0; i < from->item_idx[
min]; i++) {
355 nbits[from->items[i]]++;
358 for (i = 0; i <
size; i++) {
359 distincts[i].
sym = i;
360 distincts[i].
len = nbits[i];
368 PTable counts[256] = { {0} };
373 for (i = 0; i < 256; i++) {
375 counts[i].
value = 255 - i;
382 for (i = 0; i < 256; i++) {
402 for (j = 0; j <
height; j++) {
403 for (i = 0; i <
width; i++) {
404 const int idx = src[i];
429 int pos, slice, i, j, ret = 0;
437 bytestream2_put_le32(&pb,
MKTAG(
'M',
'A',
'G',
'Y'));
438 bytestream2_put_le32(&pb, 32);
439 bytestream2_put_byte(&pb, 7);
440 bytestream2_put_byte(&pb, s->
format);
441 bytestream2_put_byte(&pb, 12);
442 bytestream2_put_byte(&pb, 0);
444 bytestream2_put_byte(&pb, 0);
445 bytestream2_put_byte(&pb, 0);
446 bytestream2_put_byte(&pb, 32);
447 bytestream2_put_byte(&pb, 0);
449 bytestream2_put_le32(&pb, avctx->
width);
450 bytestream2_put_le32(&pb, avctx->
height);
451 bytestream2_put_le32(&pb, avctx->
width);
452 bytestream2_put_le32(&pb, avctx->
height);
453 bytestream2_put_le32(&pb, 0);
455 for (i = 0; i < s->
planes; i++) {
456 bytestream2_put_le32(&pb, 0);
458 bytestream2_put_le32(&pb, 0);
462 bytestream2_put_byte(&pb, s->
planes);
464 for (i = 0; i < s->
planes; i++) {
465 for (slice = 0; slice < s->
nb_slices; slice++) {
466 bytestream2_put_byte(&pb, i);
478 for (i = 0; i <
height; i++) {
489 for (i = 0; i < s->
planes; i++) {
490 for (slice = 0; slice < s->
nb_slices; slice++) {
498 for (i = 0; i < s->
planes; i++) {
499 for (slice = 0; slice < s->
nb_slices; slice++) {
509 for (i = 0; i < s->
planes; i++) {
518 for (i = 0; i < s->
planes; i++) {
532 bytestream2_put_le32(&pb, s->
slice_pos[0] - 32);
533 for (i = 0; i < s->
planes; i++) {
534 bytestream2_put_le32(&pb, s->
slice_pos[i] - 32);
551 for (i = 0; i < s->
planes; i++)
557 #define OFFSET(x) offsetof(MagicYUVContext, x)
558 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
580 .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.
static void left_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
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)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define u(width, name, range_min, range_max)
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.
static void magy_huffman_compute_bits(PTable *prob_table, HuffEntry *distincts, int size, int max_length)
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.
void(* predict)(struct MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
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)
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.
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.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
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.
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)
GLint GLenum GLboolean GLsizei stride
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.
#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)