Удалены лишние сервисы
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user