vf_pixdesctest.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2009 Stefano Sabatini
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * pixdesc test filter
  23. */
  24. #include "libavutil/pixdesc.h"
  25. #include "avfilter.h"
  26. typedef struct {
  27. const AVPixFmtDescriptor *pix_desc;
  28. uint16_t *line;
  29. } PixdescTestContext;
  30. static av_cold void uninit(AVFilterContext *ctx)
  31. {
  32. PixdescTestContext *priv = ctx->priv;
  33. av_freep(&priv->line);
  34. }
  35. static int config_props(AVFilterLink *inlink)
  36. {
  37. PixdescTestContext *priv = inlink->dst->priv;
  38. priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
  39. if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
  40. return AVERROR(ENOMEM);
  41. return 0;
  42. }
  43. static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  44. {
  45. PixdescTestContext *priv = inlink->dst->priv;
  46. AVFilterLink *outlink = inlink->dst->outputs[0];
  47. AVFilterBufferRef *outpicref;
  48. int i;
  49. outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
  50. outlink->w, outlink->h);
  51. outpicref = outlink->out_buf;
  52. avfilter_copy_buffer_ref_props(outpicref, picref);
  53. for (i = 0; i < 4; i++) {
  54. int h = outlink->h;
  55. h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  56. if (outpicref->data[i]) {
  57. uint8_t *data = outpicref->data[i] +
  58. (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
  59. memset(data, 0, FFABS(outpicref->linesize[i]) * h);
  60. }
  61. }
  62. /* copy palette */
  63. if (priv->pix_desc->flags & PIX_FMT_PAL ||
  64. priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
  65. memcpy(outpicref->data[1], picref->data[1], AVPALETTE_SIZE);
  66. avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
  67. }
  68. static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
  69. {
  70. PixdescTestContext *priv = inlink->dst->priv;
  71. AVFilterBufferRef *inpic = inlink->cur_buf;
  72. AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
  73. int i, c, w = inlink->w;
  74. for (c = 0; c < priv->pix_desc->nb_components; c++) {
  75. int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
  76. int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  77. int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
  78. for (i = y1; i < y1 + h1; i++) {
  79. av_read_image_line(priv->line,
  80. (void*)inpic->data,
  81. inpic->linesize,
  82. priv->pix_desc,
  83. 0, i, c, w1, 0);
  84. av_write_image_line(priv->line,
  85. outpic->data,
  86. outpic->linesize,
  87. priv->pix_desc,
  88. 0, i, c, w1);
  89. }
  90. }
  91. avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
  92. }
  93. AVFilter avfilter_vf_pixdesctest = {
  94. .name = "pixdesctest",
  95. .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
  96. .priv_size = sizeof(PixdescTestContext),
  97. .uninit = uninit,
  98. .inputs = (const AVFilterPad[]) {{ .name = "default",
  99. .type = AVMEDIA_TYPE_VIDEO,
  100. .start_frame = start_frame,
  101. .draw_slice = draw_slice,
  102. .config_props = config_props,
  103. .min_perms = AV_PERM_READ, },
  104. { .name = NULL}},
  105. .outputs = (const AVFilterPad[]) {{ .name = "default",
  106. .type = AVMEDIA_TYPE_VIDEO, },
  107. { .name = NULL}},
  108. };