FS-7500: add switch_img_copy to clone an image

This commit is contained in:
Seven Du 2015-01-18 01:32:17 +08:00 committed by Michael Jerris
parent d026624631
commit c52d69d173
2 changed files with 30 additions and 0 deletions

View File

@ -202,6 +202,18 @@ SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t *img,
unsigned int w, unsigned int w,
unsigned int h); 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) /*!\brief Flip the image vertically (top for bottom)
* *

View File

@ -73,6 +73,24 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img)
*img = NULL; *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: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c