mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-19 20:08:28 +01:00
collect all decoding utilities from examples/ in libexampledec.a
adds a generic examples/image_dec.[ch] entry point too. WebPGuessImageType() can be used to infer image type. Change-Id: I8337e7b6ad91863c9cf118e4791668d2d175079b
This commit is contained in:
parent
0b8ae8520f
commit
ae2a7222ce
@ -287,6 +287,28 @@ if(WEBP_BUILD_CWEBP OR WEBP_BUILD_DWEBP)
|
||||
target_link_libraries(exampleutil webp ${WEBP_DEP_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_CWEBP)
|
||||
# Image-decoding utility library.
|
||||
set(exampledec_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/image_dec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/image_dec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/jpegdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/jpegdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/metadata.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/metadata.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/pngdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/pngdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/tiffdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/tiffdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/webpdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/webpdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/wicdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/wicdec.h)
|
||||
add_library(exampledec ${exampledec_SRCS})
|
||||
target_link_libraries(exampledec webp ${WEBP_DEP_LIBRARIES}
|
||||
${WEBP_DEP_IMG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_DWEBP)
|
||||
# dwebp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
@ -304,20 +326,8 @@ if(WEBP_BUILD_CWEBP)
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
add_executable(cwebp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/cwebp.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/metadata.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/metadata.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/jpegdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/jpegdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/pngdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/pngdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/tiffdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/tiffdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/webpdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/webpdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/wicdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/wicdec.h)
|
||||
target_link_libraries(cwebp webp exampleutil ${WEBP_DEP_LIBRARIES}
|
||||
${WEBP_DEP_IMG_LIBRARIES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h)
|
||||
target_link_libraries(cwebp exampledec webp exampleutil
|
||||
${WEBP_DEP_LIBRARIES} ${WEBP_DEP_IMG_LIBRARIES}
|
||||
)
|
||||
endif()
|
||||
|
@ -244,6 +244,7 @@ EX_ANIM_UTIL_OBJS = \
|
||||
$(DIROBJ)\examples\anim_util.obj \
|
||||
|
||||
EX_FORMAT_DEC_OBJS = \
|
||||
$(DIROBJ)\examples\image_dec.obj \
|
||||
$(DIROBJ)\examples\jpegdec.obj \
|
||||
$(DIROBJ)\examples\metadata.obj \
|
||||
$(DIROBJ)\examples\pngdec.obj \
|
||||
|
26
build.gradle
26
build.gradle
@ -241,10 +241,31 @@ model {
|
||||
}
|
||||
}
|
||||
|
||||
example_dec(NativeLibrarySpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "webp", linkage: "static"
|
||||
}
|
||||
}
|
||||
sources {
|
||||
c {
|
||||
source {
|
||||
srcDir "./examples"
|
||||
include "image_dec.c"
|
||||
include "jpegdec.c"
|
||||
include "metadata.c"
|
||||
include "pngdec.c"
|
||||
include "tiffdec.c"
|
||||
include "webpdec.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cwebp(NativeExecutableSpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "example_util", linkage: "static"
|
||||
lib library: "example_dec", linkage: "static"
|
||||
lib library: "webp", linkage: "static"
|
||||
}
|
||||
}
|
||||
@ -253,11 +274,6 @@ model {
|
||||
source {
|
||||
srcDir "./examples"
|
||||
include "cwebp.c"
|
||||
include "jpegdec.c"
|
||||
include "metadata.c"
|
||||
include "pngdec.c"
|
||||
include "tiffdec.c"
|
||||
include "webpdec.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,27 @@ LOCAL_MODULE := example_util
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
# libexample_dec
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
image_dec.c \
|
||||
jpegdec.c \
|
||||
metadata.c \
|
||||
pngdec.c \
|
||||
tiffdec.c \
|
||||
webpdec.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
|
||||
LOCAL_MODULE := example_dec
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
################################################################################
|
||||
# cwebp
|
||||
|
||||
@ -24,15 +45,10 @@ include $(CLEAR_VARS)
|
||||
# minor modification to their Android.mk files.
|
||||
LOCAL_SRC_FILES := \
|
||||
cwebp.c \
|
||||
jpegdec.c \
|
||||
metadata.c \
|
||||
pngdec.c \
|
||||
tiffdec.c \
|
||||
webpdec.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util webp
|
||||
LOCAL_STATIC_LIBRARIES := example_util example_dec webp
|
||||
|
||||
LOCAL_MODULE := cwebp
|
||||
|
||||
|
@ -12,10 +12,20 @@ if BUILD_GIF2WEBP
|
||||
bin_PROGRAMS += gif2webp
|
||||
endif
|
||||
|
||||
noinst_LTLIBRARIES = libexampleutil.la
|
||||
noinst_LTLIBRARIES = libexampleutil.la libexampledec.la
|
||||
|
||||
libexampleutil_la_SOURCES = example_util.c example_util.h stopwatch.h
|
||||
|
||||
libexampledec_la_SOURCES = image_dec.c image_dec.h
|
||||
libexampledec_la_SOURCES += jpegdec.c jpegdec.h
|
||||
libexampledec_la_SOURCES += metadata.c metadata.h
|
||||
libexampledec_la_SOURCES += pngdec.c pngdec.h
|
||||
libexampledec_la_SOURCES += tiffdec.c tiffdec.h
|
||||
libexampledec_la_SOURCES += webpdec.c webpdec.h
|
||||
libexampledec_la_SOURCES += wicdec.c wicdec.h
|
||||
libexampledec_la_CPPFLAGS = $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
|
||||
libexampledec_la_CPPFLAGS += $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
|
||||
if BUILD_ANIMDIFF
|
||||
noinst_PROGRAMS = anim_diff
|
||||
endif
|
||||
@ -31,15 +41,9 @@ dwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
dwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES)
|
||||
dwebp_LDADD = libexampleutil.la $(PNG_LIBS) $(JPEG_LIBS)
|
||||
|
||||
cwebp_SOURCES = cwebp.c metadata.c metadata.h stopwatch.h
|
||||
cwebp_SOURCES += jpegdec.c jpegdec.h
|
||||
cwebp_SOURCES += pngdec.c pngdec.h
|
||||
cwebp_SOURCES += tiffdec.c tiffdec.h
|
||||
cwebp_SOURCES += webpdec.c webpdec.h
|
||||
cwebp_SOURCES += wicdec.c wicdec.h
|
||||
cwebp_SOURCES = cwebp.c stopwatch.h
|
||||
cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
cwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
|
||||
cwebp_LDADD = libexampleutil.la ../src/libwebp.la
|
||||
cwebp_LDADD = libexampleutil.la libexampledec.la ../src/libwebp.la
|
||||
cwebp_LDADD += $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS)
|
||||
|
||||
gif2webp_SOURCES = gif2webp.c gifdec.c gifdec.h
|
||||
|
@ -20,17 +20,10 @@
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#include "webp/encode.h"
|
||||
|
||||
#include "./example_util.h"
|
||||
#include "./metadata.h"
|
||||
#include "./image_dec.h"
|
||||
#include "./stopwatch.h"
|
||||
|
||||
#include "./jpegdec.h"
|
||||
#include "./pngdec.h"
|
||||
#include "./tiffdec.h"
|
||||
#include "./webpdec.h"
|
||||
#include "./wicdec.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#ifndef WEBP_DLL
|
||||
#ifdef __cplusplus
|
||||
@ -102,34 +95,6 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
|
||||
#else // !HAVE_WINCODEC_H
|
||||
|
||||
typedef enum {
|
||||
PNG_ = 0,
|
||||
JPEG_,
|
||||
TIFF_, // 'TIFF' clashes with libtiff
|
||||
WEBP_,
|
||||
UNSUPPORTED
|
||||
} InputFileFormat;
|
||||
|
||||
static uint32_t GetBE32(const uint8_t buf[]) {
|
||||
return ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||
}
|
||||
|
||||
static InputFileFormat GuessImageType(const uint8_t buf[12]) {
|
||||
InputFileFormat format = UNSUPPORTED;
|
||||
const uint32_t magic1 = GetBE32(buf + 0);
|
||||
const uint32_t magic2 = GetBE32(buf + 8);
|
||||
if (magic1 == 0x89504E47U) {
|
||||
format = PNG_;
|
||||
} else if (magic1 >= 0xFFD8FF00U && magic1 <= 0xFFD8FFFFU) {
|
||||
format = JPEG_;
|
||||
} else if (magic1 == 0x49492A00 || magic1 == 0x4D4D002A) {
|
||||
format = TIFF_;
|
||||
} else if (magic1 == 0x52494646 && magic2 == 0x57454250) {
|
||||
format = WEBP_;
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
int keep_alpha, Metadata* const metadata) {
|
||||
const uint8_t* data = NULL;
|
||||
@ -142,14 +107,14 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
if (pic->width == 0 || pic->height == 0) {
|
||||
ok = 0;
|
||||
if (data_size >= 12) {
|
||||
const InputFileFormat format = GuessImageType(data);
|
||||
if (format == PNG_) {
|
||||
const WebPInputFileFormat format = WebPGuessImageType(data, data_size);
|
||||
if (format == WEBP_PNG_FORMAT) {
|
||||
ok = ReadPNG(data, data_size, pic, keep_alpha, metadata);
|
||||
} else if (format == JPEG_) {
|
||||
} else if (format == WEBP_JPEG_FORMAT) {
|
||||
ok = ReadJPEG(data, data_size, pic, metadata);
|
||||
} else if (format == TIFF_) {
|
||||
} else if (format == WEBP_TIFF_FORMAT) {
|
||||
ok = ReadTIFF(data, data_size, pic, keep_alpha, metadata);
|
||||
} else if (format == WEBP_) {
|
||||
} else if (format == WEBP_WEBP_FORMAT) {
|
||||
ok = ReadWebP(data, data_size, pic, keep_alpha, metadata);
|
||||
}
|
||||
}
|
||||
|
35
examples/image_dec.c
Normal file
35
examples/image_dec.c
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING file in the root of the source
|
||||
// tree. An additional intellectual property rights grant can be found
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Generic image-type guessing.
|
||||
|
||||
#include "./image_dec.h"
|
||||
|
||||
static WEBP_INLINE uint32_t GetBE32(const uint8_t buf[]) {
|
||||
return ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||
}
|
||||
|
||||
WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
||||
size_t data_size) {
|
||||
WebPInputFileFormat format = WEBP_UNSUPPORTED_FORMAT;
|
||||
if (data != NULL && data_size >= 12) {
|
||||
const uint32_t magic1 = GetBE32(data + 0);
|
||||
const uint32_t magic2 = GetBE32(data + 8);
|
||||
if (magic1 == 0x89504E47U) {
|
||||
format = WEBP_PNG_FORMAT;
|
||||
} else if (magic1 >= 0xFFD8FF00U && magic1 <= 0xFFD8FFFFU) {
|
||||
format = WEBP_JPEG_FORMAT;
|
||||
} else if (magic1 == 0x49492A00 || magic1 == 0x4D4D002A) {
|
||||
format = WEBP_TIFF_FORMAT;
|
||||
} else if (magic1 == 0x52494646 && magic2 == 0x57454250) {
|
||||
format = WEBP_WEBP_FORMAT;
|
||||
}
|
||||
}
|
||||
return format;
|
||||
}
|
51
examples/image_dec.h
Normal file
51
examples/image_dec.h
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING file in the root of the source
|
||||
// tree. An additional intellectual property rights grant can be found
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// All-in-one library to decode PNG/JPEG/WebP/TIFF/WIC input images.
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#ifndef WEBP_EXAMPLES_IMAGE_DEC_H_
|
||||
#define WEBP_EXAMPLES_IMAGE_DEC_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#include "./metadata.h"
|
||||
#include "./jpegdec.h"
|
||||
#include "./pngdec.h"
|
||||
#include "./tiffdec.h"
|
||||
#include "./webpdec.h"
|
||||
#include "./wicdec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
WEBP_PNG_FORMAT = 0,
|
||||
WEBP_JPEG_FORMAT,
|
||||
WEBP_TIFF_FORMAT,
|
||||
WEBP_WEBP_FORMAT,
|
||||
WEBP_UNSUPPORTED_FORMAT
|
||||
} WebPInputFileFormat;
|
||||
|
||||
// Try to infer the image format. 'data_size' should be larger than 12.
|
||||
// Returns WEBP_UNSUPPORTED_FORMAT if format can't be guess safely.
|
||||
WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
||||
size_t data_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_IMAGE_DEC_H_
|
@ -201,6 +201,7 @@ ENC_OBJS = \
|
||||
src/enc/webpenc.o \
|
||||
|
||||
EX_FORMAT_DEC_OBJS = \
|
||||
examples/image_dec.o \
|
||||
examples/jpegdec.o \
|
||||
examples/metadata.o \
|
||||
examples/pngdec.o \
|
||||
@ -321,6 +322,7 @@ src/utils/bit_writer.o: src/utils/endian_inl.h
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
examples/libanim_util.a: $(ANIM_UTIL_OBJS)
|
||||
examples/libexample_dec.a: $(EX_FORMAT_DEC_OBJS)
|
||||
examples/libexample_util.a: $(EX_UTIL_OBJS)
|
||||
examples/libgifdec.a: $(GIFDEC_OBJS)
|
||||
src/libwebpdecoder.a: $(LIBWEBPDECODER_OBJS)
|
||||
@ -333,7 +335,7 @@ src/libwebpextras.a: $(LIBWEBPEXTRA_OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
examples/anim_diff: examples/anim_diff.o $(ANIM_UTIL_OBJS) $(GIFDEC_OBJS)
|
||||
examples/cwebp: examples/cwebp.o $(EX_FORMAT_DEC_OBJS)
|
||||
examples/cwebp: examples/cwebp.o
|
||||
examples/dwebp: examples/dwebp.o
|
||||
examples/gif2webp: examples/gif2webp.o $(GIFDEC_OBJS)
|
||||
examples/vwebp: examples/vwebp.o
|
||||
@ -344,7 +346,8 @@ examples/anim_diff: src/demux/libwebpdemux.a examples/libexample_util.a
|
||||
examples/anim_diff: src/libwebp.a
|
||||
examples/anim_diff: EXTRA_LIBS += $(GIF_LIBS)
|
||||
examples/anim_diff: EXTRA_FLAGS += -DWEBP_HAVE_GIF
|
||||
examples/cwebp: examples/libexample_util.a src/libwebp.a
|
||||
examples/cwebp: examples/libexample_util.a examples/libexample_dec.a
|
||||
examples/cwebp: src/libwebp.a
|
||||
examples/cwebp: EXTRA_LIBS += $(CWEBP_LIBS)
|
||||
examples/dwebp: examples/libexample_util.a src/libwebpdecoder.a
|
||||
examples/dwebp: EXTRA_LIBS += $(DWEBP_LIBS)
|
||||
|
Loading…
Reference in New Issue
Block a user