imsz
imsz.h File Reference
#include <stdint.h>
#include <stdio.h>
Include dependency graph for imsz.h:

Go to the source code of this file.

Classes

struct  ImInfo
 The width, height and format of an image. More...
 

Macros

#define IMSZ_INIT   { .width = (uint64_t)0, .height = (uint64_t)0, .format = 0 }
 
#define imsz_from_file(fp, info_ptr)   imsz_from_fd(_fileno((fp)), (info_ptr))
 

Typedefs

typedef enum ImError ImError
 Error values. More...
 
typedef enum ImFormat ImFormat
 All supported image formats.
 
typedef struct ImInfo ImInfo
 The width, height and format of an image.
 

Enumerations

enum  ImError { IMSZ_OK = 0, IMSZ_ERR_IO = -1, IMSZ_ERR_PARSER = -2, IMSZ_ERR_UNSUPPORTED = -3 }
 Error values. More...
 
enum  ImFormat {
  IMSZ_GIF = 1u, IMSZ_PNG = 2u, IMSZ_BMP = 3u, IMSZ_JPEG = 4u,
  IMSZ_WEBP = 5u, IMSZ_QOI = 6u, IMSZ_PSD = 7u, IMSZ_XCF = 8u,
  IMSZ_ICO = 9u, IMSZ_AVIF = 10u, IMSZ_TIFF = 11u, IMSZ_OpenEXR = 12u,
  IMSZ_PCX = 13u, IMSZ_TGA = 14u, IMSZ_DDS = 15u, IMSZ_HEIF = 16u,
  IMSZ_JP2K = 17u, IMSZ_DIB = 18u, IMSZ_VTF = 19u
}
 All supported image formats. More...
 

Functions

int imsz_from_path (const char *path, ImInfo *info_ptr)
 
int imsz_from_buffer (const void *buf, size_t len, ImInfo *info_ptr)
 
int imsz_from_fd (int fd, ImInfo *info_ptr)
 
const char * imsz_format_name (unsigned int format)
 
int imsz_from_pathw (const wchar_t *path, ImInfo *info_ptr)
 
int imsz_from_handle (HANDLE hnd, ImInfo *info_ptr)
 
const wchar_t * imsz_format_namew (unsigned int format)
 
int imsz (const char *path, ImInfo *info_ptr)
 Alias of imsz_from_path() More...
 
int imsz (const void *buf, size_t len, ImInfo *info_ptr)
 Alias of imsz_from_buffer() More...
 
int imsz (int fd, ImInfo *info_ptr)
 Alias of imsz_from_fd() More...
 
int imsz (FILE *file, ImInfo *info_ptr)
 Alias of imsz_from_file() More...
 
int imsz (const wchar_t *path, ImInfo *info_ptr)
 Alias of imsz_from_pathw() More...
 
int imsz (HANDLE hnd, ImInfo *info_ptr)
 Alias of imsz_from_handle() More...
 

Detailed Description

Get image width and height reading as few bytes as possible

Macro Definition Documentation

◆ imsz_from_file

#define imsz_from_file (   fp,
  info_ptr 
)    imsz_from_fd(_fileno((fp)), (info_ptr))

Get image width and height from FILE pointer fp.

Parameters
fpFILE pointer. Must be seekable.
info_ptrPointer to where to write the result. Can be NULL.
Returns
ImError value or Windows error code.

◆ IMSZ_INIT

#define IMSZ_INIT   { .width = (uint64_t)0, .height = (uint64_t)0, .format = 0 }

Initialize an ImInfo variable with all 0 values.

NOTE: The API doesn't use enum ImFormat as a type, but unsigned int. This is so to be certain about the ABI since the library is actually implemented in Rust, which doesn't know about C enums. And C enums aren't guaranteed to be any certain integer type.

Typedef Documentation

◆ ImError

typedef enum ImError ImError

Error values.

NOTE: The API doesn't use enum ImError as a return type, but int. This is so to be certain about the ABI since the library is actually implemented in Rust, which doesn't know about C enums. And C enums aren't guaranteed to be any certain integer type.

Also a returned error value is not limited to these values, but can also be an errno value under POSIX or a Windows error code under Windows. Both, POSIX and Windows error codes are positive integers (or 0 for no error), these custom error codes are negative values.

Enumeration Type Documentation

◆ ImError

enum ImError

Error values.

NOTE: The API doesn't use enum ImError as a return type, but int. This is so to be certain about the ABI since the library is actually implemented in Rust, which doesn't know about C enums. And C enums aren't guaranteed to be any certain integer type.

Also a returned error value is not limited to these values, but can also be an errno value under POSIX or a Windows error code under Windows. Both, POSIX and Windows error codes are positive integers (or 0 for no error), these custom error codes are negative values.

Enumerator
IMSZ_OK 

No error.

IMSZ_ERR_IO 

IO error happened, but no OS error (errno or WIndows error code) was reported. (Classic should never happen.)

IMSZ_ERR_PARSER 

File format was detected, but there was an error parsing the file. ImInfo::format will be set to the detected file format.

