Esempio n. 1
0
        public byte[] Decompile()
        {
            var bytes = Mipmaps[0].Bytes;

            if (Mipmaps[0].LZ4Compressed == 1)
            {
                bytes = TexLoader.DecompressLZ4(bytes, Mipmaps[0].PixelCount);
            }

            if (ImageFormat != FreeImageFormat.FIF_UNKNOWN)
            {
                return(bytes);
            }

            var invertedColorOrder = false;

            switch (Format)
            {
            case TexFormat.DXT5:
                bytes = DXT.DecompressImage(Mipmaps[0].Width, Mipmaps[0].Height, bytes, DXT.DXTFlags.DXT5);
                break;

            case TexFormat.DXT3:
                bytes = DXT.DecompressImage(Mipmaps[0].Width, Mipmaps[0].Height, bytes, DXT.DXTFlags.DXT3);
                break;

            case TexFormat.DXT1:
                bytes = DXT.DecompressImage(Mipmaps[0].Width, Mipmaps[0].Height, bytes, DXT.DXTFlags.DXT1);
                break;

            case TexFormat.ARGB8888:
                invertedColorOrder = true;
                break;

            default:
                throw new NotImplementedException($"Format: \"{Format.ToString()}\" ({(int)Format})");
            }

            var width        = ImageWidth;
            var textureWidth = Mipmaps[0].Width;
            var height       = ImageHeight;
            var bitmap       = new Bitmap(width, height);


            Helper.CopyRawPixelsIntoBitmap(bytes, textureWidth * 4, bitmap, invertedColorOrder);

            var stream = new MemoryStream();

            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            bitmap.Dispose();
            bytes = stream.GetBuffer();
            stream.Close();

            return(bytes);
        }
Esempio n. 2
0
        private void InitializeRangeSlider()
        {
            _rangeSlider = _baseView.FindViewById <RangeSliderControl>(Resource.Id.rangeSlider);

            if (_rangeSlider != null)
            {
                _rangeSlider.SetRangeValues(_minValue, _maxValue);
                _rangeSlider.StepValue = _stepValue;

                _rangeSlider.ShowTextAboveThumbs = true;
                _rangeSlider.MinThumbHidden      = true;
                _rangeSlider.MaxThumbHidden      = false;

                _rangeSlider.ActivateOnDefaultValues = true;
                _rangeSlider.TextSizeInSp            = 16;
                _rangeSlider.AlwaysActive            = true;

                _rangeSlider.ThumbShadow          = true;
                _rangeSlider.TextFormat           = _textFormat.ToString();
                _rangeSlider.ActiveColor          = Color.Rgb(46, 167, 243); //light blue
                _rangeSlider.TextAboveThumbsColor = Color.Rgb(219, 92, 76);  //main

                SetSliderValues();
            }
        }
Esempio n. 3
0
        private static string GetBaseFormat(TexFormat format)
        {
            string[] items  = { "_UNORM", "_SRGB", "_SINT", "_SNORM", "_UINT", "_UFLOAT", "_SFLOAT", "_FLOAT", "H_SF16", "H_UF16" };
            string   output = format.ToString();

            for (int i = 0; i < items.Length; i++)
            {
                output = output.Replace(items[i], string.Empty);
            }
            return(output);
        }
Esempio n. 4
0
 public bool Decode(TexFormat format, byte[] input, int width, int height, out byte[] output)
 {
     output = null;
     if (format.ToString().StartsWith("ASTC"))
     {
         var x = (int)TextureFormatHelper.GetBlockWidth(format);
         var y = (int)TextureFormatHelper.GetBlockHeight(format);
         var z = (int)TextureFormatHelper.GetBlockDepth(format);
         output = ASTCDecoder.DecodeToRGBA8888(input, x, y, z, width, height, 1);
     }
     return(output != null);
 }
