Пример #1
0
 void UpdateTransformSettings(SmartObjectLayer layer)
 {
     CropNone.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
     CropFit.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
     CropCover.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
     SamplingNearestNeighbour.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
     SamplingBilinear.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
     SamplingBicubic.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
     if (layer.Crop == null)
     {
         CropNone.GetComponent <CanvasRenderer>().SetAlpha(1f);
     }
     else if (layer.Crop.GetType() == typeof(Fit))
     {
         CropFit.GetComponent <CanvasRenderer>().SetAlpha(1f);
     }
     else if (layer.Crop.GetType() == typeof(Cover))
     {
         CropCover.GetComponent <CanvasRenderer>().SetAlpha(1f);
     }
     if (layer.Resampler.GetType() == typeof(NearestNeighbourSampling))
     {
         SamplingNearestNeighbour.GetComponent <CanvasRenderer>().SetAlpha(1f);
     }
     if (layer.Resampler.GetType() == typeof(BillinearSampling))
     {
         SamplingBilinear.GetComponent <CanvasRenderer>().SetAlpha(1f);
     }
     if (layer.Resampler.GetType() == typeof(BicubicSampling))
     {
         SamplingBicubic.GetComponent <CanvasRenderer>().SetAlpha(1f);
     }
 }
Пример #2
0
    private void ImportImage()
    {
        Controller.Instance.Popup.SetText("Please select any <#FF6666>Image<#FFFFFF> file to import.", false, () => {
            StandaloneFileBrowser.OpenFilePanelAsync("Import image", "", new ExtensionFilter[] { new ExtensionFilter("Image", new string[] { "png", "jpg", "jpeg", "bmp", "gif" }) }, false, (path) =>
            {
                if (path.Length > 0)
                {
                    try
                    {
                        int x        = 0;
                        int y        = 0;
                        int width    = Editor.CurrentPattern.CurrentSubPattern.Width;
                        int height   = Editor.CurrentPattern.CurrentSubPattern.Height;
                        var bmp      = TextureBitmap.Load(path[0]);
                        var newLayer = new SmartObjectLayer(Editor.CurrentPattern.CurrentSubPattern, System.IO.Path.GetFileNameWithoutExtension(path[0]), bmp, x, y, width, height);
                        newLayer.UpdateColors();
                        var index = Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(Editor.CurrentPattern.CurrentSubPattern.SelectedLayer) + 1;
                        Editor.CurrentPattern.CurrentSubPattern.Layers.Insert(index, newLayer);
                        Editor.CurrentPattern.CurrentSubPattern.SelectedLayer = newLayer;
                        Editor.LayersChanged();
                        Editor.CurrentPattern.CurrentSubPattern.SelectLayer(newLayer);
                        Editor.CurrentPattern.CurrentSubPattern.UpdateImage();

                        Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.LayerCreatedAction("Created: " + newLayer.Name, index, newLayer));

                        Controller.Instance.Popup.Close();
                    }
                    catch (System.IO.FileLoadException e)
                    {
                        Debug.LogException(e);
                        Controller.Instance.Popup.SetText("Failed to load the file. File error.", false, () =>
                        {
                            return(true);
                        });
                        return;
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogException(e);
                        Controller.Instance.Popup.SetText("Invalid image file.", false, () =>
                        {
                            return(true);
                        });
                        return;
                    }
                }
                else
                {
                    Controller.Instance.Popup.Close();
                }
            });
            return(false);
        });
    }
