diff --git a/pipi/codec/imlib.c b/pipi/codec/imlib.c index 0288825..85343c8 100644 --- a/pipi/codec/imlib.c +++ b/pipi/codec/imlib.c @@ -43,6 +43,8 @@ pipi_image_t *pipi_load_imlib2(const char *name) img->p[PIPI_PIXELS_RGBA32].w = img->w; img->p[PIPI_PIXELS_RGBA32].h = img->h; img->p[PIPI_PIXELS_RGBA32].pitch = 4 * img->w; + img->p[PIPI_PIXELS_RGBA32].bpp = 32; + img->p[PIPI_PIXELS_RGBA32].bytes = 4 * img->w * img->h; img->last_modified = PIPI_PIXELS_RGBA32; img->codec_priv = (void *)priv; @@ -79,6 +81,8 @@ void pipi_save_imlib2(pipi_image_t *img, const char *name) img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width(); img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height(); img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width(); + img->p[PIPI_PIXELS_RGBA32].bpp = 32; + img->p[PIPI_PIXELS_RGBA32].bytes = 4 * img->w * img->h; img->codec_priv = (void *)priv; img->codec_format = PIPI_PIXELS_RGBA32; diff --git a/pipi/codec/opencv.c b/pipi/codec/opencv.c index 7eac247..1086aaf 100644 --- a/pipi/codec/opencv.c +++ b/pipi/codec/opencv.c @@ -45,6 +45,8 @@ pipi_image_t *pipi_load_opencv(const char *name) img->p[PIPI_PIXELS_BGR24].w = priv->width; img->p[PIPI_PIXELS_BGR24].h = priv->height; img->p[PIPI_PIXELS_BGR24].pitch = priv->widthStep; + img->p[PIPI_PIXELS_BGR24].bpp = 24; + img->p[PIPI_PIXELS_BGR24].bytes = 3 * img->w * img->h; img->last_modified = PIPI_PIXELS_BGR24; img->codec_priv = (void *)priv; @@ -79,6 +81,8 @@ void pipi_save_opencv(pipi_image_t *img, const char *name) img->p[PIPI_PIXELS_BGR24].w = priv->width; img->p[PIPI_PIXELS_BGR24].h = priv->height; img->p[PIPI_PIXELS_BGR24].pitch = priv->widthStep; + img->p[PIPI_PIXELS_BGR24].bpp = 24; + img->p[PIPI_PIXELS_BGR24].bytes = 3 * img->w * img->h; img->codec_priv = (void *)priv; img->codec_format = PIPI_PIXELS_BGR24; diff --git a/pipi/codec/sdl.c b/pipi/codec/sdl.c index 6cf97c3..906c87b 100644 --- a/pipi/codec/sdl.c +++ b/pipi/codec/sdl.c @@ -52,6 +52,8 @@ pipi_image_t *pipi_load_sdl(const char *name) img->p[PIPI_PIXELS_RGBA32].w = priv->w; img->p[PIPI_PIXELS_RGBA32].h = priv->h; img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch; + img->p[PIPI_PIXELS_RGBA32].bpp = 32; + img->p[PIPI_PIXELS_RGBA32].bytes = 4 * img->w * img->h; img->last_modified = PIPI_PIXELS_RGBA32; img->codec_priv = (void *)priv; @@ -83,6 +85,8 @@ void pipi_save_sdl(pipi_image_t *img, const char *name) img->p[PIPI_PIXELS_RGBA32].w = priv->w; img->p[PIPI_PIXELS_RGBA32].h = priv->h; img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch; + img->p[PIPI_PIXELS_RGBA32].bpp = 32; + img->p[PIPI_PIXELS_RGBA32].bytes = 4 * img->w * img->h; img->codec_priv = (void *)priv; img->codec_format = PIPI_PIXELS_RGBA32; diff --git a/pipi/pipi.h b/pipi/pipi.h index d393ffc..708759e 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -19,6 +19,8 @@ #ifndef __PIPI_H__ #define __PIPI_H__ +#include + #ifdef __cplusplus extern "C" { @@ -53,7 +55,8 @@ pipi_format_t; typedef struct { void *pixels; - int w, h, pitch; + int w, h, pitch, bpp; + size_t bytes; } pipi_pixels_t; diff --git a/pipi/pixels.c b/pipi/pixels.c index 702ead8..fb459de 100644 --- a/pipi/pixels.c +++ b/pipi/pixels.c @@ -40,7 +40,7 @@ static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; } pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) { size_t bytes = 0; - int x, y, i; + int x, y, i, bpp = 0; if(type < 0 || type >= PIPI_PIXELS_MAX) return NULL; @@ -69,21 +69,27 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) { case PIPI_PIXELS_RGBA32: bytes = img->w * img->h * 4 * sizeof(uint8_t); + bpp = 4 * sizeof(uint8_t); break; case PIPI_PIXELS_BGR24: bytes = img->w * img->h * 3 * sizeof(uint8_t); + bpp = 3 * sizeof(uint8_t); break; case PIPI_PIXELS_RGBA_F: bytes = img->w * img->h * 4 * sizeof(float); + bpp = 4 * sizeof(float); break; case PIPI_PIXELS_Y_F: bytes = img->w * img->h * sizeof(float); + bpp = sizeof(float); break; default: return NULL; } img->p[type].pixels = malloc(bytes); + img->p[type].bytes = bytes; + img->p[type].bpp = bpp; } /* Convert pixels */