Initial commit
This commit is contained in:
commit
0f86b0434b
38 changed files with 2370 additions and 0 deletions
62
LibDgf.Graphics/Aqualead/Image/Conversion/PngConverter.cs
Normal file
62
LibDgf.Graphics/Aqualead/Image/Conversion/PngConverter.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using LibDgf.Aqualead.Image;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LibDgf.Aqualead.Image.Conversion
|
||||
{
|
||||
public class PngConverter : IAlImageConverter
|
||||
{
|
||||
public string FileExtension => ".png";
|
||||
|
||||
public void ConvertFromAl(AlImage image, Stream destStream)
|
||||
{
|
||||
// Only grab the first mip
|
||||
var pixels = image.Mipmaps[0];
|
||||
using (MemoryStream ms = new MemoryStream(pixels))
|
||||
{
|
||||
BinaryReader br = new BinaryReader(ms);
|
||||
using (var img = ConvertBgra32(br, (int)image.Width, (int)image.Height))
|
||||
{
|
||||
img.SaveAsPng(destStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanConvert(string pixelFormat)
|
||||
{
|
||||
return pixelFormat == "BGRA";
|
||||
}
|
||||
|
||||
public static Image<Bgra32> ConvertBgra32(BinaryReader br, int width, int height)
|
||||
{
|
||||
Image<Bgra32> img = new Image<Bgra32>(width, height);
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
var row = img.GetPixelRowSpan(y);
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
byte b = br.ReadByte();
|
||||
byte g = br.ReadByte();
|
||||
byte r = br.ReadByte();
|
||||
byte a = br.ReadByte();
|
||||
row[x] = new Bgra32(r, g, b, a);
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public void ConvertFromAlAlt(AlImage image, Stream destStream)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public bool HasAlternativeFile(AlImage image)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue