<commit_before>﻿#region Using

using System.Numerics;
using Emotion.Common;
using Emotion.Common.Threading;
using Emotion.Graphics.Objects;
using Emotion.Standard.Image.BMP;
using Emotion.Standard.Image.PNG;
using Emotion.Standard.Logging;

#endregion

namespace Emotion.IO
{
    /// <summary>
    /// Represents an image. Supports all formats supported by Emotion.Standard.Image
    /// </summary>
    public class TextureAsset : Asset
    {
        /// <summary>
        /// The asset's uploaded graphics texture.
        /// </summary>
        public Texture Texture { get; set; }

        protected override void CreateInternal(byte[] data)
        {
            byte[] pixels = null;
            var width = 0;
            var height = 0;
            var flipped = false;

            // Check if PNG.
            if (PngFormat.IsPng(data))
            {
                pixels = PngFormat.Decode(data, out PngFileHeader header);
                width = header.Width;
                height = header.Height;
                flipped = true;
            }
            // Check if BMP.
            else if (BmpFormat.IsBmp(data))
            {
                pixels = BmpFormat.Decode(data, out BmpFileHeader header);
                width = header.Width;
                height = header.Height;
            }

            if (pixels == null || width == 0 || height == 0)
            {
                Engine.Log.Warning($"Couldn't load texture - {Name}.", MessageSource.AssetLoader);
                return;
            }

            UploadTexture(new Vector2(width, height), pixels, flipped);
        }

        protected virtual void UploadTexture(Vector2 size, byte[] rgbaPixels, bool flipped)
        {
            GLThread.ExecuteGLThread(() =>
            {
                Texture = new Texture(size, rgbaPixels);
                if (flipped) Texture.TextureMatrix = Matrix4x4.CreateScale(1, -1, 1);
            });
        }

        protected override void DisposeInternal()
        {
            Texture.Dispose();
            Texture = null;
        }
    }
}<commit_msg>Fixed TextureAsset param being rgbaPixels but containing bgraPixels<commit_after>﻿#region Using

using System.Numerics;
using Emotion.Common;
using Emotion.Common.Threading;
using Emotion.Graphics.Objects;
using Emotion.Standard.Image.BMP;
using Emotion.Standard.Image.PNG;
using Emotion.Standard.Logging;

#endregion

namespace Emotion.IO
{
    /// <summary>
    /// Represents an image. Supports all formats supported by Emotion.Standard.Image
    /// </summary>
    public class TextureAsset : Asset
    {
        /// <summary>
        /// The asset's uploaded graphics texture.
        /// </summary>
        public Texture Texture { get; set; }

        protected override void CreateInternal(byte[] data)
        {
            byte[] pixels = null;
            var width = 0;
            var height = 0;
            var flipped = false;

            // Check if PNG.
            if (PngFormat.IsPng(data))
            {
                pixels = PngFormat.Decode(data, out PngFileHeader header);
                width = header.Width;
                height = header.Height;
                flipped = true;
            }
            // Check if BMP.
            else if (BmpFormat.IsBmp(data))
            {
                pixels = BmpFormat.Decode(data, out BmpFileHeader header);
                width = header.Width;
                height = header.Height;
            }

            if (pixels == null || width == 0 || height == 0)
            {
                Engine.Log.Warning($"Couldn't load texture - {Name}.", MessageSource.AssetLoader);
                return;
            }

            UploadTexture(new Vector2(width, height), pixels, flipped);
        }

        protected virtual void UploadTexture(Vector2 size, byte[] bgraPixels, bool flipped)
        {
            GLThread.ExecuteGLThread(() =>
            {
                Texture = new Texture(size, bgraPixels);
                if (flipped) Texture.TextureMatrix = Matrix4x4.CreateScale(1, -1, 1);
            });
        }

        protected override void DisposeInternal()
        {
            Texture.Dispose();
            Texture = null;
        }
    }
}
{'fraction_non_alphanumeric': 0.10122989593188268, 'fraction_numerical': 0.005203405865657522, 'mean_word_length': 1.5786585365853658, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3277039', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1103, 'n_words': 285}