ResizeConversion::ResizeConversion(unsigned src_width, unsigned src_height, PixelType type) : src_width{ src_width }, src_height{ src_height }, type{ type }, depth{ pixel_depth(type) }, filter{}, dst_width{ src_width }, dst_height{ src_height }, shift_w{}, shift_h{}, subwidth{ (double)src_width }, subheight{ (double)src_height }, cpu{ CPUClass::CPU_NONE } { }
void validate_state(const GraphBuilder::state &state) { if (!state.width || !state.height) throw error::ZeroImageSize{ "image dimensions must be non-zero" }; if (is_greyscale(state)) { if (state.subsample_w || state.subsample_h) throw error::GreyscaleSubsampling{ "cannot subsample greyscale image" }; if (state.colorspace.matrix == zimg::colorspace::MatrixCoefficients::MATRIX_RGB) throw error::ColorFamilyMismatch{ "GREY color family cannot be RGB" }; } if (is_rgb(state)) { if (state.subsample_w || state.subsample_h) throw zimg::error::UnsupportedSubsampling{ "subsampled RGB image not supported" }; if (state.colorspace.matrix != zimg::colorspace::MatrixCoefficients::MATRIX_UNSPECIFIED && state.colorspace.matrix != zimg::colorspace::MatrixCoefficients::MATRIX_RGB) throw error::ColorFamilyMismatch{ "RGB color family cannot be YUV" }; } if (is_yuv(state)) { if (state.colorspace.matrix == zimg::colorspace::MatrixCoefficients::MATRIX_RGB) throw error::ColorFamilyMismatch{ "YUV color family cannot be RGB" }; } if (state.subsample_h > 1 && state.parity != GraphBuilder::FieldParity::FIELD_PROGRESSIVE) throw error::UnsupportedSubsampling{ "vertical subsampling greater than 2x is not supported" }; if (state.subsample_w > 2 || state.subsample_h > 2) throw error::UnsupportedSubsampling{ "subsampling greater than 4x is not supported" }; if (state.width % (1 << state.subsample_w) || state.height % (1 << state.subsample_h)) throw error::ImageNotDivislbe{ "image dimensions must be divisible by subsampling factor" }; if (state.depth > pixel_depth(state.type)) throw error::BitDepthOverflow{ "bit depth exceeds limits of type" }; if (!state.fullrange && state.depth < 8) throw error::BitDepthOverflow{ "bit depth must be at least 8 for limited range" }; }