Files
RaindropViewer/Assets/Raindrop/Render/ImageUtils.cs
T

74 lines
3.1 KiB
C#

/**
* Radegast Metaverse Client
* Copyright(c) 2009-2014, Radegast Development Team
* Copyright(c) 2016-2020, Sjofn, LLC
* All rights reserved.
*
* Radegast is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.If not, see<https://www.gnu.org/licenses/>.
*/
using System.Drawing;
using OpenMetaverse;
using UnityEngine;
namespace Raindrop.Rendering
{
public static class ImageUtils
{
/// <summary>
/// Performs bilinear interpolation between four values
/// </summary>
/// <param name="v00">First, or top left value</param>
/// <param name="v01">Second, or top right value</param>
/// <param name="v10">Third, or bottom left value</param>
/// <param name="v11">Fourth, or bottom right value</param>
/// <param name="xPercent">Interpolation value on the X axis, between 0.0 and 1.0</param>
/// <param name="yPercent">Interpolation value on fht Y axis, between 0.0 and 1.0</param>
/// <returns>The bilinearly interpolated result</returns>
public static float Bilinear(float v00, float v01, float v10, float v11, float xPercent, float yPercent)
{
return Utils.Lerp(Utils.Lerp(v00, v01, xPercent), Utils.Lerp(v10, v11, xPercent), yPercent);
}
/// <summary>
/// Performs a high quality image resize
/// </summary>
/// <param name="image">Image to resize</param>
/// <param name="width">New width</param>
/// <param name="height">New height</param>
/// <returns>Resized image</returns>
///
//implementation: make new texture, copy, resize.
//public static Bitmap ResizeImage(Bitmap image, int width, int height)
public static Texture2D ResizeImage(Texture2D image, int width, int height)
{
Texture2D result = new Texture2D(width, height);
//using (Graphics graphics = Graphics.FromImage(result))
//{
// graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
// graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
// graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
// graphics.DrawImage(image, 0, 0, result.Width, result.Height);
//}
UnityEngine.Graphics.CopyTexture(image, result);
result.Resize(width,height);
return result;
}
}
}