diff --git a/pipi/codec/imlib.c b/pipi/codec/imlib.c index 45c5d35..1758528 100644 --- a/pipi/codec/imlib.c +++ b/pipi/codec/imlib.c @@ -39,16 +39,16 @@ pipi_image_t *pipi_load_imlib2(const char *name) imlib_context_set_image(priv); img = pipi_new(imlib_image_get_width(), imlib_image_get_height()); - img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data(); - 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->p[PIPI_PIXELS_RGBA_C].pixels = imlib_image_get_data(); + img->p[PIPI_PIXELS_RGBA_C].w = img->w; + img->p[PIPI_PIXELS_RGBA_C].h = img->h; + img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * img->w; + img->p[PIPI_PIXELS_RGBA_C].bpp = 32; + img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h; + img->last_modified = PIPI_PIXELS_RGBA_C; img->codec_priv = (void *)priv; - img->codec_format = PIPI_PIXELS_RGBA32; + img->codec_format = PIPI_PIXELS_RGBA_C; img->wrap = 0; img->u8 = 1; @@ -73,22 +73,22 @@ void pipi_save_imlib2(pipi_image_t *img, const char *name) data = imlib_image_get_data(); /* FIXME: check pitch differences here */ - if(img->last_modified == PIPI_PIXELS_RGBA32) + if(img->last_modified == PIPI_PIXELS_RGBA_C) { - memcpy(data, img->p[PIPI_PIXELS_RGBA32].pixels, + memcpy(data, img->p[PIPI_PIXELS_RGBA_C].pixels, 4 * img->w * img->h); - free(img->p[PIPI_PIXELS_RGBA32].pixels); + free(img->p[PIPI_PIXELS_RGBA_C].pixels); } - img->p[PIPI_PIXELS_RGBA32].pixels = data; - 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->p[PIPI_PIXELS_RGBA_C].pixels = data; + img->p[PIPI_PIXELS_RGBA_C].w = imlib_image_get_width(); + img->p[PIPI_PIXELS_RGBA_C].h = imlib_image_get_height(); + img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * imlib_image_get_width(); + img->p[PIPI_PIXELS_RGBA_C].bpp = 32; + img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h; img->codec_priv = (void *)priv; - img->codec_format = PIPI_PIXELS_RGBA32; + img->codec_format = PIPI_PIXELS_RGBA_C; img->wrap = 0; img->u8 = 1; diff --git a/pipi/codec/opencv.c b/pipi/codec/opencv.c index 1b212cf..956025d 100644 --- a/pipi/codec/opencv.c +++ b/pipi/codec/opencv.c @@ -41,16 +41,16 @@ pipi_image_t *pipi_load_opencv(const char *name) img = pipi_new(priv->width, priv->height); - img->p[PIPI_PIXELS_BGR24].pixels = priv->imageData; - 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->p[PIPI_PIXELS_BGR_C].pixels = priv->imageData; + img->p[PIPI_PIXELS_BGR_C].w = priv->width; + img->p[PIPI_PIXELS_BGR_C].h = priv->height; + img->p[PIPI_PIXELS_BGR_C].pitch = priv->widthStep; + img->p[PIPI_PIXELS_BGR_C].bpp = 24; + img->p[PIPI_PIXELS_BGR_C].bytes = 3 * img->w * img->h; + img->last_modified = PIPI_PIXELS_BGR_C; img->codec_priv = (void *)priv; - img->codec_format = PIPI_PIXELS_BGR24; + img->codec_format = PIPI_PIXELS_BGR_C; img->wrap = 0; img->u8 = 1; @@ -73,22 +73,22 @@ void pipi_save_opencv(pipi_image_t *img, const char *name) IPL_DEPTH_8U, 3); /* FIXME: check pitch differences here */ - if(img->last_modified == PIPI_PIXELS_BGR24) + if(img->last_modified == PIPI_PIXELS_BGR_C) { - memcpy(priv->imageData, img->p[PIPI_PIXELS_BGR24].pixels, + memcpy(priv->imageData, img->p[PIPI_PIXELS_BGR_C].pixels, 3 * img->w * img->h); - free(img->p[PIPI_PIXELS_BGR24].pixels); + free(img->p[PIPI_PIXELS_BGR_C].pixels); } - img->p[PIPI_PIXELS_BGR24].pixels = priv->imageData; - 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->p[PIPI_PIXELS_BGR_C].pixels = priv->imageData; + img->p[PIPI_PIXELS_BGR_C].w = priv->width; + img->p[PIPI_PIXELS_BGR_C].h = priv->height; + img->p[PIPI_PIXELS_BGR_C].pitch = priv->widthStep; + img->p[PIPI_PIXELS_BGR_C].bpp = 24; + img->p[PIPI_PIXELS_BGR_C].bytes = 3 * img->w * img->h; img->codec_priv = (void *)priv; - img->codec_format = PIPI_PIXELS_BGR24; + img->codec_format = PIPI_PIXELS_BGR_C; img->wrap = 0; img->u8 = 1; diff --git a/pipi/codec/sdl.c b/pipi/codec/sdl.c index f096194..30d1f39 100644 --- a/pipi/codec/sdl.c +++ b/pipi/codec/sdl.c @@ -48,16 +48,16 @@ pipi_image_t *pipi_load_sdl(const char *name) img = pipi_new(priv->w, priv->h); - img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels; - 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->p[PIPI_PIXELS_RGBA_C].pixels = priv->pixels; + img->p[PIPI_PIXELS_RGBA_C].w = priv->w; + img->p[PIPI_PIXELS_RGBA_C].h = priv->h; + img->p[PIPI_PIXELS_RGBA_C].pitch = priv->pitch; + img->p[PIPI_PIXELS_RGBA_C].bpp = 32; + img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h; + img->last_modified = PIPI_PIXELS_RGBA_C; img->codec_priv = (void *)priv; - img->codec_format = PIPI_PIXELS_RGBA32; + img->codec_format = PIPI_PIXELS_RGBA_C; img->wrap = 0; img->u8 = 1; @@ -77,22 +77,22 @@ void pipi_save_sdl(pipi_image_t *img, const char *name) SDL_Surface *priv = create_32bpp_surface(img->w, img->h); /* FIXME: check pitch differences here */ - if(img->last_modified == PIPI_PIXELS_RGBA32) + if(img->last_modified == PIPI_PIXELS_RGBA_C) { - memcpy(priv->pixels, img->p[PIPI_PIXELS_RGBA32].pixels, + memcpy(priv->pixels, img->p[PIPI_PIXELS_RGBA_C].pixels, priv->pitch * priv->h); - free(img->p[PIPI_PIXELS_RGBA32].pixels); + free(img->p[PIPI_PIXELS_RGBA_C].pixels); } - img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels; - 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->p[PIPI_PIXELS_RGBA_C].pixels = priv->pixels; + img->p[PIPI_PIXELS_RGBA_C].w = priv->w; + img->p[PIPI_PIXELS_RGBA_C].h = priv->h; + img->p[PIPI_PIXELS_RGBA_C].pitch = priv->pitch; + img->p[PIPI_PIXELS_RGBA_C].bpp = 32; + img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h; img->codec_priv = (void *)priv; - img->codec_format = PIPI_PIXELS_RGBA32; + img->codec_format = PIPI_PIXELS_RGBA_C; img->wrap = 0; img->u8 = 1; diff --git a/pipi/paint/floodfill.c b/pipi/paint/floodfill.c index 1aa1bd8..2b78601 100644 --- a/pipi/paint/floodfill.c +++ b/pipi/paint/floodfill.c @@ -78,12 +78,12 @@ int pipi_flood_fill(pipi_image_t *src, (px < 0) || (py < 0)) return -1; - if(src->last_modified == PIPI_PIXELS_RGBA32) { + if(src->last_modified == PIPI_PIXELS_RGBA_C) { uint32_t *dstdata; unsigned char nr, ng, nb, na; /* Get ARGB32 pointer */ - dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA32); + dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_C); dstdata = (uint32_t *)dstp->pixels; nr = r*255.0f; diff --git a/pipi/pipi.h b/pipi/pipi.h index 88bbb37..a2a32ea 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -43,12 +43,14 @@ typedef enum { PIPI_PIXELS_UNINITIALISED = -1, - PIPI_PIXELS_RGBA32 = 0, - PIPI_PIXELS_BGR24 = 1, + PIPI_PIXELS_RGBA_C = 0, + PIPI_PIXELS_BGR_C = 1, PIPI_PIXELS_RGBA_F = 2, PIPI_PIXELS_Y_F = 3, - PIPI_PIXELS_MAX = 4 + PIPI_PIXELS_MASK_C = 4, + + PIPI_PIXELS_MAX = 5 } pipi_format_t; diff --git a/pipi/pixels.c b/pipi/pixels.c index 95b2196..3f11837 100644 --- a/pipi/pixels.c +++ b/pipi/pixels.c @@ -49,17 +49,17 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) return &img->p[type]; /* Preliminary conversions */ - if(img->last_modified == PIPI_PIXELS_RGBA32 + if(img->last_modified == PIPI_PIXELS_RGBA_C && type == PIPI_PIXELS_Y_F) pipi_getpixels(img, PIPI_PIXELS_RGBA_F); - else if(img->last_modified == PIPI_PIXELS_BGR24 + else if(img->last_modified == PIPI_PIXELS_BGR_C && type == PIPI_PIXELS_Y_F) pipi_getpixels(img, PIPI_PIXELS_RGBA_F); else if(img->last_modified == PIPI_PIXELS_Y_F - && type == PIPI_PIXELS_RGBA32) + && type == PIPI_PIXELS_RGBA_C) pipi_getpixels(img, PIPI_PIXELS_RGBA_F); else if(img->last_modified == PIPI_PIXELS_Y_F - && type == PIPI_PIXELS_BGR24) + && type == PIPI_PIXELS_BGR_C) pipi_getpixels(img, PIPI_PIXELS_RGBA_F); /* Allocate pixels if necessary */ @@ -67,11 +67,11 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) { switch(type) { - case PIPI_PIXELS_RGBA32: + case PIPI_PIXELS_RGBA_C: bytes = img->w * img->h * 4 * sizeof(uint8_t); bpp = 4 * sizeof(uint8_t); break; - case PIPI_PIXELS_BGR24: + case PIPI_PIXELS_BGR_C: bytes = img->w * img->h * 3 * sizeof(uint8_t); bpp = 3 * sizeof(uint8_t); break; @@ -95,10 +95,10 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) } /* Convert pixels */ - if(img->last_modified == PIPI_PIXELS_RGBA32 + if(img->last_modified == PIPI_PIXELS_RGBA_C && type == PIPI_PIXELS_RGBA_F) { - uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_RGBA32].pixels; + uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_RGBA_C].pixels; float *dest = (float *)img->p[type].pixels; init_tables(); @@ -109,10 +109,10 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) dest[4 * (y * img->w + x) + i] = u8tof32(src[4 * (y * img->w + x) + i]); } - else if(img->last_modified == PIPI_PIXELS_BGR24 + else if(img->last_modified == PIPI_PIXELS_BGR_C && type == PIPI_PIXELS_RGBA_F) { - uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_BGR24].pixels; + uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_BGR_C].pixels; float *dest = (float *)img->p[type].pixels; init_tables(); @@ -130,7 +130,7 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) } } else if(img->last_modified == PIPI_PIXELS_RGBA_F - && type == PIPI_PIXELS_RGBA32) + && type == PIPI_PIXELS_RGBA_C) { float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels; uint8_t *dest = (uint8_t *)img->p[type].pixels; @@ -166,7 +166,7 @@ pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type) } } else if(img->last_modified == PIPI_PIXELS_RGBA_F - && type == PIPI_PIXELS_BGR24) + && type == PIPI_PIXELS_BGR_C) { float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels; uint8_t *dest = (uint8_t *)img->p[type].pixels; diff --git a/test/u8tof32tou8.c b/test/u8tof32tou8.c index 528fb83..d51ddf4 100644 --- a/test/u8tof32tou8.c +++ b/test/u8tof32tou8.c @@ -35,11 +35,11 @@ int main(int argc, char *argv[]) img1 = pipi_load("mona.png"); img2 = pipi_load("mona.png"); - pix1 = pipi_getpixels(img1, PIPI_PIXELS_RGBA32); + pix1 = pipi_getpixels(img1, PIPI_PIXELS_RGBA_C); data1 = (uint32_t *)pix1->pixels; pipi_getpixels(img2, PIPI_PIXELS_RGBA_F); - pix2 = pipi_getpixels(img2, PIPI_PIXELS_RGBA32); + pix2 = pipi_getpixels(img2, PIPI_PIXELS_RGBA_C); data2 = (uint32_t *)pix2->pixels; for(y = 0; y < pix1->h; y++)