9 #include <webp/decode.h>
10 #include <webp/encode.h>
42 WebPBitstreamFeatures features;
43 if (WebPGetFeatures(mem,
size, &features) != VP8_STATUS_OK) {
44 fprintf(stderr,
"WebP: Failed to parse features\n");
48 const int planes = features.has_alpha ? 32 : 24;
52 fprintf(stderr,
"WebP: Failed to allocate image memory\n");
57 ibuf->
ftype = IMB_FTYPE_WEBP;
60 unsigned char *last_row = (
unsigned char *)(ibuf->
rect + (ibuf->
y - 1) * ibuf->
x);
61 if (WebPDecodeRGBAInto(mem,
size, last_row, (
size_t)(ibuf->
x) * ibuf->
y * 4, -4 * ibuf->
x) ==
63 fprintf(stderr,
"WebP: Failed to decode image\n");
72 const int bytesperpixel = (ibuf->
planes + 7) >> 3;
73 unsigned char *encoded_data, *last_row;
74 size_t encoded_data_size;
76 if (bytesperpixel == 3) {
82 rgb_rect[i * 3 + 0] = rgba_rect[i * 4 + 0];
83 rgb_rect[i * 3 + 1] = rgba_rect[i * 4 + 1];
84 rgb_rect[i * 3 + 2] = rgba_rect[i * 4 + 2];
87 last_row = (
unsigned char *)(rgb_rect + (ibuf->
y - 1) * ibuf->
x * 3);
90 encoded_data_size = WebPEncodeLosslessRGB(
91 last_row, ibuf->
x, ibuf->
y, -3 * ibuf->
x, &encoded_data);
94 encoded_data_size = WebPEncodeRGB(
99 else if (bytesperpixel == 4) {
100 last_row = (
unsigned char *)(ibuf->
rect + (ibuf->
y - 1) * ibuf->
x);
103 encoded_data_size = WebPEncodeLosslessRGBA(
104 last_row, ibuf->
x, ibuf->
y, -4 * ibuf->
x, &encoded_data);
107 encoded_data_size = WebPEncodeRGBA(
112 fprintf(stderr,
"WebP: Unsupported bytes per pixel: %d for file: '%s'\n", bytesperpixel, name);
116 if (encoded_data !=
NULL) {
120 fprintf(stderr,
"WebP: Cannot open file for writing: '%s'\n", name);
123 fwrite(encoded_data, encoded_data_size, 1, fp);
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_kdtree_nd_() free(KDTree *tree)
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
bool imb_addrectImBuf(struct ImBuf *ibuf)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)
ccl_gpu_kernel_postfix ccl_global float int num_pixels
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
ImbFormatOptions foptions
ImBuf * imb_loadwebp(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
bool imb_savewebp(struct ImBuf *ibuf, const char *name, int UNUSED(flags))
bool imb_is_a_webp(const unsigned char *buf, size_t size)