ImageExtensions - Renamed 'CreateImageList' to 'Split' and 'SplitHorizontal' respectively

This commit is contained in:
miku-666
2023-08-13 15:30:18 +02:00
parent 721c9649a2
commit 6e09a9c427
6 changed files with 21 additions and 25 deletions

View File

@@ -45,30 +45,26 @@ namespace PckStudio.Extensions
}
/// <summary>
/// Creates an image array by reading in horizontal order
/// Creates an IEnumerable by reading in horizontal order
/// </summary>
/// <param name="source"></param>
/// <param name="size">Size of individual image inside of <paramref name="source"/></param>
internal static IEnumerable<Image> CreateImageList(this Image source, Size size)
/// <param name="source">this image</param>
/// <param name="scalar">Indecates width and height of image sub section</param>
/// <returns><see cref="IEnumerable{Image}"/> of type <see cref="Image"/></returns>
internal static IEnumerable<Image> SplitHorizontal(this Image source, int scalar)
{
return source.CreateImageList(size, ImageLayoutDirection.Horizontal);
return source.Split(scalar, ImageLayoutDirection.Horizontal);
}
internal static IEnumerable<Image> CreateImageList(this Image source, int scalar)
internal static IEnumerable<Image> Split(this Image source, int scalar, ImageLayoutDirection layoutDirection)
{
return source.CreateImageList(scalar, ImageLayoutDirection.Horizontal);
return Split(source, new Size(scalar, scalar), layoutDirection);
}
internal static IEnumerable<Image> CreateImageList(this Image source, int scalar, ImageLayoutDirection layoutDirection)
{
return CreateImageList(source, new Size(scalar, scalar), layoutDirection);
}
internal static IEnumerable<Image> CreateImageList(this Image source, Size size, ImageLayoutDirection imageLayout)
internal static IEnumerable<Image> Split(this Image source, Size size, ImageLayoutDirection imageLayout)
{
int rowCount = source.Width / size.Width;
int columnCount = source.Height / size.Height;
Debug.WriteLine($"{nameof(source.Size)}={source.Size}, {nameof(size)}={size}, {columnCount} {rowCount}");
Debug.WriteLine($"Image size: {source.Size}, Area size: {size}, col num: {columnCount}, row num: {rowCount}");
for (int i = 0; i < columnCount * rowCount; i++)
{
int row = Math.DivRem(i, rowCount, out int column);
@@ -80,7 +76,7 @@ namespace PckStudio.Extensions
yield break;
}
internal static IEnumerable<Image> CreateImageList(this Image source, ImageLayoutDirection layoutDirection)
internal static IEnumerable<Image> Split(this Image source, ImageLayoutDirection layoutDirection)
{
for (int i = 0; i < source.Height / source.Width; i++)
{
@@ -90,7 +86,7 @@ namespace PckStudio.Extensions
yield break;
}
internal static Image CombineImages(this IList<Image> sources, ImageLayoutDirection layoutDirection)
internal static Image Combine(this IList<Image> sources, ImageLayoutDirection layoutDirection)
{
Size imageSize = CalculateImageSize(sources, layoutDirection);
var image = new Bitmap(imageSize.Width, imageSize.Height);

View File

@@ -82,7 +82,7 @@ namespace PckStudio.Forms.Editor
{
using MemoryStream textureMem = new MemoryStream(animationFile.Data);
var texture = new Bitmap(textureMem);
var frameTextures = texture.CreateImageList(ImageLayoutDirection.Vertical);
var frameTextures = texture.Split(ImageLayoutDirection.Vertical);
currentAnimation = animationFile.Properties.HasProperty("ANIM")
? new Animation(frameTextures, animationFile.Properties.GetPropertyValue("ANIM"))
: new Animation(frameTextures, string.Empty);
@@ -329,7 +329,7 @@ namespace PckStudio.Forms.Editor
MessageBox.Show(textureFile + " was not found", "Texture not found");
return;
}
var textures = Image.FromFile(textureFile).CreateImageList(ImageLayoutDirection.Vertical);
var textures = Image.FromFile(textureFile).Split(ImageLayoutDirection.Vertical);
var new_animation = new Animation(textures);
new_animation.Category = currentAnimation.Category;
try
@@ -527,7 +527,7 @@ namespace PckStudio.Forms.Editor
if (ofd.ShowDialog() != DialogResult.OK)
return;
Image img = Image.FromFile(ofd.FileName);
var textures = img.CreateImageList(ImageLayoutDirection.Vertical);
var textures = img.Split(ImageLayoutDirection.Vertical);
currentAnimation = new Animation(textures, string.Empty);
LoadAnimationTreeView();
}

View File

@@ -95,7 +95,7 @@ namespace PckStudio.Forms.Editor
_ => (null, null),
};
originalPictureBox.Image = atlas;
var images = atlas.CreateImageList(_areaSize, _imageLayout);
var images = atlas.Split(_areaSize, _imageLayout);
var tiles = images.enumerate().Select(
p => new AtlasTile(p.index, GetAtlasArea(p.index, _rowCount, _columnCount, _areaSize, _imageLayout), tileInfos.IndexInRange(p.index) ? tileInfos[p.index] : null, p.value)
@@ -158,7 +158,7 @@ namespace PckStudio.Forms.Editor
{
using var ms = new MemoryStream(animationFile.Data);
var img = Image.FromStream(ms);
var textures = img.CreateImageList(ImageLayoutDirection.Vertical);
var textures = img.Split(ImageLayoutDirection.Vertical);
var animation = new Internal.Animation(textures, animationFile.Properties.GetPropertyValue("ANIM"));
selectTilePictureBox.Start(animation);
return;

View File

@@ -23,10 +23,10 @@ namespace PckStudio.Helper
internal static List<JsonTileInfo> BlockTileInfos => JsonTileData.Blocks;
private static Image[] _itemImages;
public static Image[] ItemImages => _itemImages ??= Resources.items_sheet.CreateImageList(16).ToArray();
public static Image[] ItemImages => _itemImages ??= Resources.items_sheet.SplitHorizontal(16).ToArray();
private static Image[] _blockImages;
public static Image[] BlockImages => _blockImages ??= Resources.terrain_sheet.CreateImageList(16).ToArray();
public static Image[] BlockImages => _blockImages ??= Resources.terrain_sheet.SplitHorizontal(16).ToArray();
private static ImageList _itemImageList;
public static ImageList ItemImageList

View File

@@ -189,7 +189,7 @@ namespace PckStudio.Internal
if (textures[0].Width != textures[0].Height)
throw new Exception("Invalid size");
return textures.CombineImages(ImageLayoutDirection.Vertical);
return textures.Combine(ImageLayoutDirection.Vertical);
}
}
}

View File

@@ -22,7 +22,7 @@ namespace PckStudio.Internal
Profiler.Configure(Debug.Listeners[0]);
Profiler.Start();
{
_entityImages ??= Resources.entities_sheet.CreateImageList(32).ToArray();
_entityImages ??= Resources.entities_sheet.SplitHorizontal(32).ToArray();
DataCacher ??= new FileCacher(Program.AppDataCache);
_ = AnimationResources.JsonTileData;
_ = AnimationResources.ItemImageList;