Удалены лишние сервисы

This commit is contained in:
2026-04-08 01:58:19 +03:00
parent 0ab6b54dff
commit e0c4287e25
10 changed files with 6 additions and 501 deletions

View File

@@ -1,29 +0,0 @@
using Minint.Core.Models;
namespace Minint.Core.Services;
public interface IFragmentService
{
/// <summary>
/// Copies a rectangular region from one document/layer to another.
/// Palette colors are merged: missing colors are added to the destination palette.
/// </summary>
/// <param name="srcDoc">Source document.</param>
/// <param name="srcLayerIndex">Index of the source layer.</param>
/// <param name="srcX">Source rectangle X origin.</param>
/// <param name="srcY">Source rectangle Y origin.</param>
/// <param name="regionWidth">Width of the region to copy.</param>
/// <param name="regionHeight">Height of the region to copy.</param>
/// <param name="dstDoc">Destination document.</param>
/// <param name="dstLayerIndex">Index of the destination layer.</param>
/// <param name="dstX">Destination X origin.</param>
/// <param name="dstY">Destination Y origin.</param>
/// <param name="containerWidth">Container width (shared by both docs).</param>
/// <param name="containerHeight">Container height (shared by both docs).</param>
void CopyFragment(
MinintDocument srcDoc, int srcLayerIndex,
int srcX, int srcY, int regionWidth, int regionHeight,
MinintDocument dstDoc, int dstLayerIndex,
int dstX, int dstY,
int containerWidth, int containerHeight);
}

View File

@@ -1,20 +0,0 @@
using Minint.Core.Models;
namespace Minint.Core.Services;
public interface IImageEffectService
{
/// <summary>
/// Adjusts contrast of the document by modifying palette colors.
/// <paramref name="factor"/> > 1 increases contrast, &lt; 1 decreases.
/// Index 0 (transparent) is not modified.
/// </summary>
void AdjustContrast(MinintDocument document, float factor);
/// <summary>
/// Converts the document to grayscale by modifying palette colors.
/// Uses ITU-R BT.601 luminance: gray = 0.299R + 0.587G + 0.114B.
/// Index 0 (transparent) is not modified.
/// </summary>
void ToGrayscale(MinintDocument document);
}

View File

@@ -1,23 +0,0 @@
using Minint.Core.Models;
namespace Minint.Core.Services;
public interface IPaletteService
{
/// <summary>
/// Returns the index of <paramref name="color"/> in the document palette.
/// If the color is not present, appends it and returns the new index.
/// </summary>
int EnsureColor(MinintDocument document, RgbaColor color);
/// <summary>
/// Finds index of an exact color match, or returns -1 if not found.
/// </summary>
int FindColor(MinintDocument document, RgbaColor color);
/// <summary>
/// Removes unused colors from the palette and remaps all layer pixel indices.
/// Index 0 (transparent) is always preserved.
/// </summary>
void CompactPalette(MinintDocument document);
}

View File

@@ -1,49 +0,0 @@
using System;
using Minint.Core.Models;
namespace Minint.Core.Services.Impl;
public sealed class FragmentService : IFragmentService
{
public void CopyFragment(
MinintDocument srcDoc, int srcLayerIndex,
int srcX, int srcY, int regionWidth, int regionHeight,
MinintDocument dstDoc, int dstLayerIndex,
int dstX, int dstY,
int containerWidth, int containerHeight)
{
ArgumentOutOfRangeException.ThrowIfNegative(srcLayerIndex);
ArgumentOutOfRangeException.ThrowIfNegative(dstLayerIndex);
if (srcLayerIndex >= srcDoc.Layers.Count)
throw new ArgumentOutOfRangeException(nameof(srcLayerIndex));
if (dstLayerIndex >= dstDoc.Layers.Count)
throw new ArgumentOutOfRangeException(nameof(dstLayerIndex));
var srcLayer = srcDoc.Layers[srcLayerIndex];
var dstLayer = dstDoc.Layers[dstLayerIndex];
int clippedSrcX = Math.Max(srcX, 0);
int clippedSrcY = Math.Max(srcY, 0);
int clippedEndX = Math.Min(srcX + regionWidth, containerWidth);
int clippedEndY = Math.Min(srcY + regionHeight, containerHeight);
for (int sy = clippedSrcY; sy < clippedEndY; sy++)
{
int dy = dstY + (sy - srcY);
if (dy < 0 || dy >= containerHeight) continue;
for (int sx = clippedSrcX; sx < clippedEndX; sx++)
{
int dx = dstX + (sx - srcX);
if (dx < 0 || dx >= containerWidth) continue;
int srcIdx = srcLayer.Pixels[sy * containerWidth + sx];
if (srcIdx == 0) continue; // skip transparent
RgbaColor color = srcDoc.Palette[srcIdx];
int dstIdx = dstDoc.EnsureColorCached(color);
dstLayer.Pixels[dy * containerWidth + dx] = dstIdx;
}
}
}
}

View File

@@ -1,56 +0,0 @@
using Minint.Core.Models;
namespace Minint.Core.Services.Impl;
public sealed class PaletteService : IPaletteService
{
public int FindColor(MinintDocument document, RgbaColor color)
=> document.FindColorCached(color);
public int EnsureColor(MinintDocument document, RgbaColor color)
=> document.EnsureColorCached(color);
public void CompactPalette(MinintDocument document)
{
var palette = document.Palette;
if (palette.Count <= 1)
return;
var usedIndices = new HashSet<int> { 0 };
foreach (var layer in document.Layers)
{
foreach (int idx in layer.Pixels)
usedIndices.Add(idx);
}
var oldToNew = new int[palette.Count];
var newPalette = new List<RgbaColor>(usedIndices.Count);
newPalette.Add(palette[0]);
oldToNew[0] = 0;
for (int i = 1; i < palette.Count; i++)
{
if (usedIndices.Contains(i))
{
oldToNew[i] = newPalette.Count;
newPalette.Add(palette[i]);
}
}
if (newPalette.Count == palette.Count)
return;
palette.Clear();
palette.AddRange(newPalette);
foreach (var layer in document.Layers)
{
var px = layer.Pixels;
for (int i = 0; i < px.Length; i++)
px[i] = oldToNew[px[i]];
}
document.InvalidatePaletteCache();
}
}