private void GenericEncodeImage(Bitmap bitmapToEncode, int[] preferredIndexes) { try { switch (_imageType) { case ImageType.Background: { var encoder = new ImageEncoder(); encoder.PaletteIndex = PaletteIndex; encoder.EncodeSettings = (ImageEncoder.EncodeTypeSettings)CompressionMethod.SelectedIndex; encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(_roomBlock, bitmapToEncode); } break; case ImageType.ZPlane: { var encoder = new ZPlaneEncoder(); encoder.Encode(_roomBlock, bitmapToEncode, _zPlaneIndex); } break; case ImageType.Object: if (_roomBlock.GetOBIMs()[_objectIndex].GetIMxx()[_imageIndex].GetSMAP() == null) { var encoder = new BompImageEncoder(); encoder.PaletteIndex = PaletteIndex; encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(_roomBlock, _objectIndex, _imageIndex, bitmapToEncode); } else { var encoder = new ImageEncoder(); encoder.PaletteIndex = PaletteIndex; encoder.EncodeSettings = (ImageEncoder.EncodeTypeSettings)CompressionMethod.SelectedIndex; encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(_roomBlock, _objectIndex, _imageIndex, bitmapToEncode); } break; case ImageType.ObjectsZPlane: { var encoder = new ZPlaneEncoder(); encoder.Encode(_roomBlock, _objectIndex, _imageIndex, bitmapToEncode, _zPlaneIndex); } break; case ImageType.Costume: { var encoder = new CostumeImageEncoder(); encoder.PaletteIndex = PaletteIndex; encoder.Encode(_roomBlock, _costume, _imageIndex, bitmapToEncode); } break; } } catch (ImageEncodeException ex) { MessageBox.Show(ex.Message, "Error importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ImportLocation.Text)) { return; } if (!Directory.Exists(ImportLocation.Text)) { return; } string location = ImportLocation.Text; Cursor = Cursors.WaitCursor; Cancel.Cursor = Cursors.Default; _cancelImport = false; _importing = true; foreach (Control control in Controls) { if (control.Name != "Cancel" && control.GetType() != typeof(Label) && control.GetType() != typeof(ProgressBar)) { control.Enabled = false; } } List <ImageInfo> files = Directory.GetFiles(location, "*.png").Select(f => new ImageInfo(f)).ToList(); Application.DoEvents(); List <DiskBlock> diskBlocks = _scummFile.DataFile.GetLFLFs(); Progress.Maximum = files.Count - 1; Progress.Value = 0; Progress.Visible = true; FilesFound.Text = files.Count.ToString(); var encoder = new ImageEncoder(); var bompEncoder = new BompImageEncoder(); var costumeEncoder = new CostumeImageEncoder(); var zplaneEncoder = new ZPlaneEncoder(); for (int i = 0; i < files.Count; i++) { ImageInfo currentFile = files[i]; RoomBlock currentRoomBlock = diskBlocks[currentFile.RoomIndex].GetROOM(); Bitmap bitmapToEncode = (Bitmap)Bitmap.FromFile(currentFile.Filename); var preferredIndexes = new int[0]; string indexFile = currentFile.Filename + ".idx"; if (File.Exists(indexFile)) { preferredIndexes = File.ReadAllText(indexFile).Split(';').Select(s => Convert.ToInt32(s)).ToArray(); } try { switch (currentFile.ImageType) { case ImageType.Background: { encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(currentRoomBlock, bitmapToEncode); } break; case ImageType.ZPlane: { zplaneEncoder.Encode(currentRoomBlock, bitmapToEncode, currentFile.ZPlaneIndex); } break; case ImageType.Object: if (currentRoomBlock.GetOBIMs()[currentFile.ObjectIndex].GetIMxx()[currentFile.ImageIndex].GetSMAP() == null) { bompEncoder.PreferredIndexes = new List <int>(preferredIndexes); bompEncoder.Encode(currentRoomBlock, currentFile.ObjectIndex, currentFile.ImageIndex, bitmapToEncode); } else { encoder.PreferredIndexes = new List <int>(preferredIndexes); encoder.Encode(currentRoomBlock, currentFile.ObjectIndex, currentFile.ImageIndex, bitmapToEncode); } break; case ImageType.ObjectsZPlane: { zplaneEncoder.Encode(currentRoomBlock, currentFile.ObjectIndex, currentFile.ImageIndex, bitmapToEncode, currentFile.ZPlaneIndex); } break; case ImageType.Costume: { Costume costume = diskBlocks[currentFile.RoomIndex].GetCostumes()[currentFile.CostumeIndex]; costumeEncoder.Encode(currentRoomBlock, costume, currentFile.FrameIndex, bitmapToEncode); } break; } } catch (ImageEncodeException ex) { MessageBox.Show(ex.Message, "Error importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } FilesImported.Text = i.ToString(); Progress.Value = i; Application.DoEvents(); } MessageBox.Show("All images imported"); DialogResult = DialogResult.OK; Close(); }