예제 #1
0
파일: NMT.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            PixelDataFormat pixelDataFormat = PixelDataFormat.Undefined;

            switch (PixelFormat)
            {
            case NmtPixelFormat.Indexed4bpp: pixelDataFormat = PixelDataFormat.FormatIndexed4; break;

            case NmtPixelFormat.Indexed8bpp: pixelDataFormat = PixelDataFormat.FormatIndexed8; break;

            case NmtPixelFormat.Argb8888: pixelDataFormat = PixelDataFormat.FormatArgb8888; break;
            }

            imageBinary.Width              = Width;
            imageBinary.Height             = Height;
            imageBinary.InputPaletteFormat = PixelDataFormat.FormatArgb8888;
            imageBinary.InputPixelFormat   = pixelDataFormat;
            imageBinary.InputEndianness    = Endian.LittleEndian;

            foreach (byte[] palette in PaletteData)
            {
                imageBinary.AddInputPalette(palette);
            }
            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #2
0
파일: KSLT.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            KsltImageData imageData = ImageData[imageIndex];

            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width           = imageData.Width;
            imageBinary.Height          = imageData.Height;
            imageBinary.InputEndianness = Endian.LittleEndian;

            switch (imageData.PixelFormat)
            {
            case KsltPixelFormat.Argb8888:
                imageBinary.InputPixelFormat = PixelDataFormat.FormatArgb8888;
                break;

            case KsltPixelFormat.DXT5:
                imageBinary.InputPixelFormat  = PixelDataFormat.FormatDXT5;
                imageBinary.InputPixelFormat |= PixelDataFormat.PixelOrderingSwizzledVita;
                break;

            default: throw new NotImplementedException(string.Format("KSLT format 0x{0:X8}", (uint)imageData.PixelFormat));
            }

            imageBinary.AddInputPixels(imageData.PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #3
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            PixelDataFormat pixelDataFormat = PixelDataFormat.Undefined;

            switch (Header.PixelFormat)
            {
            case TxfPixelFormat.Argb8888: pixelDataFormat = PixelDataFormat.FormatArgb8888; break;

            case TxfPixelFormat.RgbaDxt1: pixelDataFormat = PixelDataFormat.FormatDXT1Rgba; break;

            case TxfPixelFormat.RgbaDxt3: pixelDataFormat = PixelDataFormat.FormatDXT3; break;

            case TxfPixelFormat.RgbaDxt5: pixelDataFormat = PixelDataFormat.FormatDXT5; break;

            case TxfPixelFormat.Argb1555: pixelDataFormat = PixelDataFormat.FormatArgb1555; break;

            case TxfPixelFormat.Argb4444: pixelDataFormat = PixelDataFormat.FormatArgb4444; break;

            case TxfPixelFormat.Rgb565: pixelDataFormat = PixelDataFormat.FormatRgb565; break;
            }

            imageBinary.Width  = Header.Width;
            imageBinary.Height = Header.Height;
            //imageBinary.InputPaletteFormat = PixelDataFormat.FormatArgb8888;
            imageBinary.InputPixelFormat = pixelDataFormat;
            imageBinary.InputEndianness  = Endian.BigEndian;

            //imageBinary.AddInputPalette(PaletteData);
            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #4
0
파일: DDS.cs 프로젝트: 491467928/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            PixelDataFormat inputPixelFormat = PixelDataFormat.Undefined;

            int physicalWidth, physicalHeight;

            if (DDSHeader.PixelFormat.Flags.HasFlag(DDPF.FourCC))
            {
                switch (DDSHeader.PixelFormat.FourCC)
                {
                case "DXT1": inputPixelFormat = PixelDataFormat.FormatDXT1Rgba; break;

                case "DXT3": inputPixelFormat = PixelDataFormat.FormatDXT3; break;

                case "DXT5": inputPixelFormat = PixelDataFormat.FormatDXT5; break;

                case "PVR3": inputPixelFormat = PixelDataFormat.FormatPVRT4_Vita; break;        // TODO: verify, probably not quite like PVRT4?

                case "PVR4": inputPixelFormat = PixelDataFormat.FormatPVRT4_Vita; break;
                }

                physicalWidth = physicalHeight = 1;
                while (physicalWidth < DDSHeader.Width)
                {
                    physicalWidth *= 2;
                }
                while (physicalHeight < DDSHeader.Height)
                {
                    physicalHeight *= 2;
                }
            }
            else
            {
                physicalWidth  = (int)DDSHeader.Width;
                physicalHeight = (int)DDSHeader.Height;
            }

            if (inputPixelFormat == PixelDataFormat.Undefined)
            {
                throw new NotImplementedException("DDS pixel format not implemented");
            }

            // TODO: total guesswork, verify me!
            if (DDSHeader.Reserved1[0x0A] == 0x00020008)
            {
                inputPixelFormat |= PixelDataFormat.PixelOrderingSwizzledVita;
            }

            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width            = (int)DDSHeader.Width;
            imageBinary.Height           = (int)DDSHeader.Height;
            imageBinary.PhysicalWidth    = physicalWidth;
            imageBinary.PhysicalHeight   = physicalHeight;
            imageBinary.InputPixelFormat = inputPixelFormat;
            imageBinary.InputEndianness  = Endian.LittleEndian;
            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #5
0
파일: PSSG.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            List <PSSGNode> allTextures    = RootNode.FindNodes("TEXTURE");
            PSSGNode        texNode        = allTextures[imageIndex];
            Int32           width          = Convert.ToInt32(texNode.Attributes["width"].Value);
            Int32           height         = Convert.ToInt32(texNode.Attributes["height"].Value);
            Int32           numBlocks      = Convert.ToInt32(texNode.Attributes["imageBlockCount"].Value);
            string          texelFormat    = texNode.Attributes["texelFormat"].Value;
            PixelDataFormat pixelFormat    = PixelDataFormat.Undefined;
            bool            flipY          = false;
            List <PSSGNode> texImageBlocks = texNode.FindNodes("TEXTUREIMAGEBLOCK");

            switch (texelFormat)
            {
            case "ui8x4":
                pixelFormat = PixelDataFormat.FormatArgb8888 | PixelDataFormat.PixelOrderingLinear;
                flipY       = true;
                break;

            case "u8x4":
                pixelFormat = PixelDataFormat.FormatAbgr8888 | PixelDataFormat.PixelOrderingLinear;
                flipY       = true;
                break;

            case "dxt1":
                pixelFormat = PixelDataFormat.FormatDXT1Rgba;
                flipY       = true;
                break;

            case "dxt5":
                pixelFormat = PixelDataFormat.FormatDXT5;
                flipY       = true;
                break;

            default:
                throw new NotSupportedException(String.Format("Unsupported PSSG texel Format: {0}", texelFormat));
            }

            /* find out how many raw data blocks there are */
            if (numBlocks > 1)
            {
                throw new NotSupportedException("Loading PSSG cube maps is not yet supported");
            }
            else
            {
                /* we only have a single block. use that */
                ImageBinary imgbin = new ImageBinary();
                imgbin.Width            = width;
                imgbin.Height           = height;
                imgbin.InputPixelFormat = pixelFormat;
                imgbin.InputEndianness  = Endian.LittleEndian;
                imgbin.AddInputPixels(texImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Data);
                Bitmap bmp = imgbin.GetBitmap();
                if (flipY)
                {
                    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }
                return(bmp);
            }
        }
예제 #6
0
파일: VTXP.cs 프로젝트: wchristian/Scarlet
        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());
        }
예제 #7
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width           = (int)Width;
            imageBinary.Height          = (int)Height;
            imageBinary.InputEndianness = Endian.LittleEndian;

            if (PaletteData != null)
            {
                imageBinary.InputPaletteFormat = PixelDataFormat.FormatAbgr8888;
                imageBinary.AddInputPalette(PaletteData);
            }

            switch (PixelFormat)
            {
            case TxgPixelFormat.Abgr8888:
                imageBinary.InputPixelFormat = PixelDataFormat.FormatAbgr8888 | PixelDataFormat.PixelOrderingSwizzledPSP;
                break;

            case TxgPixelFormat.Bgr565:
                imageBinary.InputPixelFormat = PixelDataFormat.FormatBgr565 | PixelDataFormat.PixelOrderingTiled;
                break;

            case TxgPixelFormat.Indexed8bpp:
                imageBinary.InputPixelFormat = PixelDataFormat.FormatIndexed8 | PixelDataFormat.PixelOrderingSwizzledPSP;
                break;

            default: throw new NotImplementedException();
            }

            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #8
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            PixelDataFormat pixelDataFormat = PixelDataFormat.Undefined;

            switch (PixelFormat)
            {
            case DMPBMPixelFormat.Alpha8: pixelDataFormat = PixelDataFormat.FormatAlpha8; break;

            case DMPBMPixelFormat.Rgba4444: pixelDataFormat = PixelDataFormat.FormatRgba4444; break;

            case DMPBMPixelFormat.Rgba5551: pixelDataFormat = PixelDataFormat.FormatRgba5551; break;

            case DMPBMPixelFormat.Rgba8888: pixelDataFormat = PixelDataFormat.FormatRgba8888; break;

            default: throw new NotImplementedException(string.Format("DMPBM format 0x{0:X}", PixelFormat));
            }
            pixelDataFormat |= PixelDataFormat.PixelOrderingTiled3DS;

            imageBinary.Width            = (int)Width;
            imageBinary.Height           = (int)Height;
            imageBinary.InputPixelFormat = pixelDataFormat;
            imageBinary.InputEndianness  = Endian.LittleEndian;

            imageBinary.AddInputPixels(PixelData);

            Bitmap bitmap = imageBinary.GetBitmap();

            bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            return(bitmap);
        }
