public void ChangeImageData(string groupID, int index, ImageData[] newDatas) { if (newDatas[0].GetUsedColors().Length > 255) { throw new Exception("Imported images cannot have more than 255 colors!"); } //Prepare the new palette Palette p = paletteCollection.GetPalette(); int start = paletteCollection.GetOffset(GetImage(index).jobIndex); int palettePosition = 0; for (int j = 0; j < newDatas.Length; j++) { GfxImage i = images[index + j]; i.Width = newDatas[j].width; i.Height = newDatas[j].height; //i.DataOffset = offsetTable.GetImageOffset(index + j) + 12; palettePosition += RecreatePaletteAt(start, palettePosition, newDatas[j]); i.buffer = i.CreateImageData(newDatas[j]); int nextImageStartOffset = offsetTable.GetImageOffset(index + j + 1); //Get the current offset of the next image int offset = Math.Max(0, i.DataOffset + i.buffer.Length - nextImageStartOffset - 1); //Our data could be larger, calculate how much larger if (offset != 0) //We want to move all images that follow our changed image, if our new image is bigger { offsetTable.AddOffsetToFollowing(index + j + 1, offset); } i.DataOffset = 0; //Hack, the data is still at the same offset, but the way the we handle the reading forces us to set it to 0, as we write the new image data to buffer[0...] instead of buffer[DataOffset...] } byte[] gfxDataBuffer = GetData(); byte[] pilDataBuffer = paletteCollection.GetPilFile().GetData(); byte[] paletteDataBuffer = paletteCollection.GetData(); string fileId = groupID; File.WriteAllBytes(fileId + ".gfx", gfxDataBuffer); File.WriteAllBytes(fileId + ".pi4", pilDataBuffer); File.WriteAllBytes(fileId + ".p46", paletteDataBuffer); File.WriteAllBytes(fileId + ".pi2", pilDataBuffer); File.WriteAllBytes(fileId + ".p26", paletteDataBuffer); File.WriteAllBytes(fileId + ".gil", offsetTable.GetData()); }
public DataBufferCollection GetDataBufferCollection(string groupID) { byte[] gfxDataBuffer = GetData(); byte[] pilDataBuffer = paletteCollection.GetPilFile().GetData(); byte[] paletteDataBuffer = paletteCollection.GetData(); string fileId = groupID; return(new DataBufferCollection(fileId) .AddBuffer(gfxDataBuffer, "gfx") .AddBuffer(pilDataBuffer, "pil") //"pi4", "pi2") .AddBuffer(paletteDataBuffer, "pa5", "pa6") //"p46", "p26") .AddBuffer(offsetTable.GetData(), "gil")); }