vf_telecine.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * This file is part of MPlayer.
  3. *
  4. * MPlayer is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * MPlayer is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with MPlayer; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "config.h"
  22. #include "mp_msg.h"
  23. #include "img_format.h"
  24. #include "mp_image.h"
  25. #include "vf.h"
  26. #include "libvo/fastmemcpy.h"
  27. struct vf_priv_s {
  28. int frame;
  29. };
  30. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
  31. {
  32. mp_image_t *dmpi;
  33. int ret;
  34. vf->priv->frame = (vf->priv->frame+1)%4;
  35. dmpi = vf_get_image(vf->next, mpi->imgfmt,
  36. MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
  37. MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
  38. ret = 0;
  39. // 0/0 1/1 2/2 2/3 3/0
  40. switch (vf->priv->frame) {
  41. case 0:
  42. my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
  43. mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
  44. dmpi->stride[0]*2, mpi->stride[0]*2);
  45. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  46. my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
  47. mpi->planes[1]+mpi->stride[1],
  48. mpi->chroma_width, mpi->chroma_height/2,
  49. dmpi->stride[1]*2, mpi->stride[1]*2);
  50. my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
  51. mpi->planes[2]+mpi->stride[2],
  52. mpi->chroma_width, mpi->chroma_height/2,
  53. dmpi->stride[2]*2, mpi->stride[2]*2);
  54. }
  55. ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
  56. case 1:
  57. case 2:
  58. memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
  59. dmpi->stride[0], mpi->stride[0]);
  60. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  61. memcpy_pic(dmpi->planes[1], mpi->planes[1],
  62. mpi->chroma_width, mpi->chroma_height,
  63. dmpi->stride[1], mpi->stride[1]);
  64. memcpy_pic(dmpi->planes[2], mpi->planes[2],
  65. mpi->chroma_width, mpi->chroma_height,
  66. dmpi->stride[2], mpi->stride[2]);
  67. }
  68. return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret;
  69. case 3:
  70. my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
  71. mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
  72. dmpi->stride[0]*2, mpi->stride[0]*2);
  73. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  74. my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
  75. mpi->planes[1]+mpi->stride[1],
  76. mpi->chroma_width, mpi->chroma_height/2,
  77. dmpi->stride[1]*2, mpi->stride[1]*2);
  78. my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
  79. mpi->planes[2]+mpi->stride[2],
  80. mpi->chroma_width, mpi->chroma_height/2,
  81. dmpi->stride[2]*2, mpi->stride[2]*2);
  82. }
  83. ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
  84. my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
  85. dmpi->stride[0]*2, mpi->stride[0]*2);
  86. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  87. my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
  88. mpi->chroma_width, mpi->chroma_height/2,
  89. dmpi->stride[1]*2, mpi->stride[1]*2);
  90. my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
  91. mpi->chroma_width, mpi->chroma_height/2,
  92. dmpi->stride[2]*2, mpi->stride[2]*2);
  93. }
  94. return ret;
  95. }
  96. return 0;
  97. }
  98. #if 0
  99. static int query_format(struct vf_instance *vf, unsigned int fmt)
  100. {
  101. /* FIXME - figure out which other formats work */
  102. switch (fmt) {
  103. case IMGFMT_YV12:
  104. case IMGFMT_IYUV:
  105. case IMGFMT_I420:
  106. return vf_next_query_format(vf, fmt);
  107. }
  108. return 0;
  109. }
  110. static int config(struct vf_instance *vf,
  111. int width, int height, int d_width, int d_height,
  112. unsigned int flags, unsigned int outfmt)
  113. {
  114. return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
  115. }
  116. #endif
  117. static void uninit(struct vf_instance *vf)
  118. {
  119. free(vf->priv);
  120. }
  121. static int vf_open(vf_instance_t *vf, char *args)
  122. {
  123. //vf->config = config;
  124. vf->put_image = put_image;
  125. //vf->query_format = query_format;
  126. vf->uninit = uninit;
  127. vf->default_reqs = VFCAP_ACCEPT_STRIDE;
  128. vf->priv = calloc(1, sizeof(struct vf_priv_s));
  129. vf->priv->frame = 1;
  130. if (args) sscanf(args, "%d", &vf->priv->frame);
  131. vf->priv->frame--;
  132. return 1;
  133. }
  134. const vf_info_t vf_info_telecine = {
  135. "telecine filter",
  136. "telecine",
  137. "Rich Felker",
  138. "",
  139. vf_open,
  140. NULL
  141. };