예제 #9
0
파일: G1TG.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            G1TGImageDataShim imageDataShim = imageDataShims[imageIndex];

            imageBinary = new ImageBinary();
            imageBinary.AddInputPixels(imageDataShim.Data);
            imageBinary.InputPixelFormat = imageDataShim.Format;
            imageBinary.Width            = imageDataShim.Width;
            imageBinary.Height           = imageDataShim.Height;

            return(imageBinary.GetBitmap(0, 0));
        }
예제 #10
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width            = mipmapData[imageIndex].Width;
            imageBinary.Height           = mipmapData[imageIndex].Height;
            imageBinary.InputPixelFormat = (mappingInfo.Item1 /*| PixelDataFormat.PixelOrderingSwizzledSwitch*/);
            imageBinary.InputEndianness  = Endian.LittleEndian;
            imageBinary.AddInputPixels(mipmapData[imageIndex].PixelData);

            return(imageBinary.GetBitmap(0, 0));
        }
예제 #11
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width            = (int)Width;
            imageBinary.Height           = (int)Height;
            imageBinary.InputPixelFormat = pixelDataFormat;
            imageBinary.InputEndianness  = Endian.LittleEndian;

            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #12
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary
            {
                Width            = mipmapData[imageIndex].Width,
                Height           = mipmapData[imageIndex].Height,
                InputPixelFormat = pixelDataFormat
            };

            imageBinary.AddInputPixels(mipmapData[imageIndex].PixelData);

            return(imageBinary.GetBitmap(0, 0));
        }
