protected override void OnOpen(EndianBinaryReader reader) { MagicNumber = Encoding.ASCII.GetString(reader.ReadBytes(4), 0, 4); Unknown0x04 = reader.ReadUInt32(); Constant3553 = reader.ReadUInt32(); Width = reader.ReadUInt32(); Height = reader.ReadUInt32(); DataType = (PicaDataType)reader.ReadUInt32(); PixelFormat = (PicaPixelFormat)reader.ReadUInt32(); NumImageBytes = reader.ReadUInt32(); /* Disclaimer: Hacky as hell! I almost want to hope that Atlus someday leaves their internal STEX creator tool inside one of these games, maybe that'll help with figuring this out <.< */ /* ...now at offset 0x20, assume here's the pointer to image data */ ImageOffset = reader.ReadUInt32(); /* ...now assume said pointer is 0x80 */ if (ImageOffset == 0x80) { /* Read "well-formed" STEX (but really, who knows how the header's supposed to be) */ Unknown0x24 = reader.ReadUInt32(); Name = Encoding.ASCII.GetString(reader.ReadBytes(0x58), 0, 0x58).TrimEnd('\0'); /* ...but as image datasize is also unreliable, do some additional sanity checking on that, too! */ reader.BaseStream.Seek(ImageOffset, SeekOrigin.Begin); PixelData = reader.ReadBytes((int)(NumImageBytes > reader.BaseStream.Length ? reader.BaseStream.Length - ImageOffset : NumImageBytes)); } else /* ...otherwise... */ { /* Seek back, then just assume image data starts right here at 0x20, and that the image is as many bytes long as are left in the file */ reader.BaseStream.Seek(-4, SeekOrigin.Current); ImageOffset = (uint)reader.BaseStream.Position; Unknown0x24 = uint.MaxValue; Name = string.Empty; PixelData = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); } /* Initialize ImageBinary */ imageBinary = new ImageBinary(); imageBinary.Width = (int)Width; imageBinary.Height = (int)Height; imageBinary.InputPixelFormat = N3DS.GetPixelDataFormat(DataType, PixelFormat); imageBinary.InputEndianness = Endian.LittleEndian; imageBinary.AddInputPixels(PixelData); }
protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex) { CTXBTexture texture = Textures[imageIndex]; PicaPixelFormat pixelFormat = texture.PixelFormat; PicaDataType dataType = ((pixelFormat == PicaPixelFormat.ETC1RGB8NativeDMP || pixelFormat == PicaPixelFormat.ETC1AlphaRGB8A4NativeDMP) ? PicaDataType.UnsignedByte : texture.DataType); ImageBinary imageBinary = new ImageBinary(); imageBinary.Width = texture.Width; imageBinary.Height = texture.Height; imageBinary.InputPixelFormat = N3DS.GetPixelDataFormat(dataType, pixelFormat); imageBinary.InputEndianness = Endian.LittleEndian; imageBinary.AddInputPixels(pixelData[imageIndex]); return(imageBinary.GetBitmap(0, 0)); }
protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex) { ImageBinary imageBinary = new ImageBinary(); imageBinary = new ImageBinary(); imageBinary.Width = mipmapData[imageIndex].Width; imageBinary.Height = mipmapData[imageIndex].Height; imageBinary.InputPixelFormat = N3DS.GetPixelDataFormat(header.PixelFormat); imageBinary.InputEndianness = Endian.LittleEndian; imageBinary.AddInputPixels(mipmapData[imageIndex].PixelData); // Don't pass in original imageIndex and paletteIndex; Scarlet can't handle multiple widths/heights per ImageBinary, so we have to recreate it every time // TODO: uh, verify the whole Y flipping business here... //return imageBinary.GetBitmap(0, 0); Bitmap bitmap = imageBinary.GetBitmap(0, 0); bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); return(bitmap); }