Image IO (Save/Load) operations. More...
Functions | |
| SIMD_API uint8_t * | SimdImageSaveToMemory (const uint8_t *src, size_t stride, size_t width, size_t height, SimdPixelFormatType format, SimdImageFileType file, int quality, size_t *size) |
| Encodes an image to a memory buffer. More... | |
| SIMD_API SimdBool | SimdImageSaveToFile (const uint8_t *src, size_t stride, size_t width, size_t height, SimdPixelFormatType format, SimdImageFileType file, int quality, const char *path) |
| Encodes an image and writes it to a file. More... | |
| SIMD_API uint8_t * | SimdNv12SaveAsJpegToMemory (const uint8_t *y, size_t yStride, const uint8_t *uv, size_t uvStride, size_t width, size_t height, SimdYuvType yuvType, int quality, size_t *size) |
| Encodes an NV12 image to a JPEG memory buffer. More... | |
| SIMD_API uint8_t * | SimdYuv420pSaveAsJpegToMemory (const uint8_t *y, size_t yStride, const uint8_t *u, size_t uStride, const uint8_t *v, size_t vStride, size_t width, size_t height, SimdYuvType yuvType, int quality, size_t *size) |
| Encodes a YUV420P image to a JPEG memory buffer. More... | |
| SIMD_API uint8_t * | SimdImageLoadFromMemory (const uint8_t *data, size_t size, size_t *stride, size_t *width, size_t *height, SimdPixelFormatType *format) |
| Decodes an image from a memory buffer. More... | |
| SIMD_API uint8_t * | SimdImageLoadFromFile (const char *path, size_t *stride, size_t *width, size_t *height, SimdPixelFormatType *format) |
| Decodes an image from a file. More... | |
Detailed Description
Image IO (Save/Load) operations.
Function Documentation
◆ SimdImageSaveToMemory()
| uint8_t * SimdImageSaveToMemory | ( | const uint8_t * | src, |
| size_t | stride, | ||
| size_t | width, | ||
| size_t | height, | ||
| SimdPixelFormatType | format, | ||
| SimdImageFileType | file, | ||
| int | quality, | ||
| size_t * | size | ||
| ) |
Encodes an image to a memory buffer.
The source image must have non-zero width and height. Supported source pixel formats are SimdPixelFormatGray8, SimdPixelFormatBgr24, SimdPixelFormatBgra32, SimdPixelFormatRgb24 and SimdPixelFormatRgba32. Supported output file formats are PGM, PPM, PNG, JPEG and BMP variants from SimdImageFileType. If file is SimdImageFileUndefined, the function saves Gray8 input as binary PGM and all other supported inputs as binary PPM.
Encoders convert the input to the pixel layout required by the selected file format. For JPEG, quality is clamped to the range [1..100]. The returned buffer is allocated by the library.
- Parameters
-
[in] src - a pointer to pixels data of input image. [in] stride - a row size of input image (in bytes). [in] width - a width of input image. [in] height - a height of input image. [in] format - a pixel format of input image. [in] file - a format of output image file. [in] quality - a compression quality parameter for formats that use it. [out] size - a pointer to the size of output image file in bytes.
- Returns
- a pointer to memory buffer with output image file. It has to be deleted after use by function SimdFree. On error it returns NULL.
◆ SimdImageSaveToFile()
| SimdBool SimdImageSaveToFile | ( | const uint8_t * | src, |
| size_t | stride, | ||
| size_t | width, | ||
| size_t | height, | ||
| SimdPixelFormatType | format, | ||
| SimdImageFileType | file, | ||
| int | quality, | ||
| const char * | path | ||
| ) |
Encodes an image and writes it to a file.
This function first uses SimdImageSaveToMemory and then writes the encoded buffer to path. If file is SimdImageFileUndefined, the output format is selected from recognized file extensions: .pgm, .ppm, .png, .jpg/.jpeg or .bmp. For .jpg/.jpeg with default quality 100, the function uses quality 85. If the extension is not recognized, the same default selection as SimdImageSaveToMemory is used.
- Note
- This function has a C++ wrapper Simd::View::Save(const std::string & path, SimdImageFileType type = SimdImageFileUndefined, int quality = 100).
- Parameters
-
[in] src - a pointer to pixels data of input image. [in] stride - a row size of input image (in bytes). [in] width - a width of input image. [in] height - a height of input image. [in] format - a pixel format of input image. [in] file - a format of output image file, or SimdImageFileUndefined to infer it from path. [in] quality - a compression quality parameter for formats that use it. [in] path - a path to output image file.
◆ SimdNv12SaveAsJpegToMemory()
| uint8_t * SimdNv12SaveAsJpegToMemory | ( | const uint8_t * | y, |
| size_t | yStride, | ||
| const uint8_t * | uv, | ||
| size_t | uvStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| SimdYuvType | yuvType, | ||
| int | quality, | ||
| size_t * | size | ||
| ) |
Encodes an NV12 image to a JPEG memory buffer.
The input image has one full-size Y plane and one half-size interleaved UV plane. Width and height must be even. The only supported YUV type is SimdYuvTrect871. Quality is clamped to the range [1..100].
- Parameters
-
[in] y - a pointer to pixels data of input 8-bit image with Y color plane. [in] yStride - a row size of the y image (in bytes). [in] uv - a pointer to pixels data of input interleaved UV plane. [in] uvStride - a row size of the uv image (in bytes). [in] width - a width of input image. It must be even number. [in] height - a height of input image. It must be even number. [in] yuvType - a type of input YUV image (see description of SimdYuvType). Now only SimdYuvTrect871 is supported. [in] quality - a JPEG compression quality parameter. [out] size - a pointer to the size of output image file in bytes.
- Returns
- a pointer to memory buffer with output JPEG file. It has to be deleted after use by function SimdFree. On error it returns NULL.
◆ SimdYuv420pSaveAsJpegToMemory()
| uint8_t * SimdYuv420pSaveAsJpegToMemory | ( | const uint8_t * | y, |
| size_t | yStride, | ||
| const uint8_t * | u, | ||
| size_t | uStride, | ||
| const uint8_t * | v, | ||
| size_t | vStride, | ||
| size_t | width, | ||
| size_t | height, | ||
| SimdYuvType | yuvType, | ||
| int | quality, | ||
| size_t * | size | ||
| ) |
Encodes a YUV420P image to a JPEG memory buffer.
The input image has one full-size Y plane and two half-size U and V planes. Width and height must be even. The only supported YUV type is SimdYuvTrect871. Quality is clamped to the range [1..100].
- Parameters
-
[in] y - a pointer to pixels data of input 8-bit image with Y color plane. [in] yStride - a row size of the y image (in bytes). [in] u - a pointer to pixels data of input 8-bit image with U color plane. [in] uStride - a row size of the u image (in bytes). [in] v - a pointer to pixels data of input 8-bit image with V color plane. [in] vStride - a row size of the v image (in bytes). [in] width - a width of input image. It must be even number. [in] height - a height of input image. It must be even number. [in] yuvType - a type of input YUV image (see description of SimdYuvType). Now only SimdYuvTrect871 is supported. [in] quality - a JPEG compression quality parameter. [out] size - a pointer to the size of output image file in bytes.
- Returns
- a pointer to memory buffer with output JPEG file. It has to be deleted after use by function SimdFree. On error it returns NULL.
◆ SimdImageLoadFromMemory()
| uint8_t * SimdImageLoadFromMemory | ( | const uint8_t * | data, |
| size_t | size, | ||
| size_t * | stride, | ||
| size_t * | width, | ||
| size_t * | height, | ||
| SimdPixelFormatType * | format | ||
| ) |
Decodes an image from a memory buffer.
The function detects PGM/PPM, PNG, JPEG and BMP files from their in-memory signatures. On input, *format can request SimdPixelFormatGray8, SimdPixelFormatBgr24, SimdPixelFormatBgra32, SimdPixelFormatRgb24 or SimdPixelFormatRgba32. If *format is SimdPixelFormatNone, the loader keeps the natural format chosen for the input file. On success, stride, width, height and *format are filled with the decoded image properties.
- Note
- This function has a C++ wrapper Simd::View::Load(const uint8_t * src, size_t size, Simd::View::Format format = Simd::View::None).
- Parameters
-
[in] data - a pointer to memory buffer with input image file. [in] size - a size of input image file in bytes. [out] stride - a pointer to row size of output image in bytes. [out] width - a pointer to width of output image. [out] height - a pointer to height of output image. [in,out] format - a pointer to requested pixel format on input and decoded pixel format on output.
- Returns
- a pointer to pixels data of output image. It has to be deleted after use by function SimdFree. On error it returns NULL.
◆ SimdImageLoadFromFile()
| uint8_t * SimdImageLoadFromFile | ( | const char * | path, |
| size_t * | stride, | ||
| size_t * | width, | ||
| size_t * | height, | ||
| SimdPixelFormatType * | format | ||
| ) |
Decodes an image from a file.
The function reads the whole file into memory and then calls SimdImageLoadFromMemory. The file type is detected from the file content, not from the extension.
- Note
- This function has a C++ wrapper Simd::View::Load(const std::string & path, Simd::View::Format format = Simd::View::None).
- Parameters
-
[in] path - a path to input image file. [out] stride - a pointer to row size of output image in bytes. [out] width - a pointer to width of output image. [out] height - a pointer to height of output image. [in,out] format - a pointer to requested pixel format on input and decoded pixel format on output.
- Returns
- a pointer to pixels data of output image. It has to be deleted after use by function SimdFree. On error it returns NULL.