Commit 4939e86013 for freeswitch.com

commit 4939e860135667c029602e5181f4cc156f5a52de
Author: Andrey Volk <andywolk@gmail.com>
Date:   Thu Aug 11 01:13:05 2022 +0300

    [Core] Introduce switch_image.c

diff --git a/Makefile.am b/Makefile.am
index 7448ee128a..71e57cd006 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -295,7 +295,6 @@ library_include_HEADERS = \
 	src/include/switch_json.h \
 	src/include/switch_utf8.h \
 	src/include/switch_msrp.h \
-	src/include/switch_vpx.h \
 	src/include/switch_vad.h \
 	libs/libteletone/src/libteletone_detect.h \
 	libs/libteletone/src/libteletone_generate.h \
@@ -352,6 +351,7 @@ libfreeswitch_la_SOURCES = \
 	src/switch_rtp.c \
 	src/switch_jitterbuffer.c \
 	src/switch_estimators.c \
+	src/switch_image.c \
 	src/switch_ivr_bridge.c \
 	src/switch_ivr_originate.c \
 	src/switch_ivr_async.c \
diff --git a/libs/win32/libvpx/include_x64/vpx/vpx_config.h b/libs/win32/libvpx/include_x64/vpx/vpx_config.h
new file mode 100644
index 0000000000..ebb1134735
--- /dev/null
+++ b/libs/win32/libvpx/include_x64/vpx/vpx_config.h
@@ -0,0 +1,105 @@
+/* Copyright (c) 2011 The WebM project authors. All Rights Reserved. */
+/*  */
+/* Use of this source code is governed by a BSD-style license */
+/* that can be found in the LICENSE file in the root of the source */
+/* tree. An additional intellectual property rights grant can be found */
+/* in the file PATENTS.  All contributing project authors may */
+/* be found in the AUTHORS file in the root of the source tree. */
+/* This file automatically generated by configure. Do not edit! */
+#ifndef VPX_CONFIG_H
+#define VPX_CONFIG_H
+#define RESTRICT
+#define INLINE      __inline
+#define VPX_ARCH_ARM 0
+#define VPX_ARCH_MIPS 0
+#define VPX_ARCH_X86 0
+#define VPX_ARCH_X86_64 1
+#define VPX_ARCH_PPC 0
+#define VPX_ARCH_LOONGARCH 0
+#define HAVE_NEON 0
+#define HAVE_NEON_ASM 0
+#define HAVE_MIPS32 0
+#define HAVE_DSPR2 0
+#define HAVE_MSA 0
+#define HAVE_MIPS64 0
+#define HAVE_MMX 1
+#define HAVE_SSE 1
+#define HAVE_SSE2 1
+#define HAVE_SSE3 1
+#define HAVE_SSSE3 1
+#define HAVE_SSE4_1 1
+#define HAVE_AVX 1
+#define HAVE_AVX2 1
+#define HAVE_AVX512 1
+#define HAVE_VSX 0
+#define HAVE_MMI 0
+#define HAVE_LSX 0
+#define HAVE_LASX 0
+#define HAVE_VPX_PORTS 1
+#define HAVE_PTHREAD_H 0
+#define HAVE_UNISTD_H 0
+#define CONFIG_DEPENDENCY_TRACKING 1
+#define CONFIG_EXTERNAL_BUILD 1
+#define CONFIG_INSTALL_DOCS 0
+#define CONFIG_INSTALL_BINS 0
+#define CONFIG_INSTALL_LIBS 1
+#define CONFIG_INSTALL_SRCS 0
+#define CONFIG_DEBUG 0
+#define CONFIG_GPROF 0
+#define CONFIG_GCOV 0
+#define CONFIG_RVCT 0
+#define CONFIG_GCC 0
+#define CONFIG_MSVS 1
+#define CONFIG_PIC 1
+#define CONFIG_BIG_ENDIAN 0
+#define CONFIG_CODEC_SRCS 0
+#define CONFIG_DEBUG_LIBS 0
+#define CONFIG_DEQUANT_TOKENS 0
+#define CONFIG_DC_RECON 0
+#define CONFIG_RUNTIME_CPU_DETECT 1
+#define CONFIG_POSTPROC 1
+#define CONFIG_VP9_POSTPROC 0
+#define CONFIG_MULTITHREAD 1
+#define CONFIG_INTERNAL_STATS 0
+#define CONFIG_VP8_ENCODER 1
+#define CONFIG_VP8_DECODER 1
+#define CONFIG_VP9_ENCODER 1
+#define CONFIG_VP9_DECODER 1
+#define CONFIG_VP8 1
+#define CONFIG_VP9 1
+#define CONFIG_ENCODERS 1
+#define CONFIG_DECODERS 1
+#define CONFIG_STATIC_MSVCRT 1
+#define CONFIG_SPATIAL_RESAMPLING 1
+#define CONFIG_REALTIME_ONLY 0
+#define CONFIG_ONTHEFLY_BITPACKING 0
+#define CONFIG_ERROR_CONCEALMENT 0
+#define CONFIG_SHARED 0
+#define CONFIG_STATIC 1
+#define CONFIG_SMALL 0
+#define CONFIG_POSTPROC_VISUALIZER 0
+#define CONFIG_OS_SUPPORT 1
+#define CONFIG_UNIT_TESTS 0
+#define CONFIG_WEBM_IO 1
+#define CONFIG_LIBYUV 1
+#define CONFIG_DECODE_PERF_TESTS 0
+#define CONFIG_ENCODE_PERF_TESTS 0
+#define CONFIG_MULTI_RES_ENCODING 0
+#define CONFIG_TEMPORAL_DENOISING 1
+#define CONFIG_VP9_TEMPORAL_DENOISING 0
+#define CONFIG_CONSISTENT_RECODE 0
+#define CONFIG_COEFFICIENT_RANGE_CHECKING 0
+#define CONFIG_VP9_HIGHBITDEPTH 0
+#define CONFIG_BETTER_HW_COMPATIBILITY 0
+#define CONFIG_EXPERIMENTAL 0
+#define CONFIG_SIZE_LIMIT 1
+#define CONFIG_ALWAYS_ADJUST_BPM 0
+#define CONFIG_BITSTREAM_DEBUG 0
+#define CONFIG_MISMATCH_DEBUG 0
+#define CONFIG_FP_MB_STATS 0
+#define CONFIG_EMULATE_HARDWARE 0
+#define CONFIG_NON_GREEDY_MV 0
+#define CONFIG_RATE_CTRL 0
+#define DECODE_WIDTH_LIMIT 16384
+#define DECODE_HEIGHT_LIMIT 16384
+#endif /* VPX_CONFIG_H */
diff --git a/libs/win32/libvpx/include_x86/vpx/vpx_config.h b/libs/win32/libvpx/include_x86/vpx/vpx_config.h
new file mode 100644
index 0000000000..4749e162a2
--- /dev/null
+++ b/libs/win32/libvpx/include_x86/vpx/vpx_config.h
@@ -0,0 +1,105 @@
+/* Copyright (c) 2011 The WebM project authors. All Rights Reserved. */
+/*  */
+/* Use of this source code is governed by a BSD-style license */
+/* that can be found in the LICENSE file in the root of the source */
+/* tree. An additional intellectual property rights grant can be found */
+/* in the file PATENTS.  All contributing project authors may */
+/* be found in the AUTHORS file in the root of the source tree. */
+/* This file automatically generated by configure. Do not edit! */
+#ifndef VPX_CONFIG_H
+#define VPX_CONFIG_H
+#define RESTRICT
+#define INLINE      __inline
+#define VPX_ARCH_ARM 0
+#define VPX_ARCH_MIPS 0
+#define VPX_ARCH_X86 1
+#define VPX_ARCH_X86_64 0
+#define VPX_ARCH_PPC 0
+#define VPX_ARCH_LOONGARCH 0
+#define HAVE_NEON 0
+#define HAVE_NEON_ASM 0
+#define HAVE_MIPS32 0
+#define HAVE_DSPR2 0
+#define HAVE_MSA 0
+#define HAVE_MIPS64 0
+#define HAVE_MMX 1
+#define HAVE_SSE 1
+#define HAVE_SSE2 1
+#define HAVE_SSE3 1
+#define HAVE_SSSE3 1
+#define HAVE_SSE4_1 1
+#define HAVE_AVX 1
+#define HAVE_AVX2 1
+#define HAVE_AVX512 1
+#define HAVE_VSX 0
+#define HAVE_MMI 0
+#define HAVE_LSX 0
+#define HAVE_LASX 0
+#define HAVE_VPX_PORTS 1
+#define HAVE_PTHREAD_H 0
+#define HAVE_UNISTD_H 0
+#define CONFIG_DEPENDENCY_TRACKING 1
+#define CONFIG_EXTERNAL_BUILD 1
+#define CONFIG_INSTALL_DOCS 0
+#define CONFIG_INSTALL_BINS 0
+#define CONFIG_INSTALL_LIBS 1
+#define CONFIG_INSTALL_SRCS 0
+#define CONFIG_DEBUG 0
+#define CONFIG_GPROF 0
+#define CONFIG_GCOV 0
+#define CONFIG_RVCT 0
+#define CONFIG_GCC 0
+#define CONFIG_MSVS 1
+#define CONFIG_PIC 1
+#define CONFIG_BIG_ENDIAN 0
+#define CONFIG_CODEC_SRCS 0
+#define CONFIG_DEBUG_LIBS 0
+#define CONFIG_DEQUANT_TOKENS 0
+#define CONFIG_DC_RECON 0
+#define CONFIG_RUNTIME_CPU_DETECT 1
+#define CONFIG_POSTPROC 1
+#define CONFIG_VP9_POSTPROC 0
+#define CONFIG_MULTITHREAD 1
+#define CONFIG_INTERNAL_STATS 0
+#define CONFIG_VP8_ENCODER 1
+#define CONFIG_VP8_DECODER 1
+#define CONFIG_VP9_ENCODER 1
+#define CONFIG_VP9_DECODER 1
+#define CONFIG_VP8 1
+#define CONFIG_VP9 1
+#define CONFIG_ENCODERS 1
+#define CONFIG_DECODERS 1
+#define CONFIG_STATIC_MSVCRT 1
+#define CONFIG_SPATIAL_RESAMPLING 1
+#define CONFIG_REALTIME_ONLY 0
+#define CONFIG_ONTHEFLY_BITPACKING 0
+#define CONFIG_ERROR_CONCEALMENT 0
+#define CONFIG_SHARED 0
+#define CONFIG_STATIC 1
+#define CONFIG_SMALL 0
+#define CONFIG_POSTPROC_VISUALIZER 0
+#define CONFIG_OS_SUPPORT 1
+#define CONFIG_UNIT_TESTS 0
+#define CONFIG_WEBM_IO 1
+#define CONFIG_LIBYUV 1
+#define CONFIG_DECODE_PERF_TESTS 0
+#define CONFIG_ENCODE_PERF_TESTS 0
+#define CONFIG_MULTI_RES_ENCODING 0
+#define CONFIG_TEMPORAL_DENOISING 1
+#define CONFIG_VP9_TEMPORAL_DENOISING 0
+#define CONFIG_CONSISTENT_RECODE 0
+#define CONFIG_COEFFICIENT_RANGE_CHECKING 0
+#define CONFIG_VP9_HIGHBITDEPTH 0
+#define CONFIG_BETTER_HW_COMPATIBILITY 0
+#define CONFIG_EXPERIMENTAL 0
+#define CONFIG_SIZE_LIMIT 1
+#define CONFIG_ALWAYS_ADJUST_BPM 0
+#define CONFIG_BITSTREAM_DEBUG 0
+#define CONFIG_MISMATCH_DEBUG 0
+#define CONFIG_FP_MB_STATS 0
+#define CONFIG_EMULATE_HARDWARE 0
+#define CONFIG_NON_GREEDY_MV 0
+#define CONFIG_RATE_CTRL 0
+#define DECODE_WIDTH_LIMIT 16384
+#define DECODE_HEIGHT_LIMIT 16384
+#endif /* VPX_CONFIG_H */
diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h
index f65c322d30..553d2e553a 100644
--- a/src/include/switch_core_video.h
+++ b/src/include/switch_core_video.h
@@ -124,14 +124,6 @@ typedef struct {
 	double z;
 } switch_xyz_color_t;

