Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
b71472eb
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b71472eb
编写于
7月 27, 2002
作者:
P
Philip Gladstone
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add conversions to and from RGBA32 and BGRA32.
Originally committed as revision 824 to
svn://svn.ffmpeg.org/ffmpeg/trunk
上级
64e105e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
258 addition
and
1 deletion
+258
-1
libavcodec/avcodec.h
libavcodec/avcodec.h
+2
-0
libavcodec/imgconvert.c
libavcodec/imgconvert.c
+242
-0
libavcodec/utils.c
libavcodec/utils.c
+14
-1
未找到文件。
libavcodec/avcodec.h
浏览文件 @
b71472eb
...
...
@@ -59,6 +59,8 @@ enum PixelFormat {
PIX_FMT_BGR24
,
PIX_FMT_YUV422P
,
PIX_FMT_YUV444P
,
PIX_FMT_RGBA32
,
PIX_FMT_BGRA32
,
PIX_FMT_YUV410P
};
...
...
libavcodec/imgconvert.c
浏览文件 @
b71472eb
...
...
@@ -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
,
...
...
@@ -300,6 +426,98 @@ static void img_copy(UINT8 *dst, int dst_wrap,
b = cm[(y + b_add) >> SCALE_BITS];\
}
/* 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
;
}
...
...
libavcodec/utils.c
浏览文件 @
b71472eb
...
...
@@ -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
();
a
v_a
bort
();
}
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
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录