Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGS Update (part 2) #3034

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4de75d
Drawing Raw Point (raw argb)
Szymekk44 Jun 20, 2024
f6937c9
Faster DrawRectangle
Szymekk44 Jun 20, 2024
4b3ee4d
GetRawPoint & Basic GetImage
Szymekk44 Jun 20, 2024
e47e504
Finished GetRawColor and faster SVGAII GetImage
Szymekk44 Jun 20, 2024
5d9e075
VBE DrawImage change and added CroppedDrawImage
Szymekk44 Jun 20, 2024
2feb8c1
Merge branch 'CosmosOS:master' into master
Szymekk44 Jun 20, 2024
dda9df1
More summaries, alpha rectangles
Szymekk44 Jul 8, 2024
7bad71f
Merge branch 'master' into master
MishaProductions Jul 10, 2024
289270e
added preventOffBoundPixels in summary
Szymekk44 Jul 12, 2024
a3540b0
Merge branch 'master' of https://github.com/SzymekkYT/Cosmos
Szymekk44 Jul 12, 2024
f064006
Fixed VBE getimage()
Szymekk44 Jul 28, 2024
2036880
Faster VBE GetImage
Szymekk44 Jul 29, 2024
f1bedae
Fixed SVGAII image drawing (x and y < 0)
Szymekk44 Jul 29, 2024
d290822
Merge branch 'master' into master
MishaProductions Aug 9, 2024
6f38e13
New DrawArray methods, VBE bugfix
Szymekk44 Aug 9, 2024
da5e7ac
Small VBE bugfix
Szymekk44 Aug 12, 2024
b00577e
Added PCIE
Samma2009 Aug 13, 2024
8d6fa08
Update PCIExpress.cs
Samma2009 Aug 13, 2024
c5b44ce
Delete source/Cosmos.Debug.Kernel.Plugs.Asm/packages.lock.json
Samma2009 Aug 13, 2024
a770c34
fix power stuff
Samma2009 Aug 13, 2024
155b893
change of comments
Samma2009 Aug 13, 2024
f047cd9
Merge branch 'master' of https://github.com/SzymekkYT/Cosmos
Samma2009 Aug 13, 2024
98406c5
Fixed namespaceing
Samma2009 Aug 13, 2024
01342ae
Update PCIExpress.cs
Samma2009 Aug 13, 2024
7f19fbd
Merge branch 'master' into master
Szymekk44 Aug 16, 2024
d8f0aad
Add files via upload
Samma2009 Aug 16, 2024
d117063
Update packages.lock.json
Samma2009 Aug 16, 2024
98bb00f
Update packages.lock.json
Samma2009 Aug 16, 2024
3375aab
Update packages.lock.json
Samma2009 Aug 16, 2024
ac464df
Update packages.lock.json
Samma2009 Aug 16, 2024
b84f8a4
Graphics drivers are public, FileSystemType enum
Szymekk44 Sep 21, 2024
e80d1e0
Graphics drivers are public, FilsSystemType enum
Szymekk44 Sep 21, 2024
e0e7f0b
Merge pull request #1 from Szymekk44/CGE-Update
Szymekk44 Sep 21, 2024
e58fdc5
Merge pull request #2 from Szymekk44/CGE-Update2
Szymekk44 Sep 21, 2024
fb59494
Disk format - removed FIleTypeFormat enum
Szymekk44 Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions source/Cosmos.Core/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,38 @@ public unsafe void Copy(ManagedMemoryBlock block)
MemoryOperations.Copy(xDest, aDataPtr, (int)block.Size);
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Copies a specified number of integers from the memory block into an integer array.
/// </summary>
/// <param name="aByteOffset">The byte offset in the memory block from where the copy starts.</param>
/// <param name="aData">The integer array where the data will be copied to.</param>
/// <param name="aIndex">The starting index in the destination integer array.</param>
/// <param name="aCount">The number of integers to copy.</param>
public unsafe void Get(int aByteOffset, int[] aData, int aIndex, int aCount)
{
int* xSource = (int*)(Base + aByteOffset);
fixed (int* aDataPtr = aData)
{
MemoryOperations.Copy(aDataPtr + aIndex, xSource, aCount);
}
}

