Mergin itseez

This commit is contained in:
Fedor Morozov 2013-09-18 18:55:12 +04:00
commit f99be6bda6
1586 changed files with 85437 additions and 29692 deletions

80
.gitattributes vendored
View File

@ -1,42 +1,58 @@
.git* export-ignore
* text=auto whitespace=trailing-space,space-before-tab,-indent-with-non-tab,tab-in-indent,tabwidth=4 * text=auto whitespace=trailing-space,space-before-tab,-indent-with-non-tab,tab-in-indent,tabwidth=4
*.py text .git* text export-ignore
*.cpp text
*.hpp text
*.cxx text
*.hxx text
*.mm text
*.c text
*.h text
*.i text
*.js text
*.java text
*.scala text
*.cu text
*.cl text
*.css_t text
*.qrc text
*.qss text
*.S text
*.rst text
*.tex text
*.sty text
*.aidl text *.aidl text
*.mk text *.appxmanifest text
*.bib text
*.c text
*.cl text
*.conf text
*.cpp text
*.css_t text
*.cu text
*.cxx text
*.def text
*.filelist text
*.h text
*.hpp text
*.htm text
*.html text
*.hxx text
*.i text
*.idl text
*.java text
*.js text
*.mk text
*.mm text
*.plist text
*.properties text
*.py text
*.qrc text
*.qss text
*.S text
*.sbt text
*.scala text
*.sty text
*.tex text
*.txt text
*.xaml text
# reST underlines/overlines can look like conflict markers
*.rst text conflict-marker-size=80
*.cmake text whitespace=tabwidth=2 *.cmake text whitespace=tabwidth=2
*.cmakein text whitespace=tabwidth=2 *.cmakein text whitespace=tabwidth=2
*.in text whitespace=tabwidth=2 *.in text whitespace=tabwidth=2
CMakeLists.txt text whitespace=tabwidth=2 CMakeLists.txt text whitespace=tabwidth=2
*.png binary *.avi binary
*.jpeg binary *.bmp binary
*.jpg binary
*.exr binary *.exr binary
*.ico binary *.ico binary
*.jpeg binary
*.jpg binary
*.png binary
*.a binary *.a binary
*.so binary *.so binary
@ -47,6 +63,7 @@ CMakeLists.txt text whitespace=tabwidth=2
*.pbxproj binary *.pbxproj binary
*.vec binary *.vec binary
*.doc binary *.doc binary
*.dia binary
*.xml -text whitespace=cr-at-eol *.xml -text whitespace=cr-at-eol
*.yml -text whitespace=cr-at-eol *.yml -text whitespace=cr-at-eol
@ -55,9 +72,12 @@ CMakeLists.txt text whitespace=tabwidth=2
.cproject -text whitespace=cr-at-eol merge=union .cproject -text whitespace=cr-at-eol merge=union
org.eclipse.jdt.core.prefs -text whitespace=cr-at-eol merge=union org.eclipse.jdt.core.prefs -text whitespace=cr-at-eol merge=union
*.vcproj text eol=crlf merge=union
*.bat text eol=crlf *.bat text eol=crlf
*.cmd text eol=crlf *.cmd text eol=crlf
*.cmd.tmpl text eol=crlf *.cmd.tmpl text eol=crlf
*.dsp text eol=crlf -whitespace
*.sln text eol=crlf -whitespace
*.vcproj text eol=crlf -whitespace merge=union
*.vcxproj text eol=crlf -whitespace merge=union
*.sh text eol=lf *.sh text eol=lf

3
.gitignore vendored
View File

@ -2,7 +2,10 @@
.DS_Store .DS_Store
refman.rst refman.rst
OpenCV4Tegra/ OpenCV4Tegra/
tegra/
*.user *.user
.sw[a-z] .sw[a-z]
.*.swp .*.swp
tags tags
Thumbs.db
*.autosave

1
3rdparty/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* -whitespace

View File

@ -1,5 +1,4 @@
set(HAVE_FFMPEG 1) set(HAVE_FFMPEG 1)
set(NEW_FFMPEG 1)
set(HAVE_FFMPEG_CODEC 1) set(HAVE_FFMPEG_CODEC 1)
set(HAVE_FFMPEG_FORMAT 1) set(HAVE_FFMPEG_FORMAT 1)
set(HAVE_FFMPEG_UTIL 1) set(HAVE_FFMPEG_UTIL 1)
@ -9,4 +8,4 @@ set(HAVE_GENTOO_FFMPEG 1)
set(ALIASOF_libavcodec_VERSION 53.61.100) set(ALIASOF_libavcodec_VERSION 53.61.100)
set(ALIASOF_libavformat_VERSION 53.32.100) set(ALIASOF_libavformat_VERSION 53.32.100)
set(ALIASOF_libavutil_VERSION 51.35.100) set(ALIASOF_libavutil_VERSION 51.35.100)
set(ALIASOF_libswscale_VERSION 2.1.100) set(ALIASOF_libswscale_VERSION 2.1.100)

View File

@ -1,2 +1,2 @@
set path=c:\dev\msys32\bin;%path% & gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lwsock32 set path=c:\dev\msys32\bin;%path% & gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lwsock32
set path=c:\dev\msys64\bin;%path% & gcc -m64 -Wall -shared -o opencv_ffmpeg_64.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat64 -lavcodec64 -lavdevice64 -lswscale64 -lavutil64 -lavcore64 -lwsock32 -lws2_32 set path=c:\dev\msys64\bin;%path% & gcc -m64 -Wall -shared -o opencv_ffmpeg_64.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat64 -lavcodec64 -lavdevice64 -lswscale64 -lavutil64 -lavcore64 -lwsock32 -lws2_32

View File

@ -40,5 +40,3 @@ How to update opencv_ffmpeg.dll and opencv_ffmpeg_64.dll when a new version of F
8. Then, go to <opencv>\3rdparty\ffmpeg, edit make.bat 8. Then, go to <opencv>\3rdparty\ffmpeg, edit make.bat
(change paths to the actual paths to your msys32 and msys64 distributions) and then run make.bat (change paths to the actual paths to your msys32 and msys64 distributions) and then run make.bat

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
3rdparty/lib/mips/libnative_camera_r4.3.0.so vendored Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
3rdparty/lib/x86/libnative_camera_r4.3.0.so vendored Executable file

Binary file not shown.

View File

@ -9,7 +9,7 @@ else()
project(${PNG_LIBRARY}) project(${PNG_LIBRARY})
endif() endif()
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" ${ZLIB_INCLUDE_DIR}) ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" ${ZLIB_INCLUDE_DIRS})
file(GLOB lib_srcs *.c) file(GLOB lib_srcs *.c)
file(GLOB lib_hdrs *.h) file(GLOB lib_hdrs *.h)
@ -29,8 +29,12 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
endif(MSVC) endif(MSVC)
if (HAVE_WINRT)
add_definitions(-DHAVE_WINRT)
endif()
add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs}) add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARY}) target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARIES})
if(UNIX) if(UNIX)
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC) if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)

22
3rdparty/libpng/opencv-libpng.patch vendored Normal file
View File

@ -0,0 +1,22 @@
diff --git a/3rdparty/libpng/pngpriv.h b/3rdparty/libpng/pngpriv.h
index 07b2b0b..e7824b8 100644
--- a/3rdparty/libpng/pngpriv.h
+++ b/3rdparty/libpng/pngpriv.h
@@ -360,7 +360,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
/* Memory model/platform independent fns */
#ifndef PNG_ABORT
-# ifdef _WINDOWS_
+# if defined(_WINDOWS_) && !defined(HAVE_WINRT)
# define PNG_ABORT() ExitProcess(0)
# else
# define PNG_ABORT() abort()
@@ -378,7 +378,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# define png_memcpy _fmemcpy
# define png_memset _fmemset
#else
-# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */
+# if defined(_WINDOWS_) && !defined(HAVE_WINRT) /* Favor Windows over C runtime fns */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strlen lstrlenA

View File

@ -360,7 +360,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
/* Memory model/platform independent fns */ /* Memory model/platform independent fns */
#ifndef PNG_ABORT #ifndef PNG_ABORT
# ifdef _WINDOWS_ # if defined(_WINDOWS_) && !defined(HAVE_WINRT)
# define PNG_ABORT() ExitProcess(0) # define PNG_ABORT() ExitProcess(0)
# else # else
# define PNG_ABORT() abort() # define PNG_ABORT() abort()
@ -378,7 +378,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# define png_memcpy _fmemcpy # define png_memcpy _fmemcpy
# define png_memset _fmemset # define png_memset _fmemset
#else #else
# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ # if defined(_WINDOWS_) && !defined(HAVE_WINRT) /* Favor Windows over C runtime fns */
# define CVT_PTR(ptr) (ptr) # define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr) # define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strlen lstrlenA # define png_strlen lstrlenA

View File

@ -17,14 +17,14 @@ check_include_file(string.h HAVE_STRING_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(unistd.h HAVE_UNISTD_H) check_include_file(unistd.h HAVE_UNISTD_H)
if(WIN32) if(WIN32 AND NOT HAVE_WINRT)
set(USE_WIN32_FILEIO 1) set(USE_WIN32_FILEIO 1)
endif() endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmakein" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmakein"
"${CMAKE_CURRENT_BINARY_DIR}/tif_config.h" @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h" @ONLY)
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ${ZLIB_INCLUDE_DIR}) ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ${ZLIB_INCLUDE_DIRS})
set(lib_srcs set(lib_srcs
tif_aux.c tif_aux.c
@ -79,14 +79,12 @@ set(lib_srcs
"${CMAKE_CURRENT_BINARY_DIR}/tif_config.h" "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
) )
if(UNIX) if(WIN32 AND NOT HAVE_WINRT)
list(APPEND lib_srcs tif_win32.c)
else()
list(APPEND lib_srcs tif_unix.c) list(APPEND lib_srcs tif_unix.c)
endif() endif()
if(WIN32)
list(APPEND lib_srcs tif_win32.c)
endif(WIN32)
ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare
-Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast) -Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast)
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang

View File

