OSDN Git Service

Merge remote-tracking branch 'qatar/master' into master
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 29 May 2011 00:55:19 +0000 (02:55 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 29 May 2011 01:34:35 +0000 (03:34 +0200)
* qatar/master: (27 commits)
  ac3enc: fix LOCAL_ALIGNED usage in count_mantissa_bits()
  ac3dsp: do not use the ff_* prefix when referencing ff_ac3_bap_bits.
  ac3dsp: fix loop condition in ac3_update_bap_counts_c()
  ARM: unbreak build
  ac3enc: modify mantissa bit counting to keep bap counts for all values of bap instead of just 0 to 4.
  ac3enc: split mantissa bit counting into a separate function.
  ac3enc: store per-block/channel bap pointers by reference block in a 2D array rather than in the AC3Block struct.
  get_bits: add av_unused tag to cache variable
  sws: replace all long with int.
  ARM: aacdec: fix constraints on inline asm
  ARM: remove unnecessary volatile from inline asm
  ARM: add "cc" clobbers to inline asm where needed
  ARM: improve FASTDIV asm
  ac3enc: use LOCAL_ALIGNED macro
  APIchanges: fill in git hash for av_get_pix_fmt_name (0420bd7).
  lavu: add av_get_pix_fmt_name() convenience function
  cmdutils: remove OPT_FUNC2
  swscale: fix crash in bilinear scaling.
  vpxenc: add VP8E_SET_STATIC_THRESHOLD mapping
  webm: support stereo videos in matroska/webm muxer
  ...

Conflicts:
Changelog
cmdutils.c
cmdutils.h
doc/APIchanges
doc/muxers.texi
ffmpeg.c
ffplay.c
libavcodec/ac3enc.c
libavcodec/ac3enc_float.c
libavcodec/avcodec.h
libavcodec/get_bits.h
libavcodec/libvpxenc.c
libavcodec/version.h
libavdevice/libdc1394.c
libavformat/matroskaenc.c
libavutil/avutil.h
libswscale/rgb2rgb.c
libswscale/swscale.c
libswscale/swscale_template.c
libswscale/x86/swscale_template.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
42 files changed:
1  2 
Changelog
configure
doc/APIchanges
doc/general.texi
ffmpeg.c
libavcodec/Makefile
libavcodec/ac3dsp.c
libavcodec/ac3dsp.h
libavcodec/ac3enc.c
libavcodec/ac3enc_combined.c
libavcodec/ac3enc_float.c
libavcodec/allcodecs.c
libavcodec/arm/aac.h
libavcodec/arm/ac3dsp_init_arm.c
libavcodec/arm/mathops.h
libavcodec/arm/vp56_arith.h
libavcodec/x86/ac3dsp.asm
libavcodec/x86/ac3dsp_mmx.c
libavdevice/libdc1394.c
libavdevice/v4l2.c
libavformat/avformat.h
libavformat/matroska.h
libavformat/rawdec.c
libavformat/rawdec.h
libavutil/arm/intmath.h
libavutil/pixdesc.h
libswscale/bfin/internal_bfin.S
libswscale/bfin/swscale_bfin.c
libswscale/colorspace-test.c
libswscale/ppc/swscale_altivec_template.c
libswscale/ppc/swscale_template.c
libswscale/ppc/yuv2rgb_altivec.c
libswscale/rgb2rgb.c
libswscale/rgb2rgb.h
libswscale/rgb2rgb_template.c
libswscale/swscale.c
libswscale/swscale.h
libswscale/swscale_internal.h
libswscale/swscale_template.c
libswscale/utils.c
libswscale/x86/rgb2rgb_template.c
libswscale/x86/swscale_template.c

diff --cc Changelog
+++ b/Changelog
@@@ -4,22 -4,17 +4,23 @@@ releases are sorted from youngest to ol
  
  version <next>:
  
 -
 -
 -version 0.7_beta2:
 -
 +- many many things we forgot because we rather write code than changelogs
 +- libmpcodecs video filter support (3 times as many filters than before)
 +- mpeg2 aspect ratio dection fixed
 +- libxvid aspect pickiness fixed
 +- Frame multithreaded decoding
+ - E-AC-3 audio encoder
  - Lots of deprecated API cruft removed
  - fft and imdct optimizations for AVX (Sandy Bridge) processors
 +- showinfo filter added
  - DPX image encoder
  - SMPTE 302M AES3 audio decoder
 -- Remove support for quitting ffmpeg with 'q', ctrl+c should be used.
 -- 9bit and 10bit per sample support in the h264 decoder
 +- Apple Core Audio Format muxer
 +- 9bit and 10bit H.264 decoding
 +- 9bit and 10bit FFV1 encoding / decoding
 +- split filter added
 +- select filter added
 +- sdl output device added
  
  
  version 0.7_beta1:
diff --cc configure
Simple merge
diff --cc doc/APIchanges
@@@ -13,23 -13,10 +13,27 @@@ libavutil:   2011-04-1
  
  API changes, most recent first:
  
 +2011-05-28 - xxxxxx - lavu 51.3.0 - pixdesc.h
 +  Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate
 +  avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor.
 +
 +2011-05-22 - xxxxxx - lavf 53.2.0 - avformat.h
 +  Introduce avformat_alloc_output_context2() and deprecate
 +  avformat_alloc_output_context().
 +
 +2011-05-22 - xxxxxx - lavfi 2.10.0 - vsrc_buffer.h
 +  Make libavfilter/vsrc_buffer.h public.
 +
 +2011-05-XX - XXXXXX - lavfi 2.8.0 - avcodec.h
 +  Add av_vsrc_buffer_add_frame() to libavfilter/avcodec.h.
 +
 +2011-05-XX - XXXXXX - lavfi 2.6.0 - avcodec.h
 +  Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h.
 +
+ 2011-05-28 - 0420bd7 - lavu 51.2.0 - pixdesc.h
+   Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate
+   avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor.
  2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h
    Add fps_probe_size to AVFormatContext.
  
Simple merge
diff --cc ffmpeg.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 3d6b3d9,0000000..db832f1
mode 100644,000000..100644
--- /dev/null
@@@ -1,90 -1,0 +1,100 @@@
-                                 ff_ac3_options, LIBAVUTIL_VERSION_INT };
 +
 +#include "libavutil/opt.h"
 +#include "libavutil/samplefmt.h"
 +#include "avcodec.h"
 +#include "ac3.h"
 +
 +typedef struct CombineContext{
 +    AVClass *av_class;                      ///< AVClass used for AVOption
 +    AC3EncOptions options;                  ///< encoding options
 +    void *ctx;
 +    AVCodec *codec;
 +}CombineContext;
 +