/// <summary>
/// Copies a specified number of bytes from the memory block into an array.
/// </summary>
/// <param name="aByteOffset">The byte offset in the memory block from where the copy starts.</param>
/// <param name="aData">The array where the data will be copied to.</param>
/// <param name="aIndex">The starting index in the destination array.</param>
/// <param name="aCount">The number of bytes to copy.</param>
public unsafe void Get(int aByteOffset, byte[] aData, int aIndex, int aCount)
{
byte* xSource = (byte*)(Base + aByteOffset);
fixed (byte* aDataPtr = aData)
{
MemoryOperations.Copy(aDataPtr + aIndex, xSource, aCount);
}
}

/// <summary>
/// Move bytes array down the memory block.
/// </summary>
Expand Down
98 changes: 66 additions & 32 deletions source/Cosmos.System2/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public virtual void Clear(Color color)
/// <param name="y">The Y coordinate.</param>
public abstract void DrawPoint(Color color, int x, int y);

/// <summary>
/// Sets the pixel at the given coordinates to the specified <paramref name="color"/>. without ToArgb()
/// </summary>
/// <param name="color">The color to draw with (raw argb).</param>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public abstract void DrawRawPoint(uint color, int x, int y);

/// <summary>
/// The name of the Canvas implementation.
/// </summary>
Expand All @@ -117,6 +125,13 @@ public virtual void Clear(Color color)
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public abstract Color GetPointColor(int x, int y);

/// <summary>
/// Gets the color of the pixel at the given coordinates in ARGB.
/// </summary>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public abstract int GetRawPointColor(int x, int y);
/// <summary>
/// Gets the index of the pixel at the given coordinates.
/// </summary>
Expand Down Expand Up @@ -485,40 +500,17 @@ public virtual void DrawSquare(Color color, int x, int y, int size)
/// <param name="height">The height of the rectangle.</param>
public virtual void DrawRectangle(Color color, int x, int y, int width, int height)
{
/*
* we must draw four lines connecting any vertex of our rectangle to do this we first obtain the position of these
* vertex (we call these vertexes A, B, C, D as for geometric convention)
*/

/* The check of the validity of x and y are done in DrawLine() */

/* The vertex A is where x,y are */
int xa = x;
int ya = y;

/* The vertex B has the same y coordinate of A but x is moved of width pixels */
int xb = x + width;
int yb = y;
// Draw top edge from (x, y) to (x + width, y)
DrawLine(color, x, y, x + width, y);

/* The vertex C has the same x coordiate of A but this time is y that is moved of height pixels */
int xc = x;
int yc = y + height;
// Draw left edge from (x, y) to (x, y + height)
DrawLine(color, x, y, x, y + height);

/* The Vertex D has x moved of width pixels and y moved of height pixels */
int xd = x + width;
int yd = y + height;
// Draw bottom edge from (x, y + height) to (x + width, y + height)
DrawLine(color, x, y + height, x + width, y + height);

/* Draw a line betwen A and B */
DrawLine(color, xa, ya, xb, yb);

/* Draw a line between A and C */
DrawLine(color, xa, ya, xc, yc);

/* Draw a line between B and D */
DrawLine(color, xb, yb, xd, yd);

/* Draw a line between C and D */
DrawLine(color, xc, yc, xd, yd);
// Draw right edge from (x + width, y) to (x + width, y + height)
DrawLine(color, x + width, y, x + width, y + height);
}

