OSDN Git Service

Enable R5G6B5 as an internal format.
authorNicolas Capens <capn@google.com>
Fri, 4 Sep 2015 14:45:43 +0000 (10:45 -0400)
committerNicolas Capens <capn@google.com>
Thu, 24 Sep 2015 18:15:07 +0000 (18:15 +0000)
Bug 20891368

Change-Id: Iea526eebe65616079578563126a6958d87647eb1
Reviewed-on: https://swiftshader-review.googlesource.com/3255
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
src/OpenGL/common/Image.cpp
src/OpenGL/libGL/Image.cpp
src/Renderer/Surface.cpp
src/Renderer/Surface.hpp

index fd9ab52..a0f7ac6 100644 (file)
@@ -186,17 +186,7 @@ namespace
        template<>
        void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
        {
-               const unsigned short *source565 = reinterpret_cast<const unsigned short*>(source);
-               unsigned char *destB = dest + xoffset * 4;
-
-               for(int x = 0; x < width; x++)
-               {
-                       unsigned short rgba = source565[x];
-                       destB[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
-                       destB[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
-                       destB[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
-                       destB[4 * x + 3] = 0xFF;
-               }
+               memcpy(dest + xoffset * 2, source, width * 2);
        }
 
        template<>
@@ -587,7 +577,7 @@ namespace egl
                }
                else if(type == GL_UNSIGNED_SHORT_5_6_5)
                {
-                       return sw::FORMAT_X8R8G8B8;
+                       return sw::FORMAT_R5G6B5;
                }
                else UNREACHABLE(type);
 
index b01712a..c444434 100644 (file)
@@ -214,7 +214,7 @@ namespace gl
                }
                else if(type == GL_UNSIGNED_SHORT_5_6_5)
                {
-                       return sw::FORMAT_X8R8G8B8;
+                       return sw::FORMAT_R5G6B5;
                }
         else if(type == GL_UNSIGNED_INT_8_8_8_8_REV)
         {
@@ -504,16 +504,9 @@ namespace gl
                for(int y = 0; y < height; y++)
                {
                        const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
-                       unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
+                       unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 2;
                        
-                       for(int x = 0; x < width; x++)
-                       {
-                               unsigned short rgba = source[x];
-                               dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
-                               dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
-                               dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
-                               dest[4 * x + 3] = 0xFF;
-                       }
+                       memcpy(dest, source, width * 2);
                }
        }
 
index 79e4c0b..b84ba1c 100644 (file)
@@ -1416,7 +1416,6 @@ namespace sw
                        switch(source.format)
                        {
                        case FORMAT_R8G8B8:             decodeR8G8B8(destination, source);              break;   // FIXME: Check destination format
-                       case FORMAT_R5G6B5:             decodeR5G6B5(destination, source);              break;   // FIXME: Check destination format
                        case FORMAT_X1R5G5B5:   decodeX1R5G5B5(destination, source);    break;   // FIXME: Check destination format
                        case FORMAT_A1R5G5B5:   decodeA1R5G5B5(destination, source);    break;   // FIXME: Check destination format
                        case FORMAT_X4R4G4B4:   decodeX4R4G4B4(destination, source);    break;   // FIXME: Check destination format
@@ -1554,44 +1553,6 @@ namespace sw
                }
        }
 
