public void GetChannels(float x, float[] v, int m = 0) { int W = Data.GetWidth(m); x *= (W - 1); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); for (int c = 0; c < Data.Channels; c++) { v[c] = GetBilinear(ix, c, m); } } else if (Interpolation == TEXTURE_INTERPOLATION.BICUBIC) { BicubicIndex ix = NewBicubicIndex(x, W); for (int c = 0; c < Data.Channels; c++) { v[c] = GetBicubic(ix, c, m); } } else { GetChannels((int)x, v, m); } }
private float GetBilinear(BilinearIndex x, BilinearIndex y, int c, int m) { float v0 = Data[x.i0, y.i0, c, m] * (1.0f - x.fi) + Data[x.i1, y.i0, +c, m] * x.fi; float v1 = Data[x.i0, y.i1, c, m] * (1.0f - x.fi) + Data[x.i1, y.i1, c, m] * x.fi; return((float)(v0 * (1.0 - y.fi) + v1 * y.fi)); }
public float GetChannel(float x, int c, int m = 0) { if (c >= Data.Channels) { return(0); } int W = Data.GetWidth(m); x *= (W - 1); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); return(GetBilinear(ix, c, m)); } else if (Interpolation == TEXTURE_INTERPOLATION.BICUBIC) { BicubicIndex ix = NewBicubicIndex(x, W); return(GetBicubic(ix, c, m)); } else { return(GetChannel((int)x, c, m)); } }
public void GetChannels(float x, float y, float[] v, int m = 0) { int W = GetWidth(m); int H = GetHeight(m); x *= (W - 1); y *= (H - 1); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); BilinearIndex iy = NewBilinearIndex(y, H); for (int c = 0; c < Channels; c++) { v[c] = GetBilinear(ix, iy, c, m); } } else if (Interpolation == TEXTURE_INTERPOLATION.BICUBIC) { BicubicIndex ix = NewBicubicIndex(x, W); BicubicIndex iy = NewBicubicIndex(y, H); for (int c = 0; c < Channels; c++) { v[c] = GetBicubic(ix, iy, c, m); } } else { GetChannels((int)x, (int)y, v, m); } }
public float GetChannel(float x, float y, int c, int m = 0) { if (c >= Channels) { return(0); } int W = GetWidth(m); int H = GetHeight(m); x *= (W - 1); y *= (H - 1); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); BilinearIndex iy = NewBilinearIndex(y, H); return(GetBilinear(ix, iy, c, m)); } else if (Interpolation == TEXTURE_INTERPOLATION.BICUBIC) { BicubicIndex ix = NewBicubicIndex(x, W); BicubicIndex iy = NewBicubicIndex(y, H); return(GetBicubic(ix, iy, c, m)); } else { return(GetChannel((int)x, (int)y, c, m)); } }
public ColorRGBA GetPixel(float x, int m = 0) { int W = Data.GetWidth(m); x *= (W - 1); ColorRGBA pixel = new ColorRGBA(); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); if (Data.Channels > 0) { pixel.r = GetBilinear(ix, 0, m); } if (Data.Channels > 1) { pixel.g = GetBilinear(ix, 1, m); } if (Data.Channels > 2) { pixel.b = GetBilinear(ix, 2, m); } if (Data.Channels > 3) { pixel.a = GetBilinear(ix, 3, m); } } else if (Interpolation == TEXTURE_INTERPOLATION.BICUBIC) { BicubicIndex ix = NewBicubicIndex(x, W); if (Data.Channels > 0) { pixel.r = GetBicubic(ix, 0, m); } if (Data.Channels > 1) { pixel.g = GetBicubic(ix, 1, m); } if (Data.Channels > 2) { pixel.b = GetBicubic(ix, 2, m); } if (Data.Channels > 3) { pixel.a = GetBicubic(ix, 3, m); } } else { pixel = GetPixel((int)x, m); } return(pixel); }
/// <summary> /// Get a value from the datat array using bilinear filtering. /// </summary> private float GetBilinear(BilinearIndex x, BilinearIndex y, BilinearIndex z, int c, int m) { float fx1 = 1.0f - x.fi; float fy1 = 1.0f - y.fi; float fz1 = 1.0f - z.fi; float v00 = Data[x.i0, y.i0, z.i0, c, m] * fx1 + Data[x.i1, y.i0, z.i0, c, m] * x.fi; float v10 = Data[x.i0, y.i1, z.i0, c, m] * fx1 + Data[x.i1, y.i1, z.i0, c, m] * x.fi; float v01 = Data[x.i0, y.i0, z.i1, c, m] * fx1 + Data[x.i1, y.i0, z.i1, c, m] * x.fi; float v11 = Data[x.i0, y.i1, z.i1, c, m] * fx1 + Data[x.i1, y.i1, z.i1, c, m] * x.fi; float v0 = v00 * fy1 + v10 * y.fi; float v1 = v01 * fy1 + v11 * y.fi; return(v0 * fz1 + v1 * z.fi); }
/// <summary> /// Get channels into color. /// </summary> public ColorRGBA GetPixel(float x, float y, float z, int m = 0) { int W = GetWidth(m); int H = GetHeight(m); int D = GetDepth(m); x *= (W - 1); y *= (H - 1); z *= (D - 1); ColorRGBA pixel = new ColorRGBA(); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); BilinearIndex iy = NewBilinearIndex(y, H); BilinearIndex iz = NewBilinearIndex(z, D); if (Channels > 0) { pixel.r = GetBilinear(ix, iy, iz, 0, m); } if (Channels > 1) { pixel.g = GetBilinear(ix, iy, iz, 1, m); } if (Channels > 2) { pixel.b = GetBilinear(ix, iy, iz, 2, m); } if (Channels > 3) { pixel.a = GetBilinear(ix, iy, iz, 3, m); } } else { pixel = GetPixel((int)x, (int)y, (int)z, m); } return(pixel); }
private float GetBilinear(BilinearIndex x, int c, int m) { return((float)(Data[x.i0, c, m] * (1.0 - x.fi) + Data[x.i1, c, m] * x.fi)); }
public ColorRGBA GetPixel(float x, float y, int m = 0) { int W = GetWidth(m); int H = GetHeight(m); x *= (W - 1); y *= (H - 1); ColorRGBA pixel = new ColorRGBA(); if (Interpolation == TEXTURE_INTERPOLATION.BILINEAR) { BilinearIndex ix = NewBilinearIndex(x, W); BilinearIndex iy = NewBilinearIndex(y, H); int channels = Channels; if (channels > 0) { pixel.r = GetBilinear(ix, iy, 0, m); } if (channels > 1) { pixel.g = GetBilinear(ix, iy, 1, m); } if (channels > 2) { pixel.b = GetBilinear(ix, iy, 2, m); } if (channels > 3) { pixel.a = GetBilinear(ix, iy, 3, m); } } else if (Interpolation == TEXTURE_INTERPOLATION.BICUBIC) { BicubicIndex ix = NewBicubicIndex(x, W); BicubicIndex iy = NewBicubicIndex(y, H); int channels = Channels; if (channels > 0) { pixel.r = GetBicubic(ix, iy, 0, m); } if (channels > 1) { pixel.g = GetBicubic(ix, iy, 1, m); } if (channels > 2) { pixel.b = GetBicubic(ix, iy, 2, m); } if (channels > 3) { pixel.a = GetBicubic(ix, iy, 3, m); } } else { pixel = GetPixel((int)x, (int)y, m); } return(pixel); }