public void SetPixelsClamp(int x, int y, D2D_Pixels s)
 {
     for (var sy = 0; sy < s.height; sy++)
     {
         for (var sx = 0; sx < s.width; sx++)
         {
             SetPixelClamp(x + sx, y + sy, s.GetPixelClamp(sx, sy));
         }
     }
 }
示例#2
0
    public void ReplaceAlphaWith(D2D_Pixels newPixels)
    {
        DeserializeAlphaTex();

#if UNITY_EDITOR
        if (alphaTex != null)
        {
            D2D_Helper.Record(alphaTex, "Modify Alpha Tex");
        }
#endif
        if (newPixels != null)
        {
            // Remake texture?
            if (alphaTex == null || alphaTex.width != newPixels.Width || alphaTex.height != newPixels.Height)
            {
                DestroyAlphaTex();

                alphaTex    = newPixels.Apply(TextureFormat.Alpha8);
                alphaScaleX = D2D_Helper.Reciprocal(alphaTex.width - 1);
                alphaScaleY = D2D_Helper.Reciprocal(alphaTex.height - 1);

                alphaTex.wrapMode = TextureWrapMode.Clamp;
            }
            // Copy settings over?
            else
            {
                alphaTex.SetPixels32(newPixels.Pixels);
                alphaTex.Apply();
            }

            UpdateRect(0, alphaTex.width, 0, alphaTex.height);
        }
        else
        {
            DestroyAlphaTex();

            UpdateRect(0, 0, 0, 0);
        }

        cachedSolidPixelCount = 0;
        alphaTexData          = null;
        alphaTexWidth         = 0;
        alphaTexHeight        = 0;
        Dirty = true;

        NotifyChanges();

#if UNITY_EDITOR
        D2D_Helper.SetDirty(this);
#endif
    }
    public D2D_Pixels GetResized(int newWidth, int newHeight)
    {
        var o = new D2D_Pixels(newWidth, newHeight);
        var w = (float)(newWidth - 1);
        var h = (float)(newHeight - 1);

        for (var y = 0; y < newHeight; y++)
        {
            for (var x = 0; x < newWidth; x++)
            {
                var pixel = GetPixelBilinear((float)x / w, (float)y / h);

                o.SetPixel(x, y, pixel);
            }
        }

        return(o);
    }
    public D2D_Pixels GetBlurredAlpha()
    {
        var o = new D2D_Pixels(width, height);

        // Horizontal
        for (var y = 0; y < height; y++)
        {
            for (var x = 0; x < width; x++)
            {
                var a = GetPixelTransparent(x - 1, y);
                var b = GetPixelTransparent(x, y);
                var c = GetPixelTransparent(x + 1, y);
                var t = (int)a.a + (int)b.a + (int)c.a;

                b.a = (byte)(t / 3);

                o.SetPixel(x, y, b);
            }
        }

        // Vertical
        for (var y = 0; y < height; y++)
        {
            for (var x = 0; x < width; x++)
            {
                var a = GetPixelTransparent(x, y - 1);
                var b = GetPixelTransparent(x, y);
                var c = GetPixelTransparent(x, y + 1);
                var t = (int)a.a + (int)b.a + (int)c.a;

                b.a = (byte)(t / 3);

                o.SetPixel(x, y, b);
            }
        }

        return(o);
    }
	public D2D_Pixels GetBlurredAlpha()
	{
		var o = new D2D_Pixels(width, height);
		
		// Horizontal
		for (var y = 0; y < height; y++)
		{
			for (var x = 0; x < width; x++)
			{
				var a = GetPixelTransparent(x - 1, y);
				var b = GetPixelTransparent(x    , y);
				var c = GetPixelTransparent(x + 1, y);
				var t = (int)a.a + (int)b.a + (int)c.a;
				
				b.a = (byte)(t / 3);
				
				o.SetPixel(x, y, b);
			}
		}
		
		// Vertical
		for (var y = 0; y < height; y++)
		{
			for (var x = 0; x < width; x++)
			{
				var a = GetPixelTransparent(x, y - 1);
				var b = GetPixelTransparent(x, y    );
				var c = GetPixelTransparent(x, y + 1);
				var t = (int)a.a + (int)b.a + (int)c.a;
				
				b.a = (byte)(t / 3);
				
				o.SetPixel(x, y, b);
			}
		}
		
		return o;
	}
	public D2D_Pixels GetResized(int newWidth, int newHeight)
	{
		var o = new D2D_Pixels(newWidth, newHeight);
		var w = (float)(newWidth - 1);
		var h = (float)(newHeight - 1);
		
		for (var y = 0; y < newHeight; y++)
		{
			for (var x = 0; x < newWidth; x++)
			{
				var pixel = GetPixelBilinear((float)x / w, (float)y / h);
				
				o.SetPixel(x, y, pixel);
			}
		}
		
		return o;
	}
	public void SetPixelsClamp(int x, int y, D2D_Pixels s)
	{
		for (var sy = 0; sy < s.height; sy++)
		{
			for (var sx = 0; sx < s.width; sx++)
			{
				SetPixelClamp(x + sx, y + sy, s.GetPixelClamp(sx, sy));
			}
		}
	}
	public void ReplaceAlphaWith(D2D_Pixels newPixels)
	{
		DeserializeAlphaTex();
		
#if UNITY_EDITOR
		if (alphaTex != null)
		{
			D2D_Helper.Record(alphaTex, "Modify Alpha Tex");
		}
#endif
		if (newPixels != null)
		{
			// Remake texture?
			if (alphaTex == null || alphaTex.width != newPixels.Width || alphaTex.height != newPixels.Height)
			{
				DestroyAlphaTex();
				
				alphaTex    = newPixels.Apply(TextureFormat.Alpha8);
				alphaScaleX = D2D_Helper.Reciprocal(alphaTex.width  - 1);
				alphaScaleY = D2D_Helper.Reciprocal(alphaTex.height - 1);
				
				alphaTex.wrapMode = TextureWrapMode.Clamp;
			}
			// Copy settings over?
			else
			{
				alphaTex.SetPixels32(newPixels.Pixels);
				alphaTex.Apply();
			}
			
			UpdateRect(0, alphaTex.width, 0, alphaTex.height);
		}
		else
		{
			DestroyAlphaTex();
			
			UpdateRect(0, 0, 0, 0);
		}
		
		cachedSolidPixelCount = 0;
		alphaTexData          = null;
		alphaTexWidth         = 0;
		alphaTexHeight        = 0;
		Dirty                 = true;
		
		NotifyChanges();
		
#if UNITY_EDITOR
		D2D_Helper.SetDirty(this);
#endif
	}