/// <summary>
Expand All @@ -529,6 +521,7 @@ public virtual void DrawRectangle(Color color, int x, int y, int width, int heig
/// <param name="yStart">The starting point Y coordinate.</param>
/// <param name="width">The width of the rectangle.</param>
/// <param name="height">The height of the rectangle.</param>
/// <param name="preventOffBoundPixels">Prevents drawing outside the bounds of the canvas.</param>
public virtual void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true)
{
if (height == -1)
Expand Down Expand Up @@ -569,6 +562,7 @@ public virtual void DrawTriangle(Color color, int v1x, int v1y, int v2x, int v2y
/// <param name="image">The image to draw.</param>
/// <param name="x">The origin X coordinate.</param>
/// <param name="y">The origin Y coordinate.</param>
/// <param name="preventOffBoundPixels">Prevents drawing outside the bounds of the canvas.</param>
public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPixels = true)
{
Color color;
Expand Down Expand Up @@ -598,6 +592,44 @@ public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPix
}
}

/// <summary>
/// Draws the given image at the specified coordinates, cropped to maxWidth and maxHeight
/// </summary>
/// <param name="image">The image to draw.</param>
/// <param name="x">The origin X coordinate.</param>
/// <param name="y">The origin Y coordinate.</param>
/// <param name="maxWidth">Max image width to display</param>
/// <param name="maxHeight">Max image height to display</param>
public virtual void CroppedDrawImage(Image image, int x, int y, int maxWidth, int maxHeight)
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this left empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know tho i could fix it

}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Retrieves a specified region of the canvas as a bitmap.
/// </summary>
/// <param name="x">The x-coordinate of the top-left corner of the region.</param>
/// <param name="y">The y-coordinate of the top-left corner of the region.</param>
/// <param name="width">The width of the region to retrieve.</param>
/// <param name="height">The height of the region to retrieve.</param>
/// <returns>A bitmap containing the specified region of the canvas.</returns>
public virtual Bitmap GetImage(int x, int y, int width, int height)
{
Bitmap bitmap = new Bitmap((uint)x, (uint)y, ColorDepth.ColorDepth32);

for (int posy = y, desty = 0; posy < y + y; posy++, desty++)
for (int posx = x, destx = 0; posx < x + x; posx++, destx++)
bitmap.RawData[desty * x + destx] = GetRawPointColor(posx, posy);
return bitmap;
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Scales an image to the specified new width and height.
/// </summary>
/// <param name="image">The image to be scaled.</param>
/// <param name="newWidth">The width of the scaled image.</param>
/// <param name="newHeight">The height of the scaled image.</param>
/// <returns>An array of integers representing the scaled image's pixel data. (Raw bitmap data)</returns>
static int[] ScaleImage(Image image, int newWidth, int newHeight)
{
int[] pixels = image.RawData;
Expand Down Expand Up @@ -629,6 +661,7 @@ static int[] ScaleImage(Image image, int newWidth, int newHeight)
/// <param name="y">The Y coordinate.</param>
/// <param name="w">The desired width to scale the image to before drawing.</param>
/// <param name="h">The desired height to scale the image to before drawing</param>
/// <param name="preventOffBoundPixels">Prevents drawing outside the bounds of the canvas.</param>
public virtual void DrawImage(Image image, int x, int y, int w, int h, bool preventOffBoundPixels = true)
{
Color color;
Expand Down Expand Up @@ -666,7 +699,8 @@ public virtual void DrawImage(Image image, int x, int y, int w, int h, bool prev
/// <param name="image">The image to draw.</param>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
public void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels = true)
/// <param name="preventOffBoundPixels">Prevents drawing outside the bounds of the canvas.</param>
public virtual void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels = true)
{
Color color;
if (preventOffBoundPixels)
Expand Down
102 changes: 102 additions & 0 deletions source/Cosmos.System2/Graphics/SVGAIICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public override void DrawPoint(Color color, int x, int y)
driver.SetPixel((uint)x, (uint)y, (uint)color.ToArgb());
}

public override void DrawRawPoint(uint color, int x, int y)
{
driver.SetPixel((uint)x, (uint)y, color);
}

public override void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true)
{
var argb = color.ToArgb();
Expand All @@ -97,6 +102,54 @@ public override void DrawFilledRectangle(Color color, int xStart, int yStart, in
}
}

public override void DrawRectangle(Color color, int x, int y, int width, int height)
{
if(color.A < 255)
{
// Draw top edge from (x, y) to (x + width, y)
DrawLine(color, x, y, x + width, y);

// Draw left edge from (x, y) to (x, y + height)
DrawLine(color, x, y, x, y + height);

// Draw bottom edge from (x, y + height) to (x + width, y + height)
DrawLine(color, x, y + height, x + width, y + height);

// Draw right edge from (x + width, y) to (x + width, y + height)
DrawLine(color, x + width, y, x + width, y + height);
}
else
{
int rawColor = color.ToArgb();

/* Draw the top edge (A to B) */
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, y);
}

/* Draw the bottom edge (C to D) */
int newY = y + height;
for (int posX = x; posX < x + width; posX++)
{
DrawRawPoint((uint)rawColor, posX, newY);
}

/* Draw the left edge (A to C) */
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, x, posY);
}

