* Mirror/Flip for Image/Bitmap 4.x-dev

Wed, 07 Jul 2021 12:41:34 +0300

author
cemkalyoncu
date
Wed, 07 Jul 2021 12:41:34 +0300
branch
4.x-dev
changeset 1703
e7ba5162aabb
parent 1702
d68170da464d
child 1704
a0fdf33ceefe

* Mirror/Flip for Image/Bitmap

Source/Gorgon/Containers/Image.h file | annotate | diff | comparison | revisions
Source/Gorgon/Graphics/Bitmap.h file | annotate | diff | comparison | revisions
Testing/Source/Manual/Generic.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Containers/Image.h	Wed Jul 07 11:45:39 2021 +0300
+++ b/Source/Gorgon/Containers/Image.h	Wed Jul 07 12:41:34 2021 +0300
@@ -1113,6 +1113,50 @@
 
                 return target;
             }
+            
+            /// Mirrors this bitmap along X axis as a new one.
+            basic_Image MirrorX() const {
+                basic_Image target(size, GetMode());
+                int yy = size.Height - 1;
+                for(int y=0; y<size.Height; y++) {
+                    for(int x=0; x<size.Width; x++) {
+                        for(int c=0; c<cpp; c++) {
+                            target(x, y, c) = operator()(x, yy, c);
+                        }
+                    }
+                    
+                    yy--;
+                }
+                
+                return target;
+            }
+            
+            /// Mirrors this bitmap along Y axis as a new one.
+            basic_Image MirrorY() const {
+                basic_Image target(size, GetMode());
+                int xx = size.Width- 1;
+                for(int x=0; x<size.Width; x++) {
+                    for(int y=0; y<size.Height; y++) {
+                        for(int c=0; c<cpp; c++) {
+                            target(x, y, c) = operator()(xx, y, c);
+                        }
+                    }
+                    
+                    xx--;
+                }
+                
+                return target;
+            }
+
+            /// Flips this bitmap along X axis as a new one.
+            basic_Image FlipX() const {
+                return MirrorY();
+            }
+            
+            /// Flips this bitmap along Y axis as a new one.
+            basic_Image FlipY() const {
+                return MirrorX();
+            }
 
             /// Imports a given bitmap file. BMP RLE compression and colorspaces are not supported.
             bool ImportBMP(const std::string &filename, bool dib = false) {
--- a/Source/Gorgon/Graphics/Bitmap.h	Wed Jul 07 11:45:39 2021 +0300
+++ b/Source/Gorgon/Graphics/Bitmap.h	Wed Jul 07 12:41:34 2021 +0300
@@ -788,6 +788,46 @@
 			return ret;
 		}
 
+        /// Mirrors this bitmap along X axis as a new one using the supplied interpolation method.
+		Bitmap MirrorX() const {        
+			ASSERT(data, "Bitmap data is not set");
+
+			Bitmap ret;
+			ret.Assume(data->MirrorX());
+
+			return ret;
+		}
+
+        /// Mirrors this bitmap along Y axis as a new one using the supplied interpolation method.
+		Bitmap MirrorY() const {        
+			ASSERT(data, "Bitmap data is not set");
+
+			Bitmap ret;
+			ret.Assume(data->MirrorY());
+
+			return ret;
+		}
+
+        /// Flips this bitmap along X axis as a new one using the supplied interpolation method.
+		Bitmap FlipX() const {        
+			ASSERT(data, "Bitmap data is not set");
+
+			Bitmap ret;
+			ret.Assume(data->FlipX());
+
+			return ret;
+		}
+
+        /// Mirrors this bitmap along Y axis as a new one using the supplied interpolation method.
+		Bitmap FlipY() const {        
+			ASSERT(data, "Bitmap data is not set");
+
+			Bitmap ret;
+			ret.Assume(data->FlipY());
+
+			return ret;
+		}
+
 	protected:
 		/// When used as animation, an image is always persistent and it never finishes.
 		bool Progress(unsigned &) override { return true; }
--- a/Testing/Source/Manual/Generic.cpp	Wed Jul 07 11:45:39 2021 +0300
+++ b/Testing/Source/Manual/Generic.cpp	Wed Jul 07 12:41:34 2021 +0300
@@ -20,7 +20,7 @@
     Bitmap bmp;
     bmp.Import("../../Resources/Logo-large.png");
 
-    bmp = bmp.SkewY(0.2);
+    bmp = bmp.FlipX();
     bmp.Prepare();
 
     bmp.Draw(layer, 0,0);

mercurial