rs_convert.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2014 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "rs_core.rsh"
  17. #define CVT_FUNC_2(typeout, typein) \
  18. extern typeout##2 __attribute__((const, overloadable)) \
  19. convert_##typeout##2(typein##2 i) { \
  20. return __builtin_convertvector(i, typeout##2); \
  21. } \
  22. extern typeout##3 __attribute__((const, overloadable)) \
  23. convert_##typeout##3(typein##3 i) { \
  24. return __builtin_convertvector(i, typeout##3); \
  25. } \
  26. extern typeout##4 __attribute__((const, overloadable)) \
  27. convert_##typeout##4(typein##4 i) { \
  28. return __builtin_convertvector(i, typeout##4); \
  29. }
  30. #define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \
  31. CVT_FUNC_2(type, char) \
  32. CVT_FUNC_2(type, ushort) \
  33. CVT_FUNC_2(type, short) \
  34. CVT_FUNC_2(type, uint) \
  35. CVT_FUNC_2(type, int) \
  36. CVT_FUNC_2(type, ulong) \
  37. CVT_FUNC_2(type, long) \
  38. CVT_FUNC_2(type, half) \
  39. CVT_FUNC_2(type, float) \
  40. CVT_FUNC_2(type, double)
  41. CVT_FUNC(char)
  42. CVT_FUNC(uchar)
  43. CVT_FUNC(short)
  44. CVT_FUNC(ushort)
  45. CVT_FUNC(int)
  46. CVT_FUNC(uint)
  47. CVT_FUNC(long)
  48. CVT_FUNC(ulong)
  49. CVT_FUNC(half)
  50. CVT_FUNC(float)
  51. CVT_FUNC(double)
  52. /*
  53. * YUV float4 version
  54. */
  55. static float4 yuv_U_values = {0.f, -0.392f * 0.003921569f, +2.02 * 0.003921569f, 0.f};
  56. static float4 yuv_V_values = {1.603f * 0.003921569f, -0.815f * 0.003921569f, 0.f, 0.f};
  57. extern float4 __attribute__((overloadable)) rsYuvToRGBA_float4(uchar y, uchar u, uchar v) {
  58. float4 color = (float)y * 0.003921569f;
  59. float4 fU = ((float)u) - 128.f;
  60. float4 fV = ((float)v) - 128.f;
  61. color += fU * yuv_U_values;
  62. color += fV * yuv_V_values;
  63. color = clamp(color, 0.f, 1.f);
  64. return color;
  65. }