SqueezeBrains SDK 1.18
|
Collection of functions to manage images. More...
Data Structures | |
struct | sb_t_rle_seg |
Define a RLE segment. More... | |
struct | sb_t_rle |
Defines a RLE. More... | |
struct | sb_t_image |
Defines an image. More... | |
Macros | |
#define | SB_IMAGE_FILE_EXTENSIONS |
List of the possible extensions of the image. | |
Enumerations | |
enum | sb_t_image_format { SB_IMAGE_FORMAT_BW8 = 0 , SB_IMAGE_FORMAT_BGR888 , SB_IMAGE_FORMAT_RGB888 , SB_IMAGE_FORMAT_UI32 } |
Format of image pixel. More... | |
enum | sb_t_image_compress_type { SB_IMAGE_COMPRESS_NONE = 0 , SB_IMAGE_COMPRESS_RLE , SB_IMAGE_COMPRESS_JPEG , SB_IMAGE_COMPRESS_PNG } |
Type of image compression. More... | |
enum | sb_t_image_compress_par { SB_IMAGE_COMPRESS_PAR_JPEG_QUALITY = 1 } |
Definitions of parameters used by the image encoders. More... | |
enum | sb_t_image_flip_mode { SB_IMAGE_FLIP_BOTH = -1 , SB_IMAGE_FLIP_HORIZONTAL = 0 , SB_IMAGE_FLIP_VERTICAL = 1 } |
Enumeration of the flip mode. More... | |
enum | sb_t_image_circularity_type { SB_IMAGE_CIRCULARITY_TYPE_NONE = 0 , SB_IMAGE_CIRCULARITY_TYPE_HORIZONTAL , SB_IMAGE_CIRCULARITY_TYPE_VERTICAL } |
Enumeration of the image circularity type. More... | |
Functions | |
const char * | sb_image_format (sb_t_image_format format) |
Returns the string of the image format. More... | |
sb_t_err | sb_image_create (sb_t_image **const pimg, int width, int height, sb_t_image_format format) |
Creates an image. More... | |
sb_t_err | sb_image_create_header (sb_t_image **const pimg, int width, int height, int width_step, sb_t_image_format format) |
Creates an image but doesn't allocate memory for the data. More... | |
sb_t_err | sb_image_destroy (sb_t_image **const pimg) |
Destroys the image. More... | |
sb_t_err | sb_image_compress (sb_t_image **const dst, sb_t_image *const src, sb_t_image_compress_type compression, const void *const params) |
Compress the image with the compression method specified. More... | |
sb_t_err | sb_image_decompress (sb_t_image **const dst, sb_t_image *const src) |
Decompress the image. More... | |
sb_t_err | sb_image_set_clip_blend (sb_t_image *const img, int x, int y, const sb_t_rgba *const color) |
Set the pixel (x,y) with the color using also alpha blending. More... | |
sb_t_err | sb_image_get_pixel (const sb_t_image *const img, int x, int y, sb_t_rgba *const color) |
Get the pixel (x,y). More... | |
sb_t_err | sb_image_set_data (sb_t_image *const img, unsigned char *const data) |
Sets the pointer to a block of memory for image data. More... | |
sb_t_err | sb_image_clone (sb_t_image **const dst, const sb_t_image *const src) |
Clones the image. More... | |
sb_t_err | sb_image_copy (const sb_t_image *const src, sb_t_image *const dst) |
Copies the image. More... | |
sb_t_err | sb_image_copy_rect (const sb_t_image *const src, sb_t_rect rect, sb_t_image **const dst) |
Copies a rectangular crop of an image into another one. More... | |
sb_t_err | sb_image_clean (sb_t_image *const img) |
Cleans the image. More... | |
sb_t_err | sb_image_save (const sb_t_image *const img, const char *const file, const int *const params) |
Saves the image in a file. More... | |
sb_t_err | sb_image_load (sb_t_image **const img, const char *const file) |
Loads an image from a file. More... | |
sb_t_err | sb_image_convert (sb_t_image **const dst, sb_t_image *const src, sb_t_image_format format) |
Convert the source image into the destination image. More... | |
sb_t_err | sb_image_flip (const sb_t_image *const src, sb_t_image *const dst, sb_t_image_flip_mode mode) |
Flips the image. More... | |
sb_t_err | sb_image_shift (const sb_t_image *const src, sb_t_image *const dst, int x_shift, int y_shift, int circular) |
Shifts the image. More... | |
sb_t_err | sb_image_rotate (const sb_t_image *const src, sb_t_point centre, double angle, sb_t_interpolation_mode interpolation_mode, sb_t_image *const dst) |
Rotates an image. More... | |
sb_t_err | sb_image_resize (const sb_t_image *const src, sb_t_rect rect, float scale, sb_t_interpolation_mode interpolation_mode, sb_t_image *const dst) |
Resizes the image. More... | |
sb_t_err | sb_image_get_sample (const sb_t_image *const src, sb_t_point centre, double angle_rad, float scale, sb_t_image *const dst) |
Copies, rotates, resizes a rectangular roi of the source image to the destination one. More... | |
sb_t_err | sb_image_change_brightness (const sb_t_image *const src, sb_t_image *const dst, float delta_brightness) |
Changes the image brightness by the percentage amount specified. More... | |
sb_t_err | sb_image_change_contrast (const sb_t_image *const src, sb_t_image *const dst, float delta_contrast) |
Changes the image contrast by the percentage amount specified. More... | |
const char * | sb_image_circularity_type_format (sb_t_image_circularity_type type) |
Returns the string of the image circularity type. More... | |
sb_t_err | sb_image_read_size (sb_t_size *const size, const char *const file) |
Get the image size from a file. More... | |
Collection of functions to manage images.
See Image management for more detailed information about how to handle the images.
Definitions of parameters used by the image encoders.
The values are 32 bits both for 32 and 64 bits library version.
Enumerator | |
---|---|
SB_IMAGE_COMPRESS_PAR_JPEG_QUALITY | Quality of jpeg image. |
Type of image compression.
The values are 32 bits both for 32 and 64 bits library version.
enum sb_t_image_flip_mode |
Enumeration of the flip mode.
The values are 32 bits both for 32 and 64 bits library version.
enum sb_t_image_format |
Format of image pixel.
The values are 32 bits both for 32 and 64 bits library version.
sb_t_err sb_image_change_brightness | ( | const sb_t_image *const | src, |
sb_t_image *const | dst, | ||
float | delta_brightness | ||
) |
Changes the image brightness by the percentage amount specified.
Each pixel of the image is changed by adding a value in the range [-255, 255], computed from the delta_brightness percentage specified.
[in] | src | Pointer to the source image. |
[in] | dst | Pointer to the destination image. |
[in] | delta_brightness | Percentage of brightness variation to apply to the pixels of the image. Valid values [-1.0f, 1.0f]. |
sb_t_err sb_image_change_contrast | ( | const sb_t_image *const | src, |
sb_t_image *const | dst, | ||
float | delta_contrast | ||
) |
Changes the image contrast by the percentage amount specified.
Each pixel of the image is changed by computing a new value considering the actual image histogram contrast (max - min) and the percentage of the contrast variation specified. Positive percentage values increase the contrast, while negative percentage values reduce the contrast.
[in] | src | Pointer to the source image. |
[in,out] | dst | Pointer to the destination image. |
[in] | delta_contrast | Percentage of contrast variation. Valid values [-1.0f, 1.0f]. |
const char * sb_image_circularity_type_format | ( | sb_t_image_circularity_type | type | ) |
Returns the string of the image circularity type.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding value.
[in] | type | Image circularity type. |
sb_t_err sb_image_clean | ( | sb_t_image *const | img | ) |
Cleans the image.
[in,out] | img | Pointer to the image. |
sb_t_err sb_image_clone | ( | sb_t_image **const | dst, |
const sb_t_image *const | src | ||
) |
Clones the image.
[in,out] | dst | Pointer to the image. On successful return, this parameter will be updated with the pointer of the image. |
[in] | src | Pointer to the image |
sb_t_err sb_image_compress | ( | sb_t_image **const | dst, |
sb_t_image *const | src, | ||
sb_t_image_compress_type | compression, | ||
const void *const | params | ||
) |
Compress the image with the compression method specified.
[out] | dst | Pointer to the destination image, can be NULL if the compression is made on the source image. |
[in] | src | Pointer to the source image |
[in] | compression | Compression type of the image |
[in] | params | Optional parameters. Actually used only by jpeg compression to set the quality. If params is NULL the default quality is 95. Usage example: int par[3];
par[0] = SB_IMAGE_COMPRESS_PAR_JPEG_QUALITY;
par[1] = 90;
par[2] = 0;
sb_image_compress(&dst, src, SB_IMAGE_COMPRESS_JPEG, par);
sb_t_err sb_image_compress(sb_t_image **const dst, sb_t_image *const src, sb_t_image_compress_type compression, const void *const params) Compress the image with the compression method specified. |
sb_t_err sb_image_convert | ( | sb_t_image **const | dst, |
sb_t_image *const | src, | ||
sb_t_image_format | format | ||
) |
Convert the source image into the destination image.
[in] | src | Pointer to the source image. |
[out] | dst | Pointer to the destination image. If equal to src the function operates in place. . If the pointer to destination image (*dst) is NULL the destination image is created. |
[in] | format | Destination image format. The parameter is used only if destination image is created. Only the following formats are possible: |
sb_t_err sb_image_copy | ( | const sb_t_image *const | src, |
sb_t_image *const | dst | ||
) |
Copies the image.
[in] | src | Pointer to the source image. |
[out] | dst | Pointer to the destination image. |
sb_t_err sb_image_copy_rect | ( | const sb_t_image *const | src, |
sb_t_rect | rect, | ||
sb_t_image **const | dst | ||
) |
Copies a rectangular crop of an image into another one.
Borders are replicated if the rect is out of the image.
[in] | src | Pointer to the source image. |
[in] | rect | Coordinates of the rectangle ROI. |
[out] | dst | Pointer to the destination image. If the value of dst is NULL the image is allocated. If the value is not NULL the function verifies that the width and height of the image and the rect are equal, furthermore it verifies that the format of the src and dst image are the same. |
sb_t_err sb_image_create | ( | sb_t_image **const | pimg, |
int | width, | ||
int | height, | ||
sb_t_image_format | format | ||
) |
Creates an image.
[out] | pimg | Pointer to the image. On successful return, this parameter will be updated with the pointer of the image. |
[in] | width | Width, in pixel, of the image. |
[in] | height | Height, in pixel, of the image. |
[in] | format | Image format. |
sb_t_err sb_image_create_header | ( | sb_t_image **const | pimg, |
int | width, | ||
int | height, | ||
int | width_step, | ||
sb_t_image_format | format | ||
) |
Creates an image but doesn't allocate memory for the data.
The user should use the function sb_image_set_data to assign a block on memory for image data.
The block of memory must have a greater or equal than height * width_step.
[out] | pimg | Pointer to the image. On successful return, this parameter will be updated with the pointer of the handle. |
[in] | width | Width, in pixel, of the image. |
[in] | height | Height, in pixel, of the image. |
[in] | width_step | Number of bytes to move the pointer to one row to the next one. |
[in] | format | Image format. |
sb_t_err sb_image_decompress | ( | sb_t_image **const | dst, |
sb_t_image *const | src | ||
) |
Decompress the image.
[out] | dst | Pointer to the destination image, can be NULL if the decompression is made on the source image. |
[in] | src | Pointer to the source image |
sb_t_err sb_image_destroy | ( | sb_t_image **const | pimg | ) |
Destroys the image.
[out] | pimg | Pointer to the image, it is set to NULL. |
sb_t_err sb_image_flip | ( | const sb_t_image *const | src, |
sb_t_image *const | dst, | ||
sb_t_image_flip_mode | mode | ||
) |
Flips the image.
[in] | src | Pointer to the source image. |
[out] | dst | Pointer to the destination image. It may be equal to the source image. |
[in] | mode | Flip mode. |
const char * sb_image_format | ( | sb_t_image_format | format | ) |
Returns the string of the image format.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding image format.
The string must not be freed.
[in] | format | Image format. |
sb_t_err sb_image_get_pixel | ( | const sb_t_image *const | img, |
int | x, | ||
int | y, | ||
sb_t_rgba *const | color | ||
) |
Get the pixel (x,y).
The function checks if the point is out of the image.
[in] | img | image. |
[in] | x | x-coordinate of the pixel. |
[in] | y | y-coordinate of the pixel. |
[out] | color | Value of the pixel. |
sb_t_err sb_image_get_sample | ( | const sb_t_image *const | src, |
sb_t_point | centre, | ||
double | angle_rad, | ||
float | scale, | ||
sb_t_image *const | dst | ||
) |
Copies, rotates, resizes a rectangular roi of the source image to the destination one.
The width and height of the rectangular roi of the source image are the width and height of the destination image multiplicated by the scale. The function uses bilinear interpolation to rotate and resize data. The functions works correctly even if the roi is out of the image, the pixels at the border are replicated.
[in] | src | Pointer to the source image. |
[in] | centre | Centre of the rectangular roi in the source image. |
[in] | angle_rad | Rotation angle, in radians, clockwise if positive. |
[in] | scale | Scale factor of the source image. |
[out] | dst | Pointer to the destination image. |
sb_t_err sb_image_load | ( | sb_t_image **const | img, |
const char *const | file | ||
) |
Loads an image from a file.
This software is based in part on the work of the Independent JPEG Group (https://github.com/LuaDist/libjpeg).
[out] | img | Pointer to the image. |
[in] | file | File name. The admitted file extension are:
|
Get the image size from a file.
[out] | size | Size of the image. |
[in] | file | File name. |
sb_t_err sb_image_resize | ( | const sb_t_image *const | src, |
sb_t_rect | rect, | ||
float | scale, | ||
sb_t_interpolation_mode | interpolation_mode, | ||
sb_t_image *const | dst | ||
) |
Resizes the image.
[in] | src | Pointer to the source image. |
[in] | rect | Coordinates of the rectangular ROI of the source image that have to be resized. |
[in] | scale | Scale factor. If the value is greater than 1, the image size is reduced. if you need to resize the image with a different scale factor in x and y set the scale to 0. In this case the scale will be calculated internally by the function as follows:
|
[in] | interpolation_mode | Interpolation mode. |
[out] | dst | Pointer to the destination image. |
sb_t_err sb_image_rotate | ( | const sb_t_image *const | src, |
sb_t_point | centre, | ||
double | angle, | ||
sb_t_interpolation_mode | interpolation_mode, | ||
sb_t_image *const | dst | ||
) |
Rotates an image.
Destination image pixels falling outside the source image are replicated from the nearest border if mode is equal to SB_INTERPOLATION_MODE_BILINEAR, while they are left black if mode is equal to SB_INTERPOLATION_MODE_NN .
[in] | src | Pointer to the source image. |
[in] | centre | Coordinates of the rotation centre. |
[in] | angle | Rotation angle, in radians, clockwise if positive. |
[in] | interpolation_mode | Interpolation mode. |
[out] | dst | Pointer to the destination image. It must be different from source image. |
sb_t_err sb_image_save | ( | const sb_t_image *const | img, |
const char *const | file, | ||
const int *const | params | ||
) |
Saves the image in a file.
The function accepts the following images:
image | compression sb_t_image::compression | admitted file extension |
---|---|---|
uncompressed images | SB_IMAGE_COMPRESS_NONE | "bmp", "pgm", "ppm", "jpg", "jpeg", "png" |
JPEG compressed images | SB_IMAGE_COMPRESS_JPEG | "jpg", "jpeg" |
PNG compressed images | SB_IMAGE_COMPRESS_PNG | "png" |
[in] | img | Pointer to the image |
[in] | file | File name. The admitted file extension are:
|
[in] | params | Optional parameters. Actually used only by jpeg compression to set the quality. If params is NULL the default quality is 95. Usage example: int par[3];
par[0] = SB_IMAGE_COMPRESS_PAR_JPEG_QUALITY;
par[1] = 90;
par[2] = 0;
sb_image_save(img, "dummy.jpg", par);
sb_t_err sb_image_save(const sb_t_image *const img, const char *const file, const int *const params) Saves the image in a file. |
sb_t_err sb_image_set_clip_blend | ( | sb_t_image *const | img, |
int | x, | ||
int | y, | ||
const sb_t_rgba *const | color | ||
) |
Set the pixel (x,y) with the color using also alpha blending.
The function checks if the point is out of the image.
[in,out] | img | image. |
[in] | x | x-coordinate of the pixel. |
[in] | y | y-coordinate of the pixel. |
[in] | color | color to draw the pixel. |
sb_t_err sb_image_set_data | ( | sb_t_image *const | img, |
unsigned char *const | data | ||
) |
Sets the pointer to a block of memory for image data.
[in] | img | Pointer to the image. |
[in] | data | Pointer of the block of data. The block of memory must have a size greater or equal than height * width_step. |
sb_t_err sb_image_shift | ( | const sb_t_image *const | src, |
sb_t_image *const | dst, | ||
int | x_shift, | ||
int | y_shift, | ||
int | circular | ||
) |
Shifts the image.
[in] | src | Pointer to the source image. |
[out] | dst | Pointer to the destination image. It may be equal to the source image. |
[in] | x_shift | Shift along x axis. |
[in] | y_shift | Shift along y axis. |
[in] | circular | If it is set to 1 the image is considered circular. Only x-shifting has been implemented. |