Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
382 changes: 382 additions & 0 deletions Raylib-cs.Extensions/ImageExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,382 @@
using System.Numerics;

namespace Raylib_cs.Extensions;

public static class ImageExtensions
{
public static bool IsValid(this Image image)
{
return Raylib.IsImageValid(image);
}

public static void Unload(this Image image)
{
Raylib.UnloadImage(image);
}

public static CBool Export(this Image image, string fileName)
{
return Raylib.ExportImage(image, fileName);
}

public static unsafe byte[] ExportToMemory(this Image image, string fileType)
{
int fileSize = 0;
using AnsiBuffer str1 = fileType.ToAnsiBuffer();
byte* imgData = Raylib.ExportImageToMemory(image, str1.AsPointer(), &fileSize);
byte[] byteArray = new byte[fileSize];
for (int i = 0; i < fileSize; i++)
{
byteArray[i] = imgData[i];
}
Raylib.MemFree(imgData);
return byteArray;
}

public static CBool ExportAsCode(this Image image, string fileName)
{
return Raylib.ExportImageAsCode(image, fileName);
}

public static void Format(this ref Image image, PixelFormat format)
{
Raylib.ImageFormat(ref image, format);
}

public static void ToPOT(this ref Image image, Color colorFill)
{
Raylib.ImageToPOT(ref image, colorFill);
}

public static void Crop(this ref Image image, Rectangle area)
{
Raylib.ImageCrop(ref image, area);
}

public static void AlphaCrop(this ref Image image, float threshold)
{
Raylib.ImageAlphaCrop(ref image, threshold);
}

public static void AlphaClear(this ref Image image, Color color, float threshold)
{
Raylib.ImageAlphaClear(ref image, color, threshold);
}

public static void AlphaMask(this ref Image image, Image alphaMask)
{
Raylib.ImageAlphaMask(ref image, alphaMask);
}

public static void AlphaPremultiply(this ref Image image)
{
Raylib.ImageAlphaPremultiply(ref image);
}

public static void BlurGaussian(this ref Image image, int blurSize)
{
Raylib.ImageBlurGaussian(ref image, blurSize);
}

public static void KernelConvolution(this ref Image image, float[] kernel)
{
Raylib.ImageKernelConvolution(ref image, kernel);
}

public static void Resize(this ref Image image, int newWidth, int newHeight)
{
Raylib.ImageResize(ref image, newWidth, newHeight);
}

public static void Resize(this ref Image image, Vector2 newDimensions)
{
Raylib.ImageResize(ref image, (int)newDimensions.X, (int)newDimensions.Y);
}

public static void ResizeNN(this ref Image image, int newWidth, int newHeight)
{
Raylib.ImageResizeNN(ref image, newWidth, newHeight);
}

public static void ResizeNN(this ref Image image, Vector2 newDimensions)
{
Raylib.ImageResizeNN(ref image, (int)newDimensions.X, (int)newDimensions.Y);
}

public static void ResizeCanvas(this ref Image image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill)
{
Raylib.ImageResizeCanvas(ref image, newWidth, newHeight, offsetX, offsetY, fill);
}

public static void ResizeCanvas(this ref Image image, Vector2 newDimensions, int offsetX, int offsetY, Color fill)
{
Raylib.ImageResizeCanvas(ref image, (int)newDimensions.X, (int)newDimensions.Y, offsetX, offsetY, fill);
}

public static void ResizeCanvas(this ref Image image, int newWidth, int newHeight, Vector2 offset, Color fill)
{
Raylib.ImageResizeCanvas(ref image, newWidth, newHeight, (int)offset.X, (int)offset.Y, fill);
}

public static void ResizeCanvas(this ref Image image, Vector2 newDimensions, Vector2 offset, Color fill)
{
Raylib.ImageResizeCanvas(ref image, (int)newDimensions.X, (int)newDimensions.Y, (int)offset.X, (int)offset.Y, fill);
}

public static void Mipmaps(this ref Image image)
{
Raylib.ImageMipmaps(ref image);
}

public static void Dither(this ref Image image, int rBpp, int gBpp, int bBpp, int aBpp)
{
Raylib.ImageDither(ref image, rBpp, gBpp, bBpp, aBpp);
}

public static void FlipVertical(this ref Image image)
{
Raylib.ImageFlipVertical(ref image);
}

public static void FlipHorizontal(this ref Image image)
{
Raylib.ImageFlipHorizontal(ref image);
}

public static void Rotate(this ref Image image, int degrees)
{
Raylib.ImageRotate(ref image, degrees);
}

public static void RotateCW(this ref Image image)
{
Raylib.ImageRotateCW(ref image);
}

public static void RotateCCW(this ref Image image)
{
Raylib.ImageRotateCCW(ref image);
}

public static void ColorTint(this ref Image image, Color color)
{
Raylib.ImageColorTint(ref image, color);
}

public static void ColorInvert(this ref Image image)
{
Raylib.ImageColorInvert(ref image);
}

public static void ColorGrayscale(this ref Image image)
{
Raylib.ImageColorGrayscale(ref image);
}

public static void ColorContrast(this ref Image image, float contrast)
{
Raylib.ImageColorContrast(ref image, contrast);
}

public static void ColorBrightness(this ref Image image, int brightness)
{
Raylib.ImageColorBrightness(ref image, brightness);
}

public static void ColorReplace(this ref Image image, Color color, Color replace)
{
Raylib.ImageColorReplace(ref image, color, replace);
}

public static Rectangle GetAlphaBorder(this Image image, float threshold)
{
return Raylib.GetImageAlphaBorder(image, threshold);
}

public static Color GetColor(this Image image, int x, int y)
{
return Raylib.GetImageColor(image, x, y);
}

public static Color GetColor(this Image image, Vector2 pixelPosition)
{
return Raylib.GetImageColor(image, (int)pixelPosition.X, (int)pixelPosition.Y);
}


public static void ClearBackground(this ref Image image, Color color)
{
Raylib.ImageClearBackground(ref image, color);
}

public static void DrawPixel(this ref Image image, int x, int y, Color color)
{
Raylib.ImageDrawPixel(ref image, x, y, color);
}

public static void DrawPixel(this ref Image image, Vector2 position, Color color)
{
Raylib.ImageDrawPixelV(ref image, position, color);
}

public static void DrawLine(this ref Image image, int startX, int startY, int endX, int endY, Color color)
{
Raylib.ImageDrawLine(ref image, startX, startY, endX, endY, color);
}

public static void DrawLine(this ref Image image, Vector2 start, int endX, int endY, Color color)
{
Raylib.ImageDrawLine(ref image, (int)start.X, (int)start.Y, endX, endY, color);
}

public static void DrawLine(this ref Image image, int startX, int startY, Vector2 end, Color color)
{
Raylib.ImageDrawLine(ref image, startX, startY, (int)end.X, (int)end.Y, color);
}

public static void DrawLine(this ref Image image, Vector2 start, Vector2 end, Color color)
{
Raylib.ImageDrawLineV(ref image, start, end, color);
}

public static void DrawLineEx(this ref Image image, int startX, int startY, int endX, int endY, int thick, Color color)
{
Raylib.ImageDrawLineEx(ref image, new Vector2(startX, startY), new Vector2(endX, endY), thick, color);
}

public static void DrawLineEx(this ref Image image, Vector2 start, int endX, int endY, int thick, Color color)
{
Raylib.ImageDrawLineEx(ref image, start, new Vector2(endX, endY), thick, color);
}

public static void DrawLineEx(this ref Image image, int startX, int startY, Vector2 end, int thick, Color color)
{
Raylib.ImageDrawLineEx(ref image, new Vector2(startX, startY), end, thick, color);
}

public static void DrawLineEx(this ref Image image, Vector2 start, Vector2 end, int thick, Color color)
{
Raylib.ImageDrawLineEx(ref image, start, end, thick, color);
}

public static void DrawCircle(this ref Image image, int centerX, int centerY, int radius, Color color)
{
Raylib.ImageDrawCircle(ref image, centerX, centerY, radius, color);
}

public static void DrawCircle(this ref Image image, Vector2 center, int radius, Color color)
{
Raylib.ImageDrawCircleV(ref image, center, radius, color);
}

public static unsafe void DrawCircleLines(this ref Image image, int centerX, int centerY, int radius, Color color)
{
fixed (Image* dst = &image)
{
Raylib.ImageDrawCircleLines(dst, centerX, centerY, radius, color);
}
}

public static unsafe void DrawCircleLines(this ref Image image, Vector2 center, int radius, Color color)
{
fixed (Image* dst = &image)
{
Raylib.ImageDrawCircleLinesV(dst, center, radius, color);
}
}

public static unsafe void DrawRectangle(this ref Image image, int positionX, int positionY, int width, int height, Color color)
{
Raylib.ImageDrawRectangle(ref image, positionX, positionY, width, height, color);
}

public static unsafe void DrawRectangle(this ref Image image, Vector2 position, int width, int height, Color color)
{
Raylib.ImageDrawRectangleV(ref image, position, new Vector2(width, height), color);
}

public static unsafe void DrawRectangle(this ref Image image, int positionX, int positionY, Vector2 size, Color color)
{
Raylib.ImageDrawRectangleV(ref image, new Vector2(positionX, positionY), size, color);
}

public static unsafe void DrawRectangle(this ref Image image, Vector2 position, Vector2 size, Color color)
{
Raylib.ImageDrawRectangleV(ref image, position, size, color);
}

public static unsafe void DrawRectangle(this ref Image image, Rectangle rectangle, Color color)
{
Raylib.ImageDrawRectangleRec(ref image, rectangle, color);
}

public static unsafe void DrawRectangleLines(this ref Image image, int positionX, int positionY, int width, int height, int thick, Color color)
{
Raylib.ImageDrawRectangleLines(ref image, new Rectangle(positionX, positionY, width, height), thick, color);
}

public static unsafe void DrawRectangleLines(this ref Image image, Vector2 position, int width, int height, int thick, Color color)
{
Raylib.ImageDrawRectangleLines(ref image, new Rectangle(position, width, height), thick, color);
}

public static unsafe void DrawRectangleLines(this ref Image image, int positionX, int positionY, Vector2 size, int thick, Color color)
{
Raylib.ImageDrawRectangleLines(ref image, new Rectangle(positionX, positionY, size), thick, color);
}

public static unsafe void DrawRectangleLines(this ref Image image, Vector2 position, Vector2 size, int thick, Color color)
{
Raylib.ImageDrawRectangleLines(ref image, new Rectangle(position, size), thick, color);
}

public static unsafe void DrawRectangleLines(this ref Image image, Rectangle rectangle, int thick, Color color)
{
Raylib.ImageDrawRectangleLines(ref image, rectangle, thick, color);
}

public static void DrawTriangle(this ref Image image, Vector2 v1, Vector2 v2, Vector2 v3, Color color)
{
Raylib.ImageDrawTriangle(ref image, v1, v2, v3, color);
}

public static void DrawTriangleEx(this ref Image image, Vector2 v1, Vector2 v2, Vector2 v3, Color c1, Color c2, Color c3)
{
Raylib.ImageDrawTriangleEx(ref image, v1, v2, v3, c1, c2, c3);
}

public static void DrawTriangleLines(this ref Image image, Vector2 v1, Vector2 v2, Vector2 v3, Color color)
{
Raylib.ImageDrawTriangleLines(ref image, v1, v2, v3, color);
}

public static void DrawTriangleFan(this ref Image image, Vector2[] points, Color color)
{
Raylib.ImageDrawTriangleFan(ref image, points, color);
}

public static void DrawTriangleStrip(this ref Image image, Vector2[] points, Color color)
{
Raylib.ImageDrawTriangleStrip(ref image, points, color);
}

public static void Draw(this ref Image image, Image source, Rectangle sourceRec, Rectangle dstRec, Color tint)
{
Raylib.ImageDraw(ref image, source, sourceRec, dstRec, tint);
}

public static void DrawText(this ref Image image, string text, int positionX, int positionY, int fontSize, Color color)
{
Raylib.ImageDrawText(ref image, text, positionX, positionY, fontSize, color);
}

public static void DrawText(this ref Image image, string text, Vector2 position, int fontSize, Color color)
{
Raylib.ImageDrawText(ref image, text, (int)position.X, (int)position.Y, fontSize, color);
}

public static void DrawTextEx(this ref Image image, Font font, string text, Vector2 position, int fontSize, int spacing, Color tint)
{
Raylib.ImageDrawTextEx(ref image, font, text, position, fontSize, spacing, tint);
}
}
5 changes: 3 additions & 2 deletions Raylib-cs.Extensions/Raylib-cs.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<RootNamespace>Raylib_cs.Extensions</RootNamespace>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Raylib-cs" Version="7.0.1" />
<ItemGroup>
<PackageReference Include="Raylib-cs" Version="7.0.1" />
</ItemGroup>

</Project>
Loading