def DecodeYUV(data): """ Decode the given WebP image data to a YUV bitmap :param data: The original WebP image data :type data: bytearray :rtype: WebPImage """ # Prepare parameters width = c_int(-1) height = c_int(-1) size = len(data) u = create_string_buffer(0) v = create_string_buffer(0) stride = c_int(-1) uv_stride = c_int(-1) # Decode image an return pointer to decoded data bitmap_p = _LIBRARY.WebPDecodeYUV( str(data), size, width, height, u, v, # u, v, stride, uv_stride) # Convert data to Python types width = width.value height = height.value stride = stride.value uv_stride = uv_stride.value # Copy decoded data into a buffer size = stride * height bitmap = create_string_buffer(size) memmove(bitmap, bitmap_p, size) # Copy UV chrominace bitmap uv_size = uv_stride * height u_bitmap = create_string_buffer(uv_size) v_bitmap = create_string_buffer(uv_size) memmove(u_bitmap, u, uv_size) memmove(v_bitmap, v, uv_size) # End return BitmapHandler(bytearray(bitmap), BitmapHandler.YUV, width, height, stride, u_bitmap=bytearray(u_bitmap), v_bitmap=bytearray(v_bitmap), uv_stride=uv_stride)
def DecodeBGR(data): """ Decode the given WebP image data to a BGR bitmap :param data: The original WebP image data :type data: bytearray :rtype: WebPImage """ bitmap, width, height = _decode(data, _LIBRARY.WebPDecodeBGR, PIXEL_SZ) return BitmapHandler(bitmap, BitmapHandler.BGR, width, height, PIXEL_SZ * width)