IMSZ_ERR_UNSUPPORTED 

File format is not supported.

◆ ImFormat

enum ImFormat

All supported image formats.

Enumerator
IMSZ_GIF 

Graphics Interchange Format files in version GIF87a or GIF89a.

IMSZ_PNG 

Portable Network Graphics files. Requires the first chunk to be IHDR.

IMSZ_BMP 

Windows Bitmap, both for Windows 2.0 (BITMAPCOREHEADER) and for newer versions (BITMAPINFOHEADER).

IMSZ_JPEG 

Joint Photographic Experts Group files.

IMSZ_WEBP 

WebP files. Supported sub-formats: VP8, VP8L, VP8X.

IMSZ_QOI 

Quite OK Image format files.

IMSZ_PSD 

Adobe Photoshop files.

IMSZ_XCF 

GIMP files.

IMSZ_ICO 

ICO files can contain multiple images. This returns the dimensions of the biggest image in the file.

IMSZ_AVIF 

AV1 Image File Format.

IMSZ_TIFF 

Tag Image File Format. Supports big endian and little endian TIFF files.

IMSZ_OpenEXR 

OpenEXR files.

IMSZ_PCX 

PiCture eXchange files.

IMSZ_TGA 

TARGA (Truevision Advanced Raster Graphics Adapter) files.

IMSZ_DDS 

DirectDraw Surface files.

IMSZ_HEIF 

HEIC/HEIF files.

IMSZ_JP2K 

JPEG 2000 files.

IMSZ_DIB 

Device-Independent bitmap files.

IMSZ_VTF 

Valve Texture Format.

Function Documentation

◆ imsz() [1/6]

int imsz ( const char *  path,
ImInfo info_ptr 
)
inline

Alias of imsz_from_path()

Under C this is a macro using _Generic, under C++ an overloaded inline function.

◆ imsz() [2/6]

int imsz ( const void *  buf,
size_t  len,
ImInfo info_ptr 
)
inline

Alias of imsz_from_buffer()

Under C this is a macro using _Generic, under C++ an overloaded inline function.

◆ imsz() [3/6]

int imsz ( const wchar_t *  path,
ImInfo info_ptr 
)
inline

Alias of imsz_from_pathw()

Under C this is a macro using _Generic, under C++ an overloaded inline function.

◆ imsz() [4/6]

int imsz ( FILE *  file,
ImInfo info_ptr 
)
inline

Alias of imsz_from_file()

Under C this is a macro using _Generic, under C++ an overloaded inline function.

◆ imsz() [5/6]

int imsz ( HANDLE  hnd,
ImInfo info_ptr 
)
inline

Alias of imsz_from_handle()

Under C this is a macro using _Generic, under C++ an overloaded inline function.

◆ imsz() [6/6]

int imsz ( int  fd,
ImInfo info_ptr 
)
inline

Alias of imsz_from_fd()

Under C this is a macro using _Generic, under C++ an overloaded inline function.

◆ imsz_format_name()

const char* imsz_format_name ( unsigned int  format)

Get the name of an image file format.

Parameters
formatA ImFormat value.
Returns
The ASCII name of the image file format or "(unknown)" for an unknown value.

◆ imsz_format_namew()

const wchar_t* imsz_format_namew ( unsigned int  format)

Get the name of an image file format. (Windows-only)

Parameters
formatA ImFormat value.
Returns
The name of the image file format or "(unknown)" for an unknown value.

◆ imsz_from_buffer()

int imsz_from_buffer ( const void *  buf,
size_t  len,
ImInfo info_ptr 
)

Get image width and height from file loaded in buf.

Parameters
bufImage file loaded into memory.
lenSize of buf in bytes.
info_ptrPointer to where to write the result. Can be NULL.
Returns
ImError value or errno value under POSIX and Windows error code under Windows.

◆ imsz_from_fd()

int imsz_from_fd ( int  fd,
ImInfo info_ptr 
)

Get image width and height from file descriptor fd.

Parameters
fdA file descriptor of an image file. Must be seekable.
info_ptrPointer to where to write the result. Can be NULL.
Returns
ImError value or errno value under POSIX and Windows error code under Windows.

◆ imsz_from_handle()

int imsz_from_handle ( HANDLE  hnd,
ImInfo info_ptr 
)

Get image width and height from file handle hnd. (Windows-only)

Parameters
hndFile handle. Must be seekable.
info_ptrPointer to where to write the result. Can be NULL.
Returns
ImError value or Windows error code.

◆ imsz_from_path()

int imsz_from_path ( const char *  path,
ImInfo info_ptr 
)

Get image width and height from file at path.

Parameters
pathImage file path.
info_ptrPointer to where to write the result. Can be NULL.
Returns
ImError value or errno value under POSIX and Windows error code under Windows.

◆ imsz_from_pathw()

int imsz_from_pathw ( const wchar_t *  path,
ImInfo info_ptr 
)

Get image width and height from file at path. (Windows-only)

Parameters
pathImage file path as a wide string.
info_ptrPointer to where to write the result. Can be NULL.
Returns
ImError value or Windows error code.