vf_yuvcsp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 csp;
  29. };
  30. //===========================================================================//
  31. static int config(struct vf_instance *vf,
  32. int width, int height, int d_width, int d_height,
  33. unsigned int flags, unsigned int outfmt){
  34. return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
  35. }
  36. static inline int clamp_y(int x){
  37. return (x > 235) ? 235 : (x < 16) ? 16 : x;
  38. }
  39. static inline int clamp_c(int x){
  40. return (x > 240) ? 240 : (x < 16) ? 16 : x;
  41. }
  42. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
  43. int i,j;
  44. uint8_t *y_in, *cb_in, *cr_in;
  45. uint8_t *y_out, *cb_out, *cr_out;
  46. vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
  47. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
  48. mpi->width, mpi->height);
  49. y_in = mpi->planes[0];
  50. cb_in = mpi->planes[1];
  51. cr_in = mpi->planes[2];
  52. y_out = vf->dmpi->planes[0];
  53. cb_out = vf->dmpi->planes[1];
  54. cr_out = vf->dmpi->planes[2];
  55. for (i = 0; i < mpi->height; i++)
  56. for (j = 0; j < mpi->width; j++)
  57. y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]);
  58. for (i = 0; i < mpi->chroma_height; i++)
  59. for (j = 0; j < mpi->chroma_width; j++)
  60. {
  61. cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]);
  62. cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]);
  63. }
  64. return vf_next_put_image(vf,vf->dmpi, pts);
  65. }
  66. //===========================================================================//
  67. /*
  68. static void uninit(struct vf_instance *vf){
  69. free(vf->priv);
  70. }
  71. */
  72. static int query_format(struct vf_instance *vf, unsigned int fmt){
  73. switch(fmt){
  74. case IMGFMT_YV12:
  75. case IMGFMT_I420:
  76. case IMGFMT_IYUV:
  77. return 1;
  78. }
  79. return 0;
  80. }
  81. static int vf_open(vf_instance_t *vf, char *args){
  82. vf->config=config;
  83. vf->put_image=put_image;
  84. // vf->uninit=uninit;
  85. vf->query_format=query_format;
  86. // vf->priv=calloc(1, sizeof(struct vf_priv_s));
  87. // if (args)
  88. // vf->priv->csp = atoi(args);
  89. return 1;
  90. }
  91. const vf_info_t vf_info_yuvcsp = {
  92. "yuv colorspace converter",
  93. "yuvcsp",
  94. "Alex Beregszaszi",
  95. "",
  96. vf_open,
  97. NULL
  98. };
  99. //===========================================================================//