Skip to content

Commit c6ac294

Browse files
author
LoneWandererProductions
committed
set to correct image version
1 parent 7b8d2cb commit c6ac294

36 files changed

Lines changed: 291 additions & 370 deletions

Imaging/Cif.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,4 @@ private static Dictionary<Color, SortedSet<int>> SortDct(Dictionary<Color, Sorte
439439
return value.OrderByDescending(kv => kv.Value.Count)
440440
.ToDictionary(kv => kv.Key, kv => kv.Value);
441441
}
442-
}
442+
}

Imaging/CifImageData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ private static (int? Start, int? End)? GetStartEndPoint(IReadOnlyList<string> ls
9595

9696
return checkStart && checkEnd ? (start, end) : null;
9797
}
98-
}
98+
}

Imaging/CifMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ public sealed class CifMetadata
6262
/// The check sum.
6363
/// </value>
6464
public int CheckSum { get; set; }
65-
}
65+
}

Imaging/CifProcessing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,4 @@ internal static List<List<string>> GenerateCsvCompressed(int imageHeight, int im
231231

232232
return master;
233233
}
234-
}
234+
}

Imaging/ColorHsv.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public sealed class ColorHsv : IEquatable<ColorHsv>, IComparable<ColorHsv>
9797
/// <summary>
9898
/// Prevents a default instance of the <see cref="ColorHsv"/> class from being created.
9999
/// </summary>
100-
private ColorHsv() { } // internal factory use
100+
private ColorHsv()
101+
{
102+
} // internal factory use
101103

102104
/// <summary>
103105
/// Initializes a new instance of the <see cref="ColorHsv"/> class.
@@ -174,10 +176,10 @@ public static ColorHsv FromHex(string hex, int a = 255)
174176
/// <returns>Color HSV object.</returns>
175177
public static ColorHsv FromArgbInt(int argb)
176178
{
177-
int a = (argb >> 24) & 0xFF;
178-
int r = (argb >> 16) & 0xFF;
179-
int g = (argb >> 8) & 0xFF;
180-
int b = argb & 0xFF;
179+
var a = (argb >> 24) & 0xFF;
180+
var r = (argb >> 16) & 0xFF;
181+
var g = (argb >> 8) & 0xFF;
182+
var b = argb & 0xFF;
181183

182184
return FromRgb(r, g, b, a);
183185
}
@@ -231,7 +233,7 @@ public override bool Equals(object obj)
231233
/// Returns a hash code for this instance.
232234
/// </summary>
233235
/// <returns>
234-
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
236+
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
235237
/// </returns>
236238
public override int GetHashCode()
237239
=> HashCode.Combine(R, G, B, A);
@@ -304,13 +306,13 @@ public int CompareTo(ColorHsv? other)
304306
/// </summary>
305307
private void ToHsv()
306308
{
307-
double r = R / 255d;
308-
double g = G / 255d;
309-
double b = B / 255d;
309+
var r = R / 255d;
310+
var g = G / 255d;
311+
var b = B / 255d;
310312

311-
double max = Math.Max(r, Math.Max(g, b));
312-
double min = Math.Min(r, Math.Min(g, b));
313-
double delta = max - min;
313+
var max = Math.Max(r, Math.Max(g, b));
314+
var min = Math.Min(r, Math.Min(g, b));
315+
var delta = max - min;
314316

315317
// Hue
316318
if (delta == 0)
@@ -334,9 +336,9 @@ private void ToHsv()
334336
/// </summary>
335337
private void ToRgb()
336338
{
337-
double c = V * S;
338-
double x = c * (1 - Math.Abs((H / 60 % 2) - 1));
339-
double m = V - c;
339+
var c = V * S;
340+
var x = c * (1 - Math.Abs((H / 60 % 2) - 1));
341+
var m = V - c;
340342

341343
double r = 0, g = 0, b = 0;
342344

@@ -417,4 +419,4 @@ private static void ValidateHsv(double h, double s, double v, int a)
417419
if (a < 0 || a > 255) throw new ArgumentOutOfRangeException("Alpha must be 0–255");
418420
}
419421
}
420-
}
422+
}

Imaging/CustomImageFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ public void GenerateCifCompressedFromBitmap(Bitmap image, string path)
9393
var lst = CifProcessing.GenerateCsvCompressed(image.Height, image.Width, imageFormat);
9494
CsvHandler.WriteCsv(path, lst);
9595
}
96-
}
96+
}

