initial commit
This commit is contained in:
commit
1b60743303
274 changed files with 25866 additions and 0 deletions
74
SEGATools/Graphics/MRImage.cs
Normal file
74
SEGATools/Graphics/MRImage.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImage
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
public class MRImage
|
||||
{
|
||||
private MRImageHeader header;
|
||||
private Bitmap imageBitmap;
|
||||
|
||||
public Size ImageSize => new Size(this.header.Width, this.header.Height);
|
||||
|
||||
public int UncompressedSize => this.Pixels.Length;
|
||||
|
||||
public int FileSize => this.header.Size;
|
||||
|
||||
public int CompressedSize => this.header.Size - this.header.Offset;
|
||||
|
||||
public float CompressionRatio => (float) this.UncompressedSize / (float) this.CompressedSize;
|
||||
|
||||
public int Offset { get; private set; }
|
||||
|
||||
public byte[] Pixels { get; private set; }
|
||||
|
||||
public Color[] ColorPalette { get; private set; }
|
||||
|
||||
private byte[] RawData { get; set; }
|
||||
|
||||
public System.IO.Stream FileStream => (System.IO.Stream) new MemoryStream(this.RawData, 0, this.RawData.Length, false);
|
||||
|
||||
internal MRImage(
|
||||
MRImageHeader header,
|
||||
Color[] colorPalette,
|
||||
byte[] pixels,
|
||||
int offset,
|
||||
byte[] rawData)
|
||||
{
|
||||
this.header = header;
|
||||
this.ColorPalette = colorPalette;
|
||||
this.Pixels = pixels;
|
||||
this.Offset = offset;
|
||||
this.RawData = rawData;
|
||||
this.ToBitmap();
|
||||
}
|
||||
|
||||
private byte GetPixel(int x, int y) => this.Pixels[y * this.header.Width + x];
|
||||
|
||||
private Color GetColorForPixel(int x, int y) => this.ColorPalette[(int) this.GetPixel(x, y)];
|
||||
|
||||
public Bitmap ToBitmap()
|
||||
{
|
||||
if (this.imageBitmap != null)
|
||||
return this.imageBitmap;
|
||||
Bitmap bitmap = new Bitmap(this.ImageSize.Width, this.ImageSize.Height, PixelFormat.Format24bppRgb);
|
||||
for (int y = 0; y < bitmap.Height; ++y)
|
||||
{
|
||||
for (int x = 0; x < bitmap.Width; ++x)
|
||||
{
|
||||
Color colorForPixel = this.GetColorForPixel(x, y);
|
||||
bitmap.SetPixel(x, y, colorForPixel);
|
||||
}
|
||||
}
|
||||
this.imageBitmap = bitmap;
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
}
|
23
SEGATools/Graphics/MRImageColor.cs
Normal file
23
SEGATools/Graphics/MRImageColor.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageColor
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 4, Pack = 1)]
|
||||
internal struct MRImageColor
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal byte Blue;
|
||||
[FieldOffset(1)]
|
||||
internal byte Green;
|
||||
[FieldOffset(2)]
|
||||
internal byte Red;
|
||||
[FieldOffset(3)]
|
||||
internal byte Alpha;
|
||||
}
|
||||
}
|
117
SEGATools/Graphics/MRImageConverter.cs
Normal file
117
SEGATools/Graphics/MRImageConverter.cs
Normal file
|
@ -0,0 +1,117 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageConverter
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
public class MRImageConverter
|
||||
{
|
||||
private static readonly string MR_ID = "MR";
|
||||
private static readonly int MR_HEADER_OFFSET = 2;
|
||||
private static readonly int MR_COLOR_PALETTE_OFFSET = MRImageConverter.MR_HEADER_OFFSET + 28;
|
||||
private static readonly int MR_HEADER_MINIMUM_SIZE = 30;
|
||||
private static readonly int MR_COLOR_SIZE = 4;
|
||||
|
||||
public static MRImage ToMRImage(byte[] buffer, int startIndex)
|
||||
{
|
||||
if (startIndex < 0 || buffer.Length - startIndex < MRImageConverter.MR_HEADER_MINIMUM_SIZE)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
string str = Encoding.ASCII.GetString(buffer, startIndex, MRImageConverter.MR_ID.Length);
|
||||
if (!MRImageConverter.MR_ID.Equals(str))
|
||||
throw new MRImageIdentifierMissingException("Wrong MR file identifier");
|
||||
MRImageHeader structure1 = (MRImageHeader) Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement((Array) buffer, startIndex + MRImageConverter.MR_HEADER_OFFSET), typeof (MRImageHeader));
|
||||
if (structure1.NumberOfColors <= 0U || (long) (buffer.Length - startIndex - MRImageConverter.MR_COLOR_PALETTE_OFFSET) < (long) structure1.NumberOfColors * (long) MRImageConverter.MR_COLOR_SIZE)
|
||||
throw new MRImageDecompressionException("Color palette too big");
|
||||
Color[] colorArray = new Color[(int) structure1.NumberOfColors];
|
||||
for (int index1 = 0; index1 < colorArray.Length; ++index1)
|
||||
{
|
||||
int index2 = startIndex + MRImageConverter.MR_COLOR_PALETTE_OFFSET + index1 * MRImageConverter.MR_COLOR_SIZE;
|
||||
MRImageColor structure2 = (MRImageColor) Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement((Array) buffer, index2), typeof (MRImageColor));
|
||||
colorArray[index1] = Color.FromArgb((int) structure2.Alpha, (int) structure2.Red, (int) structure2.Green, (int) structure2.Blue);
|
||||
}
|
||||
int length = structure1.Size - structure1.Offset;
|
||||
int startIndex1 = startIndex + structure1.Offset;
|
||||
try
|
||||
{
|
||||
byte[] rawData = new byte[structure1.Size];
|
||||
Buffer.BlockCopy((Array) buffer, startIndex, (Array) rawData, 0, rawData.Length);
|
||||
byte[] pixels = MRImageConverter.DecompressPixelData(structure1, colorArray, buffer, startIndex1, length);
|
||||
return new MRImage(structure1, colorArray, pixels, startIndex, rawData);
|
||||
}
|
||||
catch (MRImageUnknownColorException ex)
|
||||
{
|
||||
throw new MRImageDecompressionException("Unable to decompress the image", (Exception) ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new MRImageDecompressionException("Unable to decompress the image", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] DecompressPixelData(
|
||||
MRImageHeader mrHeader,
|
||||
Color[] palette,
|
||||
byte[] buffer,
|
||||
int startIndex,
|
||||
int length)
|
||||
{
|
||||
int length1 = palette.Length;
|
||||
int index1 = 0;
|
||||
byte[] buffer1 = new byte[mrHeader.Width * mrHeader.Height];
|
||||
for (int index2 = startIndex; index2 < startIndex + length; ++index2)
|
||||
{
|
||||
if (buffer[index2] < (byte) 128)
|
||||
{
|
||||
byte colorNumber = buffer[index2];
|
||||
index1 = MRImageConverter.decodePixels(buffer1, index1, colorNumber, length1, 1);
|
||||
}
|
||||
else if (buffer[index2] == (byte) 129)
|
||||
{
|
||||
int numberOfPixels = (int) buffer[index2 + 1];
|
||||
byte colorNumber = buffer[index2 + 2];
|
||||
index1 = MRImageConverter.decodePixels(buffer1, index1, colorNumber, length1, numberOfPixels);
|
||||
index2 += 2;
|
||||
}
|
||||
else if (buffer[index2] == (byte) 130 && buffer[index2 + 1] >= (byte) 128)
|
||||
{
|
||||
int numberOfPixels = (int) buffer[index2 + 1] - 128 + 256;
|
||||
byte colorNumber = buffer[index2 + 2];
|
||||
index1 = MRImageConverter.decodePixels(buffer1, index1, colorNumber, length1, numberOfPixels);
|
||||
index2 += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
int numberOfPixels = (int) buffer[index2] - 128;
|
||||
byte colorNumber = buffer[index2 + 1];
|
||||
index1 = MRImageConverter.decodePixels(buffer1, index1, colorNumber, length1, numberOfPixels);
|
||||
++index2;
|
||||
}
|
||||
}
|
||||
return buffer1;
|
||||
}
|
||||
|
||||
private static int decodePixels(
|
||||
byte[] buffer,
|
||||
int index,
|
||||
byte colorNumber,
|
||||
int numberOfColors,
|
||||
int numberOfPixels)
|
||||
{
|
||||
for (int index1 = 0; index1 < numberOfPixels && index < buffer.Length; ++index1)
|
||||
{
|
||||
if ((int) colorNumber >= numberOfColors)
|
||||
colorNumber = colorNumber == (byte) 154 ? (byte) 0 : throw MRImageUnknownColorException.anUnknownColor(colorNumber);
|
||||
buffer[index] = colorNumber;
|
||||
++index;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
23
SEGATools/Graphics/MRImageDecompressionException.cs
Normal file
23
SEGATools/Graphics/MRImageDecompressionException.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageDecompressionException
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
internal class MRImageDecompressionException : MRImageReadingException
|
||||
{
|
||||
public MRImageDecompressionException(string message)
|
||||
: base(string.Format("MR Image Decompression Error: {0}", (object) message))
|
||||
{
|
||||
}
|
||||
|
||||
public MRImageDecompressionException(string message, Exception innerException)
|
||||
: base(string.Format("MR Image Decompression Error: {0}", (object) message), innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
99
SEGATools/Graphics/MRImageExporter.cs
Normal file
99
SEGATools/Graphics/MRImageExporter.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageExporter
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
public class MRImageExporter
|
||||
{
|
||||
private static List<MRImageExporter.MRImageFormat> supportedMRImageFormats;
|
||||
|
||||
public MRImageExporter()
|
||||
{
|
||||
if (MRImageExporter.supportedMRImageFormats != null)
|
||||
return;
|
||||
MRImageExporter.supportedMRImageFormats = new List<MRImageExporter.MRImageFormat>();
|
||||
MRImageExporter.supportedMRImageFormats.Add(new MRImageExporter.MRImageFormat(".mr", "MR image"));
|
||||
MRImageExporter.supportedMRImageFormats.Add(new MRImageExporter.MRImageFormat(".bmp", "Bitmap image", ImageFormat.Bmp));
|
||||
MRImageExporter.supportedMRImageFormats.Add(new MRImageExporter.MRImageFormat(".png", "PNG image", ImageFormat.Png));
|
||||
MRImageExporter.supportedMRImageFormats.Add(new MRImageExporter.MRImageFormat(".jpeg", "JPEG image", ImageFormat.Jpeg));
|
||||
MRImageExporter.supportedMRImageFormats.Add(new MRImageExporter.MRImageFormat(".gif", "GIF image", ImageFormat.Gif));
|
||||
}
|
||||
|
||||
public string CreateSaveFileDialogFilter()
|
||||
{
|
||||
string str = string.Empty;
|
||||
foreach (MRImageExporter.MRImageFormat supportedMrImageFormat in MRImageExporter.supportedMRImageFormats)
|
||||
str = str + "|" + supportedMrImageFormat.Description + "|*" + supportedMrImageFormat.Extension;
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
str = str.Substring(1);
|
||||
return str;
|
||||
}
|
||||
|
||||
public MRImageExporter.MRImageFormat GetMRImageFormatFromFilterIndex(int index) => index < 1 || index > MRImageExporter.supportedMRImageFormats.Count ? (MRImageExporter.MRImageFormat) null : MRImageExporter.supportedMRImageFormats[index - 1];
|
||||
|
||||
public MRImageExporter.MRImageFormat FindMRImageFileFormatForFileExtension(
|
||||
string fileExtension)
|
||||
{
|
||||
return string.IsNullOrEmpty(fileExtension) ? (MRImageExporter.MRImageFormat) null : MRImageExporter.supportedMRImageFormats.Find((Predicate<MRImageExporter.MRImageFormat>) (mrImageFileFormat => mrImageFileFormat.Extension.Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase)));
|
||||
}
|
||||
|
||||
public bool IsImageExtensionSupported(string fileExtension) => this.FindMRImageFileFormatForFileExtension(fileExtension) != null;
|
||||
|
||||
public void Save(
|
||||
MRImage mrImage,
|
||||
string outputFileName,
|
||||
MRImageExporter.MRImageFormat imageFormat)
|
||||
{
|
||||
if (imageFormat == null)
|
||||
throw new ArgumentException(nameof (imageFormat));
|
||||
if (imageFormat.IsRawMR)
|
||||
{
|
||||
using (System.IO.Stream fileStream1 = mrImage.FileStream)
|
||||
{
|
||||
byte[] buffer = new byte[fileStream1.Length];
|
||||
using (FileStream fileStream2 = new FileStream(outputFileName, FileMode.OpenOrCreate))
|
||||
{
|
||||
fileStream1.Read(buffer, 0, buffer.Length);
|
||||
fileStream2.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
mrImage.ToBitmap().Save(outputFileName, imageFormat.Format);
|
||||
}
|
||||
|
||||
public class MRImageFormat
|
||||
{
|
||||
public bool IsRawMR { get; set; }
|
||||
|
||||
public string Extension { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public ImageFormat Format { get; set; }
|
||||
|
||||
public MRImageFormat(string extension, string description, ImageFormat imageFormat)
|
||||
{
|
||||
this.Extension = extension;
|
||||
this.Description = description;
|
||||
this.Format = imageFormat;
|
||||
this.IsRawMR = false;
|
||||
}
|
||||
|
||||
public MRImageFormat(string extension, string description)
|
||||
{
|
||||
this.Extension = extension;
|
||||
this.Description = description;
|
||||
this.IsRawMR = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
SEGATools/Graphics/MRImageHeader.cs
Normal file
25
SEGATools/Graphics/MRImageHeader.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageHeader
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 28, Pack = 1)]
|
||||
internal struct MRImageHeader
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal int Size;
|
||||
[FieldOffset(8)]
|
||||
internal int Offset;
|
||||
[FieldOffset(12)]
|
||||
internal int Width;
|
||||
[FieldOffset(16)]
|
||||
internal int Height;
|
||||
[FieldOffset(24)]
|
||||
internal uint NumberOfColors;
|
||||
}
|
||||
}
|
23
SEGATools/Graphics/MRImageIdentifierMissingException.cs
Normal file
23
SEGATools/Graphics/MRImageIdentifierMissingException.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageIdentifierMissingException
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
internal class MRImageIdentifierMissingException : MRImageReadingException
|
||||
{
|
||||
public MRImageIdentifierMissingException(string message)
|
||||
: base(string.Format("MR Image Identifier Missing Error: {0}", (object) message))
|
||||
{
|
||||
}
|
||||
|
||||
public MRImageIdentifierMissingException(string message, Exception innerException)
|
||||
: base(string.Format("MR Image Identifier Missing Error: {0}", (object) message), innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
23
SEGATools/Graphics/MRImageReadingException.cs
Normal file
23
SEGATools/Graphics/MRImageReadingException.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageReadingException
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
internal class MRImageReadingException : Exception
|
||||
{
|
||||
public MRImageReadingException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public MRImageReadingException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
22
SEGATools/Graphics/MRImageUnknownColorException.cs
Normal file
22
SEGATools/Graphics/MRImageUnknownColorException.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageUnknownColorException
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
internal class MRImageUnknownColorException : MRImageReadingException
|
||||
{
|
||||
public MRImageUnknownColorException(string message)
|
||||
: base(string.Format("MR Image Unknown Color Error: {0}", (object) message))
|
||||
{
|
||||
}
|
||||
|
||||
public static MRImageUnknownColorException anUnknownColor(
|
||||
byte colorNumber)
|
||||
{
|
||||
return new MRImageUnknownColorException(string.Format("color number {0} does not exist", (object) colorNumber));
|
||||
}
|
||||
}
|
||||
}
|
284
SEGATools/Graphics/MRImageViewer.cs
Normal file
284
SEGATools/Graphics/MRImageViewer.cs
Normal file
|
@ -0,0 +1,284 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Graphics.MRImageViewer
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using SEGATools.Formater;
|
||||
using SEGATools.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SEGATools.Graphics
|
||||
{
|
||||
public class MRImageViewer : UserControl
|
||||
{
|
||||
private MRImageExporter mrImageExporter;
|
||||
private string basePath;
|
||||
private IContainer components;
|
||||
private PictureBox pictureBox;
|
||||
private GroupBox gbMRImageInfo;
|
||||
private Label lbColors;
|
||||
private Label lbImageSize;
|
||||
private Label lbNumberOfColorsValue;
|
||||
private Label lbImageSizeValue;
|
||||
private Label lbFileSizeValue;
|
||||
private Label lbFileSize;
|
||||
private Label lbCompressedSizeValue;
|
||||
private Label lbSize;
|
||||
private Label lbUncompressedSizeValue;
|
||||
private Label lbUncompressedSize;
|
||||
private Label lbCompressionRatioValue;
|
||||
private Label lbCompressionRatio;
|
||||
private Button btExportMRImage;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Label lbNoMrImage;
|
||||
|
||||
public MRImage MRImage { get; private set; }
|
||||
|
||||
public string BasePath
|
||||
{
|
||||
get => this.basePath;
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return;
|
||||
this.basePath = value;
|
||||
this.saveFileDialog.InitialDirectory = this.basePath;
|
||||
}
|
||||
}
|
||||
|
||||
private bool DisplayNoImageMessage => true;
|
||||
|
||||
public MRImageViewer()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.pictureBox.Resize += new EventHandler(this.pictureBox_Resize);
|
||||
this.mrImageExporter = new MRImageExporter();
|
||||
this.saveFileDialog.Title = Resources.SfdMRImageTitle;
|
||||
this.saveFileDialog.Filter = this.mrImageExporter.CreateSaveFileDialogFilter();
|
||||
this.lbNoMrImage.Text = Resources.MRImageNoImageMessage;
|
||||
this.CenterImageInDisplayArea((Control) this.lbNoMrImage);
|
||||
this.UpdateViewAndDisplayNoImage();
|
||||
}
|
||||
|
||||
public void LoadMRImage(MRImage mrImage, string imageName)
|
||||
{
|
||||
this.MRImage = mrImage;
|
||||
this.saveFileDialog.FileName = imageName;
|
||||
this.SetImageProperties(this.MRImage);
|
||||
this.UpdateViewAndDisplayImages();
|
||||
}
|
||||
|
||||
private void SetImageProperties(MRImage mrImage)
|
||||
{
|
||||
this.lbImageSizeValue.Text = string.Format("{0}x{1}", (object) mrImage.ImageSize.Width, (object) mrImage.ImageSize.Height);
|
||||
this.lbNumberOfColorsValue.Text = string.Format("{0}", (object) mrImage.ColorPalette.Length);
|
||||
this.lbFileSizeValue.Text = string.Format("{0} ({1} bytes)", (object) SizeFormater.ToHumanReadableSize((long) mrImage.FileSize), (object) mrImage.FileSize);
|
||||
this.lbCompressedSizeValue.Text = string.Format("{0} bytes", (object) mrImage.CompressedSize);
|
||||
this.lbUncompressedSizeValue.Text = string.Format("{0} bytes", (object) mrImage.UncompressedSize);
|
||||
this.lbCompressionRatioValue.Text = string.Format("{0:0.0}:1", (object) mrImage.CompressionRatio);
|
||||
this.pictureBox.Image = (Image) mrImage.ToBitmap();
|
||||
}
|
||||
|
||||
private void CenterImageInDisplayArea(Control control)
|
||||
{
|
||||
int x = (this.Width - control.Size.Width) / 2;
|
||||
int y = (this.gbMRImageInfo.Location.Y - control.Size.Height) / 2;
|
||||
control.Location = new Point(x, y);
|
||||
}
|
||||
|
||||
private void OpenFileDialogAndExportImage(Image image)
|
||||
{
|
||||
if (this.saveFileDialog.ShowDialog((IWin32Window) this) != DialogResult.OK)
|
||||
return;
|
||||
this.mrImageExporter.Save(this.MRImage, this.saveFileDialog.FileName, this.mrImageExporter.GetMRImageFormatFromFilterIndex(this.saveFileDialog.FilterIndex));
|
||||
this.saveFileDialog.InitialDirectory = Path.GetDirectoryName(this.saveFileDialog.FileName);
|
||||
this.saveFileDialog.FileName = Path.GetFileName(this.saveFileDialog.FileName);
|
||||
}
|
||||
|
||||
private void UpdateViewAndDisplayNoImage()
|
||||
{
|
||||
this.lbNoMrImage.Visible = this.DisplayNoImageMessage;
|
||||
this.gbMRImageInfo.Visible = false;
|
||||
this.btExportMRImage.Visible = false;
|
||||
this.pictureBox.Visible = false;
|
||||
}
|
||||
|
||||
private void UpdateViewAndDisplayImages()
|
||||
{
|
||||
this.lbNoMrImage.Visible = false;
|
||||
this.gbMRImageInfo.Visible = true;
|
||||
this.btExportMRImage.Visible = true;
|
||||
this.pictureBox.Visible = true;
|
||||
}
|
||||
|
||||
private void pictureBox_Resize(object sender, EventArgs e) => this.CenterImageInDisplayArea((Control) this.pictureBox);
|
||||
|
||||
private void btExportMRImage_Click(object sender, EventArgs e) => this.OpenFileDialogAndExportImage(this.pictureBox.Image);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && this.components != null)
|
||||
this.components.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBox = new PictureBox();
|
||||
this.gbMRImageInfo = new GroupBox();
|
||||
this.lbCompressionRatioValue = new Label();
|
||||
this.lbCompressionRatio = new Label();
|
||||
this.lbUncompressedSizeValue = new Label();
|
||||
this.lbUncompressedSize = new Label();
|
||||
this.lbCompressedSizeValue = new Label();
|
||||
this.lbSize = new Label();
|
||||
this.lbFileSizeValue = new Label();
|
||||
this.lbFileSize = new Label();
|
||||
this.lbNumberOfColorsValue = new Label();
|
||||
this.lbImageSizeValue = new Label();
|
||||
this.lbColors = new Label();
|
||||
this.lbImageSize = new Label();
|
||||
this.btExportMRImage = new Button();
|
||||
this.saveFileDialog = new SaveFileDialog();
|
||||
this.lbNoMrImage = new Label();
|
||||
((ISupportInitialize) this.pictureBox).BeginInit();
|
||||
this.gbMRImageInfo.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
this.pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
|
||||
this.pictureBox.BorderStyle = BorderStyle.FixedSingle;
|
||||
this.pictureBox.Location = new Point(6, 3);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new Size(448, 90);
|
||||
this.pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox.TabIndex = 0;
|
||||
this.pictureBox.TabStop = false;
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbCompressionRatioValue);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbCompressionRatio);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbUncompressedSizeValue);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbUncompressedSize);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbCompressedSizeValue);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbSize);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbFileSizeValue);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbFileSize);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbNumberOfColorsValue);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbImageSizeValue);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbColors);
|
||||
this.gbMRImageInfo.Controls.Add((Control) this.lbImageSize);
|
||||
this.gbMRImageInfo.Location = new Point(6, 99);
|
||||
this.gbMRImageInfo.Name = "gbMRImageInfo";
|
||||
this.gbMRImageInfo.Size = new Size(448, 75);
|
||||
this.gbMRImageInfo.TabIndex = 0;
|
||||
this.gbMRImageInfo.TabStop = false;
|
||||
this.gbMRImageInfo.Text = "Properties:";
|
||||
this.lbCompressionRatioValue.AutoSize = true;
|
||||
this.lbCompressionRatioValue.Location = new Point(345, 54);
|
||||
this.lbCompressionRatioValue.Name = "lbCompressionRatioValue";
|
||||
this.lbCompressionRatioValue.Size = new Size(89, 13);
|
||||
this.lbCompressionRatioValue.TabIndex = 0;
|
||||
this.lbCompressionRatioValue.Text = "compression ratio";
|
||||
this.lbCompressionRatio.AutoSize = true;
|
||||
this.lbCompressionRatio.Location = new Point(235, 54);
|
||||
this.lbCompressionRatio.Name = "lbCompressionRatio";
|
||||
this.lbCompressionRatio.Size = new Size(98, 13);
|
||||
this.lbCompressionRatio.TabIndex = 0;
|
||||
this.lbCompressionRatio.Text = "Compression Ratio:";
|
||||
this.lbUncompressedSizeValue.AutoSize = true;
|
||||
this.lbUncompressedSizeValue.Location = new Point(345, 37);
|
||||
this.lbUncompressedSizeValue.Name = "lbUncompressedSizeValue";
|
||||
this.lbUncompressedSizeValue.Size = new Size(97, 13);
|
||||
this.lbUncompressedSizeValue.TabIndex = 0;
|
||||
this.lbUncompressedSizeValue.Text = "uncompressed size";
|
||||
this.lbUncompressedSize.AutoSize = true;
|
||||
this.lbUncompressedSize.Location = new Point(234, 37);
|
||||
this.lbUncompressedSize.Name = "lbUncompressedSize";
|
||||
this.lbUncompressedSize.Size = new Size(104, 13);
|
||||
this.lbUncompressedSize.TabIndex = 0;
|
||||
this.lbUncompressedSize.Text = "Uncompressed Size:";
|
||||
this.lbCompressedSizeValue.AutoSize = true;
|
||||
this.lbCompressedSizeValue.Location = new Point(345, 20);
|
||||
this.lbCompressedSizeValue.Name = "lbCompressedSizeValue";
|
||||
this.lbCompressedSizeValue.Size = new Size(85, 13);
|
||||
this.lbCompressedSizeValue.TabIndex = 0;
|
||||
this.lbCompressedSizeValue.Text = "compressed size";
|
||||
this.lbSize.AutoSize = true;
|
||||
this.lbSize.Location = new Point(235, 20);
|
||||
this.lbSize.Name = "lbSize";
|
||||
this.lbSize.Size = new Size(91, 13);
|
||||
this.lbSize.TabIndex = 0;
|
||||
this.lbSize.Text = "Compressed Size:";
|
||||
this.lbFileSizeValue.AutoSize = true;
|
||||
this.lbFileSizeValue.Location = new Point(106, 54);
|
||||
this.lbFileSizeValue.Name = "lbFileSizeValue";
|
||||
this.lbFileSizeValue.Size = new Size(64, 13);
|
||||
this.lbFileSizeValue.TabIndex = 0;
|
||||
this.lbFileSizeValue.Text = "size in bytes";
|
||||
this.lbFileSize.AutoSize = true;
|
||||
this.lbFileSize.Location = new Point(7, 54);
|
||||
this.lbFileSize.Name = "lbFileSize";
|
||||
this.lbFileSize.Size = new Size(49, 13);
|
||||
this.lbFileSize.TabIndex = 0;
|
||||
this.lbFileSize.Text = "File Size:";
|
||||
this.lbNumberOfColorsValue.AutoSize = true;
|
||||
this.lbNumberOfColorsValue.Location = new Point(103, 37);
|
||||
this.lbNumberOfColorsValue.Name = "lbNumberOfColorsValue";
|
||||
this.lbNumberOfColorsValue.Size = new Size(13, 13);
|
||||
this.lbNumberOfColorsValue.TabIndex = 0;
|
||||
this.lbNumberOfColorsValue.Text = "0";
|
||||
this.lbImageSizeValue.AutoSize = true;
|
||||
this.lbImageSizeValue.Location = new Point(103, 20);
|
||||
this.lbImageSizeValue.Name = "lbImageSizeValue";
|
||||
this.lbImageSizeValue.Size = new Size(54, 13);
|
||||
this.lbImageSizeValue.TabIndex = 0;
|
||||
this.lbImageSizeValue.Text = "XXXxYYY";
|
||||
this.lbColors.AutoSize = true;
|
||||
this.lbColors.Location = new Point(7, 37);
|
||||
this.lbColors.Name = "lbColors";
|
||||
this.lbColors.Size = new Size(90, 13);
|
||||
this.lbColors.TabIndex = 0;
|
||||
this.lbColors.Text = "Number of colors:";
|
||||
this.lbImageSize.AutoSize = true;
|
||||
this.lbImageSize.Location = new Point(7, 20);
|
||||
this.lbImageSize.Name = "lbImageSize";
|
||||
this.lbImageSize.Size = new Size(62, 13);
|
||||
this.lbImageSize.TabIndex = 0;
|
||||
this.lbImageSize.Text = "Image Size:";
|
||||
this.btExportMRImage.CausesValidation = false;
|
||||
this.btExportMRImage.FlatStyle = FlatStyle.Popup;
|
||||
this.btExportMRImage.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
|
||||
this.btExportMRImage.ForeColor = Color.FromArgb(248, 48, 0);
|
||||
this.btExportMRImage.Location = new Point(6, 180);
|
||||
this.btExportMRImage.Name = "btExportMRImage";
|
||||
this.btExportMRImage.Size = new Size(108, 22);
|
||||
this.btExportMRImage.TabIndex = 1;
|
||||
this.btExportMRImage.Text = "Export Image...";
|
||||
this.btExportMRImage.UseVisualStyleBackColor = false;
|
||||
this.btExportMRImage.Click += new EventHandler(this.btExportMRImage_Click);
|
||||
this.lbNoMrImage.AutoSize = true;
|
||||
this.lbNoMrImage.Font = new Font("Microsoft Sans Serif", 15.75f, FontStyle.Bold, GraphicsUnit.Point, (byte) 0);
|
||||
this.lbNoMrImage.Location = new Point(117, 35);
|
||||
this.lbNoMrImage.Name = "lbNoMrImage";
|
||||
this.lbNoMrImage.Size = new Size(226, 25);
|
||||
this.lbNoMrImage.TabIndex = 2;
|
||||
this.lbNoMrImage.Text = "No MR Image found!";
|
||||
this.lbNoMrImage.TextAlign = ContentAlignment.MiddleCenter;
|
||||
this.AutoScaleDimensions = new SizeF(6f, 13f);
|
||||
this.AutoScaleMode = AutoScaleMode.Font;
|
||||
this.Controls.Add((Control) this.lbNoMrImage);
|
||||
this.Controls.Add((Control) this.btExportMRImage);
|
||||
this.Controls.Add((Control) this.gbMRImageInfo);
|
||||
this.Controls.Add((Control) this.pictureBox);
|
||||
this.Name = nameof (MRImageViewer);
|
||||
this.Size = new Size(460, 209);
|
||||
((ISupportInitialize) this.pictureBox).EndInit();
|
||||
this.gbMRImageInfo.ResumeLayout(false);
|
||||
this.gbMRImageInfo.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
}
|
||||
}
|
||||
}
|
120
SEGATools/Graphics/MRImageViewer.resx
Normal file
120
SEGATools/Graphics/MRImageViewer.resx
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Add table
Add a link
Reference in a new issue