SpoutCopy.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. SpoutCopy.h
  3. Functions to manage pixel buffer copying and rgb/rgba <> bgr/bgra conversion
  4. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5. Copyright (c) 2016-2017, Lynn Jarvis. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  14. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  21. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #pragma once
  24. #ifndef __spoutCopy__ // standard way as well
  25. #define __spoutCopy__
  26. #include "SpoutCommon.h"
  27. #include <windows.h>
  28. #include <stdio.h> // for debug printf
  29. #include <gl/gl.h> // For OpenGL definitions
  30. #include <intrin.h> // for cpuid to test for SSE2
  31. #include <emmintrin.h> // for SSE2
  32. #include <tmmintrin.h> // for SSSE3
  33. class SPOUT_DLLEXP spoutCopy {
  34. public:
  35. spoutCopy();
  36. ~spoutCopy();
  37. void CopyPixels(const unsigned char *src, unsigned char *dst,
  38. unsigned int width, unsigned int height,
  39. GLenum glFormat = GL_RGBA, bool bInvert = false);
  40. bool FlipBuffer(const unsigned char *src, unsigned char *dst,
  41. unsigned int width, unsigned int height,
  42. GLenum glFormat = GL_RGBA);
  43. void memcpy_sse2(void* dst, void* src, size_t size);
  44. void rgba2bgra(void* rgba_source, void *bgra_dest, unsigned int width, unsigned int height, bool bInvert = false);
  45. void bgra2rgba(void* bgra_source, void *rgba_dest, unsigned int width, unsigned int height, bool bInvert = false);
  46. void rgba_bgra(void *rgba_source, void *bgra_dest, unsigned int width, unsigned int height, bool bInvert = false);
  47. void rgba_bgra_sse2(void *rgba_source, void *rgba_dest, unsigned int width, unsigned int height, bool bInvert = false);
  48. void rgba_bgra_ssse3(void *rgba_source, void *rgba_dest, unsigned int width, unsigned int height, bool bInvert = false);
  49. // TODO avoid redundancy
  50. void rgb2rgba (void* rgb_source, void *rgba_dest, unsigned int width, unsigned int height, bool bInvert = false);
  51. void bgr2rgba (void* bgr_source, void *rgba_dest, unsigned int width, unsigned int height, bool bInvert = false);
  52. void rgb2bgra (void* rgb_source, void *bgra_dest, unsigned int width, unsigned int height, bool bInvert = false);
  53. void bgr2bgra (void* bgr_source, void *bgra_dest, unsigned int width, unsigned int height, bool bInvert = false);
  54. void rgba2rgb (void* rgba_source, void *rgb_dest, unsigned int width, unsigned int height, bool bInvert = false);
  55. void rgba2bgr (void* rgba_source, void *bgr_dest, unsigned int width, unsigned int height, bool bInvert = false);
  56. void bgra2rgb (void* bgra_source, void *rgb_dest, unsigned int width, unsigned int height, bool bInvert = false);
  57. void bgra2bgr (void* bgra_source, void *bgr_dest, unsigned int width, unsigned int height, bool bInvert = false);
  58. private :
  59. void CheckSSE();
  60. bool m_bSSE2;
  61. bool m_bSSE3;
  62. bool m_bSSSE3;
  63. };
  64. #endif