Imaging/DirectBitmap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,4 +698,4 @@ private void Dispose(bool disposing)
698698
// Finalizer calls Dispose(false)
699699
Dispose(false);
700700
}
701-
}
701+
}

Imaging/DirectBitmapImage.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ public void SetPixelsUnsafe(IEnumerable<PixelData> pixels)
123123
unsafe
124124
{
125125
var buffer = (byte*)_bitmap.BackBuffer.ToPointer();
126-
int stride = _bitmap.BackBufferStride;
126+
var stride = _bitmap.BackBufferStride;
127127

128128
foreach (var pixel in pixels)
129129
{
130130
if (pixel.X < 0 || pixel.X >= Width || pixel.Y < 0 || pixel.Y >= Height)
131131
continue;
132132

133-
int offset = pixel.Y * stride + pixel.X * 4;
133+
var offset = pixel.Y * stride + pixel.X * 4;
134134
buffer[offset + 0] = pixel.B;
135135
buffer[offset + 1] = pixel.G;
136136
buffer[offset + 2] = pixel.R;
@@ -139,7 +139,6 @@ public void SetPixelsUnsafe(IEnumerable<PixelData> pixels)
139139
Bits[pixel.Y * Width + pixel.X] =
140140
(uint)(pixel.A << 24 | pixel.R << 16 | pixel.G << 8 | pixel.B);
141141
}
142-
143142
}
144143

