vf_pixdesctest.c 4.4 KB

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