public static void ReplaceTexture(Image newImage, TextureListObject textureListObject) { ImageHeader imageHeader = textureListObject.imageHeader; PaletteHeader paletteHeader = textureListObject.paletteHeader; byte[] newPaletteData; byte[] newTextureData = TPL.ConvertToTextureMelee(newImage, textureListObject, out newPaletteData); if (newTextureData.Length != textureListObject.imageSize) { MessageBox.Show("Error: Selected image is not the same file size!"); return; } if (paletteHeader != null && newPaletteData.Length > paletteHeader.colorCount0xC * 2) { MessageBox.Show( "The selected image contains more colors than the original image. Please use no more than " + paletteHeader.colorCount0xC + " colors."); return; } Array.ConstrainedCopy(newTextureData, 0, file, (int)(imageHeader.imageOffset0x0 + dataOffset), newTextureData.Length); if (paletteHeader != null) { Array.ConstrainedCopy(newPaletteData, 0, file, (int)(paletteHeader.paletteOffset0x0 + dataOffset), Math.Min((paletteHeader.colorCount0xC * 2), newPaletteData.Length)); } OpenDatFile(file, fileName, ref textureList); }
/// <summary> /// Sets the image data from a <see cref="Bitmap"/> /// </summary> /// <param name="b"></param> public void SetFromBitmap(Bitmap b, GXTexFmt imageFormat, GXTlutFmt paletteFormat) { byte[] palData; ImageData = new HSD_Image(); ImageData.Width = (ushort)b.Width; ImageData.Height = (ushort)b.Height; ImageData.Format = imageFormat; ImageData.Data = TPL.ConvertToTextureMelee(b, (int)imageFormat, (int)paletteFormat, out palData); if (palData != null && palData.Length > 0) { Tlut = new HSD_Tlut(); Tlut.Format = paletteFormat; Tlut.ColorCount = (ushort)(palData.Length / 2); Tlut.Data = palData; } }