diff --git a/pipi/pipi.c b/pipi/pipi.c index 0c45ee2..21b7f84 100644 --- a/pipi/pipi.c +++ b/pipi/pipi.c @@ -52,3 +52,24 @@ pipi_image_t *pipi_new(int w, int h) return img; } +pipi_image_t *pipi_copy(pipi_image_t *src) +{ + pipi_image_t *dst = pipi_new(src->w, src->h); + + if(src->last_modified != PIPI_PIXELS_UNINITIALISED) + { + pipi_pixels_t *srcp, *dstp; + + srcp = &src->p[src->last_modified]; + dstp = &dst->p[src->last_modified]; + + memcpy(dstp, srcp, sizeof(pipi_pixels_t)); + dstp->pixels = malloc(dstp->bytes); + memcpy(dstp->pixels, srcp->pixels, dstp->bytes); + + dst->last_modified = src->last_modified; + } + + return dst; +} + diff --git a/pipi/pipi.h b/pipi/pipi.h index 708759e..cd50168 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -66,6 +66,7 @@ typedef struct pipi_image pipi_image_t; extern pipi_image_t *pipi_load(const char *); extern pipi_image_t *pipi_new(int, int); +extern pipi_image_t *pipi_copy(pipi_image_t *); extern void pipi_free(pipi_image_t *); extern void pipi_save(pipi_image_t *, const char *);