예제 #1
0
void zimg2_resize_params_default(zimg_resize_params *ptr, unsigned version)
{
	assert(ptr);
	API_VERSION_ASSERT(version);

	if (version >= 2) {
		ptr->version = version;

		ptr->src_width = 0;
		ptr->src_height = 0;
		ptr->dst_width = 0;
		ptr->dst_height = 0;

		ptr->pixel_type = -1;
		ptr->depth = 0;

		ptr->shift_w = 0;
		ptr->shift_h = 0;
		ptr->subwidth = NAN;
		ptr->subheight = NAN;

		ptr->filter_type = ZIMG_RESIZE_POINT;
		ptr->filter_param_a = NAN;
		ptr->filter_param_b = NAN;
	}
}
예제 #2
0
파일: zimg.cpp 프로젝트: theomission/zimg
void zimg_image_format_default(zimg_image_format *ptr, unsigned version)
{
    _zassert_d(ptr, "null pointer");
    API_VERSION_ASSERT(version);

    ptr->version = version;

    if (version >= API_VERSION_2_0) {
        ptr->width = 0;
        ptr->height = 0;
        ptr->pixel_type = (zimg_pixel_type_e)-1;

        ptr->subsample_w = 0;
        ptr->subsample_h = 0;

        ptr->color_family = ZIMG_COLOR_GREY;
        ptr->matrix_coefficients = ZIMG_MATRIX_UNSPECIFIED;
        ptr->transfer_characteristics = ZIMG_TRANSFER_UNSPECIFIED;
        ptr->color_primaries = ZIMG_PRIMARIES_UNSPECIFIED;

        ptr->depth = 0;
        ptr->pixel_range = ZIMG_RANGE_LIMITED;

        ptr->field_parity = ZIMG_FIELD_PROGRESSIVE;
        ptr->chroma_location = ZIMG_CHROMA_LEFT;
    }
}
예제 #3
0
void zimg2_colorspace_params_default(zimg_colorspace_params *ptr, unsigned version)
{
	assert(ptr);
	API_VERSION_ASSERT(version);

	if (version >= 2) {
		ptr->version = version;

		ptr->width = 0;
		ptr->height = 0;

		ptr->matrix_in = 2;
		ptr->transfer_in = 2;
		ptr->primaries_in = 2;

		ptr->matrix_out = 2;
		ptr->transfer_out = 2;
		ptr->primaries_out = 2;

		ptr->pixel_type = -1;
		ptr->depth = 0;
		ptr->range_in = 0;
		ptr->range_out = 0;
	}
}
예제 #4
0
zimg_filter *zimg2_depth_create(const zimg_depth_params *params)
{
	assert(params);
	API_VERSION_ASSERT(params->version);

	try {
		zimg::PixelFormat pixel_in{};
		zimg::PixelFormat pixel_out{};
		zimg::depth::DitherType dither = zimg::depth::DitherType::DITHER_NONE;
		unsigned width = 0;
		unsigned height = 0;

		if (params->version >= 2) {
			width = params->width;
			height = params->height;
			dither = translate_dither(params->dither_type);

			pixel_in.type = translate_pixel_type(params->pixel_in);
			pixel_in.chroma = !!params->chroma;

			if (pixel_in.type == zimg::PixelType::BYTE || pixel_in.type == zimg::PixelType::WORD) {
				pixel_in.depth = params->depth_in;
				pixel_in.fullrange = translate_pixel_range(params->range_in);
			}

			pixel_out.type = translate_pixel_type(params->pixel_out);
			pixel_out.chroma = !!params->chroma;

			if (pixel_out.type == zimg::PixelType::BYTE || pixel_out.type == zimg::PixelType::WORD) {
				pixel_out.depth = params->depth_out;
				pixel_out.fullrange = translate_pixel_range(params->range_out);
			}
		}

		return zimg::depth::create_depth2(dither, width, height, pixel_in, pixel_out, g_cpu_type);
	} catch (const zimg::ZimgException &e) {
		handle_exception(e);
		return nullptr;
	} catch (const std::bad_alloc &e) {
		handle_exception(e);
		return nullptr;
	}
}
예제 #5
0
파일: zimg.cpp 프로젝트: theomission/zimg
void zimg_graph_builder_params_default(zimg_graph_builder_params *ptr, unsigned version)
{
    _zassert_d(ptr, "null pointer");
    API_VERSION_ASSERT(version);

    ptr->version = version;

    if (version >= API_VERSION_2_0) {
        ptr->resample_filter = ZIMG_RESIZE_BICUBIC;
        ptr->filter_param_a = NAN;
        ptr->filter_param_b = NAN;

        ptr->resample_filter_uv = ZIMG_RESIZE_BILINEAR;
        ptr->filter_param_a_uv = NAN;
        ptr->filter_param_b_uv = NAN;

        ptr->dither_type = ZIMG_DITHER_NONE;

        ptr->cpu_type = ZIMG_CPU_AUTO;
    }
}
예제 #6
0
void zimg2_depth_params_default(zimg_depth_params *ptr, unsigned version)
{
	assert(ptr);
	API_VERSION_ASSERT(version);

	if (version >= 2) {
		ptr->version = version;

		ptr->width = 0;
		ptr->height = 0;

		ptr->dither_type = ZIMG_DITHER_NONE;
		ptr->chroma = 0;

		ptr->pixel_in = -1;
		ptr->depth_in = 0;
		ptr->range_in = ZIMG_RANGE_LIMITED;

		ptr->pixel_out = -1;
		ptr->depth_out = 0;
		ptr->range_out = ZIMG_RANGE_LIMITED;
	}
}
예제 #7
0
zimg_filter *zimg2_resize_create(const zimg_resize_params *params)
{
	assert(params);
	API_VERSION_ASSERT(params->version);

	try {
		std::unique_ptr<zimg::resize::Filter> filter;

		zimg::PixelType pixel_type{};
		unsigned depth = 0;

		int src_width = 0;
		int src_height = 0;
		int dst_width = 0;
		int dst_height = 0;

		double shift_w = 0;
		double shift_h = 0;

		double subwidth = NAN;
		double subheight = NAN;

		if (params->version >= 2) {
			src_width = params->src_width;
			src_height = params->src_height;
			dst_width = params->dst_width;
			dst_height = params->dst_height;

			pixel_type = translate_pixel_type(params->pixel_type);
			depth = params->depth;

			shift_w = params->shift_w;
			shift_h = params->shift_h;

			subwidth = std::isnan(params->subwidth) ? src_width : params->subwidth;
			subheight = std::isnan(params->subheight) ? src_height : params->subheight;

			filter.reset(translate_resize_filter(params->filter_type, params->filter_param_a, params->filter_param_b));
		}

		if (pixel_type == zimg::PixelType::BYTE || pixel_type == zimg::PixelType::HALF) {
			zimg::PixelType working_pixel_type = pixel_type == zimg::PixelType::BYTE ? zimg::PixelType::WORD : zimg::PixelType::FLOAT;
			zimg::PixelFormat inout_format = zimg::default_pixel_format(pixel_type);
			zimg::PixelFormat working_format = zimg::default_pixel_format(working_pixel_type);

			std::unique_ptr<zimg::IZimgFilter> resize_filter;
			std::unique_ptr<zimg::IZimgFilter> adapter_in;
			std::unique_ptr<zimg::IZimgFilter> adapter_out;
			std::unique_ptr<zimg::IZimgFilter> pair_filter1;
			std::unique_ptr<zimg::IZimgFilter> pair_filter2;

			resize_filter.reset(zimg::resize::create_resize2(*filter, working_pixel_type, working_format.depth, src_width, src_height, dst_width, dst_height, shift_w, shift_h, subwidth, subheight, g_cpu_type));

			adapter_in.reset(zimg::depth::create_depth2(zimg::depth::DitherType::DITHER_NONE, src_width, src_height, inout_format, working_format, g_cpu_type));
			adapter_out.reset(zimg::depth::create_depth2(zimg::depth::DitherType::DITHER_NONE, dst_width, dst_height, working_format, inout_format, g_cpu_type));

			pair_filter1.reset(new zimg::PairFilter{ adapter_in.get(), resize_filter.get() });
			adapter_in.release();
			resize_filter.release();

			pair_filter2.reset(new zimg::PairFilter{ pair_filter1.get(), adapter_out.get() });
			pair_filter1.release();
			adapter_out.release();

			return pair_filter2.release();
		} else {
			return zimg::resize::create_resize2(*filter, pixel_type, depth, src_width, src_height, dst_width, dst_height, shift_w, shift_h, subwidth, subheight, g_cpu_type);
		}
	} catch (const zimg::ZimgException &e) {
		handle_exception(e);
		return nullptr;
	} catch (const std::bad_alloc &e) {
		handle_exception(e);
		return nullptr;
	}
}
예제 #8
0
zimg_filter *zimg2_colorspace_create(const zimg_colorspace_params *params)
{
	assert(params);
	API_VERSION_ASSERT(params->version);

	try {
		std::unique_ptr<zimg::IZimgFilter> colorspace_filter;

		zimg::colorspace::ColorspaceDefinition csp_in{};
		zimg::colorspace::ColorspaceDefinition csp_out{};

		zimg::PixelType pixel_type{};
		unsigned width = 0;
		unsigned height = 0;
		unsigned depth = 0;
		bool range_in = false;
		bool range_out = false;

		if (params->version >= 2) {
			width = params->width;
			height = params->height;

			csp_in.matrix = translate_matrix(params->matrix_in);
			csp_in.transfer = translate_transfer(params->transfer_in);
			csp_in.primaries = translate_primaries(params->primaries_in);

			csp_out.matrix = translate_matrix(params->matrix_out);
			csp_out.transfer = translate_transfer(params->transfer_out);
			csp_out.primaries = translate_primaries(params->primaries_out);

			pixel_type = translate_pixel_type(params->pixel_type);
			depth = params->depth;
			range_in = translate_pixel_range(params->range_in);
			range_out = translate_pixel_range(params->range_out);
		}

		colorspace_filter.reset(new zimg::colorspace::ColorspaceConversion2{ width, height, csp_in, csp_out, g_cpu_type });

		if (pixel_type != zimg::PixelType::FLOAT) {
			std::unique_ptr<zimg::IZimgFilter> to_float;
			std::unique_ptr<zimg::IZimgFilter> from_float;

			std::unique_ptr<zimg::IZimgFilter> pair_filter1;
			std::unique_ptr<zimg::IZimgFilter> pair_filter2;

			zimg::PixelFormat pixel_format = zimg::default_pixel_format(pixel_type);
			zimg::PixelFormat float_format = zimg::default_pixel_format(zimg::PixelType::FLOAT);
			bool yuv_in = csp_in.matrix != zimg::colorspace::MatrixCoefficients::MATRIX_RGB;
			bool yuv_out = csp_out.matrix != zimg::colorspace::MatrixCoefficients::MATRIX_RGB;

			pixel_format.depth = depth;

			pixel_format.fullrange = range_in;
			to_float.reset(create_depth_color_filter(width, height, pixel_format, float_format, yuv_in));

			pixel_format.fullrange = range_out;
			from_float.reset(create_depth_color_filter(width, height, float_format, pixel_format, yuv_out));

			pair_filter1.reset(new zimg::PairFilter{ to_float.get(), colorspace_filter.get() });
			to_float.release();
			colorspace_filter.release();

			pair_filter2.reset(new zimg::PairFilter{ pair_filter1.get(), from_float.get() });
			pair_filter1.release();
			from_float.release();

			return pair_filter2.release();
		} else {
			return colorspace_filter.release();
		}
	} catch (const zimg::ZimgException &e) {
		handle_exception(e);
		return nullptr;
	} catch (const std::bad_alloc &e) {
		handle_exception(e);
		return nullptr;
	}
}