fehaar/FFWD — pull request #35 by Elideb (2012-04-11 12:57:30+00:00)
Title: Texture implementations of GetPixel, GetPixels, SetPixel and SetPixels, plus helpers.

This fixes issue #27.

Testing code for different cases:

using UnityEngine;
using System.Collections;

public class PixelTests : MonoBehaviour
{
private int frame = 0;
private Texture2D texture;
private Color[] pixels;

void Start()
{
texture = (Texture2D)Instantiate(this.renderer.material.mainTexture);
this.renderer.material.mainTexture = this.texture;

pixels = texture.GetPixels(0, 0, texture.width, texture.height, 0);

// Test SetPixel
////for (int i = 0; i < texture.width / 2; i++)
////{
//// for (int j = 0; j < texture.height / 2; j++)
//// {
//// texture.SetPixel(i + texture.width / 2, j + texture.height / 2, pixels[i + texture.width * j]);
//// }
////}

////texture.Apply(false, false);
}

// Update is called once per frame
void Update ()
{
// GetPixel / SetPixel test
// Shift the lower half of the cube once per frame
////for (int i = 0; i < texture.width; i++)
////{
//// for (int j = 0; j < texture.height / 2; j++)
//// {
//// texture.SetPixel(i + frame, j, pixels[i + texture.width * j]);
//// }
////}

// Test SetPixels
////texture.SetPixels(0, texture.height / 2, texture.width, texture.height / 2, pixels);

// Test SetPixel and GetPixel at runtime
for (int i = texture.width - 1; i >= 0; i--)
{
for (int j = texture.height - 1; j >= 0; j--)
{
texture.SetPixel(i + 1, j + 1, texture.GetPixel(i, j));
}
}

frame++;

texture.Apply(false);
}
}