From 66f9ce5ea4f1d90e5cb26803c98858080761ef00 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 4 Aug 2008 17:23:51 +0000 Subject: [PATCH] * pipi.c: implement pipi_copy(). git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2668 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/pipi.c | 21 +++++++++++++++++++++ pipi/pipi.h | 1 + 2 files changed, 22 insertions(+) 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 *);