public static uint[] GetMasks(TexFormat format) { switch (format) { case TexFormat.RGB5A1_UNORM: return(A1R5G5B5_MASKS); case TexFormat.RGB5_UNORM: return(X1R5G5B5_MASKS); case TexFormat.RGBA4_UNORM: return(A4R4G4B4_MASKS); case TexFormat.RGB565_UNORM: return(R5G6B5_MASKS); case TexFormat.RGB8_UNORM: return(R8G8B8_MASKS); case TexFormat.RGB8_SRGB: return(R8G8B8_MASKS); case TexFormat.BGRA8_UNORM: return(A8B8G8R8_MASKS); case TexFormat.BGRA8_SRGB: return(A8B8G8R8_MASKS); case TexFormat.BGRX8_UNORM: return(X8B8G8R8_MASKS); case TexFormat.BGRX8_UNORM_SRGB: return(X8B8G8R8_MASKS); // case TexFormat.RGB4_UNORM: // return new int[4] { X4R4G4B4_MASKS[1], X4R4G4B4_MASKS[2], X4R4G4B4_MASKS[3], X4R4G4B4_MASKS[4] }; default: return(A8R8G8B8_MASKS); } }
public static void SaveTexture2D(Texture2D texture, int width, int height, TexFormat format, string path) { if (texture != null) { byte[] textureData = null; switch (format) { case TexFormat.eJPG: { textureData = texture.EncodeToJPG(); } break; case TexFormat.ePNG: { textureData = texture.EncodeToPNG(); } break; } FileStream fs = File.Open(path, FileMode.Create, FileAccess.ReadWrite); BinaryWriter bw = new BinaryWriter(fs); bw.Write(textureData); bw.Close(); fs.Close(); } }
private bool IsSupported(TexFormat format) { switch (format) { case TexFormat.L8: case TexFormat.LA4: case TexFormat.RGB8_UNORM: case TexFormat.RGB8_SRGB: case TexFormat.RGBA8_UNORM: case TexFormat.RGBA8_SRGB: case TexFormat.BGRA8_UNORM: case TexFormat.BGRA8_SRGB: case TexFormat.BGR565_UNORM: case TexFormat.RGB565_UNORM: case TexFormat.RGB5_UNORM: case TexFormat.RGBA4_UNORM: case TexFormat.BGRA4_UNORM: case TexFormat.RGB5A1_UNORM: case TexFormat.GRGB8_UNORM: case TexFormat.RG8_UNORM: case TexFormat.RG4_UNORM: case TexFormat.R8_UNORM: return(true); } return(false); }
public static MipmapFormat GetFormatForTex(FreeImageFormat imageFormat, TexFormat texFormat) { if (imageFormat != FreeImageFormat.FIF_UNKNOWN) { return(FreeImageFormatToMipmapFormat(imageFormat)); } switch (texFormat) { case TexFormat.RGBA8888: return(MipmapFormat.RGBA8888); case TexFormat.DXT5: return(MipmapFormat.CompressedDXT5); case TexFormat.DXT3: return(MipmapFormat.CompressedDXT3); case TexFormat.DXT1: return(MipmapFormat.CompressedDXT1); case TexFormat.R8: return(MipmapFormat.R8); case TexFormat.RG88: return(MipmapFormat.RG88); default: throw new ArgumentOutOfRangeException(); } }
public static uint GetBytesPerPixel(TexFormat Format) { if (!HasFormatTableKey(Format)) { return(8); } return(FormatTable[GetBaseFormat(Format)].BytesPerPixel); }
private void formatCB_SelectedIndexChanged(object sender, EventArgs e) { if (formatCB.SelectedIndex >= 0) { Format = (TexFormat)formatCB.SelectedItem; UpdateImage(); } }
public static GLTexture2DArray FromRawData(int width, int height, TexFormat format, byte[] data) { GLTexture2DArray texture = new GLTexture2DArray(); texture.Width = width; texture.Height = height; texture.LoadImage(width, height, format, data); return(texture); }
public static uint GetBlockDepth(TexFormat Format) { if (!HasFormatTableKey(Format)) { return(8); } return(FormatTable[GetBaseFormat(Format)].BlockDepth); }
private void SetPixelFormats(TexFormat Format) { switch (Format) { case TexFormat.BC1_UNORM: case TexFormat.BC1_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case TexFormat.BC2_UNORM: case TexFormat.BC2_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; break; case TexFormat.BC3_UNORM: case TexFormat.BC3_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case TexFormat.BC4_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1; break; case TexFormat.BC4_SNORM: pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1; break; case TexFormat.BC5_SNORM: pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; case TexFormat.BC5_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2; break; case TexFormat.BC6H_UF16: pixelInternalFormat = PixelInternalFormat.CompressedRgbBptcUnsignedFloat; break; case TexFormat.BC6H_SF16: pixelInternalFormat = PixelInternalFormat.CompressedRgbBptcSignedFloat; break; case TexFormat.BC7_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaBptcUnorm; break; case TexFormat.BC7_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgbaBptcUnorm; break; default: pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; } }
public static PixelFormatInfo ConvertPixelFormat(TexFormat format) { if (!PixelFormatList.ContainsKey(format)) { return(PixelFormatList[TexFormat.RGBA8_UNORM]); } return(PixelFormatList[format]); }
public RangeFragment(string title, float minValue, float maxValue, float stepValue, string updateProperty, string propertyValue, TexFormat textFormat = TexFormat.F0) : base(title, updateProperty, Resource.Layout.RangeLayout) { _minValue = minValue; _maxValue = maxValue; _stepValue = stepValue; _propertyValue = propertyValue; _textFormat = textFormat; }
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); }
public ITexImageContainer ReadFrom(BinaryReader reader, TexFormat texFormat) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (!texFormat.IsValid()) { throw new EnumNotValidException <TexFormat>(texFormat); } var container = new TexImageContainer { Magic = reader.ReadNString(maxLength: 16) }; var imageCount = reader.ReadInt32(); if (imageCount > Constants.MaximumImageCount) { throw new UnsafeTexException( $"Image count exceeds limit: {imageCount}/{Constants.MaximumImageCount}"); } switch (container.Magic) { case "TEXB0001": case "TEXB0002": break; case "TEXB0003": container.ImageFormat = (FreeImageFormat)reader.ReadInt32(); break; default: throw new UnknownMagicException(nameof(TexImageContainerReader), container.Magic); } container.ImageContainerVersion = (TexImageContainerVersion)Convert.ToInt32(container.Magic.Substring(4)); if (!container.ImageFormat.IsValid()) { throw new EnumNotValidException <FreeImageFormat>(container.ImageFormat); } for (var i = 0; i < imageCount; i++) { container.Images.Add(_texImageReader.ReadFrom(reader, container, texFormat)); } return(container); }
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); }
public WiiUSwizzle(TexFormat format) { Format = FormatList.FirstOrDefault(x => x.Value == format).Key; OutputFormat = format; AAMode = GX2.GX2AAMode.GX2_AA_MODE_1X; TileMode = GX2.GX2TileMode.MODE_2D_TILED_THIN1; ResourceFlags = GX2.GX2RResourceFlags.GX2R_BIND_TEXTURE; SurfaceDimension = GX2.GX2SurfaceDimension.DIM_2D; SurfaceUse = GX2.GX2SurfaceUse.USE_COLOR_BUFFER; Alignment = 0; Pitch = 0; }
public static byte[] DecodeBlock(byte[] data, uint width, uint height, TexFormat format) { byte[] output = new byte[0]; foreach (var decoder in FileManager.GetTextureDecoders()) { bool isDecoded = decoder.Decode(format, data, (int)width, (int)height, out output); if (isDecoded) { return(output != null?ImageUtility.ConvertBgraToRgba(output) : new byte[0]); } } return(output != null?ImageUtility.ConvertBgraToRgba(output) : new byte[0]); }
public void ToGenericFormat() { TexFormat format = TexFormat.RGBA8_UNORM; if (IsDX10) { format = (TexFormat)Dx10Header.DxgiFormat; } else { switch (PfHeader.FourCC) { case FOURCC_DXT1: format = TexFormat.BC1_UNORM; break; case FOURCC_DXT2: case FOURCC_DXT3: format = TexFormat.BC2_UNORM; break; case FOURCC_DXT4: case FOURCC_DXT5: format = TexFormat.BC3_UNORM; break; case FOURCC_ATI1: case FOURCC_BC4U: format = TexFormat.BC4_UNORM; break; case FOURCC_ATI2: case FOURCC_BC5U: format = TexFormat.BC5_UNORM; break; case FOURCC_BC5S: format = TexFormat.BC5_SNORM; break; case FOURCC_RXGB: format = TexFormat.RGBA8_UNORM; break; default: format = TexFormat.RGBA8_UNORM; break; } } Platform.OutputFormat = format; }
public bool Decode(TexFormat format, byte[] input, int width, int height, out byte[] output) { output = null; return(false); switch (format) { case TexFormat.BC1_UNORM: output = DXT.DecompressBC1(input, width, height, false); break; case TexFormat.BC1_SRGB: output = DXT.DecompressBC1(input, width, height, true); break; case TexFormat.BC2_UNORM: output = DXT.DecompressBC2(input, width, height, false); break; case TexFormat.BC2_SRGB: output = DXT.DecompressBC2(input, width, height, true); break; case TexFormat.BC3_UNORM: output = DXT.DecompressBC3(input, width, height, false); break; case TexFormat.BC3_SRGB: output = DXT.DecompressBC3(input, width, height, true); break; case TexFormat.BC4_UNORM: output = DXT.DecompressBC4(input, width, height, false); break; case TexFormat.BC4_SNORM: output = DXT.DecompressBC4(input, width, height, true); break; case TexFormat.BC5_UNORM: output = DXT.DecompressBC5(input, width, height, false); break; case TexFormat.BC5_SNORM: output = DXT.DecompressBC5(input, width, height, true); break; } return(output != null); }
public void OnEnable() { texImporter = target as TextureImporter; texFormat.Clear(); if (texImporter != null) { path = texImporter.assetPath; cannotHotfix = path.StartsWith("Assets/Resources/StaticUI"); isUITex = (path.StartsWith("Assets/Resources/atlas/UI") || path.StartsWith("Assets/Resources/StaticUI")) && !path.EndsWith("_A.png"); if (isUITex) { GetTexFormat(IsAtlas(path), texImporter.userData, out srcFormat, out alphaSize); for (int i = 0; i < targets.Length; ++i) { TextureImporter ti = targets[i] as TextureImporter; if (ti != null) { needAlpha = ti.DoesSourceTextureHaveAlpha(); TexFormat tf = new TexFormat(); GetTexFormat(IsAtlas(ti.assetPath), ti.userData, out tf.srcFormat, out tf.alphaSize); texFormat.Add(tf); if (tf.srcFormat != srcFormat) { srcFormat = (ETextureCompress)(-1); } if (tf.alphaSize != alphaSize) { alphaSize = (ETextureSize)(-1); } } } } } SceneView.onSceneGUIDelegate = TargetUpdate; Type t = null; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (type.Name.ToLower().Contains("textureimporterinspector")) { t = type; break; } } } nativeEditor = Editor.CreateEditor(target, t); }
// Not using reflection to do this because reflection data is stripped away for RePKG.Native and it would fail public static bool IsValid(this TexFormat format) { switch (format) { case TexFormat.RGBA8888: case TexFormat.DXT5: case TexFormat.DXT3: case TexFormat.DXT1: case TexFormat.RG88: case TexFormat.R8: return(true); default: return(false); } }
public ITexImage ReadFrom( BinaryReader reader, ITexImageContainer container, TexFormat texFormat) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (container == null) { throw new ArgumentNullException(nameof(container)); } if (!texFormat.IsValid()) { throw new EnumNotValidException <TexFormat>(texFormat); } var mipmapCount = reader.ReadInt32(); if (mipmapCount > Constants.MaximumMipmapCount) { throw new UnsafeTexException( $"Mipmap count exceeds limit: {mipmapCount}/{Constants.MaximumMipmapCount}"); } var readFunction = PickMipmapReader(container.ImageContainerVersion); var format = TexMipmapFormatGetter.GetFormatForTex(container.ImageFormat, texFormat); var image = new TexImage(); for (var i = 0; i < mipmapCount; i++) { var mipmap = readFunction(reader); mipmap.Format = format; if (DecompressMipmapBytes) { _texMipmapDecompressor.DecompressMipmap(mipmap); } image.Mipmaps.Add(mipmap); } return(image); }
private void EditInExternalProgram(bool UseDefaultEditor = true) { if (!ActiveTexture.CanEdit || !IsFinished) { return; } ImageProgramSettings settings = new ImageProgramSettings(); settings.LoadImage(ActiveTexture); if (settings.ShowDialog() == DialogResult.OK) { UseDefaultEditor = !settings.OpenDefaultProgramSelection; string UseExtension = settings.GetSelectedExtension(); FormatToChange = settings.GetSelectedImageFormat(); string TemporaryName = Path.GetTempFileName(); FileUtils.DeleteIfExists(Path.ChangeExtension(TemporaryName, UseExtension)); File.Move(TemporaryName, Path.ChangeExtension(TemporaryName, UseExtension)); TemporaryName = Path.ChangeExtension(TemporaryName, UseExtension); var exportSetting = new TextureExportSettings() { ArrayLevel = CurArrayDisplayLevel, MipLevel = CurMipDisplayLevel, }; ActiveTexture.Export(TemporaryName, exportSetting); if (UseDefaultEditor) { Process.Start(TemporaryName); } else { ShowOpenWithDialog(TemporaryName); } FileWatcher.Filter = Path.GetFileName(TemporaryName); //Start watching for changes FileWatcher.EnableRaisingEvents = true; } }
public void LoadImage(int width, int height, TexFormat format, byte[] data) { if (TextureFormatHelper.IsBCNCompressed(format)) { var internalFormat = GLFormatHelper.ConvertCompressedFormat(format, true); int imageSize = GLFormatHelper.CalculateImageSize(width, height, internalFormat); GL.CompressedTexImage3D(TextureTarget.Texture2DArray, 0, internalFormat, width, height, 1, 0, imageSize, data); } else { var formatInfo = GLFormatHelper.ConvertPixelFormat(format); GL.TexImage3D(Target, 0, formatInfo.InternalFormat, width, height, 1, 0, formatInfo.Format, formatInfo.Type, data); } }
void OnGUI() { if (window == null) { GUILayout.Label("Missing window reference!"); return; } IntPow2Field("IntegrateBRDF Texture Size", ref mTexSize); TextureReadableField(); mFmt = (TexFormat)EditorGUILayout.EnumPopup("Texture Format", mFmt); if (GUILayout.Button("Generate")) { ComputeIntegrateBRDF(); } }
public void SetTextureFormat(RenderTextureFormat fmt) { switch (fmt) { case RenderTextureFormat.RHalf: _textureFormat = TexFormat.RHalf; break; case RenderTextureFormat.RGHalf: _textureFormat = TexFormat.RGHalf; break; case RenderTextureFormat.ARGBHalf: _textureFormat = TexFormat.RGBAHalf; break; default: Debug.LogError("Unsupported texture format for readback: " + fmt.ToString(), this); break; } }
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); }
public bool Encode(TexFormat format, byte[] input, int width, int height, out byte[] output) { output = null; return(false); }
//Method from https://github.com/aboood40091/BNTX-Editor/blob/master/formConv.py public bool Decode(TexFormat format, byte[] input, int width, int height, out byte[] output) { if (!IsSupported(format)) { output = null; return(false); } uint bpp = TextureFormatHelper.GetBytesPerPixel(format); int size = width * height * 4; bpp = (uint)(input.Length / (width * height)); output = new byte[size]; int inPos = 0; int outPos = 0; byte[] comp = new byte[] { 0, 0, 0, 0xFF, 0, 0xFF }; byte[] compSel = new byte[4] { 0, 1, 2, 3 }; if (format == TexFormat.LA8) { compSel = new byte[4] { 0, 0, 0, 1 }; bpp = 2; } else if (format == TexFormat.L8) { compSel = new byte[4] { 0, 0, 0, 5 } } ; for (int Y = 0; Y < height; Y++) { for (int X = 0; X < width; X++) { inPos = (Y * width + X) * (int)bpp; outPos = (Y * width + X) * 4; int pixel = 0; for (int i = 0; i < bpp; i++) { pixel |= input[inPos + i] << (8 * i); } comp = GetComponentsFromPixel(format, pixel, comp); output[outPos + 3] = comp[compSel[3]]; output[outPos + 2] = comp[compSel[2]]; output[outPos + 1] = comp[compSel[1]]; output[outPos + 0] = comp[compSel[0]]; } } return(output != null); }
public static bool IsBCNCompressed(TexFormat Format) { return(Format.ToString().StartsWith("BC")); }
public static bool HasFormatTableKey(TexFormat Format) { return(FormatTable.ContainsKey(GetBaseFormat(Format))); }