diff --git a/JAR Source/TextureOps.java b/.github/JAR Source/TextureOps.java similarity index 100% rename from JAR Source/TextureOps.java rename to .github/JAR Source/TextureOps.java diff --git a/README.md b/.github/README.md similarity index 86% rename from README.md rename to .github/README.md index 4e09aba..fe3f009 100644 --- a/README.md +++ b/.github/README.md @@ -2,9 +2,13 @@ ![SlidingPuzzleExample](screenshots/1.jpg) -This plugin helps you save/load textures and perform simple operations on them, like scale and slice. It also contains an example sliding puzzle project to demonstrate the slice operation. +**Forum Thread:** https://forum.unity.com/threads/texture-ops-a-basic-image-processing-plugin-for-unity-open-source.539065/ + +**[Support the Developer ☕](https://yasirkula.itch.io/unity3d)** + +## ABOUT -[Support the Developer ☕](https://yasirkula.itch.io/unity3d) +This plugin helps you save/load textures and perform simple operations on them, like scale and slice. It also contains an example sliding puzzle project to demonstrate the slice operation. ### iOS Setup @@ -16,9 +20,16 @@ iOS setup is normally handled automatically via a post processor script but, if ![OtherLinkerFlags](screenshots/2.png) -## How To +## INSTALLATION + +There are 3 ways to install this plugin: + +- import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextureOps/releases) via *Assets-Import Package* +- clone/[download](https://github.com/yasirkula/UnityTextureOps/archive/master.zip) this repository and move the *Plugins* folder to your Unity project's *Assets* folder +- *(via Package Manager)* add the following line to *Packages/manifest.json*: + - `"com.yasirkula.textureops": "https://github.com/yasirkula/UnityTextureOps.git",` -Simply import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextureOps/releases) to your project and you are good to go! +## HOW TO **NOTE:** functions that return a *Texture2D* or *Texture2D[]* may return *null*, if something goes wrong. @@ -42,7 +53,7 @@ Simply import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextur **NOTE:** on some Android devices, these functions may not work correctly when called with a *sourceTex* that was created in the same frame. Therefore, if you'd like to call these functions immediately after *LoadImage*, consider instead waiting for at least one frame. You can use `yield return null;` in a coroutine to wait for one frame. -`Texture2D[] TextureOps.Crop( Texture2D, sourceTex, int leftOffset, int topOffset, int width, int height, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options )`: crops sourceTex and returns the cropped texture. +`Texture2D TextureOps.Crop( Texture2D, sourceTex, int leftOffset, int topOffset, int width, int height, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options )`: crops *sourceTex* and returns the cropped texture. `Texture2D TextureOps.Scale( Texture2D sourceTex, int targetWidth, int targetHeight, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options )`: scales *sourceTex* to the specified size and returns the scaled texture. sourceTex's aspect ratio may not be preserved. @@ -56,7 +67,7 @@ Simply import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextur `TextureOps.VideoProperties TextureOps.GetVideoProperties( string videoPath )`: *[Android & iOS only]* returns a *VideoProperties* instance that holds the width, height, duration (in milliseconds) and rotation information of a video file. To play a video in correct orientation, you should rotate it by *rotation* degrees clockwise. For a 90-degree or 270-degree rotated video, values of *width* and *height* should be swapped to get the display size of the video. -## Example Code +## EXAMPLE CODE The following code loads "*DESKTOP_DIR/image.jpeg*" into a Texture, applies *TextureOps.ScaleFill* to it and then saves it as "*DESKTOP_DIR/image_new.jpeg*". See *SlidePuzzleScene* demo scene for an example usage of *TextureOps.Slice*. diff --git a/screenshots/1.jpg b/.github/screenshots/1.jpg similarity index 100% rename from screenshots/1.jpg rename to .github/screenshots/1.jpg diff --git a/screenshots/2.png b/.github/screenshots/2.png similarity index 100% rename from screenshots/2.png rename to .github/screenshots/2.png diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/LICENSE.txt.meta b/LICENSE.txt.meta new file mode 100644 index 0000000..8728baa --- /dev/null +++ b/LICENSE.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5f7a133139c5f1a4bb73c0bd9a3e27b3 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins.meta b/Plugins.meta new file mode 100644 index 0000000..de33855 --- /dev/null +++ b/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b52064d39b9b98c44ac04296543f0d70 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/TextureOps/Editor/TextureOps.Editor.asmdef b/Plugins/TextureOps/Editor/TextureOps.Editor.asmdef new file mode 100644 index 0000000..f7a123f --- /dev/null +++ b/Plugins/TextureOps/Editor/TextureOps.Editor.asmdef @@ -0,0 +1,15 @@ +{ + "name": "TextureOps.Editor", + "references": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Plugins/TextureOps/Editor/TextureOps.Editor.asmdef.meta b/Plugins/TextureOps/Editor/TextureOps.Editor.asmdef.meta new file mode 100644 index 0000000..e234982 --- /dev/null +++ b/Plugins/TextureOps/Editor/TextureOps.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3fcb67fb12a5cef4aa29e87f3e42510d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/TextureOps/README.txt b/Plugins/TextureOps/README.txt index bdb1801..a16f509 100644 --- a/Plugins/TextureOps/README.txt +++ b/Plugins/TextureOps/README.txt @@ -33,6 +33,7 @@ Texture2D TextureOps.LoadImage( string imagePath, int maxSize = -1, TextureOps.O //// TEXTURE OPERATIONS //// // NOTE: on some Android devices, these functions may not work correctly when called with a 'sourceTex' that was created in the same frame. Therefore, if you'd like to call these functions immediately after 'LoadImage', consider instead waiting for at least one frame. You can use `yield return null;` in a coroutine to wait for one frame. +Texture2D TextureOps.Crop( Texture2D, sourceTex, int leftOffset, int topOffset, int width, int height, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): crops sourceTex and returns the cropped texture. Texture2D TextureOps.Scale( Texture2D sourceTex, int targetWidth, int targetHeight, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): scales sourceTex to the specified size and returns the scaled texture. sourceTex's aspect ratio may not be preserved. Texture2D TextureOps.ScaleFill( Texture2D sourceTex, int targetWidth, int targetHeight, Color32 fillColor, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): scales sourceTex to the specified size and returns the scaled texture. sourceTex's aspect ratio is preserved and blank space is filled with fillColor. Texture2D[] TextureOps.Slice( Texture2D sourceTex, int sliceTexWidth, int sliceTexHeight, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): slices sourceTex into smaller textures and returns these textures in an array. sourceTex is sliced row-by-row, starting from top-left corner. diff --git a/Plugins/TextureOps/TextureOps.Runtime.asmdef b/Plugins/TextureOps/TextureOps.Runtime.asmdef new file mode 100644 index 0000000..920436f --- /dev/null +++ b/Plugins/TextureOps/TextureOps.Runtime.asmdef @@ -0,0 +1,3 @@ +{ + "name": "TextureOps.Runtime" +} diff --git a/Plugins/TextureOps/TextureOps.Runtime.asmdef.meta b/Plugins/TextureOps/TextureOps.Runtime.asmdef.meta new file mode 100644 index 0000000..e905522 --- /dev/null +++ b/Plugins/TextureOps/TextureOps.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0bc4c2c548993744697bb354a36f323a +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/TextureOps/TextureOps.cs b/Plugins/TextureOps/TextureOps.cs index 7a4f9dc..5167cfb 100644 --- a/Plugins/TextureOps/TextureOps.cs +++ b/Plugins/TextureOps/TextureOps.cs @@ -251,15 +251,17 @@ public static bool SaveImage( byte[] sourceBytes, string imagePath ) { if( sourceTex == null ) throw new ArgumentException( "Parameter 'sourceTex' is null!" ); - + if( width <= 0 || width > sourceTex.width ) width = sourceTex.width; if( height <= 0 || height > sourceTex.height ) height = sourceTex.height; + if( leftOffset <= 0 ) leftOffset = 0; else if( leftOffset + width > sourceTex.width ) leftOffset = sourceTex.width - width; + if( topOffset <= 0 ) topOffset = 0; else if( topOffset + height > sourceTex.height ) @@ -294,7 +296,7 @@ public static bool SaveImage( byte[] sourceBytes, string imagePath ) return result; } - + public static Texture2D Scale( Texture sourceTex, int targetWidth, int targetHeight, TextureFormat format = TextureFormat.RGBA32, Options options = new Options() ) { if( sourceTex == null ) @@ -377,7 +379,7 @@ public static bool SaveImage( byte[] sourceBytes, string imagePath ) return result; } - + public static Texture2D[] Slice( Texture sourceTex, int sliceTexWidth, int sliceTexHeight, TextureFormat format = TextureFormat.RGBA32, Options options = new Options() ) { if( sourceTex == null ) diff --git a/package.json b/package.json new file mode 100644 index 0000000..fdb879b --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "name": "com.yasirkula.textureops", + "displayName": "Texture Ops", + "version": "1.1.0", + "description": "This plugin helps you save/load textures and perform simple operations on them, like scale and slice. It also contains an example sliding puzzle project to demonstrate the slice operation." +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..f6f3eed --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 164558404a4434c418eb059f520d5a25 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: