vf_rotate.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. struct vf_priv_s {
  28. int direction;
  29. };
  30. static void rotate(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,int dir){
  31. int y;
  32. if(dir&1){
  33. src+=srcstride*(w-1);
  34. srcstride*=-1;
  35. }
  36. if(dir&2){
  37. dst+=dststride*(h-1);
  38. dststride*=-1;
  39. }
  40. for(y=0;y<h;y++){
  41. int x;
  42. switch(bpp){
  43. case 1:
  44. for(x=0;x<w;x++) dst[x]=src[y+x*srcstride];
  45. break;
  46. case 2:
  47. for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+y*2+x*srcstride));
  48. break;
  49. case 3:
  50. for(x=0;x<w;x++){
  51. dst[x*3+0]=src[0+y*3+x*srcstride];
  52. dst[x*3+1]=src[1+y*3+x*srcstride];
  53. dst[x*3+2]=src[2+y*3+x*srcstride];
  54. }
  55. break;
  56. case 4:
  57. for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+y*4+x*srcstride));
  58. }
  59. dst+=dststride;
  60. }
  61. }
  62. //===========================================================================//
  63. static int config(struct vf_instance *vf,
  64. int width, int height, int d_width, int d_height,
  65. unsigned int flags, unsigned int outfmt){
  66. if (vf->priv->direction & 4) {
  67. if (width<height) vf->priv->direction&=3;
  68. }
  69. if (vf->priv->direction & 4){
  70. vf->put_image=vf_next_put_image; // passthru mode!
  71. if (vf->next->draw_slice) vf->draw_slice=vf_next_draw_slice;
  72. /* FIXME: this should be in an other procedure in vf.c; that should always check
  73. whether the filter after the passthrough one still (not)supports slices */
  74. return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
  75. }
  76. return vf_next_config(vf,height,width,d_height,d_width,flags,outfmt);
  77. }
  78. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
  79. mp_image_t *dmpi;
  80. // hope we'll get DR buffer:
  81. dmpi=vf_get_image(vf->next,mpi->imgfmt,
  82. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
  83. mpi->h, mpi->w);
  84. if(mpi->flags&MP_IMGFLAG_PLANAR){
  85. rotate(dmpi->planes[0],mpi->planes[0],
  86. dmpi->stride[0],mpi->stride[0],
  87. dmpi->w,dmpi->h,1,vf->priv->direction);
  88. rotate(dmpi->planes[1],mpi->planes[1],
  89. dmpi->stride[1],mpi->stride[1],
  90. dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,vf->priv->direction);
  91. rotate(dmpi->planes[2],mpi->planes[2],
  92. dmpi->stride[2],mpi->stride[2],
  93. dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,vf->priv->direction);
  94. } else {
  95. rotate(dmpi->planes[0],mpi->planes[0],
  96. dmpi->stride[0],mpi->stride[0],
  97. dmpi->w,dmpi->h,dmpi->bpp>>3,vf->priv->direction);
  98. dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
  99. }
  100. return vf_next_put_image(vf,dmpi, pts);
  101. }
  102. //===========================================================================//
  103. static int query_format(struct vf_instance *vf, unsigned int fmt){
  104. if(IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt)) return vf_next_query_format(vf, fmt);
  105. // we can support only symmetric (chroma_x_shift==chroma_y_shift) YUV formats:
  106. switch(fmt) {
  107. case IMGFMT_YV12:
  108. case IMGFMT_I420:
  109. case IMGFMT_IYUV:
  110. case IMGFMT_YVU9:
  111. // case IMGFMT_IF09:
  112. case IMGFMT_Y8:
  113. case IMGFMT_Y800:
  114. case IMGFMT_444P:
  115. return vf_next_query_format(vf, fmt);
  116. }
  117. return 0;
  118. }
  119. static int vf_open(vf_instance_t *vf, char *args){
  120. vf->config=config;
  121. vf->put_image=put_image;
  122. vf->query_format=query_format;
  123. vf->priv=malloc(sizeof(struct vf_priv_s));
  124. vf->priv->direction=args?atoi(args):0;
  125. return 1;
  126. }
  127. const vf_info_t vf_info_rotate = {
  128. "rotate",
  129. "rotate",
  130. "A'rpi",
  131. "",
  132. vf_open,
  133. NULL
  134. };
  135. //===========================================================================//