From c52d69d1739176c446eb80bfaa7b3ece62762c84 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Sun, 18 Jan 2015 01:32:17 +0800 Subject: [PATCH] FS-7500: add switch_img_copy to clone an image --- src/include/switch_core_video.h | 12 ++++++++++++ src/switch_core_video.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index c439e35ec2..a29d323f4a 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -202,6 +202,18 @@ SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t *img, unsigned int w, unsigned int h); +/*!\brief Copy image to a new image +* +* if new_img is NULL, a new image is allocated +* if new_img is not NULL but not the same size as img, +* new_img is destroyed and a new new_img is allocated +* else, copy the img data to the new_img +* +* \param[in] img Image descriptor +*/ + +SWITCH_DECLARE(void) switch_img_copy(switch_image_t *img, switch_image_t **new_img); + /*!\brief Flip the image vertically (top for bottom) * diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 435ac324ef..c8cf321576 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -73,6 +73,24 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img) *img = NULL; } +SWITCH_DECLARE(void) switch_img_copy(switch_image_t *img, switch_image_t **new_img) +{ + switch_assert(img); + + if (!img->fmt == SWITCH_IMG_FMT_I420) return; + + if (img->d_w != (*new_img)->d_w || img->d_h != (*new_img)->d_w) { + vpx_img_free((vpx_image_t *)*new_img); + } + + if (*new_img == NULL) { + *new_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, img->d_w, img->d_h, 0); + } + + switch_assert(*new_img); + memcpy((*new_img)->img_data, img->img_data, img->d_w * img->d_h * 3 / 2); +} + /* For Emacs: * Local Variables: * mode:c