Compare commits

...

3 Commits

Author SHA1 Message Date
Anna c0604b2959
feat: draw dots 2024-02-22 00:32:04 -05:00
Anna 0e763b9c0e
chore: remove unused imports 2024-02-22 00:29:07 -05:00
Anna a7bc19b380
fix: calculate stride correctly 2024-02-22 00:28:49 -05:00
2 changed files with 45 additions and 32 deletions

View File

@ -45,8 +45,10 @@ internal class Viewer : IDrawable {
this.Image?.Dispose();
}
public DrawStatus Draw() {
if (!this._visible) {
public DrawStatus Draw()
{
if (!this._visible)
{
return DrawStatus.Finished;
}
@ -54,7 +56,8 @@ internal class Viewer : IDrawable {
using var popId = new OnDispose(ImGui.PopID);
using var end = new OnDispose(ImGui.End);
if (!ImGui.Begin($"View {Path.GetFileName(this.ImagePath)}", ref this._visible, ImGuiWindowFlags.NoSavedSettings)) {
if (!ImGui.Begin($"View {Path.GetFileName(this.ImagePath)}", ref this._visible, ImGuiWindowFlags.NoSavedSettings))
{
return DrawStatus.Continuing;
}
@ -63,7 +66,8 @@ internal class Viewer : IDrawable {
ImGui.SetWindowSize(viewportSize * new Vector2(0.20f), ImGuiCond.Appearing);
if (this.Error != null) {
if (this.Error != null)
{
ImGuiHelpers.CenteredText("An error ocurred loading the image.");
ImGui.PushFont(UiBuilder.MonoFont);
@ -72,35 +76,46 @@ internal class Viewer : IDrawable {
ImGui.TextUnformatted(this.Error.Message);
}
if (this.Image != null) {
var beforeImage = ImGui.GetCursorScreenPos();
var avail = ImGui.GetContentRegionAvail();
var imageSize = this.Image.Size;
if (this.Image == null) {
return DrawStatus.Continuing;
}
var constrainedX = avail.X < imageSize.X;
var constrainedY = avail.Y < imageSize.Y;
var beforeImage = ImGui.GetCursorScreenPos();
var avail = ImGui.GetContentRegionAvail();
var imageSize = this.Image.Size;
var sizeToUse = imageSize;
if (constrainedX || constrainedY) {
// var dividend = imageSize / avail;
// var inv = Vector2.One / dividend;
// scale the image based on the more-constrained dimension
// var ratio = dividend.X > dividend.Y
// ? inv.X // X is more constrained
// : inv.Y; // Y is more constrained
var constrainedX = avail.X < imageSize.X;
var constrainedY = avail.Y < imageSize.Y;
var ratio = 1f;
var dividend = avail / imageSize;
// scale the image based on the more-constrained dimension
var ratio = dividend.Y > dividend.X
? dividend.X // X is more constrained
: dividend.Y; // Y is more constrained
sizeToUse = new Vector2(
imageSize.X * ratio,
imageSize.Y * ratio
);
}
var sizeToUse = imageSize;
if (constrainedX || constrainedY) {
// var dividend = imageSize / avail;
// var inv = Vector2.One / dividend;
// scale the image based on the more-constrained dimension
// var ratio = dividend.X > dividend.Y
// ? inv.X // X is more constrained
// : inv.Y; // Y is more constrained
ImGui.Image(this.Image.ImGuiHandle, sizeToUse);
var dividend = avail / imageSize;
// scale the image based on the more-constrained dimension
ratio = dividend.Y > dividend.X
? dividend.X // X is more constrained
: dividend.Y; // Y is more constrained
sizeToUse = new Vector2(
imageSize.X * ratio,
imageSize.Y * ratio
);
}
ImGui.Image(this.Image.ImGuiHandle, sizeToUse);
if (this.DotPosition is { } pos) {
var scaledPos = pos * ratio;
var posCoord = beforeImage + scaledPos;
ImGui.GetWindowDrawList().AddCircleFilled(posCoord, 6 * ImGuiHelpers.GlobalScale, 0x000000FF);
ImGui.GetWindowDrawList().AddCircleFilled(posCoord, 4 * ImGuiHelpers.GlobalScale, 0xFFFFFFFF);
}
return DrawStatus.Continuing;

View File

@ -1,7 +1,5 @@
using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Memory;
using WebP.Net;
using WebP.Net.Natives;
using WebP.Net.Natives.Enums;
using WebP.Net.Natives.Structs;
@ -34,7 +32,7 @@ internal static class WebPHelper {
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
decoderConfig.output.isExternalMemory = 1;
decoderConfig.output.u.Rgba.size = (nuint) rgba.Length;
decoderConfig.output.u.Rgba.stride = height * 4;
decoderConfig.output.u.Rgba.stride = width * 4;
fixed (byte* rgbaPtr = rgba) {
decoderConfig.output.u.Rgba.rgba = (nint) rgbaPtr;
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);