프로젝트

일반

사용자정보

개정판 566f0526

ID566f052670e186a3d794e2c1d1ff66350ff9fd17
상위 eb9a8cb6
하위 484bd949, 81173d69

김태성이(가) 5년 이상 전에 추가함

Image 밝기 & 색 농도 조절

Change-Id: I80feb7c7a64fbaf8d1d85a32bdf8baa813be2d4c

차이점 보기:

CommonLib/DNSHelper.cs
34 34
        {
35 35
            IPHostEntry result = null;
36 36

  
37
            try
37
            await Task.Factory.StartNew(() =>
38 38
            {
39
                var ipaddress = CommonLib.DNSHelper.GetDnsAdress();
40

  
41
                await Task.Factory.StartNew(() =>
39
                try
42 40
                {
41
                    var ipaddress = CommonLib.DNSHelper.GetDnsAdress();
42

  
43 43
                    result = Dns.GetHostEntry(ipaddress);
44
                });
45
            }
46
            catch (System.Net.Sockets.SocketException ex)
47
            {
48
                if (ex.SocketErrorCode == System.Net.Sockets.SocketError.HostNotFound)
44
                }
45
                catch (System.Net.Sockets.SocketException ex)
49 46
                {
50

  
47
                    if (ex.SocketErrorCode == System.Net.Sockets.SocketError.HostNotFound)
48
                    {
49
                        System.Diagnostics.Debug.WriteLine("DNS SocketError");
50
                        result = null;
51
                    }
51 52
                }
52
            }
53
            catch (Exception ex)
54
            {
55
                System.Diagnostics.Debug.WriteLine(ex.ToString());
56
            }
53
                catch (Exception ex)
54
                {
55
                    throw ex;
56
                }
57
            });
58

  
59
            System.Diagnostics.Debug.WriteLine("DNS END");
57 60

  
58 61
            return result;
59 62
        }
ConvertService/ServiceBase/Markus.Service.StationController/MainWindow.xaml
23 23
                    <ColumnDefinition Width="Auto"/>
24 24
                    <ColumnDefinition/>
25 25
                </Grid.ColumnDefinitions>
26
                <Grid>
26
                <!--<Grid>
27 27
                    <Grid.ColumnDefinitions>
28 28
                        <ColumnDefinition Width="Auto" />
29 29
                        <ColumnDefinition Width="100*" />
......
39 39
                        </Button>
40 40
                    </materialEx:AppBar>
41 41
                <Border BorderThickness="0,0,1,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
42
                    <materialEx:SideNavigation Items="{Binding NavigationItems,Mode=OneTime}" DataContext="{Binding Mode=OneWay}"/>
42
                    <materialEx:SideNavigation SelectedItem="{Binding SelectNavigationItem,Mode=TwoWay}" Items="{Binding NavigationItems,Mode=OneTime}" DataContext="{Binding Mode=OneWay}"/>
43 43
                </Border>
44
            </Grid>
44
            </Grid>-->
45 45
                <Grid Grid.Column="1">
46 46
                    <DataGrid  ItemsSource="{Binding AliveItems}" AutoGenerateColumns="False"
47 47
                  x:Name="DataGrid" ScrollViewer.CanContentScroll="False">
ConvertService/ServiceBase/Markus.Service.StationController/Markus.Service.StationController.csproj
42 42
    <Reference Include="ConfigParser, Version=0.3.3.6, Culture=neutral, processorArchitecture=MSIL">
43 43
      <HintPath>..\packages\Salaros.ConfigParser.0.3.3\lib\net45\ConfigParser.dll</HintPath>
44 44
    </Reference>
45
    <Reference Include="MaterialDesignColors, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
46
      <HintPath>..\packages\MaterialDesignColors.1.1.2\lib\net45\MaterialDesignColors.dll</HintPath>
45
    <Reference Include="MaterialDesignColors, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
46
      <HintPath>..\packages\MaterialDesignColors.1.1.3\lib\net45\MaterialDesignColors.dll</HintPath>
47 47
    </Reference>
48 48
    <Reference Include="MaterialDesignExtensions, Version=2.6.0.0, Culture=neutral, processorArchitecture=MSIL">
49 49
      <HintPath>..\packages\MaterialDesignExtensions.2.6.0\lib\net45\MaterialDesignExtensions.dll</HintPath>
ConvertService/ServiceBase/Markus.Service.StationController/ViewModel/MainViewModel.cs
25 25

  
26 26
            NavigationItems = new List<INavigationItem>
27 27
            {
28
                new SubheaderNavigationItem(){ Subheader = "Service Settings" },
28
                new SubheaderNavigationItem(){ Subheader = "Service Settings",IsSelected = true },
29 29
                new FirstLevelNavigationItem(){Label = "Service1"},
30 30
                new DividerNavigationItem(),
31 31
                new FirstLevelNavigationItem(){Label = "Service2"},
32 32
            };
