[FFmpeg-devel] [PATCH]Implement packed 16bit to planar 16bit unscaled rgb converter
Carl Eugen Hoyos
cehoyos at ag.or.at
Thu Jan 9 14:24:38 CET 2014
Hi!
A user reported an issue when converting r210 to ffv1:
http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=7&t=1731
http://forum.videohelp.com/threads/361133-Lossless-%2810-Bit-RGB-444%29-and-%2810-Bit-YUV-422%29-Compression-Codec-s?p=2290391&viewfull=1#post2290391
I had sent a patch last year to fix this, iirc there was no usecase for it.
Attached is the rebased patch, I only tested one codepath:
$ ffmpeg -i fate-suite/r210/r210.avi -vcodec ffv1 -coder 1 -pix_fmt gbrp10le
out.avi
$ ffmpeg -i out.avi -vcodec r210 out2.avi
$ ffmpeg -i fate-suite/r210/r210.avi -f framecrc -
$ ffmpeg -i out2.avi -f framecrc -
The codepath for GBRP*16 is not activated in utils.c, it breaks fate and is
(atm) unrelated.
Please review, Carl Eugen
-------------- next part --------------
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 0f0f5fe..92f2f97 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -410,6 +410,136 @@ static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
return srcSliceH;
}
+static void packed16togbra16(const uint8_t *src, int srcStride,
+ uint16_t *dst[], int dstStride[], int srcSliceH,
+ int alpha, int swap, int shift, int width)
+{
+ int x, h, i;
+ for (h = 0; h < srcSliceH; h++) {
+ uint16_t *src_line = (uint16_t *)(src + srcStride * h);
+ switch (alpha) {
+ case 3:
+ if (swap) {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = av_bswap16(*src_line++) >> shift;
+ dst[1][x] = av_bswap16(*src_line++) >> shift;
+ dst[2][x] = av_bswap16(*src_line++) >> shift;
+ dst[3][x] = av_bswap16(*src_line++) >> shift;
+ }
+ } else {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = *src_line++ >> shift;
+ dst[1][x] = *src_line++ >> shift;
+ dst[2][x] = *src_line++ >> shift;
+ dst[3][x] = *src_line++ >> shift;
+ }
+ }
+ break;
+ case 2:
+ if (swap) {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = av_bswap16(*src_line++) >> shift;
+ dst[1][x] = av_bswap16(*src_line++) >> shift;
+ dst[2][x] = av_bswap16(*src_line++) >> shift;
+ src_line++;
+ }
+ } else {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = *src_line++ >> shift;
+ dst[1][x] = *src_line++ >> shift;
+ dst[2][x] = *src_line++ >> shift;
+ src_line++;
+ }
+ }
+ break;
+ case 1:
+ if (swap) {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = av_bswap16(*src_line++) >> shift;
+ dst[1][x] = av_bswap16(*src_line++) >> shift;
+ dst[2][x] = av_bswap16(*src_line++) >> shift;
+ dst[3][x] = 0xFFFF;
+ }
+ } else {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = *src_line++ >> shift;
+ dst[1][x] = *src_line++ >> shift;
+ dst[2][x] = *src_line++ >> shift;
+ dst[3][x] = 0xFFFF;
+ }
+ }
+ break;
+ default:
+ if (swap) {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = av_bswap16(*src_line++) >> shift;
+ dst[1][x] = av_bswap16(*src_line++) >> shift;
+ dst[2][x] = av_bswap16(*src_line++) >> shift;
+ }
+ } else {
+ for (x = 0; x < width; x++) {
+ dst[0][x] = *src_line++ >> shift;
+ dst[1][x] = *src_line++ >> shift;
+ dst[2][x] = *src_line++ >> shift;
+ }
+ }
+ }
+ for (i = 0; i < 4; i++)
+ dst[i] += dstStride[i] >> 1;
+ }
+}
+
+static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const uint8_t *src[],
+ int srcStride[], int srcSliceY, int srcSliceH,
+ uint8_t *dst[], int dstStride[])
+{
+ uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
+ uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
+ int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
+ int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
+ const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
+ const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
+ int alpha = 0;
+ int swap = (src_format->flags & AV_PIX_FMT_FLAG_BE) !=
+ (dst_format->flags & AV_PIX_FMT_FLAG_BE);
+ if (src_format->flags & AV_PIX_FMT_FLAG_ALPHA)
+ alpha += 2;
+ if (dst_format->flags & AV_PIX_FMT_FLAG_ALPHA)
+ alpha++;
+
+ if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
+ (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) ||
+ dst_format->comp[0].depth_minus1 < 8) {
+ av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n",
+ src_format->name, dst_format->name);
+ return srcSliceH;
+ }
+ switch (c->srcFormat) {
+ case AV_PIX_FMT_RGB48LE:
+ case AV_PIX_FMT_RGB48BE:
+ case AV_PIX_FMT_RGBA64LE:
+ case AV_PIX_FMT_RGBA64BE:
+ packed16togbra16(src[0] + srcSliceY * srcStride[0], srcStride[0],
+ dst2013, stride2013, srcSliceH, alpha, swap,
+ 15 - dst_format->comp[0].depth_minus1, c->srcW);
+ break;
+ case AV_PIX_FMT_BGR48LE:
+ case AV_PIX_FMT_BGR48BE:
+ case AV_PIX_FMT_BGRA64LE:
+ case AV_PIX_FMT_BGRA64BE:
+ packed16togbra16(src[0] + srcSliceY * srcStride[0], srcStride[0],
+ dst1023, stride1023, srcSliceH, alpha, swap,
+ 15 - dst_format->comp[0].depth_minus1, c->srcW);
+ break;
+ default:
+ av_log(c, AV_LOG_ERROR,
+ "unsupported conversion to planar RGB %s -> %s\n",
+ src_format->name, dst_format->name);
+ }
+
+ return srcSliceH;
+}
+
static void gbr16ptopacked16(const uint16_t *src[], int srcStride[],
uint8_t *dst, int dstStride, int srcSliceH,
int alpha, int swap, int bpp, int width)
@@ -1277,6 +1407,18 @@ void ff_get_unscaled_swscale(SwsContext *c)
if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
c->swscale = planarRgbToRgbWrapper;
+ if ((srcFormat == AV_PIX_FMT_RGB48LE || srcFormat == AV_PIX_FMT_RGB48BE ||
+ srcFormat == AV_PIX_FMT_BGR48LE || srcFormat == AV_PIX_FMT_BGR48BE ||
+ srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
+ srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
+ (dstFormat == AV_PIX_FMT_GBRP9LE || dstFormat == AV_PIX_FMT_GBRP9BE ||
+ dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
+ dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
+ dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
+ dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
+ dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
+ c->swscale = Rgb16ToPlanarRgb16Wrapper;
+
if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
More information about the ffmpeg-devel
mailing list