mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
Merge "Add Mux library for manipulating WebP container."
This commit is contained in:
commit
5f31b5ec64
@ -156,6 +156,7 @@ AC_CONFIG_FILES([Makefile src/Makefile man/Makefile \
|
|||||||
examples/Makefile src/dec/Makefile \
|
examples/Makefile src/dec/Makefile \
|
||||||
src/enc/Makefile src/dsp/Makefile \
|
src/enc/Makefile src/dsp/Makefile \
|
||||||
src/utils/Makefile \
|
src/utils/Makefile \
|
||||||
|
src/mux/Makefile \
|
||||||
src/libwebp.pc])
|
src/libwebp.pc])
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# system, for simple local building of the libraries and tools.
|
# system, for simple local building of the libraries and tools.
|
||||||
# It will not install the libraries system-wide, but just create the 'cwebp'
|
# It will not install the libraries system-wide, but just create the 'cwebp'
|
||||||
# and 'dwebp' tools in the examples/ directory, along with the static
|
# and 'dwebp' tools in the examples/ directory, along with the static
|
||||||
# library 'src/libwebp.a'.
|
# libraries 'src/libwebp.a' and 'src/mux/libwebpmux.a'.
|
||||||
#
|
#
|
||||||
# To build the library and examples, use:
|
# To build the library and examples, use:
|
||||||
# make -f makefile.unix
|
# make -f makefile.unix
|
||||||
@ -77,9 +77,9 @@ HDRS = src/webp/encode.h src/enc/vp8enci.h src/enc/cost.h \
|
|||||||
src/dsp/yuv.h src/dsp/dsp.h \
|
src/dsp/yuv.h src/dsp/dsp.h \
|
||||||
src/utils/bit_writer.h src/utils/bit_reader.h src/utils/thread.h
|
src/utils/bit_writer.h src/utils/bit_reader.h src/utils/thread.h
|
||||||
|
|
||||||
OUTPUT = examples/cwebp examples/dwebp src/libwebp.a
|
OUTPUT = examples/cwebp examples/dwebp src/libwebp.a src/mux/libwebpmux.a
|
||||||
|
|
||||||
all:ex
|
all:ex src/mux/libwebpmux.a
|
||||||
|
|
||||||
%.o: %.c $(HDRS)
|
%.o: %.c $(HDRS)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
@ -87,6 +87,11 @@ all:ex
|
|||||||
src/libwebp.a: $(OBJS)
|
src/libwebp.a: $(OBJS)
|
||||||
$(AR) $(ARFLAGS) $@ $^
|
$(AR) $(ARFLAGS) $@ $^
|
||||||
|
|
||||||
|
MUX_OBJS = src/mux/mux.o
|
||||||
|
|
||||||
|
src/mux/libwebpmux.a: $(MUX_OBJS)
|
||||||
|
$(AR) $(ARFLAGS) $@ $^
|
||||||
|
|
||||||
ex: examples/cwebp examples/dwebp
|
ex: examples/cwebp examples/dwebp
|
||||||
|
|
||||||
examples/cwebp: examples/cwebp.o src/libwebp.a
|
examples/cwebp: examples/cwebp.o src/libwebp.a
|
||||||
@ -116,6 +121,7 @@ clean:
|
|||||||
src/dec/*.o src/dec/*~ \
|
src/dec/*.o src/dec/*~ \
|
||||||
src/dsp/*.o src/dsp/*~ \
|
src/dsp/*.o src/dsp/*~ \
|
||||||
src/utils/*.o src/utils/*~ \
|
src/utils/*.o src/utils/*~ \
|
||||||
|
src/mux/*.o src/mux/*~ \
|
||||||
examples/*.o examples/*~
|
examples/*.o examples/*~
|
||||||
|
|
||||||
superclean: clean
|
superclean: clean
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
SUBDIRS = dec enc dsp utils
|
SUBDIRS = dec enc dsp utils mux
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(top_srcdir)/src
|
AM_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
lib_LTLIBRARIES = libwebp.la
|
lib_LTLIBRARIES = libwebp.la
|
||||||
|
7
src/mux/Makefile.am
Normal file
7
src/mux/Makefile.am
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
AM_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
lib_LTLIBRARIES = libwebpmux.la
|
||||||
|
|
||||||
|
libwebpmux_la_SOURCES = mux.c
|
||||||
|
libwebpmux_la_LDFLAGS = -version-info 0:0:0
|
||||||
|
libwebpmuxinclude_HEADERS = ../webp/mux.h ../webp/types.h
|
||||||
|
libwebpmuxincludedir = $(includedir)/webp
|
1321
src/mux/mux.c
Normal file
1321
src/mux/mux.c
Normal file
File diff suppressed because it is too large
Load Diff
287
src/webp/mux.h
Normal file
287
src/webp/mux.h
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
// Copyright 2011 Google Inc.
|
||||||
|
//
|
||||||
|
// This code is licensed under the same terms as WebM:
|
||||||
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
||||||
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// RIFF container manipulation for WEBP images.
|
||||||
|
//
|
||||||
|
// Author: Urvang (urvang@google.com)
|
||||||
|
|
||||||
|
#ifndef WEBP_WEBP_MUX_H_
|
||||||
|
#define WEBP_WEBP_MUX_H_
|
||||||
|
|
||||||
|
#include "webp/types.h"
|
||||||
|
|
||||||
|
#if defined(__cplusplus) || defined(c_plusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Error codes
|
||||||
|
typedef enum {
|
||||||
|
WEBP_MUX_OK = 1,
|
||||||
|
WEBP_MUX_ERROR = 0,
|
||||||
|
WEBP_MUX_NOT_FOUND = -1,
|
||||||
|
WEBP_MUX_INVALID_ARGUMENT = -2,
|
||||||
|
WEBP_MUX_INVALID_PARAMETER = -3,
|
||||||
|
WEBP_MUX_BAD_DATA = -4,
|
||||||
|
WEBP_MUX_MEMORY_ERROR = -5
|
||||||
|
} WebPMuxError;
|
||||||
|
|
||||||
|
// Flag values for different features used in VP8X chunk.
|
||||||
|
typedef enum {
|
||||||
|
TILE_FLAG = 0x00000001,
|
||||||
|
ANIMATION_FLAG = 0x00000002,
|
||||||
|
ICCP_FLAG = 0x00000004,
|
||||||
|
META_FLAG = 0x00000008
|
||||||
|
} FeatureFlags;
|
||||||
|
|
||||||
|
typedef struct WebPMux WebPMux; // main opaque object.
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Life of a Mux object
|
||||||
|
|
||||||
|
// Creates an empty mux object.
|
||||||
|
// Returns:
|
||||||
|
// A pointer to the newly created empty mux object.
|
||||||
|
WEBP_EXTERN(WebPMux*) WebPMuxNew(void);
|
||||||
|
|
||||||
|
// Deletes the mux object.
|
||||||
|
WEBP_EXTERN(void) WebPMuxDelete(WebPMux* const mux);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Writing
|
||||||
|
|
||||||
|
// Creates a mux object from raw data given in WebP RIFF format.
|
||||||
|
// WebPMuxNew() should be called before calling this function.
|
||||||
|
// copy_data - value 1 indicates given data WILL copied to the mux object, and
|
||||||
|
// value 0 indicates data will NOT be copied.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or data is NULL
|
||||||
|
// WEBP_MUX_BAD_DATA - if data cannot be read as a mux object.
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxCreate(WebPMux* const mux, const uint8_t* data,
|
||||||
|
uint32_t size, int copy_data);
|
||||||
|
|
||||||
|
// Sets the XMP metadata in the mux object. Any existing metadata chunk(s) will
|
||||||
|
// be removed.
|
||||||
|
// copy_data - value 1 indicates given data WILL copied to the mux object, and
|
||||||
|
// value 0 indicates data will NOT be copied.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or data is NULL.
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxSetMetadata(WebPMux* const mux,
|
||||||
|
const uint8_t* data,
|
||||||
|
uint32_t size, int copy_data);
|
||||||
|
|
||||||
|
// Sets the color profile in the mux object. Any existing color profile chunk(s)
|
||||||
|
// will be removed.
|
||||||
|
// copy_data - value 1 indicates given data WILL copied to the mux object, and
|
||||||
|
// value 0 indicates data will NOT be copied.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or data is NULL
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error
|
||||||
|
// WEBP_MUX_OK - on success
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxSetColorProfile(WebPMux* const mux,
|
||||||
|
const uint8_t* data,
|
||||||
|
uint32_t size, int copy_data);
|
||||||
|
|
||||||
|
// Sets the animation loop count in the mux object. Any existing loop count
|
||||||
|
// value(s) will be removed.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxSetLoopCount(WebPMux* const mux,
|
||||||
|
uint32_t loop_count);
|
||||||
|
|
||||||
|
// Adds an animation frame to the mux object.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// duration is in milliseconds.
|
||||||
|
// copy_data - value 1 indicates given data WILL copied to the mux object, and
|
||||||
|
// value 0 indicates data will NOT be copied.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or data is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If we have less than (nth-1) frames before adding.
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxAddFrame(WebPMux* const mux, uint32_t nth,
|
||||||
|
const uint8_t* data, uint32_t size,
|
||||||
|
uint32_t x_offset, uint32_t y_offset,
|
||||||
|
uint32_t duration, int copy_data);
|
||||||
|
|
||||||
|
// Adds a tile to the mux object.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// copy_data - value 1 indicates given data WILL copied to the mux object, and
|
||||||
|
// value 0 indicates data will NOT be copied.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or data is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If we have less than (nth-1) tiles before adding.
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxAddTile(WebPMux* const mux, uint32_t nth,
|
||||||
|
const uint8_t* data, uint32_t size,
|
||||||
|
uint32_t x_offset, uint32_t y_offset,
|
||||||
|
int copy_data);
|
||||||
|
|
||||||
|
// Adds a chunk with given tag at nth position.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// copy_data - value 1 indicates given data WILL copied to the mux object, and
|
||||||
|
// value 0 indicates data will NOT be copied.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, tag or data is NULL
|
||||||
|
// WEBP_MUX_INVALID_PARAMETER - if tag is invalid.
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxAddNamedData(WebPMux* const mux, uint32_t nth,
|
||||||
|
const char* const tag,
|
||||||
|
const uint8_t* data,
|
||||||
|
uint32_t size, int copy_data);
|
||||||
|
|
||||||
|
// Deletes the XMP metadata in the mux object.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If mux does not contain metadata.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteMetadata(WebPMux* const mux);
|
||||||
|
|
||||||
|
// Deletes the color profile in the mux object.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If mux does not contain color profile.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteColorProfile(WebPMux* const mux);
|
||||||
|
|
||||||
|
// Deletes an animation frame from the mux object.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object
|
||||||
|
// before deletion.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteFrame(WebPMux* const mux, uint32_t nth);
|
||||||
|
|
||||||
|
// Deletes a tile from the mux object.
|
||||||
|
// nth=0 has a special meaning - last position
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If there are less than nth tiles in the mux object
|
||||||
|
// before deletion.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteTile(WebPMux* const mux, uint32_t nth);
|
||||||
|
|
||||||
|
// Assembles all chunks in WebP RIFF format and returns in output_data.
|
||||||
|
// This function also validates the mux object.
|
||||||
|
// This function does NOT free the mux object. The caller function should free
|
||||||
|
// the mux object and output_data after output_data has been consumed.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_BAD_DATA - if mux object is invalid.
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, output_data or output_size is
|
||||||
|
// NULL.
|
||||||
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
|
// WEBP_MUX_OK - on success
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* const mux,
|
||||||
|
uint8_t** output_data,
|
||||||
|
uint32_t* output_size);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Reading
|
||||||
|
|
||||||
|
// Gets the feature flags from the mux object.
|
||||||
|
// Use enum 'FeatureFlags' to test for individual features.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or flags is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - if VP8X chunk is not present in mux object.
|
||||||
|
// WEBP_MUX_BAD_DATA - if VP8X chunk in mux is invalid.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetFeatures(const WebPMux* mux,
|
||||||
|
uint32_t* flags);
|
||||||
|
|
||||||
|
// Gets a reference to the XMP metadata in the mux object.
|
||||||
|
// The caller should not free the returned data.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either of mux, data or size is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - if metadata is not present in mux object.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetMetadata(const WebPMux* mux,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint32_t* size);
|
||||||
|
|
||||||
|
// Gets a reference to the color profile in the mux object.
|
||||||
|
// The caller should not free the returned data.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either of mux, data or size is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - if color profile is not present in mux object.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetColorProfile(const WebPMux* mux,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint32_t* size);
|
||||||
|
|
||||||
|
// Gets the animation loop count from the mux object.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either of mux or loop_count is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - if loop chunk is not present in mux object.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetLoopCount(const WebPMux* mux,
|
||||||
|
uint32_t* loop_count);
|
||||||
|
|
||||||
|
// Gets a reference to the nth animation frame from the mux object.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// duration is in milliseconds.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, data, size, x_offset,
|
||||||
|
// y_offset, or duration is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object.
|
||||||
|
// WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetFrame(const WebPMux* mux, uint32_t nth,
|
||||||
|
const uint8_t** data, uint32_t* size,
|
||||||
|
uint32_t* x_offset,
|
||||||
|
uint32_t* y_offset,
|
||||||
|
uint32_t* duration);
|
||||||
|
|
||||||
|
// Gets a reference to the nth tile from the mux object.
|
||||||
|
// The caller should not free the returned data.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, data, size, x_offset or
|
||||||
|
// y_offset is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - if there are less than nth tiles in the mux object.
|
||||||
|
// WEBP_MUX_BAD_DATA - if nth tile chunk in mux is invalid.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetTile(const WebPMux* mux, uint32_t nth,
|
||||||
|
const uint8_t** data, uint32_t* size,
|
||||||
|
uint32_t* x_offset,
|
||||||
|
uint32_t* y_offset);
|
||||||
|
|
||||||
|
// Gets number of chunks having tag value tag in the mux object.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, tag or num_elements is NULL
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxNumNamedElements(const WebPMux* mux,
|
||||||
|
const char* tag,
|
||||||
|
int* num_elements);
|
||||||
|
|
||||||
|
// Gets a reference to the nth chunk having tag value tag in the mux object.
|
||||||
|
// The caller should not free the returned data.
|
||||||
|
// nth=0 has a special meaning - last position.
|
||||||
|
// Returns:
|
||||||
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, tag, data or size is NULL
|
||||||
|
// WEBP_MUX_NOT_FOUND - If there are less than nth named elements in the mux
|
||||||
|
// object.
|
||||||
|
// WEBP_MUX_OK - on success.
|
||||||
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetNamedData(const WebPMux* mux,
|
||||||
|
const char* tag, uint32_t nth,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint32_t* size);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(__cplusplus) || defined(c_plusplus)
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WEBP_WEBP_MUX_H_ */
|
Loading…
Reference in New Issue
Block a user