2012-11-10 15:19:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mpv; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPV_TALLOC_H
|
|
|
|
#define MPV_TALLOC_H
|
|
|
|
|
|
|
|
#include "talloc.h"
|
|
|
|
#include "compat/compiler.h"
|
|
|
|
|
|
|
|
#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
|
2013-10-19 19:42:49 +00:00
|
|
|
|
|
|
|
#define MP_RESIZE_ARRAY(ctx, p, count) do { \
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
(p) = talloc_realloc_size((ctx), p, (count) * sizeof((p)[0])); } while (0)
|
2012-11-10 15:19:53 +00:00
|
|
|
|
|
|
|
#define MP_TARRAY_GROW(ctx, p, nextidx) \
|
|
|
|
do { \
|
|
|
|
size_t nextidx_ = (nextidx); \
|
2013-10-19 19:42:49 +00:00
|
|
|
if (nextidx_ >= MP_TALLOC_ELEMS(p)) \
|
|
|
|
MP_RESIZE_ARRAY(ctx, p, (nextidx_ + 1) * 2);\
|
2012-11-10 15:19:53 +00:00
|
|
|
} while (0)
|
|
|
|
|
2013-10-19 19:42:49 +00:00
|
|
|
#define MP_GROW_ARRAY(p, nextidx) MP_TARRAY_GROW(NULL, p, nextidx)
|
|
|
|
|
2012-11-10 15:19:53 +00:00
|
|
|
#define MP_TARRAY_APPEND(ctx, p, idxvar, ...) \
|
|
|
|
do { \
|
|
|
|
MP_TARRAY_GROW(ctx, p, idxvar); \
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
(p)[(idxvar)] = (MP_EXPAND_ARGS(__VA_ARGS__));\
|
|
|
|
(idxvar)++; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
// Doesn't actually free any memory, or do any other talloc calls.
|
|
|
|
#define MP_TARRAY_REMOVE_AT(p, idxvar, at) \
|
|
|
|
do { \
|
|
|
|
size_t at_ = (at); \
|
|
|
|
assert(at_ <= (idxvar)); \
|
|
|
|
memmove((p) + at_, (p) + at_ + 1, \
|
|
|
|
((idxvar) - at_ - 1) * sizeof((p)[0])); \
|
|
|
|
(idxvar)--; \
|
2012-11-10 15:19:53 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define talloc_struct(ctx, type, ...) \
|
|
|
|
talloc_memdup(ctx, &(type) MP_EXPAND_ARGS(__VA_ARGS__), sizeof(type))
|
|
|
|
|
|
|
|
#endif
|