Преглед изворни кода

Added success return value to Image::FlipVertical(). Fixed return value of Image::Resize() in AngelScript bindings.

Lasse Öörni пре 11 година
родитељ
комит
6f980453b6

+ 1 - 1
Source/Engine/LuaScript/pkgs/Resource/Image.pkg

@@ -26,7 +26,7 @@ class Image : public Resource
     void SetPixelInt(int x, int y, int z, unsigned uintColor);
     bool LoadColorLUT(Deserializer& source);
     tolua_outside bool ImageLoadColorLUT @ LoadColorLUT(const String fileName);
-    void FlipVertical();
+    bool FlipVertical();
     bool Resize(int width, int height);
     void Clear(const Color& color);
     void ClearInt(unsigned uintColor);

+ 7 - 5
Source/Engine/Resource/Image.cpp

@@ -649,15 +649,15 @@ bool Image::LoadColorLUT(Deserializer& source)
     return true;
 }
 
-void Image::FlipVertical()
+bool Image::FlipVertical()
 {
     if (!data_)
-        return;
+        return false;
 
     if (depth_ > 1)
     {
         LOGERROR("FlipVertical not supported for 3D images");
-        return;
+        return false;
     }
 
     if (!IsCompressed())
@@ -675,7 +675,7 @@ void Image::FlipVertical()
         if (compressedFormat_ > CF_DXT5)
         {
             LOGERROR("FlipVertical not yet implemented for other compressed formats than DXT1,3,5");
-            return;
+            return false;
         }
         
         // Memory use = combined size of the compressed mip levels
@@ -688,7 +688,7 @@ void Image::FlipVertical()
             if (!level.data_)
             {
                 LOGERROR("Got compressed level with no data, aborting vertical flip");
-                return;
+                return false;
             }
             
             for (unsigned y = 0; y < level.rows_; ++y)
@@ -705,6 +705,8 @@ void Image::FlipVertical()
         
         data_ = newData;
     }
+    
+    return true;
 }
 
 bool Image::Resize(int width, int height)

+ 2 - 2
Source/Engine/Resource/Image.h

@@ -119,8 +119,8 @@ public:
     void SetPixelInt(int x, int y, int z, unsigned uintColor);
     /// Load as color LUT. Return true if successful.
     bool LoadColorLUT(Deserializer& source);
-    /// Flip image vertically.
-    void FlipVertical();
+    /// Flip image vertically. Return true if successful.
+    bool FlipVertical();
     /// Resize image by bilinear resampling. Return true if successful.
     bool Resize(int width, int height);
     /// Clear the image with a color.

+ 2 - 2
Source/Engine/Script/ResourceAPI.cpp

@@ -162,8 +162,8 @@ static void RegisterImage(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Image", "void SetPixelInt(int, int, int, uint)", asMETHODPR(Image, SetPixelInt, (int, int, int, unsigned), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Image", "bool LoadColorLUT(File@+)", asFUNCTION(ImageLoadColorLUT), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Image", "bool LoadColorLUT(VectorBuffer&)", asFUNCTION(ImageLoadColorLUTVectorBuffer), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Image", "void FlipVertical()", asMETHOD(Image, FlipVertical), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Image", "void Resize(int, int)", asMETHOD(Image, Resize), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Image", "bool FlipVertical()", asMETHOD(Image, FlipVertical), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Image", "bool Resize(int, int)", asMETHOD(Image, Resize), asCALL_THISCALL);
     engine->RegisterObjectMethod("Image", "void Clear(const Color&in)", asMETHOD(Image, Clear), asCALL_THISCALL);
     engine->RegisterObjectMethod("Image", "void ClearInt(uint)", asMETHOD(Image, ClearInt), asCALL_THISCALL);
     engine->RegisterObjectMethod("Image", "void SaveBMP(const String&in) const", asMETHOD(Image, SaveBMP), asCALL_THISCALL);