Esempio n. 5
0
	/// <summary>
	/// Generates a NPOT 6x1 cubemap in the following format PX NX PY NY PZ NZ
	/// </summary>
	void GenerateTexture(Cubemap cubemap, string pathName)
	{
		// Encode the texture and save it to disk
		pathName = pathName.Replace(".cubemap", (textureFormat == TexFormat.PNG) ? ".png" : ".jpg" ).ToLower():
		pathName = pathName.Replace( cubeMapFolder.ToLower(), "" ):
		string format = textureFormat.ToString():
		string fullPath = EditorUtility.SaveFilePanel( string.Format( "Save Cubemap Screenshot as {0}", format ), "", pathName, format.ToLower() ):
		if ( !string.IsNullOrEmpty( fullPath ) )
        {
			Debug.Log( "Saving: " + fullPath ):
			OVRCubemapCapture.SaveCubemapCapture(cubemap, fullPath):
		}
	}
        private static byte[] GetComponentsFromPixel(TexFormat format, int pixel, byte[] comp)
        {
            switch (format)
            {
            case TexFormat.L8:
                comp[0] = (byte)(pixel & 0xFF);
                break;

            case TexFormat.LA8:
                comp[0] = (byte)(pixel & 0xFF);
                comp[1] = (byte)((pixel & 0xFF00) >> 8);
                break;

            case TexFormat.LA4:
                comp[0] = (byte)((pixel & 0xF) * 17);
                comp[1] = (byte)(((pixel & 0xF0) >> 4) * 17);
                break;

            case TexFormat.BGR565_UNORM:
                comp[2] = Convert5To8((byte)((pixel >> 11) & 0x1F));
                comp[1] = Convert6To8((byte)((pixel >> 5) & 0x3F));
                comp[0] = Convert5To8((byte)(pixel & 0x1F));
                comp[3] = 255;
                break;

            case TexFormat.RGB565_UNORM:
                comp[0] = Convert5To8((byte)((pixel >> 11) & 0x1F));
                comp[1] = Convert6To8((byte)((pixel >> 5) & 0x3F));
                comp[2] = Convert5To8((byte)(pixel & 0x1F));
                comp[3] = 255;
                break;

            case TexFormat.RGB5_UNORM:
            {
                int R = ((pixel >> 0) & 0x1f) << 3;
                int G = ((pixel >> 5) & 0x1f) << 3;
                int B = ((pixel >> 10) & 0x1f) << 3;

                comp[0] = (byte)(R | (R >> 5));
                comp[1] = (byte)(G | (G >> 5));
                comp[2] = (byte)(B | (B >> 5));
            }
            break;

            case TexFormat.RGBA4_UNORM:
            {
                comp[2] = Convert4To8((byte)(pixel & 0xF));
                comp[1] = Convert4To8((byte)((pixel >> 4) & 0xF));
                comp[0] = Convert4To8((byte)((pixel >> 8) & 0xF));
                comp[3] = Convert4To8((byte)((pixel >> 12) & 0xF));
            }
            break;

            case TexFormat.BGRA4_UNORM:
            {
                comp[3] = Convert4To8((byte)((pixel >> 12) & 0xF));
                comp[0] = Convert4To8((byte)((pixel >> 8) & 0xF));
                comp[1] = Convert4To8((byte)((pixel >> 4) & 0xF));
                comp[2] = Convert4To8((byte)(pixel & 0xF));
            }
            break;

            case TexFormat.RG4_UNORM:
            {
                comp[0] = Convert4To8((byte)((pixel >> 6) & 0xF));
                comp[1] = Convert4To8((byte)((pixel >> 4) & 0xF));
                comp[2] = Convert4To8((byte)((pixel >> 2) & 0xF));
            }
            break;

            case TexFormat.RGB5A1_UNORM:
            {
                int R = ((pixel >> 0) & 0x1f) << 3;
                int G = ((pixel >> 5) & 0x1f) << 3;
                int B = ((pixel >> 10) & 0x1f) << 3;
                int A = ((pixel & 0x8000) >> 15) * 0xFF;

                comp[0] = (byte)(R | (R >> 5));
                comp[1] = (byte)(G | (G >> 5));
                comp[2] = (byte)(B | (B >> 5));
                comp[3] = (byte)A;
            }
            break;

            case TexFormat.GRGB8_UNORM:
                comp[0] = (byte)((pixel & 0xFF00) >> 8);
                comp[1] = (byte)(pixel & 0xFF);
                comp[2] = (byte)((pixel & 0xFF00) >> 8);
                comp[3] = (byte)((pixel & 0xFF0000) >> 16);
                break;

            case TexFormat.RG8_UNORM:
                comp[0] = (byte)(pixel & 0xFF);
                comp[1] = (byte)((pixel & 0xFF00) >> 8);
                break;

            case TexFormat.R8_UNORM:
                comp[0] = (byte)(pixel & 0xFF);
                comp[1] = (byte)(pixel & 0xFF);
                comp[2] = (byte)(pixel & 0xFF);
                break;

            case TexFormat.RGB8_UNORM:
            case TexFormat.RGB8_SRGB:
                comp[2] = (byte)(pixel & 0xFF);
                comp[1] = (byte)((pixel & 0xFF00) >> 8);
                comp[0] = (byte)((pixel & 0xFF0000) >> 16);
                comp[3] = (byte)(0xFF);
                break;

            case TexFormat.RGBA8_SINT:
            case TexFormat.RGBA8_UINT:
            case TexFormat.RGBA8_UNORM:
            case TexFormat.RGBA8_SRGB:
            case TexFormat.BGRA8_UNORM:
            case TexFormat.BGRA8_SRGB:
                comp[0] = (byte)(pixel & 0xFF);
                comp[1] = (byte)((pixel & 0xFF00) >> 8);
                comp[2] = (byte)((pixel & 0xFF0000) >> 16);
                comp[3] = (byte)((pixel & 0xFF000000) >> 24);
                break;
            }

            if (format.ToString().StartsWith("BGR"))
            {
                return(new byte[4] {
                    comp[1], comp[0], comp[2], comp[3]
                });
            }

            return(comp);
        }
Esempio n. 7
0
 public static bool IsBCNCompressed(TexFormat Format)
 {
     return(Format.ToString().StartsWith("BC"));
 }