-/**\brief Representation of a rectangle on a surface */
-typedef struct switch_image_rect {
-	unsigned int x; /**< leftmost column */
-	unsigned int y; /**< topmost row */
-	unsigned int w; /**< width */
-	unsigned int h; /**< height */
-} switch_image_rect_t;
-
 typedef enum {
 	SWITCH_CONVERT_FMT_YUYV = 0
 } switch_convert_fmt_t;
@@ -202,26 +194,6 @@ SWITCH_DECLARE(switch_image_t *)switch_img_wrap(switch_image_t  *img,
 						unsigned int align,
 						unsigned char *img_data);

-
-/*!\brief Set the rectangle identifying the displayed portion of the image
-*
-* Updates the displayed rectangle (aka viewport) on the image surface to
-* match the specified coordinates and size.
-*
-* \param[in]    img       Image descriptor
-* \param[in]    x         leftmost column
-* \param[in]    y         topmost row
-* \param[in]    w         width
-* \param[in]    h         height
-*
-* \return 0 if the requested rectangle is valid, nonzero otherwise.
-*/
-SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t  *img,
-				   unsigned int  x,
-				   unsigned int  y,
-				   unsigned int  w,
-				   unsigned int  h);
-
 /*!\brief patch a small img to a big IMG at position x,y
 *
 * Both IMG and img must be non-NULL
diff --git a/src/include/switch_image.h b/src/include/switch_image.h
index 83cb19126a..0b6a59fcd4 100644
--- a/src/include/switch_image.h
+++ b/src/include/switch_image.h
@@ -12,8 +12,8 @@
  * \brief Describes the vpx image descriptor and associated operations
  *
  */