/* Draw the right edge (B to D) */
int newX = x + width;
for (int posY = y; posY < y + height; posY++)
{
DrawRawPoint((uint)rawColor, newX, posY);
}
}
}

//public override IReadOnlyList<Mode> AvailableModes { get; } = new List<Mode>
/// <summary>
/// Available SVGA 2 supported video modes.
Expand Down Expand Up @@ -315,6 +368,11 @@ public override Color GetPointColor(int x, int y)
return Color.FromArgb((int)driver.GetPixel((uint)x, (uint)y));
}

public override int GetRawPointColor(int x, int y)
{
return (int)driver.GetPixel((uint)x, (uint)y);
}

public override void Display()
{
driver.DoubleBufferUpdate();
Expand Down Expand Up @@ -375,5 +433,49 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi
}
}
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Draws a cropped image on the canvas at the specified position with maximum width and height.
/// </summary>
/// <param name="image">The image to be drawn.</param>
/// <param name="x">The x-coordinate of the top-left corner where the image will be drawn.</param>
/// <param name="y">The y-coordinate of the top-left corner where the image will be drawn.</param>
/// <param name="maxWidth">The maximum width of the cropped area.</param>
/// <param name="maxHeight">The maximum height of the cropped area.</param>
public override void CroppedDrawImage(Image image, int x, int y, int maxWidth, int maxHeight)
{
var width = maxWidth;
var height = maxHeight;
var frameSize = (int)driver.FrameSize;
var data = image.RawData;
for (int i = 0; i < height; i++)
{
driver.videoMemory.Copy(GetPointOffset(x, y + i) + frameSize, data, i * width, width);
}
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Retrieves a specified region of the canvas as a bitmap.
/// </summary>
/// <param name="x">The x-coordinate of the top-left corner of the region.</param>
/// <param name="y">The y-coordinate of the top-left corner of the region.</param>
/// <param name="width">The width of the region to retrieve.</param>
/// <param name="height">The height of the region to retrieve.</param>
/// <returns>A bitmap containing the specified region of the canvas.</returns>
public override Bitmap GetImage(int x, int y, int width, int height)
{
var frameSize = (int)driver.FrameSize;
int[] buffer = new int[width];
int[] all = new int[width * height];
for (int i = 0; i < height; i++)
{
driver.videoMemory.Get(GetPointOffset(x, y + i) + frameSize, buffer, 0, width);
buffer.CopyTo(all, width * i);
}
Bitmap toReturn = new Bitmap((uint)width, (uint)height, ColorDepth.ColorDepth32);
toReturn.RawData = all;

return toReturn;
}
}
}
Loading
Loading