예제 #13
0
파일: DMPBM.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            PixelDataFormat pixelDataFormat = PixelDataFormat.Undefined;

            switch (PixelFormat)
            {
            case DMPBMPixelFormat.Alpha8: pixelDataFormat = PixelDataFormat.FormatAlpha8; break;

            case DMPBMPixelFormat.Rgba4444: pixelDataFormat = PixelDataFormat.FormatRgba4444; break;

            case DMPBMPixelFormat.Rgba5551: pixelDataFormat = PixelDataFormat.FormatRgba5551; break;

            case DMPBMPixelFormat.Rgba8888: pixelDataFormat = PixelDataFormat.FormatRgba8888; break;

            case DMPBMPixelFormat.Indexed8: pixelDataFormat = PixelDataFormat.FormatIndexed8; break;

            default: throw new NotImplementedException(string.Format("DMPBM format 0x{0:X}", PixelFormat));
            }
            pixelDataFormat |= PixelDataFormat.PixelOrderingTiled3DS;

            imageBinary.Width            = (int)Width;
            imageBinary.Height           = (int)Height;
            imageBinary.InputPixelFormat = pixelDataFormat;
            imageBinary.InputEndianness  = Endian.LittleEndian;

            imageBinary.AddInputPixels(PixelData);

            if (PaletteData != null)
            {
                switch (PixelFormat)
                {
                // XBGR1555 ?
                case DMPBMPixelFormat.Indexed8:
                    imageBinary.InputPaletteFormat = (PixelDataFormat.Bpp16 | PixelDataFormat.ChannelsXbgr | PixelDataFormat.RedBits5 | PixelDataFormat.GreenBits5 | PixelDataFormat.BlueBits5 | PixelDataFormat.AlphaBits1);
                    break;

                default: throw new NotImplementedException(string.Format("DMPBM palette for format 0x{0:X}", PixelFormat));
                }

                imageBinary.AddInputPalette(PaletteData);
            }

            Bitmap bitmap = imageBinary.GetBitmap();

            bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            return(bitmap);
        }
예제 #14
0
파일: RTEX.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary
            {
                PhysicalWidth    = PhysicalWidth,
                PhysicalHeight   = PhysicalHeight,
                Width            = VirtualWidth,
                Height           = VirtualHeight,
                InputPixelFormat = pixelDataFormat,
                InputEndianness  = Endian.LittleEndian
            };

            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap(imageIndex, paletteIndex));
        }
예제 #15
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            PixelDataFormat pixelDataFormat, paletteDataFormat;

            if (Format == 0x8602)
            {
                pixelDataFormat   = PixelDataFormat.FormatIndexed4 | PixelDataFormat.PixelOrderingSwizzledPSP;
                paletteDataFormat = PixelDataFormat.FormatAbgr4444;
            }
            else if (Format == 0x8803)
            {
                pixelDataFormat   = PixelDataFormat.FormatIndexed4 | PixelDataFormat.PixelOrderingSwizzledPSP;
                paletteDataFormat = PixelDataFormat.FormatAbgr8888;
            }
            else if (Format == 0x8A02)
            {
                pixelDataFormat   = PixelDataFormat.FormatIndexed8 | PixelDataFormat.PixelOrderingSwizzledPSP;
                paletteDataFormat = PixelDataFormat.FormatAbgr4444;
            }
            else if (Format == 0x8C03)
            {
                pixelDataFormat   = PixelDataFormat.FormatIndexed8 | PixelDataFormat.PixelOrderingSwizzledPSP;
                paletteDataFormat = PixelDataFormat.FormatAbgr8888;
            }
            else if (Format == 0x800A)
            {
                pixelDataFormat   = PixelDataFormat.FormatDXT1Rgba_PSP;
                paletteDataFormat = PixelDataFormat.Undefined;
            }
            else
            {
                throw new NotImplementedException();
            }

            imageBinary.Width              = Width;
            imageBinary.Height             = Height;
            imageBinary.InputPaletteFormat = paletteDataFormat;
            imageBinary.InputPixelFormat   = pixelDataFormat;
            imageBinary.InputEndianness    = Endian.LittleEndian;

            imageBinary.AddInputPalette(PaletteData);
            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #16
