18#include <webp/decode.h>
37 WebPDecBuffer output_buffer;
44static void Webp_free(DilloWebp *webp)
46 _MSG(
"Webp_free: webp=%p\n", webp);
48 WebPFreeDecBuffer(&webp->output_buffer);
50 WebPIDelete(webp->idec);
95 DilloWebp *webp = (DilloWebp *)Client->
CbData;
98 WebPBitstreamFeatures features;
100 ret = WebPGetFeatures(Client->
Buf, Client->
BufSize, &features);
101 if (ret != VP8_STATUS_OK) {
102 MSG(
"features ret is %d\n", ret);
105 if (features.has_alpha) {
106 _MSG(
"WEBP: Alpha!\n");
108 webp->output_buffer.colorspace = features.has_alpha ? MODE_RGBA : MODE_RGB;
111 features.width, features.height,
114 webp->idec = WebPINewDecoder(&webp->output_buffer);
118 ret = WebPIUpdate(webp->idec, Client->
Buf, Client->
BufSize);
120 if (ret == VP8_STATUS_SUSPENDED || ret == VP8_STATUS_OK) {
124 int last_y, width, height, stride;
126 _MSG(
"webp completed. status: %s\n", ret == VP8_STATUS_SUSPENDED ?
"suspended" :
"ok (done)");
127 output = WebPIDecGetRGB(webp->idec, &last_y, &width, &height, &stride);
129 _MSG(
"webp decoding no output\n");
134 if (webp->output_buffer.colorspace == MODE_RGBA)
135 line =
dNew(
unsigned char, width * 3);
137 line = output + row * stride;
139 for (; row < last_y; row++) {
141 if (webp->output_buffer.colorspace == MODE_RGBA) {
144 uint_t bg_blue = (webp->bgcolor) & 0xFF;
145 uint_t bg_green = (webp->bgcolor>>8) & 0xFF;
146 uint_t bg_red = (webp->bgcolor>>16) & 0xFF;
147 for (j = 0; j < width; j++) {
148 uchar_t alpha = output[row * stride + 4 * j + 3];
149 uchar_t r = output[row * stride + 4 * j];
150 uchar_t g = output[row * stride + 4 * j + 1];
151 uchar_t b = output[row * stride + 4 * j + 2];
152 line[3 * j] = (r * alpha + (bg_red * (0xFF - alpha))) / 0xFF;
153 line[3 * j + 1] = (g * alpha + (bg_green * (0xFF - alpha))) / 0xFF;
154 line[3 * j + 2] = (b * alpha + (bg_blue * (0xFF - alpha))) / 0xFF;
157 line = output + row * stride;
163 if (webp->output_buffer.colorspace == MODE_RGBA)
167 MSG(
"webp WebPIUpdate failed with %d\n", ret);
170 Webp_close(Client->
CbData, Client);
181 int ver = WebPGetDecoderVersion();
183 int major = (ver >> 16) & 0xff;
184 int minor = (ver >> 8) & 0xff;
185 int rev = (ver >> 0) & 0xff;
187 int k = snprintf(buf, n,
"%d.%d.%d", major, minor, rev);
198 DilloWebp *webp =
dNew0(DilloWebp, 1);
199 _MSG(
"a_Webp_new: webp=%p\n", webp);
203 webp->version = version;
209 WebPInitDecBuffer(&webp->output_buffer);
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image, uint_t width, uint_t height, DilloImgType type, double gamma)
Set image's width, height & type.
void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
Implement the close method of the decoding process.
void a_Dicache_write(DilloUrl *url, int version, const uchar_t *buf, uint_t Y)
Implement the write method (Write a scan line into the Dicache entry) buf: row buffer Y : row number.
#define dNew0(type, count)
#define dNew(type, count)
Data structure for cache clients.
void * CbData
Client function data.
uint_t BufSize
Valid size of cache-data.
void * Buf
Pointer to cache-data.
int32_t bg_color
Background color.
const char * a_Webp_version(char *buf, int n)