28 #define BITSTREAM_READER_LE 41 return width * height * 2LL;
45 return width * height * 3LL;
94 int id,
int bpp, uint32_t vflipped)
113 for (h = 0; h < avctx->
height; h++) {
114 memcpy(dst, src, avctx->
width * bpp);
115 src += avctx->
width * bpp;
146 height = avctx->
height & ~3;
147 width = avctx->
width & ~3;
158 for (h = 0; h <
height; h += 4) {
159 for (w = 0; w <
width; w += 4) {
164 U[w >> 2] = src[16] + 0x80;
165 V[w >> 2] = src[17] + 0x80;
169 for (w = 0; w < hmargin; w++) {
170 Y1[width +
w] = src[
w];
171 Y2[width +
w] = src[w + hmargin * 1];
172 Y3[width +
w] = src[w + hmargin * 2];
173 Y4[width +
w] = src[w + hmargin * 3];
176 U[huvborder] = src[0] + 0x80;
177 V[huvborder] = src[1] + 0x80;
189 for (w = 0; w <
width; w += 4) {
196 U[w >> 2] = src[0] + 0x80;
197 V[w >> 2] = src[1] + 0x80;
201 for (w = 0; w < hmargin; w++) {
209 U[huvborder] = src[0] + 0x80;
210 V[huvborder] = src[1] + 0x80;
242 height = avctx->
height & ~1;
243 width = avctx->
width & ~1;
252 for (h = 0; h <
height; h += 2) {
253 for (w = 0; w <
width; w += 2) {
256 U[w >> 1] = src[4] + 0x80;
257 V[w >> 1] = src[5] + 0x80;
261 Y1[width + 1] = src[0];
262 Y2[width + 1] = src[1];
263 U[huvborder] = src[2] + 0x80;
264 V[huvborder] = src[3] + 0x80;
274 for (w = 0; w <
width; w += 2) {
276 U[w >> 1] = src[0] + 0x80;
277 V[w >> 1] = src[1] + 0x80;
282 U[huvborder] = src[1] + 0x80;
283 V[huvborder] = src[2] + 0x80;
316 for (h = 0; h < avctx->
height; h++) {
317 for (w = 0; w < avctx->
width; w++) {
319 U[
w] = *src++ ^ 0x80;
320 V[
w] = *src++ ^ 0x80;
332 static const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xFF };
343 memmove(lru + 1, lru,
sizeof(*lru) * (8 - 1));
346 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
355 int slice_size,
int off)
359 if (slice_size > src_size - off) {
361 "invalid slice size %d (only %d bytes left)\n",
362 slice_size, src_size - off);
365 if (slice_size <= 16) {
371 cur_slice_size =
AV_RL32(src + off);
372 if (cur_slice_size != slice_size - 16) {
374 "Slice sizes mismatch: got %d instead of %d\n",
375 cur_slice_size, slice_size - 16);
384 int *nslices,
int *off)
387 *nslices = bytestream2_get_le16(gb);
388 *off =
FFALIGN(*nslices * 4 + 2, 16);
389 if (src_size < *off) {
411 memmove(lru + 1, lru,
sizeof(*lru) * (6 - 1));
414 memmove(lru + 1, lru,
sizeof(*lru) * (c - 1));
436 int nslices, slice,
line = 0;
437 uint32_t off, slice_size;
442 ret =
load_buffer(avctx, src, src_size, &gb, &nslices, &off);
448 for (slice = 0; slice < nslices; slice++) {
449 slice_size = bytestream2_get_le32(&gb_check);
451 if (slice_size <= 16 + (avctx->
height * avctx->
width / (8 * nslices)))
453 off_check += slice_size;
465 for (slice = 0; slice < nslices; slice++) {
466 slice_size = bytestream2_get_le32(&gb);
474 if ((ret =
init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
482 if (avctx->
height - line) {
502 for (y = 0; y < left && get_bits_left(gb) >= 3 *
width; y++) {
503 for (x = 0; x <
width; x++) {
507 dst[x * 3 + 0] = (r << 3) | (r >> 2);
508 dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2);
509 dst[x * 3 + 2] = (b << 3) | (b >> 2);
569 for (y = 0; y < left && get_bits_left(gb) >= 3 *
width; y++) {
570 for (x = 0; x <
width; x++) {
586 for (i = 0; i < 3; i++)
615 int h,
w, hmargin, vmargin;
619 w = frame->
width & ~3;
620 hmargin = frame->
width -
w;
624 for (y = 0; y < left - 3 &&
get_bits_left(gb) >= 18 * w / 4 + hmargin * 4 + (!!hmargin * 2); y += 4) {
625 for (x = 0; x <
w; x += 4) {
626 for (j = 0; j < 4; j++)
627 for (i = 0; i < 4; i++)
628 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
633 for (j = 0; j < 4; j++)
634 for (i = 0; i < hmargin; i++)
635 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
645 if (vmargin && y + vmargin == left) {
646 for (x = 0; x <
width; x += 4) {
647 for (j = 0; j < vmargin; j++)
648 for (i = 0; i < 4; i++)
649 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
654 for (j = 0; j < vmargin; j++) {
655 for (i = 0; i < hmargin; i++)
656 Y[x + i + j * ystride] =
decode_sym(gb, lru[0]);
695 int h,
w, hmargin, vmargin;
699 w = frame->
width & ~1;
700 hmargin = frame->
width -
w;
704 for (y = 0; y < left - 1 &&
get_bits_left(gb) >= 3 * w + hmargin * 4; y += 2) {
705 for (x = 0; x <
w; x += 2) {
706 Y[x + 0 + 0 * ystride] =
decode_sym(gb, lru[0]);
707 Y[x + 1 + 0 * ystride] =
decode_sym(gb, lru[0]);
708 Y[x + 0 + 1 * ystride] =
decode_sym(gb, lru[0]);
709 Y[x + 1 + 1 * ystride] =
decode_sym(gb, lru[0]);
726 for (x = 0; x <
width; x += 2) {
767 for (y = 0; y < left && get_bits_left(gb) >= 3 *
width; y++) {
768 for (x = 0; x <
width; x++) {
800 if (avpkt->
size < 16) {
806 vflipped = !!(type & 0x20);
static int dxtory_decode_v1_420(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
packed RGB 8:8:8, 24bpp, RGBRGB...
static int decode_slice(AVCodecContext *c, void *arg)
static int dxtory_decode_v1_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static void default_setup_lru(uint8_t lru[3][8])
#define avpriv_request_sample(...)
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
static const uint8_t def_lru_555[8]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int dx2_decode_slice_565(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int is_565, uint32_t vflipped)
static int64_t get_raw_size(enum AVPixelFormat fmt, int width, int height)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Multithreading support functions.
int(* decode_slice_func)(GetBitContext *gb, AVFrame *frame, int line, int height, uint8_t lru[3][8])
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static av_always_inline int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8], int is_565)
bitstream reader API header.
static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
void(* setup_lru_func)(uint8_t lru[3][8])
static int get_bits_left(GetBitContext *gb)
static void do_vflip(AVCodecContext *avctx, AVFrame *pic, int vflip)
static const uint8_t def_lru[8]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void setup_lru_555(uint8_t lru[3][8])
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int dx2_decode_slice_420(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
const char * name
Name of the codec implementation.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames.The frames must then be freed with ff_thread_release_buffer().Otherwise decode directly into the user-supplied frames.Call ff_thread_report_progress() after some part of the current picture has decoded.A good place to put this is where draw_horiz_band() is called-add this if it isn't called anywhere
enum AVPictureType pict_type
Picture type of the frame.
static int dxtory_decode_v1_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, int id, int bpp, uint32_t vflipped)
int width
picture width / height.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
static int dx2_decode_slice_410(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
packed RGB 8:8:8, 24bpp, BGRBGR...
static int dx2_decode_slice_555(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
static uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
static int load_buffer(AVCodecContext *avctx, const uint8_t *src, int src_size, GetByteContext *gb, int *nslices, int *off)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
AVCodec ff_dxtory_decoder
static int dxtory_decode_v2_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
int discard_damaged_percentage
The percentage of damaged samples to discard a frame.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
main external API structure.
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2]...the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so...,+,-,+,-,+,+,-,+,-,+,...hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32-hcoeff[1]-hcoeff[2]-...a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2}an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||.........intra?||||:Block01:yes no||||:Block02:.................||||:Block03::y DC::ref index:||||:Block04::cb DC::motion x:||||.........:cr DC::motion y:||||.................|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------------------------------|||Y subbands||Cb subbands||Cr subbands||||------||------||------|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||------||------||------||||------||------||------|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||------||------||------||||------||------||------|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||------||------||------||||------||------||------|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------------------------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction------------|\Dequantization-------------------\||Reference frames|\IDWT|--------------|Motion\|||Frame 0||Frame 1||Compensation.OBMC v-------|--------------|--------------.\------> Frame n output Frame Frame<----------------------------------/|...|-------------------Range Coder:============Binary Range Coder:-------------------The implemented range coder is an adapted version based upon"Range encoding: an algorithm for removing redundancy from a digitised message."by G.N.N.Martin.The symbols encoded by the Snow range coder are bits(0|1).The associated probabilities are not fix but change depending on the symbol mix seen so far.bit seen|new state---------+-----------------------------------------------0|256-state_transition_table[256-old_state];1|state_transition_table[old_state];state_transition_table={0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:-------------------------FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1.the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, decode_slice_func decode_slice, setup_lru_func setup_lru, enum AVPixelFormat fmt, uint32_t vflipped)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static int check_slice_size(AVCodecContext *avctx, const uint8_t *src, int src_size, int slice_size, int off)
static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, uint32_t vflipped)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const uint8_t def_lru_565[8]
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
common internal api header.
common internal and external API header
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame, int line, int left, uint8_t lru[3][8])
int key_frame
1 -> keyframe, 0-> not
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
AVPixelFormat
Pixel format.
static double val(void *priv, double ch)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8], int bits)
#define AV_CEIL_RSHIFT(a, b)
static void setup_lru_565(uint8_t lru[3][8])
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)