Skip to content

Commit

Permalink
preventOffBoundPixels bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymekk44 committed May 11, 2024
1 parent 111b703 commit f85b607
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
12 changes: 5 additions & 7 deletions source/Cosmos.System2/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,11 @@ public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPix
}
else
{
var Width = image.Width;
for (int xi = 0; xi < Width; xi++)
for (int xi = 0; xi < image.Width; xi++)
{
for (int yi = 0; yi < image.Height; yi++)
{
color = Color.FromArgb(image.RawData[xi + (yi * Width)]);
color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]);
DrawPoint(color, x + xi, y + yi);
}
}
Expand Down Expand Up @@ -681,12 +680,11 @@ public void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels
}
else
{
var Width = image.Width;
for (int xi = 0; xi < Width; xi++)
for (int xi = 0; xi < image.Width; xi++)
{
for (int yi = 0; yi < image.Height; yi++)
{
color = Color.FromArgb(image.RawData[xi + (yi * Width)]);
color = Color.FromArgb(image.RawData[xi + (yi * image.Width)]);
DrawPoint(color, x + xi, y + yi);
}
}
Expand Down Expand Up @@ -892,4 +890,4 @@ public static Color AlphaBlend(Color to, Color from, byte alpha)
return Color.FromArgb(R, G, B);
}
}
}
}
12 changes: 6 additions & 6 deletions source/Cosmos.System2/Graphics/SVGAIICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ public override void DrawFilledRectangle(Color color, int xStart, int yStart, in
{
var argb = color.ToArgb();
var frameSize = (int)driver.FrameSize;
width = Math.Min(width, (int)mode.Width - xStart);
height = Math.Min(height, (int)mode.Height - yStart);

// For now write directly into video memory, once _xSVGADriver.Fill will be faster it will have to be changed
for (int i = yStart; i < yStart + height; i++)
{
driver.videoMemory.Fill(GetPointOffset(xStart, i) + frameSize, width, argb);
driver.videoMemory.Fill(GetPointOffset(xStart, i) + (int)frameSize, width, argb);
}
}

Expand Down Expand Up @@ -355,8 +354,9 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi
var data = image.RawData;
if(preventOffBoundPixels)
{
var maxWidth = Math.Min(width, width - x);
var maxHeight = Math.Min(height, height - y);
var maxWidth = Math.Min(width, (int)mode.Width - x);
var maxHeight = Math.Min(height, (int)mode.Height - y);

for (int i = 0; i < maxHeight; i++)
{
driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, maxWidth);
Expand All @@ -371,4 +371,4 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi
}
}
}
}
}
5 changes: 3 additions & 2 deletions source/Cosmos.System2/Graphics/VBECanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,20 @@ public override void DrawImage(Image aImage, int aX, int aY, bool preventOffBoun
var xBitmap = aImage.RawData;
var xWidth = (int)aImage.Width;
var xHeight = (int)aImage.Height;
int xOffset = aY * (int)Mode.Width + aX;
if (preventOffBoundPixels)
{
var maxWidth = Math.Min(xWidth, (int)mode.Width - aX);
var maxHeight = Math.Min(xHeight, (int)mode.Height - aY);
int xOffset = aY * (int)Mode.Width + aX;
for (int i = 0; i < maxHeight; i++)
{
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, maxWidth);
}
}
else
{
for (int i = 0; i < xHeight; i++)
int xOffset = aY * xHeight + aX;
for (int i = 0; i < Mode.Height; i++)
{
driver.CopyVRAM((i * (int)Mode.Width) + xOffset, xBitmap, i * xWidth, xWidth);
}
Expand Down

0 comments on commit f85b607

Please sign in to comment.