Browse Source

minor improves

dmuratshin 9 years ago
parent
commit
e5305f767d

+ 9 - 0
oxygine/src/AnimationFrame.cpp

@@ -79,4 +79,13 @@ namespace oxygine
         _srcRect.setY(_srcRect.getBottom());
         _srcRect.setY(_srcRect.getBottom());
         _srcRect.setHeight(-_srcRect.getHeight());
         _srcRect.setHeight(-_srcRect.getHeight());
     }
     }
+
+    AnimationFrame::AnimationFrame(spNativeTexture t)
+    {
+        _diffuse.base = t;
+        _diffuse.premultiplied = true;
+        _srcRect = RectF(0, 0, 1, 1);
+        _destRect = RectF(0, 0, t->getWidth(), t->getHeight());
+        _frameSize = Vector2(t->getWidth(), t->getHeight());
+    }
 }
 }

+ 1 - 0
oxygine/src/AnimationFrame.h

@@ -33,6 +33,7 @@ namespace oxygine
     {
     {
     public:
     public:
         AnimationFrame() : _srcRect(0, 0, 1, 1), _destRect(0, 0, 1, 1), _resAnim(0), _row(0), _column(0) {}
         AnimationFrame() : _srcRect(0, 0, 1, 1), _destRect(0, 0, 1, 1), _resAnim(0), _row(0), _column(0) {}
+        AnimationFrame(spNativeTexture t);
 
 
         void init(ResAnim* rs, const Diffuse& df,
         void init(ResAnim* rs, const Diffuse& df,
                   const RectF& srcRect, const RectF& destRect, const Vector2& frame_size);
                   const RectF& srcRect, const RectF& destRect, const Vector2& frame_size);

+ 7 - 0
oxygine/src/Image.cpp

@@ -555,6 +555,13 @@ namespace oxygine
         memset(&_buffer.front(), 0, _buffer.size());
         memset(&_buffer.front(), 0, _buffer.size());
     }
     }
 
 
+    void Image::fill(unsigned int val)
+    {
+        if (_buffer.empty())
+            return;
+        memset(&_buffer.front(), val, _buffer.size());
+    }
+
     bool Image::init(file::buffer& buffer, bool premultiplied, TextureFormat format)
     bool Image::init(file::buffer& buffer, bool premultiplied, TextureFormat format)
     {
     {
         cleanup();
         cleanup();

+ 1 - 0
oxygine/src/Image.h

@@ -35,6 +35,7 @@ namespace oxygine
         //void convert2pot(MemoryTexture &dest);
         //void convert2pot(MemoryTexture &dest);
 
 
         void fill_zero();
         void fill_zero();
+        void fill(unsigned int val);
 
 
         unsigned int    getSizeVRAM() const {return (unsigned int)_buffer.size();}
         unsigned int    getSizeVRAM() const {return (unsigned int)_buffer.size();}
         int             getWidth() const;
         int             getWidth() const;

+ 42 - 6
oxygine/src/core/ImageDataOperations.cpp

@@ -44,11 +44,42 @@ namespace oxygine
                 const unsigned char* srcLine = src.data;
                 const unsigned char* srcLine = src.data;
                 unsigned char* destLine = dest.data;
                 unsigned char* destLine = dest.data;
 
 
-                for (int h = 0; h < src.h; h++)
+                const int srch = src.h;
+                const int srcpitch = src.pitch;
+                const int destpitch = dest.pitch;
+                for (int h = 0; h < srch; h++)
                 {
                 {
                     memcpy(destLine, srcLine, bppPitch);
                     memcpy(destLine, srcLine, bppPitch);
-                    srcLine += src.pitch;
-                    destLine += dest.pitch;
+                    srcLine += srcpitch;
+                    destLine += destpitch;
+                }
+            }
+        }
+
+        void move(const ImageData& src, ImageData& dest)
+        {
+            if (!check(src, dest))
+                return;
+
+            OX_ASSERT(src.format == dest.format);
+
+            int bppPitch = src.w * src.bytespp;
+
+            if (src.pitch == dest.pitch && bppPitch == dest.pitch)
+                memmove(dest.data, src.data, bppPitch * src.h);
+            else
+            {
+                const unsigned char* srcLine = src.data;
+                unsigned char* destLine = dest.data;
+
+                const int srch = src.h;
+                const int srcpitch = src.pitch;
+                const int destpitch = dest.pitch;
+                for (int h = 0; h < srch; h++)
+                {
+                    memmove(destLine, srcLine, bppPitch);
+                    srcLine += srcpitch;
+                    destLine += destpitch;
                 }
                 }
             }
             }
         }
         }
@@ -81,11 +112,16 @@ namespace oxygine
 
 
             int bppPitch = src.w * src.bytespp;
             int bppPitch = src.w * src.bytespp;
 
 
-            for (int h = 0; h < src.h; h++)
+
+
+            const int srch = src.h;
+            const int srcpitch = src.pitch;
+            const int destpitch = dest.pitch;
+            for (int h = 0; h < srch; h++)
             {
             {
                 memcpy(destLine, srcLine, bppPitch);
                 memcpy(destLine, srcLine, bppPitch);
-                srcLine += src.pitch;
-                destLine -= dest.pitch;
+                srcLine += srcpitch;
+                destLine -= destpitch;
             }
             }
         }
         }
     }
     }

+ 5 - 0
oxygine/src/core/ImageDataOperations.h

@@ -6,7 +6,12 @@ namespace oxygine
 {
 {
     namespace operations
     namespace operations
     {
     {
+        //based on memcpy
         void copy(const ImageData& src, ImageData& dest);
         void copy(const ImageData& src, ImageData& dest);
+
+        //based on memmove, could be used for overlapped images, slower than copy
+        void move(const ImageData& src, ImageData& dest);
+
         void blit(const ImageData& src, ImageData& dest);
         void blit(const ImageData& src, ImageData& dest);
         void blitPremultiply(const ImageData& src, ImageData& dest);
         void blitPremultiply(const ImageData& src, ImageData& dest);
         void flipY(const ImageData& src, ImageData& dest);
         void flipY(const ImageData& src, ImageData& dest);

+ 10 - 0
oxygine/src/core/pixel.h

@@ -32,6 +32,16 @@ namespace oxygine
         return p;
         return p;
     }
     }
 
 
+    inline Pixel initPixel(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
+    {
+        Pixel p;
+        p.r = r;
+        p.g = g;
+        p.b = b;
+        p.a = a;
+        return p;
+    }
+
 
 
     class PixelA8
     class PixelA8
     {
     {