static const VSFrameRef *_vszimg_get_frame(struct vszimg_data *data, const VSFrameRef *src_frame, VSCore *core, const VSAPI *vsapi, char *err_msg, size_t err_msg_size) { struct vszimg_graph_data *graph_data = NULL; VSFrameRef *dst_frame = NULL; VSFrameRef *ret = NULL; void *tmp = NULL; struct callback_data unpack_cb_data = { 0 }; struct callback_data pack_cb_data = { 0 }; zimg_image_format src_format; zimg_image_format dst_format; const VSFormat *src_vsformat; const VSFormat *dst_vsformat; const VSMap *src_props; VSMap *dst_props; size_t tmp_size; zimg_image_format_default(&src_format, ZIMG_API_VERSION); zimg_image_format_default(&dst_format, ZIMG_API_VERSION); src_props = vsapi->getFramePropsRO(src_frame); src_vsformat = vsapi->getFrameFormat(src_frame); dst_vsformat = data->vi.format ? data->vi.format : src_vsformat; src_format.width = vsapi->getFrameWidth(src_frame, 0); src_format.height = vsapi->getFrameHeight(src_frame, 0); dst_format.width = data->vi.width ? (unsigned)data->vi.width : src_format.width; dst_format.height = data->vi.height ? (unsigned)data->vi.height : src_format.height; if (translate_vsformat(src_vsformat, &src_format, err_msg)) goto fail; if (translate_vsformat(dst_vsformat, &dst_format, err_msg)) goto fail; _vszimg_set_src_colorspace(data, &src_format); if (import_frame_props(vsapi, src_props, &src_format, err_msg)) goto fail; _vszimg_set_dst_colorspace(data, &src_format, &dst_format); if (!(graph_data = _vszimg_get_graph_data(data, &src_format, &dst_format, err_msg, err_msg_size))) goto fail; dst_frame = vsapi->newVideoFrame(dst_vsformat, dst_format.width, dst_format.height, src_frame, core); dst_props = vsapi->getFramePropsRW(dst_frame); if (callback_init_unpack(&unpack_cb_data, graph_data->graph, src_frame, &src_format, src_vsformat, core, vsapi, err_msg, err_msg_size)) goto fail; if (callback_init_pack(&pack_cb_data, graph_data->graph, dst_frame, &dst_format, dst_vsformat, core, vsapi, err_msg, err_msg_size)) goto fail; if (zimg_filter_graph_get_tmp_size(graph_data->graph, &tmp_size)) { format_zimg_error(err_msg, err_msg_size); goto fail; } VS_ALIGNED_MALLOC(&tmp, tmp_size, 64); if (!tmp) { sprintf(err_msg, "error allocating temporary buffer"); goto fail; } if (zimg_filter_graph_process(graph_data->graph, &unpack_cb_data.line_buf.c, &pack_cb_data.line_buf.m, tmp, unpack_cb_data.cb, &unpack_cb_data, pack_cb_data.cb, &pack_cb_data)) { format_zimg_error(err_msg, err_msg_size); goto fail; } propagate_sar(vsapi, src_props, dst_props, &src_format, &dst_format); export_frame_props(vsapi, &dst_format, dst_props); ret = dst_frame; dst_frame = NULL; fail: _vszimg_release_graph_data(data, graph_data); vsapi->freeFrame(dst_frame); VS_ALIGNED_FREE(tmp); callback_destroy(&unpack_cb_data, vsapi); callback_destroy(&pack_cb_data, vsapi); return ret; }
static const VSFrameRef * VS_CC vs_colorspace_get_frame(int n, int activationReason, void **instanceData, void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi) { vs_colorspace_data *data = *instanceData; VSFrameRef *ret = 0; char fail_str[1024]; int err = 0; if (activationReason == arInitial) { vsapi->requestFrameFilter(n, data->node, frameCtx); } else if (activationReason == arAllFramesReady) { const VSFrameRef *src_frame = 0; VSFrameRef *dst_frame = 0; void *tmp = 0; const void *src_plane[3]; void *dst_plane[3]; ptrdiff_t src_stride[3]; ptrdiff_t dst_stride[3]; int width; int height; size_t tmp_size; VSMap *props; unsigned p; width = data->vi.width; height = data->vi.height; src_frame = vsapi->getFrameFilter(n, data->node, frameCtx); dst_frame = vsapi->newVideoFrame(data->vi.format, width, height, src_frame, core); if ((err = zimg2_plane_filter_get_tmp_size(data->filter, &tmp_size))) { zimg_get_last_error(fail_str, sizeof(fail_str)); goto fail; } VS_ALIGNED_MALLOC(&tmp, tmp_size, 32); if (!tmp) { strcpy(fail_str, "error allocating temporary buffer"); err = 1; goto fail; } for (p = 0; p < 3; ++p) { src_plane[p] = vsapi->getReadPtr(src_frame, p); src_stride[p] = vsapi->getStride(src_frame, p); dst_plane[p] = vsapi->getWritePtr(dst_frame, p); dst_stride[p] = vsapi->getStride(dst_frame, p); } if ((err = zimg2_plane_filter_process(data->filter, tmp, src_plane, dst_plane, src_stride, dst_stride))) { zimg_get_last_error(fail_str, sizeof(fail_str)); goto fail; } props = vsapi->getFramePropsRW(dst_frame); vsapi->propSetInt(props, "_Matrix", data->matrix_out, paReplace); vsapi->propSetInt(props, "_Transfer", data->transfer_out, paReplace); vsapi->propSetInt(props, "_Primaries", data->primaries_out, paReplace); ret = dst_frame; dst_frame = 0; fail: vsapi->freeFrame(src_frame); vsapi->freeFrame(dst_frame); VS_ALIGNED_FREE(tmp); } if (err) vsapi->setFilterError(fail_str, frameCtx); return ret; }
static const VSFrameRef * VS_CC vs_depth_get_frame(int n, int activationReason, void **instanceData, void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi) { vs_depth_data *data = *instanceData; VSFrameRef *ret = 0; char fail_str[1024]; int err = 0; if (activationReason == arInitial) { vsapi->requestFrameFilter(n, data->node, frameCtx); } else { const VSFrameRef *src_frame = 0; VSFrameRef *dst_frame = 0; void *tmp = 0; const void *src_plane[3] = { 0 }; void *dst_plane[3] = { 0 }; ptrdiff_t src_stride[3] = { 0 }; ptrdiff_t dst_stride[3] = { 0 }; int width; int height; unsigned num_planes; size_t tmp_size; size_t tmp_size_uv; VSMap *props; unsigned p; width = data->vi.width; height = data->vi.height; num_planes = data->vi.format->numPlanes; src_frame = vsapi->getFrameFilter(n, data->node, frameCtx); dst_frame = vsapi->newVideoFrame(data->vi.format, width, height, src_frame, core); if ((err = zimg2_plane_filter_get_tmp_size(data->filter, &tmp_size))) { zimg_get_last_error(fail_str, sizeof(fail_str)); goto fail; } if (data->filter_uv) { if ((err = zimg2_plane_filter_get_tmp_size(data->filter_uv, &tmp_size_uv))) { zimg_get_last_error(fail_str, sizeof(fail_str)); goto fail; } } else { tmp_size_uv = 0; } VS_ALIGNED_MALLOC(&tmp, VSMAX(tmp_size, tmp_size_uv), 32); if (!tmp) { strcpy(fail_str, "error allocating temporary buffer"); err = 1; goto fail; } for (p = 0; p < num_planes; ++p) { const zimg_filter *filter; if ((p == 1 || p == 2) && data->filter_uv) filter = data->filter_uv; else filter = data->filter; src_plane[0] = vsapi->getReadPtr(src_frame, p); src_stride[0] = vsapi->getStride(src_frame, p); dst_plane[0] = vsapi->getWritePtr(dst_frame, p); dst_stride[0] = vsapi->getStride(dst_frame, p); if ((err = zimg2_plane_filter_process(filter, tmp, src_plane, dst_plane, src_stride, dst_stride))) { zimg_get_last_error(fail_str, sizeof(fail_str)); goto fail; } } props = vsapi->getFramePropsRW(dst_frame); vsapi->propSetInt(props, "_ColorRange", !data->fullrange, paReplace); ret = dst_frame; dst_frame = 0; fail: vsapi->freeFrame(src_frame); vsapi->freeFrame(dst_frame); VS_ALIGNED_FREE(tmp); } if (err) vsapi->setFilterError(fail_str, frameCtx); return ret; }
static const VSFrameRef * VS_CC vszimg_get_frame(int n, int activationReason, void **instanceData, void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi) { struct vszimg_data *data = *instanceData; struct vszimg_graph_data *graph_data = NULL; const VSFrameRef *src_frame = NULL; VSFrameRef *dst_frame = NULL; VSFrameRef *ret = NULL; void *tmp = NULL; char err_msg[1024]; int err_flag = 1; if (activationReason == arInitial) { vsapi->requestFrameFilter(n, data->node, frameCtx); } else if (activationReason == arAllFramesReady) { zimg_image_buffer_const src_buf = { ZIMG_API_VERSION }; zimg_image_buffer dst_buf = { { ZIMG_API_VERSION } }; zimg_image_format src_format; zimg_image_format dst_format; const VSFormat *src_vsformat; const VSFormat *dst_vsformat; const VSMap *src_props; VSMap *dst_props; size_t tmp_size; int p; zimg2_image_format_default(&src_format, ZIMG_API_VERSION); zimg2_image_format_default(&dst_format, ZIMG_API_VERSION); src_frame = vsapi->getFrameFilter(n, data->node, frameCtx); src_props = vsapi->getFramePropsRO(src_frame); src_vsformat = vsapi->getFrameFormat(src_frame); dst_vsformat = data->vi.format ? data->vi.format : src_vsformat; src_format.width = vsapi->getFrameWidth(src_frame, 0); src_format.height = vsapi->getFrameHeight(src_frame, 0); dst_format.width = data->vi.width ? (unsigned)data->vi.width : src_format.width; dst_format.height = data->vi.height ? (unsigned)data->vi.height : src_format.height; if (translate_vsformat(src_vsformat, &src_format, err_msg)) goto fail; if (translate_vsformat(dst_vsformat, &dst_format, err_msg)) goto fail; _vszimg_set_src_colorspace(data, &src_format); if (import_frame_props(vsapi, src_props, &src_format, err_msg)) goto fail; _vszimg_set_dst_colorspace(data, &src_format, &dst_format); if (!(graph_data = _vszimg_get_graph_data(data, &src_format, &dst_format, err_msg, sizeof(err_msg)))) goto fail; dst_frame = vsapi->newVideoFrame(dst_vsformat, dst_format.width, dst_format.height, src_frame, core); dst_props = vsapi->getFramePropsRW(dst_frame); for (p = 0; p < src_vsformat->numPlanes; ++p) { src_buf.data[p] = vsapi->getReadPtr(src_frame, p); src_buf.stride[p] = vsapi->getStride(src_frame, p); src_buf.mask[p] = -1; } for (p = 0; p < dst_vsformat->numPlanes; ++p) { dst_buf.m.data[p] = vsapi->getWritePtr(dst_frame, p); dst_buf.m.stride[p] = vsapi->getStride(dst_frame, p); dst_buf.m.mask[p] = -1; } if (zimg2_filter_graph_get_tmp_size(graph_data->graph, &tmp_size)) { format_zimg_error(err_msg, sizeof(err_msg)); goto fail; } VS_ALIGNED_MALLOC(&tmp, tmp_size, 64); if (!tmp) { sprintf(err_msg, "error allocating temporary buffer"); goto fail; } if (zimg2_filter_graph_process(graph_data->graph, &src_buf, &dst_buf, tmp, NULL, NULL, NULL, NULL)) { format_zimg_error(err_msg, sizeof(err_msg)); goto fail; } propagate_sar(vsapi, src_props, dst_props, &src_format, &dst_format); export_frame_props(vsapi, &dst_format, dst_props); ret = dst_frame; dst_frame = NULL; } err_flag = 0; fail: if (err_flag) vsapi->setFilterError(err_msg, frameCtx); _vszimg_release_graph_data(data, graph_data); vsapi->freeFrame(src_frame); vsapi->freeFrame(dst_frame); return ret; }