vf_mirror.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "img_format.h"
  25. #include "mp_image.h"
  26. #include "vf.h"
  27. static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){
  28. int y;
  29. for(y=0;y<h;y++){
  30. int x;
  31. switch(bpp){
  32. case 1:
  33. for(x=0;x<w;x++) dst[x]=src[w-x-1];
  34. break;
  35. case 2:
  36. switch(fmt){
  37. case IMGFMT_UYVY: {
  38. // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
  39. int w2=w>>1;
  40. for(x=0;x<w2;x++){
  41. // TODO: optimize this...
  42. dst[x*4+0]=src[0+(w2-x-1)*4];
  43. dst[x*4+1]=src[3+(w2-x-1)*4];
  44. dst[x*4+2]=src[2+(w2-x-1)*4];
  45. dst[x*4+3]=src[1+(w2-x-1)*4];
  46. }
  47. break; }
  48. case IMGFMT_YUY2:
  49. case IMGFMT_YVYU: {
  50. // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
  51. int w2=w>>1;
  52. for(x=0;x<w2;x++){
  53. // TODO: optimize this...
  54. dst[x*4+0]=src[2+(w2-x-1)*4];
  55. dst[x*4+1]=src[1+(w2-x-1)*4];
  56. dst[x*4+2]=src[0+(w2-x-1)*4];
  57. dst[x*4+3]=src[3+(w2-x-1)*4];
  58. }
  59. break; }
  60. default:
  61. for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+(w-x-1)*2));
  62. }
  63. break;
  64. case 3:
  65. for(x=0;x<w;x++){
  66. dst[x*3+0]=src[0+(w-x-1)*3];
  67. dst[x*3+1]=src[1+(w-x-1)*3];
  68. dst[x*3+2]=src[2+(w-x-1)*3];
  69. }
  70. break;
  71. case 4:
  72. for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+(w-x-1)*4));
  73. }
  74. src+=srcstride;
  75. dst+=dststride;
  76. }
  77. }
  78. //===========================================================================//
  79. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
  80. mp_image_t *dmpi;
  81. // hope we'll get DR buffer:
  82. dmpi=vf_get_image(vf->next,mpi->imgfmt,
  83. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
  84. mpi->w, mpi->h);
  85. if(mpi->flags&MP_IMGFLAG_PLANAR){
  86. mirror(dmpi->planes[0],mpi->planes[0],
  87. dmpi->stride[0],mpi->stride[0],
  88. dmpi->w,dmpi->h,1,mpi->imgfmt);
  89. mirror(dmpi->planes[1],mpi->planes[1],
  90. dmpi->stride[1],mpi->stride[1],
  91. dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
  92. mirror(dmpi->planes[2],mpi->planes[2],
  93. dmpi->stride[2],mpi->stride[2],
  94. dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
  95. } else {
  96. mirror(dmpi->planes[0],mpi->planes[0],
  97. dmpi->stride[0],mpi->stride[0],
  98. dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt);
  99. dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette
  100. }
  101. return vf_next_put_image(vf,dmpi, pts);
  102. }
  103. //===========================================================================//
  104. static int vf_open(vf_instance_t *vf, char *args){
  105. //vf->config=config;
  106. vf->put_image=put_image;
  107. return 1;
  108. }
  109. const vf_info_t vf_info_mirror = {
  110. "horizontal mirror",
  111. "mirror",
  112. "Eyck",
  113. "",
  114. vf_open,
  115. NULL
  116. };
  117. //===========================================================================//