Пример #3
0
 public override void RestorerForward(History history)
 {
     if (this.Bitmap != null)
     {
         var newLayer = new SmartObjectLayer(history.SubPattern, this.LayerName, this.Bitmap, this.ObjectX, this.ObjectY, this.ObjectWidth, this.ObjectHeight);
         newLayer.Bitmap = Bitmap.Clone();
         history.SubPattern.Layers.Insert(this.LayerIndex, newLayer);
     }
     else
     {
         var newLayer = new RasterLayer(history.SubPattern, this.LayerName);
         newLayer.Texture.CopyFrom(Colors);
         history.SubPattern.Layers.Insert(this.LayerIndex, newLayer);
     }
 }
        //ExStart:SupportCustomSmartFilterRenderer
        //ExSummary:The following code shows you how to create a custom smart filter that has a custom renderer.

        public static void CustomSmartFilterExample(string sourceFile = "psdnet1057.psd", string outputPsd = "out_psdnet1057.psd", string outputPng = "out_psdnet1057.png")
        {
            // Inits the unsupported 'Crystallize' smart filter at input array
            SmartFilter[] InitUnknownSmartFilters(SmartFilter[] smartFilters)
            {
                // the 'Crystallize' smart filter ID.
                int id = 1131574132;

                for (int i = 0; i < smartFilters.Length; i++)
                {
                    var smartFilter = smartFilters[i];
                    if (smartFilter is UnknownSmartFilter && smartFilter.FilterId == id)
                    {
                        var customSmartFilterInstance = new CustomSmartFilterWithRenderer();
                        customSmartFilterInstance.SourceDescriptor.Structures = smartFilter.SourceDescriptor.Structures;
                        smartFilters[i] = customSmartFilterInstance;
                    }
                }

                return(smartFilters);
            }

            using (var image = (PsdImage)Image.Load(sourceFile))
            {
                SmartObjectLayer smartLayer   = (SmartObjectLayer)image.Layers[1];
                Layer            maskLayer    = image.Layers[2];
                Layer            regularLayer = image.Layers[3];

                smartLayer.SmartFilters.Filters = InitUnknownSmartFilters(smartLayer.SmartFilters.Filters);
                var smartFilter = smartLayer.SmartFilters.Filters[0];

                // Apply filter to SmartObject
                smartLayer.UpdateModifiedContent();
                smartLayer.SmartFilters.UpdateResourceValues();

                // Apply filter to layer mask
                smartFilter.ApplyToMask(maskLayer);

                //Apply filter to layer
                smartFilter.Apply(regularLayer);

                image.Save(outputPsd);
                image.Save(outputPng, new PngOptions());
            }
        }