0
파일: CTXB.cs 프로젝트: wchristian/Scarlet
        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));
        }
예제 #17
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
#if DEBUG
            // DEBUG: if Scarlet format isn't set, return empty image
            if (pixelDataFormat == PixelDataFormat.Undefined)
            {
                return(new Bitmap(mipmapLevels[imageIndex].Width, mipmapLevels[imageIndex].Height));
            }
#endif
            ImageBinary imageBinary = new ImageBinary();
            imageBinary.Width            = mipmapLevels[imageIndex].Width;
            imageBinary.Height           = mipmapLevels[imageIndex].Height;
            imageBinary.InputPixelFormat = pixelDataFormat;
            imageBinary.InputEndianness  = Endian.LittleEndian; // ????
            imageBinary.AddInputPixels(mipmapLevels[imageIndex].PixelData);

            return(imageBinary.GetBitmap(0, 0));
        }
예제 #18
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);
        }
예제 #19
0
        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));
        }
예제 #20
0
        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();
            }
        }
예제 #21
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            PixelDataFormat inputPixelFormat = PixelDataFormat.Undefined;

            int physicalWidth, physicalHeight;

            if (DDSHeader.PixelFormat.Flags.HasFlag(DDPF.FourCC))
            {
                switch (DDSHeader.PixelFormat.FourCC)
                {
                case "DXT1": inputPixelFormat = PixelDataFormat.FormatDXT1Rgba; break;

                case "DXT3": inputPixelFormat = PixelDataFormat.FormatDXT3; break;

                case "DXT5": inputPixelFormat = PixelDataFormat.FormatDXT5; break;

                case "PVR3": inputPixelFormat = PixelDataFormat.FormatPVRT4_Vita; break;        // TODO: verify, probably not quite like PVRT4?

                case "PVR4": inputPixelFormat = PixelDataFormat.FormatPVRT4_Vita; break;
                }

                physicalWidth = physicalHeight = 1;
                while (physicalWidth < DDSHeader.Width)
                {
                    physicalWidth *= 2;
                }
                while (physicalHeight < DDSHeader.Height)
                {
                    physicalHeight *= 2;
                }
            }
            else
            {
                // TODO: actually implement uncompressed DDS formats...?

                PixelDataFormat alphaFormat = PixelDataFormat.Undefined, colorFormat = PixelDataFormat.Undefined;

                if (DDSHeader.PixelFormat.Flags.HasFlag(DDPF.AlphaPixels))
                {
                    switch (DDSHeader.PixelFormat.ABitMask)
                    {
                    case 0xFF000000: alphaFormat |= PixelDataFormat.AlphaBits8; break;

                    default: throw new NotImplementedException("DDS alpha bit mask not implemented");
                    }
                }

                if (DDSHeader.PixelFormat.Flags.HasFlag(DDPF.RGB))
                {
                    switch (DDSHeader.PixelFormat.RBitMask)
                    {
                    case 0x00FF0000: colorFormat |= PixelDataFormat.RedBits8; break;

                    default: throw new NotImplementedException("DDS red bit mask not implemented");
                    }

                    switch (DDSHeader.PixelFormat.GBitMask)
                    {
                    case 0x0000FF00: colorFormat |= PixelDataFormat.GreenBits8; break;

                    default: throw new NotImplementedException("DDS green bit mask not implemented");
                    }

                    switch (DDSHeader.PixelFormat.BBitMask)
                    {
                    case 0x000000FF: colorFormat |= PixelDataFormat.BlueBits8; break;

                    default: throw new NotImplementedException("DDS blue bit mask not implemented");
                    }
                }

                if (DDSHeader.PixelFormat.RBitMask != 0 && DDSHeader.PixelFormat.GBitMask != 0 && DDSHeader.PixelFormat.BBitMask != 0 && DDSHeader.PixelFormat.ABitMask != 0)
                {
                    inputPixelFormat |= PixelDataFormat.ChannelsArgb;
                }
                else
                {
                    throw new NotImplementedException("DDS channel setup not implemented");
                }

                if (DDSHeader.PixelFormat.RGBBitCount == 32)
                {
                    inputPixelFormat |= PixelDataFormat.Bpp32;
                }
                else
                {
                    throw new NotImplementedException("DDS bits per pixel not implemented");
                }

                inputPixelFormat |= colorFormat;
                inputPixelFormat |= alphaFormat;

                physicalWidth  = (int)DDSHeader.Width;
                physicalHeight = (int)DDSHeader.Height;
            }

            if (inputPixelFormat == PixelDataFormat.Undefined)
            {
                throw new NotImplementedException("DDS pixel format not implemented");
            }

            if (DDSHeader.Reserved1[0x0A] == 0x00020008)
            {
                // TODO: total guesswork, verify me!
                inputPixelFormat |= PixelDataFormat.PixelOrderingSwizzledVita;
            }

            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width            = (int)DDSHeader.Width;
            imageBinary.Height           = (int)DDSHeader.Height;
            imageBinary.PhysicalWidth    = physicalWidth;
            imageBinary.PhysicalHeight   = physicalHeight;
            imageBinary.InputPixelFormat = inputPixelFormat;
            imageBinary.InputEndianness  = Endian.LittleEndian;
            imageBinary.AddInputPixels(PixelData);

            return(imageBinary.GetBitmap());
        }
예제 #22
0
파일: GBIX.cs 프로젝트: wchristian/Scarlet
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            ImageBinary imageBinary = new ImageBinary();

            PixelDataFormat pixelDataFormat, paletteDataFormat;

            switch (ImageType)
            {
            // Non-indexed image
            case GbixImageType.Linear:
            case GbixImageType.LinearMipmaps:
                if (!dataTypeFormatMap.ContainsKey(DataType))
                {
                    throw new NotImplementedException(string.Format("GBIX: unimplemented pixel data type {0} (0x{1:X2})", DataType, (byte)DataType));
                }

                pixelDataFormat = dataTypeFormatMap[DataType];
                if (!isCompressed)
                {
                    pixelDataFormat |= PixelDataFormat.PixelOrderingSwizzledPSP;
                }
                paletteDataFormat = PixelDataFormat.Undefined;
                break;

            // Indexed image (4-bit)
            case GbixImageType.Indexed4:
            case GbixImageType.Indexed4_Alt:
                if (!dataTypeFormatMap.ContainsKey(DataType))
                {
                    throw new NotImplementedException(string.Format("GBIX: unimplemented palette data type {0} (0x{1:X2})", DataType, (byte)DataType));
                }

                pixelDataFormat   = PixelDataFormat.FormatIndexed4 | PixelDataFormat.PixelOrderingSwizzledPSP;
                paletteDataFormat = dataTypeFormatMap[DataType];
                break;

            // Indexed image (8-bit)
            case GbixImageType.Indexed8:
            case GbixImageType.Indexed8_Alt:
                if (!dataTypeFormatMap.ContainsKey(DataType))
                {
                    throw new NotImplementedException(string.Format("GBIX: unimplemented palette data type {0} (0x{1:X2})", DataType, (byte)DataType));
                }

                pixelDataFormat   = PixelDataFormat.FormatIndexed8 | PixelDataFormat.PixelOrderingSwizzledPSP;
                paletteDataFormat = dataTypeFormatMap[DataType];
                break;

            default:
                throw new NotImplementedException(string.Format("GBIX: unimplemented image type {0} (0x{1:X2})", ImageType, (byte)ImageType));
            }

            imageBinary.Width              = mipmapData[imageIndex].Width;
            imageBinary.Height             = mipmapData[imageIndex].Height;
            imageBinary.InputPaletteFormat = paletteDataFormat;
            imageBinary.InputPixelFormat   = pixelDataFormat;
            imageBinary.InputEndianness    = Endian.LittleEndian;

            imageBinary.AddInputPalette(PaletteData);
            imageBinary.AddInputPixels(mipmapData[imageIndex].PixelData);

            return(imageBinary.GetBitmap(0, 0));
        }