@ -168,4 +168,3 @@
/* Support Deflate compression */ /* Support Deflate compression */
#define ZIP_SUPPORT 1 #define ZIP_SUPPORT 1

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Alpha-plane decompression. // Alpha-plane decompression.
@ -20,20 +22,10 @@
extern "C" { extern "C" {
#endif #endif
// TODO(skal): move to dsp/ ?
static void CopyPlane(const uint8_t* src, int src_stride,
uint8_t* dst, int dst_stride, int width, int height) {
while (height-- > 0) {
memcpy(dst, src, width);
src += src_stride;
dst += dst_stride;
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Decodes the compressed data 'data' of size 'data_size' into the 'output'. // Decodes the compressed data 'data' of size 'data_size' into the 'output'.
// The 'output' buffer should be pre-allocated and must be of the same // The 'output' buffer should be pre-allocated and must be of the same
// dimension 'height'x'stride', as that of the image. // dimension 'height'x'width', as that of the image.
// //
// Returns 1 on successfully decoding the compressed alpha and // Returns 1 on successfully decoding the compressed alpha and
// 0 if either: // 0 if either:
@ -41,16 +33,16 @@ static void CopyPlane(const uint8_t* src, int src_stride,
// error returned by appropriate compression method. // error returned by appropriate compression method.
static int DecodeAlpha(const uint8_t* data, size_t data_size, static int DecodeAlpha(const uint8_t* data, size_t data_size,
int width, int height, int stride, uint8_t* output) { int width, int height, uint8_t* output) {
uint8_t* decoded_data = NULL;
const size_t decoded_size = height * width;
WEBP_FILTER_TYPE filter; WEBP_FILTER_TYPE filter;
int pre_processing; int pre_processing;
int rsrv; int rsrv;
int ok = 0; int ok = 0;
int method; int method;
const uint8_t* const alpha_data = data + ALPHA_HEADER_LEN;
const size_t alpha_data_size = data_size - ALPHA_HEADER_LEN;
assert(width > 0 && height > 0 && stride >= width); assert(width > 0 && height > 0);
assert(data != NULL && output != NULL); assert(data != NULL && output != NULL);
if (data_size <= ALPHA_HEADER_LEN) { if (data_size <= ALPHA_HEADER_LEN) {
@ -70,15 +62,12 @@ static int DecodeAlpha(const uint8_t* data, size_t data_size,
} }
if (method == ALPHA_NO_COMPRESSION) { if (method == ALPHA_NO_COMPRESSION) {
ok = (data_size >= decoded_size); const size_t alpha_decoded_size = height * width;
decoded_data = (uint8_t*)data + ALPHA_HEADER_LEN; ok = (alpha_data_size >= alpha_decoded_size);
if (ok) memcpy(output, alpha_data, alpha_decoded_size);
} else { } else {
decoded_data = (uint8_t*)malloc(decoded_size); ok = VP8LDecodeAlphaImageStream(width, height, alpha_data, alpha_data_size,
if (decoded_data == NULL) return 0; output);
ok = VP8LDecodeAlphaImageStream(width, height,
data + ALPHA_HEADER_LEN,
data_size - ALPHA_HEADER_LEN,
decoded_data);
} }
if (ok) { if (ok) {
@ -86,18 +75,13 @@ static int DecodeAlpha(const uint8_t* data, size_t data_size,
if (unfilter_func != NULL) { if (unfilter_func != NULL) {
// TODO(vikas): Implement on-the-fly decoding & filter mechanism to decode // TODO(vikas): Implement on-the-fly decoding & filter mechanism to decode
// and apply filter per image-row. // and apply filter per image-row.
unfilter_func(width, height, width, decoded_data); unfilter_func(width, height, width, output);
} }
// Construct raw_data (height x stride) from alpha data (height x width).
CopyPlane(decoded_data, width, output, stride, width, height);
if (pre_processing == ALPHA_PREPROCESSED_LEVELS) { if (pre_processing == ALPHA_PREPROCESSED_LEVELS) {
ok = DequantizeLevels(decoded_data, width, height); ok = DequantizeLevels(output, width, height);
} }
} }
if (method != ALPHA_NO_COMPRESSION) {
free(decoded_data);
}
return ok; return ok;
} }
@ -105,23 +89,25 @@ static int DecodeAlpha(const uint8_t* data, size_t data_size,
const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
int row, int num_rows) { int row, int num_rows) {
const int stride = dec->pic_hdr_.width_; const int width = dec->pic_hdr_.width_;
const int height = dec->pic_hdr_.height_;
if (row < 0 || num_rows < 0 || row + num_rows > dec->pic_hdr_.height_) { if (row < 0 || num_rows < 0 || row + num_rows > height) {
return NULL; // sanity check. return NULL; // sanity check.
} }
if (row == 0) { if (row == 0) {
// Decode everything during the first call. // Decode everything during the first call.
assert(!dec->is_alpha_decoded_);
if (!DecodeAlpha(dec->alpha_data_, (size_t)dec->alpha_data_size_, if (!DecodeAlpha(dec->alpha_data_, (size_t)dec->alpha_data_size_,
dec->pic_hdr_.width_, dec->pic_hdr_.height_, stride, width, height, dec->alpha_plane_)) {
dec->alpha_plane_)) {
return NULL; // Error. return NULL; // Error.
} }
dec->is_alpha_decoded_ = 1;
} }
// Return a pointer to the current decoded row. // Return a pointer to the current decoded row.
return dec->alpha_plane_ + row * stride; return dec->alpha_plane_ + row * width;
} }
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Everything about WebPDecBuffer // Everything about WebPDecBuffer

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Low-level API for VP8 decoder // Low-level API for VP8 decoder

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Frame-reconstruction function. Memory allocation. // Frame-reconstruction function. Memory allocation.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Incremental decoding // Incremental decoding
@ -97,6 +99,23 @@ static WEBP_INLINE size_t MemDataSize(const MemBuffer* mem) {
return (mem->end_ - mem->start_); return (mem->end_ - mem->start_);
} }
// Check if we need to preserve the compressed alpha data, as it may not have
// been decoded yet.
static int NeedCompressedAlpha(const WebPIDecoder* const idec) {
if (idec->state_ == STATE_PRE_VP8) {
// We haven't parsed the headers yet, so we don't know whether the image is
// lossy or lossless. This also means that we haven't parsed the ALPH chunk.
return 0;
}
if (idec->is_lossless_) {
return 0; // ALPH chunk is not present for lossless images.
} else {
const VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
assert(dec != NULL); // Must be true as idec->state_ != STATE_PRE_VP8.
return (dec->alpha_data_ != NULL) && !dec->is_alpha_decoded_;
}
}
static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) { static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
MemBuffer* const mem = &idec->mem_; MemBuffer* const mem = &idec->mem_;
const uint8_t* const new_base = mem->buf_ + mem->start_; const uint8_t* const new_base = mem->buf_ + mem->start_;
@ -122,6 +141,7 @@ static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
} }
assert(last_part >= 0); assert(last_part >= 0);
dec->parts_[last_part].buf_end_ = mem->buf_ + mem->end_; dec->parts_[last_part].buf_end_ = mem->buf_ + mem->end_;
if (NeedCompressedAlpha(idec)) dec->alpha_data_ += offset;
} else { // Resize lossless bitreader } else { // Resize lossless bitreader
VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
VP8LBitReaderSetBuffer(&dec->br_, new_base, MemDataSize(mem)); VP8LBitReaderSetBuffer(&dec->br_, new_base, MemDataSize(mem));
@ -133,8 +153,12 @@ static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
// size if required and also updates VP8BitReader's if new memory is allocated. // size if required and also updates VP8BitReader's if new memory is allocated.
static int AppendToMemBuffer(WebPIDecoder* const idec, static int AppendToMemBuffer(WebPIDecoder* const idec,
const uint8_t* const data, size_t data_size) { const uint8_t* const data, size_t data_size) {
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
MemBuffer* const mem = &idec->mem_; MemBuffer* const mem = &idec->mem_;
const uint8_t* const old_base = mem->buf_ + mem->start_; const int need_compressed_alpha = NeedCompressedAlpha(idec);
const uint8_t* const old_start = mem->buf_ + mem->start_;
const uint8_t* const old_base =
need_compressed_alpha ? dec->alpha_data_ : old_start;
assert(mem->mode_ == MEM_MODE_APPEND); assert(mem->mode_ == MEM_MODE_APPEND);
if (data_size > MAX_CHUNK_PAYLOAD) { if (data_size > MAX_CHUNK_PAYLOAD) {
// security safeguard: trying to allocate more than what the format // security safeguard: trying to allocate more than what the format
@ -143,7 +167,8 @@ static int AppendToMemBuffer(WebPIDecoder* const idec,
} }
if (mem->end_ + data_size > mem->buf_size_) { // Need some free memory if (mem->end_ + data_size > mem->buf_size_) { // Need some free memory
const size_t current_size = MemDataSize(mem); const size_t new_mem_start = old_start - old_base;
const size_t current_size = MemDataSize(mem) + new_mem_start;
const uint64_t new_size = (uint64_t)current_size + data_size; const uint64_t new_size = (uint64_t)current_size + data_size;
const uint64_t extra_size = (new_size + CHUNK_SIZE - 1) & ~(CHUNK_SIZE - 1); const uint64_t extra_size = (new_size + CHUNK_SIZE - 1) & ~(CHUNK_SIZE - 1);
uint8_t* const new_buf = uint8_t* const new_buf =
@ -153,7 +178,7 @@ static int AppendToMemBuffer(WebPIDecoder* const idec,
free(mem->buf_); free(mem->buf_);
mem->buf_ = new_buf; mem->buf_ = new_buf;
mem->buf_size_ = (size_t)extra_size; mem->buf_size_ = (size_t)extra_size;
mem->start_ = 0; mem->start_ = new_mem_start;
mem->end_ = current_size; mem->end_ = current_size;
} }
@ -161,14 +186,15 @@ static int AppendToMemBuffer(WebPIDecoder* const idec,
mem->end_ += data_size; mem->end_ += data_size;
assert(mem->end_ <= mem->buf_size_); assert(mem->end_ <= mem->buf_size_);
DoRemap(idec, mem->buf_ + mem->start_ - old_base); DoRemap(idec, mem->buf_ + mem->start_ - old_start);
return 1; return 1;
} }
static int RemapMemBuffer(WebPIDecoder* const idec, static int RemapMemBuffer(WebPIDecoder* const idec,
const uint8_t* const data, size_t data_size) { const uint8_t* const data, size_t data_size) {
MemBuffer* const mem = &idec->mem_; MemBuffer* const mem = &idec->mem_;
const uint8_t* const old_base = mem->buf_ + mem->start_; const uint8_t* const old_buf = mem->buf_;
const uint8_t* const old_start = old_buf + mem->start_;
assert(mem->mode_ == MEM_MODE_MAP); assert(mem->mode_ == MEM_MODE_MAP);
if (data_size < mem->buf_size_) return 0; // can't remap to a shorter buffer! if (data_size < mem->buf_size_) return 0; // can't remap to a shorter buffer!
@ -176,7 +202,7 @@ static int RemapMemBuffer(WebPIDecoder* const idec,
mem->buf_ = (uint8_t*)data; mem->buf_ = (uint8_t*)data;
mem->end_ = mem->buf_size_ = data_size; mem->end_ = mem->buf_size_ = data_size;
DoRemap(idec, mem->buf_ + mem->start_ - old_base); DoRemap(idec, mem->buf_ + mem->start_ - old_start);
return 1; return 1;
} }

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// functions for sample output. // functions for sample output.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Enhancement layer (for YUV444/422) // Enhancement layer (for YUV444/422)

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Quantizer initialization // Quantizer initialization

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Coding trees and probas // Coding trees and probas

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// main entry for the decoder // main entry for the decoder

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// VP8 decoder: internal header. // VP8 decoder: internal header.
@ -28,7 +30,7 @@ extern "C" {
// version numbers // version numbers
#define DEC_MAJ_VERSION 0 #define DEC_MAJ_VERSION 0
#define DEC_MIN_VERSION 3 #define DEC_MIN_VERSION 3
#define DEC_REV_VERSION 0 #define DEC_REV_VERSION 1
#define ONLY_KEYFRAME_CODE // to remove any code related to P-Frames #define ONLY_KEYFRAME_CODE // to remove any code related to P-Frames
@ -276,6 +278,7 @@ struct VP8Decoder {
// extensions // extensions
const uint8_t* alpha_data_; // compressed alpha data (if present) const uint8_t* alpha_data_; // compressed alpha data (if present)
size_t alpha_data_size_; size_t alpha_data_size_;
int is_alpha_decoded_; // true if alpha_data_ is decoded in alpha_plane_
uint8_t* alpha_plane_; // output. Persistent, contains the whole data. uint8_t* alpha_plane_; // output. Persistent, contains the whole data.
int layer_colorspace_; int layer_colorspace_;

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// main entry for the decoder // main entry for the decoder
@ -625,10 +627,24 @@ static void ApplyInverseTransforms(VP8LDecoder* const dec, int num_rows,
} }
} }
// Special method for paletted alpha data.
static void ApplyInverseTransformsAlpha(VP8LDecoder* const dec, int num_rows,
const uint8_t* const rows) {
const int start_row = dec->last_row_;
const int end_row = start_row + num_rows;
const uint8_t* rows_in = rows;
uint8_t* rows_out = (uint8_t*)dec->io_->opaque + dec->io_->width * start_row;
VP8LTransform* const transform = &dec->transforms_[0];
assert(dec->next_transform_ == 1);
assert(transform->type_ == COLOR_INDEXING_TRANSFORM);
VP8LColorIndexInverseTransformAlpha(transform, start_row, end_row, rows_in,
rows_out);
}
// Processes (transforms, scales & color-converts) the rows decoded after the // Processes (transforms, scales & color-converts) the rows decoded after the
// last call. // last call.
static void ProcessRows(VP8LDecoder* const dec, int row) { static void ProcessRows(VP8LDecoder* const dec, int row) {
const uint32_t* const rows = dec->argb_ + dec->width_ * dec->last_row_; const uint32_t* const rows = dec->pixels_ + dec->width_ * dec->last_row_;
const int num_rows = row - dec->last_row_; const int num_rows = row - dec->last_row_;
if (num_rows <= 0) return; // Nothing to be done. if (num_rows <= 0) return; // Nothing to be done.
@ -667,121 +683,135 @@ static void ProcessRows(VP8LDecoder* const dec, int row) {
assert(dec->last_row_ <= dec->height_); assert(dec->last_row_ <= dec->height_);
} }
static int DecodeImageData(VP8LDecoder* const dec, #define DECODE_DATA_FUNC(FUNC_NAME, TYPE, STORE_PIXEL) \
uint32_t* const data, int width, int height, static int FUNC_NAME(VP8LDecoder* const dec, TYPE* const data, int width, \
ProcessRowsFunc process_func) { int height, ProcessRowsFunc process_func) { \
int ok = 1; int ok = 1; \
int col = 0, row = 0; int col = 0, row = 0; \
VP8LBitReader* const br = &dec->br_; VP8LBitReader* const br = &dec->br_; \
VP8LMetadata* const hdr = &dec->hdr_; VP8LMetadata* const hdr = &dec->hdr_; \
HTreeGroup* htree_group = hdr->htree_groups_; HTreeGroup* htree_group = hdr->htree_groups_; \
uint32_t* src = data; TYPE* src = data; \
uint32_t* last_cached = data; TYPE* last_cached = data; \
uint32_t* const src_end = data + width * height; TYPE* const src_end = data + width * height; \
const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES; const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES; \
const int color_cache_limit = len_code_limit + hdr->color_cache_size_; const int color_cache_limit = len_code_limit + hdr->color_cache_size_; \
VP8LColorCache* const color_cache = VP8LColorCache* const color_cache = \
(hdr->color_cache_size_ > 0) ? &hdr->color_cache_ : NULL; (hdr->color_cache_size_ > 0) ? &hdr->color_cache_ : NULL; \
const int mask = hdr->huffman_mask_; const int mask = hdr->huffman_mask_; \
assert(htree_group != NULL); \
assert(htree_group != NULL); while (!br->eos_ && src < src_end) { \
int code; \
while (!br->eos_ && src < src_end) { /* Only update when changing tile. Note we could use this test: */ \
int code; /* if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed */ \
// Only update when changing tile. Note we could use the following test: /* but that's actually slower and needs storing the previous col/row. */ \
// if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed if ((col & mask) == 0) { \
// but that's actually slower and requires storing the previous col/row htree_group = GetHtreeGroupForPos(hdr, col, row); \
if ((col & mask) == 0) { } \
htree_group = GetHtreeGroupForPos(hdr, col, row); VP8LFillBitWindow(br); \
} code = ReadSymbol(&htree_group->htrees_[GREEN], br); \
VP8LFillBitWindow(br); if (code < NUM_LITERAL_CODES) { /* Literal*/ \
code = ReadSymbol(&htree_group->htrees_[GREEN], br); int red, green, blue, alpha; \
if (code < NUM_LITERAL_CODES) { // Literal. red = ReadSymbol(&htree_group->htrees_[RED], br); \
int red, green, blue, alpha; green = code; \
red = ReadSymbol(&htree_group->htrees_[RED], br); VP8LFillBitWindow(br); \
green = code; blue = ReadSymbol(&htree_group->htrees_[BLUE], br); \
VP8LFillBitWindow(br); alpha = ReadSymbol(&htree_group->htrees_[ALPHA], br); \
blue = ReadSymbol(&htree_group->htrees_[BLUE], br); *src = STORE_PIXEL(alpha, red, green, blue); \
alpha = ReadSymbol(&htree_group->htrees_[ALPHA], br); AdvanceByOne: \
*src = (alpha << 24) + (red << 16) + (green << 8) + blue; ++src; \
AdvanceByOne: ++col; \
++src; if (col >= width) { \
++col; col = 0; \
if (col >= width) { ++row; \
col = 0; if ((process_func != NULL) && (row % NUM_ARGB_CACHE_ROWS == 0)) { \
++row; process_func(dec, row); \
if ((process_func != NULL) && (row % NUM_ARGB_CACHE_ROWS == 0)) { } \
process_func(dec, row); if (color_cache != NULL) { \
} while (last_cached < src) { \
if (color_cache != NULL) { VP8LColorCacheInsert(color_cache, *last_cached++); \
while (last_cached < src) { } \
VP8LColorCacheInsert(color_cache, *last_cached++); } \
} } \
} } else if (code < len_code_limit) { /* Backward reference */ \
} int dist_code, dist; \
} else if (code < len_code_limit) { // Backward reference const int length_sym = code - NUM_LITERAL_CODES; \
int dist_code, dist; const int length = GetCopyLength(length_sym, br); \
const int length_sym = code - NUM_LITERAL_CODES; const int dist_symbol = ReadSymbol(&htree_group->htrees_[DIST], br); \
const int length = GetCopyLength(length_sym, br); VP8LFillBitWindow(br); \
const int dist_symbol = ReadSymbol(&htree_group->htrees_[DIST], br); dist_code = GetCopyDistance(dist_symbol, br); \
VP8LFillBitWindow(br); dist = PlaneCodeToDistance(width, dist_code); \
dist_code = GetCopyDistance(dist_symbol, br); if (src - data < dist || src_end - src < length) { \
dist = PlaneCodeToDistance(width, dist_code); ok = 0; \
if (src - data < dist || src_end - src < length) { goto End; \
ok = 0; } \
goto End; { \
} int i; \
{ for (i = 0; i < length; ++i) src[i] = src[i - dist]; \
int i; src += length; \
for (i = 0; i < length; ++i) src[i] = src[i - dist]; } \
src += length; col += length; \
} while (col >= width) { \
col += length; col -= width; \
while (col >= width) { ++row; \
col -= width; if ((process_func != NULL) && (row % NUM_ARGB_CACHE_ROWS == 0)) { \
++row; process_func(dec, row); \
if ((process_func != NULL) && (row % NUM_ARGB_CACHE_ROWS == 0)) { } \
process_func(dec, row); } \
} if (src < src_end) { \
} htree_group = GetHtreeGroupForPos(hdr, col, row); \
if (src < src_end) { if (color_cache != NULL) { \
htree_group = GetHtreeGroupForPos(hdr, col, row); while (last_cached < src) { \
if (color_cache != NULL) { VP8LColorCacheInsert(color_cache, *last_cached++); \
while (last_cached < src) { } \
VP8LColorCacheInsert(color_cache, *last_cached++); } \
} } \
} } else if (code < color_cache_limit) { /* Color cache */ \
} const int key = code - len_code_limit; \
} else if (code < color_cache_limit) { // Color cache. assert(color_cache != NULL); \
const int key = code - len_code_limit; while (last_cached < src) { \
assert(color_cache != NULL); VP8LColorCacheInsert(color_cache, *last_cached++); \
while (last_cached < src) { } \
VP8LColorCacheInsert(color_cache, *last_cached++); *src = VP8LColorCacheLookup(color_cache, key); \
} goto AdvanceByOne; \
*src = VP8LColorCacheLookup(color_cache, key); } else { /* Not reached */ \
goto AdvanceByOne; ok = 0; \
} else { // Not reached. goto End; \
ok = 0; } \
goto End; ok = !br->error_; \
} if (!ok) goto End; \
ok = !br->error_; } \
if (!ok) goto End; /* Process the remaining rows corresponding to last row-block. */ \
} if (process_func != NULL) process_func(dec, row); \
// Process the remaining rows corresponding to last row-block. End: \
if (process_func != NULL) process_func(dec, row); if (br->error_ || !ok || (br->eos_ && src < src_end)) { \
ok = 0; \
End: dec->status_ = \
if (br->error_ || !ok || (br->eos_ && src < src_end)) { (!br->eos_) ? VP8_STATUS_BITSTREAM_ERROR : VP8_STATUS_SUSPENDED; \
ok = 0; } else if (src == src_end) { \
dec->status_ = (!br->eos_) ? dec->state_ = READ_DATA; \
VP8_STATUS_BITSTREAM_ERROR : VP8_STATUS_SUSPENDED; } \
} else if (src == src_end) { return ok; \
dec->state_ = READ_DATA;
}
return ok;
} }
static WEBP_INLINE uint32_t GetARGBPixel(int alpha, int red, int green,
int blue) {
return (alpha << 24) | (red << 16) | (green << 8) | blue;
}
static WEBP_INLINE uint8_t GetAlphaPixel(int alpha, int red, int green,
int blue) {
(void)alpha;
(void)red;
(void)blue;
return green; // Alpha value is stored in green channel.
}
DECODE_DATA_FUNC(DecodeImageData, uint32_t, GetARGBPixel)
DECODE_DATA_FUNC(DecodeAlphaData, uint8_t, GetAlphaPixel)
#undef DECODE_DATA_FUNC
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// VP8LTransform // VP8LTransform
@ -903,8 +933,8 @@ void VP8LClear(VP8LDecoder* const dec) {
if (dec == NULL) return; if (dec == NULL) return;
ClearMetadata(&dec->hdr_); ClearMetadata(&dec->hdr_);
free(dec->argb_); free(dec->pixels_);
dec->argb_ = NULL; dec->pixels_ = NULL;
for (i = 0; i < dec->next_transform_; ++i) { for (i = 0; i < dec->next_transform_; ++i) {
ClearTransform(&dec->transforms_[i]); ClearTransform(&dec->transforms_[i]);
} }
@ -1028,35 +1058,39 @@ static int DecodeImageStream(int xsize, int ysize,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Allocate dec->argb_ and dec->argb_cache_ using dec->width_ and dec->height_ // Allocate internal buffers dec->pixels_ and dec->argb_cache_.
static int AllocateInternalBuffers(VP8LDecoder* const dec, int final_width,
static int AllocateARGBBuffers(VP8LDecoder* const dec, int final_width) { size_t bytes_per_pixel) {
const int argb_cache_needed = (bytes_per_pixel == sizeof(uint32_t));
const uint64_t num_pixels = (uint64_t)dec->width_ * dec->height_; const uint64_t num_pixels = (uint64_t)dec->width_ * dec->height_;
// Scratch buffer corresponding to top-prediction row for transforming the // Scratch buffer corresponding to top-prediction row for transforming the
// first row in the row-blocks. // first row in the row-blocks. Not needed for paletted alpha.
const uint64_t cache_top_pixels = final_width; const uint64_t cache_top_pixels =
// Scratch buffer for temporary BGRA storage. argb_cache_needed ? (uint16_t)final_width : 0ULL;
const uint64_t cache_pixels = (uint64_t)final_width * NUM_ARGB_CACHE_ROWS; // Scratch buffer for temporary BGRA storage. Not needed for paletted alpha.
const uint64_t cache_pixels =
argb_cache_needed ? (uint64_t)final_width * NUM_ARGB_CACHE_ROWS : 0ULL;
const uint64_t total_num_pixels = const uint64_t total_num_pixels =
num_pixels + cache_top_pixels + cache_pixels; num_pixels + cache_top_pixels + cache_pixels;
assert(dec->width_ <= final_width); assert(dec->width_ <= final_width);
dec->argb_ = (uint32_t*)WebPSafeMalloc(total_num_pixels, sizeof(*dec->argb_)); dec->pixels_ = (uint32_t*)WebPSafeMalloc(total_num_pixels, bytes_per_pixel);
if (dec->argb_ == NULL) { if (dec->pixels_ == NULL) {
dec->argb_cache_ = NULL; // for sanity check dec->argb_cache_ = NULL; // for sanity check
dec->status_ = VP8_STATUS_OUT_OF_MEMORY; dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
return 0; return 0;
} }
dec->argb_cache_ = dec->argb_ + num_pixels + cache_top_pixels; dec->argb_cache_ =
argb_cache_needed ? dec->pixels_ + num_pixels + cache_top_pixels : NULL;
return 1; return 1;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Special row-processing that only stores the alpha data.
// Special row-processing that only stores the alpha data.
static void ExtractAlphaRows(VP8LDecoder* const dec, int row) { static void ExtractAlphaRows(VP8LDecoder* const dec, int row) {
const int num_rows = row - dec->last_row_; const int num_rows = row - dec->last_row_;
const uint32_t* const in = dec->argb_ + dec->width_ * dec->last_row_; const uint32_t* const in = dec->pixels_ + dec->width_ * dec->last_row_;
if (num_rows <= 0) return; // Nothing to be done. if (num_rows <= 0) return; // Nothing to be done.
ApplyInverseTransforms(dec, num_rows, in); ApplyInverseTransforms(dec, num_rows, in);
@ -1070,7 +1104,17 @@ static void ExtractAlphaRows(VP8LDecoder* const dec, int row) {
int i; int i;
for (i = 0; i < cache_pixs; ++i) dst[i] = (src[i] >> 8) & 0xff; for (i = 0; i < cache_pixs; ++i) dst[i] = (src[i] >> 8) & 0xff;
} }
dec->last_row_ = dec->last_out_row_ = row;
}
// Row-processing for the special case when alpha data contains only one
// transform: color indexing.
static void ExtractPalettedAlphaRows(VP8LDecoder* const dec, int row) {
const int num_rows = row - dec->last_row_;
const uint8_t* const in =
(uint8_t*)dec->pixels_ + dec->width_ * dec->last_row_;
if (num_rows <= 0) return; // Nothing to be done.
ApplyInverseTransformsAlpha(dec, num_rows, in);
dec->last_row_ = dec->last_out_row_ = row; dec->last_row_ = dec->last_out_row_ = row;
} }
@ -1079,6 +1123,7 @@ int VP8LDecodeAlphaImageStream(int width, int height, const uint8_t* const data,
VP8Io io; VP8Io io;
int ok = 0; int ok = 0;
VP8LDecoder* const dec = VP8LNew(); VP8LDecoder* const dec = VP8LNew();
size_t bytes_per_pixel = sizeof(uint32_t); // Default: BGRA mode.
if (dec == NULL) return 0; if (dec == NULL) return 0;
dec->width_ = width; dec->width_ = width;
@ -1097,13 +1142,25 @@ int VP8LDecodeAlphaImageStream(int width, int height, const uint8_t* const data,
dec->action_ = READ_HDR; dec->action_ = READ_HDR;
if (!DecodeImageStream(width, height, 1, dec, NULL)) goto Err; if (!DecodeImageStream(width, height, 1, dec, NULL)) goto Err;
// Allocate output (note that dec->width_ may have changed here). // Special case: if alpha data uses only the color indexing transform and
if (!AllocateARGBBuffers(dec, width)) goto Err; // doesn't use color cache (a frequent case), we will use DecodeAlphaData()
// method that only needs allocation of 1 byte per pixel (alpha channel).
if (dec->next_transform_ == 1 &&
dec->transforms_[0].type_ == COLOR_INDEXING_TRANSFORM &&
dec->hdr_.color_cache_size_ == 0) {
bytes_per_pixel = sizeof(uint8_t);
}
// Allocate internal buffers (note that dec->width_ may have changed here).
if (!AllocateInternalBuffers(dec, width, bytes_per_pixel)) goto Err;
// Decode (with special row processing). // Decode (with special row processing).
dec->action_ = READ_DATA; dec->action_ = READ_DATA;
ok = DecodeImageData(dec, dec->argb_, dec->width_, dec->height_, ok = (bytes_per_pixel == sizeof(uint8_t)) ?
ExtractAlphaRows); DecodeAlphaData(dec, (uint8_t*)dec->pixels_, dec->width_, dec->height_,
ExtractPalettedAlphaRows) :
DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_,
ExtractAlphaRows);
Err: Err:
VP8LDelete(dec); VP8LDelete(dec);
@ -1143,6 +1200,7 @@ int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io) {
} }
int VP8LDecodeImage(VP8LDecoder* const dec) { int VP8LDecodeImage(VP8LDecoder* const dec) {
const size_t bytes_per_pixel = sizeof(uint32_t);
VP8Io* io = NULL; VP8Io* io = NULL;
WebPDecParams* params = NULL; WebPDecParams* params = NULL;
@ -1162,13 +1220,13 @@ int VP8LDecodeImage(VP8LDecoder* const dec) {
goto Err; goto Err;
} }
if (!AllocateARGBBuffers(dec, io->width)) goto Err; if (!AllocateInternalBuffers(dec, io->width, bytes_per_pixel)) goto Err;
if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err; if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err;
// Decode. // Decode.
dec->action_ = READ_DATA; dec->action_ = READ_DATA;
if (!DecodeImageData(dec, dec->argb_, dec->width_, dec->height_, if (!DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_,
ProcessRows)) { ProcessRows)) {
goto Err; goto Err;
} }

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Lossless decoder: internal header. // Lossless decoder: internal header.
@ -63,7 +65,8 @@ typedef struct {
const WebPDecBuffer *output_; // shortcut to io->opaque->output const WebPDecBuffer *output_; // shortcut to io->opaque->output
uint32_t *argb_; // Internal data: always in BGRA color mode. uint32_t *pixels_; // Internal data: either uint8_t* for alpha
// or uint32_t* for BGRA.
uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage. uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage.
VP8LBitReader br_; VP8LBitReader br_;

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Main decoding functions for WEBP images. // Main decoding functions for WEBP images.
@ -192,6 +194,15 @@ static VP8StatusCode ParseOptionalChunks(const uint8_t** const data,
return VP8_STATUS_BITSTREAM_ERROR; // Not a valid chunk size. return VP8_STATUS_BITSTREAM_ERROR; // Not a valid chunk size.
} }
// Start of a (possibly incomplete) VP8/VP8L chunk implies that we have
// parsed all the optional chunks.
// Note: This check must occur before the check 'buf_size < disk_chunk_size'
// below to allow incomplete VP8/VP8L chunks.
if (!memcmp(buf, "VP8 ", TAG_SIZE) ||
!memcmp(buf, "VP8L", TAG_SIZE)) {
return VP8_STATUS_OK;
}
if (buf_size < disk_chunk_size) { // Insufficient data. if (buf_size < disk_chunk_size) { // Insufficient data.
return VP8_STATUS_NOT_ENOUGH_DATA; return VP8_STATUS_NOT_ENOUGH_DATA;
} }
@ -199,9 +210,6 @@ static VP8StatusCode ParseOptionalChunks(const uint8_t** const data,
if (!memcmp(buf, "ALPH", TAG_SIZE)) { // A valid ALPH header. if (!memcmp(buf, "ALPH", TAG_SIZE)) { // A valid ALPH header.
*alpha_data = buf + CHUNK_HEADER_SIZE; *alpha_data = buf + CHUNK_HEADER_SIZE;
*alpha_size = chunk_size; *alpha_size = chunk_size;
} else if (!memcmp(buf, "VP8 ", TAG_SIZE) ||
!memcmp(buf, "VP8L", TAG_SIZE)) { // A valid VP8/VP8L header.
return VP8_STATUS_OK; // Found.
} }
// We have a full and valid chunk; skip it. // We have a full and valid chunk; skip it.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Internal header: WebP decoding parameters and custom IO on buffer // Internal header: WebP decoding parameters and custom IO on buffer

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// WebP container demux. // WebP container demux.
@ -27,7 +29,7 @@ extern "C" {
#define DMUX_MAJ_VERSION 0 #define DMUX_MAJ_VERSION 0
#define DMUX_MIN_VERSION 1 #define DMUX_MIN_VERSION 1
#define DMUX_REV_VERSION 0 #define DMUX_REV_VERSION 1
typedef struct { typedef struct {
size_t start_; // start location of the data size_t start_; // start location of the data
@ -317,6 +319,7 @@ static ParseStatus ParseAnimationFrame(
frame->duration_ = ReadLE24s(mem); frame->duration_ = ReadLE24s(mem);
frame->dispose_method_ = (WebPMuxAnimDispose)(ReadByte(mem) & 1); frame->dispose_method_ = (WebPMuxAnimDispose)(ReadByte(mem) & 1);
if (frame->width_ * (uint64_t)frame->height_ >= MAX_IMAGE_AREA) { if (frame->width_ * (uint64_t)frame->height_ >= MAX_IMAGE_AREA) {
free(frame);
return PARSE_ERROR; return PARSE_ERROR;
} }

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// CPU detection // CPU detection

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Speed-critical decoding functions. // Speed-critical decoding functions.

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// ARM NEON version of dsp functions and loop filtering. // ARM NEON version of dsp functions and loop filtering.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// SSE2 version of some decoding functions (idct, loop filtering). // SSE2 version of some decoding functions (idct, loop filtering).

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Speed-critical functions. // Speed-critical functions.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Speed-critical encoding functions. // Speed-critical encoding functions.
@ -142,9 +144,9 @@ static void FTransform(const uint8_t* src, const uint8_t* ref, int16_t* out) {
const int a1 = (d1 + d2); const int a1 = (d1 + d2);
const int a2 = (d1 - d2); const int a2 = (d1 - d2);
const int a3 = (d0 - d3); const int a3 = (d0 - d3);
tmp[0 + i * 4] = (a0 + a1) << 3; // 14b [-8160,8160] tmp[0 + i * 4] = (a0 + a1) * 8; // 14b [-8160,8160]
tmp[1 + i * 4] = (a2 * 2217 + a3 * 5352 + 1812) >> 9; // [-7536,7542] tmp[1 + i * 4] = (a2 * 2217 + a3 * 5352 + 1812) >> 9; // [-7536,7542]
tmp[2 + i * 4] = (a0 - a1) << 3; tmp[2 + i * 4] = (a0 - a1) * 8;
tmp[3 + i * 4] = (a3 * 2217 - a2 * 5352 + 937) >> 9; tmp[3 + i * 4] = (a3 * 2217 - a2 * 5352 + 937) >> 9;
} }
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
@ -187,31 +189,32 @@ static void ITransformWHT(const int16_t* in, int16_t* out) {
} }
static void FTransformWHT(const int16_t* in, int16_t* out) { static void FTransformWHT(const int16_t* in, int16_t* out) {
int tmp[16]; // input is 12b signed
int16_t tmp[16];
int i; int i;
for (i = 0; i < 4; ++i, in += 64) { for (i = 0; i < 4; ++i, in += 64) {
const int a0 = (in[0 * 16] + in[2 * 16]) << 2; const int a0 = (in[0 * 16] + in[2 * 16]); // 13b
const int a1 = (in[1 * 16] + in[3 * 16]) << 2; const int a1 = (in[1 * 16] + in[3 * 16]);
const int a2 = (in[1 * 16] - in[3 * 16]) << 2; const int a2 = (in[1 * 16] - in[3 * 16]);
const int a3 = (in[0 * 16] - in[2 * 16]) << 2; const int a3 = (in[0 * 16] - in[2 * 16]);
tmp[0 + i * 4] = (a0 + a1) + (a0 != 0); tmp[0 + i * 4] = a0 + a1; // 14b
tmp[1 + i * 4] = a3 + a2; tmp[1 + i * 4] = a3 + a2;
tmp[2 + i * 4] = a3 - a2; tmp[2 + i * 4] = a3 - a2;
tmp[3 + i * 4] = a0 - a1; tmp[3 + i * 4] = a0 - a1;
} }
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
const int a0 = (tmp[0 + i] + tmp[8 + i]); const int a0 = (tmp[0 + i] + tmp[8 + i]); // 15b
const int a1 = (tmp[4 + i] + tmp[12+ i]); const int a1 = (tmp[4 + i] + tmp[12+ i]);
const int a2 = (tmp[4 + i] - tmp[12+ i]); const int a2 = (tmp[4 + i] - tmp[12+ i]);
const int a3 = (tmp[0 + i] - tmp[8 + i]); const int a3 = (tmp[0 + i] - tmp[8 + i]);
const int b0 = a0 + a1; const int b0 = a0 + a1; // 16b
const int b1 = a3 + a2; const int b1 = a3 + a2;
const int b2 = a3 - a2; const int b2 = a3 - a2;
const int b3 = a0 - a1; const int b3 = a0 - a1;
out[ 0 + i] = (b0 + (b0 > 0) + 3) >> 3; out[ 0 + i] = b0 >> 1; // 15b
out[ 4 + i] = (b1 + (b1 > 0) + 3) >> 3; out[ 4 + i] = b1 >> 1;
out[ 8 + i] = (b2 + (b2 > 0) + 3) >> 3; out[ 8 + i] = b2 >> 1;
out[12 + i] = (b3 + (b3 > 0) + 3) >> 3; out[12 + i] = b3 >> 1;
} }
} }

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// ARM NEON version of speed-critical encoding functions. // ARM NEON version of speed-critical encoding functions.
@ -322,7 +324,7 @@ static void FTransform(const uint8_t* src, const uint8_t* ref,
"vmlal.s16 q11, d6, d17 \n" // c1*2217 + d1*5352 + 12000 "vmlal.s16 q11, d6, d17 \n" // c1*2217 + d1*5352 + 12000
"vmlsl.s16 q12, d6, d16 \n" // d1*2217 - c1*5352 + 51000 "vmlsl.s16 q12, d6, d16 \n" // d1*2217 - c1*5352 + 51000
"vmvn.s16 d4, d4 \n" "vmvn d4, d4 \n" // !(d1 == 0)
// op[4] = (c1*2217 + d1*5352 + 12000)>>16 // op[4] = (c1*2217 + d1*5352 + 12000)>>16
"vshrn.s32 d1, q11, #16 \n" "vshrn.s32 d1, q11, #16 \n"
// op[4] += (d1!=0) // op[4] += (d1!=0)
@ -363,19 +365,12 @@ static void FTransformWHT(const int16_t* in, int16_t* out) {
"vld1.16 d2[3], [%[in]], %[kStep] \n" "vld1.16 d2[3], [%[in]], %[kStep] \n"
"vld1.16 d3[3], [%[in]], %[kStep] \n" "vld1.16 d3[3], [%[in]], %[kStep] \n"
"vaddl.s16 q2, d0, d2 \n" "vaddl.s16 q2, d0, d2 \n" // a0=(in[0*16]+in[2*16])
"vshl.s32 q2, q2, #2 \n" // a0=(in[0*16]+in[2*16])<<2 "vaddl.s16 q3, d1, d3 \n" // a1=(in[1*16]+in[3*16])
"vaddl.s16 q3, d1, d3 \n" "vsubl.s16 q4, d1, d3 \n" // a2=(in[1*16]-in[3*16])
"vshl.s32 q3, q3, #2 \n" // a1=(in[1*16]+in[3*16])<<2 "vsubl.s16 q5, d0, d2 \n" // a3=(in[0*16]-in[2*16])
"vsubl.s16 q4, d1, d3 \n"
"vshl.s32 q4, q4, #2 \n" // a2=(in[1*16]-in[3*16])<<2
"vsubl.s16 q5, d0, d2 \n"
"vshl.s32 q5, q5, #2 \n" // a3=(in[0*16]-in[2*16])<<2
"vceq.s32 q10, q2, #0 \n" "vqadd.s32 q6, q2, q3 \n" // a0 + a1
"vmvn.s32 q10, q10 \n" // (a0 != 0)
"vqadd.s32 q6, q2, q3 \n" // (a0 + a1)
"vqsub.s32 q6, q6, q10 \n" // (a0 + a1) + (a0 != 0)
"vqadd.s32 q7, q5, q4 \n" // a3 + a2 "vqadd.s32 q7, q5, q4 \n" // a3 + a2
"vqsub.s32 q8, q5, q4 \n" // a3 - a2 "vqsub.s32 q8, q5, q4 \n" // a3 - a2
"vqsub.s32 q9, q2, q3 \n" // a0 - a1 "vqsub.s32 q9, q2, q3 \n" // a0 - a1
@ -398,27 +393,10 @@ static void FTransformWHT(const int16_t* in, int16_t* out) {
"vqsub.s32 q6, q3, q2 \n" // b2 = a3 - a2 "vqsub.s32 q6, q3, q2 \n" // b2 = a3 - a2
"vqsub.s32 q7, q0, q1 \n" // b3 = a0 - a1 "vqsub.s32 q7, q0, q1 \n" // b3 = a0 - a1
"vmov.s32 q0, #3 \n" // q0 = 3 "vshrn.s32 d18, q4, #1 \n" // b0 >> 1
"vshrn.s32 d19, q5, #1 \n" // b1 >> 1
"vcgt.s32 q1, q4, #0 \n" // (b0>0) "vshrn.s32 d20, q6, #1 \n" // b2 >> 1
"vqsub.s32 q2, q4, q1 \n" // (b0+(b0>0)) "vshrn.s32 d21, q7, #1 \n" // b3 >> 1
"vqadd.s32 q3, q2, q0 \n" // (b0+(b0>0)+3)
"vshrn.s32 d18, q3, #3 \n" // (b0+(b0>0)+3) >> 3
"vcgt.s32 q1, q5, #0 \n" // (b1>0)
"vqsub.s32 q2, q5, q1 \n" // (b1+(b1>0))
"vqadd.s32 q3, q2, q0 \n" // (b1+(b1>0)+3)
"vshrn.s32 d19, q3, #3 \n" // (b1+(b1>0)+3) >> 3
"vcgt.s32 q1, q6, #0 \n" // (b2>0)
"vqsub.s32 q2, q6, q1 \n" // (b2+(b2>0))
"vqadd.s32 q3, q2, q0 \n" // (b2+(b2>0)+3)
"vshrn.s32 d20, q3, #3 \n" // (b2+(b2>0)+3) >> 3
"vcgt.s32 q1, q7, #0 \n" // (b3>0)
"vqsub.s32 q2, q7, q1 \n" // (b3+(b3>0))
"vqadd.s32 q3, q2, q0 \n" // (b3+(b3>0)+3)
"vshrn.s32 d21, q3, #3 \n" // (b3+(b3>0)+3) >> 3
"vst1.16 {q9, q10}, [%[out]] \n" "vst1.16 {q9, q10}, [%[out]] \n"

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// SSE2 version of speed-critical encoding functions. // SSE2 version of speed-critical encoding functions.
@ -453,6 +455,39 @@ static void FTransformSSE2(const uint8_t* src, const uint8_t* ref,
} }
} }
static void FTransformWHTSSE2(const int16_t* in, int16_t* out) {
int16_t tmp[16];
int i;
for (i = 0; i < 4; ++i, in += 64) {
const int a0 = (in[0 * 16] + in[2 * 16]);
const int a1 = (in[1 * 16] + in[3 * 16]);
const int a2 = (in[1 * 16] - in[3 * 16]);
const int a3 = (in[0 * 16] - in[2 * 16]);
tmp[0 + i * 4] = a0 + a1;
tmp[1 + i * 4] = a3 + a2;
tmp[2 + i * 4] = a3 - a2;
tmp[3 + i * 4] = a0 - a1;
}
{
const __m128i src0 = _mm_loadl_epi64((__m128i*)&tmp[0]);
const __m128i src1 = _mm_loadl_epi64((__m128i*)&tmp[4]);
const __m128i src2 = _mm_loadl_epi64((__m128i*)&tmp[8]);
const __m128i src3 = _mm_loadl_epi64((__m128i*)&tmp[12]);
const __m128i a0 = _mm_add_epi16(src0, src2);
const __m128i a1 = _mm_add_epi16(src1, src3);
const __m128i a2 = _mm_sub_epi16(src1, src3);
const __m128i a3 = _mm_sub_epi16(src0, src2);
const __m128i b0 = _mm_srai_epi16(_mm_adds_epi16(a0, a1), 1);
const __m128i b1 = _mm_srai_epi16(_mm_adds_epi16(a3, a2), 1);
const __m128i b2 = _mm_srai_epi16(_mm_subs_epi16(a3, a2), 1);
const __m128i b3 = _mm_srai_epi16(_mm_subs_epi16(a0, a1), 1);
_mm_storel_epi64((__m128i*)&out[ 0], b0);
_mm_storel_epi64((__m128i*)&out[ 4], b1);
_mm_storel_epi64((__m128i*)&out[ 8], b2);
_mm_storel_epi64((__m128i*)&out[12], b3);
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Metric // Metric
@ -919,6 +954,7 @@ void VP8EncDspInitSSE2(void) {
VP8EncQuantizeBlock = QuantizeBlockSSE2; VP8EncQuantizeBlock = QuantizeBlockSSE2;
VP8ITransform = ITransformSSE2; VP8ITransform = ITransformSSE2;
VP8FTransform = FTransformSSE2; VP8FTransform = FTransformSSE2;
VP8FTransformWHT = FTransformWHTSSE2;
VP8SSE16x16 = SSE16x16SSE2; VP8SSE16x16 = SSE16x16SSE2;
VP8SSE16x8 = SSE16x8SSE2; VP8SSE16x8 = SSE16x8SSE2;
VP8SSE8x8 = SSE8x8SSE2; VP8SSE8x8 = SSE8x8SSE2;

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Image transforms and color space conversion methods for lossless decoder. // Image transforms and color space conversion methods for lossless decoder.
@ -1093,39 +1095,64 @@ static void ColorSpaceInverseTransform(const VP8LTransform* const transform,
} }
// Separate out pixels packed together using pixel-bundling. // Separate out pixels packed together using pixel-bundling.
static void ColorIndexInverseTransform( // We define two methods for ARGB data (uint32_t) and alpha-only data (uint8_t).
const VP8LTransform* const transform, #define COLOR_INDEX_INVERSE(FUNC_NAME, TYPE, GET_INDEX, GET_VALUE) \
int y_start, int y_end, const uint32_t* src, uint32_t* dst) { void FUNC_NAME(const VP8LTransform* const transform, \
int y; int y_start, int y_end, const TYPE* src, TYPE* dst) { \
const int bits_per_pixel = 8 >> transform->bits_; int y; \
const int width = transform->xsize_; const int bits_per_pixel = 8 >> transform->bits_; \
const uint32_t* const color_map = transform->data_; const int width = transform->xsize_; \
if (bits_per_pixel < 8) { const uint32_t* const color_map = transform->data_; \
const int pixels_per_byte = 1 << transform->bits_; if (bits_per_pixel < 8) { \
const int count_mask = pixels_per_byte - 1; const int pixels_per_byte = 1 << transform->bits_; \
const uint32_t bit_mask = (1 << bits_per_pixel) - 1; const int count_mask = pixels_per_byte - 1; \
for (y = y_start; y < y_end; ++y) { const uint32_t bit_mask = (1 << bits_per_pixel) - 1; \
uint32_t packed_pixels = 0; for (y = y_start; y < y_end; ++y) { \
int x; uint32_t packed_pixels = 0; \
for (x = 0; x < width; ++x) { int x; \
// We need to load fresh 'packed_pixels' once every 'pixels_per_byte' for (x = 0; x < width; ++x) { \
// increments of x. Fortunately, pixels_per_byte is a power of 2, so /* We need to load fresh 'packed_pixels' once every */ \
// can just use a mask for that, instead of decrementing a counter. /* 'pixels_per_byte' increments of x. Fortunately, pixels_per_byte */ \
if ((x & count_mask) == 0) packed_pixels = ((*src++) >> 8) & 0xff; /* is a power of 2, so can just use a mask for that, instead of */ \
*dst++ = color_map[packed_pixels & bit_mask]; /* decrementing a counter. */ \
packed_pixels >>= bits_per_pixel; if ((x & count_mask) == 0) packed_pixels = GET_INDEX(*src++); \
} *dst++ = GET_VALUE(color_map[packed_pixels & bit_mask]); \
} packed_pixels >>= bits_per_pixel; \
} else { } \
for (y = y_start; y < y_end; ++y) { } \
int x; } else { \
for (x = 0; x < width; ++x) { for (y = y_start; y < y_end; ++y) { \
*dst++ = color_map[((*src++) >> 8) & 0xff]; int x; \
} for (x = 0; x < width; ++x) { \
} *dst++ = GET_VALUE(color_map[GET_INDEX(*src++)]); \
} } \
} \
} \
} }
static WEBP_INLINE uint32_t GetARGBIndex(uint32_t idx) {
return (idx >> 8) & 0xff;
}
static WEBP_INLINE uint8_t GetAlphaIndex(uint8_t idx) {
return idx;
}
static WEBP_INLINE uint32_t GetARGBValue(uint32_t val) {
return val;
}
static WEBP_INLINE uint8_t GetAlphaValue(uint32_t val) {
return (val >> 8) & 0xff;
}
static COLOR_INDEX_INVERSE(ColorIndexInverseTransform, uint32_t, GetARGBIndex,
GetARGBValue)
COLOR_INDEX_INVERSE(VP8LColorIndexInverseTransformAlpha, uint8_t, GetAlphaIndex,
GetAlphaValue)
#undef COLOR_INDEX_INVERSE
void VP8LInverseTransform(const VP8LTransform* const transform, void VP8LInverseTransform(const VP8LTransform* const transform,
int row_start, int row_end, int row_start, int row_end,
const uint32_t* const in, uint32_t* const out) { const uint32_t* const in, uint32_t* const out) {
@ -1254,11 +1281,12 @@ static void CopyOrSwap(const uint32_t* src, int num_pixels, uint8_t* dst,
while (src < src_end) { while (src < src_end) {
uint32_t argb = *src++; uint32_t argb = *src++;
#if !defined(__BIG_ENDIAN__)
#if !defined(WEBP_REFERENCE_IMPLEMENTATION) #if !defined(WEBP_REFERENCE_IMPLEMENTATION)
#if !defined(__BIG_ENDIAN__) && (defined(__i386__) || defined(__x86_64__)) #if defined(__i386__) || defined(__x86_64__)
__asm__ volatile("bswap %0" : "=r"(argb) : "0"(argb)); __asm__ volatile("bswap %0" : "=r"(argb) : "0"(argb));
*(uint32_t*)dst = argb; *(uint32_t*)dst = argb;
#elif !defined(__BIG_ENDIAN__) && defined(_MSC_VER) #elif defined(_MSC_VER)
argb = _byteswap_ulong(argb); argb = _byteswap_ulong(argb);
*(uint32_t*)dst = argb; *(uint32_t*)dst = argb;
#else #else
@ -1267,11 +1295,17 @@ static void CopyOrSwap(const uint32_t* src, int num_pixels, uint8_t* dst,
dst[2] = (argb >> 8) & 0xff; dst[2] = (argb >> 8) & 0xff;
dst[3] = (argb >> 0) & 0xff; dst[3] = (argb >> 0) & 0xff;
#endif #endif
#else // WEBP_REFERENCE_IMPLEMENTATION #else // WEBP_REFERENCE_IMPLEMENTATION
dst[0] = (argb >> 24) & 0xff; dst[0] = (argb >> 24) & 0xff;
dst[1] = (argb >> 16) & 0xff; dst[1] = (argb >> 16) & 0xff;
dst[2] = (argb >> 8) & 0xff; dst[2] = (argb >> 8) & 0xff;
dst[3] = (argb >> 0) & 0xff; dst[3] = (argb >> 0) & 0xff;
#endif
#else // __BIG_ENDIAN__
dst[0] = (argb >> 0) & 0xff;
dst[1] = (argb >> 8) & 0xff;
dst[2] = (argb >> 16) & 0xff;
dst[3] = (argb >> 24) & 0xff;
#endif #endif
dst += sizeof(argb); dst += sizeof(argb);
} }
@ -1325,6 +1359,27 @@ void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
} }
} }
// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
void VP8LBundleColorMap(const uint8_t* const row, int width,
int xbits, uint32_t* const dst) {
int x;
if (xbits > 0) {
const int bit_depth = 1 << (3 - xbits);
const int mask = (1 << xbits) - 1;
uint32_t code = 0xff000000;
for (x = 0; x < width; ++x) {
const int xsub = x & mask;
if (xsub == 0) {
code = 0xff000000;
}
code |= row[x] << (8 + bit_depth * xsub);
dst[x >> xbits] = code;
}
} else {
for (x = 0; x < width; ++x) dst[x] = 0xff000000 | (row[x] << 8);
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Image transforms and color space conversion methods for lossless decoder. // Image transforms and color space conversion methods for lossless decoder.
@ -33,6 +35,13 @@ void VP8LInverseTransform(const struct VP8LTransform* const transform,
int row_start, int row_end, int row_start, int row_end,
const uint32_t* const in, uint32_t* const out); const uint32_t* const in, uint32_t* const out);
// Similar to the static method ColorIndexInverseTransform() that is part of
// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than
// uint32_t) arguments for 'src' and 'dst'.
void VP8LColorIndexInverseTransformAlpha(
const struct VP8LTransform* const transform, int y_start, int y_end,
const uint8_t* src, uint8_t* dst);
// Subtracts green from blue and red channels. // Subtracts green from blue and red channels.
void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs); void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs);
@ -83,6 +92,9 @@ static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
} }
void VP8LBundleColorMap(const uint8_t* const row, int width,
int xbits, uint32_t* const dst);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// YUV to RGB upsampling functions. // YUV to RGB upsampling functions.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// NEON version of YUV to RGB upsampling functions. // NEON version of YUV to RGB upsampling functions.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// SSE2 version of YUV to RGB upsampling functions. // SSE2 version of YUV to RGB upsampling functions.

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// YUV->RGB conversion function // YUV->RGB conversion function

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// inline YUV<->RGB conversion function // inline YUV<->RGB conversion function

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Alpha-plane compression. // Alpha-plane compression.
@ -80,7 +82,7 @@ static int EncodeLossless(const uint8_t* const data, int width, int height,
config.lossless = 1; config.lossless = 1;
config.method = effort_level; // impact is very small config.method = effort_level; // impact is very small
// Set a moderate default quality setting for alpha. // Set a moderate default quality setting for alpha.
config.quality = 5.f * effort_level; config.quality = 10.f * effort_level;
assert(config.quality >= 0 && config.quality <= 100.f); assert(config.quality >= 0 && config.quality <= 100.f);
ok = VP8LBitWriterInit(&tmp_bw, (width * height) >> 3); ok = VP8LBitWriterInit(&tmp_bw, (width * height) >> 3);
@ -156,6 +158,25 @@ static void CopyPlane(const uint8_t* src, int src_stride,
} }
} }
static int GetNumColors(const uint8_t* data, int width, int height,
int stride) {
int j;
int colors = 0;
uint8_t color[256] = { 0 };
for (j = 0; j < height; ++j) {
int i;
const uint8_t* const p = data + j * stride;
for (i = 0; i < width; ++i) {
color[p[i]] = 1;
}
}
for (j = 0; j < 256; ++j) {
if (color[j] > 0) ++colors;
}
return colors;
}
static int EncodeAlpha(VP8Encoder* const enc, static int EncodeAlpha(VP8Encoder* const enc,
int quality, int method, int filter, int quality, int method, int filter,
int effort_level, int effort_level,
@ -207,18 +228,32 @@ static int EncodeAlpha(VP8Encoder* const enc,
VP8BitWriter bw; VP8BitWriter bw;
int test_filter; int test_filter;
uint8_t* filtered_alpha = NULL; uint8_t* filtered_alpha = NULL;
int try_filter_none = (effort_level > 3);
// We always test WEBP_FILTER_NONE first. if (filter == WEBP_FILTER_FAST) { // Quick estimate of the best candidate.
ok = EncodeAlphaInternal(quant_alpha, width, height, const int kMinColorsForFilterNone = 16;
method, WEBP_FILTER_NONE, reduce_levels, const int kMaxColorsForFilterNone = 192;
effort_level, NULL, &bw, pic->stats); const int num_colors = GetNumColors(quant_alpha, width, height, width);
if (!ok) { // For low number of colors, NONE yeilds better compression.
VP8BitWriterWipeOut(&bw); filter = (num_colors <= kMinColorsForFilterNone) ? WEBP_FILTER_NONE :
goto End; EstimateBestFilter(quant_alpha, width, height, width);
// For large number of colors, try FILTER_NONE in addition to the best
// filter as well.
if (num_colors > kMaxColorsForFilterNone) {
try_filter_none = 1;
}
} }
if (filter == WEBP_FILTER_FAST) { // Quick estimate of a second candidate? // Test for WEBP_FILTER_NONE for higher effort levels.
filter = EstimateBestFilter(quant_alpha, width, height, width); if (try_filter_none || filter == WEBP_FILTER_NONE) {
ok = EncodeAlphaInternal(quant_alpha, width, height,
method, WEBP_FILTER_NONE, reduce_levels,
effort_level, NULL, &bw, pic->stats);
if (!ok) {
VP8BitWriterWipeOut(&bw);
goto End;
}
} }
// Stop? // Stop?
if (filter == WEBP_FILTER_NONE) { if (filter == WEBP_FILTER_NONE) {
@ -234,11 +269,14 @@ static int EncodeAlpha(VP8Encoder* const enc,
// Try the other mode(s). // Try the other mode(s).
{ {
WebPAuxStats best_stats; WebPAuxStats best_stats;
size_t best_score = VP8BitWriterSize(&bw); size_t best_score = try_filter_none ?
VP8BitWriterSize(&bw) : (size_t)~0U;
int wipe_tmp_bw = try_filter_none;
memset(&best_stats, 0, sizeof(best_stats)); // prevent spurious warning memset(&best_stats, 0, sizeof(best_stats)); // prevent spurious warning
if (pic->stats != NULL) best_stats = *pic->stats; if (pic->stats != NULL) best_stats = *pic->stats;
for (test_filter = WEBP_FILTER_HORIZONTAL; for (test_filter =
try_filter_none ? WEBP_FILTER_HORIZONTAL : WEBP_FILTER_NONE;
ok && (test_filter <= WEBP_FILTER_GRADIENT); ok && (test_filter <= WEBP_FILTER_GRADIENT);
++test_filter) { ++test_filter) {
VP8BitWriter tmp_bw; VP8BitWriter tmp_bw;
@ -262,7 +300,10 @@ static int EncodeAlpha(VP8Encoder* const enc,
} else { } else {
VP8BitWriterWipeOut(&bw); VP8BitWriterWipeOut(&bw);
} }
VP8BitWriterWipeOut(&tmp_bw); if (wipe_tmp_bw) {
VP8BitWriterWipeOut(&tmp_bw);
}
wipe_tmp_bw = 1; // For next filter trial for WEBP_FILTER_BEST.
} }
if (pic->stats != NULL) *pic->stats = best_stats; if (pic->stats != NULL) *pic->stats = best_stats;
} }

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Macroblock analysis // Macroblock analysis

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Author: Jyrki Alakuijala (jyrki@google.com) // Author: Jyrki Alakuijala (jyrki@google.com)
@ -142,9 +144,10 @@ static void HashChainInsert(HashChain* const p,
} }
static void GetParamsForHashChainFindCopy(int quality, int xsize, static void GetParamsForHashChainFindCopy(int quality, int xsize,
int* window_size, int* iter_pos, int cache_bits, int* window_size,
int* iter_limit) { int* iter_pos, int* iter_limit) {
const int iter_mult = (quality < 27) ? 1 : 1 + ((quality - 27) >> 4); const int iter_mult = (quality < 27) ? 1 : 1 + ((quality - 27) >> 4);
const int iter_neg = -iter_mult * (quality >> 1);
// Limit the backward-ref window size for lower qualities. // Limit the backward-ref window size for lower qualities.
const int max_window_size = (quality > 50) ? WINDOW_SIZE const int max_window_size = (quality > 50) ? WINDOW_SIZE
: (quality > 25) ? (xsize << 8) : (quality > 25) ? (xsize << 8)
@ -152,77 +155,74 @@ static void GetParamsForHashChainFindCopy(int quality, int xsize,
assert(xsize > 0); assert(xsize > 0);
*window_size = (max_window_size > WINDOW_SIZE) ? WINDOW_SIZE *window_size = (max_window_size > WINDOW_SIZE) ? WINDOW_SIZE
: max_window_size; : max_window_size;
*iter_pos = 5 + (quality >> 3); *iter_pos = 8 + (quality >> 3);
*iter_limit = -quality * iter_mult; // For lower entropy images, the rigourous search loop in HashChainFindCopy
// can be relaxed.
*iter_limit = (cache_bits > 0) ? iter_neg : iter_neg / 2;
} }
static int HashChainFindCopy(const HashChain* const p, static int HashChainFindCopy(const HashChain* const p,
int base_position, int xsize, int base_position, int xsize_signed,
const uint32_t* const argb, int maxlen, const uint32_t* const argb, int maxlen,
int window_size, int iter_pos, int iter_limit, int window_size, int iter_pos, int iter_limit,
int* const distance_ptr, int* const distance_ptr,
int* const length_ptr) { int* const length_ptr) {
const uint64_t hash_code = GetPixPairHash64(&argb[base_position]);
int prev_length = 0;
int64_t best_val = 0;
int best_length = 0;
int best_distance = 0;
const uint32_t* const argb_start = argb + base_position; const uint32_t* const argb_start = argb + base_position;
uint64_t best_val = 0;
uint32_t best_length = 1;
uint32_t best_distance = 0;
const uint32_t xsize = (uint32_t)xsize_signed;
const int min_pos = const int min_pos =
(base_position > window_size) ? base_position - window_size : 0; (base_position > window_size) ? base_position - window_size : 0;
int pos; int pos;
assert(xsize > 0); assert(xsize > 0);
for (pos = p->hash_to_first_index_[hash_code]; for (pos = p->hash_to_first_index_[GetPixPairHash64(argb_start)];
pos >= min_pos; pos >= min_pos;
pos = p->chain_[pos]) { pos = p->chain_[pos]) {
int64_t val; uint64_t val;
int curr_length; uint32_t curr_length;
uint32_t distance;
if (iter_pos < 0) { if (iter_pos < 0) {
if (iter_pos < iter_limit || best_val >= 0xff0000) { if (iter_pos < iter_limit || best_val >= 0xff0000) {
break; break;
} }
} }
--iter_pos; --iter_pos;
if (best_length != 0 && if (argb[pos + best_length - 1] != argb_start[best_length - 1]) {
argb[pos + best_length - 1] != argb_start[best_length - 1]) {
continue; continue;
} }
curr_length = FindMatchLength(argb + pos, argb_start, maxlen); curr_length = FindMatchLength(argb + pos, argb_start, maxlen);
if (curr_length < prev_length) { if (curr_length < best_length) {
continue; continue;
} }
val = 65536 * curr_length; distance = (uint32_t)(base_position - pos);
val = curr_length << 16;
// Favoring 2d locality here gives savings for certain images. // Favoring 2d locality here gives savings for certain images.
if (base_position - pos < 9 * xsize) { if (distance < 9 * xsize) {
const int y = (base_position - pos) / xsize; const uint32_t y = distance / xsize;
int x = (base_position - pos) % xsize; uint32_t x = distance % xsize;
if (x > xsize / 2) { if (x > (xsize >> 1)) {
x = xsize - x; x = xsize - x;
} }
if (x <= 7 && x >= -8) { if (x <= 7) {
val += 9 * 9 + 9 * 9;
val -= y * y + x * x; val -= y * y + x * x;
} else {
val -= 9 * 9 + 9 * 9;
} }
} else {
val -= 9 * 9 + 9 * 9;
} }
if (best_val < val) { if (best_val < val) {
prev_length = curr_length;
best_val = val; best_val = val;
best_length = curr_length; best_length = curr_length;
best_distance = base_position - pos; best_distance = distance;
if (curr_length >= MAX_LENGTH) { if (curr_length >= MAX_LENGTH) {
break; break;
} }
if ((best_distance == 1 || best_distance == xsize) && if ((best_distance == 1 || distance == xsize) &&
best_length >= 128) { best_length >= 128) {
break; break;
} }
} }
} }
*distance_ptr = best_distance; *distance_ptr = (int)best_distance;
*length_ptr = best_length; *length_ptr = best_length;
return (best_length >= MIN_LENGTH); return (best_length >= MIN_LENGTH);
} }
@ -284,8 +284,8 @@ static int BackwardReferencesHashChain(int xsize, int ysize,
if (!HashChainInit(hash_chain, pix_count)) goto Error; if (!HashChainInit(hash_chain, pix_count)) goto Error;
refs->size = 0; refs->size = 0;
GetParamsForHashChainFindCopy(quality, xsize, &window_size, &iter_pos, GetParamsForHashChainFindCopy(quality, xsize, cache_bits,
&iter_limit); &window_size, &iter_pos, &iter_limit);
for (i = 0; i < pix_count; ) { for (i = 0; i < pix_count; ) {
// Alternative#1: Code the pixels starting at 'i' using backward reference. // Alternative#1: Code the pixels starting at 'i' using backward reference.
int offset = 0; int offset = 0;
@ -510,8 +510,8 @@ static int BackwardReferencesHashChainDistanceOnly(
// We loop one pixel at a time, but store all currently best points to // We loop one pixel at a time, but store all currently best points to
// non-processed locations from this point. // non-processed locations from this point.
dist_array[0] = 0; dist_array[0] = 0;
GetParamsForHashChainFindCopy(quality, xsize, &window_size, &iter_pos, GetParamsForHashChainFindCopy(quality, xsize, cache_bits,
&iter_limit); &window_size, &iter_pos, &iter_limit);
for (i = 0; i < pix_count; ++i) { for (i = 0; i < pix_count; ++i) {
double prev_cost = 0.0; double prev_cost = 0.0;
int shortmax; int shortmax;
@ -645,8 +645,8 @@ static int BackwardReferencesHashChainFollowChosenPath(
} }
refs->size = 0; refs->size = 0;
GetParamsForHashChainFindCopy(quality, xsize, &window_size, &iter_pos, GetParamsForHashChainFindCopy(quality, xsize, cache_bits,
&iter_limit); &window_size, &iter_pos, &iter_limit);
for (ix = 0; ix < chosen_path_size; ++ix, ++size) { for (ix = 0; ix < chosen_path_size; ++ix, ++size) {
int offset = 0; int offset = 0;
int len = 0; int len = 0;
@ -785,7 +785,9 @@ int VP8LGetBackwardReferences(int width, int height,
*best = refs_lz77; // default guess: lz77 is better *best = refs_lz77; // default guess: lz77 is better
VP8LClearBackwardRefs(&refs_rle); VP8LClearBackwardRefs(&refs_rle);
if (try_lz77_trace_backwards) { if (try_lz77_trace_backwards) {
const int recursion_level = (num_pix < 320 * 200) ? 1 : 0; // Set recursion level for large images using a color cache.
const int recursion_level =
(num_pix < 320 * 200) && (cache_bits > 0) ? 1 : 0;
VP8LBackwardRefs refs_trace; VP8LBackwardRefs refs_trace;
if (!VP8LBackwardRefsAlloc(&refs_trace, num_pix)) { if (!VP8LBackwardRefsAlloc(&refs_trace, num_pix)) {
goto End; goto End;

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Author: Jyrki Alakuijala (jyrki@google.com) // Author: Jyrki Alakuijala (jyrki@google.com)

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Coding tools configuration // Coding tools configuration

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Cost tables for level and modes // Cost tables for level and modes

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Cost tables for level and modes. // Cost tables for level and modes.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Selecting filter level // Selecting filter level

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// frame coding and analysis // frame coding and analysis

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Author: Jyrki Alakuijala (jyrki@google.com) // Author: Jyrki Alakuijala (jyrki@google.com)

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Author: Jyrki Alakuijala (jyrki@google.com) // Author: Jyrki Alakuijala (jyrki@google.com)

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// VP8Iterator: block iterator // VP8Iterator: block iterator

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Enhancement layer (for YUV444/422) // Enhancement layer (for YUV444/422)

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// WebPPicture utils: colorspace conversion, crop, ... // WebPPicture utils: colorspace conversion, crop, ...
@ -709,7 +711,7 @@ static int Import(WebPPicture* const picture,
for (y = 0; y < height; ++y) { for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) { for (x = 0; x < width; ++x) {
const int offset = step * x + y * rgb_stride; const int offset = step * x + y * rgb_stride;
const uint32_t argb = (a_ptr[offset] << 24) | const uint32_t argb = ((uint32_t)a_ptr[offset] << 24) |
(r_ptr[offset] << 16) | (r_ptr[offset] << 16) |
(g_ptr[offset] << 8) | (g_ptr[offset] << 8) |
(b_ptr[offset]); (b_ptr[offset]);
@ -809,7 +811,7 @@ int WebPPictureYUVAToARGB(WebPPicture* picture) {
const uint8_t* const src = picture->a + y * picture->a_stride; const uint8_t* const src = picture->a + y * picture->a_stride;
int x; int x;
for (x = 0; x < width; ++x) { for (x = 0; x < width; ++x) {
argb_dst[x] = (argb_dst[x] & 0x00ffffffu) | (src[x] << 24); argb_dst[x] = (argb_dst[x] & 0x00ffffffu) | ((uint32_t)src[x] << 24);
} }
} }
} }

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Quantization // Quantization

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Header syntax writing // Header syntax writing

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Paginated token buffer // Paginated token buffer

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Token probabilities // Token probabilities

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// WebP encoder: internal header. // WebP encoder: internal header.
@ -28,7 +30,7 @@ extern "C" {
// version numbers // version numbers
#define ENC_MAJ_VERSION 0 #define ENC_MAJ_VERSION 0
#define ENC_MIN_VERSION 3 #define ENC_MIN_VERSION 3
#define ENC_REV_VERSION 0 #define ENC_REV_VERSION 1
// intra prediction modes // intra prediction modes
enum { B_DC_PRED = 0, // 4x4 modes enum { B_DC_PRED = 0, // 4x4 modes

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// main entry for the lossless encoder. // main entry for the lossless encoder.
@ -86,7 +88,7 @@ static int AnalyzeAndCreatePalette(const WebPPicture* const pic,
argb += pic->argb_stride; argb += pic->argb_stride;
} }
// TODO(skal): could we reuse in_use[] to speed up ApplyPalette()? // TODO(skal): could we reuse in_use[] to speed up EncodePalette()?
num_colors = 0; num_colors = 0;
for (i = 0; i < (int)(sizeof(in_use) / sizeof(in_use[0])); ++i) { for (i = 0; i < (int)(sizeof(in_use) / sizeof(in_use[0])); ++i) {
if (in_use[i]) { if (in_use[i]) {
@ -811,34 +813,66 @@ static WebPEncodingError AllocateTransformBuffer(VP8LEncoder* const enc,
return err; return err;
} }
// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel. static void ApplyPalette(uint32_t* src, uint32_t* dst,
static void BundleColorMap(const uint8_t* const row, int width, uint32_t src_stride, uint32_t dst_stride,
int xbits, uint32_t* const dst) { const uint32_t* palette, int palette_size,
int x; int width, int height, int xbits, uint8_t* row) {
if (xbits > 0) { int i, x, y;
const int bit_depth = 1 << (3 - xbits); int use_LUT = 1;
const int mask = (1 << xbits) - 1; for (i = 0; i < palette_size; ++i) {
uint32_t code = 0xff000000; if ((palette[i] & 0xffff00ffu) != 0) {
for (x = 0; x < width; ++x) { use_LUT = 0;
const int xsub = x & mask; break;
if (xsub == 0) { }
code = 0xff000000; }
if (use_LUT) {
int inv_palette[MAX_PALETTE_SIZE] = { 0 };
for (i = 0; i < palette_size; ++i) {
const int color = (palette[i] >> 8) & 0xff;
inv_palette[color] = i;
}
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
const int color = (src[x] >> 8) & 0xff;
row[x] = inv_palette[color];
} }
code |= row[x] << (8 + bit_depth * xsub); VP8LBundleColorMap(row, width, xbits, dst);
dst[x >> xbits] = code; src += src_stride;
dst += dst_stride;
} }
} else { } else {
for (x = 0; x < width; ++x) dst[x] = 0xff000000 | (row[x] << 8); // Use 1 pixel cache for ARGB pixels.
uint32_t last_pix = palette[0];
int last_idx = 0;
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
const uint32_t pix = src[x];
if (pix != last_pix) {
for (i = 0; i < palette_size; ++i) {
if (pix == palette[i]) {
last_idx = i;
last_pix = pix;
break;
}
}
}
row[x] = last_idx;
}
VP8LBundleColorMap(row, width, xbits, dst);
src += src_stride;
dst += dst_stride;
}
} }
} }
// Note: Expects "enc->palette_" to be set properly. // Note: Expects "enc->palette_" to be set properly.
// Also, "enc->palette_" will be modified after this call and should not be used // Also, "enc->palette_" will be modified after this call and should not be used
// later. // later.
static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, static WebPEncodingError EncodePalette(VP8LBitWriter* const bw,
VP8LEncoder* const enc, int quality) { VP8LEncoder* const enc, int quality) {
WebPEncodingError err = VP8_ENC_OK; WebPEncodingError err = VP8_ENC_OK;
int i, x, y; int i;
const WebPPicture* const pic = enc->pic_; const WebPPicture* const pic = enc->pic_;
uint32_t* src = pic->argb; uint32_t* src = pic->argb;
uint32_t* dst; uint32_t* dst;
@ -864,20 +898,8 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw,
row = WebPSafeMalloc((uint64_t)width, sizeof(*row)); row = WebPSafeMalloc((uint64_t)width, sizeof(*row));
if (row == NULL) return VP8_ENC_ERROR_OUT_OF_MEMORY; if (row == NULL) return VP8_ENC_ERROR_OUT_OF_MEMORY;
for (y = 0; y < height; ++y) { ApplyPalette(src, dst, pic->argb_stride, enc->current_width_,
for (x = 0; x < width; ++x) { palette, palette_size, width, height, xbits, row);
const uint32_t pix = src[x];
for (i = 0; i < palette_size; ++i) {
if (pix == palette[i]) {
row[x] = i;
break;
}
}
}
BundleColorMap(row, width, xbits, dst);
src += pic->argb_stride;
dst += enc->current_width_;
}
// Save palette to bitstream. // Save palette to bitstream.
VP8LWriteBits(bw, 1, TRANSFORM_PRESENT); VP8LWriteBits(bw, 1, TRANSFORM_PRESENT);
@ -899,13 +921,10 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw,
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static int GetHistoBits(const WebPConfig* const config, static int GetHistoBits(int method, int use_palette, int width, int height) {
const WebPPicture* const pic) {
const int width = pic->width;
const int height = pic->height;
const uint64_t hist_size = sizeof(VP8LHistogram); const uint64_t hist_size = sizeof(VP8LHistogram);
// Make tile size a function of encoding method (Range: 0 to 6). // Make tile size a function of encoding method (Range: 0 to 6).
int histo_bits = 7 - config->method; int histo_bits = (use_palette ? 9 : 7) - method;
while (1) { while (1) {
const uint64_t huff_image_size = VP8LSubSampleSize(width, histo_bits) * const uint64_t huff_image_size = VP8LSubSampleSize(width, histo_bits) *
VP8LSubSampleSize(height, histo_bits) * VP8LSubSampleSize(height, histo_bits) *
@ -917,13 +936,14 @@ static int GetHistoBits(const WebPConfig* const config,
(histo_bits > MAX_HUFFMAN_BITS) ? MAX_HUFFMAN_BITS : histo_bits; (histo_bits > MAX_HUFFMAN_BITS) ? MAX_HUFFMAN_BITS : histo_bits;
} }
static void InitEncParams(VP8LEncoder* const enc) { static void FinishEncParams(VP8LEncoder* const enc) {
const WebPConfig* const config = enc->config_; const WebPConfig* const config = enc->config_;
const WebPPicture* const picture = enc->pic_; const WebPPicture* const pic = enc->pic_;
const int method = config->method; const int method = config->method;
const float quality = config->quality; const float quality = config->quality;
const int use_palette = enc->use_palette_;
enc->transform_bits_ = (method < 4) ? 5 : (method > 4) ? 3 : 4; enc->transform_bits_ = (method < 4) ? 5 : (method > 4) ? 3 : 4;
enc->histo_bits_ = GetHistoBits(config, picture); enc->histo_bits_ = GetHistoBits(method, use_palette, pic->width, pic->height);
enc->cache_bits_ = (quality <= 25.f) ? 0 : 7; enc->cache_bits_ = (quality <= 25.f) ? 0 : 7;
} }
@ -965,8 +985,6 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
goto Error; goto Error;
} }
InitEncParams(enc);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Analyze image (entropy, num_palettes etc) // Analyze image (entropy, num_palettes etc)
@ -975,8 +993,10 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
goto Error; goto Error;
} }
FinishEncParams(enc);
if (enc->use_palette_) { if (enc->use_palette_) {
err = ApplyPalette(bw, enc, quality); err = EncodePalette(bw, enc, quality);
if (err != VP8_ENC_OK) goto Error; if (err != VP8_ENC_OK) goto Error;
// Color cache is disabled for palette. // Color cache is disabled for palette.
enc->cache_bits_ = 0; enc->cache_bits_ = 0;

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Lossless encoder: internal header. // Lossless encoder: internal header.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// WebP encoder: main entry point // WebP encoder: main entry point
@ -386,9 +388,9 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) {
// Analysis is done, proceed to actual coding. // Analysis is done, proceed to actual coding.
ok = ok && VP8EncStartAlpha(enc); // possibly done in parallel ok = ok && VP8EncStartAlpha(enc); // possibly done in parallel
if (!enc->use_tokens_) { if (!enc->use_tokens_) {
ok = VP8EncLoop(enc); ok = ok && VP8EncLoop(enc);
} else { } else {
ok = VP8EncTokenLoop(enc); ok = ok && VP8EncTokenLoop(enc);
} }
ok = ok && VP8EncFinishAlpha(enc); ok = ok && VP8EncFinishAlpha(enc);
#ifdef WEBP_EXPERIMENTAL_FEATURES #ifdef WEBP_EXPERIMENTAL_FEATURES

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Set and delete APIs for mux. // Set and delete APIs for mux.
@ -475,7 +477,7 @@ static WebPMuxError GetImageCanvasWidthHeight(
int64_t image_area = 0; int64_t image_area = 0;
// Aggregate the bounding box for animation frames & fragmented images. // Aggregate the bounding box for animation frames & fragmented images.
for (; wpi != NULL; wpi = wpi->next_) { for (; wpi != NULL; wpi = wpi->next_) {
int x_offset, y_offset, duration, w, h; int x_offset = 0, y_offset = 0, duration = 0, w = 0, h = 0;
const WebPMuxError err = GetImageInfo(wpi, &x_offset, &y_offset, const WebPMuxError err = GetImageInfo(wpi, &x_offset, &y_offset,
&duration, &w, &h); &duration, &w, &h);
const int max_x_pos = x_offset + w; const int max_x_pos = x_offset + w;

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Internal header for mux library. // Internal header for mux library.
@ -26,7 +28,7 @@ extern "C" {
#define MUX_MAJ_VERSION 0 #define MUX_MAJ_VERSION 0
#define MUX_MIN_VERSION 1 #define MUX_MIN_VERSION 1
#define MUX_REV_VERSION 0 #define MUX_REV_VERSION 1
// Chunk object. // Chunk object.
typedef struct WebPChunk WebPChunk; typedef struct WebPChunk WebPChunk;

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Internal objects and utils for mux. // Internal objects and utils for mux.

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Read APIs for mux. // Read APIs for mux.

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Boolean decoder // Boolean decoder

View File

@ -1,8 +1,10 @@
// Copyright 2010 Google Inc. All Rights Reserved. // Copyright 2010 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Boolean decoder // Boolean decoder
@ -194,6 +196,7 @@ static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) {
#endif #endif
#else // BIG_ENDIAN #else // BIG_ENDIAN
bits = (bit_t)in_bits; bits = (bit_t)in_bits;
if (BITS != 8 * sizeof(bit_t)) bits >>= (8 * sizeof(bit_t) - BITS);
#endif #endif
#ifndef USE_RIGHT_JUSTIFY #ifndef USE_RIGHT_JUSTIFY
br->value_ |= bits << (-br->bits_); br->value_ |= bits << (-br->bits_);

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Bit writing and boolean coder // Bit writing and boolean coder

View File

@ -1,8 +1,10 @@
// Copyright 2011 Google Inc. All Rights Reserved. // Copyright 2011 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Bit writing and boolean coder // Bit writing and boolean coder

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Color Cache for WebP Lossless // Color Cache for WebP Lossless

View File

@ -1,8 +1,10 @@
// Copyright 2012 Google Inc. All Rights Reserved. // Copyright 2012 Google Inc. All Rights Reserved.
// //
// This code is licensed under the same terms as WebM: // Use of this source code is governed by a BSD-style license
// Software License Agreement: http://www.webmproject.org/license/software/ // that can be found in the COPYING file in the root of the source
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ // 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.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// Color Cache for WebP Lossless // Color Cache for WebP Lossless

Some files were not shown because too many files have changed in this diff Show More