public bool AddLUTFromTexture(LUTSettings lutSettings, Texture2D lutTexture) { if (lutSettings == null || lutTexture == null) { return(false); } var size = lutTexture.height; if (size != lutSettings.Size) { return(false); } var irt = FromTexture(lutTexture); var lut = irt.GetLUT(new LUTSettings(size, 1)); if (lut == null) { return(false); } int columns = lutSettings.Columns; int rows = lutSettings.Rows; if (Width < columns * size) { return(false); } if (Height < rows * size) { return(false); } var lutdata = lut.Data; var data = ColorData; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { for (int h = 0; h < size; h++) { for (int w = 0; w < size; w++) { int row = r * size + h; int col = c * size + w; //data[col, row] = new Color((float)w / size, (float)h / size, (float)(c + r * columns) / size); data[col, row] = lutdata[w, size - h - 1, (c + r * columns)]; } } } } lut.Release(); return(true); }
public bool AddLUT(LUTSettings settings) { int size = settings.Size; int columns = settings.Columns; int rows = settings.Rows; if (Width < columns * size) { return(false); } if (Height < rows * size) { return(false); } var data = ColorData; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { for (int h = 0; h < size; h++) { for (int w = 0; w < size; w++) { int row = r * size + h; int col = c * size + w; float rf = ( float )w / (size - 1); float gf = ( float )h / (size - 1); float bf = ( float )(c + r * columns) / (size - 1); data[col, row] = new Color(rf, gf, bf); } } } } return(true); }
public bool AddLUT( LUTSettings settings ) { int size = settings.Size; int columns = settings.Columns; int rows = settings.Rows; if ( Width < columns * size ) { return false; } if ( Height < rows * size ) { return false; } var data = ColorData; for ( int r = 0; r < rows; r++ ) { for ( int c = 0; c < columns; c++ ) { for ( int h = 0; h < size; h++ ) { for ( int w = 0; w < size; w++ ) { int row = r * size + h; int col = c * size + w; float rf = ( float ) w / ( size - 1 ); float gf = ( float ) h / ( size - 1 ); float bf = ( float ) ( c + r * columns ) / ( size - 1 ); data[ col, row ] = new Color( rf, gf, bf ); } } } } return true; }
public LUTResult GetLUT(LUTSettings lutSettings) { int size = lutSettings.Size; int columns = lutSettings.Columns; int rows = lutSettings.Rows; if (Width < columns * size) { return(null); } if (Height < rows * size) { return(null); } Color[ , , ] data = new Color[size, size, size]; var colorData = ColorData; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { for (int h = 0; h < size; h++) { for (int w = 0; w < size; w++) { int row = r * size + h; int col = c * size + w; int stack = (c + r * columns); data[w, h, stack] = colorData[col, row]; } } } } return(new LUTResult(data)); }
public static bool LoadTexture2DLutFromPhotoshopData( byte[] data, LUTSettings settings, out Texture2D texture ) { int columns = settings.Columns; int rows = settings.Rows; int size = settings.Size; var decryptedBytes = data.AsEnumerable(); //byte imageType = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip( 1 ); var tempbytes = decryptedBytes.Take( 4 ).Reverse().ToArray(); decryptedBytes = decryptedBytes.Skip( 4 ); int imageWidth = BitConverter.ToInt32( tempbytes, 0 ); tempbytes = decryptedBytes.Take( 4 ).Reverse().ToArray(); decryptedBytes = decryptedBytes.Skip( 4 ); int imageHeight = BitConverter.ToInt32( tempbytes, 0 ); //tempbytes = decryptedBytes.Take(4).Reverse().ToArray(); decryptedBytes = decryptedBytes.Skip( 4 ); //int rowBytes = BitConverter.ToInt32(tempbytes, 0); //byte colorMode = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip( 1 ); //byte channelCount = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip( 1 ); //byte bitsChannel = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip( 1 ); var imageData = new Color[ imageWidth, imageHeight ]; var bytesarray = decryptedBytes.ToArray(); for ( int i = 0, k = 0; i < imageHeight; i++ ) { for ( int j = 0; j < imageWidth; j++ ) { imageData[ j, i ] = new Color( bytesarray[ k++ ] / 255f, bytesarray[ k++ ] / 255f, bytesarray[ k++ ] / 255f, 1f ); } } var lutTexture = new Texture2D( size * size, size, TextureFormat.ARGB32, false ); var lutData = new Color[ size * size * size ]; for ( int h = 0, i = 0; h < size; h++ ) { for ( int r = 0; r < rows; r++ ) { for ( int w = 0; w < size * columns; w++ ) { lutData[ i++ ] = imageData[ w, h + r * size ]; } } } lutTexture.SetPixels( lutData ); lutTexture.Apply(); texture = lutTexture; return true; }
public static bool LoadTexture2DLutFromPhotoshopData(byte[] data, LUTSettings settings, out Texture2D texture) { int columns = settings.Columns; int rows = settings.Rows; int size = settings.Size; var decryptedBytes = data.AsEnumerable(); //byte imageType = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip(1); var tempbytes = decryptedBytes.Take(4).Reverse().ToArray(); decryptedBytes = decryptedBytes.Skip(4); int imageWidth = BitConverter.ToInt32(tempbytes, 0); tempbytes = decryptedBytes.Take(4).Reverse().ToArray(); decryptedBytes = decryptedBytes.Skip(4); int imageHeight = BitConverter.ToInt32(tempbytes, 0); //tempbytes = decryptedBytes.Take(4).Reverse().ToArray(); decryptedBytes = decryptedBytes.Skip(4); //int rowBytes = BitConverter.ToInt32(tempbytes, 0); //byte colorMode = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip(1); //byte channelCount = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip(1); //byte bitsChannel = decryptedBytes.Take(1).First(); decryptedBytes = decryptedBytes.Skip(1); var imageData = new Color[imageWidth, imageHeight]; var bytesarray = decryptedBytes.ToArray(); for (int i = 0, k = 0; i < imageHeight; i++) { for (int j = 0; j < imageWidth; j++) { imageData[j, i] = new Color(bytesarray[k++] / 255f, bytesarray[k++] / 255f, bytesarray[k++] / 255f, 1f); } } var lutTexture = new Texture2D(size * size, size, TextureFormat.ARGB32, false); var lutData = new Color[size * size * size]; for (int h = 0, i = 0; h < size; h++) { for (int r = 0; r < rows; r++) { for (int w = 0; w < size * columns; w++) { lutData[i++] = imageData[w, h + r * size]; } } } lutTexture.SetPixels(lutData); lutTexture.Apply(); texture = lutTexture; return(true); }
public LUTResult GetLUT( LUTSettings lutSettings ) { int size = lutSettings.Size; int columns = lutSettings.Columns; int rows = lutSettings.Rows; if ( Width < columns * size ) { return null; } if ( Height < rows * size ) { return null; } Color[ , , ] data = new Color[ size, size, size ]; var colorData = ColorData; for ( int r = 0; r < rows; r++ ) { for ( int c = 0; c < columns; c++ ) { for ( int h = 0; h < size; h++ ) { for ( int w = 0; w < size; w++ ) { int row = r * size + h; int col = c * size + w; int stack = ( c + r * columns ); data[ w, h, stack ] = colorData[ col, row ]; } } } } return new LUTResult( data ); }
public bool AddLUTFromTexture( LUTSettings lutSettings, Texture2D lutTexture ) { if ( lutSettings == null || lutTexture == null ) { return false; } var size = lutTexture.height; if ( size != lutSettings.Size ) { return false; } var irt = FromTexture( lutTexture ); var lut = irt.GetLUT( new LUTSettings( size, 1 ) ); if ( lut == null ) { return false; } int columns = lutSettings.Columns; int rows = lutSettings.Rows; if ( Width < columns * size ) { return false; } if ( Height < rows * size ) { return false; } var lutdata = lut.Data; var data = ColorData; for ( int r = 0; r < rows; r++ ) { for ( int c = 0; c < columns; c++ ) { for ( int h = 0; h < size; h++ ) { for ( int w = 0; w < size; w++ ) { int row = r * size + h; int col = c * size + w; //data[col, row] = new Color((float)w / size, (float)h / size, (float)(c + r * columns) / size); data[ col, row ] = lutdata[ w, size - h - 1, ( c + r * columns ) ]; } } } } return true; }