Skip to content

Commit ab1aa5d

Browse files
committed
bad git...
1 parent 4d6eb7f commit ab1aa5d

19 files changed

Lines changed: 1071 additions & 0 deletions

CSJ2K/Util/BitmapImage.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
using System.Drawing;
7+
using System.Drawing.Imaging;
8+
9+
internal class BitmapImage : ImageBase<Image>
10+
{
11+
#region CONSTRUCTORS
12+
13+
internal BitmapImage(int width, int height, byte[] bytes)
14+
: base(width, height, bytes)
15+
{
16+
}
17+
18+
#endregion
19+
20+
#region METHODS
21+
22+
protected override object GetImageObject()
23+
{
24+
var bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
25+
26+
var dstdata = bitmap.LockBits(
27+
new Rectangle(0, 0, Width, Height),
28+
ImageLockMode.ReadWrite,
29+
bitmap.PixelFormat);
30+
31+
var ptr = dstdata.Scan0;
32+
System.Runtime.InteropServices.Marshal.Copy(Bytes, 0, ptr, Bytes.Length);
33+
bitmap.UnlockBits(dstdata);
34+
35+
return bitmap;
36+
}
37+
38+
#endregion
39+
}
40+
}

CSJ2K/Util/BitmapImageCreator.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
using CSJ2K.j2k.image;
7+
8+
public class BitmapImageCreator : IImageCreator
9+
{
10+
#region FIELDS
11+
12+
private static readonly IImageCreator Instance = new BitmapImageCreator();
13+
14+
#endregion
15+
16+
#region PROPERTIES
17+
18+
public bool IsDefault
19+
{
20+
get
21+
{
22+
return false;
23+
}
24+
}
25+
26+
#endregion
27+
28+
#region METHODS
29+
30+
public static void Register()
31+
{
32+
ImageFactory.Register(Instance);
33+
}
34+
35+
public IImage Create(int width, int height, byte[] bytes)
36+
{
37+
return new BitmapImage(width, height, bytes);
38+
}
39+
40+
public BlkImgDataSrc ToPortableImageSource(object imageObject)
41+
{
42+
return BitmapImageSource.Create(imageObject);
43+
}
44+
45+
#endregion
46+
}
47+
}

CSJ2K/Util/BitmapImageSource.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
using System;
7+
using System.Drawing;
8+
using System.Drawing.Imaging;
9+
using System.Linq;
10+
11+
using CSJ2K.j2k.image;
12+
13+
internal class BitmapImageSource : PortableImageSource
14+
{
15+
#region CONSTRUCTORS
16+
17+
private BitmapImageSource(Bitmap bitmap)
18+
: base(
19+
bitmap.Width,
20+
bitmap.Height,
21+
GetNumberOfComponents(bitmap.PixelFormat),
22+
GetRangeBits(bitmap.PixelFormat),
23+
GetSignedArray(bitmap.PixelFormat),
24+
GetComponents(bitmap))
25+
{
26+
}
27+
28+
#endregion
29+
30+
#region METHODS
31+
32+
33+
internal static BlkImgDataSrc Create(object imageObject)
34+
{
35+
var bitmap = imageObject as Bitmap;
36+
return bitmap == null ? null : new BitmapImageSource(bitmap);
37+
}
38+
39+
private static int GetNumberOfComponents(PixelFormat pixelFormat)
40+
{
41+
switch (pixelFormat)
42+
{
43+
case PixelFormat.Format16bppGrayScale:
44+
case PixelFormat.Format1bppIndexed:
45+
case PixelFormat.Format4bppIndexed:
46+
case PixelFormat.Format8bppIndexed:
47+
return 1;
48+
case PixelFormat.Format24bppRgb:
49+
case PixelFormat.Format32bppArgb:
50+
case PixelFormat.Format32bppPArgb:
51+
case PixelFormat.Format32bppRgb:
52+
return 3;
53+
default:
54+
throw new ArgumentOutOfRangeException("pixelFormat");
55+
}
56+
}
57+
58+
private static int GetRangeBits(PixelFormat pixelFormat)
59+
{
60+
switch (pixelFormat)
61+
{
62+
case PixelFormat.Format16bppGrayScale:
63+
return 16;
64+
case PixelFormat.Format1bppIndexed:
65+
return 1;
66+
case PixelFormat.Format4bppIndexed:
67+
return 4;
68+
case PixelFormat.Format8bppIndexed:
69+
case PixelFormat.Format24bppRgb:
70+
case PixelFormat.Format32bppArgb:
71+
case PixelFormat.Format32bppPArgb:
72+
case PixelFormat.Format32bppRgb:
73+
return 8;
74+
default:
75+
throw new ArgumentOutOfRangeException("pixelFormat");
76+
}
77+
}
78+
79+
private static bool[] GetSignedArray(PixelFormat pixelFormat)
80+
{
81+
return Enumerable.Repeat(false, GetNumberOfComponents(pixelFormat)).ToArray();
82+
}
83+
84+
private static int[][] GetComponents(Bitmap bitmap)
85+
{
86+
var w = bitmap.Width;
87+
var h = bitmap.Height;
88+
var nc = GetNumberOfComponents(bitmap.PixelFormat);
89+
90+
var comps = new int[nc][];
91+
for (var c = 0; c < nc; ++c) comps[c] = new int[w * h];
92+
93+
for (int y = 0, xy = 0; y < h; ++y)
94+
{
95+
for (var x = 0; x < w; ++x, ++xy)
96+
{
97+
var color = bitmap.GetPixel(x, y);
98+
for (var c = 0; c < nc; ++c)
99+
{
100+
comps[c][xy] = c == 0 ? color.R : c == 1 ? color.G : color.B;
101+
}
102+
}
103+
}
104+
105+
return comps;
106+
}
107+
108+
#endregion
109+
}
110+
}

