mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 21:39:59 +02:00
speed-up GetResidualCost()
+ misc cosmetics and code polishing Change-Id: I5830cd2f268d64c072b1cbccc0a4674833875055
This commit is contained in:
@ -25,7 +25,7 @@ extern "C" {
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int WebPPictureAlloc(WebPPicture* const picture) {
|
||||
if (picture) {
|
||||
if (picture != NULL) {
|
||||
const WebPEncCSP uv_csp = picture->colorspace & WEBP_CSP_UV_MASK;
|
||||
const int has_alpha = picture->colorspace & WEBP_CSP_ALPHA_BIT;
|
||||
const int width = picture->width;
|
||||
@ -108,7 +108,7 @@ int WebPPictureAlloc(WebPPicture* const picture) {
|
||||
// into 'dst'. Mark 'dst' as not owning any memory. 'src' can be NULL.
|
||||
static void WebPPictureGrabSpecs(const WebPPicture* const src,
|
||||
WebPPicture* const dst) {
|
||||
if (src) *dst = *src;
|
||||
if (src != NULL) *dst = *src;
|
||||
dst->y = dst->u = dst->v = NULL;
|
||||
dst->u0 = dst->v0 = NULL;
|
||||
dst->a = NULL;
|
||||
@ -116,7 +116,7 @@ static void WebPPictureGrabSpecs(const WebPPicture* const src,
|
||||
|
||||
// Release memory owned by 'picture'.
|
||||
void WebPPictureFree(WebPPicture* const picture) {
|
||||
if (picture) {
|
||||
if (picture != NULL) {
|
||||
free(picture->y);
|
||||
WebPPictureGrabSpecs(NULL, picture);
|
||||
}
|
||||
@ -125,7 +125,7 @@ void WebPPictureFree(WebPPicture* const picture) {
|
||||
//------------------------------------------------------------------------------
|
||||
// Picture copying
|
||||
|
||||
// TODO(skal): move to dsp/ ?
|
||||
// Not worth moving to dsp/enc.c (only used here).
|
||||
static void CopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height) {
|
||||
while (height-- > 0) {
|
||||
@ -195,13 +195,13 @@ int WebPPictureCrop(WebPPicture* const pic,
|
||||
tmp.v, tmp.uv_stride, HALVE(width), HALVE(height));
|
||||
}
|
||||
|
||||
if (tmp.a) {
|
||||
if (tmp.a != NULL) {
|
||||
const int a_offset = top * pic->a_stride + left;
|
||||
CopyPlane(pic->a + a_offset, pic->a_stride,
|
||||
tmp.a, tmp.a_stride, width, height);
|
||||
}
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
||||
if (tmp.u0) {
|
||||
if (tmp.u0 != NULL) {
|
||||
int w = width;
|
||||
int l = left;
|
||||
if (tmp.colorspace == WEBP_YUV422) {
|
||||
@ -348,12 +348,12 @@ int WebPPictureRescale(WebPPicture* const pic, int width, int height) {
|
||||
tmp.v,
|
||||
HALVE(width), HALVE(height), tmp.uv_stride, work);
|
||||
|
||||
if (tmp.a) {
|
||||
if (tmp.a != NULL) {
|
||||
RescalePlane(pic->a, prev_width, prev_height, pic->a_stride,
|
||||
tmp.a, width, height, tmp.a_stride, work);
|
||||
}
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
||||
if (tmp.u0) {
|
||||
if (tmp.u0 != NULL) {
|
||||
int s = 1;
|
||||
if ((tmp.colorspace & WEBP_CSP_UV_MASK) == WEBP_YUV422) {
|
||||
s = 2;
|
||||
@ -382,7 +382,7 @@ typedef struct {
|
||||
size_t* size;
|
||||
} WebPMemoryWriter;
|
||||
|
||||
static void InitMemoryWriter(WebPMemoryWriter* const writer) {
|
||||
static void WebPMemoryWriterInit(WebPMemoryWriter* const writer) {
|
||||
*writer->mem = NULL;
|
||||
*writer->size = 0;
|
||||
writer->max_size = 0;
|
||||
@ -412,7 +412,7 @@ static int WebPMemoryWrite(const uint8_t* data, size_t data_size,
|
||||
*w->mem = new_mem;
|
||||
w->max_size = next_max_size;
|
||||
}
|
||||
if (data_size) {
|
||||
if (data_size > 0) {
|
||||
memcpy((*w->mem) + (*w->size), data, data_size);
|
||||
*w->size += data_size;
|
||||
}
|
||||
@ -683,7 +683,7 @@ static size_t Encode(const uint8_t* rgba, int width, int height, int stride,
|
||||
|
||||
wrt.mem = output;
|
||||
wrt.size = &output_size;
|
||||
InitMemoryWriter(&wrt);
|
||||
WebPMemoryWriterInit(&wrt);
|
||||
|
||||
ok = import(&pic, rgba, stride) && WebPEncode(&config, &pic);
|
||||
WebPPictureFree(&pic);
|
||||
|
Reference in New Issue
Block a user