vf_rgbtest.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. //===========================================================================//
  28. struct vf_priv_s {
  29. unsigned int fmt;
  30. int w, h;
  31. };
  32. static unsigned int getfmt(unsigned int outfmt){
  33. switch(outfmt){
  34. case IMGFMT_RGB12:
  35. case IMGFMT_RGB15:
  36. case IMGFMT_RGB16:
  37. case IMGFMT_RGB24:
  38. case IMGFMT_RGBA:
  39. case IMGFMT_ARGB:
  40. case IMGFMT_BGR12:
  41. case IMGFMT_BGR15:
  42. case IMGFMT_BGR16:
  43. case IMGFMT_BGR24:
  44. case IMGFMT_BGRA:
  45. case IMGFMT_ABGR:
  46. return outfmt;
  47. }
  48. return 0;
  49. }
  50. static void put_pixel(uint8_t *buf, int x, int y, int stride, int r, int g, int b, int fmt){
  51. switch(fmt){
  52. case IMGFMT_BGR12: ((uint16_t*)(buf + y*stride))[x]=
  53. ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
  54. break;
  55. case IMGFMT_RGB12: ((uint16_t*)(buf + y*stride))[x]=
  56. ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4);
  57. break;
  58. case IMGFMT_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
  59. break;
  60. case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
  61. break;
  62. case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
  63. break;
  64. case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
  65. break;
  66. case IMGFMT_RGB24:
  67. buf[3*x + y*stride + 0]= r;
  68. buf[3*x + y*stride + 1]= g;
  69. buf[3*x + y*stride + 2]= b;
  70. break;
  71. case IMGFMT_BGR24:
  72. buf[3*x + y*stride + 0]= b;
  73. buf[3*x + y*stride + 1]= g;
  74. buf[3*x + y*stride + 2]= r;
  75. break;
  76. case IMGFMT_RGBA:
  77. buf[4*x + y*stride + 0]= r;
  78. buf[4*x + y*stride + 1]= g;
  79. buf[4*x + y*stride + 2]= b;
  80. break;
  81. case IMGFMT_BGRA:
  82. buf[4*x + y*stride + 0]= b;
  83. buf[4*x + y*stride + 1]= g;
  84. buf[4*x + y*stride + 2]= r;
  85. break;
  86. case IMGFMT_ARGB:
  87. buf[4*x + y*stride + 1]= r;
  88. buf[4*x + y*stride + 2]= g;
  89. buf[4*x + y*stride + 3]= b;
  90. break;
  91. case IMGFMT_ABGR:
  92. buf[4*x + y*stride + 1]= b;
  93. buf[4*x + y*stride + 2]= g;
  94. buf[4*x + y*stride + 3]= r;
  95. break;
  96. }
  97. }
  98. static int config(struct vf_instance *vf,
  99. int width, int height, int d_width, int d_height,
  100. unsigned int flags, unsigned int outfmt){
  101. if (vf->priv->w > 0) { d_width = width = vf->priv->w; }
  102. if (vf->priv->h > 0) { d_height = height = vf->priv->h; }
  103. vf->priv->fmt=getfmt(outfmt);
  104. mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt));
  105. return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
  106. }
  107. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
  108. mp_image_t *dmpi;
  109. int x, y;
  110. int w = vf->priv->w > 0 ? vf->priv->w : mpi->w;
  111. int h = vf->priv->h > 0 ? vf->priv->h : mpi->h;
  112. // hope we'll get DR buffer:
  113. dmpi=vf_get_image(vf->next,vf->priv->fmt,
  114. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
  115. w, h);
  116. for(y=0; y<h; y++){
  117. for(x=0; x<w; x++){
  118. int c= 256*x/w;
  119. int r=0,g=0,b=0;
  120. if(3*y<h) r=c;
  121. else if(3*y<2*h) g=c;
  122. else b=c;
  123. put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt);
  124. }
  125. }
  126. return vf_next_put_image(vf,dmpi, pts);
  127. }
  128. //===========================================================================//
  129. static int query_format(struct vf_instance *vf, unsigned int outfmt){
  130. unsigned int fmt=getfmt(outfmt);
  131. if(!fmt) return 0;
  132. return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
  133. }
  134. static int vf_open(vf_instance_t *vf, char *args){
  135. vf->config=config;
  136. vf->put_image=put_image;
  137. vf->query_format=query_format;
  138. vf->priv=malloc(sizeof(struct vf_priv_s));
  139. vf->priv->w = vf->priv->h = 0;
  140. if (args)
  141. sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h);
  142. return 1;
  143. }
  144. const vf_info_t vf_info_rgbtest = {
  145. "rgbtest",
  146. "rgbtest",
  147. "Michael Niedermayer",
  148. "",
  149. vf_open,
  150. NULL
  151. };
  152. //===========================================================================//