The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
image.c File Reference

load images into libgfx buffers, through stb_image. More...

#include "image.h"
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../stb/stb_image.h"

Macros

#define STBI_ONLY_PNG
#define STBI_ONLY_JPEG
#define STBI_ONLY_BMP
#define STBI_NO_STDIO
#define STBI_NO_HDR
#define STBI_NO_SIMD
#define STBI_NO_THREAD_LOCALS
#define STBI_ASSERT(x)
#define STBI_MAX_DIMENSIONS   IMAGE_MAX_SIDE
#define STB_IMAGE_IMPLEMENTATION
#define FILE_MAX_SIZE   (64u * 1024 * 1024)

Functions

gfx_buffer_t * image_decode (const uint8_t *data, size_t size, const char **error)
 decode an image from memory.
gfx_buffer_t * image_load (const char *path, const char **error)
 load an image file.
int32_t image_inflate (const uint8_t *in, size_t in_size, uint8_t *out, size_t out_size)
 decompress zlib data (RFC 1950) into a buffer of known size.

Detailed Description

load images into libgfx buffers, through stb_image.

stb_image is built here with only what ginnOS needs: PNG, JPEG and BMP from memory, no file access of its own (the file is read here), no SIMD, no thread-local storage, and no HDR. (STBI_NO_LINEAR is not set: in v2.30 it leaves a helper the PNG decoder needs undefined.)

Macro Definition Documentation

◆ STBI_ONLY_PNG

#define STBI_ONLY_PNG

◆ STBI_ONLY_JPEG

#define STBI_ONLY_JPEG

◆ STBI_ONLY_BMP

#define STBI_ONLY_BMP

◆ STBI_NO_STDIO

#define STBI_NO_STDIO

◆ STBI_NO_HDR

#define STBI_NO_HDR

◆ STBI_NO_SIMD

#define STBI_NO_SIMD

◆ STBI_NO_THREAD_LOCALS

#define STBI_NO_THREAD_LOCALS

◆ STBI_ASSERT

#define STBI_ASSERT ( x)
Value:
((void)0)

◆ STBI_MAX_DIMENSIONS

#define STBI_MAX_DIMENSIONS   IMAGE_MAX_SIDE

◆ STB_IMAGE_IMPLEMENTATION

#define STB_IMAGE_IMPLEMENTATION

◆ FILE_MAX_SIZE

#define FILE_MAX_SIZE   (64u * 1024 * 1024)

Function Documentation

◆ image_decode()

gfx_buffer_t * image_decode ( const uint8_t * data,
size_t size,
const char ** error )

decode an image from memory.

◆ image_load()

gfx_buffer_t * image_load ( const char * path,
const char ** error )

load an image file.

Parameters
errorreceives a short reason on failure (may be NULL).
Returns
a new buffer (free it with gfx_buffer_free), or NULL.

◆ image_inflate()

int32_t image_inflate ( const uint8_t * in,
size_t in_size,
uint8_t * out,
size_t out_size )

decompress zlib data (RFC 1950) into a buffer of known size.

Returns
the bytes written, or -1 (bad data, or out does not hold it).