| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 return x; | 33 return x; |
| 34 } | 34 } |
| 35 | 35 |
| 36 static void img_buf_free(void *memblk) { | 36 static void img_buf_free(void *memblk) { |
| 37 if (memblk) { | 37 if (memblk) { |
| 38 void *addr = (void *)(((size_t *)memblk)[-1]); | 38 void *addr = (void *)(((size_t *)memblk)[-1]); |
| 39 free(addr); | 39 free(addr); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 static vpx_image_t *img_alloc_helper(vpx_image_t *img, | 43 static vpx_image_t *img_alloc_helper(vpx_image_t *img, |
| 44 vpx_img_fmt_t fmt, | 44 vpx_img_fmt_t fmt, |
| 45 unsigned int d_w, | 45 unsigned int d_w, |
| 46 unsigned int d_h, | 46 unsigned int d_h, |
| 47 unsigned int buf_align, | 47 unsigned int buf_align, |
| 48 unsigned int stride_align, | 48 unsigned int stride_align, |
| 49 unsigned char *img_data) { | 49 unsigned char *img_data) { |
| 50 | 50 |
| 51 unsigned int h, w, s, xcs, ycs, bps; | 51 unsigned int h, w, s, xcs, ycs, bps; |
| 52 int align; | 52 int align; |
| 53 | 53 |
| 54 /* Treat align==0 like align==1 */ | 54 /* Treat align==0 like align==1 */ |
| 55 if (!buf_align) | 55 if (!buf_align) |
| 56 buf_align = 1; | 56 buf_align = 1; |
| 57 | 57 |
| 58 /* Validate alignment (must be power of 2) */ | 58 /* Validate alignment (must be power of 2) */ |
| 59 if (buf_align & (buf_align - 1)) | 59 if (buf_align & (buf_align - 1)) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 87 case VPX_IMG_FMT_YUY2: | 87 case VPX_IMG_FMT_YUY2: |
| 88 case VPX_IMG_FMT_YVYU: | 88 case VPX_IMG_FMT_YVYU: |
| 89 bps = 16; | 89 bps = 16; |
| 90 break; | 90 break; |
| 91 case VPX_IMG_FMT_I420: | 91 case VPX_IMG_FMT_I420: |
| 92 case VPX_IMG_FMT_YV12: | 92 case VPX_IMG_FMT_YV12: |
| 93 case VPX_IMG_FMT_VPXI420: | 93 case VPX_IMG_FMT_VPXI420: |
| 94 case VPX_IMG_FMT_VPXYV12: | 94 case VPX_IMG_FMT_VPXYV12: |
| 95 bps = 12; | 95 bps = 12; |
| 96 break; | 96 break; |
| 97 case VPX_IMG_FMT_I422: |
| 98 bps = 16; |
| 99 break; |
| 100 case VPX_IMG_FMT_I444: |
| 101 bps = 24; |
| 102 break; |
| 103 case VPX_IMG_FMT_I42016: |
| 104 bps = 24; |
| 105 break; |
| 106 case VPX_IMG_FMT_I42216: |
| 107 bps = 32; |
| 108 break; |
| 109 case VPX_IMG_FMT_I44416: |
| 110 bps = 48; |
| 111 break; |
| 97 default: | 112 default: |
| 98 bps = 16; | 113 bps = 16; |
| 99 break; | 114 break; |
| 100 } | 115 } |
| 101 | 116 |
| 102 /* Get chroma shift values for this format */ | 117 /* Get chroma shift values for this format */ |
| 103 switch (fmt) { | 118 switch (fmt) { |
| 104 case VPX_IMG_FMT_I420: | 119 case VPX_IMG_FMT_I420: |
| 105 case VPX_IMG_FMT_YV12: | 120 case VPX_IMG_FMT_YV12: |
| 106 case VPX_IMG_FMT_VPXI420: | 121 case VPX_IMG_FMT_VPXI420: |
| 107 case VPX_IMG_FMT_VPXYV12: | 122 case VPX_IMG_FMT_VPXYV12: |
| 123 case VPX_IMG_FMT_I422: |
| 124 case VPX_IMG_FMT_I42016: |
| 125 case VPX_IMG_FMT_I42216: |
| 108 xcs = 1; | 126 xcs = 1; |
| 109 break; | 127 break; |
| 110 default: | 128 default: |
| 111 xcs = 0; | 129 xcs = 0; |
| 112 break; | 130 break; |
| 113 } | 131 } |
| 114 | 132 |
| 115 switch (fmt) { | 133 switch (fmt) { |
| 116 case VPX_IMG_FMT_I420: | 134 case VPX_IMG_FMT_I420: |
| 117 case VPX_IMG_FMT_YV12: | 135 case VPX_IMG_FMT_YV12: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (!img_data) { | 167 if (!img_data) { |
| 150 img->img_data = img_buf_memalign(buf_align, ((fmt & VPX_IMG_FMT_PLANAR) ? | 168 img->img_data = img_buf_memalign(buf_align, ((fmt & VPX_IMG_FMT_PLANAR) ? |
| 151 h * s * bps / 8 : h * s)); | 169 h * s * bps / 8 : h * s)); |
| 152 img->img_data_owner = 1; | 170 img->img_data_owner = 1; |
| 153 } | 171 } |
| 154 | 172 |
| 155 if (!img->img_data) | 173 if (!img->img_data) |
| 156 goto fail; | 174 goto fail; |
| 157 | 175 |
| 158 img->fmt = fmt; | 176 img->fmt = fmt; |
| 177 img->bit_depth = (fmt & VPX_IMG_FMT_HIGH) ? 16 : 8; |
| 159 img->w = w; | 178 img->w = w; |
| 160 img->h = h; | 179 img->h = h; |
| 161 img->x_chroma_shift = xcs; | 180 img->x_chroma_shift = xcs; |
| 162 img->y_chroma_shift = ycs; | 181 img->y_chroma_shift = ycs; |
| 163 img->bps = bps; | 182 img->bps = bps; |
| 164 | 183 |
| 165 /* Calculate strides */ | 184 /* Calculate strides */ |
| 166 img->stride[VPX_PLANE_Y] = img->stride[VPX_PLANE_ALPHA] = s; | 185 img->stride[VPX_PLANE_Y] = img->stride[VPX_PLANE_ALPHA] = s; |
| 167 img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = s >> xcs; | 186 img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = s >> xcs; |
| 168 | 187 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 289 |
| 271 void vpx_img_free(vpx_image_t *img) { | 290 void vpx_img_free(vpx_image_t *img) { |
| 272 if (img) { | 291 if (img) { |
| 273 if (img->img_data && img->img_data_owner) | 292 if (img->img_data && img->img_data_owner) |
| 274 img_buf_free(img->img_data); | 293 img_buf_free(img->img_data); |
| 275 | 294 |
| 276 if (img->self_allocd) | 295 if (img->self_allocd) |
| 277 free(img); | 296 free(img); |
| 278 } | 297 } |
| 279 } | 298 } |
| OLD | NEW |