You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.4KB

  1. /*
  2. * Copyright (c) 2009 Stefano Sabatini
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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. #include "internal.h"
  27. #include "video.h"
  28. typedef struct {
  29. const AVPixFmtDescriptor *pix_desc;
  30. uint16_t *line;
  31. } PixdescTestContext;
  32. static av_cold void uninit(AVFilterContext *ctx)
  33. {
  34. PixdescTestContext *priv = ctx->priv;
  35. av_freep(&priv->line);
  36. }
  37. static int config_props(AVFilterLink *inlink)
  38. {
  39. PixdescTestContext *priv = inlink->dst->priv;
  40. priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
  41. if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
  42. return AVERROR(ENOMEM);
  43. return 0;
  44. }
  45. static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  46. {
  47. PixdescTestContext *priv = inlink->dst->priv;
  48. AVFilterLink *outlink = inlink->dst->outputs[0];
  49. AVFilterBufferRef *outpicref;
  50. int i;
  51. outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
  52. outlink->w, outlink->h);
  53. outpicref = outlink->out_buf;
  54. avfilter_copy_buffer_ref_props(outpicref, picref);
  55. for (i = 0; i < 4; i++) {
  56. int h = outlink->h;
  57. h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  58. if (outpicref->data[i]) {
  59. uint8_t *data = outpicref->data[i] +
  60. (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
  61. memset(data, 0, FFABS(outpicref->linesize[i]) * h);
  62. }
  63. }
  64. /* copy palette */
  65. if (priv->pix_desc->flags & PIX_FMT_PAL ||
  66. priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
  67. memcpy(outpicref->data[1], outpicref->data[1], 256*4);
  68. ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
  69. }
  70. static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
  71. {
  72. PixdescTestContext *priv = inlink->dst->priv;
  73. AVFilterBufferRef *inpic = inlink->cur_buf;
  74. AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
  75. int i, c, w = inlink->w;
  76. for (c = 0; c < priv->pix_desc->nb_components; c++) {
  77. int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
  78. int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  79. int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
  80. for (i = y1; i < y1 + h1; i++) {
  81. av_read_image_line(priv->line,
  82. inpic->data,
  83. inpic->linesize,
  84. priv->pix_desc,
  85. 0, i, c, w1, 0);
  86. av_write_image_line(priv->line,
  87. outpic->data,
  88. outpic->linesize,
  89. priv->pix_desc,
  90. 0, i, c, w1);
  91. }
  92. }
  93. ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
  94. }
  95. AVFilter avfilter_vf_pixdesctest = {
  96. .name = "pixdesctest",
  97. .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
  98. .priv_size = sizeof(PixdescTestContext),
  99. .uninit = uninit,
  100. .inputs = (AVFilterPad[]) {{ .name = "default",
  101. .type = AVMEDIA_TYPE_VIDEO,
  102. .start_frame = start_frame,
  103. .draw_slice = draw_slice,
  104. .config_props = config_props,
  105. .min_perms = AV_PERM_READ, },
  106. { .name = NULL}},
  107. .outputs = (AVFilterPad[]) {{ .name = "default",
  108. .type = AVMEDIA_TYPE_VIDEO, },
  109. { .name = NULL}},
  110. };