mirror of
https://github.com/Syping/ragephoto-cli.git
synced 2025-12-04 16:51:48 +01:00
impl. image processing and rename update-sign option to update-json
This commit is contained in:
parent
9a70c45c7a
commit
89b37b6ede
8 changed files with 232 additions and 390 deletions
42
Jpeg.cs
Normal file
42
Jpeg.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
namespace RagePhoto.Cli;
|
||||
|
||||
internal class Jpeg {
|
||||
|
||||
internal static Byte[] GetEmptyJpeg(PhotoFormat format, out Size size) {
|
||||
size = format == PhotoFormat.GTA5 ? new(960, 536) : new(1920, 1080);
|
||||
using Image<Rgb24> image = new(size.Width, size.Height);
|
||||
image.ProcessPixelRows(static pixelAccessor => {
|
||||
for (Int32 y = 0; y < pixelAccessor.Height; y++) {
|
||||
Span<Rgb24> pixelRow = pixelAccessor.GetRowSpan(y);
|
||||
for (Int32 x = 0; x < pixelRow.Length; x++) {
|
||||
pixelRow[x] = Color.Black;
|
||||
}
|
||||
}
|
||||
});
|
||||
using MemoryStream output = new();
|
||||
image.SaveAsJpeg(output, new() {
|
||||
Quality = 100,
|
||||
ColorType = JpegEncodingColor.YCbCrRatio444
|
||||
});
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
internal static Byte[] GetJpeg(Stream stream, out Size size) {
|
||||
using Image image = Image.Load(stream);
|
||||
size = image.Size;
|
||||
image.Metadata.ExifProfile = null;
|
||||
using MemoryStream output = new();
|
||||
image.SaveAsJpeg(output, new() {
|
||||
Quality = 100,
|
||||
ColorType = JpegEncodingColor.YCbCrRatio444
|
||||
});
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
internal static Size GetSize(ReadOnlySpan<Byte> jpeg) {
|
||||
return Image.Identify(jpeg).Size;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue