From f7813a5324be39d13ab536c245d15dfc602a7849 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 29 Dec 2013 12:19:38 +0000 Subject: basic type mechanism working --- ffmpeg/libavfilter/drawutils.c | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'ffmpeg/libavfilter/drawutils.c') diff --git a/ffmpeg/libavfilter/drawutils.c b/ffmpeg/libavfilter/drawutils.c index aebc000..a5064f8 100644 --- a/ffmpeg/libavfilter/drawutils.c +++ b/ffmpeg/libavfilter/drawutils.c @@ -37,12 +37,22 @@ int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt) case AV_PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break; case AV_PIX_FMT_0BGR: case AV_PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break; + case AV_PIX_FMT_RGB48LE: + case AV_PIX_FMT_RGB48BE: + case AV_PIX_FMT_RGBA64BE: + case AV_PIX_FMT_RGBA64LE: case AV_PIX_FMT_RGB0: case AV_PIX_FMT_RGBA: case AV_PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break; + case AV_PIX_FMT_BGR48LE: + case AV_PIX_FMT_BGR48BE: + case AV_PIX_FMT_BGRA64BE: + case AV_PIX_FMT_BGRA64LE: case AV_PIX_FMT_BGRA: case AV_PIX_FMT_BGR0: case AV_PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break; + case AV_PIX_FMT_GBRAP: + case AV_PIX_FMT_GBRP: rgba_map[GREEN] = 0; rgba_map[BLUE ] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break; default: /* unsupported */ return AVERROR(EINVAL); } @@ -83,7 +93,7 @@ int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t int hsub1 = (plane == 1 || plane == 2) ? hsub : 0; pixel_step[plane] = 1; - line_size = (w >> hsub1) * pixel_step[plane]; + line_size = FF_CEIL_RSHIFT(w, hsub1) * pixel_step[plane]; line[plane] = av_malloc(line_size); memset(line[plane], dst_color[plane], line_size); } @@ -102,11 +112,13 @@ void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4], for (plane = 0; plane < 4 && dst[plane]; plane++) { int hsub1 = plane == 1 || plane == 2 ? hsub : 0; int vsub1 = plane == 1 || plane == 2 ? vsub : 0; + int width = FF_CEIL_RSHIFT(w, hsub1); + int height = FF_CEIL_RSHIFT(h, vsub1); p = dst[plane] + (y >> vsub1) * dst_linesize[plane]; - for (i = 0; i < (h >> vsub1); i++) { + for (i = 0; i < height; i++) { memcpy(p + (x >> hsub1) * pixelstep[plane], - src[plane], (w >> hsub1) * pixelstep[plane]); + src[plane], width * pixelstep[plane]); p += dst_linesize[plane]; } } @@ -122,11 +134,13 @@ void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4], for (plane = 0; plane < 4 && dst[plane]; plane++) { int hsub1 = plane == 1 || plane == 2 ? hsub : 0; int vsub1 = plane == 1 || plane == 2 ? vsub : 0; + int width = FF_CEIL_RSHIFT(w, hsub1); + int height = FF_CEIL_RSHIFT(h, vsub1); p = dst[plane] + (y >> vsub1) * dst_linesize[plane]; - for (i = 0; i < (h >> vsub1); i++) { + for (i = 0; i < height; i++) { memcpy(p + (x >> hsub1) * pixelstep[plane], - src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), (w >> hsub1) * pixelstep[plane]); + src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]); p += dst_linesize[plane]; } } @@ -141,7 +155,7 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags) if (!desc->name) return AVERROR(EINVAL); - if (desc->flags & ~(PIX_FMT_PLANAR | PIX_FMT_RGB | PIX_FMT_PSEUDOPAL | PIX_FMT_ALPHA)) + if (desc->flags & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA)) return AVERROR(ENOSYS); for (i = 0; i < desc->nb_components; i++) { c = &desc->comp[i]; @@ -166,10 +180,8 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags) draw->format = format; draw->nb_planes = nb_planes; memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep)); - if (nb_planes >= 3 && !(desc->flags & PIX_FMT_RGB)) { - draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w; - draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h; - } + draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w; + draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h; for (i = 0; i < ((desc->nb_components - 1) | 1); i++) draw->comp_mask[desc->comp[i].plane] |= 1 << (desc->comp[i].offset_plus1 - 1); @@ -183,10 +195,15 @@ void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4 if (rgba != color->rgba) memcpy(color->rgba, rgba, sizeof(color->rgba)); - if ((draw->desc->flags & PIX_FMT_RGB) && draw->nb_planes == 1 && + if ((draw->desc->flags & AV_PIX_FMT_FLAG_RGB) && ff_fill_rgba_map(rgba_map, draw->format) >= 0) { + if (draw->nb_planes == 1) { for (i = 0; i < 4; i++) color->comp[0].u8[rgba_map[i]] = rgba[i]; + } else { + for (i = 0; i < 4; i++) + color->comp[rgba_map[i]].u8[0] = rgba[i]; + } } else if (draw->nb_planes == 3 || draw->nb_planes == 4) { /* assume YUV */ color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); @@ -223,8 +240,8 @@ void ff_copy_rectangle2(FFDrawContext *draw, for (plane = 0; plane < draw->nb_planes; plane++) { p = pointer_at(draw, src, src_linesize, plane, src_x, src_y); q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y); - wp = (w >> draw->hsub[plane]) * draw->pixelstep[plane]; - hp = (h >> draw->vsub[plane]); + wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane]; + hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]); for (y = 0; y < hp; y++) { memcpy(q, p, wp); p += src_linesize[plane]; @@ -242,8 +259,8 @@ void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, for (plane = 0; plane < draw->nb_planes; plane++) { p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y); - wp = (w >> draw->hsub[plane]); - hp = (h >> draw->vsub[plane]); + wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]); + hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]); if (!hp) return; p = p0; -- cgit v1.2.3