yuv2rgb_mlib.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "libswscale/swscale.h"
  30. #include "libswscale/swscale_internal.h"
  31. static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
  32. int srcSliceH, uint8_t* dst[], int dstStride[])
  33. {
  34. if(c->srcFormat == PIX_FMT_YUV422P) {
  35. srcStride[1] *= 2;
  36. srcStride[2] *= 2;
  37. }
  38. assert(srcStride[1] == srcStride[2]);
  39. mlib_VideoColorYUV2ARGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW,
  40. srcSliceH, dstStride[0], srcStride[0], srcStride[1]);
  41. return srcSliceH;
  42. }
  43. static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
  44. int srcSliceH, uint8_t* dst[], int dstStride[])
  45. {
  46. if(c->srcFormat == PIX_FMT_YUV422P) {
  47. srcStride[1] *= 2;
  48. srcStride[2] *= 2;
  49. }
  50. assert(srcStride[1] == srcStride[2]);
  51. mlib_VideoColorYUV2ABGR420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW,
  52. srcSliceH, dstStride[0], srcStride[0], srcStride[1]);
  53. return srcSliceH;
  54. }
  55. static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
  56. int srcSliceH, uint8_t* dst[], int dstStride[])
  57. {
  58. if(c->srcFormat == PIX_FMT_YUV422P) {
  59. srcStride[1] *= 2;
  60. srcStride[2] *= 2;
  61. }
  62. assert(srcStride[1] == srcStride[2]);
  63. mlib_VideoColorYUV2RGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW,
  64. srcSliceH, dstStride[0], srcStride[0], srcStride[1]);
  65. return srcSliceH;
  66. }
  67. SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c)
  68. {
  69. switch(c->dstFormat) {
  70. case PIX_FMT_RGB24: return mlib_YUV2RGB420_24;
  71. case PIX_FMT_BGR32: return mlib_YUV2ARGB420_32;
  72. case PIX_FMT_RGB32: return mlib_YUV2ABGR420_32;
  73. default: return NULL;
  74. }
  75. }