33 33

  
34
            NavigationItems.First().IsSelected = true;
34
            SelectNavigationItem = NavigationItems.First();
35 35
        }
36 36

  
37 37
        private void ServiceConnection()
......
49 49

  
50 50
                var config = ConfigHelper.AppConfig(configFileName);
51 51

  
52
                var serviceUri = config.GetValue("SERVICE", "ADDRESS", "http://LOCALHOST:9101/StationService");
52
                var serviceUri = config.GetValue("SERVICE", "ADDRESS", "http://172.20.101.119:9101/StationService");
53 53

  
54 54
                BasicHttpBinding myBinding = new BasicHttpBinding();
55 55
                EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(serviceUri));
......
103 103

  
104 104
        private List<INavigationItem> navigationItems;
105 105

  
106
        public List<INavigationItem> NavigationItems {
106
        public List<INavigationItem> NavigationItems
107
        {
107 108
            get => navigationItems; set
108 109
            {
109 110
                navigationItems = value;
110 111
                OnPropertyChanged(() => navigationItems);
111 112
            }
112 113
        }
114

  
115
        private INavigationItem selectNavigationItem;
116

  
117
        public INavigationItem SelectNavigationItem
118
        {
119
            get => selectNavigationItem; set
120
            {
121
                selectNavigationItem = value;
122
                OnPropertyChanged(() => SelectNavigationItem);
123
    }
124
}
125

  
126

  
113 127
    }
114 128
}
ConvertService/ServiceBase/Markus.Service.StationController/packages.config
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<packages>
3
  <package id="MaterialDesignColors" version="1.1.2" targetFramework="net461" />
3
  <package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
4 4
  <package id="MaterialDesignExtensions" version="2.6.0" targetFramework="net461" />
5 5
  <package id="MaterialDesignThemes" version="2.5.1" targetFramework="net461" />
6 6
  <package id="Microsoft.CSharp" version="4.5.0" targetFramework="net45" />
KCOM/App.xaml.cs
103 103
          
104 104
            try
105 105
            {
106
                #region  //  DNS 체크
107
               
108
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
109

  
110
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
111

  
112
                if (hostEntry == null)
113
                {
114
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
115
                    isExternal = true;
116
                }
117
                else if (!hostEntry.HostName.EndsWith(localdomain))
118
                {
119
                    // 외부 사용자
120
                    isExternal = true;
121
                }
122
                #endregion
123

  
106 124
                splashScreen.Show();
107 125
               
108 126
                /// create log database and table
......
178 196
                //Support.SetLicense();
179 197

  
180 198
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
181
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
182

  
183
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
184

  
185
                if (hostEntry == null || !hostEntry.HostName.EndsWith(localdomain))
186
                {
187
                    // 외부 사용자
188
                    isExternal = true;
189
                }
199
        
190 200
#if DEBUG
191 201
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
202
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
192 203
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
193 204
#else
194 205
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
KCOM/Common/ImageSourceHelper.cs
54 54
                image = null;
55 55
            }
56 56
        }
57

  
58
        public static byte[] CopyPixels(BitmapSource image)
59
        {
60
            byte[] result = new byte[image.PixelWidth * image.PixelHeight * 4];
61
            image.CopyPixels(result, image.PixelWidth * 4, 0);
62

  
63
            return result;
64
        }
65

  
66
        public static byte[] SetBrightness(int brightness, byte[] pixels)
67
        {
68
            for (int i = 0; i < pixels.Length / 4; ++i)
69
            {
70
                byte b = pixels[i * 4];
71
                byte g = pixels[i * 4 + 1];
72
                byte r = pixels[i * 4 + 2];
73
                byte a = pixels[i * 4 + 3];
74

  
75
                if (r != 255 || g != 255 || b != 255 || a == 255)
76
                {
77
                    b = (byte)(b + brightness);
78
                    g = (byte)(g + brightness);
79
                    r = (byte)(r + brightness);
80
                    ///a = (byte)(a + brightness);
81

  
82
                    if (r < 0) r = 1;
83
                    if (r > 255) r = 255;
84

  
85
                    if (g < 0) g = 1;
86
                    if (g > 255) g = 255;
87

  
88
                    if (b < 0) b = 1;
89
                    if (b > 255) b = 255;
90

  
91
                    pixels[i * 4] = b;
92
                    pixels[i * 4 + 1] = g;
93
                    pixels[i * 4 + 2] = r;
94
                }
95
            }
96

  
97
            return pixels;
98
        }
99

  
100
        public static byte[] SetBrightnessAndContrast(int brightness,double contrast, byte[] pixels)
