image

Image loading and manipulation for Kit using stb_image

Files

FileDescription
kit.tomlPackage manifest with metadata and dependencies
src/image.kitImage loading, pixel manipulation, and format conversion
tests/image.test.kitTests for colors, hex conversion, and error types
examples/basic.kitLoad images and create gradient fills
examples/drawing.kitDraw rectangles, lines, and checkerboard patterns
examples/filters.kitApply grayscale, invert, brightness, and resize
LICENSEMIT license file

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-image.git

Usage

import Kit.Image

License

MIT License - see LICENSE for details.

Exported Functions & Types

ImageError

Image error type with specific variants for different failure modes.

Variants

ImageLoadError {message}
ImageSaveError {message}
ImageProcessError {message}

rgba

Create a color from RGBA values.

Parameters:

  • - r - Red component (0-255)
  • - g - Green component (0-255)
  • - b - Blue component (0-255)
  • - a - Alpha/transparency component (0-255, where 255 is fully opaque)

Returns: Color record with the specified RGBA values

Int -> Int -> Int -> Int -> Color

semi-transparent-red = rgba 255 0 0 128

rgb

Create a color from RGB values with full opacity.

The alpha channel is automatically set to 255 (fully opaque).

Parameters:

  • - r - Red component (0-255)
  • - g - Green component (0-255)
  • - b - Blue component (0-255)

Returns: Color record with the specified RGB values and alpha=255

Int -> Int -> Int -> Color

purple = rgb 128 0 128

white

White color (255, 255, 255).

Color

black

Black color (0, 0, 0).

Color

red

Red color (255, 0, 0).

Color

green

Green color (0, 255, 0).

Color

blue

Blue color (0, 0, 255).

Color

yellow

Yellow color (255, 255, 0).

Color

cyan

Cyan color (0, 255, 255).

Color

magenta

Magenta color (255, 0, 255).

Color

transparent

Transparent color (0, 0, 0, 0).

Color

load

Load image from file.

String -> Result Image ImageError

load-with-channels

Load image with specific number of channels.

String -> Int -> Result Image ImageError

load-rgb

Load as RGB (3 channels).

String -> Result Image ImageError

load-rgba

Load as RGBA (4 channels).

String -> Result Image ImageError

load-grayscale

Load as grayscale (1 channel).

String -> Result Image ImageError

free

Free image memory.

Image -> Void

create

Create a new blank image.

Int -> Int -> Result Image ImageError

create-with-channels

Create with specific number of channels.

Int -> Int -> Int -> Result Image ImageError

copy

Copy an image.

Image -> Result Image ImageError

width

Get image width.

Image -> Int

height

Get image height.

Image -> Int

channels

Get image channels.

Image -> Int

in-bounds?

Check if coordinates are in bounds.

Image -> Int -> Int -> Bool

get-pixel

Get pixel color at (x, y).

Image -> Int -> Int -> Option Color

set-pixel?

Set pixel color at (x, y). Returns true if successful.

Image -> Int -> Int -> Color -> Bool

fill

Fill entire image with color.

Image -> Color -> Void

save-png

Save as PNG.

Image -> String -> Result () ImageError

save-jpg

Save as JPEG with quality (1-100).

Image -> String -> Int -> Result () ImageError

save-jpeg

Save as JPEG with default quality (90).

Image -> String -> Result () ImageError

save-bmp

Save as BMP.

Image -> String -> Result () ImageError

save-tga

Save as TGA.

Image -> String -> Result () ImageError

resize

Resize image.

Image -> Int -> Int -> Result Image ImageError

scale

Scale image by factor.

Image -> Float -> Result Image ImageError

flip-vertical

Flip image vertically (in place).

Image -> Void

flip-horizontal

Flip image horizontally (in place).

Image -> Void

draw-rect

Draw a filled rectangle.

Image -> Int -> Int -> Int -> Int -> Color -> Void

draw-line-h

Draw a horizontal line.

Image -> Int -> Int -> Int -> Color -> Void

draw-line-v

Draw a vertical line.

Image -> Int -> Int -> Int -> Color -> Void

draw-rect-outline

Draw rectangle outline.

Image -> Int -> Int -> Int -> Int -> Color -> Void

average-color

Get average color of entire image.

Image -> Color

invert

Invert colors.

Image -> Void

grayscale

Convert to grayscale.

Image -> Void

brightness

Adjust brightness (-255 to 255).

Image -> Int -> Void

info

Print image info.

Image -> Void

color-to-hex

Color to hex string.

Color -> String

hex-to-color

Parse hex color string.

String -> Option Color