From 4708393c3b647480046d72d42e7b67eef768dee2 Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 21 Jun 2012 18:27:54 -0700 Subject: [PATCH] demux: add {Next,Prev}Chunk replaces WebPDemuxSetChunk(). makes this consistent with the Frame interface. Change-Id: Ia2b1b98cc290f35b41fd14ee35a2a17cecac7ba8 --- src/mux/demux.c | 16 +++++++++++++--- src/webp/mux.h | 7 ++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mux/demux.c b/src/mux/demux.c index 2b4caf2f..d219ddfe 100644 --- a/src/mux/demux.c +++ b/src/mux/demux.c @@ -853,10 +853,20 @@ int WebPDemuxGetChunk(const WebPDemuxer* const dmux, return SetChunk(fourcc, chunk_num, iter); } -int WebPDemuxSetChunk(WebPChunkIterator* const iter, int chunk) { +int WebPDemuxNextChunk(WebPChunkIterator* const iter) { if (iter != NULL) { - const uint8_t* const header = iter->chunk_.bytes_ - CHUNK_HEADER_SIZE; - return SetChunk((const char*)header, chunk, iter); + const char* const fourcc = + (const char*)iter->chunk_.bytes_ - CHUNK_HEADER_SIZE; + return SetChunk(fourcc, iter->chunk_num_ + 1, iter); + } + return 0; +} + +int WebPDemuxPrevChunk(WebPChunkIterator* const iter) { + if (iter != NULL && iter->chunk_num_ > 1) { + const char* const fourcc = + (const char*)iter->chunk_.bytes_ - CHUNK_HEADER_SIZE; + return SetChunk(fourcc, iter->chunk_num_ - 1, iter); } return 0; } diff --git a/src/webp/mux.h b/src/webp/mux.h index ee3a7d4a..c86fd5a9 100644 --- a/src/webp/mux.h +++ b/src/webp/mux.h @@ -585,10 +585,11 @@ WEBP_EXTERN(int) WebPDemuxGetChunk(const WebPDemuxer* const dmux, const char fourcc[4], int chunk_number, WebPChunkIterator* const iter); -// Sets 'iter->chunk_' to point to chunk 'chunk_number'. +// Sets 'iter->chunk_' to point to the next ('iter->chunk_num_' + 1) or previous +// ('iter->chunk_num_' - 1) chunk. These functions do not loop. // Returns true on success, false otherwise. -WEBP_EXTERN(int) WebPDemuxSetChunk(WebPChunkIterator* const iter, - int chunk_number); +WEBP_EXTERN(int) WebPDemuxNextChunk(WebPChunkIterator* const iter); +WEBP_EXTERN(int) WebPDemuxPrevChunk(WebPChunkIterator* const iter); // Releases any memory associated with 'iter'. // Must be called before destroying the associated WebPDemuxer with