<commit_before>﻿// Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using osu.Framework.Graphics.OpenGL;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.IO.Stores;
using OpenTK.Graphics.ES20;

namespace osu.Framework.Graphics.Textures
{
    public class TextureStore : ResourceStore<RawTexture>
    {
        Dictionary<string, TextureGL> textureCache = new Dictionary<string, TextureGL>();

        private TextureAtlas atlas = new TextureAtlas(GLWrapper.MaxTextureSize, GLWrapper.MaxTextureSize);

        public float ScaleAdjust = 1;

        public TextureStore(IResourceStore<RawTexture> store = null) : base(store)
        {
            AddExtension(@"png");
            AddExtension(@"jpg");
        }

        private Texture getTexture(string name)
        {
            RawTexture raw = base.Get($@"{name}");
            if (raw == null) return null;
            return TextureLoader.FromRawTexture(raw, atlas);
        }

        public async Task<Texture> GetAsync(string name) => await Task.Run(() => Get(name));

        /// <summary>
        /// Retrieves a texture from the store and adds it to the atlas.
        /// </summary>
        /// <param name="name">The name of the texture.</param>
        /// <returns>The texture.</returns>
        public virtual new Texture Get(string name)
        {
            Texture tex = null;

            try
            {
                TextureGL cachedTex;
                if (textureCache.TryGetValue(name, out cachedTex))
                {
                    //use existing TextureGL (but provide a new texture instance).
                    return tex = cachedTex != null ? new Texture(cachedTex) : null;
                }

                switch (name)
                {
                    case @"_whitepixel":
                        tex = atlas?.GetWhitePixel();

                        if (tex == null)
                        {
                            tex = new Texture(1, 1, true);
                            tex.SetData(new TextureUpload(new byte[] { 255, 255, 255, 255 }));
                        }
                        break;
                    default:
                        tex = getTexture(name);
                        break;
                }

                //load available mipmaps
                //int level = 1;
                //int div = 2;

                //while (tex.Width / div > 0)
                //{
                //    s = base.GetStream($@"{name}/{div}");

                //    if (s == null) break;

                //    int w = tex.Width / div;
                //    int h = tex.Height / div;

                //    TextureUpload upload = new TextureUpload(w * h * 4)
                //    {
                //        Level = level
                //    };

                //    using (MagickImage image = new MagickImage(s))
                //    {
                //        if (image.Width != w || image.Height != h)
                //        {
                //            image.Resize(new MagickGeometry($"{w}x{h}!"));
                //        }

                //        image.Write(new MemoryStream(upload.Data), MagickFormat.Rgba);
                //    }

                //    tex.SetData(upload);

                //    level++;
                //    div *= 2;
                //}

                textureCache[name] = tex?.TextureGL;

                return tex;
            }
            finally
            {
                if (tex != null && ScaleAdjust != 1)
                    tex.DpiScale = 1 / ScaleAdjust;
            }
        }
    }
}
<commit_msg>Remove redundant null check<commit_after>﻿// Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using osu.Framework.Graphics.OpenGL;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.IO.Stores;
using OpenTK.Graphics.ES20;

namespace osu.Framework.Graphics.Textures
{
    public class TextureStore : ResourceStore<RawTexture>
    {
        Dictionary<string, TextureGL> textureCache = new Dictionary<string, TextureGL>();

        private TextureAtlas atlas = new TextureAtlas(GLWrapper.MaxTextureSize, GLWrapper.MaxTextureSize);

        public float ScaleAdjust = 1;

        public TextureStore(IResourceStore<RawTexture> store = null) : base(store)
        {
            AddExtension(@"png");
            AddExtension(@"jpg");
        }

        private Texture getTexture(string name)
        {
            return TextureLoader.FromRawTexture(base.Get($@"{name}"), atlas);
        }

        public async Task<Texture> GetAsync(string name) => await Task.Run(() => Get(name));

        /// <summary>
        /// Retrieves a texture from the store and adds it to the atlas.
        /// </summary>
        /// <param name="name">The name of the texture.</param>
        /// <returns>The texture.</returns>
        public virtual new Texture Get(string name)
        {
            Texture tex = null;

            try
            {
                TextureGL cachedTex;
                if (textureCache.TryGetValue(name, out cachedTex))
                {
                    //use existing TextureGL (but provide a new texture instance).
                    return tex = cachedTex != null ? new Texture(cachedTex) : null;
                }

                switch (name)
                {
                    case @"_whitepixel":
                        tex = atlas?.GetWhitePixel();

                        if (tex == null)
                        {
                            tex = new Texture(1, 1, true);
                            tex.SetData(new TextureUpload(new byte[] { 255, 255, 255, 255 }));
                        }
                        break;
                    default:
                        tex = getTexture(name);
                        break;
                }

                //load available mipmaps
                //int level = 1;
                //int div = 2;

                //while (tex.Width / div > 0)
                //{
                //    s = base.GetStream($@"{name}/{div}");

                //    if (s == null) break;

                //    int w = tex.Width / div;
                //    int h = tex.Height / div;

                //    TextureUpload upload = new TextureUpload(w * h * 4)
                //    {
                //        Level = level
                //    };

                //    using (MagickImage image = new MagickImage(s))
                //    {
                //        if (image.Width != w || image.Height != h)
                //        {
                //            image.Resize(new MagickGeometry($"{w}x{h}!"));
                //        }

                //        image.Write(new MemoryStream(upload.Data), MagickFormat.Rgba);
                //    }

                //    tex.SetData(upload);

                //    level++;
                //    div *= 2;
                //}

                textureCache[name] = tex?.TextureGL;

                return tex;
            }
            finally
            {
                if (tex != null && ScaleAdjust != 1)
                    tex.DpiScale = 1 / ScaleAdjust;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.10844455852156057, 'fraction_numerical': 0.008213552361396304, 'mean_word_length': 1.0982767905223478, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 2, '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': '1880191', 'n_tokens_mistral': 2157, 'n_tokens_neox': 1903, 'n_words': 453}