polished_graphics

Crates.iopolished_graphics
lib.rspolished_graphics
version0.1.1
created_at2025-06-10 23:42:54.629375+00
updated_at2025-06-12 20:23:56.273212+00
descriptionA graphics library for the Polished OS project.
homepage
repositoryhttps://codeberg.org/ofluffydev/polished
max_upload_size
id1707858
size15,484
Kaden Frisk (ofluffydev)

documentation

README

Polished Graphics Library

This crate is part of Polished OS, an experimental operating system written in Rust. The graphics library provides low-level graphics and framebuffer routines for use in OS kernels, bootloaders, or other system software where direct framebuffer access is required.


Overview

The graphics library exposes two main modules:

  • framebuffer: Initialization and management of the framebuffer, including structures describing its memory layout, pixel format, and display properties.
  • drawing: Basic drawing routines, such as line drawing (using Bresenham's algorithm) and demo patterns, that operate directly on the framebuffer.

The library is written for no_std environments and is intended to be portable across different platforms, with special support for UEFI environments via the uefi feature flag.


How It Works

Framebuffer Management

A framebuffer is a contiguous region of memory mapped to the display hardware. Each pixel is represented by a value (typically 32 bits for RGBA), and the display hardware reads this memory to show the image on the screen. By writing to the framebuffer, software can directly control what appears on the display.

The framebuffer module provides:

  • FramebufferInfo: A struct describing the framebuffer's address, size, width, height, stride (pixels per row), and pixel format.
  • UEFI-specific initialization (with the uefi feature): Uses the UEFI Graphics Output Protocol (GOP) to discover and initialize the framebuffer at boot time.

Drawing Routines

The drawing module provides basic drawing functions, including:

  • draw_bresenham: Draws a line between two points using Bresenham's algorithm, writing directly to the framebuffer memory.
  • framebuffer_x_demo: Draws an 'X' across the entire framebuffer as a demonstration.

All drawing routines operate by calculating the correct memory offset for each pixel and writing color values (currently hardcoded to white for demos) directly to the framebuffer.


Features

  • UEFI framebuffer initialization (via uefi-rs)
  • Modular, no_std-compatible design
  • Basic drawing primitives (lines, demo patterns)
  • Safe Rust abstractions for framebuffer access

Usage

Add this crate as a dependency in your Cargo workspace. If you are building for UEFI, enable the uefi feature:

[dependencies]
polished_graphics = { path = "../graphics", features = ["uefi"] }

In your code:

use polished_graphics::framebuffer::{FramebufferInfo};
use polished_graphics::drawing::{draw_bresenham, framebuffer_x_demo};

// For UEFI environments:
#[cfg(feature = "uefi")]
let mut fb = polished_graphics::initialize_framebuffer();

// Draw an X across the screen
framebuffer_x_demo(&mut fb);

License

Unless otherwise noted, all code in this crate is licensed under the zlib License:

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

See the LICENSE file for full details.


Acknowledgments

  • uefi-rs — UEFI support in Rust
  • Rust OSDev community — For resources, examples, and inspiration

This library is actively developed as part of Polished OS. Feedback and contributions are welcome!

Commit count: 0

cargo fmt