145144
_bitmap.AddDirtyRect(new Int32Rect(0, 0, Width, Height));
@@ -152,16 +151,16 @@ public void SetPixelsUnsafe(IEnumerable<PixelData> pixels)
152151
/// <param name="color">The color to fill with.</param>
153152
public unsafe void FillSimd(Color color)
154153
{
155-
uint packed = (uint)(color.A << 24 | color.R << 16 | color.G << 8 | color.B);
154+
var packed = (uint)(color.A << 24 | color.R << 16 | color.G << 8 | color.B);
156155
_bitmap.Lock();
157156

158-
uint* ptr = (uint*)_bitmap.BackBuffer.ToPointer();
159-
int len = Bits.Length;
160-
int vecSize = Vector<uint>.Count;
161-
int i = 0;
157+
var ptr = (uint*)_bitmap.BackBuffer.ToPointer();
158+
var len = Bits.Length;
159+
var vecSize = Vector<uint>.Count;
160+
var i = 0;
162161

163162
// SIMD bulk fill
164-
Vector<uint> v = new Vector<uint>(packed);
163+
var v = new Vector<uint>(packed);
165164
for (; i <= len - vecSize; i += vecSize)
166165
v.CopyTo(Bits, i);
167166

@@ -202,9 +201,9 @@ public void ApplyColorMatrix(float[][] matrix)
202201
// We reuse output array to avoid allocations when repeating effects
203202
var pixels = new (int x, int y, Color color)[Bits.Length];
204203

205-
for (int i = 0; i < Bits.Length; i++)
204+
for (var i = 0; i < Bits.Length; i++)
206205
{
207-
uint argb = Bits[i];
206+
var argb = Bits[i];
208207

209208
// Manual unpack (fastest + identical)
210209
float r = (byte)(argb >> 16);
@@ -213,16 +212,16 @@ public void ApplyColorMatrix(float[][] matrix)
213212
float a = (byte)(argb >> 24);
214213

215214
// Ordered multiply like WinForms (NOT SIMD parallel)
216-
float rr = r * m00 + g * m01 + b * m02 + a * m03;
217-
float gg = r * m10 + g * m11 + b * m12 + a * m13;
218-
float bb = r * m20 + g * m21 + b * m22 + a * m23;
219-
float aa = r * m30 + g * m31 + b * m32 + a * m33;
215+
var rr = r * m00 + g * m01 + b * m02 + a * m03;
216+
var gg = r * m10 + g * m11 + b * m12 + a * m13;
217+
var bb = r * m20 + g * m21 + b * m22 + a * m23;
218+
var aa = r * m30 + g * m31 + b * m32 + a * m33;
220219

221220
// Same exact truncation as WinForms (NOT Math.Round)
222-
byte R = (byte)(rr < 0f ? 0f : (rr > 255f ? 255f : rr));
223-
byte G = (byte)(gg < 0f ? 0f : (gg > 255f ? 255f : gg));
224-
byte B = (byte)(bb < 0f ? 0f : (bb > 255f ? 255f : bb));
225-
byte A = (byte)(aa < 0f ? 0f : (aa > 255f ? 255f : aa));
221+
var R = (byte)(rr < 0f ? 0f : (rr > 255f ? 255f : rr));
222+
var G = (byte)(gg < 0f ? 0f : (gg > 255f ? 255f : gg));
223+
var B = (byte)(bb < 0f ? 0f : (bb > 255f ? 255f : bb));
224+
var A = (byte)(aa < 0f ? 0f : (aa > 255f ? 255f : aa));
226225

227226
// Save (no packing yet)
228227
pixels[i] = (i % Width, i / Width, Color.FromArgb(A, R, G, B));
@@ -264,22 +263,22 @@ public void BlendSimd(uint[] src)
264263
if (src == null || src.Length != Bits.Length)
265264
throw new ArgumentException("Source must match image size");
266265

267-
int len = Bits.Length;
266+
var len = Bits.Length;
268267

269-
for (int i = 0; i < len; i++)
268+
for (var i = 0; i < len; i++)
270269
{
271-
uint s = src[i];
270+
var s = src[i];
272271
if ((s >> 24) == 0)
273272
continue; // fully transparent, skip completely
274273

275-
uint d = Bits[i];
274+
var d = Bits[i];
276275

277276
// Load BGRA from packed uint into float components
278277
var sf = new Vector4(
279-
(s >> 16) & 255, // R
280-
(s >> 8) & 255, // G
281-
(s) & 255, // B
282-
(s >> 24) & 255 // A
278+
(s >> 16) & 255, // R
279+
(s >> 8) & 255, // G
280+
(s) & 255, // B
281+
(s >> 24) & 255 // A
283282
);
284283

285284
var df = new Vector4(
@@ -289,12 +288,12 @@ public void BlendSimd(uint[] src)
289288
(d >> 24) & 255
290289
);
291290

292-
float a = sf.W * (1f / 255f);
291+
var a = sf.W * (1f / 255f);
293292
if (a <= 0.0001f)
294293
continue; // ignore near-transparent pixels
295294

296295
// SIMD blend: Dst = Src * a + Dst * (1−a)
297-
Vector4 r = sf * a + df * (1f - a);
296+
var r = sf * a + df * (1f - a);
298297

299298
// Clamp and repack BGRA
300299
Bits[i] =
@@ -319,8 +318,8 @@ public unsafe void SetPixelsSimd(IEnumerable<(int x, int y, Color color)> pixels
319318
foreach (var (x, y, c) in pixels)
320319
{
321320
if ((uint)x >= Width || (uint)y >= Height) continue;
322-
uint packed = (uint)(c.A << 24 | c.R << 16 | c.G << 8 | c.B);
323-
int index = x + y * Width;
321+
var packed = (uint)(c.A << 24 | c.R << 16 | c.G << 8 | c.B);
322+
var index = x + y * Width;
324323
ptr[index] = packed;
325324
Bits[index] = packed;
326325
}
@@ -368,10 +367,11 @@ public void UpdateBitmapFromBits()
368367
_bitmap.Lock();
369368
unsafe
370369
{
371-
void* src = (void*)_bitsHandle.AddrOfPinnedObject();
372-
void* dst = (void*)_bitmap.BackBuffer;
370+
var src = (void*)_bitsHandle.AddrOfPinnedObject();
371+
var dst = (void*)_bitmap.BackBuffer;
373372
Buffer.MemoryCopy(src, dst, Bits.Length * sizeof(uint), Bits.Length * sizeof(uint));
374373
}
374+
375375
_bitmap.AddDirtyRect(new Int32Rect(0, 0, Width, Height));
376376
_bitmap.Unlock();
377377
}
@@ -403,4 +403,4 @@ private void Dispose(bool disposing)
403403
{
404404
Dispose(false);
405405
}
406-
}
406+
}

Imaging/Enums/FiltersType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ public enum FiltersType
155155
/// The pencil sketch effect
156156
/// </summary>
157157
PencilSketchEffect = 26
158-
}
158+
}

Imaging/Enums/MaskShape.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ public enum MaskShape
2929
/// The polygon
3030
/// </summary>
3131
Polygon = 2
32-
}
32+
}

0 commit comments

Comments
 (0)