Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
2a7128f4
Commit
2a7128f4
authored
Apr 17, 2015
by
Pedro Arthur
Committed by
Michael Niedermayer
Apr 23, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add gamma encodign/decoding before/after scaling in libswscale
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
d9555adf
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
139 additions
and
1 deletion
+139
-1
options.c
libswscale/options.c
+3
-0
swscale.c
libswscale/swscale.c
+51
-0
swscale.h
libswscale/swscale.h
+1
-0
swscale_internal.h
libswscale/swscale_internal.h
+8
-1
utils.c
libswscale/utils.c
+76
-0
No files found.
libswscale/options.c
View file @
2a7128f4
...
@@ -75,6 +75,9 @@ static const AVOption swscale_options[] = {
...
@@ -75,6 +75,9 @@ static const AVOption swscale_options[] = {
{
"ed"
,
"error diffusion"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
SWS_DITHER_ED
},
INT_MIN
,
INT_MAX
,
VE
,
"sws_dither"
},
{
"ed"
,
"error diffusion"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
SWS_DITHER_ED
},
INT_MIN
,
INT_MAX
,
VE
,
"sws_dither"
},
{
"a_dither"
,
"arithmetic addition dither"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
SWS_DITHER_A_DITHER
},
INT_MIN
,
INT_MAX
,
VE
,
"sws_dither"
},
{
"a_dither"
,
"arithmetic addition dither"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
SWS_DITHER_A_DITHER
},
INT_MIN
,
INT_MAX
,
VE
,
"sws_dither"
},
{
"x_dither"
,
"arithmetic xor dither"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
SWS_DITHER_X_DITHER
},
INT_MIN
,
INT_MAX
,
VE
,
"sws_dither"
},
{
"x_dither"
,
"arithmetic xor dither"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
SWS_DITHER_X_DITHER
},
INT_MIN
,
INT_MAX
,
VE
,
"sws_dither"
},
{
"gamma"
,
"gamma correct scaling"
,
OFFSET
(
gamma_flag
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
VE
,
"gamma"
},
{
"true"
,
"enable"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
1
},
INT_MIN
,
INT_MAX
,
VE
,
"gamma"
},
{
"false"
,
"disable"
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
0
},
INT_MIN
,
INT_MAX
,
VE
,
"gamma"
},
{
NULL
}
{
NULL
}
};
};
...
...
libswscale/swscale.c
View file @
2a7128f4
...
@@ -52,6 +52,22 @@ DECLARE_ALIGNED(8, static const uint8_t, sws_pb_64)[8] = {
...
@@ -52,6 +52,22 @@ DECLARE_ALIGNED(8, static const uint8_t, sws_pb_64)[8] = {
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
};
};
static
void
gamma_convert
(
uint8_t
*
src
[],
int
width
,
uint16_t
*
gamma
)
{
int
i
;
uint16_t
*
src1
=
(
uint16_t
*
)
src
[
0
];
for
(
i
=
0
;
i
<
width
;
++
i
)
{
uint16_t
r
=
AV_RL16
(
src1
+
i
*
4
+
0
);
uint16_t
g
=
AV_RL16
(
src1
+
i
*
4
+
1
);
uint16_t
b
=
AV_RL16
(
src1
+
i
*
4
+
2
);
AV_WL16
(
src1
+
i
*
4
+
0
,
gamma
[
r
]);
AV_WL16
(
src1
+
i
*
4
+
1
,
gamma
[
g
]);
AV_WL16
(
src1
+
i
*
4
+
2
,
gamma
[
b
]);
}
}
static
av_always_inline
void
fillPlane
(
uint8_t
*
plane
,
int
stride
,
int
width
,
static
av_always_inline
void
fillPlane
(
uint8_t
*
plane
,
int
stride
,
int
width
,
int
height
,
int
y
,
uint8_t
val
)
int
height
,
int
y
,
uint8_t
val
)
{
{
...
@@ -353,6 +369,8 @@ static int swscale(SwsContext *c, const uint8_t *src[],
...
@@ -353,6 +369,8 @@ static int swscale(SwsContext *c, const uint8_t *src[],
int
chrBufIndex
=
c
->
chrBufIndex
;
int
chrBufIndex
=
c
->
chrBufIndex
;
int
lastInLumBuf
=
c
->
lastInLumBuf
;
int
lastInLumBuf
=
c
->
lastInLumBuf
;
int
lastInChrBuf
=
c
->
lastInChrBuf
;
int
lastInChrBuf
=
c
->
lastInChrBuf
;
int
perform_gamma
=
c
->
flags
&
SWS_GAMMA_CORRECT
;
if
(
!
usePal
(
c
->
srcFormat
))
{
if
(
!
usePal
(
c
->
srcFormat
))
{
pal
=
c
->
input_rgb2yuv_table
;
pal
=
c
->
input_rgb2yuv_table
;
...
@@ -480,6 +498,10 @@ static int swscale(SwsContext *c, const uint8_t *src[],
...
@@ -480,6 +498,10 @@ static int swscale(SwsContext *c, const uint8_t *src[],
av_assert0
(
lumBufIndex
<
2
*
vLumBufSize
);
av_assert0
(
lumBufIndex
<
2
*
vLumBufSize
);
av_assert0
(
lastInLumBuf
+
1
-
srcSliceY
<
srcSliceH
);
av_assert0
(
lastInLumBuf
+
1
-
srcSliceY
<
srcSliceH
);
av_assert0
(
lastInLumBuf
+
1
-
srcSliceY
>=
0
);
av_assert0
(
lastInLumBuf
+
1
-
srcSliceY
>=
0
);
if
(
perform_gamma
)
gamma_convert
((
uint8_t
**
)
src1
,
srcW
,
c
->
inv_gamma
);
hyscale
(
c
,
lumPixBuf
[
lumBufIndex
],
dstW
,
src1
,
srcW
,
lumXInc
,
hyscale
(
c
,
lumPixBuf
[
lumBufIndex
],
dstW
,
src1
,
srcW
,
lumXInc
,
hLumFilter
,
hLumFilterPos
,
hLumFilterSize
,
hLumFilter
,
hLumFilterPos
,
hLumFilterSize
,
formatConvBuffer
,
pal
,
0
);
formatConvBuffer
,
pal
,
0
);
...
@@ -641,6 +663,8 @@ static int swscale(SwsContext *c, const uint8_t *src[],
...
@@ -641,6 +663,8 @@ static int swscale(SwsContext *c, const uint8_t *src[],
chrUSrcPtr
,
chrVSrcPtr
,
vChrFilterSize
,
chrUSrcPtr
,
chrVSrcPtr
,
vChrFilterSize
,
alpSrcPtr
,
dest
,
dstW
,
dstY
);
alpSrcPtr
,
dest
,
dstW
,
dstY
);
}
}
if
(
perform_gamma
)
gamma_convert
(
dest
,
dstW
,
c
->
gamma
);
}
}
}
}
if
(
isPlanar
(
dstFormat
)
&&
isALPHA
(
dstFormat
)
&&
!
alpPixBuf
)
{
if
(
isPlanar
(
dstFormat
)
&&
isALPHA
(
dstFormat
)
&&
!
alpPixBuf
)
{
...
@@ -900,6 +924,33 @@ int attribute_align_arg sws_scale(struct SwsContext *c,
...
@@ -900,6 +924,33 @@ int attribute_align_arg sws_scale(struct SwsContext *c,
av_log
(
c
,
AV_LOG_ERROR
,
"One of the input parameters to sws_scale() is NULL, please check the calling code
\n
"
);
av_log
(
c
,
AV_LOG_ERROR
,
"One of the input parameters to sws_scale() is NULL, please check the calling code
\n
"
);
return
0
;
return
0
;
}
}
if
(
c
->
gamma_flag
&&
c
->
cascaded_context
[
0
])
{
ret
=
sws_scale
(
c
->
cascaded_context
[
0
],
srcSlice
,
srcStride
,
srcSliceY
,
srcSliceH
,
c
->
cascaded_tmp
,
c
->
cascaded_tmpStride
);
if
(
ret
<
0
)
return
ret
;
if
(
c
->
cascaded_context
[
2
])
ret
=
sws_scale
(
c
->
cascaded_context
[
1
],
(
const
uint8_t
*
const
*
)
c
->
cascaded_tmp
,
c
->
cascaded_tmpStride
,
srcSliceY
,
srcSliceH
,
c
->
cascaded1_tmp
,
c
->
cascaded1_tmpStride
);
else
ret
=
sws_scale
(
c
->
cascaded_context
[
1
],
(
const
uint8_t
*
const
*
)
c
->
cascaded_tmp
,
c
->
cascaded_tmpStride
,
srcSliceY
,
srcSliceH
,
dst
,
dstStride
);
if
(
ret
<
0
)
return
ret
;
if
(
c
->
cascaded_context
[
2
])
{
ret
=
sws_scale
(
c
->
cascaded_context
[
2
],
(
const
uint8_t
*
const
*
)
c
->
cascaded1_tmp
,
c
->
cascaded1_tmpStride
,
c
->
cascaded_context
[
1
]
->
dstY
-
ret
,
c
->
cascaded_context
[
1
]
->
dstY
,
dst
,
dstStride
);
}
return
ret
;
}
if
(
c
->
cascaded_context
[
0
]
&&
srcSliceY
==
0
&&
srcSliceH
==
c
->
cascaded_context
[
0
]
->
srcH
)
{
if
(
c
->
cascaded_context
[
0
]
&&
srcSliceY
==
0
&&
srcSliceH
==
c
->
cascaded_context
[
0
]
->
srcH
)
{
ret
=
sws_scale
(
c
->
cascaded_context
[
0
],
ret
=
sws_scale
(
c
->
cascaded_context
[
0
],
srcSlice
,
srcStride
,
srcSliceY
,
srcSliceH
,
srcSlice
,
srcStride
,
srcSliceY
,
srcSliceH
,
...
...
libswscale/swscale.h
View file @
2a7128f4
...
@@ -64,6 +64,7 @@ const char *swscale_license(void);
...
@@ -64,6 +64,7 @@ const char *swscale_license(void);
#define SWS_SINC 0x100
#define SWS_SINC 0x100
#define SWS_LANCZOS 0x200
#define SWS_LANCZOS 0x200
#define SWS_SPLINE 0x400
#define SWS_SPLINE 0x400
#define SWS_GAMMA_CORRECT 0x800
#define SWS_SRC_V_CHR_DROP_MASK 0x30000
#define SWS_SRC_V_CHR_DROP_MASK 0x30000
#define SWS_SRC_V_CHR_DROP_SHIFT 16
#define SWS_SRC_V_CHR_DROP_SHIFT 16
...
...
libswscale/swscale_internal.h
View file @
2a7128f4
...
@@ -307,9 +307,16 @@ typedef struct SwsContext {
...
@@ -307,9 +307,16 @@ typedef struct SwsContext {
* sequential steps, this is for example used to limit the maximum
* sequential steps, this is for example used to limit the maximum
* downscaling factor that needs to be supported in one scaler.
* downscaling factor that needs to be supported in one scaler.
*/
*/
struct
SwsContext
*
cascaded_context
[
2
];
struct
SwsContext
*
cascaded_context
[
3
];
int
cascaded_tmpStride
[
4
];
int
cascaded_tmpStride
[
4
];
uint8_t
*
cascaded_tmp
[
4
];
uint8_t
*
cascaded_tmp
[
4
];
int
cascaded1_tmpStride
[
4
];
uint8_t
*
cascaded1_tmp
[
4
];
double
gamma_value
;
int
gamma_flag
;
uint16_t
*
gamma
;
uint16_t
*
inv_gamma
;
uint32_t
pal_yuv
[
256
];
uint32_t
pal_yuv
[
256
];
uint32_t
pal_rgb
[
256
];
uint32_t
pal_rgb
[
256
];
...
...
libswscale/utils.c
View file @
2a7128f4
...
@@ -960,6 +960,20 @@ SwsContext *sws_alloc_context(void)
...
@@ -960,6 +960,20 @@ SwsContext *sws_alloc_context(void)
return
c
;
return
c
;
}
}
static
uint16_t
*
alloc_gamma_tbl
(
double
e
)
{
int
i
=
0
;
uint16_t
*
tbl
;
tbl
=
(
uint16_t
*
)
av_malloc
(
sizeof
(
uint16_t
)
*
1
<<
16
);
if
(
!
tbl
)
return
NULL
;
for
(
i
=
0
;
i
<
65536
;
++
i
)
{
tbl
[
i
]
=
pow
(
i
/
65535
.
0
,
e
)
*
65535
.
0
;
}
return
tbl
;
}
av_cold
int
sws_init_context
(
SwsContext
*
c
,
SwsFilter
*
srcFilter
,
av_cold
int
sws_init_context
(
SwsContext
*
c
,
SwsFilter
*
srcFilter
,
SwsFilter
*
dstFilter
)
SwsFilter
*
dstFilter
)
{
{
...
@@ -978,6 +992,7 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
...
@@ -978,6 +992,7 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
const
AVPixFmtDescriptor
*
desc_src
;
const
AVPixFmtDescriptor
*
desc_src
;
const
AVPixFmtDescriptor
*
desc_dst
;
const
AVPixFmtDescriptor
*
desc_dst
;
int
ret
=
0
;
int
ret
=
0
;
enum
AVPixelFormat
tmpFmt
;
cpu_flags
=
av_get_cpu_flags
();
cpu_flags
=
av_get_cpu_flags
();
flags
=
c
->
flags
;
flags
=
c
->
flags
;
...
@@ -1235,6 +1250,61 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
...
@@ -1235,6 +1250,61 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
}
}
}
}
// hardcoded for now
c
->
gamma_value
=
2
.
2
;
tmpFmt
=
AV_PIX_FMT_RGBA64LE
;
if
(
!
unscaled
&&
c
->
gamma_flag
&&
(
srcFormat
!=
tmpFmt
||
dstFormat
!=
tmpFmt
))
{
c
->
cascaded_context
[
0
]
=
NULL
;
ret
=
av_image_alloc
(
c
->
cascaded_tmp
,
c
->
cascaded_tmpStride
,
srcW
,
srcH
,
tmpFmt
,
64
);
if
(
ret
<
0
)
return
ret
;
c
->
cascaded_context
[
0
]
=
sws_getContext
(
srcW
,
srcH
,
srcFormat
,
srcW
,
srcH
,
tmpFmt
,
flags
,
NULL
,
NULL
,
c
->
param
);
if
(
!
c
->
cascaded_context
[
0
])
{
return
-
1
;
}
c
->
cascaded_context
[
1
]
=
sws_getContext
(
srcW
,
srcH
,
tmpFmt
,
dstW
,
dstH
,
tmpFmt
,
flags
|
SWS_GAMMA_CORRECT
,
srcFilter
,
dstFilter
,
c
->
param
);
if
(
!
c
->
cascaded_context
[
1
])
return
-
1
;
c
->
cascaded_context
[
2
]
=
NULL
;
if
(
dstFormat
!=
tmpFmt
)
{
ret
=
av_image_alloc
(
c
->
cascaded1_tmp
,
c
->
cascaded1_tmpStride
,
dstW
,
dstH
,
tmpFmt
,
64
);
if
(
ret
<
0
)
return
ret
;
c
->
cascaded_context
[
2
]
=
sws_getContext
(
dstW
,
dstH
,
tmpFmt
,
dstW
,
dstH
,
dstFormat
,
flags
,
NULL
,
NULL
,
c
->
param
);
if
(
!
c
->
cascaded_context
[
2
])
return
-
1
;
}
return
0
;
}
c
->
gamma
=
NULL
;
c
->
inv_gamma
=
NULL
;
if
(
c
->
flags
&
SWS_GAMMA_CORRECT
)
{
c
->
gamma
=
alloc_gamma_tbl
(
c
->
gamma_value
);
if
(
!
c
->
gamma
)
return
AVERROR
(
ENOMEM
);
c
->
inv_gamma
=
alloc_gamma_tbl
(
1
.
f
/
c
->
gamma_value
);
if
(
!
c
->
inv_gamma
)
{
return
AVERROR
(
ENOMEM
);
}
}
if
(
isBayer
(
srcFormat
))
{
if
(
isBayer
(
srcFormat
))
{
if
(
!
unscaled
||
if
(
!
unscaled
||
(
dstFormat
!=
AV_PIX_FMT_RGB24
&&
dstFormat
!=
AV_PIX_FMT_YUV420P
))
{
(
dstFormat
!=
AV_PIX_FMT_RGB24
&&
dstFormat
!=
AV_PIX_FMT_YUV420P
))
{
...
@@ -1977,8 +2047,14 @@ void sws_freeContext(SwsContext *c)
...
@@ -1977,8 +2047,14 @@ void sws_freeContext(SwsContext *c)
sws_freeContext
(
c
->
cascaded_context
[
0
]);
sws_freeContext
(
c
->
cascaded_context
[
0
]);
sws_freeContext
(
c
->
cascaded_context
[
1
]);
sws_freeContext
(
c
->
cascaded_context
[
1
]);
sws_freeContext
(
c
->
cascaded_context
[
2
]);
memset
(
c
->
cascaded_context
,
0
,
sizeof
(
c
->
cascaded_context
));
memset
(
c
->
cascaded_context
,
0
,
sizeof
(
c
->
cascaded_context
));
av_freep
(
&
c
->
cascaded_tmp
[
0
]);
av_freep
(
&
c
->
cascaded_tmp
[
0
]);
av_freep
(
&
c
->
cascaded1_tmp
[
0
]);
av_freep
(
&
c
->
gamma
);
av_freep
(
&
c
->
inv_gamma
);
av_free
(
c
);
av_free
(
c
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment