// Initalize public override bool Initalize(int Width, int Height, GimPaletteDecoder PaletteDecoder, int PaletteEntries) { width = Width; height = Height; init = true; return true; }
// Initalize public override bool Initalize(int Width, int Height, GimPaletteDecoder PaletteDecoder, int PaletteEntries) { width = Width; height = Height; init = true; return(true); }
// Initalize public abstract bool Initalize(int Width, int Height, GimPaletteDecoder PaletteDecoder, int PaletteEntries);
// - Data Input - // Description: Inputs compressed GIM data (And unpacks it to RGBA8888) // Parameters: // byte[] Compressed: Compressed Data to load // Return Value: True if the data was properly loaded. public bool SetCompressedData(byte[] Compressed) { if (Compressed == null) { throw new ArgumentException("SetCompressedData: Argument 1, 'Compressed', Can not be null."); } else { CompressedData = Compressed; } if (!IsMig()) throw new NotGimException("The file sent to SetCompressedData() is not a little endian GIM file."); // Sometimes, the palette is stored after the image data if (CompressedData[0x30] == 0x05) { // Palette is stored before the image data GimPaletteOffset = 0x30; GimDataOffset = 0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8); } else if (0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8) < CompressedData.Length && CompressedData[0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8)] == 0x05) { // Palette is stored after the image data GimPaletteOffset = 0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8); GimDataOffset = 0x30; } else { // No Palette GimPaletteOffset = 0x00; GimDataOffset = 0x30; } // Some files do not have a palette. Trying to get a palette will throw an exception. if (GimPaletteOffset > 0x00) { // Get Palette Information GimPaletteFormatCode = Compressed[GimPaletteOffset + 0x14]; GimPaletteColors = BitConverter.ToUInt16(Compressed, GimPaletteOffset + 0x18); // Set up the palette decoder try { GimPaletteDecoder = GimCodecs.GetPaletteCodec(GimPaletteFormatCode).Decode; GimPaletteSize = GimPaletteColors * (GimPaletteDecoder.GetBpp() / 8); } catch (Exception e) { throw new GimCodecLoadingException("The codec for palette format 0x" + GimPaletteFormatCode.ToString("X") + " could not be loaded or does not exist.", e); } } GimFileWidth = RoundUp(BitConverter.ToUInt16(Compressed, GimDataOffset + 0x18), 16); GimFileHeight = RoundUp(BitConverter.ToUInt16(Compressed, GimDataOffset + 0x1A), 8); GimDataFormatCode = Compressed[GimDataOffset + 0x14]; GimDataSwizzled = (BitConverter.ToUInt16(Compressed, GimDataOffset + 0x16) == 0x01); // Set up and initalize the data decoder try { GimDataDecoder = GimCodecs.GetDataCodec(GimDataFormatCode).Decode; GimDataDecoder.Initalize(GimFileWidth, GimFileHeight, GimPaletteDecoder, GimPaletteColors); } catch (Exception e) { throw new GimCodecLoadingException("The codec for data format 0x" + GimDataFormatCode.ToString("X") + " could not be loaded or does not exist.", e); } // Decode palette and then start decoding the image DecompressedData = new byte[GimFileWidth * GimFileHeight * 4]; GimDataDecoder.DecodePalette(ref CompressedData, GimPaletteOffset + 0x50); if (GimDataSwizzled) GimDataDecoder.UnSwizzle(ref CompressedData, GimDataOffset + 0x50); GimDataDecoder.DecodeData(ref CompressedData, GimDataOffset + 0x50, ref DecompressedData); return true; }
// - Data Input - // Description: Inputs compressed GIM data (And unpacks it to RGBA8888) // Parameters: // byte[] Compressed: Compressed Data to load // Return Value: True if the data was properly loaded. public bool SetCompressedData(byte[] Compressed) { if (Compressed == null) { throw new ArgumentException("SetCompressedData: Argument 1, 'Compressed', Can not be null."); } else { CompressedData = Compressed; } if (!IsMig()) { throw new NotGimException("The file sent to SetCompressedData() is not a little endian GIM file."); } // Sometimes, the palette is stored after the image data if (CompressedData[0x30] == 0x05) { // Palette is stored before the image data GimPaletteOffset = 0x30; GimDataOffset = 0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8); } else if (0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8) < CompressedData.Length && CompressedData[0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8)] == 0x05) { // Palette is stored after the image data GimPaletteOffset = 0x30 + BitConverter.ToInt32(CompressedData, 0x30 + 0x8); GimDataOffset = 0x30; } else { // No Palette GimPaletteOffset = 0x00; GimDataOffset = 0x30; } // Some files do not have a palette. Trying to get a palette will throw an exception. if (GimPaletteOffset > 0x00) { // Get Palette Information GimPaletteFormatCode = Compressed[GimPaletteOffset + 0x14]; GimPaletteColors = BitConverter.ToUInt16(Compressed, GimPaletteOffset + 0x18); // Set up the palette decoder try { GimPaletteDecoder = GimCodecs.GetPaletteCodec(GimPaletteFormatCode).Decode; GimPaletteSize = GimPaletteColors * (GimPaletteDecoder.GetBpp() / 8); } catch (Exception e) { throw new GimCodecLoadingException("The codec for palette format 0x" + GimPaletteFormatCode.ToString("X") + " could not be loaded or does not exist.", e); } } GimFileWidth = RoundUp(BitConverter.ToUInt16(Compressed, GimDataOffset + 0x18), 16); GimFileHeight = RoundUp(BitConverter.ToUInt16(Compressed, GimDataOffset + 0x1A), 8); GimDataFormatCode = Compressed[GimDataOffset + 0x14]; GimDataSwizzled = (BitConverter.ToUInt16(Compressed, GimDataOffset + 0x16) == 0x01); // Set up and initalize the data decoder try { GimDataDecoder = GimCodecs.GetDataCodec(GimDataFormatCode).Decode; GimDataDecoder.Initalize(GimFileWidth, GimFileHeight, GimPaletteDecoder, GimPaletteColors); } catch (Exception e) { throw new GimCodecLoadingException("The codec for data format 0x" + GimDataFormatCode.ToString("X") + " could not be loaded or does not exist.", e); } // Decode palette and then start decoding the image DecompressedData = new byte[GimFileWidth * GimFileHeight * 4]; GimDataDecoder.DecodePalette(ref CompressedData, GimPaletteOffset + 0x50); if (GimDataSwizzled) { GimDataDecoder.UnSwizzle(ref CompressedData, GimDataOffset + 0x50); } GimDataDecoder.DecodeData(ref CompressedData, GimDataOffset + 0x50, ref DecompressedData); return(true); }