1 /*
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
28
31
34
39 int x, y, mb_x;
41 int block_w = plane_index ? block_size>>s->
chroma_h_shift : block_size;
42 int block_h = plane_index ? block_size>>s->
chroma_v_shift : block_size;
44 int obmc_stride= plane_index ? (2*block_size)>>s->
chroma_h_shift : 2*block_size;
49
51 if(mb_y==mb_h)
52 return;
53
54 if(add){
55 for(y=block_h*mb_y; y<
FFMIN(
h,block_h*(mb_y+1)); y++){
56 // DWTELEM * line = slice_buffer_get_line(sb, y);
58 for(x=0; x<w; x++){
59 // int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
62 if(v&(~255)) v= ~(v>>31);
63 dst8[x + y*ref_stride]= v;
64 }
65 }
66 }else{
67 for(y=block_h*mb_y; y<
FFMIN(
h,block_h*(mb_y+1)); y++){
68 // DWTELEM * line = slice_buffer_get_line(sb, y);
70 for(x=0; x<w; x++){
72 // buf[x + y*w]-= 128<<FRAC_BITS;
73 }
74 }
75 }
76
77 return;
78 }
79
80 for(mb_x=0; mb_x<=mb_w; mb_x++){
82 block_w*mb_x - block_w/2,
83 block_h*mb_y - block_h/2,
84 block_w, block_h,
86 w, ref_stride, obmc_stride,
87 mb_x - 1, mb_y - 1,
88 add, 0, plane_index);
89 }
90
91 if(s->
avmv && mb_y < mb_h && plane_index == 0)
92 for(mb_x=0; mb_x<mb_w; mb_x++){
95 const int b_stride= b_width;
97
99 continue;
100
102
105 avmv->
dst_x = block_w*mb_x - block_w/2;
106 avmv->
dst_y = block_h*mb_y - block_h/2;
114 }
115 }
116
118 const int w= b->
width;
119 int y;
123 int new_index = 0;
124
126 qadd= 0;
128 }
129
130 /* If we are on the second or later slice, restore our index. */
131 if (start_y != 0)
132 new_index = save_state[0];
133
134
135 for(y=start_y; y<
h; y++){
136 int x = 0;
137 int v;
142 while(x < w){
143 register int t= ( (v>>1)*qmul + qadd)>>
QEXPSHIFT;
144 register int u= -(v&1);
145 line[x] = (t^u) - u;
146
149 }
150 }
151
152 /* Save our variables for the next slice. */
153 save_state[0] = new_index;
154
155 return;
156 }
157
161 const int index= (x + y*w) << rem_depth;
162 int trx= (x+1)<<rem_depth;
166 const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->
block[index-w+(1<<rem_depth)] : tl;
//FIXME use lt
168 int res;
169
171 set_blocks(s, level, x, y,
null_block.
color[0],
null_block.
color[1],
null_block.
color[2],
null_block.
mx,
null_block.
my,
null_block.
ref,
BLOCK_INTRA);
172 return 0;
173 }
174
177 int l = left->
color[0];
180 unsigned ref = 0;
184
186
187 if(type){
188 pred_mv(s, &mx, &my, 0, left, top, tr);
193 }
194 }else{
200 }
201 pred_mv(s, &mx, &my, ref, left, top, tr);
204 }
205 set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type);
206 }else{
211 return res;
212 }
213 return 0;
214 }
215
217 const int w= b->
width;
221 int x,y;
222
224
225 for(y=start_y; y<end_y; y++){
226 // DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride));
228 for(x=0; x<w; x++){
229 int i= line[x];
230 if(i<0){
231 line[x]= -((-i*qmul + qadd)>>(
QEXPSHIFT));
//FIXME try different bias
232 }else if(i>0){
233 line[x]= (( i*qmul + qadd)>>(
QEXPSHIFT));
234 }
235 }
236 }
237 }
238
240 const int w= b->
width;
241 int x,y;
242
243 IDWTELEM *
line=0;
// silence silly "could be used without having been initialized" warning
245
246 if (start_y != 0)
248
249 for(y=start_y; y<end_y; y++){
250 prev = line;
251 // line = slice_buffer_get_line_from_address(sb, src + (y * stride));
253 for(x=0; x<w; x++){
254 if(x){
255 if(use_median){
256 if(y && x+1<w) line[x] +=
mid_pred(line[x - 1], prev[x], prev[x + 1]);
257 else line[x] += line[x - 1];
258 }else{
259 if(y) line[x] +=
mid_pred(line[x - 1], prev[x], line[x - 1] + prev[x] - prev[x - 1]);
260 else line[x] += line[x - 1];
261 }
262 }else{
263 if(y) line[x] += prev[x];
264 }
265 }
266 }
267 }
268
270 int plane_index,
level, orientation;
271
272 for(plane_index=0; plane_index < s->
nb_planes; plane_index++){
274 for(orientation=level ? 1:0; orientation<4; orientation++){
275 int q;
280 }
281 }
282 }
283 }
284
285 #define GET_S(dst, check) \
286 tmp= get_symbol(&s->c, s->header_state, 0);\
287 if(!(check)){\
288 av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\
289 return AVERROR_INVALIDDATA;\
290 }\
291 dst= tmp;
292
294 int plane_index, tmp;
296
297 memset(kstate,
MID_STATE,
sizeof(kstate));
298
307 }
321
328 } else {
333 }
335 } else {
340 }
341
342
344 // s->rate_scalability= get_rac(&s->c, s->header_state);
347
349 }
350
353 for(plane_index=0; plane_index<
FFMIN(s->
nb_planes, 2); plane_index++){
358 if((
unsigned)htaps >
HTAPS_MAX || htaps==0)
361 for(i= htaps/2; i; i--){
364 }
366 }
370 }
374 }
375 }
376
381 }
386 }
387
388
397 }
398
399 return 0;
400 }
401
403 {
404 int ret;
405
407 return ret;
408 }
409
410 return 0;
411 }
412
414 int x, y;
417 int res;
418
420 for(x=0; x<w; x++){
422 return res;
423 }
424 }
425 return 0;
426 }
427
430 {
432 int buf_size = avpkt->
size;
435 int bytes_read;
437 int level, orientation, plane_index;
438 int res;
439
442
445 return res;
447 return res;
448
449 // realloc slice buffer for the case that spatial_decomposition_count changed
456 return res;
457
458 for(plane_index=0; plane_index < s->
nb_planes; plane_index++){
463 }
464
466
468 return res;
469
471
472 //keyframe flag duplication mess FIXME
475 "keyframe:%d qlog:%d qbias: %d mvscale: %d "
476 "decomposition_type:%d decomposition_count:%d\n",
480 );
481
485 }
487
489 return res;
490
491 for(plane_index=0; plane_index < s->
nb_planes; plane_index++){
495 int x, y;
496 int decode_state[
MAX_DECOMPOSITIONS][4][1];
/* Stored state info for unpack_coeffs. 1 variable per instance. */
497
501
503 for(x=0; x<w; x++){
506 }
507 }
508 }
509
510 {
512 for(orientation=level ? 1 : 0; orientation<4; orientation++){
515 }
516 }
517 }
518
519 {
522 const int block_h = plane_index ? block_size>>s->
chroma_v_shift : block_size;
523 int mb_y;
525 int yd=0, yq=0;
526 int y;
527 int end_y;
528
530 for(mb_y=0; mb_y<=mb_h; mb_y++){
531
532 int slice_starty = block_h*mb_y;
533 int slice_h = block_h*(mb_y+1);
534
536 slice_starty =
FFMAX(0, slice_starty - (block_h >> 1));
537 slice_h -= (block_h >> 1);
538 }
539
541 for(orientation=level ? 1 : 0; orientation<4; orientation++){
543 int start_y;
544 int end_y;
545 int our_mb_start = mb_y;
546 int our_mb_end = (mb_y + 1);
547 const int extra= 3;
553 }
556
557 if (start_y != end_y){
558 if (orientation == 0){
561 int correlate_start_y =
FFMIN(b->
height, (start_y ? start_y + 1 : 0));
565 }
566 else
568 }
569 }
570 }
571
572 for(; yd<slice_h; yd+=4){
574 }
575
577 for(; yq<slice_h && yq<
h; yq++){
579 for(x=0; x<w; x++){
581 }
582 }
583 }
584
586
589 while(y < end_y)
591 }
592
594 }
595
596 }
597
598 emms_c();
599
601
604 else
608
610 if (!sd)
613 }
614
616
617 if (res < 0)
618 return res;
619
620 *got_frame = 1;
621
624
625 return bytes_read;
626 }
627
629 {
631
633
635
636 return 0;
637 }
638
651 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add)
int ff_snow_frame_start(SnowContext *s)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static const double htaps[HTAPS]
The 2nd half (48 coeffs) of a 96-tap symmetric lowpass filter.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int16_t src_x
Absolute source position.
static av_cold int init(AVCodecContext *avctx)
void ff_slice_buffer_destroy(slice_buffer *buf)
static av_cold int decode_end(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int ff_snow_common_init_after_header(AVCodecContext *avctx)
void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs, slice_buffer *slice_buf, IDWTELEM *temp, int width, int height, int stride_line, int type, int decomposition_count, int y)
void ff_snow_reset_contexts(SnowContext *s)
static void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type)
int qlog
log(qscale)/log[2^(1/6)]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static double cb(void *priv, double x, double y)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static int get_rac(RangeCoder *c, uint8_t *const state)
#define FF_DEBUG_PICT_INFO
int16_t dst_x
Absolute destination position.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Structure to hold side data for an AVFrame.
int32_t source
Where the current macroblock comes from; negative value when it comes from the past, positive value when it comes from the future.
static const BlockNode null_block
void ff_snow_release_buffer(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, int height, int stride_line, int type, int decomposition_count)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
uint8_t w
Width and height of the block.
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
const uint8_t *const ff_obmc_tab[4]
const char * name
Name of the codec implementation.
static av_cold int decode_init(AVCodecContext *avctx)
void ff_slice_buffer_flush(slice_buffer *buf)
static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
SubBand band[DWT_LEVELS][4]
enum AVPictureType pict_type
Picture type of the frame.
static void unpack_coeffs(SnowContext *s, SubBand *b, SubBand *parent, int orientation)
int32_t motion_x
Motion vector src_x = dst_x + motion_x / motion_scale src_y = dst_y + motion_y / motion_scale.
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index)
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void correlate_slice_buffered(SnowContext *s, slice_buffer *sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y)
static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer *sb, IDWTELEM *old_buffer, int plane_index, int add, int mb_y)
uint8_t block_state[128+32 *128]
Libavcodec external API header.
int spatial_decomposition_count
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_slice_buffer_init(slice_buffer *buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM *base_buffer)
main external API structure.
int8_t hcoeff[HTAPS_MAX/2]
int ff_snow_alloc_blocks(SnowContext *s)
static void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer *sb, int start_y, int h, int save_state[1])
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
static void decode_qlogs(SnowContext *s)
int ff_snow_common_init(AVCodecContext *avctx)
static int decode_header(SnowContext *s)
int spatial_decomposition_type
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVFrame * current_picture
#define MAX_DECOMPOSITIONS
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
uint64_t flags
Extra flag information.
int temporal_decomposition_type
common internal api header.
IDWTELEM ** line
For use by idwt and predict_slices.
IDWTELEM * temp_idwt_buffer
#define slice_buffer_get_line(slice_buf, line_num)
DWTELEM * spatial_dwt_buffer
IDWTELEM * spatial_idwt_buffer
uint8_t * bytestream_start
static void dequantize_slice_buffered(SnowContext *s, slice_buffer *sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y)
int flags2
AV_CODEC_FLAG2_*.
av_cold void ff_snow_common_end(SnowContext *s)
#define AV_CODEC_FLAG2_EXPORT_MVS
Export motion vectors through frame side data.
static int decode_blocks(SnowContext *s)
void ff_slice_buffer_release(slice_buffer *buf, int line)
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
#define av_malloc_array(a, b)
Used to minimize the amount of memory used in order to optimize cache performance.
static double cr(void *priv, double x, double y)
int temporal_decomposition_count
This structure stores compressed data.
static int decode_q_branch(SnowContext *s, int level, int x, int y)
#define GET_S(dst, check)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int stride_line
Stride measured in lines, not pixels.