public TiledPixelOrderIterator(int width, int height, int tileWidth, int tileHeight) { Width = NumberUtils.Align(width, tileWidth); Height = NumberUtils.Align(height, tileHeight); TileWidth = tileWidth; TileHeight = tileHeight; }
private void EnsureAligned() { if (DisableInjection) { return; } long pos = OutputStream.Length; OutputStream.Position = pos; long alignedPos = NumberUtils.Align(pos, 32); while (pos < alignedPos) { OutputStream.WriteByte(0); ++pos; } CurrentInjectionOffset = pos; }
public GamecubeCmpPixelOrderIterator(int width, int height) { Width = NumberUtils.Align(width, 8); Height = NumberUtils.Align(height, 8); }
private (uint width, uint height, IPixelOrderIterator pxit, IColorFetchingIterator colit) GenerateIterators(Stream plane, uint mip) { switch (TXM.Format) { case TextureFormat.RGB565: case TextureFormat.GamecubeRGBA8: case TextureFormat.GamecubeCMP: case TextureFormat.GamecubeCMP2: case TextureFormat.GamecubeCMP4: case TextureFormat.GamecubeCMPA: case TextureFormat.GamecubeCMPC: case TextureFormat.ARGBa: case TextureFormat.ARGBb: case TextureFormat.Indexed4Bits_Grey8Alpha8: case TextureFormat.Indexed4Bits_RGB565: case TextureFormat.Indexed4Bits_RGB5A3: case TextureFormat.Indexed8Bits_Grey8Alpha8: case TextureFormat.Indexed8Bits_RGB565: case TextureFormat.Indexed8Bits_RGB5A3: // we can decode all of these break; default: throw new Exception("Unhandled texture format " + TXM.Format); } var dims = TXM.GetDimensions((int)mip); IPixelOrderIterator pxit; if (TXM.Format == TextureFormat.ARGBa) { pxit = new ARGBaPixelOrderIterator((int)dims.width, (int)dims.height); } else if (TXM.Format == TextureFormat.Indexed4Bits_Grey8Alpha8 || TXM.Format == TextureFormat.Indexed4Bits_RGB565 || TXM.Format == TextureFormat.Indexed4Bits_RGB5A3) { pxit = new TiledPixelOrderIterator((int)dims.width, (int)dims.height, 8, 8); } else if (TXM.Format == TextureFormat.Indexed8Bits_Grey8Alpha8 || TXM.Format == TextureFormat.Indexed8Bits_RGB565 || TXM.Format == TextureFormat.Indexed8Bits_RGB5A3) { pxit = new TiledPixelOrderIterator((int)dims.width, (int)dims.height, 8, 4); } else if (TXM.Format == TextureFormat.RGB565 || TXM.Format == TextureFormat.GamecubeRGBA8) { pxit = new TiledPixelOrderIterator((int)dims.width, (int)dims.height, 4, 4); } else if (TXM.Format == TextureFormat.GamecubeCMP || TXM.Format == TextureFormat.GamecubeCMP2 || TXM.Format == TextureFormat.GamecubeCMP4 || TXM.Format == TextureFormat.GamecubeCMPA || TXM.Format == TextureFormat.GamecubeCMPC) { pxit = new GamecubeCmpPixelOrderIterator((int)dims.width, (int)dims.height); } else { pxit = new LinearPixelOrderIterator((int)dims.width, (int)dims.height); } IColorFetchingIterator colit; if (TXM.Format == TextureFormat.Indexed4Bits_Grey8Alpha8 || TXM.Format == TextureFormat.Indexed4Bits_RGB565 || TXM.Format == TextureFormat.Indexed4Bits_RGB5A3 || TXM.Format == TextureFormat.Indexed8Bits_Grey8Alpha8 || TXM.Format == TextureFormat.Indexed8Bits_RGB565 || TXM.Format == TextureFormat.Indexed8Bits_RGB5A3) { Stream ms = new MemoryStream(); long tmp = plane.Position; plane.Position = plane.Length - TXM.GetExtraPaletteBytes(); StreamUtils.CopyStream(plane, ms, TXM.GetExtraPaletteBytes()); plane.Position = tmp; ms.Position = 0; IColorFetchingIterator colors; if (TXM.Format == TextureFormat.Indexed4Bits_Grey8Alpha8) { colors = new ColorFetcherGrey8Alpha8(ms, 16, 1, EndianUtils.Endianness.BigEndian); colit = new ColorFetcherIndexed4Bits(plane, NumberUtils.Align((long)dims.width, 8), NumberUtils.Align((long)dims.height, 8), colors); } else if (TXM.Format == TextureFormat.Indexed4Bits_RGB565) { colors = new ColorFetcherRGB565(ms, 16, 1, EndianUtils.Endianness.BigEndian); colit = new ColorFetcherIndexed4Bits(plane, NumberUtils.Align((long)dims.width, 8), NumberUtils.Align((long)dims.height, 8), colors); } else if (TXM.Format == TextureFormat.Indexed4Bits_RGB5A3) { colors = new ColorFetcherRGB5A3(ms, 16, 1, EndianUtils.Endianness.BigEndian); colit = new ColorFetcherIndexed4Bits(plane, NumberUtils.Align((long)dims.width, 8), NumberUtils.Align((long)dims.height, 8), colors); } else if (TXM.Format == TextureFormat.Indexed8Bits_Grey8Alpha8) { colors = new ColorFetcherGrey8Alpha8(ms, 256, 1, EndianUtils.Endianness.BigEndian); colit = new ColorFetcherIndexed8Bits(plane, NumberUtils.Align((long)dims.width, 8), NumberUtils.Align((long)dims.height, 4), colors); } else if (TXM.Format == TextureFormat.Indexed8Bits_RGB565) { colors = new ColorFetcherRGB565(ms, 256, 1, EndianUtils.Endianness.BigEndian); colit = new ColorFetcherIndexed8Bits(plane, NumberUtils.Align((long)dims.width, 8), NumberUtils.Align((long)dims.height, 4), colors); } else if (TXM.Format == TextureFormat.Indexed8Bits_RGB5A3) { colors = new ColorFetcherRGB5A3(ms, 256, 1, EndianUtils.Endianness.BigEndian); colit = new ColorFetcherIndexed8Bits(plane, NumberUtils.Align((long)dims.width, 8), NumberUtils.Align((long)dims.height, 4), colors); } else { throw new Exception("Internal error."); } } else if (TXM.Format == TextureFormat.RGB565) { colit = new ColorFetcherRGB565(plane, dims.width, dims.height, EndianUtils.Endianness.BigEndian); } else if (TXM.Format == TextureFormat.GamecubeRGBA8) { colit = new ColorFetcherARGB8888Gamecube(plane, dims.width, dims.height); } else if (TXM.Format == TextureFormat.GamecubeCMP || TXM.Format == TextureFormat.GamecubeCMP2 || TXM.Format == TextureFormat.GamecubeCMP4 || TXM.Format == TextureFormat.GamecubeCMPA || TXM.Format == TextureFormat.GamecubeCMPC) { colit = new ColorFetcherDXT(plane, dims.width, dims.height, DxtFormat.GamecubeCMPR); } else { colit = new ColorFetcherARGB8888(plane, dims.width, dims.height); } return(dims.width, dims.height, pxit, colit); }