More Line ending crap. Forgetting to add a .gitattributes is a nightmare

This commit is contained in:
Paul Betts 2013-06-30 16:56:51 -07:00
Родитель c6e08b497d
Коммит 083265ca14
2 изменённых файлов: 189 добавлений и 189 удалений

Просмотреть файл

@ -1,89 +1,89 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Splat
{
public enum CompressedBitmapFormat
{
Png, Jpeg,
}
/// <summary>
/// Represents the platform-specific image loader class. Unless you are
/// testing image loading, you don't usually need to implement this.
/// </summary>
public interface IBitmapLoader
{
/// <summary>
/// Loads a bitmap from a byte stream
/// </summary>
/// <param name="sourceStream">The stream to load the image from.</param>
/// <param name="desiredWidth">The desired width of the image.</param>
/// <param name="desiredHeight">The desired height of the image.</param>
/// <returns>A future result representing the loaded image</returns>
Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight);
/// <summary>
/// Creates an empty bitmap of the specified dimensions
/// </summary>
/// <param name="width">The width of the canvas</param>
/// <param name="height">The height of the canvas</param>
/// <returns>A new image. Use ToNative() to convert this to a native bitmap</returns>
IBitmap Create(float width, float height);
}
/// <summary>
/// Represents a bitmap image that was loaded via a ViewModel. Every platform
/// provides FromNative and ToNative methods to convert this object to the
/// platform-specific versions.
/// </summary>
public interface IBitmap : IDisposable
{
/// <summary>
/// Width in pixel units (depending on platform)
/// </summary>
float Width { get; }
/// <summary>
/// Height in pixel units (depending on platform)
/// </summary>
float Height { get; }
/// <summary>
/// Saves an image to a target stream
/// </summary>
/// <param name="format">The format to save the image in.</param>
/// <param name="quality">If JPEG is specified, this is a quality
/// factor between 0.0 and 1.0f where 1.0f is the best quality.</param>
/// <param name="target">The target stream to save to.</param>
/// <returns>A signal indicating the Save has completed.</returns>
Task Save(CompressedBitmapFormat format, float quality, Stream target);
}
/// <summary>
/// This class loads and creates bitmap resources in a platform-independent
/// way.
/// </summary>
public static class BitmapLoader
{
// TODO: This needs to be improved once we move the "Detect in Unit Test
// Runner" code into Splat
static IBitmapLoader _Current;
public static IBitmapLoader Current {
get {
var ret = _Current;
if (ret == null) {
throw new Exception("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken");
}
return ret;
}
set { _Current = value; }
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Splat
{
public enum CompressedBitmapFormat
{
Png, Jpeg,
}
/// <summary>
/// Represents the platform-specific image loader class. Unless you are
/// testing image loading, you don't usually need to implement this.
/// </summary>
public interface IBitmapLoader
{
/// <summary>
/// Loads a bitmap from a byte stream
/// </summary>
/// <param name="sourceStream">The stream to load the image from.</param>
/// <param name="desiredWidth">The desired width of the image.</param>
/// <param name="desiredHeight">The desired height of the image.</param>
/// <returns>A future result representing the loaded image</returns>
Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight);
/// <summary>
/// Creates an empty bitmap of the specified dimensions
/// </summary>
/// <param name="width">The width of the canvas</param>
/// <param name="height">The height of the canvas</param>
/// <returns>A new image. Use ToNative() to convert this to a native bitmap</returns>
IBitmap Create(float width, float height);
}
/// <summary>
/// Represents a bitmap image that was loaded via a ViewModel. Every platform
/// provides FromNative and ToNative methods to convert this object to the
/// platform-specific versions.
/// </summary>
public interface IBitmap : IDisposable
{
/// <summary>
/// Width in pixel units (depending on platform)
/// </summary>
float Width { get; }
/// <summary>
/// Height in pixel units (depending on platform)
/// </summary>
float Height { get; }
/// <summary>
/// Saves an image to a target stream
/// </summary>
/// <param name="format">The format to save the image in.</param>
/// <param name="quality">If JPEG is specified, this is a quality
/// factor between 0.0 and 1.0f where 1.0f is the best quality.</param>
/// <param name="target">The target stream to save to.</param>
/// <returns>A signal indicating the Save has completed.</returns>
Task Save(CompressedBitmapFormat format, float quality, Stream target);
}
/// <summary>
/// This class loads and creates bitmap resources in a platform-independent
/// way.
/// </summary>
public static class BitmapLoader
{
// TODO: This needs to be improved once we move the "Detect in Unit Test
// Runner" code into Splat
static IBitmapLoader _Current;
public static IBitmapLoader Current {
get {
var ret = _Current;
if (ret == null) {
throw new Exception("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken");
}
return ret;
}
set { _Current = value; }
}
}
}

Просмотреть файл

@ -1,102 +1,102 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Splat
{
class BitmapLoader : IBitmapLoader
{
public Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight)
{
return Task.Run(() => {
var ret = new BitmapImage();
withInit(ret, source => {
if (desiredWidth != null) {
source.DecodePixelWidth = (int)desiredWidth;
source.DecodePixelHeight = (int)desiredHeight;
}
#if SILVERLIGHT
source.SetSource(sourceStream);
#else
source.StreamSource = sourceStream;
#endif
});
return (IBitmap) new BitmapSourceBitmap(ret);
});
}
public IBitmap Create(float width, float height)
{
#if SILVERLIGHT
return (IBitmap)new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height));
#else
return (IBitmap) new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Default, null));
#endif
}
void withInit(BitmapImage source, Action<BitmapImage> block)
{
#if SILVERLIGHT
block(source);
#else
source.BeginInit();
block(source);
source.EndInit();
source.Freeze();
#endif
}
}
class BitmapSourceBitmap : IBitmap
{
BitmapSource inner;
public float Width { get; protected set; }
public float Height { get; protected set; }
public BitmapSourceBitmap(BitmapSource bitmap)
{
inner = bitmap;
#if SILVERLIGHT
Width = (float)inner.PixelWidth;
Height = (float)inner.PixelHeight;
#else
Width = (float)inner.Width;
Height = (float)inner.Height;
#endif
}
public Task Save(CompressedBitmapFormat format, float quality, Stream target)
{
return Task.Run(() => {
#if SILVERLIGHT
if (format == CompressedBitmapFormat.Png) {
throw new PlatformNotSupportedException("WP8 can't save PNGs.");
}
var wb = new WriteableBitmap(inner);
wb.SaveJpeg(target, wb.PixelWidth, wb.PixelHeight, 0, (int)(quality * 100.0f));
#else
var encoder = format == CompressedBitmapFormat.Jpeg ?
(BitmapEncoder)new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } :
(BitmapEncoder)new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(inner));
encoder.Save(target);
#endif
});
}
public void Dispose()
{
inner = null;
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Splat
{
class BitmapLoader : IBitmapLoader
{
public Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight)
{
return Task.Run(() => {
var ret = new BitmapImage();
withInit(ret, source => {
if (desiredWidth != null) {
source.DecodePixelWidth = (int)desiredWidth;
source.DecodePixelHeight = (int)desiredHeight;
}
#if SILVERLIGHT
source.SetSource(sourceStream);
#else
source.StreamSource = sourceStream;
#endif
});
return (IBitmap) new BitmapSourceBitmap(ret);
});
}
public IBitmap Create(float width, float height)
{
#if SILVERLIGHT
return (IBitmap)new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height));
#else
return (IBitmap) new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Default, null));
#endif
}
void withInit(BitmapImage source, Action<BitmapImage> block)
{
#if SILVERLIGHT
block(source);
#else
source.BeginInit();
block(source);
source.EndInit();
source.Freeze();
#endif
}
}
class BitmapSourceBitmap : IBitmap
{
BitmapSource inner;
public float Width { get; protected set; }
public float Height { get; protected set; }
public BitmapSourceBitmap(BitmapSource bitmap)
{
inner = bitmap;
#if SILVERLIGHT
Width = (float)inner.PixelWidth;
Height = (float)inner.PixelHeight;
#else
Width = (float)inner.Width;
Height = (float)inner.Height;
#endif
}
public Task Save(CompressedBitmapFormat format, float quality, Stream target)
{
return Task.Run(() => {
#if SILVERLIGHT
if (format == CompressedBitmapFormat.Png) {
throw new PlatformNotSupportedException("WP8 can't save PNGs.");
}
var wb = new WriteableBitmap(inner);
wb.SaveJpeg(target, wb.PixelWidth, wb.PixelHeight, 0, (int)(quality * 100.0f));
#else
var encoder = format == CompressedBitmapFormat.Jpeg ?
(BitmapEncoder)new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } :
(BitmapEncoder)new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(inner));
encoder.Save(target);
#endif
});
}
public void Dispose()
{
inner = null;
}
}
}