Convert data from one image format to another
#include <img.h>
int img_convert_data( img_format_t sformat,
const uint8_t* src,
img_format_t dformat,
uint8_t* dst,
size_t n );
- sformat
- The format of the data you are converting from (see below).
- src
- A pointer to a buffer containing the source data.
- dformat
- The format you would like to convert the data to.
- dst
- A pointer to a buffer to store the converted data. This may point to a different buffer, or it can point to the same buffer as src, as long as you've ensured that the source buffer is large enough to store the converted data (the IMG_FMT_BPL() macro can help you with this).
- n
- The number of samples to convert.
img
This function converts data from one image format to another. The conversion may be done from one buffer to another, or in place.
|
The neither the destination nor the source formats can be a palette-based format (for example IMG_FMT_PAL8 or IMG_FMT_PAL4). Both must be “direct” formats. See img_expand_getfunc() to convert a palette-based image to a direct format. |
If you are repeatedly converting data, it is better to call img_convert_getfunc() to get the conversion function, and then call the conversion function as required.
The img_format_t is an enumeration of these possible image formats:
- IMG_FMT_INVALID
- Invalid image format
- IMG_FMT_MONO
- Monochromatic bitmap with 1 bit/pixel, packing 8 pixels per byte.
- IMG_FMT_G8
- 8-bits/pixel graymap.
- IMG_FMT_PAL1
- 1-bit/pixel index into a palette of 2 entries, packing 8 pixels per byte.
- IMG_FMT_PAL4
- 4-bits/pixel index into a palette of up to 16 entries, packing 2 pixels per byte.
- IMG_FMT_PAL8
- 8-bits/pixel index into a palette of up to 256 entries.
- IMG_FMT_PKLE_RGB565
- 16-bits/pixel RGB packed into 16-bit little-endian integer type with bits 0-4 for B, 5-10 for G, and 11-15 for R.
- IMG_FMT_PKBE_RGB565
- A big-endian version of PKLE_RGB565
- IMG_FMT_PKLE_ARGB1555
- 16-bits/pixel ARGB packed into 16-bit little-endian integer type with bits 0-4 for B, 5-9 for G, 10-14 for R and most significant bit for A.
- IMG_FMT_PKBE_ARGB1555
- A big-endian version of PKLE_ARGB1555
- IMG_FMT_BGR888
- 24-bits/pixel BGR with 8 bits per channel as an ordered byte sequence.
- IMG_FMT_RGB888
- 24-bits/pixel RGB with 8 bits per channel as an ordered byte sequence.
- IMG_FMT_RGBA8888
- 32-bits/pixel RGBA with 8 bits per channel as an ordered byte sequence.
- IMG_FMT_PKLE_ARGB8888
- 32-bits/pixel ARGB packed into 32-bit little-endian integer type with byte 0 (least-significant byte) for B, byte 1 for G, byte 2 for R and byte 3 for A.
- IMG_FMT_PKBE_ARGB8888
- A big endian version of PKLE_ARGB8888
- IMG_FMT_PKLE_XRGB8888
- 24-bits/pixel BGR with 8 bits per channel as an ordered byte sequence, followed by a single byte of padding.
- IMG_FMT_PKBE_XRGB8888
- A big endian version of IMG_FMT_PKLE_XRGB8888
In addition to PKLE and PKBE variants listed above, there are PKHE and PKOE variants that make it easier to identify host-endian (HE) formats and other-endian (OE). So for example, if your code is executing on an x86 platform, IMG_FMT_PKHE_ARGB1555 equals IMG_FMT_PKLE_ARGB1555. Or on a ppcbe platform, IMG_FMT_PKOE_ARGB8888 equals IMG_FMT_PKLE_ARGB8888.
- IMG_ERR_OK
- Success.
- IMG_ERR_NOSUPPORT
- One of the formats specified is invalid.
Image library
Safety: | |
Interrupt handler |
No |
Signal handler |
No |
Thread |
No |
img_convert_getfunc(),
IMG_FMT_BPL(),
img_lib_attach()