yuv2rgb_mlib.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * software YUV to RGB converter using mediaLib
  3. *
  4. * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <mlib_types.h>
  23. #include <mlib_status.h>
  24. #include <mlib_sys.h>
  25. #include <mlib_video.h>
  26. #include <inttypes.h>
  27. #include <stdlib.h>
  28. #include <assert.h>
  29. #include "swscale.h"
  30. static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
  31. int srcSliceH, uint8_t* dst[], int dstStride[]){
  32. if(c->srcFormat == PIX_FMT_YUV422P){
  33. srcStride[1] *= 2;
  34. srcStride[2] *= 2;
  35. }
  36. assert(srcStride[1] == srcStride[2]);
  37. mlib_VideoColorYUV2ARGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW,
  38. srcSliceH, dstStride[0], srcStride[0], srcStride[1]);
  39. return srcSliceH;
  40. }
  41. static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
  42. int srcSliceH, uint8_t* dst[], int dstStride[]){
  43. if(c->srcFormat == PIX_FMT_YUV422P){
  44. srcStride[1] *= 2;
  45. srcStride[2] *= 2;
  46. }
  47. assert(srcStride[1] == srcStride[2]);
  48. mlib_VideoColorYUV2ABGR420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW,
  49. srcSliceH, dstStride[0], srcStride[0], srcStride[1]);
  50. return srcSliceH;
  51. }
  52. static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
  53. int srcSliceH, uint8_t* dst[], int dstStride[]){
  54. if(c->srcFormat == PIX_FMT_YUV422P){
  55. srcStride[1] *= 2;
  56. srcStride[2] *= 2;
  57. }
  58. assert(srcStride[1] == srcStride[2]);
  59. mlib_VideoColorYUV2RGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW,
  60. srcSliceH, dstStride[0], srcStride[0], srcStride[1]);
  61. return srcSliceH;
  62. }
  63. SwsFunc sws_yuv2rgb_init_mlib(SwsContext *c)
  64. {
  65. switch(c->dstFormat){
  66. case PIX_FMT_RGB24: return mlib_YUV2RGB420_24;
  67. case PIX_FMT_BGR32: return mlib_YUV2ARGB420_32;
  68. case PIX_FMT_RGB32: return mlib_YUV2ABGR420_32;
  69. default: return NULL;
  70. }
  71. }