개정판 997071b8
이미지 진하게 하는 부분 해제
KCOM/Common/ImageSourceHelper.cs | ||
---|---|---|
99 | 99 |
|
100 | 100 |
public static byte[] SetBrightnessAndContrast(int brightness,double contrast, byte[] pixels) |
101 | 101 |
{ |
102 |
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); |
|
103 |
stopwatch.Start(); |
|
104 |
|
|
102 | 105 |
if (contrast < -100) contrast = -100; |
103 | 106 |
if (contrast > 100) contrast = 100; |
104 | 107 |
contrast = (100.0 + contrast) / 100.0; |
... | ... | |
111 | 114 |
byte r = pixels[i * 4 + 2]; |
112 | 115 |
byte a = pixels[i * 4 + 3]; |
113 | 116 |
|
114 |
if (r != 255 || g != 255 || b != 255 || a != 255) |
|
117 |
//System.Diagnostics.Debug.WriteLineIf(i< 4, $"B :{b} G : {g} r : {r}"); |
|
118 |
|
|
119 |
if (r != 255 || g != 255 || b != 255) |
|
115 | 120 |
{ |
116 | 121 |
b = (byte)(b + brightness); |
117 | 122 |
g = (byte)(g + brightness); |
... | ... | |
157 | 162 |
} |
158 | 163 |
} |
159 | 164 |
|
165 |
System.Diagnostics.Debug.WriteLine($"일반 : {stopwatch.Elapsed.ToString()}"); |
|
166 |
|
|
167 |
return pixels; |
|
168 |
} |
|
169 |
|
|
170 |
public static byte[] SetBrightnessAndContrastLinp(int brightness, double contrast, byte[] pixels) |
|
171 |
{ |
|
172 |
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); |
|
173 |
stopwatch.Start(); |
|
174 |
|
|
175 |
if (contrast < -100) contrast = -100; |
|
176 |
|
|
177 |
if (contrast > 100) contrast = 100; |
|
178 |
|
|
179 |
contrast = (100.0 + contrast) / 100.0; |
|
180 |
|
|
181 |
contrast *= contrast; |
|
182 |
|
|
183 |
Parallel.ForEach(SteppedIntegerList(pixels,0, pixels.Length, 4,4),new ParallelOptions {MaxDegreeOfParallelism = 5 }, item=> |
|
184 |
{ |
|
185 |
var pixel = item.ToList(); |
|
186 |
|
|
187 |
byte b = pixel[0].Value; |
|
188 |
byte g = pixel[1].Value; |
|
189 |
byte r = pixel[2].Value; |
|
190 |
byte a = pixel[3].Value; |
|
191 |
|
|
192 |
//System.Diagnostics.Debug.WriteLineIf(pixel[0].Key < 4, $"B :{b} G : {g} r : {r}"); |
|
193 |
|
|
194 |
if (r != 255 || g != 255 || b != 255) |
|
195 |
{ |
|
196 |
b = (byte)(b + brightness); |
|
197 |
g = (byte)(g + brightness); |
|
198 |
r = (byte)(r + brightness); |
|
199 |
///a = (byte)(a + brightness); |
|
200 |
|
|
201 |
if (r < 0) r = 1; |
|
202 |
if (r > 255) r = 255; |
|
203 |
|
|
204 |
if (g < 0) g = 1; |
|
205 |
if (g > 255) g = 255; |
|
206 |
|
|
207 |
if (b < 0) b = 1; |
|
208 |
if (b > 255) b = 255; |
|
209 |
|
|
210 |
double pR = r / 255.0; |
|
211 |
pR -= 0.5; |
|
212 |
pR *= contrast; |
|
213 |
pR += 0.5; |
|
214 |
pR *= 255; |
|
215 |
if (pR < 0) pR = 0; |
|
216 |
if (pR > 255) pR = 255; |
|
217 |
|
|
218 |
double pG = g / 255.0; |
|
219 |
pG -= 0.5; |
|
220 |
pG *= contrast; |
|
221 |
pG += 0.5; |
|
222 |
pG *= 255; |
|
223 |
if (pG < 0) pG = 0; |
|
224 |
if (pG > 255) pG = 255; |
|
225 |
|
|
226 |
double pB = b / 255.0; |
|
227 |
pB -= 0.5; |
|
228 |
pB *= contrast; |
|
229 |
pB += 0.5; |
|
230 |
pB *= 255; |
|
231 |
if (pB < 0) pB = 0; |
|
232 |
if (pB > 255) pB = 255; |
|
233 |
|
|
234 |
pixels[pixel[0].Key] = (byte)pB; |
|
235 |
pixels[pixel[1].Key] = (byte)pG; |
|
236 |
pixels[pixel[2].Key] = (byte)pR; |
|
237 |
} |
|
238 |
}); |
|
239 |
|
|
240 |
System.Diagnostics.Debug.WriteLine($"Linq : {stopwatch.Elapsed.ToString()}"); |
|
241 |
|
|
160 | 242 |
return pixels; |
161 | 243 |
} |
162 | 244 |
|
245 |
public static IEnumerable<Dictionary<int,T>> SteppedIntegerList<T>(T[] array, int startIndex,int endEndex, int stepSize,int TakeSize) |
|
246 |
{ |
|
247 |
for (int i = startIndex; i < endEndex; i += stepSize) |
|
248 |
{ |
|
249 |
Dictionary<int, T> result = new Dictionary<int, T>(); |
|
250 |
|
|
251 |
for (int j = 0; j < TakeSize; j++) |
|
252 |
{ |
|
253 |
result.Add(j, array[i + j]); |
|
254 |
} |
|
255 |
|
|
256 |
yield return result; |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
163 | 260 |
public static byte[] SetContrast(double contrast, byte[] pixels) |
164 | 261 |
{ |
165 | 262 |
if (contrast < -100) contrast = -100; |
KCOM/Controls/DecodeImage.cs | ||
---|---|---|
98 | 98 |
tb.Transform = new ScaleTransform(value, value); |
99 | 99 |
tb.EndInit(); |
100 | 100 |
|
101 |
owner.ViewSource = tb; |
|
102 |
|
|
103 |
#region 진하게 하는 부분은 해제 김태성 2019.07.10 |
|
104 |
|
|
105 |
/* |
|
101 | 106 |
byte[] pixels = ImageSourceHelper.CopyPixels(tb); |
102 | 107 |
|
103 | 108 |
var brightness = (double)(value * 100) / (double)100 * (double)100 - 10; |
104 | 109 |
|
105 | 110 |
if (brightness < 0) |
106 | 111 |
{ |
107 |
pixels = ImageSourceHelper.SetBrightnessAndContrast((int)brightness, brightness * -1.0, pixels); |
|
112 |
var pixels2 = ImageSourceHelper.SetBrightnessAndContrast((int)brightness, brightness * -1.0, pixels); |
|
113 |
|
|
114 |
pixels = ImageSourceHelper.SetBrightnessAndContrastLinp((int)brightness, brightness * -1.0, pixels); |
|
115 |
|
|
116 |
System.Diagnostics.Debug.WriteLine("pixels 비교 : " + pixels.SequenceEqual(pixels2)); |
|
117 |
|
|
108 | 118 |
//pixels = ImageSourceHelper.SetContrast(brightness * -1.0, pixels); |
109 | 119 |
|
110 | 120 |
var bmp = new WriteableBitmap(tb.PixelWidth, tb.PixelHeight, tb.DpiX, tb.DpiY, PixelFormats.Pbgra32, null); |
... | ... | |
115 | 125 |
{ |
116 | 126 |
owner.ViewSource = tb; |
117 | 127 |
} |
128 |
*/ |
|
129 |
#endregion |
|
118 | 130 |
|
119 | 131 |
owner.scaleImages.Add(new ScaleImage { Scale = value, source = owner.ViewSource }); |
120 | 132 |
|
내보내기 Unified diff