diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | image_writer.c | 2 | ||||
-rw-r--r-- | libmpcodecs/sws_utils.c | 134 | ||||
-rw-r--r-- | libmpcodecs/sws_utils.h | 27 | ||||
-rw-r--r-- | libmpcodecs/vf_scale.c | 83 | ||||
-rw-r--r-- | libmpcodecs/vf_scale.h | 28 | ||||
-rw-r--r-- | libmpcodecs/vf_screenshot.c | 2 | ||||
-rw-r--r-- | libvo/vo_x11.c | 3 |
8 files changed, 166 insertions, 114 deletions
@@ -144,6 +144,7 @@ SRCS_COMMON = asxparser.c \ libmpcodecs/img_format.c \ libmpcodecs/mp_image.c \ libmpcodecs/pullup.c \ + libmpcodecs/sws_utils.c \ libmpcodecs/vd.c \ libmpcodecs/vd_ffmpeg.c \ libmpcodecs/vf.c \ diff --git a/image_writer.c b/image_writer.c index ded114f140..f4851a9176 100644 --- a/image_writer.c +++ b/image_writer.c @@ -40,7 +40,7 @@ #include "fmt-conversion.h" //for sws_getContextFromCmdLine_hq and mp_sws_set_colorspace -#include "libmpcodecs/vf_scale.h" +#include "libmpcodecs/sws_utils.h" #include "libvo/csputils.h" #include "m_option.h" diff --git a/libmpcodecs/sws_utils.c b/libmpcodecs/sws_utils.c new file mode 100644 index 0000000000..438db4a13a --- /dev/null +++ b/libmpcodecs/sws_utils.c @@ -0,0 +1,134 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <assert.h> + +#include "libmpcodecs/sws_utils.h" + +#include "libmpcodecs/mp_image.h" +#include "libmpcodecs/img_format.h" +#include "fmt-conversion.h" +#include "libvo/csputils.h" +#include "mp_msg.h" + +//global sws_flags from the command line +int sws_flags = 2; + +float sws_lum_gblur = 0.0; +float sws_chr_gblur = 0.0; +int sws_chr_vshift = 0; +int sws_chr_hshift = 0; +float sws_chr_sharpen = 0.0; +float sws_lum_sharpen = 0.0; + +//global srcFilter +static SwsFilter *src_filter = NULL; + +void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, + SwsFilter **dstFilterParam) +{ + static int firstTime = 1; + *flags = 0; + + if (firstTime) { + firstTime = 0; + *flags = SWS_PRINT_INFO; + } else if (mp_msg_test(MSGT_VFILTER, MSGL_DBG2)) + *flags = SWS_PRINT_INFO; + + if (src_filter) + sws_freeFilter(src_filter); + + src_filter = sws_getDefaultFilter( + sws_lum_gblur, sws_chr_gblur, + sws_lum_sharpen, sws_chr_sharpen, + sws_chr_hshift, sws_chr_vshift, verbose > 1); + + switch (sws_flags) { + case 0: *flags |= SWS_FAST_BILINEAR; + break; + case 1: *flags |= SWS_BILINEAR; + break; + case 2: *flags |= SWS_BICUBIC; + break; + case 3: *flags |= SWS_X; + break; + case 4: *flags |= SWS_POINT; + break; + case 5: *flags |= SWS_AREA; + break; + case 6: *flags |= SWS_BICUBLIN; + break; + case 7: *flags |= SWS_GAUSS; + break; + case 8: *flags |= SWS_SINC; + break; + case 9: *flags |= SWS_LANCZOS; + break; + case 10: *flags |= SWS_SPLINE; + break; + default: *flags |= SWS_BILINEAR; + break; + } + + *srcFilterParam = src_filter; + *dstFilterParam = NULL; +} + +// will use sws_flags & src_filter (from cmd line) +static struct SwsContext *sws_getContextFromCmdLine2(int srcW, int srcH, + int srcFormat, int dstW, + int dstH, int dstFormat, + int extraflags) +{ + int flags; + SwsFilter *dstFilterParam, *srcFilterParam; + enum PixelFormat dfmt, sfmt; + + dfmt = imgfmt2pixfmt(dstFormat); + sfmt = imgfmt2pixfmt(srcFormat); + if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) + sfmt = PIX_FMT_PAL8; + sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam); + + return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | + extraflags, srcFilterParam, dstFilterParam, + NULL); +} + +struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, + int dstW, int dstH, + int dstFormat) +{ + return sws_getContextFromCmdLine2(srcW, srcH, srcFormat, dstW, dstH, + dstFormat, + 0); +} + +struct SwsContext *sws_getContextFromCmdLine_hq(int srcW, int srcH, + int srcFormat, int dstW, + int dstH, + int dstFormat) +{ + return sws_getContextFromCmdLine2( + srcW, srcH, srcFormat, dstW, dstH, dstFormat, + SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP | + SWS_ACCURATE_RND | SWS_BITEXACT); +} + +// vim: ts=4 sw=4 et tw=80 diff --git a/libmpcodecs/sws_utils.h b/libmpcodecs/sws_utils.h new file mode 100644 index 0000000000..a8dc970d08 --- /dev/null +++ b/libmpcodecs/sws_utils.h @@ -0,0 +1,27 @@ +#ifndef MPLAYER_SWS_UTILS_H +#define MPLAYER_SWS_UTILS_H + +#include <libswscale/swscale.h> + +struct mp_image; +struct mp_csp_details; + +// libswscale currently requires 16 bytes alignment for row pointers and +// strides. Otherwise, it will print warnings and use slow codepaths. +// Guaranteed to be a power of 2 and > 1. +#define SWS_MIN_BYTE_ALIGN 16 + +void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, + SwsFilter **dstFilterParam); +struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, + int dstW, int dstH, + int dstFormat); +struct SwsContext *sws_getContextFromCmdLine_hq(int srcW, int srcH, + int srcFormat, int dstW, + int dstH, + int dstFormat); +int mp_sws_set_colorspace(struct SwsContext *sws, struct mp_csp_details *csp); + +#endif /* MP_SWS_UTILS_H */ + +// vim: ts=4 sw=4 et tw=80 diff --git a/libmpcodecs/vf_scale.c b/libmpcodecs/vf_scale.c index 71428685ac..5ea62bacbd 100644 --- a/libmpcodecs/vf_scale.c +++ b/libmpcodecs/vf_scale.c @@ -32,8 +32,7 @@ #include "fmt-conversion.h" #include "mpbswap.h" -#include "libswscale/swscale.h" -#include "vf_scale.h" +#include "libmpcodecs/sws_utils.h" #include "libvo/csputils.h" // VOFLAG_SWSCALE @@ -68,8 +67,6 @@ static struct vf_priv_s { //===========================================================================// -void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam); - static const unsigned int outfmt_list[]={ // YUV: IMGFMT_444P, @@ -647,84 +644,6 @@ static int vf_open(vf_instance_t *vf, char *args){ return 1; } -//global sws_flags from the command line -int sws_flags=2; - -//global srcFilter -static SwsFilter *src_filter= NULL; - -float sws_lum_gblur= 0.0; -float sws_chr_gblur= 0.0; -int sws_chr_vshift= 0; -int sws_chr_hshift= 0; -float sws_chr_sharpen= 0.0; -float sws_lum_sharpen= 0.0; - -void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam) -{ - static int firstTime=1; - *flags=0; - - if(firstTime) - { - firstTime=0; - *flags= SWS_PRINT_INFO; - } - else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO; - - if(src_filter) sws_freeFilter(src_filter); - - src_filter= sws_getDefaultFilter( - sws_lum_gblur, sws_chr_gblur, - sws_lum_sharpen, sws_chr_sharpen, - sws_chr_hshift, sws_chr_vshift, verbose>1); - - switch(sws_flags) - { - case 0: *flags|= SWS_FAST_BILINEAR; break; - case 1: *flags|= SWS_BILINEAR; break; - case 2: *flags|= SWS_BICUBIC; break; - case 3: *flags|= SWS_X; break; - case 4: *flags|= SWS_POINT; break; - case 5: *flags|= SWS_AREA; break; - case 6: *flags|= SWS_BICUBLIN; break; - case 7: *flags|= SWS_GAUSS; break; - case 8: *flags|= SWS_SINC; break; - case 9: *flags|= SWS_LANCZOS; break; - case 10:*flags|= SWS_SPLINE; break; - default:*flags|= SWS_BILINEAR; break; - } - - *srcFilterParam= src_filter; - *dstFilterParam= NULL; -} - -// will use sws_flags & src_filter (from cmd line) -static struct SwsContext *sws_getContextFromCmdLine2(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int extraflags) -{ - int flags; - SwsFilter *dstFilterParam, *srcFilterParam; - enum PixelFormat dfmt, sfmt; - - dfmt = imgfmt2pixfmt(dstFormat); - sfmt = imgfmt2pixfmt(srcFormat); - if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8; - sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam); - - return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | extraflags, srcFilterParam, dstFilterParam, NULL); -} - -struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat) -{ - return sws_getContextFromCmdLine2(srcW, srcH, srcFormat, dstW, dstH, dstFormat, 0); -} - -struct SwsContext *sws_getContextFromCmdLine_hq(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat) -{ - return sws_getContextFromCmdLine2(srcW, srcH, srcFormat, dstW, dstH, dstFormat, - SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND | SWS_BITEXACT); -} - /// An example of presets usage static const struct size_preset { char* name; diff --git a/libmpcodecs/vf_scale.h b/libmpcodecs/vf_scale.h deleted file mode 100644 index 575d4f3640..0000000000 --- a/libmpcodecs/vf_scale.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_VF_SCALE_H -#define MPLAYER_VF_SCALE_H - -struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat); -struct SwsContext *sws_getContextFromCmdLine_hq(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat); - -struct mp_csp_details; -int mp_sws_set_colorspace(struct SwsContext *sws, struct mp_csp_details *csp); - -#endif /* MPLAYER_VF_SCALE_H */ diff --git a/libmpcodecs/vf_screenshot.c b/libmpcodecs/vf_screenshot.c index eb961d8118..013525694a 100644 --- a/libmpcodecs/vf_screenshot.c +++ b/libmpcodecs/vf_screenshot.c @@ -27,7 +27,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vf_scale.h" +#include "libmpcodecs/sws_utils.h" #include "fmt-conversion.h" #include "libvo/fastmemcpy.h" diff --git a/libvo/vo_x11.c b/libvo/vo_x11.c index 8090821fa8..d43601f7c2 100644 --- a/libvo/vo_x11.c +++ b/libvo/vo_x11.c @@ -43,8 +43,7 @@ #include "sub/sub.h" -#include "libswscale/swscale.h" -#include "libmpcodecs/vf_scale.h" +#include "libmpcodecs/sws_utils.h" #define MODE_RGB 0x1 #define MODE_BGR 0x2 |