当前位置: 首页>>代码示例>>C#>>正文


C# RgbSpectrum.DeGamma方法代码示例

本文整理汇总了C#中RayDen.Library.Core.Primitives.RgbSpectrum.DeGamma方法的典型用法代码示例。如果您正苦于以下问题:C# RgbSpectrum.DeGamma方法的具体用法?C# RgbSpectrum.DeGamma怎么用?C# RgbSpectrum.DeGamma使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RayDen.Library.Core.Primitives.RgbSpectrum的用法示例。


在下文中一共展示了RgbSpectrum.DeGamma方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTextureSampler

        public TextureSampler CreateTextureSampler(string path, bool scale = false)
        {
            var newTex = Path.GetFileName(path) ?? path;
            if (samplers.ContainsKey(newTex))
                return samplers[newTex];
            else
            {
                if (!File.Exists(path))
                {
                    Console.WriteLine("ISSUES DUDE {0} not found", path);
                    throw new ArgumentException("imagepath");
                }
                Console.WriteLine("{0} Loading. {1} total samplers loaded ", Path.GetFileName(path), samplers.Count);
                using (var bitmap = new FreeImageBitmap(path))
                {
                    var bmp = bitmap.Width > MaxTextureWidth || bitmap.Height > MaxTextureHeight
                        ? GetScaledBmp(bitmap)
                        : bitmap;
                    var desc = new BufferDesc()
                    {
                        Width = (uint) bmp.Width,
                        Height = (uint) bmp.Height,
                        Format = Format.Float4,
                        Type = BufferType.Input
                    };
                    var texData = EngineContext.Instance.ResourceManager.CreateBuffer(context, desc);

                    BufferStream data = texData.Map();
                    for (int i = 0; i < bmp.Height; i++)
                    {

                        switch (bmp.ColorDepth)
                        {

                            case 8:
                                Scanline<byte> s_8 = bmp.GetScanline<byte>(i);

                                for (int j = 0; j < bmp.Width; j++)
                                {
                                    var c = new Vector4(bmp.Palette[s_8[j]].rgbRed/255.0f,
                                        bmp.Palette[s_8[j]].rgbGreen/255.0f,
                                        bmp.Palette[s_8[j]].rgbBlue/255.0f,
                                        1.0f);
                                    data.Write(c);

                                }
                                break;

                            case 24:
                                Scanline<RGBTRIPLE> s_t = bmp.GetScanline<RGBTRIPLE>(i);
                                for (int j = 0; j < bmp.Width; j++)
                                {
                                    var rgb =
                                        new RgbSpectrum(s_t[j].rgbtRed/255.0f, s_t[j].rgbtGreen/255.0f,
                                            s_t[j].rgbtBlue/255.0f);
                                    rgb.DeGamma();
                                    var c = new Vector4(rgb.c1, rgb.c2, rgb.c3, 1.0f);
                                    data.Write(c);

                                }
                                break;

                            case 32:
                                Scanline<RGBQUAD> s_32 = bmp.GetScanline<RGBQUAD>(i);
                                for (int j = 0; j < bmp.Width; j++)
                                {
                                    var rgb =
                                        new RgbSpectrum(s_32[j].rgbRed / 255.0f,
                                                        s_32[j].rgbGreen / 255.0f,
                                                        s_32[j].rgbBlue / 255.0f);
                                    rgb.DeGamma();
                                    var c = new Vector4(rgb.c1, rgb.c2, rgb.c3, 1.0f);

                                    data.Write(c);

                                }
                                break;


                        }


                    }

                    texData.Unmap();

                    TextureSamplerDesc texDesc = TextureSamplerDesc.Default;
                    texDesc.Read = TextureReadMode.ElementType;
                    TextureSampler sampler = new TextureSampler(context, texDesc);
                    sampler.SetBuffer(texData, 0);
                    samplers.Add(newTex, sampler);
                    Console.WriteLine("2D Sampler loaded  {0} {1}x{2} pixels", path, bmp.Width, bmp.Height);
                    return sampler;
                }
            }
        }
开发者ID:HungryBear,项目名称:rayden,代码行数:96,代码来源:TexManager.cs


注:本文中的RayDen.Library.Core.Primitives.RgbSpectrum.DeGamma方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。