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.

137 lines
3.8KB

  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/common.h"
  25. #include "libavutil/pixdesc.h"
  26. #include "avfilter.h"
  27. #include "internal.h"
  28. #include "video.h"
  29. typedef struct {
  30. const AVPixFmtDescriptor *pix_desc;
  31. uint16_t *line;
  32. } PixdescTestContext;
  33. static av_cold void uninit(AVFilterContext *ctx)
  34. {
  35. PixdescTestContext *priv = ctx->priv;
  36. av_freep(&priv->line);
  37. }
  38. static int config_props(AVFilterLink *inlink)
  39. {
  40. PixdescTestContext *priv = inlink->dst->priv;
  41. priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
  42. if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
  43. return AVERROR(ENOMEM);
  44. return 0;
  45. }
  46. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  47. {
  48. PixdescTestContext *priv = inlink->dst->priv;
  49. AVFilterLink *outlink = inlink->dst->outputs[0];
  50. AVFrame *out;
  51. int i, c, w = inlink->w, h = inlink->h;
  52. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  53. if (!out) {
  54. av_frame_free(&in);
  55. return AVERROR(ENOMEM);
  56. }
  57. av_frame_copy_props(out, in);
  58. for (i = 0; i < 4; i++) {
  59. int h = outlink->h;
  60. h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  61. if (out->data[i]) {
  62. uint8_t *data = out->data[i] +
  63. (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h-1));
  64. memset(data, 0, FFABS(out->linesize[i]) * h);
  65. }
  66. }
  67. /* copy palette */
  68. if (priv->pix_desc->flags & PIX_FMT_PAL ||
  69. priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
  70. memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
  71. for (c = 0; c < priv->pix_desc->nb_components; c++) {
  72. int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
  73. int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  74. for (i = 0; i < h1; i++) {
  75. av_read_image_line(priv->line,
  76. (void*)in->data,
  77. in->linesize,
  78. priv->pix_desc,
  79. 0, i, c, w1, 0);
  80. av_write_image_line(priv->line,
  81. out->data,
  82. out->linesize,
  83. priv->pix_desc,
  84. 0, i, c, w1);
  85. }
  86. }
  87. av_frame_free(&in);
  88. return ff_filter_frame(outlink, out);
  89. }
  90. static const AVFilterPad avfilter_vf_pixdesctest_inputs[] = {
  91. {
  92. .name = "default",
  93. .type = AVMEDIA_TYPE_VIDEO,
  94. .filter_frame = filter_frame,
  95. .config_props = config_props,
  96. },
  97. { NULL }
  98. };
  99. static const AVFilterPad avfilter_vf_pixdesctest_outputs[] = {
  100. {
  101. .name = "default",
  102. .type = AVMEDIA_TYPE_VIDEO,
  103. },
  104. { NULL }
  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 = avfilter_vf_pixdesctest_inputs,
  112. .outputs = avfilter_vf_pixdesctest_outputs,
  113. };