101
        {
102
            if (contrast < -100) contrast = -100;
103
            if (contrast > 100) contrast = 100;
104
            contrast = (100.0 + contrast) / 100.0;
105
            contrast *= contrast;
106

  
107
            for (int i = 0; i < pixels.Length / 4; ++i)
108
            {
109
                byte b = pixels[i * 4];
110
                byte g = pixels[i * 4 + 1];
111
                byte r = pixels[i * 4 + 2];
112
                byte a = pixels[i * 4 + 3];
113

  
114
                if (r != 255 || g != 255 || b != 255 || a == 255)
115
                {
116
                    b = (byte)(b + brightness);
117
                    g = (byte)(g + brightness);
118
                    r = (byte)(r + brightness);
119
                    ///a = (byte)(a + brightness);
120

  
121
                    if (r < 0) r = 1;
122
                    if (r > 255) r = 255;
123

  
124
                    if (g < 0) g = 1;
125
                    if (g > 255) g = 255;
126

  
127
                    if (b < 0) b = 1;
128
                    if (b > 255) b = 255;
129

  
130
                    double pR = r / 255.0;
131
                    pR -= 0.5;
132
                    pR *= contrast;
133
                    pR += 0.5;
134
                    pR *= 255;
135
                    if (pR < 0) pR = 0;
136
                    if (pR > 255) pR = 255;
137

  
138
                    double pG = g / 255.0;
139
                    pG -= 0.5;
140
                    pG *= contrast;
141
                    pG += 0.5;
142
                    pG *= 255;
143
                    if (pG < 0) pG = 0;
144
                    if (pG > 255) pG = 255;
145

  
146
                    double pB = b / 255.0;
147
                    pB -= 0.5;
148
                    pB *= contrast;
149
                    pB += 0.5;
150
                    pB *= 255;
151
                    if (pB < 0) pB = 0;
152
                    if (pB > 255) pB = 255;
153

  
154
                    pixels[i * 4] = (byte)pB;
155
                    pixels[i * 4 + 1] = (byte)pG;
156
                    pixels[i * 4 + 2] = (byte)pR;
157
                }
158
            }
159

  
160
            return pixels;
161
        }
162

  
163
        public static byte[] SetContrast(double contrast, byte[] pixels)
164
        {
165
            if (contrast < -100) contrast = -100;
166
            if (contrast > 100) contrast = 100;
167
            contrast = (100.0 + contrast) / 100.0;
168
            contrast *= contrast;
169

  
170
            for (int i = 0; i < pixels.Length / 4; ++i)
171
            {
172
                byte b = pixels[i * 4];
173
                byte g = pixels[i * 4 + 1];
174
                byte r = pixels[i * 4 + 2];
175
                byte a = pixels[i * 4 + 3];
176

  
177
                if (r != 255 || g != 255 || b != 255 || a == 255)
178
                {
179
                    double pR = r / 255.0;
180
                    pR -= 0.5;
181
                    pR *= contrast;
182
                    pR += 0.5;
183
                    pR *= 255;
184
                    if (pR < 0) pR = 0;
185
                    if (pR > 255) pR = 255;
186

  
187
                    double pG = g / 255.0;
188
                    pG -= 0.5;
189
                    pG *= contrast;
190
                    pG += 0.5;
191
                    pG *= 255;
192
                    if (pG < 0) pG = 0;
193
                    if (pG > 255) pG = 255;
194

  
195
                    double pB = b / 255.0;
196
                    pB -= 0.5;
197
                    pB *= contrast;
198
                    pB += 0.5;
199
                    pB *= 255;
200
                    if (pB < 0) pB = 0;
201
                    if (pB > 255) pB = 255;
202

  
203
                    pixels[i * 4] = (byte)pB;
204
                    pixels[i * 4 + 1] = (byte)pG;
205
                    pixels[i * 4 + 2] = (byte)pR;
206
                }
207
            }
208

  
209
            return pixels;
210
        }
57 211
    }
58 212
}
KCOM/Controls/DecodeImage.cs
1
using System;
1
using KCOM.Common;
2
using System;
2 3
using System.Collections.Generic;
3 4

  
4 5
using System.Linq;
......
69 70
            set => SetValue(ScaleProperty, value);
70 71
        }
71 72

  
72
        private static void ScalePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e)
73
        private static async void ScalePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e)
