vf_il.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of MPlayer.
  5. *
  6. * MPlayer is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * MPlayer 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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with MPlayer; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <inttypes.h>
  24. #include <assert.h>
  25. #include "mp_msg.h"
  26. #include "img_format.h"
  27. #include "mp_image.h"
  28. #include "vf.h"
  29. #include "libvo/fastmemcpy.h"
  30. //===========================================================================//
  31. typedef struct FilterParam{
  32. int interleave;
  33. int swap;
  34. }FilterParam;
  35. struct vf_priv_s {
  36. FilterParam lumaParam;
  37. FilterParam chromaParam;
  38. };
  39. /***************************************************************************/
  40. static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){
  41. const int a= swap;
  42. const int b= 1-a;
  43. const int m= h>>1;
  44. int y;
  45. switch(interleave){
  46. case -1:
  47. for(y=0; y < m; y++){
  48. fast_memcpy(dst + dstStride* y , src + srcStride*(y*2 + a), w);
  49. fast_memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w);
  50. }
  51. break;
  52. case 0:
  53. for(y=0; y < m; y++){
  54. fast_memcpy(dst + dstStride* y*2 , src + srcStride*(y*2 + a), w);
  55. fast_memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w);
  56. }
  57. break;
  58. case 1:
  59. for(y=0; y < m; y++){
  60. fast_memcpy(dst + dstStride*(y*2+a), src + srcStride* y , w);
  61. fast_memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w);
  62. }
  63. break;
  64. }
  65. }
  66. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
  67. int w;
  68. FilterParam *luma = &vf->priv->lumaParam;
  69. FilterParam *chroma= &vf->priv->chromaParam;
  70. mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
  71. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
  72. mpi->w,mpi->h);
  73. if(mpi->flags&MP_IMGFLAG_PLANAR)
  74. w= mpi->w;
  75. else
  76. w= mpi->w * mpi->bpp/8;
  77. interleave(dmpi->planes[0], mpi->planes[0],
  78. w, mpi->h, dmpi->stride[0], mpi->stride[0], luma->interleave, luma->swap);
  79. if(mpi->flags&MP_IMGFLAG_PLANAR){
  80. int cw= mpi->w >> mpi->chroma_x_shift;
  81. int ch= mpi->h >> mpi->chroma_y_shift;
  82. interleave(dmpi->planes[1], mpi->planes[1], cw,ch,
  83. dmpi->stride[1], mpi->stride[1], chroma->interleave, luma->swap);
  84. interleave(dmpi->planes[2], mpi->planes[2], cw,ch,
  85. dmpi->stride[2], mpi->stride[2], chroma->interleave, luma->swap);
  86. }
  87. return vf_next_put_image(vf,dmpi, pts);
  88. }
  89. //===========================================================================//
  90. static void parse(FilterParam *fp, char* args){
  91. char *pos;
  92. char *max= strchr(args, ':');
  93. if(!max) max= args + strlen(args);
  94. pos= strchr(args, 's');
  95. if(pos && pos<max) fp->swap=1;
  96. pos= strchr(args, 'i');
  97. if(pos && pos<max) fp->interleave=1;
  98. pos= strchr(args, 'd');
  99. if(pos && pos<max) fp->interleave=-1;
  100. }
  101. static int vf_open(vf_instance_t *vf, char *args){
  102. vf->put_image=put_image;
  103. // vf->get_image=get_image;
  104. vf->priv=malloc(sizeof(struct vf_priv_s));
  105. memset(vf->priv, 0, sizeof(struct vf_priv_s));
  106. if(args)
  107. {
  108. char *arg2= strchr(args,':');
  109. if(arg2) parse(&vf->priv->chromaParam, arg2+1);
  110. parse(&vf->priv->lumaParam, args);
  111. }
  112. return 1;
  113. }
  114. const vf_info_t vf_info_il = {
  115. "(de)interleave",
  116. "il",
  117. "Michael Niedermayer",
  118. "",
  119. vf_open,
  120. NULL
  121. };
  122. //===========================================================================//