diff options
author | Philip Gladstone <philipjsg@users.sourceforge.net> | 2002-07-27 03:08:04 +0000 |
---|---|---|
committer | Philip Gladstone <philipjsg@users.sourceforge.net> | 2002-07-27 03:08:04 +0000 |
commit | b71472eb62ec9317bfe119ede3222bf66dbbdb1a (patch) | |
tree | 86068aa491598cef51b5a9405199313556a2be1b | |
parent | 64e105e051ca3e5088b0db64551244482b2836b4 (diff) | |
download | ffmpeg-b71472eb62ec9317bfe119ede3222bf66dbbdb1a.tar.gz |
Add conversions to and from RGBA32 and BGRA32.
Originally committed as revision 824 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/avcodec.h | 2 | ||||
-rw-r--r-- | libavcodec/imgconvert.c | 242 | ||||
-rw-r--r-- | libavcodec/utils.c | 15 |
3 files changed, 258 insertions, 1 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 76de60a19f..641cf15216 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -59,6 +59,8 @@ enum PixelFormat { PIX_FMT_BGR24, PIX_FMT_YUV422P, PIX_FMT_YUV444P, + PIX_FMT_RGBA32, + PIX_FMT_BGRA32, PIX_FMT_YUV410P }; diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index ad6495da30..48d6c014c4 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -117,6 +117,69 @@ static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, } } +static void rgba32_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, + UINT8 *src, int width, int height) +{ + int wrap, wrap4, x, y; + int r, g, b, r1, g1, b1; + UINT8 *p; + + wrap = width; + wrap4 = width * 4; + p = src; + for(y=0;y<height;y+=2) { + for(x=0;x<width;x+=2) { + r = p[0]; + g = p[1]; + b = p[2]; + r1 = r; + g1 = g; + b1 = b; + lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + r = p[4]; + g = p[5]; + b = p[6]; + r1 += r; + g1 += g; + b1 += b; + lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + p += wrap4; + lum += wrap; + + r = p[0]; + g = p[1]; + b = p[2]; + r1 += r; + g1 += g; + b1 += b; + lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + r = p[4]; + g = p[5]; + b = p[6]; + r1 += r; + g1 += g; + b1 += b; + lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + + cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + + FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - + FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + + cb++; + cr++; + p += -wrap4 + 2 * 4; + lum += -wrap + 2; + } + p += wrap4; + lum += wrap; + } +} + static void bgr24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, UINT8 *src, int width, int height) { @@ -180,6 +243,69 @@ static void bgr24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, } } +static void bgra32_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, + UINT8 *src, int width, int height) +{ + int wrap, wrap4, x, y; + int r, g, b, r1, g1, b1; + UINT8 *p; + + wrap = width; + wrap4 = width * 4; + p = src; + for(y=0;y<height;y+=2) { + for(x=0;x<width;x+=2) { + b = p[0]; + g = p[1]; + r = p[2]; + r1 = r; + g1 = g; + b1 = b; + lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + b = p[4]; + g = p[5]; + r = p[6]; + r1 += r; + g1 += g; + b1 += b; + lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + p += wrap4; + lum += wrap; + + b = p[0]; + g = p[1]; + r = p[2]; + r1 += r; + g1 += g; + b1 += b; + lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + b = p[4]; + g = p[5]; + r = p[6]; + r1 += r; + g1 += g; + b1 += b; + lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; + + cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + + FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - + FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + + cb++; + cr++; + p += -wrap4 + 2 * 4; + lum += -wrap + 2; + } + p += wrap4; + lum += wrap; + } +} + /* XXX: use generic filter ? */ /* 1x2 -> 1x1 */ static void shrink2(UINT8 *dst, int dst_wrap, @@ -301,6 +427,98 @@ static void img_copy(UINT8 *dst, int dst_wrap, } /* XXX: no chroma interpolating is done */ +static void yuv420p_to_bgra32(AVPicture *dst, AVPicture *src, + int width, int height) +{ + UINT8 *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; + int w, y, cb, cr, r_add, g_add, b_add, width2; + UINT8 *cm = cropTbl + MAX_NEG_CROP; + + d = dst->data[0]; + y1_ptr = src->data[0]; + cb_ptr = src->data[1]; + cr_ptr = src->data[2]; + width2 = width >> 1; + for(;height > 0; height -= 2) { + d1 = d; + d2 = d + dst->linesize[0]; + y2_ptr = y1_ptr + src->linesize[0]; + for(w = width2; w > 0; w --) { + cb = cb_ptr[0] - 128; + cr = cr_ptr[0] - 128; + r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); + g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); + b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); + + /* output 4 pixels */ + RGBOUT(d1[2], d1[1], d1[0], y1_ptr[0]); + RGBOUT(d1[6], d1[5], d1[4], y1_ptr[1]); + RGBOUT(d2[2], d2[1], d2[0], y2_ptr[0]); + RGBOUT(d2[6], d2[5], d2[4], y2_ptr[1]); + + d1[3] = d1[7] = d2[3] = d2[7] = 255; + + d1 += 8; + d2 += 8; + y1_ptr += 2; + y2_ptr += 2; + cb_ptr++; + cr_ptr++; + } + d += 2 * dst->linesize[0]; + y1_ptr += 2 * src->linesize[0] - width; + cb_ptr += src->linesize[1] - width2; + cr_ptr += src->linesize[2] - width2; + } +} + +/* XXX: no chroma interpolating is done */ +static void yuv420p_to_rgba32(AVPicture *dst, AVPicture *src, + int width, int height) +{ + UINT8 *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; + int w, y, cb, cr, r_add, g_add, b_add, width2; + UINT8 *cm = cropTbl + MAX_NEG_CROP; + + d = dst->data[0]; + y1_ptr = src->data[0]; + cb_ptr = src->data[1]; + cr_ptr = src->data[2]; + width2 = width >> 1; + for(;height > 0; height -= 2) { + d1 = d; + d2 = d + dst->linesize[0]; + y2_ptr = y1_ptr + src->linesize[0]; + for(w = width2; w > 0; w --) { + cb = cb_ptr[0] - 128; + cr = cr_ptr[0] - 128; + r_add = C_RV * cr + (1 << (SCALE_BITS - 1)); + g_add = - C_GU * cb - C_GV * cr + (1 << (SCALE_BITS - 1)); + b_add = C_BU * cb + (1 << (SCALE_BITS - 1)); + + /* output 4 pixels */ + RGBOUT(d1[0], d1[1], d1[2], y1_ptr[0]); + RGBOUT(d1[4], d1[5], d1[6], y1_ptr[1]); + RGBOUT(d2[0], d2[1], d2[2], y2_ptr[0]); + RGBOUT(d2[4], d2[5], d2[6], y2_ptr[1]); + + d1[3] = d1[7] = d2[3] = d2[7] = 255; + + d1 += 8; + d2 += 8; + y1_ptr += 2; + y2_ptr += 2; + cb_ptr++; + cr_ptr++; + } + d += 2 * dst->linesize[0]; + y1_ptr += 2 * src->linesize[0] - width; + cb_ptr += src->linesize[1] - width2; + cr_ptr += src->linesize[2] - width2; + } +} + +/* XXX: no chroma interpolating is done */ static void yuv420p_to_rgb24(AVPicture *dst, AVPicture *src, int width, int height) { @@ -460,10 +678,18 @@ int img_convert(AVPicture *dst, int dst_pix_fmt, rgb24_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], src->data[0], width, height); break; + case PIX_FMT_RGBA32: + rgba32_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], + src->data[0], width, height); + break; case PIX_FMT_BGR24: bgr24_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], src->data[0], width, height); break; + case PIX_FMT_BGRA32: + bgra32_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], + src->data[0], width, height); + break; default: return -1; } @@ -478,6 +704,22 @@ int img_convert(AVPicture *dst, int dst_pix_fmt, default: return -1; } + } else if (dst_pix_fmt == PIX_FMT_RGBA32) { + switch(pix_fmt) { + case PIX_FMT_YUV420P: + yuv420p_to_rgba32(dst, src, width, height); + break; + default: + return -1; + } + } else if (dst_pix_fmt == PIX_FMT_BGRA32) { + switch(pix_fmt) { + case PIX_FMT_YUV420P: + yuv420p_to_bgra32(dst, src, width, height); + break; + default: + return -1; + } } else { return -1; } diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 05fd6ab704..943614da65 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -199,6 +199,8 @@ const char *pix_fmt_str[] = { "bgr24", "yuv422p", "yuv444p", + "rgba32", + "bgra32", "yuv410p" }; @@ -299,7 +301,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) } break; default: - abort(); + av_abort(); } if (bitrate != 0) { snprintf(buf + strlen(buf), buf_size - strlen(buf), @@ -346,6 +348,13 @@ void avpicture_fill(AVPicture *picture, UINT8 *ptr, picture->data[2] = NULL; picture->linesize[0] = width * 3; break; + case PIX_FMT_RGBA32: + case PIX_FMT_BGRA32: + picture->data[0] = ptr; + picture->data[1] = NULL; + picture->data[2] = NULL; + picture->linesize[0] = width * 4; + break; case PIX_FMT_YUV422: picture->data[0] = ptr; picture->data[1] = NULL; @@ -379,6 +388,10 @@ int avpicture_get_size(int pix_fmt, int width, int height) case PIX_FMT_BGR24: size = (size * 3); break; + case PIX_FMT_RGBA32: + case PIX_FMT_BGRA32: + size = (size * 4); + break; case PIX_FMT_YUV422: size = (size * 2); break; |