1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

swscale/rgb2xyz: follow convention on image pointers and strides

Instead of taking an int16_t pointer and a stride in halfwords, follow the
usual convention of treating all planes and strides as byte-addressed.

This does not have any immediate effect but makes these functions more
reusable without unintended "gotchas".

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
Niklas Haas 2024-10-07 19:33:44 +02:00
parent 9d8f5141cf
commit 775de8c19d

View File

@ -637,23 +637,26 @@ static int check_image_pointers(const uint8_t * const data[4], enum AVPixelForma
return 1; return 1;
} }
static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst, static void xyz12Torgb48(struct SwsContext *c, uint8_t *dst, int dst_stride,
const uint16_t *src, int stride, int w, int h) const uint8_t *src, int src_stride, int w, int h)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
for (int yp = 0; yp < h; yp++) { for (int yp = 0; yp < h; yp++) {
const uint16_t *src16 = (const uint16_t *) src;
uint16_t *dst16 = (uint16_t *) dst;
for (int xp = 0; xp < 3 * w; xp += 3) { for (int xp = 0; xp < 3 * w; xp += 3) {
int x, y, z, r, g, b; int x, y, z, r, g, b;
if (desc->flags & AV_PIX_FMT_FLAG_BE) { if (desc->flags & AV_PIX_FMT_FLAG_BE) {
x = AV_RB16(src + xp + 0); x = AV_RB16(src16 + xp + 0);
y = AV_RB16(src + xp + 1); y = AV_RB16(src16 + xp + 1);
z = AV_RB16(src + xp + 2); z = AV_RB16(src16 + xp + 2);
} else { } else {
x = AV_RL16(src + xp + 0); x = AV_RL16(src16 + xp + 0);
y = AV_RL16(src + xp + 1); y = AV_RL16(src16 + xp + 1);
z = AV_RL16(src + xp + 2); z = AV_RL16(src16 + xp + 2);
} }
x = c->xyzgamma[x >> 4]; x = c->xyzgamma[x >> 4];
@ -678,37 +681,41 @@ static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst,
// convert from sRGBlinear to RGB and scale from 12bit to 16bit // convert from sRGBlinear to RGB and scale from 12bit to 16bit
if (desc->flags & AV_PIX_FMT_FLAG_BE) { if (desc->flags & AV_PIX_FMT_FLAG_BE) {
AV_WB16(dst + xp + 0, c->rgbgamma[r] << 4); AV_WB16(dst16 + xp + 0, c->rgbgamma[r] << 4);
AV_WB16(dst + xp + 1, c->rgbgamma[g] << 4); AV_WB16(dst16 + xp + 1, c->rgbgamma[g] << 4);
AV_WB16(dst + xp + 2, c->rgbgamma[b] << 4); AV_WB16(dst16 + xp + 2, c->rgbgamma[b] << 4);
} else { } else {
AV_WL16(dst + xp + 0, c->rgbgamma[r] << 4); AV_WL16(dst16 + xp + 0, c->rgbgamma[r] << 4);
AV_WL16(dst + xp + 1, c->rgbgamma[g] << 4); AV_WL16(dst16 + xp + 1, c->rgbgamma[g] << 4);
AV_WL16(dst + xp + 2, c->rgbgamma[b] << 4); AV_WL16(dst16 + xp + 2, c->rgbgamma[b] << 4);
} }
} }
src += stride;
dst += stride; src += src_stride;
dst += dst_stride;
} }
} }
static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst, static void rgb48Toxyz12(struct SwsContext *c, uint8_t *dst, int dst_stride,
const uint16_t *src, int stride, int w, int h) const uint8_t *src, int src_stride, int w, int h)
{ {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
for (int yp = 0; yp < h; yp++) { for (int yp = 0; yp < h; yp++) {
uint16_t *src16 = (uint16_t *) src;
uint16_t *dst16 = (uint16_t *) dst;
for (int xp = 0; xp < 3 * w; xp += 3) { for (int xp = 0; xp < 3 * w; xp += 3) {
int x, y, z, r, g, b; int x, y, z, r, g, b;
if (desc->flags & AV_PIX_FMT_FLAG_BE) { if (desc->flags & AV_PIX_FMT_FLAG_BE) {
r = AV_RB16(src + xp + 0); r = AV_RB16(src16 + xp + 0);
g = AV_RB16(src + xp + 1); g = AV_RB16(src16 + xp + 1);
b = AV_RB16(src + xp + 2); b = AV_RB16(src16 + xp + 2);
} else { } else {
r = AV_RL16(src + xp + 0); r = AV_RL16(src16 + xp + 0);
g = AV_RL16(src + xp + 1); g = AV_RL16(src16 + xp + 1);
b = AV_RL16(src + xp + 2); b = AV_RL16(src16 + xp + 2);
} }
r = c->rgbgammainv[r>>4]; r = c->rgbgammainv[r>>4];
@ -733,17 +740,18 @@ static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst,
// convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
if (desc->flags & AV_PIX_FMT_FLAG_BE) { if (desc->flags & AV_PIX_FMT_FLAG_BE) {
AV_WB16(dst + xp + 0, c->xyzgammainv[x] << 4); AV_WB16(dst16 + xp + 0, c->xyzgammainv[x] << 4);
AV_WB16(dst + xp + 1, c->xyzgammainv[y] << 4); AV_WB16(dst16 + xp + 1, c->xyzgammainv[y] << 4);
AV_WB16(dst + xp + 2, c->xyzgammainv[z] << 4); AV_WB16(dst16 + xp + 2, c->xyzgammainv[z] << 4);
} else { } else {
AV_WL16(dst + xp + 0, c->xyzgammainv[x] << 4); AV_WL16(dst16 + xp + 0, c->xyzgammainv[x] << 4);
AV_WL16(dst + xp + 1, c->xyzgammainv[y] << 4); AV_WL16(dst16 + xp + 1, c->xyzgammainv[y] << 4);
AV_WL16(dst + xp + 2, c->xyzgammainv[z] << 4); AV_WL16(dst16 + xp + 2, c->xyzgammainv[z] << 4);
} }
} }
src += stride;
dst += stride; src += src_stride;
dst += dst_stride;
} }
} }
@ -993,8 +1001,7 @@ static int scale_internal(SwsContext *c,
base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) : base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) :
c->xyz_scratch; c->xyz_scratch;
xyz12Torgb48(c, (uint16_t*)base, (const uint16_t*)src2[0], srcStride[0]/2, xyz12Torgb48(c, base, srcStride[0], src2[0], srcStride[0], c->srcW, srcSliceH);
c->srcW, srcSliceH);
src2[0] = base; src2[0] = base;
} }
@ -1052,21 +1059,21 @@ static int scale_internal(SwsContext *c,
} }
if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
uint16_t *dst16; uint8_t *dst;
if (scale_dst) { if (scale_dst) {
dst16 = (uint16_t *)dst2[0]; dst = dst2[0];
} else { } else {
int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH; int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH;
av_assert0(dstY >= ret); av_assert0(dstY >= ret);
av_assert0(ret >= 0); av_assert0(ret >= 0);
av_assert0(c->dstH >= dstY); av_assert0(c->dstH >= dstY);
dst16 = (uint16_t*)(dst2[0] + (dstY - ret) * dstStride2[0]); dst = dst2[0] + (dstY - ret) * dstStride2[0];
} }
/* replace on the same data */ /* replace on the same data */
rgb48Toxyz12(c, dst16, dst16, dstStride2[0]/2, c->dstW, ret); rgb48Toxyz12(c, dst, dstStride2[0], dst, dstStride2[0], c->dstW, ret);
} }
/* reset slice direction at end of frame */ /* reset slice direction at end of frame */