예제 #23
0
 protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
 {
     return(imageBinary.GetBitmap(imageIndex, paletteIndex));
 }
예제 #24
0
파일: TxrBlock.cs 프로젝트: jpmac26/SrdTool
        public void ExtractImages(string srdvPath, string outputFolder, bool extractMipmaps)
        {
            // Read image data based on resource info
            for (int m = 0; m < (extractMipmaps ? ResourceBlock.ResourceInfoList1.Count : 1); m++)
            {
                byte[] imageData;

                using (BinaryReader srdvReader = new BinaryReader(new FileStream(srdvPath, FileMode.Open)))
                {
                    srdvReader.BaseStream.Seek(ResourceBlock.ResourceInfoList1[m].Unk1, SeekOrigin.Begin);
                    imageData = srdvReader.ReadBytes(ResourceBlock.ResourceInfoList1[m].Unk2);

                    // TODO: Read palette data
                }


                // Determine pixel format
                PixelDataFormat pixelFormat = PixelDataFormat.Undefined;
                switch (Format)
                {
                case 0x01:
                    pixelFormat = PixelDataFormat.FormatArgb8888;
                    break;

                case 0x02:
                    pixelFormat = PixelDataFormat.FormatBgr565;
                    break;

                case 0x05:
                    pixelFormat = PixelDataFormat.FormatBgra4444;
                    break;

                case 0x0F:
                    pixelFormat = PixelDataFormat.FormatDXT1Rgb;
                    break;

                case 0x11:
                    pixelFormat = PixelDataFormat.FormatDXT5;
                    break;

                case 0x14:      // RGTC2 / BC5
                    pixelFormat = PixelDataFormat.FormatRGTC2;
                    break;

                case 0x16:      // RCTC1 / BC4
                    pixelFormat = PixelDataFormat.FormatRGTC1;
                    break;

                case 0x1C:
                    pixelFormat = PixelDataFormat.FormatBPTC;
                    break;
                }

                if (ResourceBlock.Unk3 == 0x08)
                {
                    DispWidth  = (short)Utils.PowerOfTwo(DispWidth);
                    DispHeight = (short)Utils.PowerOfTwo(DispHeight);
                }

                bool swizzled = ((Swizzle & 1) == 0);

                // Calculate mipmap dimensions
                int mipWidth  = (int)Math.Max(1, DispWidth / Math.Pow(2, m));
                int mipHeight = (int)Math.Max(1, DispHeight / Math.Pow(2, m));

                ImageBinary imageBinary = new ImageBinary(mipWidth, mipHeight, pixelFormat, imageData);
                Bitmap      tex         = imageBinary.GetBitmap();


                string mipmapName      = ResourceBlock.StringData.First();
                int    extensionLength = mipmapName.Split('.').Last().Length + 1;

                if (m > 0)
                {
                    mipmapName = mipmapName.Insert(mipmapName.Length - extensionLength, string.Format(" ({0}x{1})", mipWidth.ToString(), mipHeight.ToString()));
                }


                ImageFormat imageFormat;
                switch (mipmapName.Split('.').Last().ToLower())
                {
                case "bmp":
                    imageFormat = ImageFormat.Bmp;
                    break;

                case "png":
                    imageFormat = ImageFormat.Png;
                    break;

                default:
                    imageFormat = ImageFormat.Png;
                    mipmapName += ".png";
                    break;
                }

                FileStream imageOut = File.Create(outputFolder + '/' + mipmapName);
                tex.Save(imageOut, imageFormat);
                imageOut.Close();
            }
        }