++#define OFFSET(param) offsetof(CombineContext, options.param)
++#define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
++
++#define AC3ENC_TYPE_AC3_FIXED   0
++#define AC3ENC_TYPE_AC3         1
++#define AC3ENC_TYPE_EAC3        2
++
++#define AC3ENC_TYPE 12354
++#include "ac3enc_opts_template.c"
++
 +static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
++                                eac3_options, LIBAVUTIL_VERSION_INT };
 +
 +static av_cold AVCodec *get_codec(enum AVSampleFormat s){
 +#if CONFIG_AC3_FIXED_ENCODER
 +    if(s==AV_SAMPLE_FMT_S16) return &ff_ac3_fixed_encoder;
 +#endif
 +#if CONFIG_AC3_FLOAT_ENCODER
 +    if(s==AV_SAMPLE_FMT_FLT) return &ff_ac3_float_encoder;
 +#endif
 +    return NULL;
 +}
 +
 +
 +static av_cold int encode_init(AVCodecContext *avctx)
 +{
 +    CombineContext *c= avctx->priv_data;
 +    int ret;
 +    int offset= (uint8_t*)&c->options - (uint8_t*)c;
 +
 +    c->codec= get_codec(avctx->sample_fmt);
 +    if(!c->codec){
 +        av_log(avctx, AV_LOG_ERROR, "Unsupported sample format\n");
 +        return -1;
 +    }
 +    c->ctx= av_mallocz(c->codec->priv_data_size);
 +    memcpy((uint8_t*)c->ctx + offset, &c->options, (uint8_t*)&c->ctx - (uint8_t*)&c->options);
 +    FFSWAP(void *,avctx->priv_data, c->ctx);
 +    ret= c->codec->init(avctx);
 +    FFSWAP(void *,avctx->priv_data, c->ctx);
 +    return ret;
 +}
 +
 +static int encode_frame(AVCodecContext *avctx, unsigned char *frame,
 +                        int buf_size, void *data)
 +{
 +    CombineContext *c= avctx->priv_data;
 +    int ret;
 +
 +    FFSWAP(void *,avctx->priv_data, c->ctx);
 +    ret= c->codec->encode(avctx, frame, buf_size, data);
 +    FFSWAP(void *,avctx->priv_data, c->ctx);
 +    return ret;
 +}
 +
 +static av_cold int encode_close(AVCodecContext *avctx)
 +{
 +    CombineContext *c= avctx->priv_data;
 +    int ret;
 +
 +    FFSWAP(void *,avctx->priv_data, c->ctx);
 +    ret= c->codec->close(avctx);
 +    FFSWAP(void *,avctx->priv_data, c->ctx);
 +    return ret;
 +}
 +
 +AVCodec ff_ac3_encoder = {
 +    "ac3",
 +    AVMEDIA_TYPE_AUDIO,
 +    CODEC_ID_AC3,
 +    sizeof(CombineContext),
 +    encode_init,
 +    encode_frame,
 +    encode_close,
 +    NULL,
 +    .sample_fmts = (const enum AVSampleFormat[]){
 +#if CONFIG_AC3_FLOAT_ENCODER
 +        AV_SAMPLE_FMT_FLT,
 +#endif
 +#if CONFIG_AC3_FIXED_ENCODER
 +        AV_SAMPLE_FMT_S16,
 +#endif
 +        AV_SAMPLE_FMT_NONE},
 +    .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
 +    .priv_class = &ac3enc_class,
 +    .channel_layouts = ff_ac3_channel_layouts,
 +};
@@@ -100,8 -100,9 +100,9 @@@ static void scale_coefficients(AC3Encod
  }
  
  
 -AVCodec ff_ac3_encoder = {
 -    "ac3",
+ #if CONFIG_AC3_ENCODER
 +AVCodec ff_ac3_float_encoder = {
 +    "ac3_float",
      AVMEDIA_TYPE_AUDIO,
      CODEC_ID_AC3,
      sizeof(AC3EncodeContext),
      .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
      .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
      .priv_class = &ac3enc_class,
 -    .channel_layouts = ac3_channel_layouts,
 +    .channel_layouts = ff_ac3_channel_layouts,
  };
 -    .channel_layouts = ac3_channel_layouts,
+ #endif
+ #if CONFIG_EAC3_ENCODER
+ AVCodec ff_eac3_encoder = {
+     .name            = "eac3",
+     .type            = AVMEDIA_TYPE_AUDIO,
+     .id              = CODEC_ID_EAC3,
+     .priv_data_size  = sizeof(AC3EncodeContext),
+     .init            = ac3_encode_init,
+     .encode          = ac3_encode_frame,
+     .close           = ac3_encode_close,
+     .sample_fmts     = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
+     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
+     .priv_class      = &eac3enc_class,
++    .channel_layouts = ff_ac3_channel_layouts,
+ };
+ #endif
@@@ -251,9 -239,9 +251,9 @@@ void avcodec_register_all(void
      REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct);
      REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft);
      REGISTER_DECODER (COOK, cook);
 -    REGISTER_DECODER (DCA, dca);
 +    REGISTER_ENCDEC  (DCA, dca);
      REGISTER_DECODER (DSICINAUDIO, dsicinaudio);
-     REGISTER_DECODER (EAC3, eac3);
+     REGISTER_ENCDEC  (EAC3, eac3);
      REGISTER_ENCDEC  (FLAC, flac);
      REGISTER_DECODER (GSM, gsm);
      REGISTER_DECODER (GSM_MS, gsm_ms);
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
   */
  
  #include "config.h"
 -#include "libavformat/avformat.h"
  #include "libavutil/log.h"
  #include "libavutil/opt.h"
 +#include "avdevice.h"
 +
 +#include <stdlib.h>
 +#include <string.h>
  #include "libavutil/parseutils.h"
+ #include "libavutil/pixdesc.h"
  
 -#if HAVE_LIBDC1394_2
  #include <dc1394/dc1394.h>
 -#elif HAVE_LIBDC1394_1
 -#include <libraw1394/raw1394.h>
 -#include <libdc1394/dc1394_control.h>
 -
 -#define DC1394_VIDEO_MODE_320x240_YUV422 MODE_320x240_YUV422
 -#define DC1394_VIDEO_MODE_640x480_YUV411 MODE_640x480_YUV411
 -#define DC1394_VIDEO_MODE_640x480_YUV422 MODE_640x480_YUV422
 -#define DC1394_FRAMERATE_1_875 FRAMERATE_1_875
 -#define DC1394_FRAMERATE_3_75  FRAMERATE_3_75
 -#define DC1394_FRAMERATE_7_5   FRAMERATE_7_5
 -#define DC1394_FRAMERATE_15    FRAMERATE_15
 -#define DC1394_FRAMERATE_30    FRAMERATE_30
 -#define DC1394_FRAMERATE_60    FRAMERATE_60
 -#define DC1394_FRAMERATE_120   FRAMERATE_120
 -#define DC1394_FRAMERATE_240   FRAMERATE_240
 -#endif
  
  #undef free
  
