//------------------------------------------------------------------------------ static byte* Decode(WEBP_CSP_MODE mode, byte* data, uint data_size, int* width, int* height, WebPDecBuffer* keep_info) { WebPDecParams params; WebPDecBuffer output; WebPInitDecBuffer(&output); WebPResetDecParams(¶ms); params.output = &output; output.colorspace = mode; // Retrieve (and report back) the required dimensions from bitstream. if (!WebPGetInfo(data, data_size, &output.width, &output.height)) { return null; } if (width != null) *width = output.width; if (height != null) *height = output.height; // Decode if (DecodeInto(data, data_size, ¶ms) != VP8_STATUS_OK) { return null; } if (keep_info != null) { // keep track of the side-info WebPCopyDecBuffer(&output, keep_info); } // return decoded samples (don't clear 'output'!) return (mode >= MODE_YUV) ? output.u.YUVA.y : output.u.RGBA.rgba; }
static void WebPCopyDecBuffer(WebPDecBuffer src, WebPDecBuffer dst) { throw(new NotImplementedException("Should copy every field")); /* if (src != null && dst != null) { *dst = *src; if (src.private_memory != null) { dst.is_external_memory = 1; // dst buffer doesn't own the memory. dst.private_memory = null; } } */ }
/// <summary> /// Copy and transfer ownership from src to dst (beware of parameter order!) /// </summary> /// <param name="src"></param> /// <param name="dst"></param> void WebPGrabDecBuffer(WebPDecBuffer src, WebPDecBuffer dst) { throw (new NotImplementedException("Should copy every field")); /* if (src != null && dst != null) { *dst = *src; if (src.private_memory != null) { src.is_external_memory = 1; // src relinquishes ownership src.private_memory = null; } */ }
VP8StatusCode WebPAllocateDecBuffer(int w, int h, WebPDecoderOptions options, WebPDecBuffer _out) { if (_out == null || w <= 0 || h <= 0) { return VP8_STATUS_INVALID_PARAM; } if (options != null) { // First, apply options if there is any. if (options.use_cropping) { int cw = options.crop_width; int ch = options.crop_height; int x = options.crop_left & ~1; int y = options.crop_top & ~1; if (x < 0 || y < 0 || cw <= 0 || ch <= 0 || x + cw > w || y + ch > h) { return VP8_STATUS_INVALID_PARAM; // out of frame boundary. } w = cw; h = ch; } if (options.use_scaling) { if (options.scaled_width <= 0 || options.scaled_height <= 0) { return VP8_STATUS_INVALID_PARAM; } w = options.scaled_width; h = options.scaled_height; } } _out.width = w; _out.height = h; // Then, allocate buffer for real return _out.AllocateBuffer(); }