|
46 | 46 | using ASCOM.Standard.Interfaces; |
47 | 47 | using ASCOM.Alpaca.Responses; |
48 | 48 | using System.Runtime.CompilerServices; |
| 49 | +using SixLabors.ImageSharp; |
| 50 | +using SixLabors.ImageSharp.PixelFormats; |
| 51 | +using SixLabors.ImageSharp.ColorSpaces; |
| 52 | +using SixLabors.ImageSharp.ColorSpaces.Conversion; |
49 | 53 |
|
50 | 54 | [assembly: InternalsVisibleTo("ASCOM.Alpaca.Simulators")] |
51 | 55 | namespace ASCOM.Simulators |
@@ -2875,7 +2879,7 @@ private double DarkData(int x, int y, int p) |
2875 | 2879 | } |
2876 | 2880 |
|
2877 | 2881 | private delegate void GetData(int x, int y); |
2878 | | - private Bitmap bmp; |
| 2882 | + private Image<Rgba32> bmp; |
2879 | 2883 | // Bayer offsets |
2880 | 2884 | private int x0; |
2881 | 2885 | private int x1; |
@@ -2910,7 +2914,7 @@ private void ReadImageFile() |
2910 | 2914 |
|
2911 | 2915 | try |
2912 | 2916 | { |
2913 | | - bmp = (Bitmap)Image.FromFile(imagePath); |
| 2917 | + bmp = Image.Load<Rgba32>(imagePath); |
2914 | 2918 |
|
2915 | 2919 | // x0 = bayerOffsetX; |
2916 | 2920 | // x1 = (bayerOffsetX + 1) & 1; |
@@ -2976,73 +2980,82 @@ private void ReadImageFile() |
2976 | 2980 | } |
2977 | 2981 |
|
2978 | 2982 | } |
2979 | | - catch |
| 2983 | + catch(Exception ex) |
2980 | 2984 | { |
| 2985 | + Log.log.LogError(ex.Message); |
2981 | 2986 | } |
2982 | 2987 | } |
2983 | 2988 |
|
2984 | 2989 | // get data using the sensor types |
2985 | 2990 | private void MonochromeData(int x, int y) |
2986 | 2991 | { |
2987 | | - imageData[x, y, 0] = (bmp.GetPixel(x, y).GetBrightness() * 255); |
| 2992 | + |
| 2993 | + ColorSpaceConverter converter = new ColorSpaceConverter(); |
| 2994 | + |
| 2995 | + |
| 2996 | + imageData[x, y, 0] = (converter.ToHsl(bmp[x, y]).L * 255); |
2988 | 2997 | } |
2989 | 2998 | private void RGGBData(int x, int y) |
2990 | 2999 | { |
2991 | | - Color px = bmp.GetPixel(x / 2, y / 2); |
| 3000 | + var px = bmp[x / 2, y / 2]; |
2992 | 3001 | imageData[x + x0, y + y0, 0] = px.R; // red |
2993 | 3002 | imageData[x + x1, y + y0, 0] = px.G; // green |
2994 | 3003 | imageData[x + x0, y + y1, 0] = px.G; // green |
2995 | 3004 | imageData[x + x1, y + y1, 0] = px.B; // blue |
2996 | 3005 | } |
2997 | 3006 | private void CMYGData(int x, int y) |
2998 | 3007 | { |
2999 | | - Color px = bmp.GetPixel(x / 2, y / 2); |
| 3008 | + var px = bmp[x / 2, y / 2]; |
3000 | 3009 | imageData[x + x0, y + y0, 0] = (px.R + px.G) / 2; // yellow |
3001 | 3010 | imageData[x + x1, y + y0, 0] = (px.G + px.B) / 2; // cyan |
3002 | 3011 | imageData[x + x0, y + y1, 0] = px.G; // green |
3003 | 3012 | imageData[x + x1, y + y1, 0] = (px.R + px.B) / 2; // magenta |
3004 | 3013 | } |
3005 | 3014 | private void CMYG2Data(int x, int y) |
3006 | 3015 | { |
3007 | | - Color px = bmp.GetPixel(x / 2, y / 2); |
| 3016 | + var px = bmp[x / 2, y / 2]; |
3008 | 3017 | imageData[x + x0, y + y0, 0] = (px.G); |
3009 | 3018 | imageData[x + x1, y + y0, 0] = (px.B + px.R) / 2; // magenta |
3010 | 3019 | imageData[x + x0, y + y1, 0] = (px.G + px.B) / 2; // cyan |
3011 | 3020 | imageData[x + x1, y + y1, 0] = (px.R + px.G) / 2; // yellow |
3012 | | - px = bmp.GetPixel(x / 2, (y / 2) + 1); |
| 3021 | + px = bmp[x / 2, (y / 2) + 1]; |
3013 | 3022 | imageData[x + x0, y + y2, 0] = (px.B + px.R) / 2; // magenta |
3014 | 3023 | imageData[x + x1, y + y2, 0] = (px.G); |
3015 | 3024 | imageData[x + x0, y + y3, 0] = (px.G + px.B) / 2; // cyan |
3016 | 3025 | imageData[x + x1, y + y3, 0] = (px.R + px.G) / 2; // yellow |
3017 | 3026 | } |
3018 | 3027 | private void LRGBData(int x, int y) |
3019 | 3028 | { |
3020 | | - Color px = bmp.GetPixel(x / 2, y / 2); |
3021 | | - imageData[x + x0, y + y0, 0] = px.GetBrightness() * 255; |
| 3029 | + ColorSpaceConverter converter = new ColorSpaceConverter(); |
| 3030 | + |
| 3031 | + |
| 3032 | + |
| 3033 | + var px = bmp[x / 2, y / 2]; |
| 3034 | + imageData[x + x0, y + y0, 0] = converter.ToHsl(px).L * 255; |
3022 | 3035 | imageData[x + x1, y + y0, 0] = (px.R); |
3023 | 3036 | imageData[x + x0, y + y1, 0] = (px.R); |
3024 | | - imageData[x + x1, y + y1, 0] = px.GetBrightness() * 255; |
3025 | | - px = bmp.GetPixel((x / 2) + 1, y / 2); |
3026 | | - imageData[x + x2, y + y0, 0] = px.GetBrightness() * 255; |
| 3037 | + imageData[x + x1, y + y1, 0] = converter.ToHsl(px).L * 255; |
| 3038 | + px = bmp[(x / 2) + 1, y / 2]; |
| 3039 | + imageData[x + x2, y + y0, 0] = converter.ToHsl(px).L * 255; |
3027 | 3040 | imageData[x + x3, y + y0, 0] = (px.G); |
3028 | 3041 | imageData[x + x2, y + y1, 0] = (px.G); |
3029 | | - imageData[x + x3, y + y1, 0] = px.GetBrightness() * 255; |
3030 | | - px = bmp.GetPixel(x / 2, (y / 2) + 1); |
3031 | | - imageData[x + x0, y + y2, 0] = px.GetBrightness() * 255; |
| 3042 | + imageData[x + x3, y + y1, 0] = converter.ToHsl(px).L * 255; |
| 3043 | + px = bmp[x / 2, (y / 2) + 1]; |
| 3044 | + imageData[x + x0, y + y2, 0] = converter.ToHsl(px).L * 255; |
3032 | 3045 | imageData[x + x1, y + y2, 0] = (px.G); |
3033 | 3046 | imageData[x + x0, y + y3, 0] = (px.G); |
3034 | | - imageData[x + x1, y + y3, 0] = px.GetBrightness() * 255; |
3035 | | - px = bmp.GetPixel((x / 2) + 1, (y / 2) + 1); |
3036 | | - imageData[x + x2, y + y2, 0] = px.GetBrightness() * 255; |
| 3047 | + imageData[x + x1, y + y3, 0] = converter.ToHsl(px).L * 255; |
| 3048 | + px = bmp[(x / 2) + 1, (y / 2) + 1]; |
| 3049 | + imageData[x + x2, y + y2, 0] = converter.ToHsl(px).L * 255; |
3037 | 3050 | imageData[x + x3, y + y2, 0] = (px.B); |
3038 | 3051 | imageData[x + x2, y + y3, 0] = (px.B); |
3039 | | - imageData[x + x3, y + y3, 0] = px.GetBrightness() * 255; |
| 3052 | + imageData[x + x3, y + y3, 0] = converter.ToHsl(px).L * 255; |
3040 | 3053 | } |
3041 | 3054 | private void ColorData(int x, int y) |
3042 | 3055 | { |
3043 | | - imageData[x, y, 0] = (bmp.GetPixel(x, y).R); |
3044 | | - imageData[x, y, 1] = (bmp.GetPixel(x, y).G); |
3045 | | - imageData[x, y, 2] = (bmp.GetPixel(x, y).B); |
| 3056 | + imageData[x, y, 0] = (bmp[x, y].R); |
| 3057 | + imageData[x, y, 1] = (bmp[x, y].G); |
| 3058 | + imageData[x, y, 2] = (bmp[x, y].B); |
3046 | 3059 | } |
3047 | 3060 |
|
3048 | 3061 | /// <summary> |
|
0 commit comments