├── .gitignore ├── .gitmodules ├── Editor.meta ├── Editor ├── QoiImporter.cs └── QoiImporter.cs.meta ├── LICENSE ├── QoiSharp.meta ├── README.md ├── img.meta └── img ├── .gitignore ├── benchmarks.jpg ├── unity-cube.jpg ├── unity-logo.png └── unity_import.gif /.gitignore: -------------------------------------------------------------------------------- 1 | LICENSE.meta 2 | README.md.meta -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "QoiSharp"] 2 | path = QoiSharp 3 | url = https://github.com/Ben1138/QoiSharp 4 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db60699120cad0d4e8131c8f5a4cac13 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/QoiImporter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using UnityEngine; 4 | using UnityEditor; 5 | using UnityEditor.AssetImporters; 6 | 7 | 8 | [ScriptedImporter(1, "qoi")] 9 | public class QoiImporter : ScriptedImporter 10 | { 11 | public override void OnImportAsset(AssetImportContext ctx) 12 | { 13 | if (ctx.assetPath.EndsWith(".qoi", StringComparison.InvariantCultureIgnoreCase)) 14 | { 15 | FileStream stream = File.OpenRead(ctx.assetPath); 16 | if (stream == null) 17 | { 18 | ctx.LogImportError($"Failed to open QOI image file '{ctx.assetPath}'!"); 19 | return; 20 | } 21 | 22 | byte[] data = new byte[stream.Length]; 23 | stream.Read(data, 0, data.Length); 24 | 25 | QoiSharp.QoiImage img = QoiSharp.QoiDecoder.Decode(data); 26 | if (img == null) 27 | { 28 | ctx.LogImportError($"Failed to decode QOI image '{ctx.assetPath}'!"); 29 | return; 30 | } 31 | 32 | TextureFormat format; 33 | switch (img.Channels) 34 | { 35 | case QoiSharp.Codec.Channels.Rgb: 36 | { 37 | format = TextureFormat.RGB24; 38 | break; 39 | } 40 | case QoiSharp.Codec.Channels.RgbWithAlpha: 41 | { 42 | format = TextureFormat.RGBA32; 43 | break; 44 | } 45 | default: 46 | { 47 | ctx.LogImportError($"Unhandled QOI channel format '{img.Channels}'!"); 48 | return; 49 | } 50 | } 51 | 52 | bool bIsLinear = img.ColorSpace == QoiSharp.Codec.ColorSpace.Linear; 53 | Texture2D tex = new Texture2D(img.Width, img.Height, format, true, bIsLinear); 54 | 55 | int slashIdx = ctx.assetPath.LastIndexOf('/'); 56 | if (slashIdx < 0) 57 | { 58 | slashIdx = 0; 59 | } 60 | 61 | int dotIdx = ctx.assetPath.LastIndexOf('.'); 62 | Debug.Assert(dotIdx >= 0); 63 | 64 | tex.name = ctx.assetPath.Substring(slashIdx, dotIdx - slashIdx); 65 | 66 | tex.SetPixelData(img.Data, 0); 67 | if (format == TextureFormat.RGBA32) 68 | { 69 | tex.alphaIsTransparency = true; 70 | } 71 | tex.Apply(); 72 | 73 | stream.Close(); 74 | 75 | ctx.AddObjectToAsset(tex.name, tex, tex); 76 | ctx.SetMainObject(tex); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Editor/QoiImporter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9999d147bfbfc049b9e82df57f71e57 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ben 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /QoiSharp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e963116ec94d6ff43be5eca7e8387cc2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![QOI Logo](https://qoiformat.org/qoi-logo.svg) ![Unity Logo](img/unity-logo.png) 2 | 3 | # unity-qoi 4 | A simple Unity importer for [qoi, the "Quite OK Image" image format](https://github.com/phoboslab/qoi) for fast, lossless image compression. 5 | This importer utilises the [QoiSharp](https://github.com/NUlliiON/QoiSharp) implementation. 6 | 7 | ## Installation 8 | Download the lastest [Release (.unitypackage)](https://github.com/Ben1138/unity-qoi/releases) and drag-drop it into your project. 9 | 10 | Requires Unity 2021.1.x or newer! 11 | Importing the unitypackage on older versions will cause errors. 12 | 13 | ## About 14 | 15 | ![](img/unity_import.gif) 16 | ![Unity Logo](img/unity-cube.jpg) 17 | 18 | Qoi provides on-par compression with PNG, while being way faster at decoding (3x - 4x) and encoding (20x - 50x). 19 | [Benchmarks](https://youtu.be/EFUYNoFRHQI?t=1706) by [Reducible](https://www.youtube.com/c/Reducible) 20 | ![](img/benchmarks.jpg) 21 | -------------------------------------------------------------------------------- /img.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 386a4d22220f3de408574dcbcd9d03ff 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /img/.gitignore: -------------------------------------------------------------------------------- 1 | *.meta -------------------------------------------------------------------------------- /img/benchmarks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ben1138/unity-qoi/5cc2bc642b260c581648baf4cd4139b19306db52/img/benchmarks.jpg -------------------------------------------------------------------------------- /img/unity-cube.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ben1138/unity-qoi/5cc2bc642b260c581648baf4cd4139b19306db52/img/unity-cube.jpg -------------------------------------------------------------------------------- /img/unity-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ben1138/unity-qoi/5cc2bc642b260c581648baf4cd4139b19306db52/img/unity-logo.png -------------------------------------------------------------------------------- /img/unity_import.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ben1138/unity-qoi/5cc2bc642b260c581648baf4cd4139b19306db52/img/unity_import.gif --------------------------------------------------------------------------------