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.

132 lines
4.4KB

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