mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-28 23:03:20 +02:00
apply clang-format
(Debian clang-format version 19.1.7 (3+build4)) with `--style=Google`. Manual changes: * clang-format disabled around macros with stringification (mostly assembly) * some inline assembly strings were adjusted to avoid awkward line breaks * trailing commas, `//` or suffixes (`ull`) added to help array formatting * thread_utils.c: parameter comments were changed to the more common /*...=*/ style to improve formatting The automatically generated code under swig/ was skipped. Bug: 433996651 Change-Id: Iea3f24160d78d2a2653971cdf13fa932e47ff1b3
This commit is contained in:
@@ -45,7 +45,7 @@ int WebPImportGray(const uint8_t* gray_data, WebPPicture* pic) {
|
||||
uv_width = (width + 1) >> 1;
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
memcpy(pic->y + y * pic->y_stride, gray_data, width);
|
||||
gray_data += width; // <- we could use some 'data_stride' here if needed
|
||||
gray_data += width; // <- we could use some 'data_stride' here if needed
|
||||
if ((y & 1) == 0) {
|
||||
memset(pic->u + (y >> 1) * pic->uv_stride, 128, uv_width);
|
||||
memset(pic->v + (y >> 1) * pic->uv_stride, 128, uv_width);
|
||||
|
@@ -22,7 +22,7 @@ extern "C" {
|
||||
#include "sharpyuv/sharpyuv.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#define WEBP_EXTRAS_ABI_VERSION 0x0003 // MAJOR(8b) + MINOR(8b)
|
||||
#define WEBP_EXTRAS_ABI_VERSION 0x0003 // MAJOR(8b) + MINOR(8b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -49,10 +49,10 @@ WEBP_EXTERN int WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic);
|
||||
// MAX_PALETTE_SIZE. 'pic' must have been initialized. Its content, if any,
|
||||
// will be discarded. Returns 'false' in case of error, or if indexed[] contains
|
||||
// invalid indices.
|
||||
WEBP_EXTERN int
|
||||
WebPImportColorMappedARGB(const uint8_t* indexed, int indexed_stride,
|
||||
const uint32_t palette[], int palette_size,
|
||||
WebPPicture* pic);
|
||||
WEBP_EXTERN int WebPImportColorMappedARGB(const uint8_t* indexed,
|
||||
int indexed_stride,
|
||||
const uint32_t palette[],
|
||||
int palette_size, WebPPicture* pic);
|
||||
|
||||
// Convert the ARGB content of 'pic' from associated to unassociated.
|
||||
// 'pic' can be for instance the result of calling of some WebPPictureImportXXX
|
||||
@@ -98,15 +98,17 @@ WEBP_EXTERN int VP8EstimateQuality(const uint8_t* const data, size_t size);
|
||||
// currently supported.
|
||||
// width, height: width and height of the image in pixels
|
||||
// Returns 0 on failure.
|
||||
WEBP_EXTERN int SharpYuvEstimate420Risk(
|
||||
const void* r_ptr, const void* g_ptr, const void* b_ptr, int rgb_step,
|
||||
int rgb_stride, int rgb_bit_depth, int width, int height,
|
||||
const SharpYuvOptions* options, float* score);
|
||||
WEBP_EXTERN int SharpYuvEstimate420Risk(const void* r_ptr, const void* g_ptr,
|
||||
const void* b_ptr, int rgb_step,
|
||||
int rgb_stride, int rgb_bit_depth,
|
||||
int width, int height,
|
||||
const SharpYuvOptions* options,
|
||||
float* score);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXTRAS_EXTRAS_H_
|
||||
|
@@ -48,7 +48,7 @@ static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
reader = WebPGuessImageReader(data, data_size);
|
||||
ok = reader(data, data_size, pic, keep_alpha, NULL);
|
||||
|
||||
End:
|
||||
End:
|
||||
if (!ok) {
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
@@ -57,8 +57,8 @@ static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
return ok ? data_size : 0;
|
||||
}
|
||||
|
||||
static void RescalePlane(uint8_t* plane, int width, int height,
|
||||
int x_stride, int y_stride, int max) {
|
||||
static void RescalePlane(uint8_t* plane, int width, int height, int x_stride,
|
||||
int y_stride, int max) {
|
||||
const uint32_t factor = (max > 0) ? (255u << 16) / max : 0;
|
||||
int x, y;
|
||||
for (y = 0; y < height; ++y) {
|
||||
@@ -71,9 +71,9 @@ static void RescalePlane(uint8_t* plane, int width, int height,
|
||||
}
|
||||
|
||||
// Return the max absolute difference.
|
||||
static int DiffScaleChannel(uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int x_stride, int w, int h, int do_scaling) {
|
||||
static int DiffScaleChannel(uint8_t* src1, int stride1, const uint8_t* src2,
|
||||
int stride2, int x_stride, int w, int h,
|
||||
int do_scaling) {
|
||||
int x, y;
|
||||
int max = 0;
|
||||
for (y = 0; y < h; ++y) {
|
||||
@@ -95,7 +95,7 @@ static int DiffScaleChannel(uint8_t* src1, int stride1,
|
||||
// breaking the library's hidden visibility. This code duplication avoids the
|
||||
// bigger annoyance of having to open up internal details of libdsp...
|
||||
|
||||
#define SSIM_KERNEL 3 // total size of the kernel: 2 * SSIM_KERNEL + 1
|
||||
#define SSIM_KERNEL 3 // total size of the kernel: 2 * SSIM_KERNEL + 1
|
||||
|
||||
// struct for accumulating statistical moments
|
||||
typedef struct {
|
||||
@@ -105,19 +105,19 @@ typedef struct {
|
||||
} DistoStats;
|
||||
|
||||
// hat-shaped filter. Sum of coefficients is equal to 16.
|
||||
static const uint32_t kWeight[2 * SSIM_KERNEL + 1] = { 1, 2, 3, 4, 3, 2, 1 };
|
||||
static const uint32_t kWeight[2 * SSIM_KERNEL + 1] = {1, 2, 3, 4, 3, 2, 1};
|
||||
|
||||
static WEBP_INLINE double SSIMCalculation(const DistoStats* const stats) {
|
||||
const uint32_t N = stats->w;
|
||||
const uint32_t w2 = N * N;
|
||||
const uint32_t w2 = N * N;
|
||||
const uint32_t C1 = 20 * w2;
|
||||
const uint32_t C2 = 60 * w2;
|
||||
const uint32_t C3 = 8 * 8 * w2; // 'dark' limit ~= 6
|
||||
const uint32_t C3 = 8 * 8 * w2; // 'dark' limit ~= 6
|
||||
const uint64_t xmxm = (uint64_t)stats->xm * stats->xm;
|
||||
const uint64_t ymym = (uint64_t)stats->ym * stats->ym;
|
||||
if (xmxm + ymym >= C3) {
|
||||
const int64_t xmym = (int64_t)stats->xm * stats->ym;
|
||||
const int64_t sxy = (int64_t)stats->xym * N - xmym; // can be negative
|
||||
const int64_t sxy = (int64_t)stats->xym * N - xmym; // can be negative
|
||||
const uint64_t sxx = (uint64_t)stats->xxm * N - xmxm;
|
||||
const uint64_t syy = (uint64_t)stats->yym * N - ymym;
|
||||
// we descale by 8 to prevent overflow during the fnum/fden multiply.
|
||||
@@ -129,13 +129,13 @@ static WEBP_INLINE double SSIMCalculation(const DistoStats* const stats) {
|
||||
assert(r >= 0. && r <= 1.0);
|
||||
return r;
|
||||
}
|
||||
return 1.; // area is too dark to contribute meaningfully
|
||||
return 1.; // area is too dark to contribute meaningfully
|
||||
}
|
||||
|
||||
static double SSIMGetClipped(const uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int xo, int yo, int W, int H) {
|
||||
DistoStats stats = { 0, 0, 0, 0, 0, 0 };
|
||||
const uint8_t* src2, int stride2, int xo, int yo,
|
||||
int W, int H) {
|
||||
DistoStats stats = {0, 0, 0, 0, 0, 0};
|
||||
const int ymin = (yo - SSIM_KERNEL < 0) ? 0 : yo - SSIM_KERNEL;
|
||||
const int ymax = (yo + SSIM_KERNEL > H - 1) ? H - 1 : yo + SSIM_KERNEL;
|
||||
const int xmin = (xo - SSIM_KERNEL < 0) ? 0 : xo - SSIM_KERNEL;
|
||||
@@ -145,13 +145,13 @@ static double SSIMGetClipped(const uint8_t* src1, int stride1,
|
||||
src2 += ymin * stride2;
|
||||
for (y = ymin; y <= ymax; ++y, src1 += stride1, src2 += stride2) {
|
||||
for (x = xmin; x <= xmax; ++x) {
|
||||
const uint32_t w = kWeight[SSIM_KERNEL + x - xo]
|
||||
* kWeight[SSIM_KERNEL + y - yo];
|
||||
const uint32_t w =
|
||||
kWeight[SSIM_KERNEL + x - xo] * kWeight[SSIM_KERNEL + y - yo];
|
||||
const uint32_t s1 = src1[x];
|
||||
const uint32_t s2 = src2[x];
|
||||
stats.w += w;
|
||||
stats.xm += w * s1;
|
||||
stats.ym += w * s2;
|
||||
stats.w += w;
|
||||
stats.xm += w * s1;
|
||||
stats.ym += w * s2;
|
||||
stats.xxm += w * s1 * s1;
|
||||
stats.xym += w * s1 * s2;
|
||||
stats.yym += w * s2 * s2;
|
||||
@@ -161,9 +161,9 @@ static double SSIMGetClipped(const uint8_t* src1, int stride1,
|
||||
}
|
||||
|
||||
// Compute SSIM-score map. Return -1 in case of error, max diff otherwise.
|
||||
static int SSIMScaleChannel(uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int x_stride, int w, int h, int do_scaling) {
|
||||
static int SSIMScaleChannel(uint8_t* src1, int stride1, const uint8_t* src2,
|
||||
int stride2, int x_stride, int w, int h,
|
||||
int do_scaling) {
|
||||
int x, y;
|
||||
int max = 0;
|
||||
uint8_t* const plane1 = (uint8_t*)malloc(2 * w * h * sizeof(*plane1));
|
||||
@@ -205,8 +205,8 @@ static void ConvertToGray(WebPPicture* const pic) {
|
||||
for (x = 0; x < pic->width; ++x) {
|
||||
const uint32_t argb = row[x];
|
||||
const uint32_t r = (argb >> 16) & 0xff;
|
||||
const uint32_t g = (argb >> 8) & 0xff;
|
||||
const uint32_t b = (argb >> 0) & 0xff;
|
||||
const uint32_t g = (argb >> 8) & 0xff;
|
||||
const uint32_t b = (argb >> 0) & 0xff;
|
||||
// We use BT.709 for converting to luminance.
|
||||
const uint32_t Y = (uint32_t)(0.2126 * r + 0.7152 * g + 0.0722 * b + .5);
|
||||
row[x] = (argb & 0xff000000u) | (Y * 0x010101u);
|
||||
@@ -297,8 +297,7 @@ int main(int argc, const char* argv[]) {
|
||||
fprintf(stderr, "Error while computing the distortion.\n");
|
||||
goto End;
|
||||
}
|
||||
printf("%u %.2f %.2f %.2f %.2f %.2f [ %.2f bpp ]\n",
|
||||
(unsigned int)size1,
|
||||
printf("%u %.2f %.2f %.2f %.2f %.2f [ %.2f bpp ]\n", (unsigned int)size1,
|
||||
disto[4], disto[0], disto[1], disto[2], disto[3],
|
||||
8.f * size1 / pic1.width / pic1.height);
|
||||
|
||||
@@ -306,21 +305,25 @@ int main(int argc, const char* argv[]) {
|
||||
uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
if (pic1.use_argb != pic2.use_argb) {
|
||||
fprintf(stderr, "Pictures are not in the same argb format. "
|
||||
"Can't save the difference map.\n");
|
||||
fprintf(stderr,
|
||||
"Pictures are not in the same argb format. "
|
||||
"Can't save the difference map.\n");
|
||||
goto End;
|
||||
}
|
||||
if (pic1.use_argb) {
|
||||
int n;
|
||||
fprintf(stderr, "max differences per channel: ");
|
||||
for (n = 0; n < 3; ++n) { // skip the alpha channel
|
||||
const int range = (type == 1) ?
|
||||
SSIMScaleChannel((uint8_t*)pic1.argb + n, pic1.argb_stride * 4,
|
||||
(const uint8_t*)pic2.argb + n, pic2.argb_stride * 4,
|
||||
4, pic1.width, pic1.height, scale) :
|
||||
DiffScaleChannel((uint8_t*)pic1.argb + n, pic1.argb_stride * 4,
|
||||
(const uint8_t*)pic2.argb + n, pic2.argb_stride * 4,
|
||||
4, pic1.width, pic1.height, scale);
|
||||
for (n = 0; n < 3; ++n) { // skip the alpha channel
|
||||
const int range =
|
||||
(type == 1)
|
||||
? SSIMScaleChannel(
|
||||
(uint8_t*)pic1.argb + n, pic1.argb_stride * 4,
|
||||
(const uint8_t*)pic2.argb + n, pic2.argb_stride * 4, 4,
|
||||
pic1.width, pic1.height, scale)
|
||||
: DiffScaleChannel(
|
||||
(uint8_t*)pic1.argb + n, pic1.argb_stride * 4,
|
||||
(const uint8_t*)pic2.argb + n, pic2.argb_stride * 4, 4,
|
||||
pic1.width, pic1.height, scale);
|
||||
if (range < 0) fprintf(stderr, "\nError computing diff map\n");
|
||||
fprintf(stderr, "[%d]", range);
|
||||
}
|
||||
@@ -331,10 +334,9 @@ int main(int argc, const char* argv[]) {
|
||||
goto End;
|
||||
}
|
||||
#if !defined(WEBP_REDUCE_CSP)
|
||||
data_size = WebPEncodeLosslessBGRA((const uint8_t*)pic1.argb,
|
||||
pic1.width, pic1.height,
|
||||
pic1.argb_stride * 4,
|
||||
&data);
|
||||
data_size =
|
||||
WebPEncodeLosslessBGRA((const uint8_t*)pic1.argb, pic1.width,
|
||||
pic1.height, pic1.argb_stride * 4, &data);
|
||||
if (data_size == 0) {
|
||||
fprintf(stderr, "Error during lossless encoding.\n");
|
||||
goto End;
|
||||
@@ -346,14 +348,15 @@ int main(int argc, const char* argv[]) {
|
||||
#else
|
||||
(void)data;
|
||||
(void)data_size;
|
||||
fprintf(stderr, "Cannot save the difference map. Please recompile "
|
||||
"without the WEBP_REDUCE_CSP flag.\n");
|
||||
fprintf(stderr,
|
||||
"Cannot save the difference map. Please recompile "
|
||||
"without the WEBP_REDUCE_CSP flag.\n");
|
||||
goto End;
|
||||
#endif // WEBP_REDUCE_CSP
|
||||
}
|
||||
ret = EXIT_SUCCESS;
|
||||
|
||||
End:
|
||||
End:
|
||||
WebPPictureFree(&pic1);
|
||||
WebPPictureFree(&pic2);
|
||||
FREE_WARGV_AND_RETURN(ret);
|
||||
|
@@ -54,10 +54,10 @@ int VP8EstimateQuality(const uint8_t* const data, size_t size) {
|
||||
if (data == NULL) return -1;
|
||||
|
||||
if (WebPGetFeatures(data, size, &features) != VP8_STATUS_OK) {
|
||||
return -1; // invalid file
|
||||
return -1; // invalid file
|
||||
}
|
||||
if (features.format == 2) return 101; // lossless
|
||||
if (features.format == 0 || features.has_animation) return -1; // mixed
|
||||
if (features.format == 2) return 101; // lossless
|
||||
if (features.format == 0 || features.has_animation) return -1; // mixed
|
||||
|
||||
while (pos < size) {
|
||||
sig = (sig >> 8) | ((uint64_t)data[pos++] << 40);
|
||||
@@ -78,29 +78,29 @@ int VP8EstimateQuality(const uint8_t* const data, size_t size) {
|
||||
GET_BIT(2); // colorspace + clamp type
|
||||
|
||||
// Segment header
|
||||
if (GET_BIT(1)) { // use_segment
|
||||
if (GET_BIT(1)) { // use_segment
|
||||
int s;
|
||||
const int update_map = GET_BIT(1);
|
||||
if (GET_BIT(1)) { // update data
|
||||
if (GET_BIT(1)) { // update data
|
||||
const int absolute_delta = GET_BIT(1);
|
||||
int q[4] = { 0, 0, 0, 0 };
|
||||
int q[4] = {0, 0, 0, 0};
|
||||
for (s = 0; s < 4; ++s) {
|
||||
if (GET_BIT(1)) {
|
||||
q[s] = GET_BIT(7);
|
||||
if (GET_BIT(1)) q[s] = -q[s]; // sign
|
||||
if (GET_BIT(1)) q[s] = -q[s]; // sign
|
||||
}
|
||||
}
|
||||
if (absolute_delta) Q = q[0]; // just use the first segment's quantizer
|
||||
for (s = 0; s < 4; ++s) CONDITIONAL_SKIP(7); // filter strength
|
||||
for (s = 0; s < 4; ++s) CONDITIONAL_SKIP(7); // filter strength
|
||||
}
|
||||
if (update_map) {
|
||||
for (s = 0; s < 3; ++s) CONDITIONAL_SKIP(8);
|
||||
}
|
||||
}
|
||||
// Filter header
|
||||
GET_BIT(1 + 6 + 3); // simple + level + sharpness
|
||||
if (GET_BIT(1)) { // use_lf_delta
|
||||
if (GET_BIT(1)) { // update lf_delta?
|
||||
GET_BIT(1 + 6 + 3); // simple + level + sharpness
|
||||
if (GET_BIT(1)) { // use_lf_delta
|
||||
if (GET_BIT(1)) { // update lf_delta?
|
||||
int n;
|
||||
for (n = 0; n < 4 + 4; ++n) CONDITIONAL_SKIP(6);
|
||||
}
|
||||
|
@@ -23,10 +23,10 @@
|
||||
|
||||
#if defined(WEBP_HAVE_SDL)
|
||||
|
||||
#include "webp_to_sdl.h"
|
||||
#include "webp/decode.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "webp/decode.h"
|
||||
#include "webp_to_sdl.h"
|
||||
|
||||
#if defined(WEBP_HAVE_JUST_SDL_H)
|
||||
#include <SDL.h>
|
||||
@@ -41,11 +41,15 @@ static void ProcessEvents(void) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYUP:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_q: done = 1; break;
|
||||
default: break;
|
||||
case SDLK_q:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +97,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
Error:
|
||||
SDL_Quit();
|
||||
FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
@@ -12,9 +12,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "../examples/unicode.h"
|
||||
#include "src/webp/types.h"
|
||||
#include "extras/extras.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "src/webp/types.h"
|
||||
|
||||
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
|
||||
int main(int argc, const char* argv[]) {
|
||||
@@ -46,7 +46,7 @@ int main(int argc, const char* argv[]) {
|
||||
if (!quiet) {
|
||||
printf("Estimated quality factor: %d\n", q);
|
||||
} else {
|
||||
printf("%d\n", q); // just print the number
|
||||
printf("%d\n", q); // just print the number
|
||||
}
|
||||
}
|
||||
free((void*)data);
|
||||
|
@@ -17,11 +17,10 @@
|
||||
|
||||
#if defined(WEBP_HAVE_SDL)
|
||||
|
||||
#include "webp_to_sdl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "src/webp/decode.h"
|
||||
#include "webp_to_sdl.h"
|
||||
|
||||
#if defined(WEBP_HAVE_JUST_SDL_H)
|
||||
#include <SDL.h>
|
||||
@@ -67,11 +66,11 @@ int WebPToSDL(const char* data, unsigned int data_size) {
|
||||
}
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
output = WebPDecodeBGRA((const uint8_t*)data, (size_t)data_size, &width,
|
||||
&height);
|
||||
output =
|
||||
WebPDecodeBGRA((const uint8_t*)data, (size_t)data_size, &width, &height);
|
||||
#else
|
||||
output = WebPDecodeRGBA((const uint8_t*)data, (size_t)data_size, &width,
|
||||
&height);
|
||||
output =
|
||||
WebPDecodeRGBA((const uint8_t*)data, (size_t)data_size, &width, &height);
|
||||
#endif
|
||||
if (output == NULL) {
|
||||
fprintf(stderr, "Error decoding image (%d)\n", status);
|
||||
@@ -84,7 +83,7 @@ int WebPToSDL(const char* data, unsigned int data_size) {
|
||||
SDL_RenderPresent(renderer);
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
Error:
|
||||
// We should call SDL_DestroyWindow(window) but that makes .js fail.
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyTexture(texture);
|
||||
|
Reference in New Issue
Block a user