@@@ -81,7 -97,11 +83,8 @@@ struct dc1394_frame_rate 
  #define OFFSET(x) offsetof(dc1394_data, x)
  #define DEC AV_OPT_FLAG_DECODING_PARAM
  static const AVOption options[] = {
 -#if HAVE_LIBDC1394_1
 -    { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
 -#endif
      { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
+     { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC },
      { NULL },
  };
  
@@@ -118,124 -131,32 +121,132 @@@ static int dc1394_read_header(AVFormatC
          goto out;
      }
  
 -    if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) {
 -        av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n");
 -        goto out;
 +    /* FIXME: To select a specific camera I need to search in list its guid */
 +    dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid);
 +    if (list->num > 1) {
 +        av_log(c, AV_LOG_INFO, "Working with the first camera found\n");
      }
 -#if FF_API_FORMAT_PARAMETERS
 -    if (ap->width > 0)
 -        width = ap->width;
 -    if (ap->height > 0)
 -        height = ap->height;
 -    if (ap->pix_fmt)
 -        pix_fmt = ap->pix_fmt;
 -#endif
 -
 -    for (fmt = dc1394_frame_formats; fmt->width; fmt++)
 -         if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height)
 -             break;
 -
 -    for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
 -         if (fps->frame_rate == frame_rate)
 -             break;
 -
 -    if (!fps->frame_rate || !fmt->width) {
 -        av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", avcodec_get_pix_fmt_name(pix_fmt),
 -                                                                                                width, height, frame_rate);
 -        ret = AVERROR(EINVAL);
 -        goto out;
 +
 +    /* Freeing list of cameras */
 +    dc1394_camera_free_list (list);
 +
 +    /* Get the list of video modes supported by the camera. */
 +    res = dc1394_video_get_supported_modes (dc1394->camera, &video_modes);
 +    if (res != DC1394_SUCCESS) {
 +        av_log(c, AV_LOG_ERROR, "Could not get video formats.\n");
 +        goto out_camera;
 +    }
 +
++    if (dc1394->pixel_format) {
++        if ((ap->pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) {
++            av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format);
++            ret = AVERROR(EINVAL);
++            goto out;
++        }
++    }
++
 +    if (dc1394->video_size) {
 +        if ((ret = av_parse_video_size(&ap->width, &ap->height, dc1394->video_size)) < 0) {
 +            av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n");
 +            goto out;
 +        }
 +    }
 +    
 +    /* Choose the best mode. */
 +    rate = (ap->time_base.num ? av_rescale(1000, ap->time_base.den, ap->time_base.num) : -1);
 +    max_score = -1;
 +    for (i = 0; i < video_modes.num; i++) {
 +        if (video_modes.modes[i] == DC1394_VIDEO_MODE_EXIF
 +                || (video_modes.modes[i] >= DC1394_VIDEO_MODE_FORMAT7_MIN
 +                    && video_modes.modes[i] <= DC1394_VIDEO_MODE_FORMAT7_MAX)) {
 +            /* These modes are currently not supported as they would require
 +             * much more work. For the remaining modes, the functions
 +             * dc1394_get_image_size_from_video_mode and
 +             * dc1394_get_color_coding_from_video_mode do not need to query the
 +             * camera, and thus cannot fail. */
 +            continue;
 +        }
 +        dc1394_get_color_coding_from_video_mode (NULL, video_modes.modes[i],
 +                &dc1394_color_coding);
 +        for (cc = dc1394_color_codings; cc->pix_fmt != PIX_FMT_NONE; cc++)
 +            if (cc->coding == dc1394_color_coding)
 +                break;
 +        if (cc->pix_fmt == PIX_FMT_NONE) {
 +            /* We currently cannot handle this color coding. */
 +            continue;
 +        }
 +        /* Here we know that the mode is supported. Get its frame size and the list
 +         * of frame rates supported by the camera for this mode. This list is sorted
 +         * in ascending order according to libdc1394 example programs. */
 +        dc1394_get_image_size_from_video_mode (NULL, video_modes.modes[i],
 +                &dc1394_width, &dc1394_height);
 +        res = dc1394_video_get_supported_framerates (dc1394->camera, video_modes.modes[i],
 +                &frame_rates);
 +        if (res != DC1394_SUCCESS || frame_rates.num == 0) {
 +            av_log(c, AV_LOG_ERROR, "Cannot get frame rates for video mode.\n");
 +            goto out_camera;
 +        }
 +        /* Choose the best frame rate. */
 +        best_rate = -1;
 +        for (j = 0; j < frame_rates.num; j++) {
 +            for (fr = dc1394_frame_rates; fr->frame_rate; fr++) {
 +                if (fr->frame_rate_id == frame_rates.framerates[j]) {
 +                    break;
 +                }
 +            }
 +            if (!fr->frame_rate) {
 +                /* This frame rate is not supported. */
 +                continue;
 +            }
 +            best_rate = fr->frame_rate;
 +            frame_rate = fr->frame_rate_id;
 +            if (ap->time_base.num && rate == fr->frame_rate) {
 +                /* This is the requested frame rate. */
 +                break;
 +            }
 +        }
 +        if (best_rate == -1) {
 +            /* No supported rate found. */
 +            continue;
 +        }
 +        /* Here we know that both the mode and the rate are supported. Compute score. */
 +        if (ap->width && ap->height
 +                && (dc1394_width == ap->width && dc1394_height == ap->height)) {
 +            score = 110000;
 +        } else {
 +            score = dc1394_width * 10;  // 1600 - 16000
 +        }
 +        if (ap->pix_fmt == cc->pix_fmt) {
 +            score += 90000;
 +        } else {
 +            score += cc->score;         // 1000 - 1500
 +        }
 +        if (ap->time_base.num && rate == best_rate) {
 +            score += 70000;
 +        } else {
 +            score += best_rate / 1000;  // 1 - 240
 +        }
 +        if (score > max_score) {
 +            video_mode = video_modes.modes[i];
 +            final_width = dc1394_width;
 +            final_height = dc1394_height;
 +            final_pix_fmt = cc->pix_fmt;
 +            final_frame_rate = best_rate;
 +            max_score = score;
 +        }
 +    }
 +    if (max_score == -1) {
 +        av_log(c, AV_LOG_ERROR, "No suitable video mode / frame rate available.\n");
 +        goto out_camera;
 +    }
 +    if (ap->width && ap->height && !(ap->width == final_width && ap->height == final_height)) {
 +        av_log(c, AV_LOG_WARNING, "Requested frame size is not available, using fallback.\n");
 +    }
 +    if (ap->pix_fmt != PIX_FMT_NONE && ap->pix_fmt != final_pix_fmt) {
 +        av_log(c, AV_LOG_WARNING, "Requested pixel format is not supported, using fallback.\n");
 +    }
 +    if (ap->time_base.num && rate != final_frame_rate) {
 +        av_log(c, AV_LOG_WARNING, "Requested frame rate is not available, using fallback.\n");
      }
  
      /* create a video stream */