-#ifndef VPX_VPX_VPX_IMAGE_H_
-#define VPX_VPX_VPX_IMAGE_H_
+#ifndef SWITCH_IMAGE_H
+#define SWITCH_IMAGE_H

 #ifdef __cplusplus
 extern "C" {
@@ -27,68 +27,59 @@ extern "C" {
  * types, removing or reassigning enums, adding/removing/rearranging
  * fields to structures
  */
-#define VPX_IMAGE_ABI_VERSION (4) /**<\hideinitializer*/
+#define SWITCH_IMAGE_ABI_VERSION (5) /**<\hideinitializer*/

-#define VPX_IMG_FMT_PLANAR 0x100       /**< Image is a planar format. */
-#define VPX_IMG_FMT_UV_FLIP 0x200      /**< V plane precedes U in memory. */
-#define VPX_IMG_FMT_HAS_ALPHA 0x400    /**< Image has an alpha channel. */
-#define VPX_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */
+#define SWITCH_IMG_FMT_PLANAR 0x100       /**< Image is a planar format. */
+#define SWITCH_IMG_FMT_UV_FLIP 0x200      /**< V plane precedes U in memory. */
+#define SWITCH_IMG_FMT_HAS_ALPHA 0x400    /**< Image has an alpha channel. */
+#define SWITCH_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */

 /*!\brief List of supported image formats */
-typedef enum vpx_img_fmt {
-  VPX_IMG_FMT_NONE,
-  VPX_IMG_FMT_RGB24,     /**< 24 bit per pixel packed RGB */
-  VPX_IMG_FMT_RGB32,     /**< 32 bit per pixel packed 0RGB */
-  VPX_IMG_FMT_RGB565,    /**< 16 bit per pixel, 565 */
-  VPX_IMG_FMT_RGB555,    /**< 16 bit per pixel, 555 */
-  VPX_IMG_FMT_UYVY,      /**< UYVY packed YUV */
-  VPX_IMG_FMT_YUY2,      /**< YUYV packed YUV */
-  VPX_IMG_FMT_YVYU,      /**< YVYU packed YUV */
-  VPX_IMG_FMT_BGR24,     /**< 24 bit per pixel packed BGR */
-  VPX_IMG_FMT_RGB32_LE,  /**< 32 bit packed BGR0 */
-  VPX_IMG_FMT_ARGB,      /**< 32 bit packed ARGB, alpha=255 */
-  VPX_IMG_FMT_ARGB_LE,   /**< 32 bit packed BGRA, alpha=255 */
-  VPX_IMG_FMT_RGB565_LE, /**< 16 bit per pixel, gggbbbbb rrrrrggg */
-  VPX_IMG_FMT_RGB555_LE, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */
-  VPX_IMG_FMT_YV12 =
-      VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */
-  VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2,
-  VPX_IMG_FMT_VPXYV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP |
-                        3, /** < planar 4:2:0 format with vpx color space */
-  VPX_IMG_FMT_VPXI420 = VPX_IMG_FMT_PLANAR | 4,
-  VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5,
-  VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6,
-  VPX_IMG_FMT_I440 = VPX_IMG_FMT_PLANAR | 7,
-  VPX_IMG_FMT_444A = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_HAS_ALPHA | 6,
-  VPX_IMG_FMT_I42016 = VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH,
-  VPX_IMG_FMT_I42216 = VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH,
-  VPX_IMG_FMT_I44416 = VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH,
-  VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH
-} vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */
+typedef enum switch_img_fmt {
+  SWITCH_IMG_FMT_NONE,
+  SWITCH_IMG_FMT_GD = SWITCH_IMG_FMT_NONE, /* experimental */
+  SWITCH_IMG_FMT_RGB24,     /**< 24 bit per pixel packed RGB */
+  SWITCH_IMG_FMT_YUY2,      /**< YUYV packed YUV */
+  SWITCH_IMG_FMT_BGR24,     /**< 24 bit per pixel packed BGR */
+  SWITCH_IMG_FMT_ARGB,      /**< 32 bit packed ARGB, alpha=255 */
+  SWITCH_IMG_FMT_ARGB_LE,   /**< 32 bit packed BGRA, alpha=255 */
+  SWITCH_IMG_FMT_YV12 =
+      SWITCH_IMG_FMT_PLANAR | SWITCH_IMG_FMT_UV_FLIP | 1, /**< planar YVU */
+  SWITCH_IMG_FMT_I420 = SWITCH_IMG_FMT_PLANAR | 2,
+  SWITCH_IMG_FMT_I422 = SWITCH_IMG_FMT_PLANAR | 5,
+  SWITCH_IMG_FMT_I444 = SWITCH_IMG_FMT_PLANAR | 6,
+  SWITCH_IMG_FMT_I440 = SWITCH_IMG_FMT_PLANAR | 7,
+  SWITCH_IMG_FMT_NV12 = SWITCH_IMG_FMT_PLANAR | 9,
+  SWITCH_IMG_FMT_444A = SWITCH_IMG_FMT_PLANAR | SWITCH_IMG_FMT_HAS_ALPHA | 6,
+  SWITCH_IMG_FMT_I42016 = SWITCH_IMG_FMT_I420 | SWITCH_IMG_FMT_HIGHBITDEPTH,
+  SWITCH_IMG_FMT_I42216 = SWITCH_IMG_FMT_I422 | SWITCH_IMG_FMT_HIGHBITDEPTH,
+  SWITCH_IMG_FMT_I44416 = SWITCH_IMG_FMT_I444 | SWITCH_IMG_FMT_HIGHBITDEPTH,
+  SWITCH_IMG_FMT_I44016 = SWITCH_IMG_FMT_I440 | SWITCH_IMG_FMT_HIGHBITDEPTH
+} switch_img_fmt_t; /**< alias for enum vpx_img_fmt */

 /*!\brief List of supported color spaces */
-typedef enum vpx_color_space {
-  VPX_CS_UNKNOWN = 0,   /**< Unknown */
-  VPX_CS_BT_601 = 1,    /**< BT.601 */
-  VPX_CS_BT_709 = 2,    /**< BT.709 */
-  VPX_CS_SMPTE_170 = 3, /**< SMPTE.170 */
-  VPX_CS_SMPTE_240 = 4, /**< SMPTE.240 */
-  VPX_CS_BT_2020 = 5,   /**< BT.2020 */
-  VPX_CS_RESERVED = 6,  /**< Reserved */
-  VPX_CS_SRGB = 7       /**< sRGB */
-} vpx_color_space_t;    /**< alias for enum vpx_color_space */
+typedef enum switch_color_space {
+  SWITCH_CS_UNKNOWN = 0,   /**< Unknown */
+  SWITCH_CS_BT_601 = 1,    /**< BT.601 */
+  SWITCH_CS_BT_709 = 2,    /**< BT.709 */
+  SWITCH_CS_SMPTE_170 = 3, /**< SMPTE.170 */
+  SWITCH_CS_SMPTE_240 = 4, /**< SMPTE.240 */
+  SWITCH_CS_BT_2020 = 5,   /**< BT.2020 */
+  SWITCH_CS_RESERVED = 6,  /**< Reserved */
+  SWITCH_CS_SRGB = 7       /**< sRGB */
+} switch_color_space_t;    /**< alias for enum vpx_color_space */

 /*!\brief List of supported color range */
-typedef enum vpx_color_range {
-  VPX_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */
-  VPX_CR_FULL_RANGE = 1    /**< YUV/RGB [0..255] */
-} vpx_color_range_t;       /**< alias for enum vpx_color_range */
+typedef enum switch_color_range {
+  SWITCH_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */
+  SWITCH_CR_FULL_RANGE = 1    /**< YUV/RGB [0..255] */
+} switch_color_range_t;       /**< alias for enum vpx_color_range */

 /**\brief Image Descriptor */
-typedef struct vpx_image {
-  vpx_img_fmt_t fmt;       /**< Image Format */
-  vpx_color_space_t cs;    /**< Color Space */
-  vpx_color_range_t range; /**< Color Range */
+typedef struct switch_image {
+  switch_img_fmt_t fmt;       /**< Image Format */
+  switch_color_space_t cs;    /**< Color Space */
+  switch_color_range_t range; /**< Color Range */

   /* Image storage dimensions */
   unsigned int w;         /**< Stored image width */
@@ -108,11 +99,11 @@ typedef struct vpx_image {
   unsigned int y_chroma_shift; /**< subsampling order, Y */

 /* Image data pointers. */
-#define VPX_PLANE_PACKED 0  /**< To be used for all packed formats */
-#define VPX_PLANE_Y 0       /**< Y (Luminance) plane */
-#define VPX_PLANE_U 1       /**< U (Chroma) plane */
-#define VPX_PLANE_V 2       /**< V (Chroma) plane */
-#define VPX_PLANE_ALPHA 3   /**< A (Transparency) plane */
+#define SWITCH_PLANE_PACKED 0  /**< To be used for all packed formats */
+#define SWITCH_PLANE_Y 0       /**< Y (Luminance) plane */
+#define SWITCH_PLANE_U 1       /**< U (Chroma) plane */
+#define SWITCH_PLANE_V 2       /**< V (Chroma) plane */
+#define SWITCH_PLANE_ALPHA 3   /**< A (Transparency) plane */
   unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */
   int stride[4];            /**< stride between rows for each plane */

@@ -129,15 +120,15 @@ typedef struct vpx_image {
   int self_allocd;         /**< private */

   void *fb_priv; /**< Frame buffer data associated with the image. */
-} vpx_image_t;   /**< alias for struct vpx_image */
+} switch_image_t;   /**< alias for struct vpx_image */

 /**\brief Representation of a rectangle on a surface */
-typedef struct vpx_image_rect {
+typedef struct switch_image_rect {
   unsigned int x;   /**< leftmost column */
   unsigned int y;   /**< topmost row */
   unsigned int w;   /**< width */
   unsigned int h;   /**< height */
-} vpx_image_rect_t; /**< alias for struct vpx_image_rect */
+} switch_image_rect_t; /**< alias for struct vpx_image_rect */

 /*!\brief Open a descriptor, allocating storage for the underlying image
  *
@@ -157,7 +148,7 @@ typedef struct vpx_image_rect {
  *         parameter is non-null, the value of the img parameter will be
  *         returned.
  */
-vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt,
+switch_image_t *switch_img_raw_alloc(switch_image_t *img, switch_img_fmt_t fmt,
                            unsigned int d_w, unsigned int d_h,
                            unsigned int align);

@@ -180,7 +171,7 @@ vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt,
  *         parameter is non-null, the value of the img parameter will be
  *         returned.
  */
-vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w,
+switch_image_t *switch_img_raw_wrap(switch_image_t *img,switch_img_fmt_t fmt, unsigned int d_w,
                           unsigned int d_h, unsigned int stride_align,
                           unsigned char *img_data);

@@ -197,28 +188,19 @@ vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w,
  *
  * \return 0 if the requested rectangle is valid, nonzero otherwise.
  */
-int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y,
+SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t *img, unsigned int x, unsigned int y,
                      unsigned int w, unsigned int h);

-/*!\brief Flip the image vertically (top for bottom)
- *
- * Adjusts the image descriptor's pointers and strides to make the image
- * be referenced upside-down.
- *
- * \param[in]    img       Image descriptor
- */
-void vpx_img_flip(vpx_image_t *img);
-
 /*!\brief Close an image descriptor
  *
  * Frees all allocated storage associated with an image descriptor.
  *
  * \param[in]    img       Image descriptor
  */
-void vpx_img_free(vpx_image_t *img);
+void switch_img_raw_free(switch_image_t *img);

 #ifdef __cplusplus
 }  // extern "C"
 #endif

-#endif  // VPX_VPX_VPX_IMAGE_H_
+#endif  // SWITCH_IMAGE_H
diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index a68d5bbf70..cd47eb0a0e 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -41,7 +41,7 @@

 #include <switch.h>
 #include <switch_json.h>
-#include <switch_vpx.h>
+#include <switch_image.h>

 SWITCH_BEGIN_EXTERN_C
 #define SWITCH_ENT_ORIGINATE_DELIM ":_:"
diff --git a/src/include/switch_vpx.h b/src/include/switch_vpx.h
deleted file mode 100644
index f2791678f7..0000000000
--- a/src/include/switch_vpx.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
- *
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- *
- * The Initial Developer of the Original Code is
- * Seven Du <dujinfang@gmail.com>
- * Portions created by the Initial Developer are Copyright (C)
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- *
- * switch_vpx.h -- vpx resources
- *
- */
-/*! \file switch_vpx.h
-	\brief vpx resources
-
-	The things powered by libvpx are renamed into the switch_ namespace to provide a cleaner
-	look to things and helps me to document what parts of video I am using I'd like to take this
-	opportunity to thank libvpx for all the awesome stuff it does and for making my life much easier.
-
-*/
-
-#ifndef SWITCH_VPX_H
-#define SWITCH_VPX_H
-
-#include <switch.h>
-#include <switch_image.h>
-
-SWITCH_BEGIN_EXTERN_C
-
-#define SWITCH_IMG_FMT_PLANAR    VPX_IMG_FMT_PLANAR
-#define SWITCH_IMG_FMT_UV_FLIP   VPX_IMG_FMT_UV_FLIP
-#define SWITCH_IMG_FMT_HAS_ALPHA VPX_IMG_FMT_HAS_ALPHA
-
-
-#define SWITCH_PLANE_PACKED VPX_PLANE_PACKED
-#define SWITCH_PLANE_Y      VPX_PLANE_Y
-#define SWITCH_PLANE_U      VPX_PLANE_U
-#define SWITCH_PLANE_V      VPX_PLANE_V
-#define SWITCH_PLANE_ALPHA  VPX_PLANE_ALPHA
-
-#ifndef VPX_IMG_FMT_HIGH         /* not available in libvpx 1.3.0 (see commit hash e97aea28) */
-#define VPX_IMG_FMT_HIGH         0x800  /**< Image uses 16bit framebuffer */
-#endif
-
-#define SWITCH_IMG_FMT_NONE      VPX_IMG_FMT_NONE
-#define SWITCH_IMG_FMT_RGB24     VPX_IMG_FMT_RGB24
-#define SWITCH_IMG_FMT_RGB32     VPX_IMG_FMT_RGB32
-#define SWITCH_IMG_FMT_RGB565    VPX_IMG_FMT_RGB565
-#define SWITCH_IMG_FMT_RGB555    VPX_IMG_FMT_RGB555
-#define SWITCH_IMG_FMT_UYVY      VPX_IMG_FMT_UYVY
-#define SWITCH_IMG_FMT_YUY2      VPX_IMG_FMT_YUY2
-#define SWITCH_IMG_FMT_YVYU      VPX_IMG_FMT_YVYU
-#define SWITCH_IMG_FMT_BGR24     VPX_IMG_FMT_BGR24
-#define SWITCH_IMG_FMT_RGB32_LE  VPX_IMG_FMT_RGB32_LE
-#define SWITCH_IMG_FMT_ARGB      VPX_IMG_FMT_ARGB
-#define SWITCH_IMG_FMT_ARGB_LE   VPX_IMG_FMT_ARGB_LE
-#define SWITCH_IMG_FMT_RGB565_LE VPX_IMG_FMT_RGB565_LE
-#define SWITCH_IMG_FMT_RGB555_LE VPX_IMG_FMT_RGB555_LE
-#define SWITCH_IMG_FMT_YV12      VPX_IMG_FMT_YV12
-#define SWITCH_IMG_FMT_I420      VPX_IMG_FMT_I420
-#define SWITCH_IMG_FMT_VPXYV12   VPX_IMG_FMT_VPXYV12
-#define SWITCH_IMG_FMT_VPXI420   VPX_IMG_FMT_VPXI420
-#define SWITCH_IMG_FMT_I422      VPX_IMG_FMT_I422
-#define SWITCH_IMG_FMT_I444      VPX_IMG_FMT_I444
-#define SWITCH_IMG_FMT_I440      VPX_IMG_FMT_I440
-#define SWITCH_IMG_FMT_444A      VPX_IMG_FMT_444A
-#define SWITCH_IMG_FMT_I42016    VPX_IMG_FMT_I42016
-#define SWITCH_IMG_FMT_I42216    VPX_IMG_FMT_I42216
-#define SWITCH_IMG_FMT_I44416    VPX_IMG_FMT_I44416
-#define SWITCH_IMG_FMT_I44016    VPX_IMG_FMT_I44016
-/* experimental */
-#define SWITCH_IMG_FMT_GD	     VPX_IMG_FMT_NONE
-
-typedef vpx_img_fmt_t switch_img_fmt_t;
-
-typedef vpx_image_t switch_image_t;
-
-
-SWITCH_END_EXTERN_C
-#endif
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
diff --git a/src/switch_core_video.c b/src/switch_core_video.c
index dad3181c2a..0e1d6cba6b 100644
--- a/src/switch_core_video.c
+++ b/src/switch_core_video.c
@@ -29,13 +29,6 @@
  *
  */

-#ifdef SWITCH_HAVE_VPX
-#include "vpx/vpx_image.h"
-#if VPX_IMAGE_ABI_VERSION != (4)
-#error VPX_IMAGE_ABI_VERSION is not (4)
-#endif
-#endif
-
 #include <switch.h>
 #include <switch_utf8.h>

@@ -204,7 +197,7 @@ SWITCH_DECLARE(switch_image_t *)switch_img_alloc(switch_image_t  *img,
 		if (!gd) return NULL;

 		switch_img_free(&img);
-		img = (switch_image_t *)vpx_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, 1, 1, 1);
+		img = switch_img_raw_alloc(NULL, SWITCH_IMG_FMT_ARGB, 1, 1, 1);

 		if (!img) {
 			gdImageDestroy(gd);
@@ -221,7 +214,7 @@ SWITCH_DECLARE(switch_image_t *)switch_img_alloc(switch_image_t  *img,

 	switch_assert(d_w > 0);
 	switch_assert(d_h > 0);
-	r = (switch_image_t *)vpx_img_alloc((vpx_image_t *)img, (vpx_img_fmt_t)fmt, d_w, d_h, align);
+	r = switch_img_raw_alloc(img, fmt, d_w, d_h, align);
 	switch_assert(r);
 	switch_assert(r->d_w == d_w);
 	switch_assert(r->d_h == d_h);
@@ -240,25 +233,12 @@ SWITCH_DECLARE(switch_image_t *)switch_img_wrap(switch_image_t  *img,
 						unsigned char      *img_data)
 {
 #ifdef SWITCH_HAVE_VPX
-	return (switch_image_t *)vpx_img_wrap((vpx_image_t *)img, (vpx_img_fmt_t)fmt, d_w, d_h, align, img_data);
+	return switch_img_raw_wrap(img, fmt, d_w, d_h, align, img_data);
 #else
 	return NULL;
 #endif
 }

-SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t  *img,
-				   unsigned int  x,
-				   unsigned int  y,
-				   unsigned int  w,
-				   unsigned int  h)
-{
-#ifdef SWITCH_HAVE_VPX
-	return vpx_img_set_rect((vpx_image_t *)img, x, y, w, h);
-#else
-	return 0;
-#endif
-}
-
 SWITCH_DECLARE(void) switch_img_rotate(switch_image_t **img, switch_image_rotation_mode_t mode)
 {
 #ifdef SWITCH_HAVE_YUV
@@ -308,7 +288,7 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img)
 		switch_assert((*img)->fmt <= SWITCH_IMG_FMT_I44016);
 		switch_assert((*img)->d_w <= 7860 && (*img)->d_w > 0);
 		switch_assert((*img)->d_h <= 4320 && (*img)->d_h > 0);
-		vpx_img_free((vpx_image_t *)*img);
+		switch_img_raw_free(*img);
 		*img = NULL;
 	}
 #endif
@@ -563,7 +543,7 @@ SWITCH_DECLARE(void) switch_img_patch_rect(switch_image_t *IMG, int X, int Y, sw
 	}

 	if (img->d_w == img->stride[0]) {
-		tmp = (switch_image_t *)vpx_img_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
+		tmp = switch_img_raw_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
 	} else {
 		switch_img_copy(img, &tmp);
 	}
@@ -700,7 +680,7 @@ SWITCH_DECLARE(switch_image_t *) switch_img_copy_rect(switch_image_t *img, uint3
 		data = img->planes[SWITCH_PLANE_Y];
 	}

-	tmp = (switch_image_t *)vpx_img_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
+	tmp = switch_img_raw_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
 	if (!tmp) return NULL;

 	w = MIN(img->d_w - x, w);
@@ -3453,22 +3433,22 @@ static inline uint32_t switch_img_fmt2fourcc(switch_img_fmt_t fmt)
 	switch(fmt) {
 		case SWITCH_IMG_FMT_NONE:      fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_RGB24:     fourcc = (uint32_t)FOURCC_24BG; break;
-		case SWITCH_IMG_FMT_RGB32:     fourcc = (uint32_t)FOURCC_ANY ; break;
-		case SWITCH_IMG_FMT_RGB565:    fourcc = (uint32_t)FOURCC_ANY ; break;
-		case SWITCH_IMG_FMT_RGB555:    fourcc = (uint32_t)FOURCC_ANY ; break;
-		case SWITCH_IMG_FMT_UYVY:      fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_RGB32:     fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_RGB565:    fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_RGB555:    fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_UYVY:      fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_YUY2:      fourcc = (uint32_t)FOURCC_YUY2; break;
-		case SWITCH_IMG_FMT_YVYU:      fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_YVYU:      fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_BGR24:     fourcc = (uint32_t)FOURCC_RAW ; break;
-		case SWITCH_IMG_FMT_RGB32_LE:  fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_RGB32_LE:  fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_ARGB:      fourcc = (uint32_t)FOURCC_ARGB; break;
 		case SWITCH_IMG_FMT_ARGB_LE:   fourcc = (uint32_t)FOURCC_ANY ; break;
-		case SWITCH_IMG_FMT_RGB565_LE: fourcc = (uint32_t)FOURCC_ANY ; break;
-		case SWITCH_IMG_FMT_RGB555_LE: fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_RGB565_LE: fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_RGB555_LE: fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_YV12:      fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_I420:      fourcc = (uint32_t)FOURCC_I420; break;
-		case SWITCH_IMG_FMT_VPXYV12:   fourcc = (uint32_t)FOURCC_ANY ; break;
-		case SWITCH_IMG_FMT_VPXI420:   fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_VPXYV12:   fourcc = (uint32_t)FOURCC_ANY ; break;
+		//case SWITCH_IMG_FMT_VPXI420:   fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_I422:      fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_I444:      fourcc = (uint32_t)FOURCC_ANY ; break;
 		case SWITCH_IMG_FMT_I440:      fourcc = (uint32_t)FOURCC_ANY ; break;
diff --git a/src/switch_image.c b/src/switch_image.c
new file mode 100644
index 0000000000..bcc88de893
--- /dev/null
+++ b/src/switch_image.c
@@ -0,0 +1,266 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Andrey Volk <andrey@signalwire.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Andrey Volk <andrey@signalwire.com>
+ *
+ *
+ * switch_image.c -- Image
+ *
+ */
+
+#ifdef SWITCH_HAVE_VPX
+#include "vpx/vpx_integer.h"
+#include "vpx_mem/vpx_mem.h"
+#endif
+
+#include <switch.h>
+#include <switch_image.h>
+
+#ifdef SWITCH_HAVE_VPX
+static switch_image_t *img_alloc_helper(switch_image_t *img, switch_img_fmt_t fmt,
+	unsigned int d_w, unsigned int d_h,
+	unsigned int buf_align,
+	unsigned int stride_align,
+	unsigned char *img_data)
+{
+	unsigned int h, w, s, xcs, ycs, bps;
+	unsigned int stride_in_bytes;
+	unsigned int align;
+
+	if (img != NULL) memset(img, 0, sizeof(switch_image_t));
+
+	/* Treat align==0 like align==1 */
+	if (!buf_align) buf_align = 1;
+
+	/* Validate alignment (must be power of 2) */
+	if (buf_align & (buf_align - 1)) goto fail;
+
+	/* Treat align==0 like align==1 */
+	if (!stride_align) stride_align = 1;
+
+	/* Validate alignment (must be power of 2) */
+	if (stride_align & (stride_align - 1)) goto fail;
+
+	/* Get sample size for this format */
+	switch (fmt) {
+	case SWITCH_IMG_FMT_ARGB:
+	case SWITCH_IMG_FMT_ARGB_LE: bps = 32; break;
+	case SWITCH_IMG_FMT_RGB24:
+	case SWITCH_IMG_FMT_BGR24: bps = 24; break;
+	case SWITCH_IMG_FMT_YUY2: bps = 16; break;
+	case SWITCH_IMG_FMT_I420:
+	case SWITCH_IMG_FMT_YV12:
+	case SWITCH_IMG_FMT_NV12: bps = 12; break;
+	case SWITCH_IMG_FMT_I422:
+	case SWITCH_IMG_FMT_I440: bps = 16; break;
+	case SWITCH_IMG_FMT_I444: bps = 24; break;
+	case SWITCH_IMG_FMT_I42016: bps = 24; break;
+	case SWITCH_IMG_FMT_I42216:
+	case SWITCH_IMG_FMT_I44016: bps = 32; break;
+	case SWITCH_IMG_FMT_I44416: bps = 48; break;
+	default: bps = 16; break;
+	}
+
+	/* Get chroma shift values for this format */
+	// For VPX_IMG_FMT_NV12, xcs needs to be 0 such that UV data is all read at
+	// one time.
+	switch (fmt) {
+	case SWITCH_IMG_FMT_I420:
+	case SWITCH_IMG_FMT_YV12:
+	case SWITCH_IMG_FMT_I422:
+	case SWITCH_IMG_FMT_I42016:
+	case SWITCH_IMG_FMT_I42216: xcs = 1; break;
+	default: xcs = 0; break;
+	}
+
+	switch (fmt) {
+	case SWITCH_IMG_FMT_I420:
+	case SWITCH_IMG_FMT_NV12:
+	case SWITCH_IMG_FMT_I440:
+	case SWITCH_IMG_FMT_YV12:
+	case SWITCH_IMG_FMT_I42016:
+	case SWITCH_IMG_FMT_I44016: ycs = 1; break;
+	default: ycs = 0; break;
+	}
+
+	/* Calculate storage sizes. If the buffer was allocated externally, the width
+	 * and height shouldn't be adjusted. */
+	w = d_w;
+	h = d_h;
+	s = (fmt & SWITCH_IMG_FMT_PLANAR) ? w : bps * w / 8;
+	s = (s + stride_align - 1) & ~(stride_align - 1);
+	stride_in_bytes = (fmt & SWITCH_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s;
+
+	/* Allocate the new image */
+	if (!img) {
+		img = (switch_image_t *)calloc(1, sizeof(switch_image_t));
+
+		if (!img) goto fail;
+
+		img->self_allocd = 1;
+	}
+
+	img->img_data = img_data;
+
+	if (!img_data) {
+		uint64_t alloc_size;
+		/* Calculate storage sizes given the chroma subsampling */
+		align = (1 << xcs) - 1;
+		w = (d_w + align) & ~align;
+		align = (1 << ycs) - 1;
+		h = (d_h + align) & ~align;
+
+		s = (fmt & SWITCH_IMG_FMT_PLANAR) ? w : bps * w / 8;
+		s = (s + stride_align - 1) & ~(stride_align - 1);
+		stride_in_bytes = (fmt & SWITCH_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s;
+		alloc_size = (fmt & SWITCH_IMG_FMT_PLANAR) ? (uint64_t)h * s * bps / 8
+			: (uint64_t)h * s;
+
+		if (alloc_size != (size_t)alloc_size) goto fail;
+
+		img->img_data = (uint8_t *)vpx_memalign(buf_align, (size_t)alloc_size);
+		img->img_data_owner = 1;
+	}
+
+	if (!img->img_data) goto fail;
+
+	img->fmt = fmt;
+	img->bit_depth = (fmt & SWITCH_IMG_FMT_HIGHBITDEPTH) ? 16 : 8;
+	img->w = w;
+	img->h = h;
+	img->x_chroma_shift = xcs;
+	img->y_chroma_shift = ycs;
+	img->bps = bps;
+
+	/* Calculate strides */
+	img->stride[SWITCH_PLANE_Y] = img->stride[SWITCH_PLANE_ALPHA] = stride_in_bytes;
+	img->stride[SWITCH_PLANE_U] = img->stride[SWITCH_PLANE_V] = stride_in_bytes >> xcs;
+
+	/* Default viewport to entire image */
+	if (!switch_img_set_rect(img, 0, 0, d_w, d_h)) return img;
+
+fail:
+	switch_img_raw_free(img);
+	return NULL;
+}
+
+switch_image_t *switch_img_raw_alloc(switch_image_t *img, switch_img_fmt_t fmt,
+	unsigned int d_w, unsigned int d_h,
+	unsigned int align)
+{
+	return img_alloc_helper(img, fmt, d_w, d_h, align, align, NULL);
+}
+
+switch_image_t *switch_img_raw_wrap(switch_image_t *img, switch_img_fmt_t fmt, unsigned int d_w,
+	unsigned int d_h, unsigned int stride_align,
+	unsigned char *img_data)
+{
+	/* By setting buf_align = 1, we don't change buffer alignment in this function. */
+	return img_alloc_helper(img, fmt, d_w, d_h, 1, stride_align, img_data);
+}
+#endif /* SWITCH_HAVE_VPX */
+
+SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t *img,
+	unsigned int  x,
+	unsigned int  y,
+	unsigned int  w,
+	unsigned int  h)
+{
+#ifdef SWITCH_HAVE_VPX
+	if (x <= UINT_MAX - w && x + w <= img->w && y <= UINT_MAX - h &&
+		y + h <= img->h) {
+		img->d_w = w;
+		img->d_h = h;
+
+			/* Calculate plane pointers */
+			if (!(img->fmt & SWITCH_IMG_FMT_PLANAR)) {
+				img->planes[SWITCH_PLANE_PACKED] =
+					img->img_data + x * img->bps / 8 + y * img->stride[SWITCH_PLANE_PACKED];
+			} else {
+				const int bytes_per_sample =
+					(img->fmt & SWITCH_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
+				unsigned char *data = img->img_data;
+
+				if (img->fmt & SWITCH_IMG_FMT_HAS_ALPHA) {
+					img->planes[SWITCH_PLANE_ALPHA] =
+						data + x * bytes_per_sample + y * img->stride[SWITCH_PLANE_ALPHA];
+					data += img->h * img->stride[SWITCH_PLANE_ALPHA];
+				}
+
+				img->planes[SWITCH_PLANE_Y] =
+					data + x * bytes_per_sample + y * img->stride[SWITCH_PLANE_Y];
+				data += img->h * img->stride[SWITCH_PLANE_Y];
+
+				if (img->fmt == SWITCH_IMG_FMT_NV12) {
+					img->planes[SWITCH_PLANE_U] =
+						data + (x >> img->x_chroma_shift) +
+						(y >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_U];
+					img->planes[SWITCH_PLANE_V] = img->planes[SWITCH_PLANE_U] + 1;
+				} else if (!(img->fmt & SWITCH_IMG_FMT_UV_FLIP)) {
+					img->planes[SWITCH_PLANE_U] =
+						data + (x >> img->x_chroma_shift) * bytes_per_sample +
+						(y >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_U];
+					data += (img->h >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_U];
+					img->planes[SWITCH_PLANE_V] =
+						data + (x >> img->x_chroma_shift) * bytes_per_sample +
+						(y >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_V];
+				} else {
+					img->planes[SWITCH_PLANE_V] =
+						data + (x >> img->x_chroma_shift) * bytes_per_sample +
+						(y >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_V];
+					data += (img->h >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_V];
+					img->planes[SWITCH_PLANE_U] =
+						data + (x >> img->x_chroma_shift) * bytes_per_sample +
+						(y >> img->y_chroma_shift) * img->stride[SWITCH_PLANE_U];
+				}
+			}
+		return 0;
+}
+	return -1;
+#else
+	return 0;
+#endif
+}
+
+void switch_img_raw_free(switch_image_t *img)
+{
+#ifdef SWITCH_HAVE_VPX
+	if (img) {
+		if (img->img_data && img->img_data_owner) vpx_free(img->img_data);
+
+		if (img->self_allocd) free(img);
+	}
+#endif
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
+ */
diff --git a/src/switch_vpx.c b/src/switch_vpx.c
index e65db6b6c8..6c5d6475ce 100644
--- a/src/switch_vpx.c
+++ b/src/switch_vpx.c
@@ -387,7 +387,7 @@ struct vpx_context {

 	vpx_codec_ctx_t	encoder;
 	uint8_t encoder_init;
-	vpx_image_t *pic;
+	switch_image_t *pic;
 	switch_bool_t force_key_frame;
 	int fps;
 	int format;
@@ -1502,7 +1502,7 @@ static switch_status_t switch_vpx_destroy(switch_codec_t *codec)
 		}

 		if (context->pic) {
-			vpx_img_free(context->pic);
+			vpx_img_free((vpx_image_t*)context->pic);
 			context->pic = NULL;
 		}
 		if (context->vpx_packet_buffer) {
diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj
index 88d76d41a7..12045cd190 100644
--- a/w32/Library/FreeSwitchCore.2017.vcxproj
+++ b/w32/Library/FreeSwitchCore.2017.vcxproj
@@ -128,7 +128,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     <BuildLog />
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -178,7 +178,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -219,7 +219,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     <BuildLog />
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
-      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <PrecompiledHeader>Create</PrecompiledHeader>
@@ -257,7 +257,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     </Midl>
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
-      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <PrecompiledHeader>Create</PrecompiledHeader>
@@ -360,6 +360,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     <ClCompile Include="..\..\src\switch_estimators.c" />
     <ClCompile Include="..\..\src\switch_event.c" />
     <ClCompile Include="..\..\src\switch_hashtable.c" />
+    <ClCompile Include="..\..\src\switch_image.c" />
     <ClCompile Include="..\..\src\switch_ivr.c" />
     <ClCompile Include="..\..\src\switch_ivr_async.c" />
     <ClCompile Include="..\..\src\switch_ivr_bridge.c" />
@@ -733,6 +734,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     <ClInclude Include="..\..\src\include\switch_cJSON.h" />
     <ClInclude Include="..\..\src\include\switch_cJSON_Utils.h" />
     <ClInclude Include="..\..\src\include\switch_json.h" />
+    <ClInclude Include="..\..\src\include\switch_image.h" />
     <ClInclude Include="..\..\src\include\switch_limit.h" />
     <ClInclude Include="..\..\src\include\switch_loadable_module.h" />
     <ClInclude Include="..\..\src\include\switch_log.h" />
@@ -752,7 +754,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     <ClInclude Include="..\..\src\include\private\switch_uuidv7_pvt.h" />
     <ClInclude Include="..\..\src\include\switch_vad.h" />
     <ClInclude Include="..\..\src\include\switch_version.h" />
-    <ClInclude Include="..\..\src\include\switch_vpx.h" />
     <ClInclude Include="..\..\src\include\switch_xml.h" />
     <ClInclude Include="..\..\src\include\switch_xml_config.h" />
   </ItemGroup>