73 74
        {
74 75
            var owner = d as ScaleDecodeImage;
75 76

  
76 77
            if (owner != null)
77 78
            {
78
                var value = owner.Scale;
79
                //System.Windows.Media.Imaging.BitmapImage image = owner.Source.Clone();
80

  
81
                //image.DecodePixelWidth = (int)(image.PixelWidth * value);
82
                //image.DecodePixelHeight = (int)(image.PixelHeight * value);
83

  
84
                //owner.ViewSource = image;
85

  
86
                if (value < 1)
87
                {
88
                    TransformedBitmap tb = new TransformedBitmap();
89
                    tb.BeginInit();
90
                    tb.Source = owner.Source;
91
                    tb.Transform = new ScaleTransform(value, value);
92
                    tb.EndInit();
93
                    System.Diagnostics.Debug.WriteLine($"TranFormImage Height : {tb.Height} Scale : {value}");
94
                    owner.ViewSource = tb;
95
                }
79
                await owner.Dispatcher.InvokeAsync(() => {
80

  
81
                    var value = owner.Scale;
82

  
83
                    if (value < 1)
84
                    {
85
                        TransformedBitmap tb = new TransformedBitmap();
86
                        tb.BeginInit();
87
                        tb.Source = owner.Source;
88
                        tb.Transform = new ScaleTransform(value, value);
89
                        tb.EndInit();
90

  
91
                        byte[] pixels = ImageSourceHelper.CopyPixels(tb);
92

  
93
                        var brightness = (double)(value * 100) / (double)100 * (double)100 - 80;
94

  
95
                        if (brightness < -30)
96
                        {
97
                            pixels = ImageSourceHelper.SetBrightnessAndContrast((int)brightness, brightness * -1.0, pixels);
98
                            //pixels = ImageSourceHelper.SetContrast(brightness * -1.0, pixels);
99

  
100
                            var bmp = new WriteableBitmap(tb.PixelWidth, tb.PixelHeight, tb.DpiX, tb.DpiY, PixelFormats.Pbgra32, null);
101
                            bmp.WritePixels(new Int32Rect(0, 0, tb.PixelWidth, tb.PixelHeight), pixels, tb.PixelWidth * 4, 0);
102
                            owner.ViewSource = bmp;
103
                        }
104
                        else
105
                        {
106
                            owner.ViewSource = tb;
107
                        }
108

  
109
                        System.Diagnostics.Debug.WriteLine($"TranFormImage Height : {tb.Height} Scale : {value}  brightness : {brightness}");
110
                    
111
                    }
112
                });
96 113
            }
97 114
        }
98 115
    }
KCOM/KCOM.csproj.user
16 16
    <StartArguments>eyJEb2N1bWVudEl0ZW1JRCI6IjQwMDAwMTQyIiwiYlBhcnRuZXIiOmZhbHNlLCJDcmVhdGVGaW5hbFBERlBlcm1pc3Npb24iOmZhbHNlLCJOZXdDb21tZW50UGVybWlzc2lvbiI6dHJ1ZSwiUHJvamVjdE5PIjoiMDAwMDAwIiwiVXNlcklEIjoiZG9mdGVjaCIsIk1vZGUiOjB9</StartArguments>
17 17
  </PropertyGroup>
18 18
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
19
    <StartArguments>eyJEb2N1bWVudEl0ZW1JRCI6IjQwMDAwMTQwIiwiYlBhcnRuZXIiOmZhbHNlLCJDcmVhdGVGaW5hbFBERlBlcm1pc3Npb24iOnRydWUsIk5ld0NvbW1lbnRQZXJtaXNzaW9uIjp0cnVlLCJQcm9qZWN0Tk8iOiIwMDAwMDAiLCJVc2VySUQiOiJIMjAxMTM1NyIsIk1vZGUiOjB9</StartArguments>
19
    <StartArguments>eyJEb2N1bWVudEl0ZW1JRCI6IjQwMDAwMTQxIiwiYlBhcnRuZXIiOmZhbHNlLCJDcmVhdGVGaW5hbFBERlBlcm1pc3Npb24iOnRydWUsIk5ld0NvbW1lbnRQZXJtaXNzaW9uIjp0cnVlLCJQcm9qZWN0Tk8iOiIwMDAwMDAiLCJVc2VySUQiOiJhZG1pbiIsIk1vZGUiOjB9</StartArguments>
20 20
    <StartAction>Project</StartAction>
21 21
    <StartProgram>C:\Program Files\DOFTECH\MARKUS\KCOM.exe</StartProgram>
22 22
  </PropertyGroup>
KCOM/Resources/DecodeImageTemplate.xaml
5 5
        <Setter Property="Template">
6 6
            <Setter.Value>
7 7
                <ControlTemplate TargetType="local:ScaleDecodeImage">
8
                    <Image x:Name="PART_IMAGE" Stretch="Fill" Source="{TemplateBinding ViewSource}" RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Unspecified" RenderOptions.ClearTypeHint="Enabled"/>
8
                    <Image x:Name="PART_IMAGE" Stretch="Fill" Source="{TemplateBinding ViewSource}" RenderOptions.BitmapScalingMode="HighQuality"  RenderOptions.EdgeMode="Unspecified" RenderOptions.ClearTypeHint="Enabled"/>
9 9
                </ControlTemplate>
10 10
            </Setter.Value>
11 11
        </Setter>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)