PixelFormat.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2007 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 <ui/PixelFormat.h>
  17. // ----------------------------------------------------------------------------
  18. namespace android {
  19. // ----------------------------------------------------------------------------
  20. uint32_t bytesPerPixel(PixelFormat format) {
  21. switch (format) {
  22. case PIXEL_FORMAT_RGBA_8888:
  23. case PIXEL_FORMAT_RGBX_8888:
  24. case PIXEL_FORMAT_BGRA_8888:
  25. return 4;
  26. case PIXEL_FORMAT_RGB_888:
  27. return 3;
  28. case PIXEL_FORMAT_RGB_565:
  29. case PIXEL_FORMAT_RGBA_5551:
  30. case PIXEL_FORMAT_RGBA_4444:
  31. return 2;
  32. }
  33. return 0;
  34. }
  35. uint32_t bitsPerPixel(PixelFormat format) {
  36. switch (format) {
  37. case PIXEL_FORMAT_RGBA_8888:
  38. case PIXEL_FORMAT_RGBX_8888:
  39. case PIXEL_FORMAT_BGRA_8888:
  40. return 32;
  41. case PIXEL_FORMAT_RGB_888:
  42. return 24;
  43. case PIXEL_FORMAT_RGB_565:
  44. case PIXEL_FORMAT_RGBA_5551:
  45. case PIXEL_FORMAT_RGBA_4444:
  46. return 16;
  47. }
  48. return 0;
  49. }
  50. // ----------------------------------------------------------------------------
  51. }; // namespace android
  52. // ----------------------------------------------------------------------------