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.

147 lines
4.8KB

  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 int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  46. {
  47. PixdescTestContext *priv = inlink->dst->priv;
  48. AVFilterLink *outlink = inlink->dst->outputs[0];
  49. AVFilterBufferRef *outpicref, *for_next_filter;
  50. int i, ret = 0;
  51. outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
  52. outlink->w, outlink->h);
  53. if (!outpicref)
  54. return AVERROR(ENOMEM);
  55. avfilter_copy_buffer_ref_props(outpicref, picref);
  56. for (i = 0; i < 4; i++) {
  57. int h = outlink->h;
  58. h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  59. if (outpicref->data[i]) {
  60. uint8_t *data = outpicref->data[i] +
  61. (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
  62. memset(data, 0, FFABS(outpicref->linesize[i]) * h);
  63. }
  64. }
  65. /* copy palette */
  66. if (priv->pix_desc->flags & PIX_FMT_PAL ||
  67. priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
  68. memcpy(outpicref->data[1], outpicref->data[1], 256*4);
  69. for_next_filter = avfilter_ref_buffer(outpicref, ~0);
  70. if (for_next_filter)
  71. ret = ff_start_frame(outlink, for_next_filter);
  72. else
  73. ret = AVERROR(ENOMEM);
  74. if (ret < 0) {
  75. avfilter_unref_bufferp(&outpicref);
  76. return ret;
  77. }
  78. outlink->out_buf = outpicref;
  79. return 0;
  80. }
  81. static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
  82. {
  83. PixdescTestContext *priv = inlink->dst->priv;
  84. AVFilterBufferRef *inpic = inlink->cur_buf;
  85. AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
  86. int i, c, w = inlink->w;
  87. for (c = 0; c < priv->pix_desc->nb_components; c++) {
  88. int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
  89. int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  90. int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
  91. for (i = y1; i < y1 + h1; i++) {
  92. av_read_image_line(priv->line,
  93. inpic->data,
  94. inpic->linesize,
  95. priv->pix_desc,
  96. 0, i, c, w1, 0);
  97. av_write_image_line(priv->line,
  98. outpic->data,
  99. outpic->linesize,
  100. priv->pix_desc,
  101. 0, i, c, w1);
  102. }
  103. }
  104. return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
  105. }
  106. AVFilter avfilter_vf_pixdesctest = {
  107. .name = "pixdesctest",
  108. .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
  109. .priv_size = sizeof(PixdescTestContext),
  110. .uninit = uninit,
  111. .inputs = (const AVFilterPad[]) {{ .name = "default",
  112. .type = AVMEDIA_TYPE_VIDEO,
  113. .start_frame = start_frame,
  114. .draw_slice = draw_slice,
  115. .config_props = config_props,
  116. .min_perms = AV_PERM_READ, },
  117. { .name = NULL}},
  118. .outputs = (const AVFilterPad[]) {{ .name = "default",
  119. .type = AVMEDIA_TYPE_VIDEO, },
  120. { .name = NULL}},
  121. };