/// <inheritdoc /> protected override System.Drawing.Image GetImage(int activeFrame, int activePalette) { TIM2Segment tim2 = imagesList[activeFrame]; tim2.SelectedPalette = activePalette; return(tim2.GetImage()); }
private List <Image> ConstructImages(TIM2Segment segment, out Image referenceImage) { referenceImage = segment.GetReferenceImage(); if (referenceImage == null) { return(new List <Image>() { segment.GetImage() }); } var list = new List <Image>(); int oldSelected = segment.SelectedPalette; for (int i = 0; i < segment.PalettesCount; i++) { segment.SelectedPalette = i; Bitmap img = new Bitmap(segment.Palette.Length, 1); for (int j = 0; j < segment.Palette.Length; j++) { img.SetPixel(j, 0, segment.Palette[j]); } list.Add(img); } segment.SelectedPalette = oldSelected; return(list); }
protected override Color[] GetPalette(int activePalette) { TIM2Segment format = imagesList[SelectedFrame]; int oldPal = format.SelectedPalette; format.SelectedPalette = activePalette; Color[] palette = format.Palette; format.SelectedPalette = oldPal; return(palette); }
public void Save(TextureFormat texture, Stream outFormatData) { TIM2Segment segment = texture as TIM2Segment; if (segment == null) { throw new TextureFormatException("Not A valid TIM2Segment!"); } byte[] imageData = segment.GetImageData(); byte[] paletteData = segment.GetPaletteData(); TIM2Segment.TIM2SegmentParameters parameters = segment.GetParameters(); //write header WriteHeader(parameters, outFormatData, imageData, paletteData); outFormatData.Write(imageData, 0, imageData.Length); outFormatData.Write(paletteData, 0, paletteData.Length); }
public TextureFormat Import(MetadataReader metadata, string directory) { TIM2Texture tim2 = null; try { metadata.EnterSection("TIM2"); int version = metadata.GetAttribute <int>("Version"); string basename = metadata.GetAttribute <string>("Basename"); bool swizzled = metadata.GetAttribute <bool>("Swizzled"); int textureCount = metadata.GetAttribute <int>("Textures"); List <TIM2Segment> imagesList = new List <TIM2Segment>(); for (int i = 0; i < textureCount; i++) { TIM2Segment segment = (TIM2Segment) new TIM2SegmentSerializer(swizzled).Import(metadata, directory); imagesList.Add(segment); } metadata.ExitSection(); tim2 = new TIM2Texture(imagesList); tim2.Version = version; } catch (FormatException e) { throw new TextureFormatException("Cannot parse value!\n" + e.Message, e); } catch (XmlException e) { throw new TextureFormatException("Not valid metadata!\n" + e.Message, e); } catch (TextureFormatException e) { throw new TextureFormatException(e.Message, e); } catch (Exception e) { throw new TextureFormatException("Error:\n" + e.Message, e); } return(tim2); }
public TextureFormat Open(Stream formatData) { int version, textureCount; ReadHeader(formatData, out version, out textureCount); //construct images List <TIM2Segment> imagesList = new List <TIM2Segment>(); for (int i = 0; i < textureCount; i++) { TextureFormatSerializer serializer = new TIM2SegmentSerializer(); TIM2Segment segment = (TIM2Segment)serializer.Open(formatData); imagesList.Add(segment); } TIM2Texture tim = new TIM2Texture(imagesList); tim.Version = version; return(tim); }
public TextureFormat Import(MetadataReader metadata, string directory) { TIM2Segment segment = null; int palCount; string basename; TIM2Segment.TIM2SegmentParameters parameters; Readmetadata(metadata, out parameters, out basename, out palCount); Image referenceImage = null; List <Image> images = ReadImageData(directory, basename, palCount, out referenceImage); if (referenceImage != null) { segment = new TIM2Segment(referenceImage, images.Select(img => img.GetColorArray()).ToList(), parameters); } else { segment = new TIM2Segment(images.First(), null, parameters); } return(segment); }
private void Writemetadata(TIM2Segment segment, MetadataWriter metadata, string basename) { metadata.BeginSection("TIM2Texture"); metadata.PutAttribute("Basename", basename); metadata.PutAttribute("Cluts", segment.PalettesCount); metadata.PutAttribute("LinearClut", segment.GetParameters().linearPalette); metadata.Put("Width", segment.GetParameters().width); metadata.Put("Height", segment.GetParameters().height); metadata.Put("Bpp", segment.GetParameters().bpp); metadata.Put("ColorSize", segment.GetParameters().colorSize); metadata.Put("MipmapCount", segment.GetParameters().mipmapCount); metadata.Put("Format", segment.GetParameters().format); metadata.Put("GsTEX0", segment.GetParameters().GsTEX0); metadata.Put("GsTEX1", segment.GetParameters().GsTEX1); metadata.Put("GsRegs", segment.GetParameters().GsRegs); metadata.Put("GsTexClut", segment.GetParameters().GsTexClut); metadata.Put("UserData", segment.GetParameters().userdata); metadata.EndSection(); }
public void Export(TextureFormat texture, MetadataWriter metadata, string directory, string basename) { TIM2Segment segment = texture as TIM2Segment; if (segment == null) { throw new TextureFormatException("Not A valid TIM2Segment!"); } Writemetadata(segment, metadata, basename); int i = 0; Image referenceImage = null; List <Image> images = ConstructImages(segment, out referenceImage); foreach (Image img in images) { img.Save(Path.Combine(directory, basename + "_" + i++ + ".png")); } if (referenceImage != null) { referenceImage.Save(Path.Combine(directory, basename + "_reference.png")); } }