Lines Matching defs:mp

59     MotionPixelsContext *mp = avctx->priv_data;
61 av_freep(&mp->changes_map);
62 av_freep(&mp->vpt);
63 av_freep(&mp->hpt);
64 av_freep(&mp->bswapbuf);
65 av_frame_free(&mp->frame);
73 MotionPixelsContext *mp = avctx->priv_data;
82 mp->avctx = avctx;
83 ff_bswapdsp_init(&mp->bdsp);
84 mp->changes_map = av_calloc(avctx->width, h4);
85 mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1;
86 mp->vpt = av_calloc(avctx->height, sizeof(*mp->vpt));
87 mp->hpt = av_calloc(h4 / 4, w4 / 4 * sizeof(*mp->hpt));
88 if (!mp->changes_map || !mp->vpt || !mp->hpt)
92 mp->frame = av_frame_alloc();
93 if (!mp->frame)
103 static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int count, int bits_len, int read_color)
109 offset = get_bits_long(gb, mp->offset_bits_len);
114 x = offset % mp->avctx->width;
115 y = offset / mp->avctx->width;
116 if (y >= mp->avctx->height)
118 w = FFMIN(w, mp->avctx->width - x);
119 h = FFMIN(h, mp->avctx->height - y);
120 pixels = (uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2];
122 mp->changes_map[offset] = w;
126 offset += mp->avctx->width;
127 pixels += mp->frame->linesize[0] / 2;
132 static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size)
136 if (size > mp->max_codes_bits) {
137 av_log(mp->avctx, AV_LOG_ERROR, "invalid code size %d/%d\n", size, mp->max_codes_bits);
140 if (mp_get_code(mp, gb, size) < 0)
143 if (mp->current_codes_count >= mp->codes_count) {
144 av_log(mp->avctx, AV_LOG_ERROR, "too many codes\n");
148 mp->codes[mp->current_codes_count++].size = size;
152 static int mp_read_codes_table(MotionPixelsContext *mp, GetBitContext *gb)
154 if (mp->codes_count == 1) {
155 mp->codes[0].delta = get_bits(gb, 4);
160 mp->max_codes_bits = get_bits(gb, 4);
161 for (i = 0; i < mp->codes_count; ++i)
162 mp->codes[i].delta = get_bits(gb, 4);
163 mp->current_codes_count = 0;
164 if ((ret = mp_get_code(mp, gb, 0)) < 0)
166 if (mp->current_codes_count < mp->codes_count) {
167 av_log(mp->avctx, AV_LOG_ERROR, "too few codes\n");
174 static av_always_inline int mp_gradient(MotionPixelsContext *mp, int component, int v)
178 delta = (v - 7) * mp->gradient_scale[component];
179 mp->gradient_scale[component] = (v == 0 || v == 14) ? 2 : 1;
183 static YuvPixel mp_get_yuv_from_rgb(MotionPixelsContext *mp, int x, int y)
187 color = *(uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2];
191 static void mp_set_rgb_from_yuv(MotionPixelsContext *mp, int x, int y, const YuvPixel *p)
196 *(uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2] = color;
199 static av_always_inline int mp_get_vlc(MotionPixelsContext *mp, GetBitContext *gb)
201 return mp->vlc.table ? get_vlc2(gb, mp->vlc.table, mp->max_codes_bits, 1)
202 : mp->codes[0].delta;
205 static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y)
208 const int y0 = y * mp->avctx->width;
211 p = mp->vpt[y];
212 if (mp->changes_map[y0 + x] == 0) {
213 memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
216 while (x < mp->avctx->width) {
217 w = mp->changes_map[y0 + x];
220 if (mp->changes_map[y0 + x + mp->avctx->width] < w ||
221 mp->changes_map[y0 + x + mp->avctx->width * 2] < w ||
222 mp->changes_map[y0 + x + mp->avctx->width * 3] < w) {
224 mp->hpt[((y / 4) * mp->avctx->width + i) / 4] = mp_get_yuv_from_rgb(mp, i, y);
229 memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
230 p = mp_get_yuv_from_rgb(mp, x - 1, y);
232 p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb));
236 p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb));
238 p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb));
240 mp->hpt[((y / 4) * mp->avctx->width + x) / 4] = p;
242 p.v = mp->hpt[((y / 4) * mp->avctx->width + x) / 4].v;
243 p.u = mp->hpt[((y / 4) * mp->avctx->width + x) / 4].u;
246 mp_set_rgb_from_yuv(mp, x, y, &p);
252 static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb)
257 av_assert1(mp->changes_map[0]);
259 for (y = 0; y < mp->avctx->height; ++y) {
260 if (mp->changes_map[y * mp->avctx->width] != 0) {
261 memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
262 p = mp_get_yuv_from_rgb(mp, 0, y);
264 p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb));
267 p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb));
269 p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb));
272 mp->vpt[y] = p;
273 mp_set_rgb_from_yuv(mp, 0, y, &p);
277 for (y = y0; y < mp->avctx->height; y += 2)
278 mp_decode_line(mp, gb, y);
286 MotionPixelsContext *mp = avctx->priv_data;
290 if ((ret = ff_reget_buffer(avctx, mp->frame, 0)) < 0)
294 av_fast_padded_malloc(&mp->bswapbuf, &mp->bswapbuf_size, buf_size);
295 if (!mp->bswapbuf)
297 mp->bdsp.bswap_buf((uint32_t *) mp->bswapbuf, (const uint32_t *) buf,
300 memcpy(mp->bswapbuf + (buf_size & ~3), buf + (buf_size & ~3), buf_size & 3);
301 init_get_bits(&gb, mp->bswapbuf, buf_size * 8);
303 memset(mp->changes_map, 0, avctx->width * avctx->height);
307 mp_read_changes_map(mp, &gb, count1, 8, i);
308 mp_read_changes_map(mp, &gb, count2, 4, i);
311 mp->codes_count = get_bits(&gb, 4);
312 if (mp->codes_count == 0)
315 if (mp->changes_map[0] == 0) {
316 *(uint16_t *)mp->frame->data[0] = get_bits(&gb, 15);
317 mp->changes_map[0] = 1;
319 if (mp_read_codes_table(mp, &gb) < 0)
328 if (mp->codes_count > 1) {
329 /* The entries of the mp->codes array are sorted from right to left
331 ret = ff_init_vlc_from_lengths(&mp->vlc, mp->max_codes_bits, mp->codes_count,
332 &mp->codes[mp->codes_count - 1].size, -(int)sizeof(HuffCode),
333 &mp->codes[mp->codes_count - 1].delta, -(int)sizeof(HuffCode), 1,
338 mp_decode_frame_helper(mp, &gb);
339 ff_free_vlc(&mp->vlc);
342 if ((ret = av_frame_ref(rframe, mp->frame)) < 0)