Пример #5
0
    void UpdateTransformSettings(SmartObjectLayer layer)
    {
        CropNone.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        CropFit.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        CropCover.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        SamplingBox.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        SamplingLanczos8.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        SamplingMitchell.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        SamplingCosine.GetComponent <CanvasRenderer>().SetAlpha(0.5f);
        SamplingCubicConvolution.GetComponent <CanvasRenderer>().SetAlpha(0.5f);

        if (layer.Crop == TextureBitmap.CropMode.Scale)
        {
            CropNone.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        else if (layer.Crop == TextureBitmap.CropMode.Fit)
        {
            CropFit.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        else if (layer.Crop == TextureBitmap.CropMode.Cover)
        {
            CropCover.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        if (layer.Resampler == ResamplingFilters.Box)
        {
            SamplingBox.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        if (layer.Resampler == ResamplingFilters.Lanczos8)
        {
            SamplingLanczos8.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        if (layer.Resampler == ResamplingFilters.Mitchell)
        {
            SamplingMitchell.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        if (layer.Resampler == ResamplingFilters.CubicConvolution)
        {
            SamplingCubicConvolution.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
        if (layer.Resampler == ResamplingFilters.Cosine)
        {
            SamplingCosine.GetComponent <CanvasRenderer>().SetAlpha(1f);
        }
    }
        public static void Run()
        {
            //ExStart:SupportOfReplaceContentsInSmartObjects

            // This example demonstrates that the ReplaceContents method works correctly when the new content file has a different resolution.

            // The path to the documents directory.
            string SourceDir = RunExamples.GetDataDir_PSD();
            string OutputDir = RunExamples.GetDataDir_Output();

            string fileName       = "CommonPsb.psd";
            string filePath       = SourceDir + fileName;    // original PSD image
            string newContentPath = SourceDir + "image.jpg"; // the new content file for the smart object
            string outputFilePath = OutputDir + "ChangedPsd";
            string pngOutputPath  = outputFilePath + ".png"; // the output PNG file
            string psdOutputPath  = outputFilePath + ".psd"; // the output PSD file

            using (PsdImage psd = (PsdImage)Image.Load(filePath))
            {
                for (int i = 0; i < psd.Layers.Length; i++)
                {
                    var layer = psd.Layers[i];
                    SmartObjectLayer smartObjectLayer = layer as SmartObjectLayer;
                    if (smartObjectLayer != null)
                    {
                        smartObjectLayer.ReplaceContents(newContentPath);

                        psd.Save(psdOutputPath);
                        psd.Save(pngOutputPath, new PngOptions()
                        {
                            ColorType = PngColorType.TruecolorWithAlpha
                        });
                    }
                }
            }

            //ExEnd:SupportOfReplaceContentsInSmartObjects

            File.Delete(psdOutputPath);
            File.Delete(pngOutputPath);

            Console.WriteLine("SupportOfReplaceContentsInSmartObjects executed successfully");
        }
Пример #7
0
        public override void RestoreBackward(History history)
        {
            var copy = new Color[Colors.Length];

            Array.Copy(Colors, copy, copy.Length);
            if (this.Bitmap != null)
            {
                var newLayer = new SmartObjectLayer(history.SubPattern, this.LayerName, this.Bitmap, this.ObjectX, this.ObjectY, this.ObjectWidth, this.ObjectHeight);
                newLayer.Colors = copy;
                //newLayer.UpdateColors();
                history.SubPattern.Layers.Insert(this.LayerIndex, newLayer);
            }
            else
            {
                var newLayer = new RasterLayer(history.SubPattern, this.LayerName);
                newLayer.Colors = copy;
                history.SubPattern.Layers.Insert(this.LayerIndex, newLayer);
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string SourceDir = RunExamples.GetDataDir_PSD();
            string OutputDir = RunExamples.GetDataDir_Output();

            //ExStart:SupportAccessToSmartFilters
            //ExSummary:This example demonstrates the support of the smart filters interface.

            string sourceFilte = Path.Combine(SourceDir, "r2_SmartFilters.psd");
            string outputPsd   = Path.Combine(OutputDir, "out_r2_SmartFilters.psd");

            void AssertAreEqual(object expected, object actual)
            {
                if (!object.Equals(expected, actual))
                {
                    throw new Exception("Objects are not equal.");
                }
            }

            using (var image = (PsdImage)Image.Load(sourceFilte))
            {
                SmartObjectLayer smartObj = (SmartObjectLayer)image.Layers[1];

                // edit smart filters
                GaussianBlurSmartFilter gaussianBlur = (GaussianBlurSmartFilter)smartObj.SmartFilters.Filters[0];

                // check filter values
                AssertAreEqual(3.1, gaussianBlur.Radius);
                AssertAreEqual(BlendMode.Dissolve, gaussianBlur.BlendMode);
                AssertAreEqual(90d, gaussianBlur.Opacity);
                AssertAreEqual(true, gaussianBlur.IsEnabled);

                // update filter values
                gaussianBlur.Radius    = 1;
                gaussianBlur.BlendMode = BlendMode.Divide;
                gaussianBlur.Opacity   = 75;
                gaussianBlur.IsEnabled = false;
                AddNoiseSmartFilter addNoise = (AddNoiseSmartFilter)smartObj.SmartFilters.Filters[1];
                addNoise.Distribution = NoiseDistribution.Uniform;

                // add new filter items
                var filters = new List <SmartFilter>(smartObj.SmartFilters.Filters);
                filters.Add(new GaussianBlurSmartFilter());
                filters.Add(new AddNoiseSmartFilter());
                smartObj.SmartFilters.Filters = filters.ToArray();

                // apply changes
                smartObj.SmartFilters.UpdateResourceValues();

                // Apply filters
                smartObj.SmartFilters.Filters[0].Apply(image.Layers[2]);
                smartObj.SmartFilters.Filters[4].ApplyToMask(image.Layers[2]);

                image.Save(outputPsd);
            }

            using (var image = (PsdImage)Image.Load(outputPsd))
            {
                SmartObjectLayer smartObj = (SmartObjectLayer)image.Layers[1];

                GaussianBlurSmartFilter gaussianBlur = (GaussianBlurSmartFilter)smartObj.SmartFilters.Filters[0];

                // check filter values
                AssertAreEqual(1d, gaussianBlur.Radius);
                AssertAreEqual(BlendMode.Divide, gaussianBlur.BlendMode);
                AssertAreEqual(75d, gaussianBlur.Opacity);
                AssertAreEqual(false, gaussianBlur.IsEnabled);

                AssertAreEqual(true, smartObj.SmartFilters.Filters[5] is GaussianBlurSmartFilter);
                AssertAreEqual(true, smartObj.SmartFilters.Filters[6] is AddNoiseSmartFilter);
            }

            //ExEnd:SupportAccessToSmartFilters

            Console.WriteLine("SupportAccessToSmartFilters executed successfully");

            File.Delete(outputPsd);
        }
Пример #9
0
    public void FromBytes(byte[] bytes)
    {
        using (MemoryStream stream = new MemoryStream(bytes))
        {
            BinaryReader reader  = new BinaryReader(stream);
            byte         version = reader.ReadByte();
            if (version == 0x00)
            {
                var t = (DesignPattern.TypeEnum)reader.ReadByte();
                if (this._Type == DesignPattern.TypeEnum.SimplePattern && t != DesignPattern.TypeEnum.SimplePattern)
                {
                    throw new ArgumentException("Simple design spot can't hold pro design.", "project");
                }
                if (this._Type != DesignPattern.TypeEnum.SimplePattern && t == DesignPattern.TypeEnum.SimplePattern)
                {
                    throw new ArgumentException("Pro design spot can't hold simple design.", "project");
                }
                this._Type = t;
                Quantizer  = Quantizers[reader.ReadByte()];
                ColorCache = ColorCaches[reader.ReadByte()];

                var info = DesignPatternInformation.Types[this._Type];
                this.SubPatterns = new List <SubPattern>();
                for (int i = 0; i < info.Parts.Count; i++)
                {
                    var subPattern = new SubPattern(this, info.Parts[i], true);
                    this.SubPatterns.Add(subPattern);

                    int layerCount = reader.ReadByte();
                    for (int j = 0; j < layerCount; j++)
                    {
                        var layerType = reader.ReadByte();
                        if (layerType == 0x01)
                        {
                            int    objectX      = reader.ReadInt32();
                            int    objectY      = reader.ReadInt32();
                            int    objectW      = reader.ReadInt32();
                            int    objectH      = reader.ReadInt32();
                            byte   crop         = reader.ReadByte();
                            byte   resampling   = reader.ReadByte();
                            int    nameLength   = reader.ReadInt32();
                            string name         = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
                            int    bitmapWidth  = reader.ReadInt32();
                            int    bitmapHeight = reader.ReadInt32();
                            byte[] bitmapPixels = reader.ReadBytes(bitmapWidth * bitmapHeight * 4);
                            var    bitmap       = new System.Drawing.Bitmap(bitmapWidth, bitmapHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            bitmap.FromBytes(bitmapPixels);
                            SmartObjectLayer layer = new SmartObjectLayer(subPattern, name, bitmap, objectX, objectY, objectW, objectH);
                            subPattern.Layers.Add(layer);
                            layer.Crop      = SmartObjectLayer.Crops[crop];
                            layer.Resampler = SmartObjectLayer.Resamplers[resampling];
                            layer.Colors    = new UnityEngine.Color[layer.Width * layer.Height];
                            layer.UpdateColors();
                            layer.UpdateTexture();
                        }
                        else if (layerType == 0x00)
                        {
                            int         nameLength = reader.ReadInt32();
                            string      name       = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
                            RasterLayer layer      = new RasterLayer(subPattern, name);
                            layer.Colors = new UnityEngine.Color[layer.Width * layer.Height];
                            for (int y = 0; y < layer.Height; y++)
                            {
                                for (int x = 0; x < layer.Width; x++)
                                {
                                    layer.Colors[x + y * layer.Width] = new UnityEngine.Color(reader.ReadByte() / 255f, reader.ReadByte() / 255f, reader.ReadByte() / 255f, reader.ReadByte() / 255f);
                                }
                            }
                            layer.UpdateTexture();
                            subPattern.Layers.Add(layer);
                        }
                    }
                }
            }
        }
        _CurrentSubPattern = 0;
        Editor.SetSize(CurrentSubPattern.Width, CurrentSubPattern.Height);
        Editor.LayersChanged();
        Editor.SubPatternChanged(CurrentSubPattern.Part);
        Editor.SetType(this._Type);
        Editor.Show(null, null, null);
        Editor.OnImageUpdated();
        Editor.Tools.HistoryChanged(CurrentSubPattern.History);
        for (int i = 0; i < SubPatterns.Count; i++)
        {
            SubPatterns[i].UpdateImage(false);
        }
        this.RegeneratePreview();
    }
Пример #10
0
    private void ImportImage()
    {
        Controller.Instance.Popup.SetText("Please select any <#FF6666>Image<#FFFFFF> file to import.", false, () => {
            StandaloneFileBrowser.OpenFilePanelAsync("Import image", "", new ExtensionFilter[] { new ExtensionFilter("Image", new string[] { "png", "jpg", "jpeg", "bmp", "gif" }) }, false, (path) =>
            {
                if (path.Length > 0)
                {
                    try
                    {
                        System.Drawing.Bitmap bmp = null;
                        var imageStream           = new System.IO.FileStream(path[0], System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        byte[] fourBytes          = new byte[4];
                        imageStream.Read(fourBytes, 0, 4);
                        if (fourBytes[0] == 0x52 && fourBytes[1] == 0x49 && fourBytes[2] == 0x46 && fourBytes[3] == 0x46)
                        {
                            var bytes = System.IO.File.ReadAllBytes(path[0]);
                            int webpWidth;
                            int webpHeight;
                            WebP.Error error;
                            WebP.Texture2DExt.GetWebPDimensions(bytes, out webpWidth, out webpHeight);
                            var colorData = WebP.Texture2DExt.LoadRGBAFromWebP(bytes, ref webpWidth, ref webpHeight, false, out error);
                            bmp           = new System.Drawing.Bitmap(webpWidth, webpHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            bmp.FromBytes(colorData);

                            /*using (WebP webp = new WebP())
                             *      bmp = webp.Load(path[0]);*/
                            imageStream.Close();
                            imageStream.Dispose();
                        }
                        else
                        {
                            bmp = new System.Drawing.Bitmap(System.Drawing.Image.FromFile(path[0]));
                            imageStream.Close();
                            imageStream.Dispose();
                        }
                        int x           = 0;
                        int y           = 0;
                        int width       = Editor.CurrentPattern.CurrentSubPattern.Width;
                        int height      = Editor.CurrentPattern.CurrentSubPattern.Height;
                        var newLayer    = new SmartObjectLayer(Editor.CurrentPattern.CurrentSubPattern, System.IO.Path.GetFileNameWithoutExtension(path[0]), bmp, x, y, width, height);
                        newLayer.Colors = new UnityEngine.Color[width * height];
                        newLayer.UpdateColors();
                        var index = Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(Editor.CurrentPattern.CurrentSubPattern.SelectedLayer) + 1;
                        Editor.CurrentPattern.CurrentSubPattern.Layers.Insert(index, newLayer);
                        Editor.CurrentPattern.CurrentSubPattern.SelectedLayer = newLayer;
                        Editor.LayersChanged();
                        Editor.CurrentPattern.CurrentSubPattern.SelectLayer(newLayer);
                        Editor.CurrentPattern.CurrentSubPattern.UpdateImage();

                        Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.LayerCreatedAction("Created: " + newLayer.Name, index, newLayer));

                        Controller.Instance.Popup.Close();
                    }
                    catch (System.IO.FileLoadException e)
                    {
                        Debug.LogException(e);
                        Controller.Instance.Popup.SetText("Failed to load the file. File error.", false, () =>
                        {
                            return(true);
                        });
                        return;
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogException(e);
                        Controller.Instance.Popup.SetText("Invalid image file.", false, () =>
                        {
                            return(true);
                        });
                        return;
                    }
                }
                else
                {
                    Controller.Instance.Popup.Close();
                }
            });
            return(false);
        });
    }
Пример #11
0
    public Pattern(PatternEditor editor, byte[] bytes)
    {
        try
        {
            Editor = editor;

            using (MemoryStream stream = new MemoryStream(bytes))
            {
                BinaryReader reader  = new BinaryReader(stream);
                byte         version = reader.ReadByte();
                var          t       = (DesignPattern.TypeEnum)reader.ReadByte();
                if (!Editor.IsPro && t != DesignPattern.TypeEnum.SimplePattern)
                {
                    throw new ArgumentException("Simple design spot can't hold pro design.", "project");
                }
                if (Editor.IsPro && t == DesignPattern.TypeEnum.SimplePattern)
                {
                    throw new ArgumentException("Pro design spot can't hold simple design.", "project");
                }
                this._Type = t;
                Quantizer  = Quantizers[reader.ReadByte()];
                ColorCache = ColorCaches[reader.ReadByte()];

                var info = DesignPatternInformation.Types[this._Type];
                this.SubPatterns = new List <SubPattern>();
                for (int i = 0; i < info.Parts.Count; i++)
                {
                    var subPattern = new SubPattern(this, info.Parts[i], true);
                    this.SubPatterns.Add(subPattern);

                    int layerCount = reader.ReadByte();
                    for (int j = 0; j < layerCount; j++)
                    {
                        var layerType = reader.ReadByte();
                        if (layerType == 0x01)
                        {
                            int    objectX      = reader.ReadInt32();
                            int    objectY      = reader.ReadInt32();
                            int    objectW      = reader.ReadInt32();
                            int    objectH      = reader.ReadInt32();
                            byte   crop         = reader.ReadByte();
                            byte   resampling   = reader.ReadByte();
                            int    nameLength   = reader.ReadInt32();
                            string name         = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
                            int    bitmapWidth  = reader.ReadInt32();
                            int    bitmapHeight = reader.ReadInt32();
                            byte[] bitmapPixels = reader.ReadBytes(bitmapWidth * bitmapHeight * 4);
                            var    bitmap       = new TextureBitmap(bitmapWidth, bitmapHeight);
                            int    m            = bitmapWidth * bitmapHeight * bitmap.PixelSize;
                            unsafe
                            {
                                byte *ptr = (byte *)bitmap.Bytes.ToPointer();
                                for (int k = 0; k < m; k++)
                                {
                                    *(ptr + k) = bitmapPixels[k];
                                }
                            }
                            if (version == 0)
                            {
                                bitmap.FlipY();
                            }
                            SmartObjectLayer layer = new SmartObjectLayer(subPattern, name, bitmap, objectX, objectY, objectW, objectH);
                            subPattern.Layers.Add(layer);
                            layer.Crop      = (TextureBitmap.CropMode)crop;
                            layer.Resampler = (ResamplingFilters)resampling;
                            layer.Bitmap    = bitmap;
                            layer.UpdateColors();
                            layer.UpdateTexture();
                        }
                        else if (layerType == 0x00)
                        {
                            int         nameLength = reader.ReadInt32();
                            string      name       = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
                            RasterLayer layer      = new RasterLayer(subPattern, name);

                            int    m            = layer.Width * layer.Height * layer.Texture.PixelSize;
                            byte[] bitmapPixels = reader.ReadBytes(m);
                            layer.Texture = new TextureBitmap(layer.Width, layer.Height);

                            unsafe
                            {
                                byte *ptr = (byte *)layer.Texture.Bytes.ToPointer();
                                for (int k = 0; k < m; k++)
                                {
                                    *(ptr + k) = bitmapPixels[k];
                                }
                            }
                            if (version == 0)
                            {
                                layer.Texture.FlipY();
                            }

                            layer.UpdateTexture();
                            subPattern.Layers.Add(layer);
                        }
                    }
                }
            }
            GC.Collect();
            _CurrentSubPattern = 0;

            Logger.Log(Logger.Level.INFO, "[PatternEditor/Pattern] Creating new pattern");
            StartPreviewThread();
            Logger.Log(Logger.Level.DEBUG, "[PatternEditor/Pattern] Pattern type: " + _Type.ToString());
            Bitmap = new TextureBitmap(Width, Height);
            Logger.Log(Logger.Level.DEBUG, "[PatternEditor/Pattern] Created TextureBitmap " + Width + "x" + Height);
            Bitmap.Clear();
            PreviewBitmap = new TextureBitmap(Width, Height);
            Logger.Log(Logger.Level.DEBUG, "[PatternEditor/Pattern] Created preview TextureBitmap " + Width + "x" + Height);
            PreviewBitmap.Clear();
            PreviewSprite = UnityEngine.Sprite.Create(PreviewBitmap.Texture, new UnityEngine.Rect(0, 0, PreviewBitmap.Width, PreviewBitmap.Height), new UnityEngine.Vector2(0.5f, 0.5f));
            Logger.Log(Logger.Level.DEBUG, "[PatternEditor/Pattern] Created preview sprite");

            UpscaledPreviewBitmap = new TextureBitmap(Width * 4, Height * 4);
            Logger.Log(Logger.Level.DEBUG, "[PatternEditor/Pattern] Created upscaled preview TextureBitmap " + (Width * 4) + "x" + (Height * 4));
            UpscaledPreviewBitmap.Clear();

            Info = DesignPatternInformation.Types[this._Type];
            Logger.Log(Logger.Level.DEBUG, "[PatternEditor/Pattern] Pattern information obtained.");
        }
        catch (System.Exception e)
        {
            Logger.Log(Logger.Level.ERROR, "[PatternEditor/Pattern] Error while creating pattern: " + e.ToString());
            this.Dispose();
            throw e;
        }
    }