PixelFormat.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include "Types.h"
  24. #include "PixelFormat.h"
  25. namespace crown
  26. {
  27. //-----------------------------------------------------------------------------
  28. size_t Pixel::bits_per_pixel(PixelFormat format)
  29. {
  30. return bytes_per_pixel(format) * 8;
  31. }
  32. //-----------------------------------------------------------------------------
  33. size_t Pixel::bytes_per_pixel(PixelFormat format)
  34. {
  35. switch (format)
  36. {
  37. case PF_L_8:
  38. case PF_RGB_3_3_2:
  39. case PF_BGR_2_3_3:
  40. {
  41. return 1;
  42. }
  43. case PF_L_16:
  44. case PF_LA_8:
  45. case PF_AL_8:
  46. case PF_RGB_5_6_5:
  47. case PF_BGR_5_6_5:
  48. case PF_RGBA_4_4_4_4:
  49. case PF_RGBA_5_5_5_1:
  50. case PF_ABGR_4_4_4_4:
  51. case PF_ABGR_1_5_5_5:
  52. {
  53. return 2;
  54. }
  55. case PF_RGB_8:
  56. case PF_BGR_8:
  57. {
  58. return 3;
  59. }
  60. case PF_L_32:
  61. case PF_L_FLOAT_32:
  62. case PF_LA_16:
  63. case PF_AL_16:
  64. case PF_RGBA_8:
  65. case PF_RGBA_8_8_8_8:
  66. case PF_RGBA_10_10_10_2:
  67. case PF_ABGR_8:
  68. case PF_ABGR_8_8_8_8:
  69. case PF_ABGR_2_10_10_10:
  70. {
  71. return 4;
  72. }
  73. case PF_RGB_16:
  74. case PF_BGR_16:
  75. {
  76. return 6;
  77. }
  78. case PF_LA_32:
  79. case PF_LA_FLOAT_32:
  80. case PF_AL_32:
  81. case PF_AL_FLOAT_32:
  82. case PF_RGBA_16:
  83. case PF_ABGR_16:
  84. {
  85. return 8;
  86. }
  87. case PF_RGB_32:
  88. case PF_RGB_FLOAT_32:
  89. case PF_BGR_32:
  90. case PF_BGR_FLOAT_32:
  91. {
  92. return 12;
  93. }
  94. case PF_RGBA_32:
  95. case PF_RGBA_FLOAT_32:
  96. case PF_ABGR_32:
  97. case PF_ABGR_FLOAT_32:
  98. {
  99. return 16;
  100. }
  101. case PF_UNKNOWN:
  102. default:
  103. {
  104. return 0;
  105. }
  106. }
  107. }
  108. } // namespace crown