libsf3
Loading...
Searching...
No Matches
sf3_image.h
Go to the documentation of this file.
1#ifndef __SF3_IMAGE__
2#define __SF3_IMAGE__
3#include "sf3_core.h"
4
6#define SF3_FORMAT_ID_IMAGE 0x03
7
36
68
73 struct sf3_identifier identifier;
75 uint32_t width;
77 uint32_t height;
79 uint32_t depth;
81 uint8_t channels;
83 uint8_t format;
85 char pixels[];
86};
87
90 return image->format & 0x0F;
91}
92
95 return image->channels & 0x0F;
96}
97
100 return (image->channels & 0x0F) * (image->format & 0x0F);
101}
102
105 switch(format){
106 case SF3_PIXEL_INT8: return "int8";
107 case SF3_PIXEL_INT16: return "int16";
108 case SF3_PIXEL_INT32: return "int32";
109 case SF3_PIXEL_INT64: return "int64";
110 case SF3_PIXEL_UINT8: return "uint8";
111 case SF3_PIXEL_UINT16: return "uint16";
112 case SF3_PIXEL_UINT32: return "uint32";
113 case SF3_PIXEL_UINT64: return "uint64";
114 case SF3_PIXEL_FLOAT16: return "float2";
115 case SF3_PIXEL_FLOAT32: return "float4";
116 case SF3_PIXEL_FLOAT64: return "float8";
117 default: "Unknown";
118 }
119}
120
123 switch(format){
124 case SF3_PIXEL_V: return "V";
125 case SF3_PIXEL_VA: return "VA";
126 case SF3_PIXEL_RGB: return "RGB";
127 case SF3_PIXEL_RGBA: return "RGBA";
128 case SF3_PIXEL_AV: return "AV";
129 case SF3_PIXEL_BGR: return "BGR";
130 case SF3_PIXEL_ABGR: return "ABGR";
131 case SF3_PIXEL_ARGB: return "ARGB";
132 case SF3_PIXEL_BGRA: return "BGRA";
133 case SF3_PIXEL_CMYK: return "CMYK";
134 case SF3_PIXEL_KYMC: return "KYMC";
135 default: return "Unknown";
136 }
137}
138
140SF3_EXPORT size_t sf3_image_size(const struct sf3_image *image){
141 return sizeof(struct sf3_image)
142 + sf3_image_pixel_stride(image) * image->width * image->height * image->depth;
143}
144#endif
#define SF3_INLINE
Definition sf3_core.h:16
#define SF3_EXPORT
Definition sf3_core.h:13
#define SF3_PACK
Definition sf3_core.h:9
SF3_INLINE int sf3_image_pixel_stride(const struct sf3_image *image)
Returns the number of bytes per pixel.
Definition sf3_image.h:99
sf3_channel_layout
The possible pixel channel layouts.
Definition sf3_image.h:38
@ SF3_PIXEL_VA
Each pixel consists of a (grayscale) value and an alpha channel.
Definition sf3_image.h:42
@ SF3_PIXEL_V
Each pixel consists of a (grayscale) value channel.
Definition sf3_image.h:40
@ SF3_PIXEL_ARGB
Definition sf3_image.h:59
@ SF3_PIXEL_AV
Each pixel consists of an alpha and a (grayscale) value channel.
Definition sf3_image.h:50
@ SF3_PIXEL_RGBA
Definition sf3_image.h:48
@ SF3_PIXEL_BGRA
Definition sf3_image.h:62
@ SF3_PIXEL_RGB
Definition sf3_image.h:45
@ SF3_PIXEL_BGR
Definition sf3_image.h:53
@ SF3_PIXEL_KYMC
Each pixel consists of a black, yellow, magenta, and cyan channel.
Definition sf3_image.h:66
@ SF3_PIXEL_ABGR
Definition sf3_image.h:56
@ SF3_PIXEL_CMYK
Each pixel consists of a cyan, magenta, yellow, and black channel.
Definition sf3_image.h:64
SF3_INLINE int sf3_image_channel_count(const struct sf3_image *image)
Returns the number of channels per pixel.
Definition sf3_image.h:94
SF3_EXPORT size_t sf3_image_size(const struct sf3_image *image)
Computes the size of the image file in bytes.
Definition sf3_image.h:140
SF3_INLINE char * sf3_image_channel_layout(enum sf3_channel_layout format)
Returns a human-readable string representation of the layout.
Definition sf3_image.h:122
sf3_pixel_format
The possible pixel channel formats.
Definition sf3_image.h:9
@ SF3_PIXEL_UINT32
The channel values are stored in 32-bit unsigned format.
Definition sf3_image.h:23
@ SF3_PIXEL_INT32
The channel values are stored in 32-bit signed format.
Definition sf3_image.h:15
@ SF3_PIXEL_FLOAT16
Definition sf3_image.h:28
@ SF3_PIXEL_FLOAT64
Definition sf3_image.h:34
@ SF3_PIXEL_FLOAT32
Definition sf3_image.h:31
@ SF3_PIXEL_UINT64
The channel values are stored in 64-bit unsigned format.
Definition sf3_image.h:25
@ SF3_PIXEL_UINT16
The channel values are stored in 16-bit unsigned format.
Definition sf3_image.h:21
@ SF3_PIXEL_INT64
The channel values are stored in 64-bit signed format.
Definition sf3_image.h:17
@ SF3_PIXEL_INT8
The channel values are stored in 8-bit signed format.
Definition sf3_image.h:11
@ SF3_PIXEL_INT16
The channel values are stored in 16-bit signed format.
Definition sf3_image.h:13
@ SF3_PIXEL_UINT8
The channel values are stored in 8-bit unsigned format.
Definition sf3_image.h:19
SF3_EXPORT char * sf3_image_pixel_format(enum sf3_pixel_format format)
Returns a human-readable string representation of the format.
Definition sf3_image.h:104
SF3_INLINE int sf3_image_channel_size(const struct sf3_image *image)
Returns the number of bytes per channel.
Definition sf3_image.h:89
The basic header structure of every SF3 file.
Definition sf3_core.h:70
uint32_t height
The height of the image.
Definition sf3_image.h:77
uint32_t width
The width of the image.
Definition sf3_image.h:75
uint8_t channels
The channel layout of the pixels.
Definition sf3_image.h:81
uint8_t format
The value format of the channels.
Definition sf3_image.h:83
uint32_t depth
The depth (number of layers) of the image.
Definition sf3_image.h:79