]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7500: add switch_img_copy to clone an image
authorSeven Du <dujinfang@gmail.com>
Sat, 17 Jan 2015 17:32:17 +0000 (01:32 +0800)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:46:54 +0000 (12:46 -0500)
src/include/switch_core_video.h
src/switch_core_video.c

index c439e35ec238536e04aae8ee013700626f952c0c..a29d323f4a77ac5247748cc4e3af857e54e57613 100644 (file)
@@ -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)
 *
index 435ac324ef915025c651361d2a73fe4ed8be2240..c8cf321576d0702ef6695441e36201979fbb4bfc 100644 (file)
@@ -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