81 dst[
i] =
src[
i] - prev;
86 for (j = 1; j <
height; j++) {
89 dst[
i] =
src[
i] - prev;
101 int left = 0, top, lefttop;
105 dst[
i] =
src[
i] - left;
110 for (j = 1; j <
height; j++) {
118 dst[
i] = (
src[
i] - top) - left + lefttop;
129 int left = 0, lefttop;
133 dst[
i] =
src[
i] - left;
138 for (j = 1; j <
height; j++) {
201 for (
i = 0;
i <
s->planes;
i++) {
210 switch (
s->frame_pred) {
227 bytestream2_put_le32(&
pb,
MKTAG(
'M',
'A',
'G',
'Y'));
228 bytestream2_put_le32(&
pb, 32);
229 bytestream2_put_byte(&
pb, 7);
230 bytestream2_put_byte(&
pb,
s->format);
231 bytestream2_put_byte(&
pb, 12);
232 bytestream2_put_byte(&
pb, 0);
234 bytestream2_put_byte(&
pb, 0);
235 bytestream2_put_byte(&
pb, 0);
236 bytestream2_put_byte(&
pb, 32);
237 bytestream2_put_byte(&
pb, 0);
239 bytestream2_put_le32(&
pb, avctx->
width);
240 bytestream2_put_le32(&
pb, avctx->
height);
241 bytestream2_put_le32(&
pb, avctx->
width);
242 bytestream2_put_le32(&
pb, avctx->
height);
249 for (
unsigned i = 32, nb_codes = 0;
i > 0;
i--) {
250 uint16_t curr = codes_count[
i];
251 codes_count[
i] = nb_codes / 2;
252 nb_codes = codes_count[
i] + curr;
255 for (
unsigned i = 0;
i < 256;
i++) {
266 for (j = 0; j <
height; j++) {
285 return a2->prob -
b2->prob;
289 uint16_t codes_counts[33],
290 int size,
int max_length)
294 int nbits[257] = {0};
302 from->item_idx[0] = 0;
305 for (times = 0; times <= max_length; times++) {
312 if (times < max_length) {
315 while (
i <
size || j + 1 <
from->nitems) {
317 to->item_idx[
to->nitems] =
to->item_idx[
to->nitems - 1];
319 (j + 1 >=
from->nitems ||
321 from->probability[j] +
from->probability[j + 1])) {
322 to->items[
to->item_idx[
to->nitems]++] = prob_table[
i].
value;
323 to->probability[
to->nitems - 1] = prob_table[
i].
prob;
326 for (k =
from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
327 to->items[
to->item_idx[
to->nitems]++] =
from->items[k];
329 to->probability[
to->nitems - 1] =
330 from->probability[j] +
from->probability[j + 1];
341 nbits[
from->items[
i]]++;
345 distincts[
i].
len = nbits[
i];
346 codes_counts[nbits[
i]]++;
354 PTable counts[256] = { {0} };
355 uint16_t codes_counts[33] = { 0 };
360 for (
i = 0;
i < 256;
i++) {
369 for (
i = 0;
i < 256;
i++) {
389 for (j = 0; j <
height; j++) {
391 const int idx =
src[
i];
416 int pos, slice,
i, j, ret = 0;
424 bytestream2_put_le32(&pb,
MKTAG(
'M',
'A',
'G',
'Y'));
425 bytestream2_put_le32(&pb, 32);
426 bytestream2_put_byte(&pb, 7);
427 bytestream2_put_byte(&pb,
s->format);
428 bytestream2_put_byte(&pb, 12);
429 bytestream2_put_byte(&pb, 0);
431 bytestream2_put_byte(&pb, 0);
432 bytestream2_put_byte(&pb, 0);
433 bytestream2_put_byte(&pb, 32);
434 bytestream2_put_byte(&pb, 0);
436 bytestream2_put_le32(&pb, avctx->
width);
437 bytestream2_put_le32(&pb, avctx->
height);
438 bytestream2_put_le32(&pb, avctx->
width);
439 bytestream2_put_le32(&pb, avctx->
height);
440 bytestream2_put_le32(&pb, 0);
442 for (
i = 0;
i <
s->planes;
i++) {
443 bytestream2_put_le32(&pb, 0);
444 for (j = 1; j <
s->nb_slices; j++) {
445 bytestream2_put_le32(&pb, 0);
449 bytestream2_put_byte(&pb,
s->planes);
451 for (
i = 0;
i <
s->planes;
i++) {
452 for (slice = 0; slice <
s->nb_slices; slice++) {
453 bytestream2_put_byte(&pb,
i);
466 s->llvidencdsp.diff_bytes(
b,
b,
g,
width);
467 s->llvidencdsp.diff_bytes(
r,
r,
g,
width);
476 for (
i = 0;
i <
s->planes;
i++) {
477 for (slice = 0; slice <
s->nb_slices; slice++) {
485 for (
i = 0;
i <
s->planes;
i++) {
486 for (slice = 0; slice <
s->nb_slices; slice++) {
496 for (
i = 0;
i <
s->planes;
i++) {
505 for (
i = 0;
i <
s->planes;
i++) {
513 s->he[
i],
s->frame_pred);
519 bytestream2_put_le32(&pb,
s->slice_pos[0] - 32);
520 for (
i = 0;
i <
s->planes;
i++) {
521 bytestream2_put_le32(&pb,
s->slice_pos[
i] - 32);
538 for (
i = 0;
i <
s->planes;
i++)
544 #define OFFSET(x) offsetof(MagicYUVContext, x)
545 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left_p(PutByteContext *p)
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
#define AV_CEIL_RSHIFT(a, b)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define LIBAVUTIL_VERSION_INT
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
static void count_usage(uint8_t *src, int width, int height, PTable *counts)
static int encode_table(AVCodecContext *avctx, uint8_t *dst, int width, int height, PutBitContext *pb, HuffEntry *he)
static void left_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
static const AVOption options[]
static av_cold int magy_encode_init(AVCodecContext *avctx)
AVCodec ff_magicyuv_encoder
static void calculate_codes(HuffEntry *he, uint16_t codes_count[33])
static void median_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
static int encode_slice(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he, int prediction)
static const AVClass magicyuv_class
static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static void magy_huffman_compute_bits(PTable *prob_table, HuffEntry *distincts, uint16_t codes_counts[33], int size, int max_length)
static int compare_by_prob(const void *a, const void *b)
static av_cold int magy_encode_close(AVCodecContext *avctx)
static void gradient_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#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...
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
void(* predict)(struct MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
LLVidEncDSPContext llvidencdsp
Used to assign a occurrence count or "probability" to an input value.
int64_t prob
number of occurences of this value in input
Used to store intermediate lists in the package merge algorithm.
int probability[514]
probability of each item 3, 8, 18, 46
int items[257 *16]
chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D,...
int item_idx[515]
index range for each item in items 0, 2, 5, 9, 13
int nitems
number of items in the list and probability ex. 4
static double b2(void *priv, double x, double y)