Просмотр исходного кода

* pipi.h: add the PIPI_PIXELS_MASK_C pixel format for canvas boundaries.

* pipi.h: rename RGBA32 and BGR24 into RGBA_C and BGR_C.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2772 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 лет назад
Родитель
Сommit
23bd005f9c
7 измененных файлов: 75 добавлений и 73 удалений
  1. +18
    -18
      pipi/codec/imlib.c
  2. +18
    -18
      pipi/codec/opencv.c
  3. +18
    -18
      pipi/codec/sdl.c
  4. +2
    -2
      pipi/paint/floodfill.c
  5. +5
    -3
      pipi/pipi.h
  6. +12
    -12
      pipi/pixels.c
  7. +2
    -2
      test/u8tof32tou8.c

+ 18
- 18
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;


+ 18
- 18
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;


+ 18
- 18
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;


+ 2
- 2
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;


+ 5
- 3
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;



+ 12
- 12
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;


+ 2
- 2
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++)


Загрузка…
Отмена
Сохранить