protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex) { VtxpImageHeader imageHeader = ImageHeaders[imageIndex]; bool isIndexed = (imageHeader.PaletteOffset != 0); ImageBinary imageBinary = new ImageBinary(); imageBinary.Width = imageHeader.Width; imageBinary.Height = imageHeader.Height; imageBinary.InputEndianness = Endian.LittleEndian; if (isIndexed) { imageBinary.InputPaletteFormat = PSVita.GetPaletteFormat(imageHeader.TextureFormat); imageBinary.AddInputPalette(imageHeader.PaletteData); } imageBinary.InputPixelFormat = PSVita.GetPixelDataFormat(imageHeader.TextureFormat); imageBinary.AddInputPixels(imageHeader.PixelData); if (imageHeader.TextureType == VtxpTextureType.Swizzled) { imageBinary.InputPixelFormat |= PixelDataFormat.PixelOrderingSwizzledVita; } return(imageBinary.GetBitmap()); }
private Bitmap CreateBitmap(int infoIdx, int forcePaletteIdx = -1) { SceGxtTextureInfo info = TextureInfos[infoIdx]; ImageBinary imageBinary = new ImageBinary(); imageBinary.Width = info.GetWidth(); imageBinary.Height = info.GetHeight(); imageBinary.InputPixelFormat = PSVita.GetPixelDataFormat(info.GetTextureFormat()); imageBinary.InputEndianness = Endian.LittleEndian; imageBinary.AddInputPixels(PixelData[infoIdx]); // TODO: verify all this crap, GXT conversion wrt image [dimension/format/type] is fragile as all hell SceGxmTextureBaseFormat textureBaseFormat = info.GetTextureBaseFormat(); SceGxmTextureType textureType = info.GetTextureType(); if (textureType == SceGxmTextureType.Linear && textureBaseFormat != SceGxmTextureBaseFormat.UBC1 && textureBaseFormat != SceGxmTextureBaseFormat.UBC2 && textureBaseFormat != SceGxmTextureBaseFormat.UBC3 && textureBaseFormat != SceGxmTextureBaseFormat.PVRT2BPP && textureBaseFormat != SceGxmTextureBaseFormat.PVRT4BPP && textureBaseFormat != SceGxmTextureBaseFormat.PVRTII2BPP && textureBaseFormat != SceGxmTextureBaseFormat.PVRTII4BPP) { imageBinary.PhysicalWidth = (int)(((info.DataSize / imageBinary.Height) * 8) / PSVita.GetBitsPerPixel(textureBaseFormat)); imageBinary.PhysicalHeight = info.GetHeight(); } else { imageBinary.PhysicalWidth = info.GetWidthRounded(); imageBinary.PhysicalHeight = info.GetHeightRounded(); } if (textureBaseFormat != SceGxmTextureBaseFormat.PVRT2BPP && textureBaseFormat != SceGxmTextureBaseFormat.PVRT4BPP) { switch (textureType) { case SceGxmTextureType.Linear: // Nothing to be done! break; case SceGxmTextureType.Tiled: // TODO: verify me! imageBinary.InputPixelFormat |= PixelDataFormat.PixelOrderingTiled3DS; break; case SceGxmTextureType.Swizzled: case SceGxmTextureType.Cube: // TODO: is cube really the same as swizzled? seems that way from CS' *env* files... imageBinary.InputPixelFormat |= PixelDataFormat.PixelOrderingSwizzledVita; break; case (SceGxmTextureType)0xA0000000: // TODO: this is odd and needs investigation, found ex. in Odin Sphere, Puyo Puyo Tetris, ... imageBinary.InputPixelFormat |= PixelDataFormat.PixelOrderingSwizzledVita; break; } } if (textureBaseFormat == SceGxmTextureBaseFormat.P4 || textureBaseFormat == SceGxmTextureBaseFormat.P8) { imageBinary.InputPaletteFormat = PSVita.GetPaletteFormat(info.GetTextureFormat()); if (textureBaseFormat == SceGxmTextureBaseFormat.P4) { foreach (byte[] paletteData in P4Palettes) { imageBinary.AddInputPalette(paletteData); } } else if (textureBaseFormat == SceGxmTextureBaseFormat.P8) { foreach (byte[] paletteData in P8Palettes) { imageBinary.AddInputPalette(paletteData); } } } return(imageBinary.GetBitmap(0, forcePaletteIdx != -1 ? forcePaletteIdx : info.PaletteIndex)); }