CSJ2K/Util/DotnetFileInfo.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
using System;
7+
using System.IO;
8+
9+
internal class DotnetFileInfo : IFileInfo
10+
{
11+
#region FIELDS
12+
13+
private readonly FileInfo _fileInfo;
14+
15+
#endregion
16+
17+
#region CONSTRUCTORS
18+
19+
internal DotnetFileInfo(string fileName)
20+
{
21+
_fileInfo = new FileInfo(fileName);
22+
}
23+
24+
#endregion
25+
26+
#region PROPERTIES
27+
28+
public string Name
29+
{
30+
get
31+
{
32+
return _fileInfo.Name;
33+
}
34+
}
35+
36+
public string FullName
37+
{
38+
get
39+
{
40+
return _fileInfo.FullName;
41+
}
42+
}
43+
44+
public bool Exists
45+
{
46+
get
47+
{
48+
return _fileInfo.Exists;
49+
}
50+
}
51+
52+
#endregion
53+
54+
#region METHODS
55+
56+
public bool Delete()
57+
{
58+
try
59+
{
60+
_fileInfo.Delete();
61+
return true;
62+
}
63+
catch (Exception)
64+
{
65+
return false;
66+
}
67+
}
68+
69+
#endregion
70+
}
71+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
public class DotnetFileInfoCreator : IFileInfoCreator
7+
{
8+
#region FIELDS
9+
10+
private static readonly IFileInfoCreator Instance = new DotnetFileInfoCreator();
11+
12+
#endregion
13+
14+
#region METHODS
15+
16+
public static void Register()
17+
{
18+
FileInfoFactory.Register(Instance);
19+
}
20+
21+
public IFileInfo Create(string fileName)
22+
{
23+
return new DotnetFileInfo(fileName);
24+
}
25+
26+
#endregion
27+
}
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
using System;
7+
using System.IO;
8+
9+
public class DotnetFileStreamCreator : IFileStreamCreator
10+
{
11+
#region FIELDS
12+
13+
private static readonly IFileStreamCreator Instance = new DotnetFileStreamCreator();
14+
15+
#endregion
16+
17+
#region METHODS
18+
19+
public static void Register()
20+
{
21+
FileStreamFactory.Register(Instance);
22+
}
23+
24+
public Stream Create(string path, string mode)
25+
{
26+
if (mode.Equals("rw", StringComparison.OrdinalIgnoreCase)) return new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
27+
if (mode.Equals("r", StringComparison.OrdinalIgnoreCase)) return new FileStream(path, FileMode.Open, FileAccess.Read);
28+
throw new ArgumentException(String.Format("File mode: {0} not supported.", mode), "mode");
29+
}
30+
31+
#endregion
32+
}
33+
}

CSJ2K/Util/DotnetMsgLogger.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2007-2016 CSJ2K contributors.
2+
// Licensed under the BSD 3-Clause License.
3+
4+
namespace CSJ2K.Util
5+
{
6+
using System;
7+
8+
using CSJ2K.j2k.util;
9+
10+
public class DotnetMsgLogger : StreamMsgLogger
11+
{
12+
#region FIELDS
13+
14+
private static readonly IMsgLogger Instance = new DotnetMsgLogger();
15+
16+
#endregion
17+
18+
#region CONSTRUCTORS
19+
20+
public DotnetMsgLogger()
21+
: base(Console.OpenStandardOutput(), Console.OpenStandardError(), 78)
22+
{
23+
}
24+
25+
#endregion
26+
27+
#region METHODS
28+
29+
public static void Register()
30+
{
31+
FacilityManager.DefaultMsgLogger = Instance;
32+
}
33+
34+
#endregion
35+
}
36+
}

0 commit comments

Comments
 (0)