buffer.c revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright 2011 Google Inc. All Rights Reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Use of this source code is governed by a BSD-style license 4eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// that can be found in the COPYING file in the root of the source 5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// tree. An additional intellectual property rights grant can be found 6eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// in the file PATENTS. All contributing project authors may 7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// be found in the AUTHORS file in the root of the source tree. 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ----------------------------------------------------------------------------- 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Everything about WebPDecBuffer 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Author: Skal (pascal.massimino@gmail.com) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdlib.h> 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "./vp8i.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "./webpi.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "../utils/utils.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(__cplusplus) || defined(c_plusplus) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern "C" { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//------------------------------------------------------------------------------ 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebPDecBuffer 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Number of bytes per pixel for the different color-spaces. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const int kModeBpp[MODE_LAST] = { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3, 4, 3, 4, 4, 2, 2, 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4, 4, 4, 2, // pre-multiplied modes 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1, 1 }; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that webp_csp_mode is within the bounds of WEBP_CSP_MODE. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Convert to an integer to handle both the unsigned/signed enum cases 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// without the need for casting to remove type limit warnings. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static int IsValidColorspace(int webp_csp_mode) { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return (webp_csp_mode >= MODE_RGB && webp_csp_mode < MODE_LAST); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int ok = 1; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const WEBP_CSP_MODE mode = buffer->colorspace; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int width = buffer->width; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int height = buffer->height; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!IsValidColorspace(mode)) { 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok = 0; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (!WebPIsRGBMode(mode)) { // YUV checks 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const WebPYUVABuffer* const buf = &buffer->u.YUVA; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64_t y_size = (uint64_t)buf->y_stride * height; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64_t u_size = (uint64_t)buf->u_stride * ((height + 1) / 2); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64_t v_size = (uint64_t)buf->v_stride * ((height + 1) / 2); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64_t a_size = (uint64_t)buf->a_stride * height; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (y_size <= buf->y_size); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (u_size <= buf->u_size); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (v_size <= buf->v_size); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->y_stride >= width); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->u_stride >= (width + 1) / 2); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->v_stride >= (width + 1) / 2); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->y != NULL); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->u != NULL); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->v != NULL); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (mode == MODE_YUVA) { 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->a_stride >= width); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (a_size <= buf->a_size); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->a != NULL); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { // RGB checks 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const WebPRGBABuffer* const buf = &buffer->u.RGBA; 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64_t size = (uint64_t)buf->stride * height; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (size <= buf->size); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->stride >= width * kModeBpp[mode]); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ok &= (buf->rgba != NULL); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ok ? VP8_STATUS_OK : VP8_STATUS_INVALID_PARAM; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) { 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int w = buffer->width; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int h = buffer->height; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const WEBP_CSP_MODE mode = buffer->colorspace; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (w <= 0 || h <= 0 || !IsValidColorspace(mode)) { 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return VP8_STATUS_INVALID_PARAM; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!buffer->is_external_memory && buffer->private_memory == NULL) { 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint8_t* output; 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int uv_stride = 0, a_stride = 0; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64_t uv_size = 0, a_size = 0, total_size; 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We need memory and it hasn't been allocated yet. 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // => initialize output buffer, now that dimensions are known. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int stride = w * kModeBpp[mode]; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64_t size = (uint64_t)stride * h; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!WebPIsRGBMode(mode)) { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uv_stride = (w + 1) / 2; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uv_size = (uint64_t)uv_stride * ((h + 1) / 2); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (mode == MODE_YUVA) { 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) a_stride = w; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) a_size = (uint64_t)a_stride * h; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) total_size = size + 2 * uv_size + a_size; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Security/sanity checks 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) output = (uint8_t*)WebPSafeMalloc(total_size, sizeof(*output)); 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (output == NULL) { 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return VP8_STATUS_OUT_OF_MEMORY; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buffer->private_memory = output; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!WebPIsRGBMode(mode)) { // YUVA initialization 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebPYUVABuffer* const buf = &buffer->u.YUVA; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->y = output; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->y_stride = stride; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->y_size = (size_t)size; 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->u = output + size; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->u_stride = uv_stride; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->u_size = (size_t)uv_size; 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->v = output + size + uv_size; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->v_stride = uv_stride; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->v_size = (size_t)uv_size; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (mode == MODE_YUVA) { 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->a = output + size + 2 * uv_size; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->a_size = (size_t)a_size; 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->a_stride = a_stride; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { // RGBA initialization 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebPRGBABuffer* const buf = &buffer->u.RGBA; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->rgba = output; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->stride = stride; 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buf->size = (size_t)size; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return CheckDecBuffer(buffer); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)VP8StatusCode WebPAllocateDecBuffer(int w, int h, 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const WebPDecoderOptions* const options, 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebPDecBuffer* const out) { 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (out == NULL || w <= 0 || h <= 0) { 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return VP8_STATUS_INVALID_PARAM; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (options != NULL) { // First, apply options if there is any. 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (options->use_cropping) { 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int cw = options->crop_width; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int ch = options->crop_height; 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int x = options->crop_left & ~1; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const int y = options->crop_top & ~1; 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (x < 0 || y < 0 || cw <= 0 || ch <= 0 || x + cw > w || y + ch > h) { 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return VP8_STATUS_INVALID_PARAM; // out of frame boundary. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) w = cw; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) h = ch; 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (options->use_scaling) { 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (options->scaled_width <= 0 || options->scaled_height <= 0) { 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return VP8_STATUS_INVALID_PARAM; 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) w = options->scaled_width; 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) h = options->scaled_height; 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) out->width = w; 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) out->height = h; 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Then, allocate buffer for real 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return AllocateBuffer(out); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//------------------------------------------------------------------------------ 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// constructors / destructors 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int WebPInitDecBufferInternal(WebPDecBuffer* buffer, int version) { 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DECODER_ABI_VERSION)) { 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; // version mismatch 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (buffer == NULL) return 0; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) memset(buffer, 0, sizeof(*buffer)); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 1; 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebPFreeDecBuffer(WebPDecBuffer* buffer) { 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (buffer != NULL) { 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!buffer->is_external_memory) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) free(buffer->private_memory); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) buffer->private_memory = NULL; 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebPCopyDecBuffer(const WebPDecBuffer* const src, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebPDecBuffer* const dst) { 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (src != NULL && dst != NULL) { 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *dst = *src; 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (src->private_memory != NULL) { 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dst->is_external_memory = 1; // dst buffer doesn't own the memory. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dst->private_memory = NULL; 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copy and transfer ownership from src to dst (beware of parameter order!) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst) { 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (src != NULL && dst != NULL) { 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *dst = *src; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (src->private_memory != NULL) { 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) src->is_external_memory = 1; // src relinquishes ownership 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) src->private_memory = NULL; 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//------------------------------------------------------------------------------ 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(__cplusplus) || defined(c_plusplus) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // extern "C" 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 218