@@@ -303,11 -361,11 +314,13 @@@ out_camera
      dc1394_video_set_transmission(dc1394->camera, DC1394_OFF);
      dc1394_camera_free (dc1394->camera);
  out:
++    av_freep(&dc1394->video_size);
++    av_freep(&dc1394->pixel_format);
      dc1394_free(dc1394->d);
 -    return -1;
 +    return ret;
  }
  
 -static int dc1394_v2_read_packet(AVFormatContext *c, AVPacket *pkt)
 +static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt)
  {
      struct dc1394_data *dc1394 = c->priv_data;
      int res;
@@@ -48,8 -46,8 +48,9 @@@
  #include "libavutil/imgutils.h"
  #include "libavutil/log.h"
  #include "libavutil/opt.h"
 +#include "avdevice.h"
  #include "libavutil/parseutils.h"
+ #include "libavutil/pixdesc.h"
  
  static const int desired_video_buffers = 256;
  
@@@ -704,11 -726,11 +715,12 @@@ static int v4l2_read_close(AVFormatCont
  
  #define OFFSET(x) offsetof(struct video_data, x)
  #define DEC AV_OPT_FLAG_DECODING_PARAM
 +
  static const AVOption options[] = {
 -    { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = "NTSC" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
 -    { "channel",  "", offsetof(struct video_data, channel),  FF_OPT_TYPE_INT,    {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
 +    { "standard", "", OFFSET(standard), FF_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
 +    { "channel",  "", OFFSET(channel),  FF_OPT_TYPE_INT,    {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
      { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+     { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
      { NULL },
  };
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -22,8 -22,8 +22,9 @@@
  #ifndef AVUTIL_PIXDESC_H
  #define AVUTIL_PIXDESC_H
  
 +#include "pixfmt.h"
  #include <inttypes.h>
+ #include "pixfmt.h"
  
  typedef struct AVComponentDescriptor{
      uint16_t plane        :2;            ///< which of the 4 planes contains the component
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -123,38 -123,10 +123,38 @@@ void sws_rgb2rgb_init(void
          rgb2rgb_init_x86();
  }
  
- void rgb32to24(const uint8_t *src, uint8_t *dst, long src_size)
 +#if LIBSWSCALE_VERSION_MAJOR < 1
 +void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
 +{
 +    sws_convertPalette8ToPacked32(src, dst, num_pixels, palette);
 +}
 +
 +void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
 +{
 +    sws_convertPalette8ToPacked24(src, dst, num_pixels, palette);
 +}
 +
 +/**
 + * Palette is assumed to contain BGR16, see rgb32to16 to convert the palette.
 + */
 +void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
 +{
 +    long i;
 +    for (i=0; i<num_pixels; i++)
 +        ((uint16_t *)dst)[i] = ((const uint16_t *)palette)[src[i]];
 +}
 +void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
 +{
 +    long i;
 +    for (i=0; i<num_pixels; i++)
 +        ((uint16_t *)dst)[i] = av_bswap16(((const uint16_t *)palette)[src[i]]);
 +}
 +#endif
 +
+ void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
  {
-     long i;
-     long num_pixels = src_size >> 2;
+     int i;
+     int num_pixels = src_size >> 2;
      for (i=0; i<num_pixels; i++) {
  #if HAVE_BIGENDIAN
          /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
  #include "libavutil/avutil.h"
  
  /* A full collection of RGB to RGB(BGR) converters */
- extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb32to16)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb32to15)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb15to16)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb15to32)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb16to15)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb16to32)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb24to16)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb24to15)   (const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
- extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
- void rgb24to32   (const uint8_t *src, uint8_t *dst, long src_size);
- void rgb32to24   (const uint8_t *src, uint8_t *dst, long src_size);
- void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
- void rgb16to24   (const uint8_t *src, uint8_t *dst, long src_size);
- void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size);
- void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size);
- void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
- void rgb15to24   (const uint8_t *src, uint8_t *dst, long src_size);
- void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size);
- void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size);
- void bgr8torgb8  (const uint8_t *src, uint8_t *dst, long src_size);
- void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, long src_size);
- void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, long src_size);
- void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size);
- void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size);
+ extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb32to16)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb32to15)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb15to16)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb15to32)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb16to15)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb16to32)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb24to16)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb24to15)   (const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
+ extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb24to32   (const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb32to24   (const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb16to24   (const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb15to24   (const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size);
+ void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size);
+ void bgr8torgb8  (const uint8_t *src, uint8_t *dst, int src_size);
+ void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, int src_size);
+ void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, int src_size);
+ void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, int src_size);
+ void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, int src_size);
  
 +#if LIBSWSCALE_VERSION_MAJOR < 1
 +/* deprecated, use the public versions in swscale.h */
 +attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +attribute_deprecated void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +
 +/* totally deprecated, please fix code that uses this */
 +attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +#endif
 +
 +
  void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
