Skip to content

Commit ae8ef64

Browse files
committed
swscale/swscale_unscaled: add unscaled x2rgb10le to planar RGB
Signed-off-by: James Almer <[email protected]>
1 parent 8503c64 commit ae8ef64

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

libswscale/swscale_unscaled.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,77 @@ static void packed16togbra16(const uint8_t *src, int srcStride,
742742
}
743743
}
744744

745+
static void packed30togbra10(const uint8_t *src, int srcStride,
746+
uint16_t *dst[], const int dstStride[], int srcSliceH,
747+
int swap, int bpc, int width)
748+
{
749+
int x, h, i;
750+
int dst_alpha = dst[3] != NULL;
751+
int scale_high = bpc - 10, scale_low = 10 - scale_high;
752+
for (h = 0; h < srcSliceH; h++) {
753+
uint32_t *src_line = (uint32_t *)(src + srcStride * h);
754+
unsigned component;
755+
756+
switch (swap) {
757+
case 3:
758+
case 2:
759+
if (dst_alpha) {
760+
for (x = 0; x < width; x++) {
761+
unsigned p = AV_RL32(src_line);
762+
component = (p >> 20) & 0x3FF;
763+
dst[0][x] = av_bswap16(component << scale_high | component >> scale_low);
764+
component = (p >> 10) & 0x3FF;
765+
dst[1][x] = av_bswap16(component << scale_high | component >> scale_low);
766+
component = p & 0x3FF;
767+
dst[2][x] = av_bswap16(component << scale_high | component >> scale_low);
768+
dst[3][x] = 0xFFFF;
769+
src_line++;
770+
}
771+
} else {
772+
for (x = 0; x < width; x++) {
773+
unsigned p = AV_RL32(src_line);
774+
component = (p >> 20) & 0x3FF;
775+
dst[0][x] = av_bswap16(component << scale_high | component >> scale_low);
776+
component = (p >> 10) & 0x3FF;
777+
dst[1][x] = av_bswap16(component << scale_high | component >> scale_low);
778+
component = p & 0x3FF;
779+
dst[2][x] = av_bswap16(component << scale_high | component >> scale_low);
780+
src_line++;
781+
}
782+
}
783+
break;
784+
default:
785+
if (dst_alpha) {
786+
for (x = 0; x < width; x++) {
787+
unsigned p = AV_RL32(src_line);
788+
component = (p >> 20) & 0x3FF;
789+
dst[0][x] = component << scale_high | component >> scale_low;
790+
component = (p >> 10) & 0x3FF;
791+
dst[1][x] = component << scale_high | component >> scale_low;
792+
component = p & 0x3FF;
793+
dst[2][x] = component << scale_high | component >> scale_low;
794+
dst[3][x] = 0xFFFF;
795+
src_line++;
796+
}
797+
} else {
798+
for (x = 0; x < width; x++) {
799+
unsigned p = AV_RL32(src_line);
800+
component = (p >> 20) & 0x3FF;
801+
dst[0][x] = component << scale_high | component >> scale_low;
802+
component = (p >> 10) & 0x3FF;
803+
dst[1][x] = component << scale_high | component >> scale_low;
804+
component = p & 0x3FF;
805+
dst[2][x] = component << scale_high | component >> scale_low;
806+
src_line++;
807+
}
808+
}
809+
break;
810+
}
811+
for (i = 0; i < 4; i++)
812+
dst[i] += dstStride[i] >> 1;
813+
}
814+
}
815+
745816
static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[],
746817
const int srcStride[], int srcSliceY, int srcSliceH,
747818
uint8_t *const dst[], const int dstStride[])
@@ -785,6 +856,12 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[],
785856
dst2013, stride2013, srcSliceH, alpha, swap,
786857
16 - bpc, c->srcW);
787858
break;
859+
case AV_PIX_FMT_X2RGB10LE:
860+
av_assert0(bpc >= 10);
861+
packed30togbra10(src[0], srcStride[0],
862+
dst2013, stride2013, srcSliceH, swap,
863+
bpc, c->srcW);
864+
break;
788865
case AV_PIX_FMT_BGR48LE:
789866
case AV_PIX_FMT_BGR48BE:
790867
case AV_PIX_FMT_BGRA64LE:
@@ -793,6 +870,12 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[],
793870
dst1023, stride1023, srcSliceH, alpha, swap,
794871
16 - bpc, c->srcW);
795872
break;
873+
case AV_PIX_FMT_X2BGR10LE:
874+
av_assert0(bpc >= 10);
875+
packed30togbra10(src[0], srcStride[0],
876+
dst1023, stride1023, srcSliceH, swap,
877+
bpc, c->srcW);
878+
break;
796879
default:
797880
av_log(c, AV_LOG_ERROR,
798881
"unsupported conversion to planar RGB %s -> %s\n",
@@ -2301,6 +2384,11 @@ void ff_get_unscaled_swscale(SwsInternal *c)
23012384
dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
23022385
c->convert_unscaled = Rgb16ToPlanarRgb16Wrapper;
23032386

2387+
if (av_pix_fmt_desc_get(dstFormat)->comp[0].depth >= 10 &&
2388+
isPlanarRGB(dstFormat) && !isFloat(dstFormat) &&
2389+
(srcFormat == AV_PIX_FMT_X2RGB10LE || srcFormat == AV_PIX_FMT_X2BGR10LE))
2390+
c->convert_unscaled = Rgb16ToPlanarRgb16Wrapper;
2391+
23042392
if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
23052393
srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
23062394
srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||

tests/ref/pixfmt/gbrp10-x2bgr10le

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
909448714837e324484d85f3da37e2ba *tests/data/pixfmt/gbrp10-x2bgr10le.yuv
1+
1f9cc212a4081b6e35811df461b18fec *tests/data/pixfmt/gbrp10-x2bgr10le.yuv
22
15206400 tests/data/pixfmt/gbrp10-x2bgr10le.yuv

tests/ref/pixfmt/gbrp10-x2rgb10le

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
909448714837e324484d85f3da37e2ba *tests/data/pixfmt/gbrp10-x2rgb10le.yuv
1+
1f9cc212a4081b6e35811df461b18fec *tests/data/pixfmt/gbrp10-x2rgb10le.yuv
22
15206400 tests/data/pixfmt/gbrp10-x2rgb10le.yuv

0 commit comments

Comments
 (0)