| 179 | } \ |
| 180 | |
| 181 | static int unsharp_init(hb_filter_object_t *filter, |
| 182 | hb_filter_init_t *init) |
| 183 | { |
| 184 | filter->private_data = calloc(sizeof(struct hb_filter_private_s), 1); |
| 185 | if (filter->private_data == NULL) |
| 186 | { |
| 187 | hb_error("Unsharp calloc failed"); |
| 188 | return -1; |
| 189 | } |
| 190 | hb_filter_private_t * pv = filter->private_data; |
| 191 | |
| 192 | pv->input = *init; |
| 193 | |
| 194 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(init->pix_fmt); |
| 195 | pv->depth = desc->comp[0].depth; |
| 196 | |
| 197 | // Mark parameters unset |
| 198 | for (int c = 0; c < 3; c++) |
| 199 | { |
| 200 | pv->plane_ctx[c].strength = -1; |
| 201 | pv->plane_ctx[c].size = -1; |
| 202 | } |
| 203 | |
| 204 | // Read user parameters |
| 205 | if (filter->settings != NULL) |
| 206 | { |
| 207 | hb_dict_t * dict = filter->settings; |
| 208 | hb_dict_extract_double(&pv->plane_ctx[0].strength, dict, "y-strength"); |
| 209 | hb_dict_extract_int(&pv->plane_ctx[0].size, dict, "y-size"); |
| 210 | |
| 211 | hb_dict_extract_double(&pv->plane_ctx[1].strength, dict, "cb-strength"); |
| 212 | hb_dict_extract_int(&pv->plane_ctx[1].size, dict, "cb-size"); |
| 213 | |
| 214 | hb_dict_extract_double(&pv->plane_ctx[2].strength, dict, "cr-strength"); |
| 215 | hb_dict_extract_int(&pv->plane_ctx[2].size, dict, "cr-size"); |
| 216 | } |
| 217 | |
| 218 | // Cascade values |
| 219 | // Cr not set; inherit Cb. Cb not set; inherit Y. Y not set; defaults. |
| 220 | for (int c = 1; c < 3; c++) |
| 221 | { |
| 222 | unsharp_plane_context_t * prev_ctx = &pv->plane_ctx[c - 1]; |
| 223 | unsharp_plane_context_t * ctx = &pv->plane_ctx[c]; |
| 224 | |
| 225 | if (ctx->strength == -1) ctx->strength = prev_ctx->strength; |
| 226 | if (ctx->size == -1) ctx->size = prev_ctx->size; |
| 227 | } |
| 228 | |
| 229 | for (int c = 0; c < 3; c++) |
| 230 | { |
| 231 | unsharp_plane_context_t * ctx = &pv->plane_ctx[c]; |
| 232 | |
| 233 | ctx->width = init->geometry.width; |
| 234 | ctx->pix_fmt = init->pix_fmt; |
| 235 | ctx->bps = pv->depth > 8 ? 2 : 1; |
| 236 | ctx->max_value = (1 << pv->depth) - 1; |
| 237 | |
| 238 | // Replace unset values with defaults |
nothing calls this directly
no test coverage detected