-                    uint8_t *vdst, long width, long height, long lumStride,
-                    long chromStride, long srcStride);
+                    uint8_t *vdst, int width, int height, int lumStride,
+                    int chromStride, int srcStride);
  
  /**
   * Height should be a multiple of 2 and width should be a multiple of 16.
Simple merge
@@@ -1074,58 -980,96 +1074,58 @@@ static void fillPlane(uint8_t* plane, i
      }
  }
  
 -static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int width,
 -                            uint32_t *unused)
 -{
 -    int i;
 -    for (i = 0; i < width; i++) {
 -        int r = src[i*6+0];
 -        int g = src[i*6+2];
 -        int b = src[i*6+4];
 -
 -        dst[i] = (RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 -    }
 -}
 -
 -static inline void rgb48ToUV(uint8_t *dstU, uint8_t *dstV,
 -                             const uint8_t *src1, const uint8_t *src2,
 -                             int width, uint32_t *unused)
 -{
 -    int i;
 -    assert(src1==src2);
 -    for (i = 0; i < width; i++) {
 -        int r = src1[6*i + 0];
 -        int g = src1[6*i + 2];
 -        int b = src1[6*i + 4];
 -
 -        dstU[i] = (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 -        dstV[i] = (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 -    }
 -}
 -
 -static inline void rgb48ToUV_half(uint8_t *dstU, uint8_t *dstV,
 -                                  const uint8_t *src1, const uint8_t *src2,
 -                                  int width, uint32_t *unused)
 -{
 -    int i;
 -    assert(src1==src2);
 -    for (i = 0; i < width; i++) {
 -        int r= src1[12*i + 0] + src1[12*i + 6];
 -        int g= src1[12*i + 2] + src1[12*i + 8];
 -        int b= src1[12*i + 4] + src1[12*i + 10];
 -
 -        dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
 -        dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
 -    }
 -}
 -
 -static inline void bgr48ToY(uint8_t *dst, const uint8_t *src, int width,
 -                            uint32_t *unused)
 -{
 -    int i;
 -    for (i = 0; i < width; i++) {
 -        int b = src[i*6+0];
 -        int g = src[i*6+2];
 -        int r = src[i*6+4];
 -
 -        dst[i] = (RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 -    }
 -}
 -
 -static inline void bgr48ToUV(uint8_t *dstU, uint8_t *dstV,
 -                             const uint8_t *src1, const uint8_t *src2,
 -                             int width, uint32_t *unused)
 -{
 -    int i;
 -    for (i = 0; i < width; i++) {
 -        int b = src1[6*i + 0];
 -        int g = src1[6*i + 2];
 -        int r = src1[6*i + 4];
 -
 -        dstU[i] = (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 -        dstV[i] = (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 -    }
 +#define RGB48(name, R, B, READ)\
- static inline void name ## ToY(int16_t *dst, const uint16_t *src, long width, uint32_t *unused)\
++static inline void name ## ToY(int16_t *dst, const uint16_t *src, int width, uint32_t *unused)\
 +{\
 +    int i;\
 +    for (i = 0; i < width; i++) {\
 +        int r = READ(&src[i*3+R]);\
 +        int g = READ(&src[i*3+1]);\
 +        int b = READ(&src[i*3+B]);\
 +\
 +        dst[i] = (RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);\
 +    }\
 +}\
 +\
 +static inline void name ## ToUV(int16_t *dstU, int16_t *dstV,\
 +                             const uint16_t *src1, const uint16_t *src2,\
-                              long width, uint32_t *unused)\
++                             int width, uint32_t *unused)\
 +{\
 +    int i;\
 +    assert(src1==src2);\
 +    for (i = 0; i < width; i++) {\
 +        int r = READ(&src1[3*i + R]);\
 +        int g = READ(&src1[3*i + 1]);\
 +        int b = READ(&src1[3*i + B]);\
 +\
 +        dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);\
 +        dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);\
 +    }\
 +}\
 +\
 +static inline void name ## ToUV_half(int16_t *dstU, int16_t *dstV,\
 +                                  const uint16_t *src1, const uint16_t *src2,\
-                                   long width, uint32_t *unused)\
++                                  int width, uint32_t *unused)\
 +{\
 +    int i;\
 +    assert(src1==src2);\
 +    for (i = 0; i < width; i++) {\
 +        int r= READ(&src1[6*i + R]) + READ(&src1[6*i + 3+R]);\
 +        int g= READ(&src1[6*i + 1]) + READ(&src1[6*i + 4]);\
 +        int b= READ(&src1[6*i + B]) + READ(&src1[6*i + 3+B]);\
 +\
 +        dstU[i]= (RU*r + GU*g + BU*b + (256U<<(RGB2YUV_SHIFT+8)) + (1<<(RGB2YUV_SHIFT-6+8))) >> (RGB2YUV_SHIFT-5+8);\
 +        dstV[i]= (RV*r + GV*g + BV*b + (256U<<(RGB2YUV_SHIFT+8)) + (1<<(RGB2YUV_SHIFT-6+8))) >> (RGB2YUV_SHIFT-5+8);\
 +    }\
  }
  
 -static inline void bgr48ToUV_half(uint8_t *dstU, uint8_t *dstV,
 -                                  const uint8_t *src1, const uint8_t *src2,
 -                                  int width, uint32_t *unused)
 -{
 -    int i;
 -    for (i = 0; i < width; i++) {
 -        int b= src1[12*i + 0] + src1[12*i + 6];
 -        int g= src1[12*i + 2] + src1[12*i + 8];
 -        int r= src1[12*i + 4] + src1[12*i + 10];
 -
 -        dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
 -        dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
 -    }
 -}
 +RGB48(rgb48LE, 0, 2, AV_RL16)
 +RGB48(rgb48BE, 0, 2, AV_RB16)
 +RGB48(bgr48LE, 2, 0, AV_RL16)
 +RGB48(bgr48BE, 2, 0, AV_RB16)
  
  #define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\
- static inline void name(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)\
 -static inline void name(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)\
++static inline void name(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)\
  {\
      int i;\
      for (i=0; i<width; i++) {\
@@@ -1146,7 -1090,7 +1146,7 @@@ BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x00
  BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY    , GY<<5, BY<<11, RGB2YUV_SHIFT+8)
  BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY    , GY<<5, BY<<10, RGB2YUV_SHIFT+7)
  
- static inline void abgrToA(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
 -static inline void abgrToA(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
++static inline void abgrToA(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  {
      int i;
      for (i=0; i<width; i++) {
  }
  
  #define BGR2UV(type, name, shr, shg, shb, shp, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S) \
- static inline void name(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
 -static inline void name(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
++static inline void name(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
  {\
      int i;\
      for (i=0; i<width; i++) {\
          int g= ((((const type*)src)[i]>>shp)&maskg)>>shg;\
          int r= ((((const type*)src)[i]>>shp)&maskr)>>shr;\
  \
 -        dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\
 -        dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<((S)-1)))>>(S);\
 +        dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (256<<((S)-1)) + (1<<(S-7)))>>((S)-6);\
 +        dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (256<<((S)-1)) + (1<<(S-7)))>>((S)-6);\
      }\
  }\
- static inline void name ## _half(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
 -static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
++static inline void name ## _half(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
  {\
      int i;\
      for (i=0; i<width; i++) {\
@@@ -1194,7 -1138,7 +1194,7 @@@ BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0
  BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0,   0xF800, 0x07E0,   0x001F, RU    , GU<<5, BU<<11, RV    , GV<<5, BV<<11, RGB2YUV_SHIFT+8)
  BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0,   0x7C00, 0x03E0,   0x001F, RU    , GU<<5, BU<<10, RV    , GV<<5, BV<<10, RGB2YUV_SHIFT+7)
  
- static inline void palToA(int16_t *dst, const uint8_t *src, long width, uint32_t *pal)
 -static inline void palToY(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
++static inline void palToA(int16_t *dst, const uint8_t *src, int width, uint32_t *pal)
  {
      int i;
      for (i=0; i<width; i++) {
      }
  }
  
 -static inline void palToUV(uint8_t *dstU, uint8_t *dstV,
 +static inline void palToY(int16_t *dst, const uint8_t *src, long width, uint32_t *pal)
 +{
 +    int i;
 +    for (i=0; i<width; i++) {
 +        int d= src[i];
 +
 +        dst[i]= (pal[d] & 0xFF)<<6;
 +    }
 +}
 +
 +static inline void palToUV(uint16_t *dstU, int16_t *dstV,
                             const uint8_t *src1, const uint8_t *src2,
-                            long width, uint32_t *pal)
+                            int width, uint32_t *pal)
  {
      int i;
      assert(src1 == src2);
      }
  }
  
- static inline void monowhite2Y(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
 -static inline void monowhite2Y(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
++static inline void monowhite2Y(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  {
      int i, j;
      for (i=0; i<width/8; i++) {
      }
  }
  
- static inline void monoblack2Y(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
 -static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
++static inline void monoblack2Y(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  {
      int i, j;
      for (i=0; i<width/8; i++) {
@@@ -2076,18 -2056,10 +2076,18 @@@ int sws_scale(SwsContext *c, const uint
      }
  }
  
 +#if LIBSWSCALE_VERSION_MAJOR < 1
 +int sws_scale_ordered(SwsContext *c, const uint8_t* const src[], int srcStride[], int srcSliceY,
 +                      int srcSliceH, uint8_t* dst[], int dstStride[])
 +{
 +    return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
 +}
 +#endif
 +
  /* Convert the palette to the same packed 32-bit format as the palette */
