From 595ccd8865dc2d00d470bc7a36fcb32d02f1397f Mon Sep 17 00:00:00 2001
From: blah38621_cp <36925b492f9af1e8e676baa1ba817f9639f49ec7y44YxFx5>
Date: Fri, 5 Aug 2011 03:17:10 +0000
Subject: [PATCH] Enabled Jpeg support.
---
source2/Users/Orvid/Orvid.Graphics/Image.cs | 28 +++++++++++++++++++
.../ImageFormats/FormatManager.cs | 2 ++
.../{ => Jpeg Support}/LibJpeg.cs | 0
.../ImageFormats/{ => Jpeg Support}/zLib.cs | 0
.../ImageFormats/JpegSupport.cs | 23 +++++++++++++++
.../Orvid.Graphics/Orvid.Graphics.csproj | 3 ++
6 files changed, 56 insertions(+)
rename source2/Users/Orvid/Orvid.Graphics/ImageFormats/{ => Jpeg Support}/LibJpeg.cs (100%)
rename source2/Users/Orvid/Orvid.Graphics/ImageFormats/{ => Jpeg Support}/zLib.cs (100%)
create mode 100644 source2/Users/Orvid/Orvid.Graphics/ImageFormats/JpegSupport.cs
diff --git a/source2/Users/Orvid/Orvid.Graphics/Image.cs b/source2/Users/Orvid/Orvid.Graphics/Image.cs
index d6d2903b4..7920def34 100644
--- a/source2/Users/Orvid/Orvid.Graphics/Image.cs
+++ b/source2/Users/Orvid/Orvid.Graphics/Image.cs
@@ -984,5 +984,33 @@ namespace Orvid.Graphics
{
Parent.DrawImage(new Vec2(base.X, base.Y), this);
}
+
+ #region Operators
+ public static explicit operator System.Drawing.Bitmap(Image i)
+ {
+ System.Drawing.Bitmap b = new System.Drawing.Bitmap(i.Width, i.Height);
+ for (uint x = 0; x < i.Width; x++)
+ {
+ for (uint y = 0; y < i.Height; y++)
+ {
+ b.SetPixel((int)x, (int)y, i.GetPixel(x, y));
+ }
+ }
+ return b;
+ }
+
+ public static explicit operator Image(System.Drawing.Bitmap b)
+ {
+ Image i = new Image(b.Width, b.Height);
+ for (uint x = 0; x < b.Width; x++)
+ {
+ for (uint y = 0; y < b.Height; y++)
+ {
+ i.SetPixel(x, y, b.GetPixel((int)x, (int)y));
+ }
+ }
+ return i;
+ }
+ #endregion
}
}
diff --git a/source2/Users/Orvid/Orvid.Graphics/ImageFormats/FormatManager.cs b/source2/Users/Orvid/Orvid.Graphics/ImageFormats/FormatManager.cs
index 85d7cdd33..756f99ca3 100644
--- a/source2/Users/Orvid/Orvid.Graphics/ImageFormats/FormatManager.cs
+++ b/source2/Users/Orvid/Orvid.Graphics/ImageFormats/FormatManager.cs
@@ -10,7 +10,9 @@ namespace Orvid.Graphics.ImageFormats
public FormatManager()
{
Formats.Add(new OIFImage());
+ //Formats.Add(new PngImage());
Formats.Add(new VbpImage());
+ Formats.Add(new JpgImage());
}
}
diff --git a/source2/Users/Orvid/Orvid.Graphics/ImageFormats/LibJpeg.cs b/source2/Users/Orvid/Orvid.Graphics/ImageFormats/Jpeg Support/LibJpeg.cs
similarity index 100%
rename from source2/Users/Orvid/Orvid.Graphics/ImageFormats/LibJpeg.cs
rename to source2/Users/Orvid/Orvid.Graphics/ImageFormats/Jpeg Support/LibJpeg.cs
diff --git a/source2/Users/Orvid/Orvid.Graphics/ImageFormats/zLib.cs b/source2/Users/Orvid/Orvid.Graphics/ImageFormats/Jpeg Support/zLib.cs
similarity index 100%
rename from source2/Users/Orvid/Orvid.Graphics/ImageFormats/zLib.cs
rename to source2/Users/Orvid/Orvid.Graphics/ImageFormats/Jpeg Support/zLib.cs
diff --git a/source2/Users/Orvid/Orvid.Graphics/ImageFormats/JpegSupport.cs b/source2/Users/Orvid/Orvid.Graphics/ImageFormats/JpegSupport.cs
new file mode 100644
index 000000000..994467d8f
--- /dev/null
+++ b/source2/Users/Orvid/Orvid.Graphics/ImageFormats/JpegSupport.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using BitMiracle.LibJpeg;
+
+namespace Orvid.Graphics.ImageFormats
+{
+ public class JpgImage : ImageFormat
+ {
+ public override void Save(Image i, Stream dest)
+ {
+ JpegImage j = JpegImage.FromBitmap((System.Drawing.Bitmap)i);
+ j.WriteJpeg(dest);
+ }
+
+ public override Image Load(Stream s)
+ {
+ JpegImage j = new JpegImage(s);
+ return (Image)j.ToBitmap();
+ }
+ }
+}
diff --git a/source2/Users/Orvid/Orvid.Graphics/Orvid.Graphics.csproj b/source2/Users/Orvid/Orvid.Graphics/Orvid.Graphics.csproj
index 06f99ebe8..6e37ab3de 100644
--- a/source2/Users/Orvid/Orvid.Graphics/Orvid.Graphics.csproj
+++ b/source2/Users/Orvid/Orvid.Graphics/Orvid.Graphics.csproj
@@ -54,8 +54,11 @@
+
+
+