vf_pixdesctest.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, AVFilterBufferRef *in)
  47. {
  48. PixdescTestContext *priv = inlink->dst->priv;
  49. AVFilterLink *outlink = inlink->dst->outputs[0];
  50. AVFilterBufferRef *out;
  51. int i, c, w = inlink->w, h = inlink->h;
  52. out = ff_get_video_buffer(outlink, AV_PERM_WRITE,
  53. outlink->w, outlink->h);
  54. if (!out) {
  55. avfilter_unref_bufferp(&in);
  56. return AVERROR(ENOMEM);
  57. }
  58. avfilter_copy_buffer_ref_props(out, in);
  59. for (i = 0; i < 4; i++) {
  60. int h = outlink->h;
  61. h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
  62. if (out->data[i]) {
  63. uint8_t *data = out->data[i] +
  64. (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h-1));
  65. memset(data, 0, FFABS(out->linesize[i]) * h);
  66. }
  67. }
  68. /* copy palette */
  69. if (priv->pix_desc->flags & PIX_FMT_PAL ||
  70. priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
  71. memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
  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. for (i = 0; i < h1; i++) {
  76. av_read_image_line(priv->line,
  77. (void*)in->data,
  78. in->linesize,
  79. priv->pix_desc,
  80. 0, i, c, w1, 0);
  81. av_write_image_line(priv->line,
  82. out->data,
  83. out->linesize,
  84. priv->pix_desc,
  85. 0, i, c, w1);
  86. }
  87. }
  88. avfilter_unref_bufferp(&in);
  89. return ff_filter_frame(outlink, out);
  90. }
  91. static const AVFilterPad avfilter_vf_pixdesctest_inputs[] = {
  92. {
  93. .name = "default",
  94. .type = AVMEDIA_TYPE_VIDEO,
  95. .filter_frame = filter_frame,
  96. .config_props = config_props,
  97. .min_perms = AV_PERM_READ,
  98. },
  99. { NULL }
  100. };
  101. static const AVFilterPad avfilter_vf_pixdesctest_outputs[] = {
  102. {
  103. .name = "default",
  104. .type = AVMEDIA_TYPE_VIDEO,
  105. },
  106. { NULL }
  107. };
  108. AVFilter avfilter_vf_pixdesctest = {
  109. .name = "pixdesctest",
  110. .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
  111. .priv_size = sizeof(PixdescTestContext),
  112. .uninit = uninit,
  113. .inputs = avfilter_vf_pixdesctest_inputs,
  114. .outputs = avfilter_vf_pixdesctest_outputs,
  115. };