- void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+ void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
  {
-     long i;
+     int i;
  
      for (i=0; i<num_pixels; i++)
          ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
Simple merge
@@@ -306,14 -308,10 +308,14 @@@ typedef struct SwsContext 
  
      void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
                     int xInc, const int16_t *filter, const int16_t *filterPos,
-                    long filterSize);
+                    int filterSize);
  
 -    void (*lumConvertRange)(uint16_t *dst, int width); ///< Color range conversion function for luma plane if needed.
 -    void (*chrConvertRange)(uint16_t *dst1, uint16_t *dst2, int width); ///< Color range conversion function for chroma planes if needed.
 +    void (*hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW,
 +                   int xInc, const int16_t *filter, const int16_t *filterPos,
 +                   long filterSize, int shift);
 +
 +    void (*lumConvertRange)(int16_t *dst, int width); ///< Color range conversion function for luma plane if needed.
 +    void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width); ///< Color range conversion function for chroma planes if needed.
  
      int lumSrcOffset; ///< Offset given to luma src pointers passed to horizontal input functions.
      int chrSrcOffset; ///< Offset given to chroma src pointers passed to horizontal input functions.
@@@ -200,23 -200,39 +200,23 @@@ static inline void nvXXtoUV_c(uint8_t *
      }
  }
  
 -static inline void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
 -                              const uint8_t *src1, const uint8_t *src2,
 -                              int width, uint32_t *unused)
 -{
 -    nvXXtoUV_c(dstU, dstV, src1, width);
 -}
 -
 -static inline void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
 -                              const uint8_t *src1, const uint8_t *src2,
 -                              int width, uint32_t *unused)
 -{
 -    nvXXtoUV_c(dstV, dstU, src1, width);
 -}
 -
  // FIXME Maybe dither instead.
 +#ifndef YUV_NBPS
  #define YUV_NBPS(depth, endianness, rfunc) \
  static inline void endianness ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
 -                                          const uint8_t *_srcU, const uint8_t *_srcV, \
 +                                          const uint16_t *srcU, const uint16_t *srcV, \
-                                           long width, uint32_t *unused) \
+                                           int width, uint32_t *unused) \
  { \
      int i; \
 -    const uint16_t *srcU = (const uint16_t*)_srcU; \
 -    const uint16_t *srcV = (const uint16_t*)_srcV; \
      for (i = 0; i < width; i++) { \
          dstU[i] = rfunc(&srcU[i])>>(depth-8); \
          dstV[i] = rfunc(&srcV[i])>>(depth-8); \
      } \
  } \
  \
- static inline void endianness ## depth ## ToY_c(uint8_t *dstY, const uint16_t *srcY, long width, uint32_t *unused) \
 -static inline void endianness ## depth ## ToY_c(uint8_t *dstY, const uint8_t *_srcY, int width, uint32_t *unused) \
++static inline void endianness ## depth ## ToY_c(uint8_t *dstY, const uint16_t *srcY, int width, uint32_t *unused) \
  { \
      int i; \
 -    const uint16_t *srcY = (const uint16_t*)_srcY; \
      for (i = 0; i < width; i++) \
          dstY[i] = rfunc(&srcY[i])>>(depth-8); \
  } \
@@@ -225,24 -241,9 +225,24 @@@ YUV_NBPS( 9, LE, AV_RL16
  YUV_NBPS( 9, BE, AV_RB16)
  YUV_NBPS(10, LE, AV_RL16)
  YUV_NBPS(10, BE, AV_RB16)
 +#endif // YUV_NBPS
  
 -static inline void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
 +static inline void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
 +                              const uint8_t *src1, const uint8_t *src2,
-                               long width, uint32_t *unused)
++                              int width, uint32_t *unused)
 +{
 +    nvXXtoUV_c(dstU, dstV, src1, width);
 +}
 +
 +static inline void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
 +                              const uint8_t *src1, const uint8_t *src2,
-                               long width, uint32_t *unused)
++                              int width, uint32_t *unused)
 +{
 +    nvXXtoUV_c(dstV, dstU, src1, width);
 +}
 +
 +static inline void bgr24ToY_c(int16_t *dst, const uint8_t *src,
-                               long width, uint32_t *unused)
+                               int width, uint32_t *unused)
  {
      int i;
      for (i=0; i<width; i++) {
      }
  }
  
 -static inline void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
 +static inline void bgr24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
