| 145 | } |
| 146 | |
| 147 | bool swscale::initialize(int flags) |
| 148 | { |
| 149 | if (this->context) { |
| 150 | return false; |
| 151 | } |
| 152 | if (source_size.first == 0 || source_size.second == 0 || source_format == AV_PIX_FMT_NONE || source_colorspace == AVCOL_SPC_UNSPECIFIED) { |
| 153 | throw std::invalid_argument("not all source parameters were set"); |
| 154 | } |
| 155 | if (target_size.first == 0 || target_size.second == 0 || target_format == AV_PIX_FMT_NONE || target_colorspace == AVCOL_SPC_UNSPECIFIED) { |
| 156 | throw std::invalid_argument("not all target parameters were set"); |
| 157 | } |
| 158 | |
| 159 | this->context = sws_getContext(static_cast<int>(source_size.first), static_cast<int>(source_size.second), source_format, static_cast<int>(target_size.first), static_cast<int>(target_size.second), target_format, flags, nullptr, nullptr, nullptr); |
| 160 | if (!this->context) { |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | sws_setColorspaceDetails(this->context, sws_getCoefficients(source_colorspace), source_full_range ? 1 : 0, sws_getCoefficients(target_colorspace), target_full_range ? 1 : 0, 1L << 16 | 0L, 1L << 16 | 0L, 1L << 16 | 0L); |
| 165 | |
| 166 | return true; |
| 167 | } |
| 168 | |
| 169 | bool swscale::finalize() |
| 170 | { |