/// <summary>Creates a new Frame with the given <see cref="PixelFormat.Format8bppIndexed"/> image</summary> /// <param name="parent">The <see cref="ActImage"/> the Frame belongs to</param> /// <param name="image">Image to be used for the Frame, must be <see cref="PixelFormat.Format8bppIndexed"/></param> /// <exception cref="FormatException"><i>image</i> is not <see cref="PixelFormat.Format8bppIndexed"/></exception> /// <exception cref="Idmr.Common.BoundaryException"><i>image</i> exceeds maximum allowable dimensions</exception> internal Frame(ActImage parent, Bitmap image) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) throw new FormatException("Image must be 8bppIndexed (256 color)"); _parent = parent; initializeHeader(); Image = image; }
/// <summary>Populates the Frame with information from raw data</summary> /// <param name="parent">The <see cref="ActImage"/> the Frame belongs to</param> /// <param name="raw">Complete raw byte data of a Frame</param> /// <exception cref="ArgumentException">Validation error</exception> internal Frame(ActImage parent, byte[] raw) { ArrayFunctions.TrimArray(raw, 0, _header); if (BitConverter.ToInt32(_header, 4) != _headerLength) throw new ArgumentException(ActImage._validationErrorMessage, "file"); if (BitConverter.ToInt32(_header, 0x24) != _headerReserved) throw new ArgumentException(ActImage._validationErrorMessage, "file"); _parent = parent; _colors = new Color[BitConverter.ToInt32(_header, 0x28)]; System.Diagnostics.Debug.WriteLine("Colors: " + NumberOfColors); for (int c = 0, pos = _headerLength; c < _colors.Length; c++, pos += 4) _colors[c] = Color.FromArgb(raw[pos], raw[pos + 1], raw[pos + 2]); // Red, Green, Blue, Alpha unused int offset = _headerLength + _colors.Length * 4; _location = new Point(BitConverter.ToInt32(raw, offset), BitConverter.ToInt32(raw, offset + 4)); // FrameLeft, FrameTop System.Diagnostics.Debug.WriteLine("Location: " + X + "," + Y + "\r\nSize: " + Width + "," + Height); offset += 0x10; _rows = new byte[raw.Length - offset]; ArrayFunctions.TrimArray(raw, offset, _rows); _image = ActImage.DecodeImage(_rows, Width, Height, _colors, _shift); }
/// <summary>Processes raw data to populate the resource</summary> /// <param name="raw">Raw byte data</param> /// <param name="containsHeader">Whether or not <i>raw</i> contains the resource Header information</param> /// <exception cref="ArgumentException">Header-defined <see cref="Type"/> is not <see cref="ResourceType.Xact"/></exception> public override void DecodeResource(byte[] raw, bool containsHeader) { _decodeResource(raw, containsHeader); if (_type != ResourceType.Xact) throw new ArgumentException("Raw header is not for a Xact resource"); _act = new ActImage(_rawData); }
private void opnAct_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { txtFile.Text = opnAct.FileName; try { _image = new ActImage(txtFile.Text); } catch (Exception x) { _image = null; Text = "X-wing series ACT Editor"; pnlNavigation.Enabled = false; pnlColors.Enabled = false; lblFrame.Text = "Frame 0 of 0"; grpImage.Enabled = false; grpFrame.Enabled = false; pctAct.BackgroundImage = null; cmdExport.Enabled = false; System.Diagnostics.Debug.WriteLine(x.StackTrace); MessageBox.Show(x.Message); return; } LoadFile(); }
private void cmdCopy_Click(object sender, EventArgs e) { if (_image == null) { try { _image = new ActImage((Bitmap)pctImport.BackgroundImage); } catch (Exception x) { _image = null; Text = "X-wing series ACT Editor"; pnlNavigation.Enabled = false; pnlColors.Enabled = false; lblFrame.Text = "Frame 0 of 0"; grpImage.Enabled = false; grpFrame.Enabled = false; pctAct.BackgroundImage = null; cmdExport.Enabled = false; MessageBox.Show(x.Message); return; } LoadFile(); txtFile.Text = _image.FilePath; } else { _image.Frames[_frame].Image = (Bitmap)pctImport.BackgroundImage; lblHeight.Text = _image.Height.ToString(); lblWidth.Text = _image.Width.ToString(); if (chkAutoCenter.Checked) { if (_image.NumberOfFrames == 1) { _loading = true; numCenterX.Maximum = _image.Width - 1; numCenterY.Maximum = _image.Height - 1; numCenterX.Value = _image.Width / 2; numCenterY.Value = _image.Height / 2; _loading = false; ChangeCenter(); } _image.Frames[0].X = -_image.Frames[0].Width / 2; _image.Frames[0].Y = -_image.Frames[0].Height / 2; } UpdateView(); } if (!Text.Contains("*")) Text += "*"; }
/// <summary>Creates an empty Frame</summary> /// <param name="parent">The <see cref="ActImage"/> the Frame belongs to</param> internal Frame(ActImage parent) { _parent = parent; initializeHeader(); }