|
|
|
@ -192,12 +192,12 @@ static const uint8_t white_gbrp_color[4] = { 255, 255, 255, 255 }; |
|
|
|
|
|
|
|
|
|
static int config_input(AVFilterLink *inlink) |
|
|
|
|
{ |
|
|
|
|
HistogramContext *h = inlink->dst->priv; |
|
|
|
|
HistogramContext *s = inlink->dst->priv; |
|
|
|
|
|
|
|
|
|
h->desc = av_pix_fmt_desc_get(inlink->format); |
|
|
|
|
h->ncomp = h->desc->nb_components; |
|
|
|
|
h->histogram_size = 1 << h->desc->comp[0].depth; |
|
|
|
|
h->mult = h->histogram_size / 256; |
|
|
|
|
s->desc = av_pix_fmt_desc_get(inlink->format); |
|
|
|
|
s->ncomp = s->desc->nb_components; |
|
|
|
|
s->histogram_size = 1 << s->desc->comp[0].depth; |
|
|
|
|
s->mult = s->histogram_size / 256; |
|
|
|
|
|
|
|
|
|
switch (inlink->format) { |
|
|
|
|
case AV_PIX_FMT_GBRAP12: |
|
|
|
@ -207,21 +207,21 @@ static int config_input(AVFilterLink *inlink) |
|
|
|
|
case AV_PIX_FMT_GBRP9: |
|
|
|
|
case AV_PIX_FMT_GBRAP: |
|
|
|
|
case AV_PIX_FMT_GBRP: |
|
|
|
|
memcpy(h->bg_color, black_gbrp_color, 4); |
|
|
|
|
memcpy(h->fg_color, white_gbrp_color, 4); |
|
|
|
|
memcpy(s->bg_color, black_gbrp_color, 4); |
|
|
|
|
memcpy(s->fg_color, white_gbrp_color, 4); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
memcpy(h->bg_color, black_yuva_color, 4); |
|
|
|
|
memcpy(h->fg_color, white_yuva_color, 4); |
|
|
|
|
memcpy(s->bg_color, black_yuva_color, 4); |
|
|
|
|
memcpy(s->fg_color, white_yuva_color, 4); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
h->fg_color[3] = h->fgopacity * 255; |
|
|
|
|
h->bg_color[3] = h->bgopacity * 255; |
|
|
|
|
s->fg_color[3] = s->fgopacity * 255; |
|
|
|
|
s->bg_color[3] = s->bgopacity * 255; |
|
|
|
|
|
|
|
|
|
h->planeheight[1] = h->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, h->desc->log2_chroma_h); |
|
|
|
|
h->planeheight[0] = h->planeheight[3] = inlink->h; |
|
|
|
|
h->planewidth[1] = h->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, h->desc->log2_chroma_w); |
|
|
|
|
h->planewidth[0] = h->planewidth[3] = inlink->w; |
|
|
|
|
s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); |
|
|
|
|
s->planeheight[0] = s->planeheight[3] = inlink->h; |
|
|
|
|
s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, s->desc->log2_chroma_w); |
|
|
|
|
s->planewidth[0] = s->planewidth[3] = inlink->w; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -229,18 +229,18 @@ static int config_input(AVFilterLink *inlink) |
|
|
|
|
static int config_output(AVFilterLink *outlink) |
|
|
|
|
{ |
|
|
|
|
AVFilterContext *ctx = outlink->src; |
|
|
|
|
HistogramContext *h = ctx->priv; |
|
|
|
|
HistogramContext *s = ctx->priv; |
|
|
|
|
int ncomp = 0, i; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < h->ncomp; i++) { |
|
|
|
|
if ((1 << i) & h->components) |
|
|
|
|
for (i = 0; i < s->ncomp; i++) { |
|
|
|
|
if ((1 << i) & s->components) |
|
|
|
|
ncomp++; |
|
|
|
|
} |
|
|
|
|
outlink->w = h->histogram_size * FFMAX(ncomp * (h->display_mode == 1), 1); |
|
|
|
|
outlink->h = (h->level_height + h->scale_height) * FFMAX(ncomp * (h->display_mode == 2), 1); |
|
|
|
|
outlink->w = s->histogram_size * FFMAX(ncomp * (s->display_mode == 1), 1); |
|
|
|
|
outlink->h = (s->level_height + s->scale_height) * FFMAX(ncomp * (s->display_mode == 2), 1); |
|
|
|
|
|
|
|
|
|
h->odesc = av_pix_fmt_desc_get(outlink->format); |
|
|
|
|
h->dncomp = h->odesc->nb_components; |
|
|
|
|
s->odesc = av_pix_fmt_desc_get(outlink->format); |
|
|
|
|
s->dncomp = s->odesc->nb_components; |
|
|
|
|
outlink->sample_aspect_ratio = (AVRational){1,1}; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
@ -248,7 +248,7 @@ static int config_output(AVFilterLink *outlink) |
|
|
|
|
|
|
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
|
{ |
|
|
|
|
HistogramContext *h = inlink->dst->priv; |
|
|
|
|
HistogramContext *s = inlink->dst->priv; |
|
|
|
|
AVFilterContext *ctx = inlink->dst; |
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0]; |
|
|
|
|
AVFrame *out; |
|
|
|
@ -264,92 +264,92 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
|
|
|
|
|
|
|
|
|
for (k = 0; k < 4 && out->data[k]; k++) { |
|
|
|
|
const int is_chroma = (k == 1 || k == 2); |
|
|
|
|
const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? h->odesc->log2_chroma_h : 0)); |
|
|
|
|
const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? h->odesc->log2_chroma_w : 0)); |
|
|
|
|
const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? s->odesc->log2_chroma_h : 0)); |
|
|
|
|
const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? s->odesc->log2_chroma_w : 0)); |
|
|
|
|
|
|
|
|
|
if (h->histogram_size <= 256) { |
|
|
|
|
if (s->histogram_size <= 256) { |
|
|
|
|
for (i = 0; i < dst_h ; i++) |
|
|
|
|
memset(out->data[h->odesc->comp[k].plane] + |
|
|
|
|
i * out->linesize[h->odesc->comp[k].plane], |
|
|
|
|
h->bg_color[k], dst_w); |
|
|
|
|
memset(out->data[s->odesc->comp[k].plane] + |
|
|
|
|
i * out->linesize[s->odesc->comp[k].plane], |
|
|
|
|
s->bg_color[k], dst_w); |
|
|
|
|
} else { |
|
|
|
|
const int mult = h->mult; |
|
|
|
|
const int mult = s->mult; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < dst_h ; i++) |
|
|
|
|
for (j = 0; j < dst_w; j++) |
|
|
|
|
AV_WN16(out->data[h->odesc->comp[k].plane] + |
|
|
|
|
i * out->linesize[h->odesc->comp[k].plane] + j * 2, |
|
|
|
|
h->bg_color[k] * mult); |
|
|
|
|
AV_WN16(out->data[s->odesc->comp[k].plane] + |
|
|
|
|
i * out->linesize[s->odesc->comp[k].plane] + j * 2, |
|
|
|
|
s->bg_color[k] * mult); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (m = 0, k = 0; k < h->ncomp; k++) { |
|
|
|
|
const int p = h->desc->comp[k].plane; |
|
|
|
|
const int height = h->planeheight[p]; |
|
|
|
|
const int width = h->planewidth[p]; |
|
|
|
|
for (m = 0, k = 0; k < s->ncomp; k++) { |
|
|
|
|
const int p = s->desc->comp[k].plane; |
|
|
|
|
const int height = s->planeheight[p]; |
|
|
|
|
const int width = s->planewidth[p]; |
|
|
|
|
double max_hval_log; |
|
|
|
|
unsigned max_hval = 0; |
|
|
|
|
int start, startx; |
|
|
|
|
|
|
|
|
|
if (!((1 << k) & h->components)) |
|
|
|
|
if (!((1 << k) & s->components)) |
|
|
|
|
continue; |
|
|
|
|
startx = m * h->histogram_size * (h->display_mode == 1); |
|
|
|
|
start = m++ * (h->level_height + h->scale_height) * (h->display_mode == 2); |
|
|
|
|
startx = m * s->histogram_size * (s->display_mode == 1); |
|
|
|
|
start = m++ * (s->level_height + s->scale_height) * (s->display_mode == 2); |
|
|
|
|
|
|
|
|
|
if (h->histogram_size <= 256) { |
|
|
|
|
if (s->histogram_size <= 256) { |
|
|
|
|
for (i = 0; i < height; i++) { |
|
|
|
|
const uint8_t *src = in->data[p] + i * in->linesize[p]; |
|
|
|
|
for (j = 0; j < width; j++) |
|
|
|
|
h->histogram[src[j]]++; |
|
|
|
|
s->histogram[src[j]]++; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for (i = 0; i < height; i++) { |
|
|
|
|
const uint16_t *src = (const uint16_t *)(in->data[p] + i * in->linesize[p]); |
|
|
|
|
for (j = 0; j < width; j++) |
|
|
|
|
h->histogram[src[j]]++; |
|
|
|
|
s->histogram[src[j]]++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < h->histogram_size; i++) |
|
|
|
|
max_hval = FFMAX(max_hval, h->histogram[i]); |
|
|
|
|
for (i = 0; i < s->histogram_size; i++) |
|
|
|
|
max_hval = FFMAX(max_hval, s->histogram[i]); |
|
|
|
|
max_hval_log = log2(max_hval + 1); |
|
|
|
|
|
|
|
|
|
for (i = 0; i < h->histogram_size; i++) { |
|
|
|
|
for (i = 0; i < s->histogram_size; i++) { |
|
|
|
|
int col_height; |
|
|
|
|
|
|
|
|
|
if (h->levels_mode) |
|
|
|
|
col_height = lrint(h->level_height * (1. - (log2(h->histogram[i] + 1) / max_hval_log))); |
|
|
|
|
if (s->levels_mode) |
|
|
|
|
col_height = lrint(s->level_height * (1. - (log2(s->histogram[i] + 1) / max_hval_log))); |
|
|
|
|
else |
|
|
|
|
col_height = h->level_height - (h->histogram[i] * (int64_t)h->level_height + max_hval - 1) / max_hval; |
|
|
|
|
col_height = s->level_height - (s->histogram[i] * (int64_t)s->level_height + max_hval - 1) / max_hval; |
|
|
|
|
|
|
|
|
|
if (h->histogram_size <= 256) { |
|
|
|
|
for (j = h->level_height - 1; j >= col_height; j--) { |
|
|
|
|
if (h->display_mode) { |
|
|
|
|
for (l = 0; l < h->dncomp; l++) |
|
|
|
|
out->data[l][(j + start) * out->linesize[l] + startx + i] = h->fg_color[l]; |
|
|
|
|
if (s->histogram_size <= 256) { |
|
|
|
|
for (j = s->level_height - 1; j >= col_height; j--) { |
|
|
|
|
if (s->display_mode) { |
|
|
|
|
for (l = 0; l < s->dncomp; l++) |
|
|
|
|
out->data[l][(j + start) * out->linesize[l] + startx + i] = s->fg_color[l]; |
|
|
|
|
} else { |
|
|
|
|
out->data[p][(j + start) * out->linesize[p] + startx + i] = 255; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--) |
|
|
|
|
for (j = s->level_height + s->scale_height - 1; j >= s->level_height; j--) |
|
|
|
|
out->data[p][(j + start) * out->linesize[p] + startx + i] = i; |
|
|
|
|
} else { |
|
|
|
|
const int mult = h->mult; |
|
|
|
|
const int mult = s->mult; |
|
|
|
|
|
|
|
|
|
for (j = h->level_height - 1; j >= col_height; j--) { |
|
|
|
|
if (h->display_mode) { |
|
|
|
|
for (l = 0; l < h->dncomp; l++) |
|
|
|
|
AV_WN16(out->data[l] + (j + start) * out->linesize[l] + startx * 2 + i * 2, h->fg_color[l] * mult); |
|
|
|
|
for (j = s->level_height - 1; j >= col_height; j--) { |
|
|
|
|
if (s->display_mode) { |
|
|
|
|
for (l = 0; l < s->dncomp; l++) |
|
|
|
|
AV_WN16(out->data[l] + (j + start) * out->linesize[l] + startx * 2 + i * 2, s->fg_color[l] * mult); |
|
|
|
|
} else { |
|
|
|
|
AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, 255 * mult); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--) |
|
|
|
|
for (j = s->level_height + s->scale_height - 1; j >= s->level_height; j--) |
|
|
|
|
AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
memset(h->histogram, 0, h->histogram_size * sizeof(unsigned)); |
|
|
|
|
memset(s->histogram, 0, s->histogram_size * sizeof(unsigned)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
av_frame_free(&in); |
|
|
|
|