-                                const uint8_t *src2, long width, uint32_t *unused)
+                                const uint8_t *src2, int width, uint32_t *unused)
  {
      int i;
      for (i=0; i<width; i++) {
      assert(src1 == src2);
  }
  
 -static inline void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
 +static inline void bgr24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
-                                     const uint8_t *src2, long width, uint32_t *unused)
+                                     const uint8_t *src2, int width, uint32_t *unused)
  {
      int i;
      for (i=0; i<width; i++) {
      assert(src1 == src2);
  }
  
- static inline void rgb24ToY_c(int16_t *dst, const uint8_t *src, long width,
 -static inline void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width,
++static inline void rgb24ToY_c(int16_t *dst, const uint8_t *src, int width,
                                uint32_t *unused)
  {
      int i;
      }
  }
  
 -static inline void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
 +static inline void rgb24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
-                                const uint8_t *src2, long width, uint32_t *unused)
+                                const uint8_t *src2, int width, uint32_t *unused)
  {
      int i;
      assert(src1==src2);
      }
  }
  
 -static inline void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
 +static inline void rgb24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
-                                     const uint8_t *src2, long width, uint32_t *unused)
+                                     const uint8_t *src2, int width, uint32_t *unused)
  {
      int i;
      assert(src1==src2);
@@@ -429,8 -401,8 +429,8 @@@ static inline void hyscale_c(SwsContex
                               uint8_t *formatConvBuffer,
                               uint32_t *pal, int isAlpha)
  {
-     void (*toYV12)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
+     void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
 -    void (*convertRange)(uint16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
 +    void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
  
      src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset;
  
Simple merge
Simple merge
@@@ -190,10 -190,10 +190,10 @@@ static inline void RENAME(yuv2yuv1)(Sws
                                      const int16_t *chrUSrc, const int16_t *chrVSrc,
                                      const int16_t *alpSrc,
                                      uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
-                                     uint8_t *aDest, long dstW, long chrDstW)
+                                     uint8_t *aDest, int dstW, int chrDstW)
  {
-     long p= 4;
+     int p= 4;
 -    const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
 +    const int16_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
      uint8_t *dst[4]= { aDest, dest, uDest, vDest };
      x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW };
  
@@@ -231,10 -231,10 +231,10 @@@ static inline void RENAME(yuv2yuv1_ar)(
                                         const int16_t *chrUSrc, const int16_t *chrVSrc,
                                         const int16_t *alpSrc,
                                         uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
-                                        uint8_t *aDest, long dstW, long chrDstW)
+                                        uint8_t *aDest, int dstW, int chrDstW)
  {
-     long p= 4;
+     int p= 4;
 -    const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
 +    const int16_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
      uint8_t *dst[4]= { aDest, dest, uDest, vDest };
      x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW };
  
@@@ -1774,7 -1759,7 +1759,7 @@@ static inline void RENAME(nv21ToUV)(uin
  }
  #endif /* !COMPILE_TEMPLATE_MMX2 */
  
- static inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, long width, enum PixelFormat srcFormat)
 -static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, int width, enum PixelFormat srcFormat)
++static inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, int width, enum PixelFormat srcFormat)
  {
  
      if(srcFormat == PIX_FMT_BGR24) {
      );
  }
  
- static inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, const uint8_t *src, long width, enum PixelFormat srcFormat)
 -static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, int width, enum PixelFormat srcFormat)
++static inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, const uint8_t *src, int width, enum PixelFormat srcFormat)
  {
      __asm__ volatile(
          "movq                    24(%4), %%mm6       \n\t"
      );
  }
  
- static inline void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
 -static inline void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
++static inline void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  {
      RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
  }
  
- static inline void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
 -static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
++static inline void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
  {
      RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
      assert(src1 == src2);
  }
  
- static inline void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
 -static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
++static inline void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  {
      RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
  }
  
- static inline void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
 -static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
