internal static PVRTCTexHeader Read(BinaryReader br) { var h = new PVRTCTexHeader(); h.headerLength = br.ReadInt32(); h.height = br.ReadInt32(); h.width = br.ReadInt32(); h.numMipmaps = br.ReadInt32(); h.flags = br.ReadInt32(); h.dataLength = br.ReadInt32(); h.bpp = br.ReadInt32(); h.bitmaskRed = br.ReadInt32(); h.bitmaskGreen = br.ReadInt32(); h.bitmaskBlue = br.ReadInt32(); h.bitmaskAlpha = br.ReadInt32(); h.pvrTag = br.ReadInt32(); h.numSurfs = br.ReadInt32(); return(h); }
internal static PVRTCTexHeader Read( BinaryReader br ) { var h = new PVRTCTexHeader(); h.headerLength = br.ReadInt32(); h.height = br.ReadInt32(); h.width = br.ReadInt32(); h.numMipmaps = br.ReadInt32(); h.flags = br.ReadInt32(); h.dataLength = br.ReadInt32(); h.bpp = br.ReadInt32(); h.bitmaskRed = br.ReadInt32(); h.bitmaskGreen = br.ReadInt32(); h.bitmaskBlue = br.ReadInt32(); h.bitmaskAlpha = br.ReadInt32(); h.pvrTag = br.ReadInt32(); h.numSurfs = br.ReadInt32(); return h; }
public override Codec.DecodeResult Decode(Stream input) { using (var br = new BinaryReader(input)) { var numFaces = 1; // Assume one face until we know otherwise var imgData = new ImageData(); // Read the PVRTC header var header = PVRTCTexHeader.Read(br); // Get the file type identifier var pvrTag = header.pvrTag; if (this.PVR_MAGIC != pvrTag) { throw new AxiomException("This is not a PVR file!"); } // Get format flags var flags = header.flags; using (var wrap = BufferBase.Wrap(flags, 2)) { _flipEndian(wrap, sizeof(int)); } var formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK; var bitmaskAlpha = header.bitmaskAlpha; using (var wrap = BufferBase.Wrap(bitmaskAlpha, 2)) { _flipEndian(wrap, sizeof(int)); } if (formatFlags == kPVRTextureFlagTypePVRTC_4 || formatFlags == kPVRTextureFlagTypePVRTC_2) { if (formatFlags == kPVRTextureFlagTypePVRTC_4) { imgData.format = bitmaskAlpha != 0 ? PixelFormat.PVRTC_RGBA4 : PixelFormat.PVRTC_RGB4; } else if (formatFlags == kPVRTextureFlagTypePVRTC_2) { imgData.format = bitmaskAlpha != 0 ? PixelFormat.PVRTC_RGBA2 : PixelFormat.PVRTC_RGB2; } imgData.depth = 1; imgData.width = header.width; imgData.height = header.height; imgData.numMipMaps = header.numMipmaps; // PVRTC is a compressed format imgData.flags |= ImageFlags.Compressed; } // Calculate total size from number of mipmaps, faces and size imgData.size = Image.CalculateSize(imgData.numMipMaps, numFaces, imgData.width, imgData.height, imgData.depth, imgData.format); // Now deal with the data var dest = br.ReadBytes(imgData.size); return(new DecodeResult(new MemoryStream(dest), imgData)); } }