mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
vwebp: use demux interface
fixes broken build since:
ab3234a
Create WebPMuxFrameInfo struct for Mux APIs
Change-Id: I19d472f672b9234b15425a2e55ca89a3ea35bd64
This commit is contained in:
parent
931e0ea1d5
commit
d7a5ac86b9
@ -46,22 +46,15 @@ static struct {
|
|||||||
int decoding_error;
|
int decoding_error;
|
||||||
int print_info;
|
int print_info;
|
||||||
|
|
||||||
uint32_t flags;
|
|
||||||
int loop_count;
|
int loop_count;
|
||||||
int frame_num;
|
|
||||||
int frame_max;
|
|
||||||
|
|
||||||
const char* file_name;
|
const char* file_name;
|
||||||
WebPData data;
|
WebPData data;
|
||||||
WebPMux* mux;
|
|
||||||
WebPDecoderConfig* config;
|
WebPDecoderConfig* config;
|
||||||
const WebPDecBuffer* pic;
|
const WebPDecBuffer* pic;
|
||||||
} kParams = {
|
WebPDemuxer* dmux;
|
||||||
0, 0, 0, 0, // has_animation, ...
|
WebPIterator frameiter;
|
||||||
0, 1, 1, 0, // flags, ...
|
} kParams;
|
||||||
NULL, { NULL, 0 }, // file_name, ...
|
|
||||||
NULL, NULL, NULL // mux, ...
|
|
||||||
};
|
|
||||||
|
|
||||||
static void ClearPreviousPic(void) {
|
static void ClearPreviousPic(void) {
|
||||||
WebPFreeDecBuffer((WebPDecBuffer*)kParams.pic);
|
WebPFreeDecBuffer((WebPDecBuffer*)kParams.pic);
|
||||||
@ -71,8 +64,9 @@ static void ClearPreviousPic(void) {
|
|||||||
static void ClearParams(void) {
|
static void ClearParams(void) {
|
||||||
ClearPreviousPic();
|
ClearPreviousPic();
|
||||||
WebPDataClear(&kParams.data);
|
WebPDataClear(&kParams.data);
|
||||||
WebPMuxDelete(kParams.mux);
|
WebPDemuxReleaseIterator(&kParams.frameiter);
|
||||||
kParams.mux = NULL;
|
WebPDemuxDelete(kParams.dmux);
|
||||||
|
kParams.dmux = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -177,36 +171,24 @@ static void StartDisplay(const WebPDecBuffer* const pic) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// File decoding
|
// File decoding
|
||||||
|
|
||||||
static int Decode(const int frame_number, int* const duration) {
|
static int Decode(int* const duration) {
|
||||||
|
const WebPIterator* const iter = &kParams.frameiter;
|
||||||
WebPDecoderConfig* const config = kParams.config;
|
WebPDecoderConfig* const config = kParams.config;
|
||||||
WebPData *data, image_data;
|
|
||||||
int x_off = 0, y_off = 0;
|
|
||||||
WebPDecBuffer* const output_buffer = &config->output;
|
WebPDecBuffer* const output_buffer = &config->output;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
ClearPreviousPic();
|
ClearPreviousPic();
|
||||||
if (kParams.has_animation) {
|
if (iter->x_offset_ != 0 || iter->y_offset_ != 0) {
|
||||||
if (WebPMuxGetFrame(kParams.mux, frame_number, &image_data,
|
|
||||||
&x_off, &y_off, duration) != WEBP_MUX_OK) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
if (x_off != 0 || y_off != 0) {
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Frame offsets not yet supported! Forcing offset to 0,0\n");
|
"Frame offsets not yet supported! Forcing offset to 0,0\n");
|
||||||
x_off = y_off = 0;
|
|
||||||
}
|
}
|
||||||
data = &image_data;
|
|
||||||
} else {
|
|
||||||
data = &kParams.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
output_buffer->colorspace = MODE_RGBA;
|
output_buffer->colorspace = MODE_RGBA;
|
||||||
ok = (WebPDecode(data->bytes_, data->size_, config) == VP8_STATUS_OK);
|
ok = (WebPDecode(iter->tile_.bytes_, iter->tile_.size_,
|
||||||
|
config) == VP8_STATUS_OK);
|
||||||
end:
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
fprintf(stderr, "Decoding of frame #%d failed!\n", frame_number);
|
fprintf(stderr, "Decoding of frame #%d failed!\n", iter->frame_num_);
|
||||||
} else {
|
} else {
|
||||||
|
*duration = iter->duration_;
|
||||||
kParams.pic = output_buffer;
|
kParams.pic = output_buffer;
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
@ -215,16 +197,21 @@ static int Decode(const int frame_number, int* const duration) {
|
|||||||
static void decode_callback(int what) {
|
static void decode_callback(int what) {
|
||||||
if (what == 0 && !kParams.done) {
|
if (what == 0 && !kParams.done) {
|
||||||
int duration = 0;
|
int duration = 0;
|
||||||
if (kParams.mux != NULL) {
|
if (kParams.dmux != NULL) {
|
||||||
if (!Decode(kParams.frame_num, &duration)) {
|
if (!Decode(&duration)) {
|
||||||
kParams.decoding_error = 1;
|
kParams.decoding_error = 1;
|
||||||
kParams.done = 1;
|
kParams.done = 1;
|
||||||
} else {
|
} else {
|
||||||
++kParams.frame_num;
|
WebPIterator* const iter = &kParams.frameiter;
|
||||||
if (kParams.frame_num > kParams.frame_max) {
|
if (!WebPDemuxNextFrame(iter)) {
|
||||||
kParams.frame_num = 1;
|
WebPDemuxReleaseIterator(iter);
|
||||||
|
if (WebPDemuxGetFrame(kParams.dmux, 1, iter)) {
|
||||||
--kParams.loop_count;
|
--kParams.loop_count;
|
||||||
kParams.done = (kParams.loop_count == 0);
|
kParams.done = (kParams.loop_count == 0);
|
||||||
|
} else {
|
||||||
|
kParams.decoding_error = 1;
|
||||||
|
kParams.done = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,7 +239,6 @@ static void Help(void) {
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
WebPDecoderConfig config;
|
WebPDecoderConfig config;
|
||||||
WebPMuxError mux_err;
|
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if (!WebPInitDecoderConfig(&config)) {
|
if (!WebPInitDecoderConfig(&config)) {
|
||||||
@ -306,41 +292,28 @@ int main(int argc, char *argv[]) {
|
|||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
kParams.mux = WebPMuxCreate(&kParams.data, 0);
|
kParams.dmux = WebPDemux(&kParams.data);
|
||||||
if (kParams.mux == NULL) {
|
if (kParams.dmux == NULL) {
|
||||||
fprintf(stderr, "Could not create demuxing object!\n");
|
fprintf(stderr, "Could not create demuxing object!\n");
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
mux_err = WebPMuxGetFeatures(kParams.mux, &kParams.flags);
|
if (WebPDemuxGetI(kParams.dmux, WEBP_FF_FORMAT_FLAGS) & TILE_FLAG) {
|
||||||
if (mux_err != WEBP_MUX_OK) {
|
|
||||||
goto Error;
|
|
||||||
}
|
|
||||||
if (kParams.flags & TILE_FLAG) {
|
|
||||||
fprintf(stderr, "Tiling is not supported for now!\n");
|
fprintf(stderr, "Tiling is not supported for now!\n");
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
kParams.has_animation = !!(kParams.flags & ANIMATION_FLAG);
|
if (!WebPDemuxGetFrame(kParams.dmux, 1, &kParams.frameiter)) goto Error;
|
||||||
|
|
||||||
if (kParams.has_animation) {
|
kParams.has_animation = (kParams.frameiter.num_frames_ > 1);
|
||||||
mux_err = WebPMuxGetLoopCount(kParams.mux, &kParams.loop_count);
|
kParams.loop_count = (int)WebPDemuxGetI(kParams.dmux, WEBP_FF_LOOP_COUNT);
|
||||||
if (mux_err != WEBP_MUX_OK && mux_err != WEBP_MUX_NOT_FOUND) {
|
|
||||||
goto Error;
|
|
||||||
}
|
|
||||||
mux_err = WebPMuxNumChunks(kParams.mux, WEBP_CHUNK_IMAGE,
|
|
||||||
&kParams.frame_max);
|
|
||||||
if (mux_err != WEBP_MUX_OK) {
|
|
||||||
goto Error;
|
|
||||||
}
|
|
||||||
printf("VP8X: Found %d images in file (loop count = %d)\n",
|
printf("VP8X: Found %d images in file (loop count = %d)\n",
|
||||||
kParams.frame_max, kParams.loop_count);
|
kParams.frameiter.num_frames_, kParams.loop_count);
|
||||||
}
|
|
||||||
|
|
||||||
// Decode first frame
|
// Decode first frame
|
||||||
{
|
{
|
||||||
int duration;
|
int duration;
|
||||||
if (!Decode(1, &duration)) goto Error;
|
if (!Decode(&duration)) goto Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start display (and timer)
|
// Start display (and timer)
|
||||||
|
Loading…
Reference in New Issue
Block a user