private TIPSImageInfo[] GetImageInfos(params int[] indices) { if (indices.Length != ImageInfos.Max(x => x.Index) + 1) { throw new Exception(); } TIPSImageInfo[] infos = new TIPSImageInfo[indices.Length]; for (int i = 0; i < infos.Length; i++) { // TODO: hacky! infos[i] = ImageInfos.Where(x => x.Index == i).Skip(indices[i]).FirstOrDefault(); if (infos[i] == null) { infos[i] = ImageInfos.LastOrDefault(x => x.Index == i); } } return(infos); }
protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex) { #if ANITEST int[] indices = ImagePermutations[imageIndex]; TIPSImageInfo[] infos = GetImageInfos(indices); TIPSImageInfo main = infos.Aggregate((agg, next) => (next != null && next.Height > agg.Height && next.Width > agg.Width) ? next : agg); Bitmap image = new Bitmap(main.Width, main.Height); using (Graphics g = Graphics.FromImage(image)) { foreach (TIPSImageInfo info in infos.Where(x => x != null)) { TIPSRectangleInfo[] rectInfos = RectInfos[info]; for (int i = 0; i < rectInfos.Length; i++) { TIPSRectangleInfo rectInfo = rectInfos[i]; Rectangle sourceRect = new Rectangle(rectInfo.SourceX * BlockWidth, rectInfo.SourceY * BlockHeight, (int)rectInfo.SourceWidth * BlockWidth, BlockHeight); g.DrawImage(rawImage, info.X + (rectInfo.TargetX * BlockWidth), info.Y + (rectInfo.TargetY * BlockHeight), sourceRect, GraphicsUnit.Pixel); } } } return(image); #else TIPSImageInfo imageInfo = ImageInfos[imageIndex]; TIPSRectangleInfo[] rectInfos = RectInfos[imageInfo]; Bitmap image = new Bitmap(imageInfo.Width, imageInfo.Height); using (Graphics g = Graphics.FromImage(image)) { for (int i = 0; i < rectInfos.Length; i++) { TIPSRectangleInfo rectInfo = rectInfos[i]; Rectangle sourceRect = new Rectangle(rectInfo.SourceX * BlockWidth, rectInfo.SourceY * BlockHeight, (int)rectInfo.SourceWidth * BlockWidth, BlockHeight); g.DrawImage(rawImage, rectInfo.TargetX * BlockWidth, rectInfo.TargetY * BlockHeight, sourceRect, GraphicsUnit.Pixel); } } return(image); #endif }
protected override void OnOpen(EndianBinaryReader reader) { /* Read header(?) */ Unknown0x00 = reader.ReadUInt32(); Unknown0x04 = reader.ReadUInt32(); FrameDataOffset = reader.ReadUInt32(); PixelDataOffset = reader.ReadUInt32(); RawImageWidth = reader.ReadUInt16(); RawImageHeight = reader.ReadUInt16(); NumImageInformation = reader.ReadUInt16(); BlockWidth = reader.ReadByte(); BlockHeight = reader.ReadByte(); Unknown0x18 = reader.ReadUInt16(); Unknown0x1A = reader.ReadUInt16(); Unknown0x1C = reader.ReadUInt32(); Unknown0x20 = reader.ReadUInt32(); Unknown0x24 = reader.ReadUInt32(); Unknown0x28 = reader.ReadUInt32(); Unknown0x2C = reader.ReadUInt32(); Unknown0x30 = reader.ReadUInt32(); Unknown0x34 = reader.ReadUInt32(); Unknown0x38 = reader.ReadUInt32(); Unknown0x3C = reader.ReadUInt32(); /* Get image information */ ImageInfos = new TIPSImageInfo[NumImageInformation]; for (int i = 0; i < NumImageInformation; i++) { ImageInfos[i] = new TIPSImageInfo(reader); } /* Get rect information */ RectInfos = new Dictionary <TIPSImageInfo, TIPSRectangleInfo[]>(); for (int i = 0; i < NumImageInformation; i++) { TIPSImageInfo imageInfo = ImageInfos[i]; long position = reader.BaseStream.Position; reader.BaseStream.Seek(imageInfo.RectOffset, SeekOrigin.Begin); RectInfos.Add(imageInfo, new TIPSRectangleInfo[imageInfo.NumRects]); for (int j = 0; j < imageInfo.NumRects; j++) { RectInfos[imageInfo][j] = new TIPSRectangleInfo(reader); } reader.BaseStream.Seek(position, SeekOrigin.Begin); } /* Get all image permutations (eyes, mouths, etc) */ ImagePermutations = new List <int[]>(); int maxType = (int)(ImageInfos.Max(x => x.Index) + 1); int[] indices = new int[maxType]; for (int t = maxType - 1; t >= 0; t--) { GetImagePermutations(ref indices, t); } /* Get pixel data */ reader.BaseStream.Seek(PixelDataOffset, SeekOrigin.Begin); PixelData = reader.ReadBytes((int)(reader.BaseStream.Length - PixelDataOffset)); /* Scale alpha */ for (int i = 0; i < PixelData.Length; i += 4) { PixelData[i + 3] = PS2.ScaleAlpha(PixelData[i + 3]); } /* Create raw image bitmap */ ImageBinary rawImageBinary = new ImageBinary(); if (RawImageWidth != 0 && RawImageHeight != 0) { rawImageBinary.Width = RawImageWidth; rawImageBinary.Height = RawImageHeight; rawImageBinary.InputPixelFormat = PixelDataFormat.FormatAbgr8888; rawImageBinary.AddInputPixels(PixelData); rawImage = rawImageBinary.GetBitmap(); } }