Ignore:
Timestamp:
Aug 2, 2008, 2:00:51 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • pipi.c: reimplement pipi_new() without relying on the underlying codec library, so we can have several or none of them at some time.
  • sdl.c imlib.c: allow to save images that weren't created using the current codec.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/codec/imlib.c

    r2605 r2629  
    3737        return NULL;
    3838
    39     img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
    40     memset(img, 0, sizeof(pipi_image_t));
    41 
    4239    imlib_context_set_image(priv);
    43     img->w = imlib_image_get_width();
    44     img->h = imlib_image_get_height();
     40    img = pipi_new(imlib_image_get_width(), imlib_image_get_height());
    4541
    4642    img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
    47     img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
    48     img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
    49     img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
    50     img->last_modified = PIPI_PIXELS_RGBA32;
    51 
    52     img->codec_priv = (void *)priv;
    53     img->codec_format = PIPI_PIXELS_RGBA32;
    54 
    55     return img;
    56 }
    57 
    58 pipi_image_t *pipi_new_imlib2(int width, int height)
    59 {
    60     pipi_image_t *img;
    61     Imlib_Image priv = imlib_create_image(width, height);
    62 
    63     if(!priv)
    64         return NULL;
    65 
    66     img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
    67     memset(img, 0, sizeof(pipi_image_t));
    68 
    69     imlib_context_set_image(priv);
    70     img->w = imlib_image_get_width();
    71     img->h = imlib_image_get_height();
    72 
    73     img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
    74     img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
    75     img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
    76     img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
     43    img->p[PIPI_PIXELS_RGBA32].w = img->w;
     44    img->p[PIPI_PIXELS_RGBA32].h = img->h;
     45    img->p[PIPI_PIXELS_RGBA32].pitch = 4 * img->w;
    7746    img->last_modified = PIPI_PIXELS_RGBA32;
    7847
     
    8756    imlib_context_set_image(img->codec_priv);
    8857    imlib_free_image();
    89 
    90     free(img);
    9158}
    9259
    9360void pipi_save_imlib2(pipi_image_t *img, const char *name)
    9461{
     62    if(!img->codec_priv)
     63    {
     64        Imlib_Image priv = imlib_create_image(img->w, img->h);
     65        void *data;
     66
     67        imlib_context_set_image(priv);
     68        data = imlib_image_get_data();
     69
     70        /* FIXME: check pitch differences here */
     71        if(img->last_modified == PIPI_PIXELS_RGBA32)
     72        {
     73            memcpy(data, img->p[PIPI_PIXELS_RGBA32].pixels,
     74                   4 * img->w * img->h);
     75            free(img->p[PIPI_PIXELS_RGBA32].pixels);
     76        }
     77
     78        img->p[PIPI_PIXELS_RGBA32].pixels = data;
     79        img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
     80        img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
     81        img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
     82
     83        img->codec_priv = (void *)priv;
     84        img->codec_format = PIPI_PIXELS_RGBA32;
     85    }
     86
    9587    pipi_getpixels(img, img->codec_format);
    9688    imlib_context_set_image(img->codec_priv);
Note: See TracChangeset for help on using the changeset viewer.