| 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 |
| 11 | 11 |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include "vpx/vpx_image.h" | 14 #include "vpx/vpx_image.h" |
| 15 #include "vpx/vpx_integer.h" |
| 15 | 16 |
| 16 #define ADDRESS_STORAGE_SIZE sizeof(size_t) | 17 #define ADDRESS_STORAGE_SIZE sizeof(size_t) |
| 17 /*returns an addr aligned to the byte boundary specified by align*/ | 18 /*returns an addr aligned to the byte boundary specified by align*/ |
| 18 #define align_addr(addr,align) (void*)(((size_t)(addr) + ((align) - 1)) & (size_
t)-(align)) | 19 #define align_addr(addr,align) (void*)(((size_t)(addr) + ((align) - 1)) & (size_
t)-(align)) |
| 19 | 20 |
| 20 /* Memalign code is copied from vpx_mem.c */ | 21 /* Memalign code is copied from vpx_mem.c */ |
| 21 static void *img_buf_memalign(size_t align, size_t size) { | 22 static void *img_buf_memalign(size_t align, size_t size) { |
| 22 void *addr, | 23 void *addr, |
| 23 * x = NULL; | 24 * x = NULL; |
| 24 | 25 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 goto fail; | 159 goto fail; |
| 159 | 160 |
| 160 img->self_allocd = 1; | 161 img->self_allocd = 1; |
| 161 } else { | 162 } else { |
| 162 memset(img, 0, sizeof(vpx_image_t)); | 163 memset(img, 0, sizeof(vpx_image_t)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 img->img_data = img_data; | 166 img->img_data = img_data; |
| 166 | 167 |
| 167 if (!img_data) { | 168 if (!img_data) { |
| 168 img->img_data = img_buf_memalign(buf_align, ((fmt & VPX_IMG_FMT_PLANAR) ? | 169 const uint64_t alloc_size = (fmt & VPX_IMG_FMT_PLANAR) ? |
| 169 h * s * bps / 8 : h * s)); | 170 (uint64_t)h * s * bps / 8 : (uint64_t)h * s; |
| 171 |
| 172 if (alloc_size != (size_t)alloc_size) |
| 173 goto fail; |
| 174 |
| 175 img->img_data = img_buf_memalign(buf_align, (size_t)alloc_size); |
| 170 img->img_data_owner = 1; | 176 img->img_data_owner = 1; |
| 171 } | 177 } |
| 172 | 178 |
| 173 if (!img->img_data) | 179 if (!img->img_data) |
| 174 goto fail; | 180 goto fail; |
| 175 | 181 |
| 176 img->fmt = fmt; | 182 img->fmt = fmt; |
| 177 img->bit_depth = (fmt & VPX_IMG_FMT_HIGH) ? 16 : 8; | 183 img->bit_depth = (fmt & VPX_IMG_FMT_HIGH) ? 16 : 8; |
| 178 img->w = w; | 184 img->w = w; |
| 179 img->h = h; | 185 img->h = h; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 295 |
| 290 void vpx_img_free(vpx_image_t *img) { | 296 void vpx_img_free(vpx_image_t *img) { |
| 291 if (img) { | 297 if (img) { |
| 292 if (img->img_data && img->img_data_owner) | 298 if (img->img_data && img->img_data_owner) |
| 293 img_buf_free(img->img_data); | 299 img_buf_free(img->img_data); |
| 294 | 300 |
| 295 if (img->self_allocd) | 301 if (img->self_allocd) |
| 296 free(img); | 302 free(img); |
| 297 } | 303 } |
| 298 } | 304 } |
| OLD | NEW |