Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
 public void Close()
 {
     baseStream.Close();
     offsetTable?.baseStream.Close();
     jobIndexList?.baseStream.Close();
     directionIndexList?.baseStream.Close();
     paletteCollection?.baseStream.Close();
     paletteCollection?.GetPilFile().baseStream.Close();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Changes the images starting from index.
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="index"></param>
        /// <param name="newDatas"></param>
        /// <returns></returns>
        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 palettePosition = 0;
            int addedLength     = 0;
            int oldIndex        = (GetImage(index) as GfxImage)?.jobIndex ?? 0;

            for (int j = 0; j < newDatas.Length; j++)
            {
                if (index + j >= images.Length)
                {
                    Array.Resize(ref images, index + j + 1);

                    paletteCollection.GetPilFile().Resize(images.Length);
                    p.AddEntry();

                    paletteCollection.GetPilFile().SetOffset(index + j, (paletteCollection.GetPilFile().GetOffset(index + j - 1) + 256 * 2));

                    images[index + j] = new GfxImage(
                        null,
                        p,
                        paletteCollection.GetOffset(index + j));

                    images[index + j].jobIndex = index + j;

                    offsetTable.AddOffset();

                    offsetTable.offsetTable[index + j] = (int)baseStream.Length + addedLength;
                }

                GfxImage i = images[index + j];

                if (i.jobIndex != oldIndex)
                {
                    palettePosition = 0;
                }

                int start = paletteCollection.GetOffset(i.jobIndex);

                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]);
                addedLength += i.buffer.Length;

                int nextImageStartOffset = offsetTable.GetImageOffset(index + j + 1);                                                        //Get the current offset of the next image
                int offset = Math.Max(0, offsetTable.GetImageOffset(index + j) + i.HeaderSize + 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...]

                oldIndex = i.jobIndex;

                Console.WriteLine($"{j}/{newDatas.Length} importing...");
            }
            //return GetDataBufferCollection(groupID);
        }