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".
Unified · Split
| @@ -637,23 +637,26 @@ static int check_image_pointers(const uint8_t * const data[4], enum AVPixelForma · 636 unmodified lines | |||
| 637 | return 1; | 637 | return 1; |
| 638 | } | 638 | } |
| 639 | 639 | ||
| 640 | static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst, | 640 | static void xyz12Torgb48(struct SwsContext *c, uint8_t *dst, int dst_stride, |
| 641 | const uint16_t *src, int stride, int w, int h) | 641 | const uint8_t *src, int src_stride, int w, int h) |
| 642 | { | 642 | { |
| 643 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); | 643 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); |
| 644 | 644 | ||
| 645 | for (int yp = 0; yp < h; yp++) { | 645 | for (int yp = 0; yp < h; yp++) { |
| 646 | const uint16_t *src16 = (const uint16_t *) src; | ||
| 647 | uint16_t *dst16 = (uint16_t *) dst; | ||
| 648 | |||
| 646 | for (int xp = 0; xp < 3 * w; xp += 3) { | 649 | for (int xp = 0; xp < 3 * w; xp += 3) { |
| 647 | int x, y, z, r, g, b; | 650 | int x, y, z, r, g, b; |
| 648 | 651 | ||
| 649 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { | 652 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { |
| 650 | x = AV_RB16(src + xp + 0); | 653 | x = AV_RB16(src16 + xp + 0); |
| 651 | y = AV_RB16(src + xp + 1); | 654 | y = AV_RB16(src16 + xp + 1); |
| 652 | z = AV_RB16(src + xp + 2); | 655 | z = AV_RB16(src16 + xp + 2); |
| 653 | } else { | 656 | } else { |
| 654 | x = AV_RL16(src + xp + 0); | 657 | x = AV_RL16(src16 + xp + 0); |
| 655 | y = AV_RL16(src + xp + 1); | 658 | y = AV_RL16(src16 + xp + 1); |
| 656 | z = AV_RL16(src + xp + 2); | 659 | z = AV_RL16(src16 + xp + 2); |
| 657 | } | 660 | } |
| 658 | 661 | ||
| 659 | x = c->xyzgamma[x >> 4]; | 662 | x = c->xyzgamma[x >> 4]; |
| @@ -678,37 +681,41 @@ static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst, · 18 unmodified lines | |||
| 678 | 681 | ||
| 679 | // convert from sRGBlinear to RGB and scale from 12bit to 16bit | 682 | // convert from sRGBlinear to RGB and scale from 12bit to 16bit |
| 680 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { | 683 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { |
| 681 | AV_WB16(dst + xp + 0, c->rgbgamma[r] << 4); | 684 | AV_WB16(dst16 + xp + 0, c->rgbgamma[r] << 4); |
| 682 | AV_WB16(dst + xp + 1, c->rgbgamma[g] << 4); | 685 | AV_WB16(dst16 + xp + 1, c->rgbgamma[g] << 4); |
| 683 | AV_WB16(dst + xp + 2, c->rgbgamma[b] << 4); | 686 | AV_WB16(dst16 + xp + 2, c->rgbgamma[b] << 4); |
| 684 | } else { | 687 | } else { |
| 685 | AV_WL16(dst + xp + 0, c->rgbgamma[r] << 4); | 688 | AV_WL16(dst16 + xp + 0, c->rgbgamma[r] << 4); |
| 686 | AV_WL16(dst + xp + 1, c->rgbgamma[g] << 4); | 689 | AV_WL16(dst16 + xp + 1, c->rgbgamma[g] << 4); |
| 687 | AV_WL16(dst + xp + 2, c->rgbgamma[b] << 4); | 690 | AV_WL16(dst16 + xp + 2, c->rgbgamma[b] << 4); |
| 688 | } | 691 | } |
| 689 | } | 692 | } |
| 690 | src += stride; | 693 | |
| 691 | dst += stride; | 694 | src += src_stride; |
| 695 | dst += dst_stride; | ||
| 692 | } | 696 | } |
| 693 | } | 697 | } |
| 694 | 698 | ||
| 695 | static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst, | 699 | static void rgb48Toxyz12(struct SwsContext *c, uint8_t *dst, int dst_stride, |
| 696 | const uint16_t *src, int stride, int w, int h) | 700 | const uint8_t *src, int src_stride, int w, int h) |
| 697 | { | 701 | { |
| 698 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); | 702 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); |
| 699 | 703 | ||
| 700 | for (int yp = 0; yp < h; yp++) { | 704 | for (int yp = 0; yp < h; yp++) { |
| 705 | uint16_t *src16 = (uint16_t *) src; | ||
| 706 | uint16_t *dst16 = (uint16_t *) dst; | ||
| 707 | |||
| 701 | for (int xp = 0; xp < 3 * w; xp += 3) { | 708 | for (int xp = 0; xp < 3 * w; xp += 3) { |
| 702 | int x, y, z, r, g, b; | 709 | int x, y, z, r, g, b; |
| 703 | 710 | ||
| 704 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { | 711 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { |
| 705 | r = AV_RB16(src + xp + 0); | 712 | r = AV_RB16(src16 + xp + 0); |
| 706 | g = AV_RB16(src + xp + 1); | 713 | g = AV_RB16(src16 + xp + 1); |
| 707 | b = AV_RB16(src + xp + 2); | 714 | b = AV_RB16(src16 + xp + 2); |
| 708 | } else { | 715 | } else { |
| 709 | r = AV_RL16(src + xp + 0); | 716 | r = AV_RL16(src16 + xp + 0); |
| 710 | g = AV_RL16(src + xp + 1); | 717 | g = AV_RL16(src16 + xp + 1); |
| 711 | b = AV_RL16(src + xp + 2); | 718 | b = AV_RL16(src16 + xp + 2); |
| 712 | } | 719 | } |
| 713 | 720 | ||
| 714 | r = c->rgbgammainv[r>>4]; | 721 | r = c->rgbgammainv[r>>4]; |
| @@ -733,17 +740,18 @@ static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst, · 18 unmodified lines | |||
| 733 | 740 | ||
| 734 | // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit | 741 | // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit |
| 735 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { | 742 | if (desc->flags & AV_PIX_FMT_FLAG_BE) { |
| 736 | AV_WB16(dst + xp + 0, c->xyzgammainv[x] << 4); | 743 | AV_WB16(dst16 + xp + 0, c->xyzgammainv[x] << 4); |
| 737 | AV_WB16(dst + xp + 1, c->xyzgammainv[y] << 4); | 744 | AV_WB16(dst16 + xp + 1, c->xyzgammainv[y] << 4); |
| 738 | AV_WB16(dst + xp + 2, c->xyzgammainv[z] << 4); | 745 | AV_WB16(dst16 + xp + 2, c->xyzgammainv[z] << 4); |
| 739 | } else { | 746 | } else { |
| 740 | AV_WL16(dst + xp + 0, c->xyzgammainv[x] << 4); | 747 | AV_WL16(dst16 + xp + 0, c->xyzgammainv[x] << 4); |
| 741 | AV_WL16(dst + xp + 1, c->xyzgammainv[y] << 4); | 748 | AV_WL16(dst16 + xp + 1, c->xyzgammainv[y] << 4); |
| 742 | AV_WL16(dst + xp + 2, c->xyzgammainv[z] << 4); | 749 | AV_WL16(dst16 + xp + 2, c->xyzgammainv[z] << 4); |
| 743 | } | 750 | } |
| 744 | } | 751 | } |
| 745 | src += stride; | 752 | |
| 746 | dst += stride; | 753 | src += src_stride; |
| 754 | dst += dst_stride; | ||
| 747 | } | 755 | } |
| 748 | } | 756 | } |
| 749 | 757 | ||
| @@ -993,8 +1001,7 @@ static int scale_internal(SwsContext *c, · 243 unmodified lines | |||
| 993 | base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) : | 1001 | base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) : |
| 994 | c->xyz_scratch; | 1002 | c->xyz_scratch; |
| 995 | 1003 | ||
| 996 | xyz12Torgb48(c, (uint16_t*)base, (const uint16_t*)src2[0], srcStride[0]/2, | 1004 | xyz12Torgb48(c, base, srcStride[0], src2[0], srcStride[0], c->srcW, srcSliceH); |
| 997 | c->srcW, srcSliceH); | ||
| 998 | src2[0] = base; | 1005 | src2[0] = base; |
| 999 | } | 1006 | } |
| 1000 | 1007 | ||
| @@ -1052,21 +1059,21 @@ static int scale_internal(SwsContext *c, · 51 unmodified lines | |||
| 1052 | } | 1059 | } |
| 1053 | 1060 | ||
| 1054 | if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { | 1061 | if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { |
| 1055 | uint16_t *dst16; | 1062 | uint8_t *dst; |
| 1056 | 1063 | ||
| 1057 | if (scale_dst) { | 1064 | if (scale_dst) { |
| 1058 | dst16 = (uint16_t *)dst2[0]; | 1065 | dst = dst2[0]; |
| 1059 | } else { | 1066 | } else { |
| 1060 | int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH; | 1067 | int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH; |
| 1061 | 1068 | ||
| 1062 | av_assert0(dstY >= ret); | 1069 | av_assert0(dstY >= ret); |
| 1063 | av_assert0(ret >= 0); | 1070 | av_assert0(ret >= 0); |
| 1064 | av_assert0(c->dstH >= dstY); | 1071 | av_assert0(c->dstH >= dstY); |
| 1065 | dst16 = (uint16_t*)(dst2[0] + (dstY - ret) * dstStride2[0]); | 1072 | dst = dst2[0] + (dstY - ret) * dstStride2[0]; |
| 1066 | } | 1073 | } |
| 1067 | 1074 | ||
| 1068 | /* replace on the same data */ | 1075 | /* replace on the same data */ |
| 1069 | rgb48Toxyz12(c, dst16, dst16, dstStride2[0]/2, c->dstW, ret); | 1076 | rgb48Toxyz12(c, dst, dstStride2[0], dst, dstStride2[0], c->dstW, ret); |
| 1070 | } | 1077 | } |
| 1071 | 1078 | ||
| 1072 | /* reset slice direction at end of frame */ | 1079 | /* reset slice direction at end of frame */ |