Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -62,7 +62,7 @@ typedef struct ScanItem { · 61 unmodified lines | ||
| 62 | 62 | int found; |
| 63 | 63 | int white; |
| 64 | 64 | int black; |
| 65 | − uint64_t histogram[256]; | |
| 65 | + uint64_t *histogram; | |
| 66 | 66 | uint8_t byte[2]; |
| 67 | 67 | |
| 68 | 68 | CodeItem *code; |
| @@ -77,8 +77,13 @@ typedef struct ReadEIA608Context { · 8 unmodified lines | ||
| 77 | 77 | int chp; |
| 78 | 78 | int lp; |
| 79 | 79 | |
| 80 | + int depth; | |
| 81 | + int max; | |
| 80 | 82 | int nb_allocated; |
| 81 | 83 | ScanItem *scan; |
| 84 | + | |
| 85 | + void (*read_line[2])(AVFrame *in, int nb_line, | |
| 86 | + LineItem *line, int lp, int w); | |
| 82 | 87 | } ReadEIA608Context; |
| 83 | 88 | |
| 84 | 89 | #define OFFSET(x) offsetof(ReadEIA608Context, x) |
| @@ -98,13 +103,26 @@ AVFILTER_DEFINE_CLASS(readeia608); · 13 unmodified lines | ||
| 98 | 103 | static int query_formats(AVFilterContext *ctx) |
| 99 | 104 | { |
| 100 | 105 | static const enum AVPixelFormat pixel_fmts[] = { |
| 101 | − AV_PIX_FMT_GRAY8, | |
| 106 | + AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, | |
| 107 | + AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, | |
| 108 | + AV_PIX_FMT_GRAY16, | |
| 102 | 109 | AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, |
| 103 | 110 | AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, |
| 104 | 111 | AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, |
| 105 | 112 | AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, |
| 106 | 113 | AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, |
| 107 | 114 | AV_PIX_FMT_YUVJ411P, |
| 115 | + AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9, | |
| 116 | + AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, | |
| 117 | + AV_PIX_FMT_YUV440P10, | |
| 118 | + AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, | |
| 119 | + AV_PIX_FMT_YUV440P12, | |
| 120 | + AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV420P14, | |
| 121 | + AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, | |
| 122 | + AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, | |
| 123 | + AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA444P16, | |
| 124 | + AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA422P16, | |
| 125 | + AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16, | |
| 108 | 126 | AV_PIX_FMT_NONE |
| 109 | 127 | }; |
| 110 | 128 | AVFilterFormats *formats = ff_make_format_list(pixel_fmts); |
| @@ -142,11 +160,13 @@ static int config_filter(AVFilterContext *ctx, int start, int end) · 31 unmodified lines | ||
| 142 | 160 | for (int i = 0; i < s->nb_allocated; i++) { |
| 143 | 161 | ScanItem *scan = &s->scan[i]; |
| 144 | 162 | |
| 163 | + if (!scan->histogram) | |
| 164 | + scan->histogram = av_calloc(s->max + 1, sizeof(*scan->histogram)); | |
| 145 | 165 | if (!scan->line) |
| 146 | 166 | scan->line = av_calloc(size, sizeof(*scan->line)); |
| 147 | 167 | if (!scan->code) |
| 148 | 168 | scan->code = av_calloc(size, sizeof(*scan->code)); |
| 149 | − if (!scan->line || !scan->code) | |
| 169 | + if (!scan->line || !scan->code || !scan->histogram) | |
| 150 | 170 | return AVERROR(ENOMEM); |
| 151 | 171 | } |
| 152 | 172 | |
| @@ -156,17 +176,9 @@ static int config_filter(AVFilterContext *ctx, int start, int end) · 3 unmodified lines | ||
| 156 | 176 | return 0; |
| 157 | 177 | } |
| 158 | 178 | |
| 159 | −static int config_input(AVFilterLink *inlink) | |
| 160 | −{ | |
| 161 | − AVFilterContext *ctx = inlink->dst; | |
| 162 | − ReadEIA608Context *s = ctx->priv; | |
| 163 | − | |
| 164 | − return config_filter(ctx, s->start, s->end); | |
| 165 | −} | |
| 166 | − | |
| 167 | 179 | static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len) |
| 168 | 180 | { |
| 169 | − memset(scan->histogram, 0, sizeof(scan->histogram)); | |
| 181 | + memset(scan->histogram, 0, (s->max + 1) * sizeof(*scan->histogram)); | |
| 170 | 182 | |
| 171 | 183 | for (int i = LAG; i < len + LAG; i++) |
| 172 | 184 | scan->histogram[line[i].input]++; |
| @@ -174,18 +186,19 @@ static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem · 1 unmodified line | ||
| 174 | 186 | |
| 175 | 187 | static void find_black_and_white(ReadEIA608Context *s, ScanItem *scan) |
| 176 | 188 | { |
| 189 | + const int max = s->max; | |
| 177 | 190 | int start = 0, end = 0, middle; |
| 178 | 191 | int black = 0, white = 0; |
| 179 | 192 | int cnt; |
| 180 | 193 | |
| 181 | − for (int i = 0; i < 256; i++) { | |
| 194 | + for (int i = 0; i <= max; i++) { | |
| 182 | 195 | if (scan->histogram[i]) { |
| 183 | 196 | start = i; |
| 184 | 197 | break; |
| 185 | 198 | } |
| 186 | 199 | } |
| 187 | 200 | |
| 188 | − for (int i = 255; i >= 0; i--) { | |
| 201 | + for (int i = max; i >= 0; i--) { | |
| 189 | 202 | if (scan->histogram[i]) { |
| 190 | 203 | end = i; |
| 191 | 204 | break; |
| @@ -308,12 +321,54 @@ static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item) · 116 unmodified lines | ||
| 308 | 321 | av_log(ctx, AV_LOG_DEBUG, "\n"); |
| 309 | 322 | } |
| 310 | 323 | |
| 324 | +#define READ_LINE(type, name) \ | |
| 325 | +static void read_##name(AVFrame *in, int nb_line, LineItem *line, int lp, int w) \ | |
| 326 | +{ \ | |
| 327 | + const type *src = (const type *)(&in->data[0][nb_line * in->linesize[0]]);\ | |
| 328 | + \ | |
| 329 | + if (lp) { \ | |
| 330 | + for (int i = 0; i < w; i++) { \ | |
| 331 | + int a = FFMAX(i - 3, 0); \ | |
| 332 | + int b = FFMAX(i - 2, 0); \ | |
| 333 | + int c = FFMAX(i - 1, 0); \ | |
| 334 | + int d = FFMIN(i + 3, w-1); \ | |
| 335 | + int e = FFMIN(i + 2, w-1); \ | |
| 336 | + int f = FFMIN(i + 1, w-1); \ | |
| 337 | + \ | |
| 338 | + line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + \ | |
| 339 | + src[d] + src[e] + src[f] + 6) / 7; \ | |
| 340 | + } \ | |
| 341 | + } else { \ | |
| 342 | + for (int i = 0; i < w; i++) { \ | |
| 343 | + line[LAG + i].input = src[i]; \ | |
| 344 | + } \ | |
| 345 | + } \ | |
| 346 | +} | |
| 347 | + | |
| 348 | +READ_LINE(uint8_t, byte) | |
| 349 | +READ_LINE(uint16_t, word) | |
| 350 | + | |
| 351 | +static int config_input(AVFilterLink *inlink) | |
| 352 | +{ | |
| 353 | + AVFilterContext *ctx = inlink->dst; | |
| 354 | + ReadEIA608Context *s = ctx->priv; | |
| 355 | + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | |
| 356 | + | |
| 357 | + if (!desc) | |
| 358 | + return AVERROR_BUG; | |
| 359 | + s->depth = desc->comp[0].depth; | |
| 360 | + s->max = (1 << desc->comp[0].depth) - 1; | |
| 361 | + s->read_line[0] = read_byte; | |
| 362 | + s->read_line[1] = read_word; | |
| 363 | + | |
| 364 | + return config_filter(ctx, s->start, s->end); | |
| 365 | +} | |
| 366 | + | |
| 311 | 367 | static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line) |
| 312 | 368 | { |
| 313 | 369 | ReadEIA608Context *s = ctx->priv; |
| 314 | 370 | LineItem *line = scan->line; |
| 315 | 371 | int i, j, ch, len; |
| 316 | − const uint8_t *src; | |
| 317 | 372 | uint8_t codes[19] = { 0 }; |
| 318 | 373 | float bit_size = 0.f; |
| 319 | 374 | int parity; |
| @@ -322,23 +377,7 @@ static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int · 2 unmodified lines | ||
| 322 | 377 | scan->byte[0] = scan->byte[1] = 0; |
| 323 | 378 | scan->found = 0; |
| 324 | 379 | |
| 325 | − src = &in->data[0][nb_line * in->linesize[0]]; | |
| 326 | − if (s->lp) { | |
| 327 | − for (i = 0; i < w; i++) { | |
| 328 | − int a = FFMAX(i - 3, 0); | |
| 329 | − int b = FFMAX(i - 2, 0); | |
| 330 | − int c = FFMAX(i - 1, 0); | |
| 331 | − int d = FFMIN(i + 3, w-1); | |
| 332 | − int e = FFMIN(i + 2, w-1); | |
| 333 | − int f = FFMIN(i + 1, w-1); | |
| 334 | − | |
| 335 | − line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + src[d] + src[e] + src[f] + 6) / 7; | |
| 336 | − } | |
| 337 | − } else { | |
| 338 | − for (i = 0; i < w; i++) { | |
| 339 | − line[LAG + i].input = src[i]; | |
| 340 | − } | |
| 341 | − } | |
| 380 | + s->read_line[s->depth > 8](in, nb_line, line, s->lp, w); | |
| 342 | 381 | |
| 343 | 382 | build_histogram(s, scan, line, w); |
| 344 | 383 | find_black_and_white(s, scan); |
| @@ -471,6 +510,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 126 unmodified lines | ||
| 471 | 510 | for (int i = 0; i < s->nb_allocated; i++) { |
| 472 | 511 | ScanItem *scan = &s->scan[i]; |
| 473 | 512 | |
| 513 | + av_freep(&scan->histogram); | |
| 474 | 514 | av_freep(&scan->code); |
| 475 | 515 | av_freep(&scan->line); |
| 476 | 516 | } |