mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-19 23:39:58 +02:00
Compare commits
10 Commits
v1.2.2-rc1
...
v1.2.2
Author | SHA1 | Date | |
---|---|---|---|
b0a860891d | |||
6db8248c01 | |||
827a307fec | |||
286e7fceaa | |||
9195ea0538 | |||
4acae017bd | |||
883f063397 | |||
567e1f442b | |||
f084244d9f | |||
b217b4fff7 |
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
6db8248c libwebp: Fix VP8EncTokenLoop() progress
|
||||
827a307f BMP enc: fix the transparency case
|
||||
286e7fce libwebp: do not destroy jpeg codec twice on error
|
||||
9195ea05 update ChangeLog (tag: v1.2.2-rc2)
|
||||
4acae017 update NEWS
|
||||
883f0633 man/img2webp.1: update date
|
||||
567e1f44 Reword img2webp synopsis command line
|
||||
f084244d anim_decode: fix alpha blending with big-endian
|
||||
b217b4ff webpinfo: fix fourcc comparison w/big-endian
|
||||
f035d2e4 update ChangeLog (tag: v1.2.2-rc1)
|
||||
7031946a update NEWS
|
||||
973390b6 bump version to 1.2.2
|
||||
abd6664f update AUTHORS
|
||||
|
4
NEWS
4
NEWS
@ -1,10 +1,10 @@
|
||||
- 12/15/2021: version 1.2.2
|
||||
- 1/11/2022: version 1.2.2
|
||||
This is a binary compatible release.
|
||||
* webpmux: add "-set bgcolor A,R,G,B"
|
||||
* add ARM64 NEON support for MSVC builds (#539)
|
||||
* fix duplicate include error in Xcode when using multiple XCFrameworks in a
|
||||
project (#542)
|
||||
* doc updates and bug fixes (#538, #544)
|
||||
* doc updates and bug fixes (#538, #544, #548, #550)
|
||||
|
||||
- 7/20/2021: version 1.2.1
|
||||
This is a binary compatible release.
|
||||
|
2
README
2
README
@ -456,7 +456,7 @@ modes, etc.
|
||||
|
||||
Usage:
|
||||
|
||||
img2webp [file-level options] [image files...] [per-frame options...]
|
||||
img2webp [file_options] [[frame_options] frame_file]...
|
||||
|
||||
File-level options (only used at the start of compression):
|
||||
-min_size ............ minimize size
|
||||
|
@ -35,8 +35,7 @@
|
||||
|
||||
static void Help(void) {
|
||||
printf("Usage:\n\n");
|
||||
printf(" img2webp [file-level options] [image files...] "
|
||||
"[per-frame options...]\n");
|
||||
printf(" img2webp [file_options] [[frame_options] frame_file]...\n");
|
||||
printf("\n");
|
||||
|
||||
printf("File-level options (only used at the start of compression):\n");
|
||||
|
@ -125,16 +125,16 @@ static void WebPInfoInit(WebPInfo* const webp_info) {
|
||||
memset(webp_info, 0, sizeof(*webp_info));
|
||||
}
|
||||
|
||||
static const char kWebPChunkTags[CHUNK_TYPES][4] = {
|
||||
{ 'V', 'P', '8', ' ' },
|
||||
{ 'V', 'P', '8', 'L' },
|
||||
{ 'V', 'P', '8', 'X' },
|
||||
{ 'A', 'L', 'P', 'H' },
|
||||
{ 'A', 'N', 'I', 'M' },
|
||||
{ 'A', 'N', 'M', 'F' },
|
||||
{ 'I', 'C', 'C', 'P' },
|
||||
{ 'E', 'X', 'I', 'F' },
|
||||
{ 'X', 'M', 'P', ' ' },
|
||||
static const uint32_t kWebPChunkTags[CHUNK_TYPES] = {
|
||||
MKFOURCC('V', 'P', '8', ' '),
|
||||
MKFOURCC('V', 'P', '8', 'L'),
|
||||
MKFOURCC('V', 'P', '8', 'X'),
|
||||
MKFOURCC('A', 'L', 'P', 'H'),
|
||||
MKFOURCC('A', 'N', 'I', 'M'),
|
||||
MKFOURCC('A', 'N', 'M', 'F'),
|
||||
MKFOURCC('I', 'C', 'C', 'P'),
|
||||
MKFOURCC('E', 'X', 'I', 'F'),
|
||||
MKFOURCC('X', 'M', 'P', ' '),
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -644,7 +644,7 @@ static WebPInfoStatus ParseChunk(const WebPInfo* const webp_info,
|
||||
return WEBP_INFO_TRUNCATED_DATA;
|
||||
}
|
||||
for (i = 0; i < CHUNK_TYPES; ++i) {
|
||||
if (!memcmp(kWebPChunkTags[i], &fourcc, TAG_SIZE)) break;
|
||||
if (kWebPChunkTags[i] == fourcc) break;
|
||||
}
|
||||
chunk_data->offset_ = chunk_start_offset;
|
||||
chunk_data->size_ = chunk_size;
|
||||
@ -939,7 +939,13 @@ static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data,
|
||||
LOG_WARN(error_message);
|
||||
} else {
|
||||
if (!webp_info->quiet_) {
|
||||
const char* tag = kWebPChunkTags[chunk_data->id_];
|
||||
char tag[4];
|
||||
uint32_t fourcc = kWebPChunkTags[chunk_data->id_];
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
fourcc = (fourcc >> 24) | ((fourcc >> 8) & 0xff00) |
|
||||
((fourcc << 8) & 0xff0000) | (fourcc << 24);
|
||||
#endif
|
||||
memcpy(tag, &fourcc, sizeof(tag));
|
||||
printf("Chunk %c%c%c%c at offset %6d, length %6d\n",
|
||||
tag[0], tag[1], tag[2], tag[3], (int)chunk_data->offset_,
|
||||
(int)chunk_data->size_);
|
||||
|
@ -280,7 +280,7 @@ int WebPWrite16bAsPGM(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// BMP
|
||||
// BMP (see https://en.wikipedia.org/wiki/BMP_file_format#Pixel_storage)
|
||||
|
||||
static void PutLE16(uint8_t* const dst, uint32_t value) {
|
||||
dst[0] = (value >> 0) & 0xff;
|
||||
@ -293,8 +293,11 @@ static void PutLE32(uint8_t* const dst, uint32_t value) {
|
||||
}
|
||||
|
||||
#define BMP_HEADER_SIZE 54
|
||||
#define BMP_HEADER_ALPHA_EXTRA_SIZE 16 // for alpha info
|
||||
int WebPWriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
const int header_size =
|
||||
BMP_HEADER_SIZE + (has_alpha ? BMP_HEADER_ALPHA_EXTRA_SIZE : 0);
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* rgba = buffer->u.RGBA.rgba;
|
||||
@ -303,8 +306,9 @@ int WebPWriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
uint32_t y;
|
||||
const uint32_t line_size = bytes_per_px * width;
|
||||
const uint32_t bmp_stride = (line_size + 3) & ~3; // pad to 4
|
||||
const uint32_t total_size = bmp_stride * height + BMP_HEADER_SIZE;
|
||||
uint8_t bmp_header[BMP_HEADER_SIZE] = { 0 };
|
||||
const uint32_t image_size = bmp_stride * height;
|
||||
const uint32_t total_size = image_size + header_size;
|
||||
uint8_t bmp_header[BMP_HEADER_SIZE + BMP_HEADER_ALPHA_EXTRA_SIZE] = { 0 };
|
||||
|
||||
if (fout == NULL || buffer == NULL || rgba == NULL) return 0;
|
||||
|
||||
@ -312,30 +316,37 @@ int WebPWriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
PutLE16(bmp_header + 0, 0x4d42); // signature 'BM'
|
||||
PutLE32(bmp_header + 2, total_size); // size including header
|
||||
PutLE32(bmp_header + 6, 0); // reserved
|
||||
PutLE32(bmp_header + 10, BMP_HEADER_SIZE); // offset to pixel array
|
||||
PutLE32(bmp_header + 10, header_size); // offset to pixel array
|
||||
// bitmap info header
|
||||
PutLE32(bmp_header + 14, 40); // DIB header size
|
||||
PutLE32(bmp_header + 14, header_size - 14); // DIB header size
|
||||
PutLE32(bmp_header + 18, width); // dimensions
|
||||
PutLE32(bmp_header + 22, -(int)height); // vertical flip!
|
||||
PutLE32(bmp_header + 22, height); // no vertical flip
|
||||
PutLE16(bmp_header + 26, 1); // number of planes
|
||||
PutLE16(bmp_header + 28, bytes_per_px * 8); // bits per pixel
|
||||
PutLE32(bmp_header + 30, 0); // no compression (BI_RGB)
|
||||
PutLE32(bmp_header + 34, 0); // image size (placeholder)
|
||||
PutLE32(bmp_header + 30, has_alpha ? 3 : 0); // BI_BITFIELDS or BI_RGB
|
||||
PutLE32(bmp_header + 34, image_size);
|
||||
PutLE32(bmp_header + 38, 2400); // x pixels/meter
|
||||
PutLE32(bmp_header + 42, 2400); // y pixels/meter
|
||||
PutLE32(bmp_header + 46, 0); // number of palette colors
|
||||
PutLE32(bmp_header + 50, 0); // important color count
|
||||
if (has_alpha) { // BITMAPV3INFOHEADER complement
|
||||
PutLE32(bmp_header + 54, 0x00ff0000); // red mask
|
||||
PutLE32(bmp_header + 58, 0x0000ff00); // green mask
|
||||
PutLE32(bmp_header + 62, 0x000000ff); // blue mask
|
||||
PutLE32(bmp_header + 66, 0xff000000); // alpha mask
|
||||
}
|
||||
|
||||
// TODO(skal): color profile
|
||||
|
||||
// write header
|
||||
if (fwrite(bmp_header, sizeof(bmp_header), 1, fout) != 1) {
|
||||
if (fwrite(bmp_header, header_size, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// write pixel array
|
||||
// write pixel array, bottom to top
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba, line_size, 1, fout) != 1) {
|
||||
const uint8_t* const src = &rgba[(uint64_t)(height - 1 - y) * stride];
|
||||
if (fwrite(src, line_size, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
// write padding zeroes
|
||||
@ -345,11 +356,11 @@ int WebPWriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
rgba += stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#undef BMP_HEADER_SIZE
|
||||
#undef BMP_HEADER_ALPHA_EXTRA_SIZE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// TIFF
|
||||
|
@ -336,7 +336,11 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
pic->width = width;
|
||||
pic->height = height;
|
||||
ok = WebPPictureImportRGB(pic, rgb, (int)stride);
|
||||
if (!ok) goto Error;
|
||||
if (!ok) {
|
||||
pic->width = 0; // WebPPictureImportRGB() barely touches 'pic' on failure.
|
||||
pic->height = 0; // Just reset dimensions but keep any 'custom_ptr' etc.
|
||||
MetadataFree(metadata); // In case the caller forgets to free it on error.
|
||||
}
|
||||
|
||||
End:
|
||||
free(rgb);
|
||||
|
@ -1,10 +1,10 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH IMG2WEBP 1 "November 17, 2021"
|
||||
.TH IMG2WEBP 1 "January 5, 2022"
|
||||
.SH NAME
|
||||
img2webp \- create animated WebP file from a sequence of input images.
|
||||
.SH SYNOPSIS
|
||||
.B img2webp
|
||||
[file_level_options] [files] [per_frame_options...]
|
||||
[file_options] [[frame_options] frame_file]...
|
||||
.br
|
||||
.B img2webp argument_file_name
|
||||
.br
|
||||
|
@ -23,6 +23,14 @@
|
||||
|
||||
#define NUM_CHANNELS 4
|
||||
|
||||
// Channel extraction from a uint32_t representation of a uint8_t RGBA/BGRA
|
||||
// buffer.
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define CHANNEL_SHIFT(i) (24 - (i) * 8)
|
||||
#else
|
||||
#define CHANNEL_SHIFT(i) ((i) * 8)
|
||||
#endif
|
||||
|
||||
typedef void (*BlendRowFunc)(uint32_t* const, const uint32_t* const, int);
|
||||
static void BlendPixelRowNonPremult(uint32_t* const src,
|
||||
const uint32_t* const dst, int num_pixels);
|
||||
@ -209,35 +217,35 @@ static uint8_t BlendChannelNonPremult(uint32_t src, uint8_t src_a,
|
||||
const uint8_t dst_channel = (dst >> shift) & 0xff;
|
||||
const uint32_t blend_unscaled = src_channel * src_a + dst_channel * dst_a;
|
||||
assert(blend_unscaled < (1ULL << 32) / scale);
|
||||
return (blend_unscaled * scale) >> 24;
|
||||
return (blend_unscaled * scale) >> CHANNEL_SHIFT(3);
|
||||
}
|
||||
|
||||
// Blend 'src' over 'dst' assuming they are NOT pre-multiplied by alpha.
|
||||
static uint32_t BlendPixelNonPremult(uint32_t src, uint32_t dst) {
|
||||
const uint8_t src_a = (src >> 24) & 0xff;
|
||||
const uint8_t src_a = (src >> CHANNEL_SHIFT(3)) & 0xff;
|
||||
|
||||
if (src_a == 0) {
|
||||
return dst;
|
||||
} else {
|
||||
const uint8_t dst_a = (dst >> 24) & 0xff;
|
||||
const uint8_t dst_a = (dst >> CHANNEL_SHIFT(3)) & 0xff;
|
||||
// This is the approximate integer arithmetic for the actual formula:
|
||||
// dst_factor_a = (dst_a * (255 - src_a)) / 255.
|
||||
const uint8_t dst_factor_a = (dst_a * (256 - src_a)) >> 8;
|
||||
const uint8_t blend_a = src_a + dst_factor_a;
|
||||
const uint32_t scale = (1UL << 24) / blend_a;
|
||||
|
||||
const uint8_t blend_r =
|
||||
BlendChannelNonPremult(src, src_a, dst, dst_factor_a, scale, 0);
|
||||
const uint8_t blend_g =
|
||||
BlendChannelNonPremult(src, src_a, dst, dst_factor_a, scale, 8);
|
||||
const uint8_t blend_b =
|
||||
BlendChannelNonPremult(src, src_a, dst, dst_factor_a, scale, 16);
|
||||
const uint8_t blend_r = BlendChannelNonPremult(
|
||||
src, src_a, dst, dst_factor_a, scale, CHANNEL_SHIFT(0));
|
||||
const uint8_t blend_g = BlendChannelNonPremult(
|
||||
src, src_a, dst, dst_factor_a, scale, CHANNEL_SHIFT(1));
|
||||
const uint8_t blend_b = BlendChannelNonPremult(
|
||||
src, src_a, dst, dst_factor_a, scale, CHANNEL_SHIFT(2));
|
||||
assert(src_a + dst_factor_a < 256);
|
||||
|
||||
return (blend_r << 0) |
|
||||
(blend_g << 8) |
|
||||
(blend_b << 16) |
|
||||
((uint32_t)blend_a << 24);
|
||||
return ((uint32_t)blend_r << CHANNEL_SHIFT(0)) |
|
||||
((uint32_t)blend_g << CHANNEL_SHIFT(1)) |
|
||||
((uint32_t)blend_b << CHANNEL_SHIFT(2)) |
|
||||
((uint32_t)blend_a << CHANNEL_SHIFT(3));
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,7 +255,7 @@ static void BlendPixelRowNonPremult(uint32_t* const src,
|
||||
const uint32_t* const dst, int num_pixels) {
|
||||
int i;
|
||||
for (i = 0; i < num_pixels; ++i) {
|
||||
const uint8_t src_alpha = (src[i] >> 24) & 0xff;
|
||||
const uint8_t src_alpha = (src[i] >> CHANNEL_SHIFT(3)) & 0xff;
|
||||
if (src_alpha != 0xff) {
|
||||
src[i] = BlendPixelNonPremult(src[i], dst[i]);
|
||||
}
|
||||
@ -264,7 +272,7 @@ static WEBP_INLINE uint32_t ChannelwiseMultiply(uint32_t pix, uint32_t scale) {
|
||||
|
||||
// Blend 'src' over 'dst' assuming they are pre-multiplied by alpha.
|
||||
static uint32_t BlendPixelPremult(uint32_t src, uint32_t dst) {
|
||||
const uint8_t src_a = (src >> 24) & 0xff;
|
||||
const uint8_t src_a = (src >> CHANNEL_SHIFT(3)) & 0xff;
|
||||
return src + ChannelwiseMultiply(dst, 256 - src_a);
|
||||
}
|
||||
|
||||
@ -274,7 +282,7 @@ static void BlendPixelRowPremult(uint32_t* const src, const uint32_t* const dst,
|
||||
int num_pixels) {
|
||||
int i;
|
||||
for (i = 0; i < num_pixels; ++i) {
|
||||
const uint8_t src_alpha = (src[i] >> 24) & 0xff;
|
||||
const uint8_t src_alpha = (src[i] >> CHANNEL_SHIFT(3)) & 0xff;
|
||||
if (src_alpha != 0xff) {
|
||||
src[i] = BlendPixelPremult(src[i], dst[i]);
|
||||
}
|
||||
|
@ -778,6 +778,7 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
|
||||
// Roughly refresh the proba eight times per pass
|
||||
int max_count = (enc->mb_w_ * enc->mb_h_) >> 3;
|
||||
int num_pass_left = enc->config_->pass;
|
||||
int remaining_progress = 40; // percents
|
||||
const int do_search = enc->do_search_;
|
||||
VP8EncIterator it;
|
||||
VP8EncProba* const proba = &enc->proba_;
|
||||
@ -805,6 +806,9 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
|
||||
uint64_t size_p0 = 0;
|
||||
uint64_t distortion = 0;
|
||||
int cnt = max_count;
|
||||
// The final number of passes is not trivial to know in advance.
|
||||
const int pass_progress = remaining_progress / (2 + num_pass_left);
|
||||
remaining_progress -= pass_progress;
|
||||
VP8IteratorInit(enc, &it);
|
||||
SetLoopParams(enc, stats.q);
|
||||
if (is_last_pass) {
|
||||
@ -832,7 +836,7 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
|
||||
StoreSideInfo(&it);
|
||||
VP8StoreFilterStats(&it);
|
||||
VP8IteratorExport(&it);
|
||||
ok = VP8IteratorProgress(&it, 20);
|
||||
ok = VP8IteratorProgress(&it, pass_progress);
|
||||
}
|
||||
VP8IteratorSaveBoundary(&it);
|
||||
} while (ok && VP8IteratorNext(&it));
|
||||
@ -878,7 +882,8 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
|
||||
ok = VP8EmitTokens(&enc->tokens_, enc->parts_ + 0,
|
||||
(const uint8_t*)proba->coeffs_, 1);
|
||||
}
|
||||
ok = ok && WebPReportProgress(enc->pic_, enc->percent_ + 20, &enc->percent_);
|
||||
ok = ok && WebPReportProgress(enc->pic_, enc->percent_ + remaining_progress,
|
||||
&enc->percent_);
|
||||
return PostLoopFinalize(&it, ok);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user