History

avfilter/vf_histogram: use the name 's' for the pointer to the private context

This is consistent across filters.

Paul B Mahol committed 6 years ago

Commit b5f0cea1 parent 4fa2d5a1 file · +62 −62Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_histogram.c+62−62
@@ -192,12 +192,12 @@ static const uint8_t white_gbrp_color[4] = { 255, 255, 255, 255 }; · 191 unmodified lines
192 192
193static int config_input(AVFilterLink *inlink)193static int config_input(AVFilterLink *inlink)
194{194{
195 HistogramContext *h = inlink->dst->priv;195 HistogramContext *s = inlink->dst->priv;
196 196
197 h->desc = av_pix_fmt_desc_get(inlink->format);197 s->desc = av_pix_fmt_desc_get(inlink->format);
198 h->ncomp = h->desc->nb_components;198 s->ncomp = s->desc->nb_components;
199 h->histogram_size = 1 << h->desc->comp[0].depth;199 s->histogram_size = 1 << s->desc->comp[0].depth;
200 h->mult = h->histogram_size / 256;200 s->mult = s->histogram_size / 256;
201 201
202 switch (inlink->format) {202 switch (inlink->format) {
203 case AV_PIX_FMT_GBRAP12:203 case AV_PIX_FMT_GBRAP12:
@@ -207,21 +207,21 @@ static int config_input(AVFilterLink *inlink) · 3 unmodified lines
207 case AV_PIX_FMT_GBRP9:207 case AV_PIX_FMT_GBRP9:
208 case AV_PIX_FMT_GBRAP:208 case AV_PIX_FMT_GBRAP:
209 case AV_PIX_FMT_GBRP:209 case AV_PIX_FMT_GBRP:
210 memcpy(h->bg_color, black_gbrp_color, 4);210 memcpy(s->bg_color, black_gbrp_color, 4);
211 memcpy(h->fg_color, white_gbrp_color, 4);211 memcpy(s->fg_color, white_gbrp_color, 4);
212 break;212 break;
213 default:213 default:
214 memcpy(h->bg_color, black_yuva_color, 4);214 memcpy(s->bg_color, black_yuva_color, 4);
215 memcpy(h->fg_color, white_yuva_color, 4);215 memcpy(s->fg_color, white_yuva_color, 4);
216 }216 }
217 217
218 h->fg_color[3] = h->fgopacity * 255;218 s->fg_color[3] = s->fgopacity * 255;
219 h->bg_color[3] = h->bgopacity * 255;219 s->bg_color[3] = s->bgopacity * 255;
220 220
221 h->planeheight[1] = h->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, h->desc->log2_chroma_h);221 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h);
222 h->planeheight[0] = h->planeheight[3] = inlink->h;222 s->planeheight[0] = s->planeheight[3] = inlink->h;
223 h->planewidth[1] = h->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, h->desc->log2_chroma_w);223 s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, s->desc->log2_chroma_w);
224 h->planewidth[0] = h->planewidth[3] = inlink->w;224 s->planewidth[0] = s->planewidth[3] = inlink->w;
225 225
226 return 0;226 return 0;
227}227}
@@ -229,18 +229,18 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line
229static int config_output(AVFilterLink *outlink)229static int config_output(AVFilterLink *outlink)
230{230{
231 AVFilterContext *ctx = outlink->src;231 AVFilterContext *ctx = outlink->src;
232 HistogramContext *h = ctx->priv;232 HistogramContext *s = ctx->priv;
233 int ncomp = 0, i;233 int ncomp = 0, i;
234 234
235 for (i = 0; i < h->ncomp; i++) {235 for (i = 0; i < s->ncomp; i++) {
236 if ((1 << i) & h->components)236 if ((1 << i) & s->components)
237 ncomp++;237 ncomp++;
238 }238 }
239 outlink->w = h->histogram_size * FFMAX(ncomp * (h->display_mode == 1), 1);239 outlink->w = s->histogram_size * FFMAX(ncomp * (s->display_mode == 1), 1);
240 outlink->h = (h->level_height + h->scale_height) * FFMAX(ncomp * (h->display_mode == 2), 1);240 outlink->h = (s->level_height + s->scale_height) * FFMAX(ncomp * (s->display_mode == 2), 1);
241 241
242 h->odesc = av_pix_fmt_desc_get(outlink->format);242 s->odesc = av_pix_fmt_desc_get(outlink->format);
243 h->dncomp = h->odesc->nb_components;243 s->dncomp = s->odesc->nb_components;
244 outlink->sample_aspect_ratio = (AVRational){1,1};244 outlink->sample_aspect_ratio = (AVRational){1,1};
245 245
246 return 0;246 return 0;
@@ -248,7 +248,7 @@ static int config_output(AVFilterLink *outlink) · 1 unmodified line
248 248
249static int filter_frame(AVFilterLink *inlink, AVFrame *in)249static int filter_frame(AVFilterLink *inlink, AVFrame *in)
250{250{
251 HistogramContext *h = inlink->dst->priv;251 HistogramContext *s = inlink->dst->priv;
252 AVFilterContext *ctx = inlink->dst;252 AVFilterContext *ctx = inlink->dst;
253 AVFilterLink *outlink = ctx->outputs[0];253 AVFilterLink *outlink = ctx->outputs[0];
254 AVFrame *out;254 AVFrame *out;
@@ -264,92 +264,92 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 9 unmodified lines
264 264
265 for (k = 0; k < 4 && out->data[k]; k++) {265 for (k = 0; k < 4 && out->data[k]; k++) {
266 const int is_chroma = (k == 1 || k == 2);266 const int is_chroma = (k == 1 || k == 2);
267 const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? h->odesc->log2_chroma_h : 0));267 const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? s->odesc->log2_chroma_h : 0));
268 const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? h->odesc->log2_chroma_w : 0));268 const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? s->odesc->log2_chroma_w : 0));
269 269
270 if (h->histogram_size <= 256) {270 if (s->histogram_size <= 256) {
271 for (i = 0; i < dst_h ; i++)271 for (i = 0; i < dst_h ; i++)
272 memset(out->data[h->odesc->comp[k].plane] +272 memset(out->data[s->odesc->comp[k].plane] +
273 i * out->linesize[h->odesc->comp[k].plane],273 i * out->linesize[s->odesc->comp[k].plane],
274 h->bg_color[k], dst_w);274 s->bg_color[k], dst_w);
275 } else {275 } else {
276 const int mult = h->mult;276 const int mult = s->mult;
277 277
278 for (i = 0; i < dst_h ; i++)278 for (i = 0; i < dst_h ; i++)
279 for (j = 0; j < dst_w; j++)279 for (j = 0; j < dst_w; j++)
280 AV_WN16(out->data[h->odesc->comp[k].plane] +280 AV_WN16(out->data[s->odesc->comp[k].plane] +
281 i * out->linesize[h->odesc->comp[k].plane] + j * 2,281 i * out->linesize[s->odesc->comp[k].plane] + j * 2,
282 h->bg_color[k] * mult);282 s->bg_color[k] * mult);
283 }283 }
284 }284 }
285 285
286 for (m = 0, k = 0; k < h->ncomp; k++) {286 for (m = 0, k = 0; k < s->ncomp; k++) {
287 const int p = h->desc->comp[k].plane;287 const int p = s->desc->comp[k].plane;
288 const int height = h->planeheight[p];288 const int height = s->planeheight[p];
289 const int width = h->planewidth[p];289 const int width = s->planewidth[p];
290 double max_hval_log;290 double max_hval_log;
291 unsigned max_hval = 0;291 unsigned max_hval = 0;
292 int start, startx;292 int start, startx;
293 293
294 if (!((1 << k) & h->components))294 if (!((1 << k) & s->components))
295 continue;295 continue;
296 startx = m * h->histogram_size * (h->display_mode == 1);296 startx = m * s->histogram_size * (s->display_mode == 1);
297 start = m++ * (h->level_height + h->scale_height) * (h->display_mode == 2);297 start = m++ * (s->level_height + s->scale_height) * (s->display_mode == 2);
298 298
299 if (h->histogram_size <= 256) {299 if (s->histogram_size <= 256) {
300 for (i = 0; i < height; i++) {300 for (i = 0; i < height; i++) {
301 const uint8_t *src = in->data[p] + i * in->linesize[p];301 const uint8_t *src = in->data[p] + i * in->linesize[p];
302 for (j = 0; j < width; j++)302 for (j = 0; j < width; j++)
303 h->histogram[src[j]]++;303 s->histogram[src[j]]++;
304 }304 }
305 } else {305 } else {
306 for (i = 0; i < height; i++) {306 for (i = 0; i < height; i++) {
307 const uint16_t *src = (const uint16_t *)(in->data[p] + i * in->linesize[p]);307 const uint16_t *src = (const uint16_t *)(in->data[p] + i * in->linesize[p]);
308 for (j = 0; j < width; j++)308 for (j = 0; j < width; j++)
309 h->histogram[src[j]]++;309 s->histogram[src[j]]++;
310 }310 }
311 }311 }
312 312
313 for (i = 0; i < h->histogram_size; i++)313 for (i = 0; i < s->histogram_size; i++)
314 max_hval = FFMAX(max_hval, h->histogram[i]);314 max_hval = FFMAX(max_hval, s->histogram[i]);
315 max_hval_log = log2(max_hval + 1);315 max_hval_log = log2(max_hval + 1);
316 316
317 for (i = 0; i < h->histogram_size; i++) {317 for (i = 0; i < s->histogram_size; i++) {
318 int col_height;318 int col_height;
319 319
320 if (h->levels_mode)320 if (s->levels_mode)
321 col_height = lrint(h->level_height * (1. - (log2(h->histogram[i] + 1) / max_hval_log)));321 col_height = lrint(s->level_height * (1. - (log2(s->histogram[i] + 1) / max_hval_log)));
322 else322 else
323 col_height = h->level_height - (h->histogram[i] * (int64_t)h->level_height + max_hval - 1) / max_hval;323 col_height = s->level_height - (s->histogram[i] * (int64_t)s->level_height + max_hval - 1) / max_hval;
324 324
325 if (h->histogram_size <= 256) {325 if (s->histogram_size <= 256) {
326 for (j = h->level_height - 1; j >= col_height; j--) {326 for (j = s->level_height - 1; j >= col_height; j--) {
327 if (h->display_mode) {327 if (s->display_mode) {
328 for (l = 0; l < h->dncomp; l++)328 for (l = 0; l < s->dncomp; l++)
329 out->data[l][(j + start) * out->linesize[l] + startx + i] = h->fg_color[l];329 out->data[l][(j + start) * out->linesize[l] + startx + i] = s->fg_color[l];
330 } else {330 } else {
331 out->data[p][(j + start) * out->linesize[p] + startx + i] = 255;331 out->data[p][(j + start) * out->linesize[p] + startx + i] = 255;
332 }332 }
333 }333 }
334 for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--)334 for (j = s->level_height + s->scale_height - 1; j >= s->level_height; j--)
335 out->data[p][(j + start) * out->linesize[p] + startx + i] = i;335 out->data[p][(j + start) * out->linesize[p] + startx + i] = i;
336 } else {336 } else {
337 const int mult = h->mult;337 const int mult = s->mult;
338 338
339 for (j = h->level_height - 1; j >= col_height; j--) {339 for (j = s->level_height - 1; j >= col_height; j--) {
340 if (h->display_mode) {340 if (s->display_mode) {
341 for (l = 0; l < h->dncomp; l++)341 for (l = 0; l < s->dncomp; l++)
342 AV_WN16(out->data[l] + (j + start) * out->linesize[l] + startx * 2 + i * 2, h->fg_color[l] * mult);342 AV_WN16(out->data[l] + (j + start) * out->linesize[l] + startx * 2 + i * 2, s->fg_color[l] * mult);
343 } else {343 } else {
344 AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, 255 * mult);344 AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, 255 * mult);
345 }345 }
346 }346 }
347 for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--)347 for (j = s->level_height + s->scale_height - 1; j >= s->level_height; j--)
348 AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, i);348 AV_WN16(out->data[p] + (j + start) * out->linesize[p] + startx * 2 + i * 2, i);
349 }349 }
350 }350 }
351 351
352 memset(h->histogram, 0, h->histogram_size * sizeof(unsigned));352 memset(s->histogram, 0, s->histogram_size * sizeof(unsigned));
353 }353 }
354 354
355 av_frame_free(&in);355 av_frame_free(&in);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t