vf_down3dright.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <inttypes.h>
  22. #include "config.h"
  23. #include "mp_msg.h"
  24. #include "cpudetect.h"
  25. #include "img_format.h"
  26. #include "mp_image.h"
  27. #include "vf.h"
  28. #include "libvo/fastmemcpy.h"
  29. struct vf_priv_s {
  30. int skipline;
  31. int scalew;
  32. int scaleh;
  33. };
  34. static void toright(unsigned char *dst[3], unsigned char *src[3],
  35. int dststride[3], int srcstride[3],
  36. int w, int h, struct vf_priv_s* p)
  37. {
  38. int k;
  39. for (k = 0; k < 3; k++) {
  40. unsigned char* fromL = src[k];
  41. unsigned char* fromR = src[k];
  42. unsigned char* to = dst[k];
  43. int src = srcstride[k];
  44. int dst = dststride[k];
  45. int ss;
  46. unsigned int dd;
  47. int i;
  48. if (k > 0) {
  49. i = h / 4 - p->skipline / 2;
  50. ss = src * (h / 4 + p->skipline / 2);
  51. dd = w / 4;
  52. } else {
  53. i = h / 2 - p->skipline;
  54. ss = src * (h / 2 + p->skipline);
  55. dd = w / 2;
  56. }
  57. fromR += ss;
  58. for ( ; i > 0; i--) {
  59. int j;
  60. unsigned char* t = to;
  61. unsigned char* sL = fromL;
  62. unsigned char* sR = fromR;
  63. if (p->scalew == 1) {
  64. for (j = dd; j > 0; j--) {
  65. *t++ = (sL[0] + sL[1]) / 2;
  66. sL+=2;
  67. }
  68. for (j = dd ; j > 0; j--) {
  69. *t++ = (sR[0] + sR[1]) / 2;
  70. sR+=2;
  71. }
  72. } else {
  73. for (j = dd * 2 ; j > 0; j--)
  74. *t++ = *sL++;
  75. for (j = dd * 2 ; j > 0; j--)
  76. *t++ = *sR++;
  77. }
  78. if (p->scaleh == 1) {
  79. fast_memcpy(to + dst, to, dst);
  80. to += dst;
  81. }
  82. to += dst;
  83. fromL += src;
  84. fromR += src;
  85. }
  86. //printf("K %d %d %d %d %d \n", k, w, h, src, dst);
  87. }
  88. }
  89. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
  90. {
  91. mp_image_t *dmpi;
  92. // hope we'll get DR buffer:
  93. dmpi=vf_get_image(vf->next, IMGFMT_YV12,
  94. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
  95. (vf->priv->scaleh == 1) ? MP_IMGFLAG_READABLE : 0,
  96. mpi->w * vf->priv->scalew,
  97. mpi->h / vf->priv->scaleh - vf->priv->skipline);
  98. toright(dmpi->planes, mpi->planes, dmpi->stride,
  99. mpi->stride, mpi->w, mpi->h, vf->priv);
  100. return vf_next_put_image(vf,dmpi, pts);
  101. }
  102. static int config(struct vf_instance *vf,
  103. int width, int height, int d_width, int d_height,
  104. unsigned int flags, unsigned int outfmt)
  105. {
  106. /* FIXME - also support UYVY output? */
  107. return vf_next_config(vf, width * vf->priv->scalew,
  108. height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12);
  109. }
  110. static int query_format(struct vf_instance *vf, unsigned int fmt)
  111. {
  112. /* FIXME - really any YUV 4:2:0 input format should work */
  113. switch (fmt) {
  114. case IMGFMT_YV12:
  115. case IMGFMT_IYUV:
  116. case IMGFMT_I420:
  117. return vf_next_query_format(vf, IMGFMT_YV12);
  118. }
  119. return 0;
  120. }
  121. static void uninit(struct vf_instance *vf)
  122. {
  123. free(vf->priv);
  124. }
  125. static int vf_open(vf_instance_t *vf, char *args)
  126. {
  127. vf->config=config;
  128. vf->query_format=query_format;
  129. vf->put_image=put_image;
  130. vf->uninit=uninit;
  131. vf->priv = calloc(1, sizeof (struct vf_priv_s));
  132. vf->priv->skipline = 0;
  133. vf->priv->scalew = 1;
  134. vf->priv->scaleh = 2;
  135. if (args) sscanf(args, "%d:%d:%d", &vf->priv->skipline, &vf->priv->scalew, &vf->priv->scaleh);
  136. return 1;
  137. }
  138. const vf_info_t vf_info_down3dright = {
  139. "convert stereo movie from top-bottom to left-right field",
  140. "down3dright",
  141. "Zdenek Kabelac",
  142. "",
  143. vf_open,
  144. NULL
  145. };