-       void Surface::decodeR5G6B5(Buffer &destination, const Buffer &source)
-       {
-               unsigned char *sourceSlice = (unsigned char*)source.buffer;
-               unsigned char *destinationSlice = (unsigned char*)destination.buffer;
-
-               for(int z = 0; z < destination.depth && z < source.depth; z++)
-               {
-                       unsigned char *sourceRow = sourceSlice;
-                       unsigned char *destinationRow = destinationSlice;
-
-                       for(int y = 0; y < destination.height && y < source.height; y++)
-                       {
-                               unsigned char *sourceElement = sourceRow;
-                               unsigned char *destinationElement = destinationRow;
-
-                               for(int x = 0; x < destination.width && x < source.width; x++)
-                               {
-                                       unsigned int rgb = *(unsigned short*)sourceElement;
-                                               
-                                       unsigned int r = (((rgb & 0xF800) * 67385 + 0x800000) >> 8) & 0x00FF0000;
-                                       unsigned int g = (((rgb & 0x07E0) * 8289  + 0x8000) >> 8) & 0x0000FF00;
-                                       unsigned int b = (((rgb & 0x001F) * 2106  + 0x80) >> 8);
-
-                                       *(unsigned int*)destinationElement = 0xFF000000 | r | g | b;
-
-                                       sourceElement += source.bytes;
-                                       destinationElement += destination.bytes;
-                               }
-
-                               sourceRow += source.pitchB;
-                               destinationRow += destination.pitchB;
-                       }
-
-                       sourceSlice += source.sliceB;
-                       destinationSlice += destination.sliceB;
-               }
-       }
-
        void Surface::decodeX1R5G5B5(Buffer &destination, const Buffer &source)
        {
                unsigned char *sourceSlice = (unsigned char*)source.buffer;
@@ -2460,6 +2421,7 @@ namespace sw
        {
                switch(format)
                {
+               case FORMAT_R5G6B5:
                case FORMAT_X8R8G8B8:
                case FORMAT_X8B8G8R8:
                case FORMAT_A8R8G8B8:
@@ -2507,6 +2469,7 @@ namespace sw
                switch(format)
                {
                case FORMAT_NULL:
+               case FORMAT_R5G6B5:
                case FORMAT_X8R8G8B8:
                case FORMAT_X8B8G8R8:
                case FORMAT_A8R8G8B8:
@@ -2686,30 +2649,31 @@ namespace sw
        {
                switch(format)
                {
-               case FORMAT_X8R8G8B8:           return 3;
-               case FORMAT_X8B8G8R8:           return 3;
-               case FORMAT_A8R8G8B8:           return 4;
-               case FORMAT_A8B8G8R8:           return 4;
-               case FORMAT_G8R8:                       return 2;
-               case FORMAT_G16R16:                     return 2;
-               case FORMAT_A16B16G16R16:       return 4;
-               case FORMAT_V8U8:                       return 2;
-               case FORMAT_Q8W8V8U8:           return 4;
-               case FORMAT_X8L8V8U8:           return 3;
-               case FORMAT_V16U16:                     return 2;
-               case FORMAT_A16W16V16U16:       return 4;
-               case FORMAT_Q16W16V16U16:       return 4;
-               case FORMAT_R32F:                       return 1;
-               case FORMAT_G32R32F:            return 2;
-               case FORMAT_A32B32G32R32F:      return 4;
-               case FORMAT_D32F_LOCKABLE:      return 1;
-               case FORMAT_D32FS8_TEXTURE:     return 1;
-               case FORMAT_D32FS8_SHADOW:      return 1;
-               case FORMAT_A8:                         return 1;
-               case FORMAT_R8:                         return 1;
-               case FORMAT_L8:                         return 1;
-               case FORMAT_L16:                        return 1;
-               case FORMAT_A8L8:                       return 2;
+               case FORMAT_R5G6B5:         return 3;
+               case FORMAT_X8R8G8B8:       return 3;
+               case FORMAT_X8B8G8R8:       return 3;
+               case FORMAT_A8R8G8B8:       return 4;
+               case FORMAT_A8B8G8R8:       return 4;
+               case FORMAT_G8R8:           return 2;
+               case FORMAT_G16R16:         return 2;
+               case FORMAT_A16B16G16R16:   return 4;
+               case FORMAT_V8U8:           return 2;
+               case FORMAT_Q8W8V8U8:       return 4;
+               case FORMAT_X8L8V8U8:       return 3;
+               case FORMAT_V16U16:         return 2;
+               case FORMAT_A16W16V16U16:   return 4;
+               case FORMAT_Q16W16V16U16:   return 4;
+               case FORMAT_R32F:           return 1;
+               case FORMAT_G32R32F:        return 2;
+               case FORMAT_A32B32G32R32F:  return 4;
+               case FORMAT_D32F_LOCKABLE:  return 1;
+               case FORMAT_D32FS8_TEXTURE: return 1;
+               case FORMAT_D32FS8_SHADOW:  return 1;
+               case FORMAT_A8:             return 1;
+               case FORMAT_R8:             return 1;
+               case FORMAT_L8:             return 1;
+               case FORMAT_L16:            return 1;
+               case FORMAT_A8L8:           return 2;
                case FORMAT_YV12_BT601:     return 3;
                case FORMAT_YV12_BT709:     return 3;
                case FORMAT_YV12_JFIF:      return 3;
@@ -3593,8 +3557,9 @@ namespace sw
                case FORMAT_R4G4B4A4:
                case FORMAT_A8B8G8R8:
                        return FORMAT_A8B8G8R8;
-               case FORMAT_R3G3B2:
                case FORMAT_R5G6B5:
+                       return FORMAT_R5G6B5;
+               case FORMAT_R3G3B2:
                case FORMAT_R8G8B8:
                case FORMAT_X4R4G4B4:
                case FORMAT_X1R5G5B5:
index 9860b6d..23a392d 100644 (file)
@@ -388,7 +388,6 @@ namespace sw
                };\r
 \r
                static void decodeR8G8B8(Buffer &destination, const Buffer &source);\r
-               static void decodeR5G6B5(Buffer &destination, const Buffer &source);\r
                static void decodeX1R5G5B5(Buffer &destination, const Buffer &source);\r
                static void decodeA1R5G5B5(Buffer &destination, const Buffer &source);\r
                static void decodeX4R4G4B4(Buffer &destination, const Buffer &source);\r