++static inline void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
  {
      assert(src1==src2);
      RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
@@@ -2061,166 -2049,9 +2046,166 @@@ static inline void RENAME(hScale)(int16
  }
  #endif /* !COMPILE_TEMPLATE_MMX2 */
  
 +static inline void RENAME(hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW, int xInc,
 +                                    const int16_t *filter, const int16_t *filterPos, long filterSize, int shift)
 +{
 +    int i, j;
 +
 +    assert(filterSize % 4 == 0 && filterSize>0);
 +    if (filterSize==4 && shift<15) { // Always true for upscaling, sometimes for down, too.
 +        x86_reg counter= -2*dstW;
 +        filter-= counter*2;
 +        filterPos-= counter/2;
 +        dst-= counter/2;
 +        __asm__ volatile(
 +            "movd                   %5, %%mm7       \n\t"
 +#if defined(PIC)
 +            "push            %%"REG_b"              \n\t"
 +#endif
 +            "push           %%"REG_BP"              \n\t" // we use 7 regs here ...
 +            "mov             %%"REG_a", %%"REG_BP"  \n\t"
 +            ".p2align                4              \n\t"
 +            "1:                                     \n\t"
 +            "movzwl   (%2, %%"REG_BP"), %%eax       \n\t"
 +            "movzwl  2(%2, %%"REG_BP"), %%ebx       \n\t"
 +            "movq  (%1, %%"REG_BP", 4), %%mm1       \n\t"
 +            "movq 8(%1, %%"REG_BP", 4), %%mm3       \n\t"
 +            "movq      (%3, %%"REG_a", 2), %%mm0    \n\t"
 +            "movq      (%3, %%"REG_b", 2), %%mm2    \n\t"
 +            "pmaddwd             %%mm1, %%mm0       \n\t"
 +            "pmaddwd             %%mm2, %%mm3       \n\t"
 +            "movq                %%mm0, %%mm4       \n\t"
 +            "punpckldq           %%mm3, %%mm0       \n\t"
 +            "punpckhdq           %%mm3, %%mm4       \n\t"
 +            "paddd               %%mm4, %%mm0       \n\t"
 +            "psrad               %%mm7, %%mm0       \n\t"
 +            "packssdw            %%mm0, %%mm0       \n\t"
 +            "movd                %%mm0, (%4, %%"REG_BP")    \n\t"
 +            "add                    $4, %%"REG_BP"  \n\t"
 +            " jnc                   1b              \n\t"
 +
 +            "pop            %%"REG_BP"              \n\t"
 +#if defined(PIC)
 +            "pop             %%"REG_b"              \n\t"
 +#endif
 +            : "+a" (counter)
 +            : "c" (filter), "d" (filterPos), "S" (src), "D" (dst), "m"(shift)
 +#if !defined(PIC)
 +            : "%"REG_b
 +#endif
 +        );
 +    } else if (filterSize==8 && shift<15) {
 +        x86_reg counter= -2*dstW;
 +        filter-= counter*4;
 +        filterPos-= counter/2;
 +        dst-= counter/2;
 +        __asm__ volatile(
 +            "movd                   %5, %%mm7       \n\t"
 +#if defined(PIC)
 +            "push            %%"REG_b"              \n\t"
 +#endif
 +            "push            %%"REG_BP"             \n\t" // we use 7 regs here ...
 +            "mov              %%"REG_a", %%"REG_BP" \n\t"
 +            ".p2align                 4             \n\t"
 +            "1:                                     \n\t"
 +            "movzwl    (%2, %%"REG_BP"), %%eax      \n\t"
 +            "movzwl   2(%2, %%"REG_BP"), %%ebx      \n\t"
 +            "movq   (%1, %%"REG_BP", 8), %%mm1      \n\t"
 +            "movq 16(%1, %%"REG_BP", 8), %%mm3      \n\t"
 +            "movq       (%3, %%"REG_a", 2), %%mm0   \n\t"
 +            "movq       (%3, %%"REG_b", 2), %%mm2   \n\t"
 +            "pmaddwd              %%mm1, %%mm0      \n\t"
 +            "pmaddwd              %%mm2, %%mm3      \n\t"
 +
 +            "movq  8(%1, %%"REG_BP", 8), %%mm1      \n\t"
 +            "movq 24(%1, %%"REG_BP", 8), %%mm5      \n\t"
 +            "movq      8(%3, %%"REG_a", 2), %%mm4   \n\t"
 +            "movq      8(%3, %%"REG_b", 2), %%mm2   \n\t"
 +            "pmaddwd              %%mm1, %%mm4      \n\t"
 +            "pmaddwd              %%mm2, %%mm5      \n\t"
 +            "paddd                %%mm4, %%mm0      \n\t"
 +            "paddd                %%mm5, %%mm3      \n\t"
 +            "movq                 %%mm0, %%mm4      \n\t"
 +            "punpckldq            %%mm3, %%mm0      \n\t"
 +            "punpckhdq            %%mm3, %%mm4      \n\t"
 +            "paddd                %%mm4, %%mm0      \n\t"
 +            "psrad                %%mm7, %%mm0      \n\t"
 +            "packssdw             %%mm0, %%mm0      \n\t"
 +            "movd                 %%mm0, (%4, %%"REG_BP")   \n\t"
 +            "add                     $4, %%"REG_BP" \n\t"
 +            " jnc                    1b             \n\t"
 +
 +            "pop             %%"REG_BP"             \n\t"
 +#if defined(PIC)
 +            "pop             %%"REG_b"              \n\t"
 +#endif
 +            : "+a" (counter)
 +            : "c" (filter), "d" (filterPos), "S" (src), "D" (dst), "m"(shift)
 +#if !defined(PIC)
 +            : "%"REG_b
 +#endif
 +        );
 +    } else if (shift<15){
 +        const uint16_t *offset = src+filterSize;
 +        x86_reg counter= -2*dstW;
 +        //filter-= counter*filterSize/2;
 +        filterPos-= counter/2;
 +        dst-= counter/2;
 +        __asm__ volatile(
 +            "movd                   %7, %%mm7       \n\t"
 +            ".p2align                  4            \n\t"
 +            "1:                                     \n\t"
 +            "mov                      %2, %%"REG_c" \n\t"
 +            "movzwl      (%%"REG_c", %0), %%eax     \n\t"
 +            "movzwl     2(%%"REG_c", %0), %%edx     \n\t"
 +            "mov                      %5, %%"REG_c" \n\t"
 +            "pxor                  %%mm4, %%mm4     \n\t"
 +            "pxor                  %%mm5, %%mm5     \n\t"
 +            "2:                                     \n\t"
 +            "movq                   (%1), %%mm1     \n\t"
 +            "movq               (%1, %6), %%mm3     \n\t"
 +            "movq (%%"REG_c", %%"REG_a", 2), %%mm0     \n\t"
 +            "movq (%%"REG_c", %%"REG_d", 2), %%mm2     \n\t"
 +            "pmaddwd               %%mm1, %%mm0     \n\t"
 +            "pmaddwd               %%mm2, %%mm3     \n\t"
 +            "paddd                 %%mm3, %%mm5     \n\t"
 +            "paddd                 %%mm0, %%mm4     \n\t"
 +            "add                      $8, %1        \n\t"
 +            "add                      $8, %%"REG_c" \n\t"
 +            "cmp                      %4, %%"REG_c" \n\t"
 +            " jb                      2b            \n\t"
 +            "add                      %6, %1        \n\t"
 +            "movq                  %%mm4, %%mm0     \n\t"
 +            "punpckldq             %%mm5, %%mm4     \n\t"
 +            "punpckhdq             %%mm5, %%mm0     \n\t"
 +            "paddd                 %%mm0, %%mm4     \n\t"
 +            "psrad                 %%mm7, %%mm4     \n\t"
 +            "packssdw              %%mm4, %%mm4     \n\t"
 +            "mov                      %3, %%"REG_a" \n\t"
 +            "movd                  %%mm4, (%%"REG_a", %0)   \n\t"
 +            "add                      $4, %0        \n\t"
 +            " jnc                     1b            \n\t"
 +
 +            : "+r" (counter), "+r" (filter)
 +            : "m" (filterPos), "m" (dst), "m"(offset),
 +            "m" (src), "r" ((x86_reg)filterSize*2), "m"(shift)
 +            : "%"REG_a, "%"REG_c, "%"REG_d
 +        );
 +    } else
 +    for (i=0; i<dstW; i++) {
 +        int srcPos= filterPos[i];
 +        int val=0;
 +        for (j=0; j<filterSize; j++) {
 +            val += ((int)src[srcPos + j])*filter[filterSize*i + j];
 +        }
 +        dst[i] = FFMIN(val>>shift, (1<<15)-1); // the cubic equation does overflow ...
 +    }
 +}
 +
 +
  #if COMPILE_TEMPLATE_MMX2
  static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
-                                         long dstWidth, const uint8_t *src, int srcW,
+                                         int dstWidth, const uint8_t *src, int srcW,
                                          int xInc)
  {
      int32_t *filterPos = c->hLumFilterPos;