private void MakeFallback() { if (Mipmaps.ContainsKey(0) == false || Mipmaps[0] == null) { Mipmaps[0] = new Mipmap(Width, Height); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { // r 0 b // g 1 g // b 2 r // a 3 a //this[x, Height - 1 - y, 0] = data[x * 4 + (y * bmdata.Stride) + 2]; //this[x, Height - 1 - y, 1] = data[x * 4 + (y * bmdata.Stride) + 1]; //this[x, Height - 1 - y, 2] = data[x * 4 + (y * bmdata.Stride) + 0]; //this[x, Height - 1 - y, 3] = data[x * 4 + (y * bmdata.Stride) + 3]; Mipmaps[0][x, y, 0] = (byte)((System.Math.Max(x, y) % 64) * 4); Mipmaps[0][x, y, 1] = 0; Mipmaps[0][x, y, 2] = 0; Mipmaps[0][x, y, 3] = 127; } } } }
public Image(int width, int height, float r, float g, float b, float a) { Width = width; Height = height; Mipmap root = new Mipmap(Width, Height); Mipmaps[0] = root; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { root[x, y, 0] = (byte)(255.0f * r); root[x, y, 1] = (byte)(255.0f * g); root[x, y, 2] = (byte)(255.0f * b); root[x, y, 3] = (byte)(255.0f * a); } } }
void Nvidia.TextureTools.IOutputHandler.BeginImage( int size, int width, int height, int depth, int face, int miplevel ) { //Logger.Log("Incoming mipmap " + width + " x " + height + " level " + miplevel); nvttSize = size; //nvttDepth = depth; //nvttFace = face; nvttOffset = 0; if (size != width * height * depth * 4) { throw new InvalidDataException(); } nvttMipmap = new Mipmap(width, height); Mipmaps[miplevel] = nvttMipmap; }
private void UpdatePixels(System.Drawing.Bitmap bitmap) { Width = bitmap.Width; Height = bitmap.Height; Mipmap root = new Mipmap(Width, Height); Mipmaps[0] = root; System.Drawing.Imaging.BitmapData bmdata = bitmap.LockBits( new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); byte[] data = new byte[bitmap.Size.Width * bitmap.Size.Height * 4]; Marshal.Copy(bmdata.Scan0, data, 0, bitmap.Size.Width * bitmap.Size.Height * 4); bitmap.UnlockBits(bmdata); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { // r 0 b // g 1 g // b 2 r // a 3 a //this[x, Height - 1 - y, 0] = data[x * 4 + (y * bmdata.Stride) + 2]; //this[x, Height - 1 - y, 1] = data[x * 4 + (y * bmdata.Stride) + 1]; //this[x, Height - 1 - y, 2] = data[x * 4 + (y * bmdata.Stride) + 0]; //this[x, Height - 1 - y, 3] = data[x * 4 + (y * bmdata.Stride) + 3]; root[x, y, 0] = data[x * 4 + (y * bmdata.Stride) + 2]; root[x, y, 1] = data[x * 4 + (y * bmdata.Stride) + 1]; root[x, y, 2] = data[x * 4 + (y * bmdata.Stride) + 0]; root[x, y, 3] = data[x * 4 + (y * bmdata.Stride) + 3]; } } }
bool Nvidia.TextureTools.IOutputHandler.WriteDataUnsafe( System.IntPtr data, int size ) { if (nvttMipmap == null) { //Logger.Log("no mipmap yet, assuming header, skipping..."); return(true); } System.Runtime.InteropServices.Marshal.Copy( data, nvttMipmap.Pixels, nvttOffset, size ); nvttOffset += size; if (nvttOffset == nvttSize) { //Logger.Log("Mipmap " + nvttMipmap.Width + " x " + nvttMipmap.Height + " completed"); nvttMipmap = null; } return(true); }