mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-17 06:19:54 +02:00
Refactor CopyPlane() and CopyPixels() methods: put them in utils.
Change-Id: I0e1533df557a0fa42c670e3b826fc0675c36e0a5
This commit is contained in:
@ -82,7 +82,6 @@ static int EncodeLossless(const uint8_t* const data, int width, int height,
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -166,16 +165,6 @@ static int EncodeAlphaInternal(const uint8_t* const data, int width, int height,
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
static int GetNumColors(const uint8_t* data, int width, int height,
|
||||
int stride) {
|
||||
int j;
|
||||
@ -326,7 +315,7 @@ static int EncodeAlpha(VP8Encoder* const enc,
|
||||
}
|
||||
|
||||
// Extract alpha data (width x height) from raw_data (stride x height).
|
||||
CopyPlane(pic->a, pic->a_stride, quant_alpha, width, width, height);
|
||||
WebPCopyPlane(pic->a, pic->a_stride, quant_alpha, width, width, height);
|
||||
|
||||
if (reduce_levels) { // No Quantization required for 'quality = 100'.
|
||||
// 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence
|
||||
|
@ -30,16 +30,6 @@ static void PictureGrabSpecs(const WebPPicture* const src,
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Picture copying
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust top-left corner to chroma sample position.
|
||||
static void SnapTopLeftPosition(const WebPPicture* const pic,
|
||||
@ -70,20 +60,20 @@ int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) {
|
||||
if (!WebPPictureAlloc(dst)) return 0;
|
||||
|
||||
if (!src->use_argb) {
|
||||
CopyPlane(src->y, src->y_stride,
|
||||
dst->y, dst->y_stride, dst->width, dst->height);
|
||||
CopyPlane(src->u, src->uv_stride,
|
||||
dst->u, dst->uv_stride, HALVE(dst->width), HALVE(dst->height));
|
||||
CopyPlane(src->v, src->uv_stride,
|
||||
dst->v, dst->uv_stride, HALVE(dst->width), HALVE(dst->height));
|
||||
WebPCopyPlane(src->y, src->y_stride,
|
||||
dst->y, dst->y_stride, dst->width, dst->height);
|
||||
WebPCopyPlane(src->u, src->uv_stride, dst->u, dst->uv_stride,
|
||||
HALVE(dst->width), HALVE(dst->height));
|
||||
WebPCopyPlane(src->v, src->uv_stride, dst->v, dst->uv_stride,
|
||||
HALVE(dst->width), HALVE(dst->height));
|
||||
if (dst->a != NULL) {
|
||||
CopyPlane(src->a, src->a_stride,
|
||||
dst->a, dst->a_stride, dst->width, dst->height);
|
||||
WebPCopyPlane(src->a, src->a_stride,
|
||||
dst->a, dst->a_stride, dst->width, dst->height);
|
||||
}
|
||||
} else {
|
||||
CopyPlane((const uint8_t*)src->argb, 4 * src->argb_stride,
|
||||
(uint8_t*)dst->argb, 4 * dst->argb_stride,
|
||||
4 * dst->width, dst->height);
|
||||
WebPCopyPlane((const uint8_t*)src->argb, 4 * src->argb_stride,
|
||||
(uint8_t*)dst->argb, 4 * dst->argb_stride,
|
||||
4 * dst->width, dst->height);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -144,24 +134,23 @@ int WebPPictureCrop(WebPPicture* pic,
|
||||
if (!pic->use_argb) {
|
||||
const int y_offset = top * pic->y_stride + left;
|
||||
const int uv_offset = (top / 2) * pic->uv_stride + left / 2;
|
||||
CopyPlane(pic->y + y_offset, pic->y_stride,
|
||||
tmp.y, tmp.y_stride, width, height);
|
||||
CopyPlane(pic->u + uv_offset, pic->uv_stride,
|
||||
tmp.u, tmp.uv_stride, HALVE(width), HALVE(height));
|
||||
CopyPlane(pic->v + uv_offset, pic->uv_stride,
|
||||
tmp.v, tmp.uv_stride, HALVE(width), HALVE(height));
|
||||
WebPCopyPlane(pic->y + y_offset, pic->y_stride,
|
||||
tmp.y, tmp.y_stride, width, height);
|
||||
WebPCopyPlane(pic->u + uv_offset, pic->uv_stride,
|
||||
tmp.u, tmp.uv_stride, HALVE(width), HALVE(height));
|
||||
WebPCopyPlane(pic->v + uv_offset, pic->uv_stride,
|
||||
tmp.v, tmp.uv_stride, HALVE(width), HALVE(height));
|
||||
|
||||
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);
|
||||
WebPCopyPlane(pic->a + a_offset, pic->a_stride,
|
||||
tmp.a, tmp.a_stride, width, height);
|
||||
}
|
||||
} else {
|
||||
const uint8_t* const src =
|
||||
(const uint8_t*)(pic->argb + top * pic->argb_stride + left);
|
||||
CopyPlane(src, pic->argb_stride * 4,
|
||||
(uint8_t*)tmp.argb, tmp.argb_stride * 4,
|
||||
width * 4, height);
|
||||
WebPCopyPlane(src, pic->argb_stride * 4, (uint8_t*)tmp.argb,
|
||||
tmp.argb_stride * 4, width * 4, height);
|
||||
}
|
||||
WebPPictureFree(pic);
|
||||
*pic = tmp;
|
||||
|
Reference in New Issue
Block a user