Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / images / pixel.cpp
index aae23a9..b50816f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,6 +43,34 @@ bool Pixel::HasAlpha(Format pixelformat)
     case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
     case COMPRESSED_RGBA8_ETC2_EAC:
     case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+    case COMPRESSED_RGBA_ASTC_4x4_KHR:
+    case COMPRESSED_RGBA_ASTC_5x4_KHR:
+    case COMPRESSED_RGBA_ASTC_5x5_KHR:
+    case COMPRESSED_RGBA_ASTC_6x5_KHR:
+    case COMPRESSED_RGBA_ASTC_6x6_KHR:
+    case COMPRESSED_RGBA_ASTC_8x5_KHR:
+    case COMPRESSED_RGBA_ASTC_8x6_KHR:
+    case COMPRESSED_RGBA_ASTC_8x8_KHR:
+    case COMPRESSED_RGBA_ASTC_10x5_KHR:
+    case COMPRESSED_RGBA_ASTC_10x6_KHR:
+    case COMPRESSED_RGBA_ASTC_10x8_KHR:
+    case COMPRESSED_RGBA_ASTC_10x10_KHR:
+    case COMPRESSED_RGBA_ASTC_12x10_KHR:
+    case COMPRESSED_RGBA_ASTC_12x12_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
     {
       return true;
     }
@@ -61,6 +89,9 @@ bool Pixel::HasAlpha(Format pixelformat)
     case COMPRESSED_SRGB8_ETC2:
     case COMPRESSED_RGB8_ETC1:
     case COMPRESSED_RGB_PVRTC_4BPPV1:
+    case RGB16F:
+    case RGB32F:
+    case INVALID:
     {
       return false;
     }
@@ -68,7 +99,7 @@ bool Pixel::HasAlpha(Format pixelformat)
   return false;
 }
 
-unsigned int Pixel::GetBytesPerPixel(Format pixelFormat)
+uint32_t Pixel::GetBytesPerPixel(Format pixelFormat)
 {
   switch (pixelFormat)
   {
@@ -102,6 +133,16 @@ unsigned int Pixel::GetBytesPerPixel(Format pixelFormat)
       return 4;
     }
 
+    case RGB16F:
+    {
+      return 12;
+    }
+
+    case RGB32F:
+    {
+      return 24;
+    }
+
     case COMPRESSED_R11_EAC:
     case COMPRESSED_SIGNED_R11_EAC:
     case COMPRESSED_RG11_EAC:
@@ -114,6 +155,35 @@ unsigned int Pixel::GetBytesPerPixel(Format pixelFormat)
     case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
     case COMPRESSED_RGBA8_ETC2_EAC:
     case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+    case COMPRESSED_RGBA_ASTC_4x4_KHR:
+    case COMPRESSED_RGBA_ASTC_5x4_KHR:
+    case COMPRESSED_RGBA_ASTC_5x5_KHR:
+    case COMPRESSED_RGBA_ASTC_6x5_KHR:
+    case COMPRESSED_RGBA_ASTC_6x6_KHR:
+    case COMPRESSED_RGBA_ASTC_8x5_KHR:
+    case COMPRESSED_RGBA_ASTC_8x6_KHR:
+    case COMPRESSED_RGBA_ASTC_8x8_KHR:
+    case COMPRESSED_RGBA_ASTC_10x5_KHR:
+    case COMPRESSED_RGBA_ASTC_10x6_KHR:
+    case COMPRESSED_RGBA_ASTC_10x8_KHR:
+    case COMPRESSED_RGBA_ASTC_10x10_KHR:
+    case COMPRESSED_RGBA_ASTC_12x10_KHR:
+    case COMPRESSED_RGBA_ASTC_12x12_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
+    case INVALID:
     {
       DALI_LOG_ERROR("Pixel formats for compressed images do not have meaningful integer bits per pixel values.\n");
       return 0;
@@ -188,6 +258,37 @@ void Pixel::GetAlphaOffsetAndMask(Format pixelFormat, int& byteOffset, int& bitM
     case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
     case COMPRESSED_RGBA8_ETC2_EAC:
     case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+    case COMPRESSED_RGBA_ASTC_4x4_KHR:
+    case COMPRESSED_RGBA_ASTC_5x4_KHR:
+    case COMPRESSED_RGBA_ASTC_5x5_KHR:
+    case COMPRESSED_RGBA_ASTC_6x5_KHR:
+    case COMPRESSED_RGBA_ASTC_6x6_KHR:
+    case COMPRESSED_RGBA_ASTC_8x5_KHR:
+    case COMPRESSED_RGBA_ASTC_8x6_KHR:
+    case COMPRESSED_RGBA_ASTC_8x8_KHR:
+    case COMPRESSED_RGBA_ASTC_10x5_KHR:
+    case COMPRESSED_RGBA_ASTC_10x6_KHR:
+    case COMPRESSED_RGBA_ASTC_10x8_KHR:
+    case COMPRESSED_RGBA_ASTC_10x10_KHR:
+    case COMPRESSED_RGBA_ASTC_12x10_KHR:
+    case COMPRESSED_RGBA_ASTC_12x12_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
+    case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
+    case RGB16F:
+    case RGB32F:
+    case INVALID:
     {
       DALI_LOG_ERROR("Pixel formats for compressed images are not compatible with simple masking-out of per-pixel alpha.\n");
       byteOffset=0;